use of org.hisp.dhis.dashboard.Dashboard in project dhis2-core by dhis2.
the class DashboardItemController method putDashboardItemShape.
@RequestMapping(value = "/{uid}/shape/{shape}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void putDashboardItemShape(@PathVariable String uid, @PathVariable DashboardItemShape shape, HttpServletRequest request, HttpServletResponse response) throws Exception {
DashboardItem item = dashboardService.getDashboardItem(uid);
if (item == null) {
throw new WebMessageException(WebMessageUtils.notFound("Dashboard item does not exist: " + uid));
}
Dashboard dashboard = dashboardService.getDashboardFromDashboardItem(item);
if (!aclService.canUpdate(currentUserService.getCurrentUser(), dashboard)) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this dashboard.");
}
item.setShape(shape);
dashboardService.updateDashboardItem(item);
}
use of org.hisp.dhis.dashboard.Dashboard in project dhis2-core by dhis2.
the class DashboardController method postJsonObject.
@Override
@RequestMapping(method = RequestMethod.POST, consumes = "application/json")
public void postJsonObject(HttpServletRequest request, HttpServletResponse response) throws Exception {
Dashboard dashboard = renderService.fromJson(request.getInputStream(), Dashboard.class);
dashboard.getTranslations().clear();
dashboardService.mergeDashboard(dashboard);
dashboardService.saveDashboard(dashboard);
response.addHeader("Location", DashboardSchemaDescriptor.API_ENDPOINT + "/" + dashboard.getUid());
webMessageService.send(WebMessageUtils.created("Dashboard created"), response, request);
}
use of org.hisp.dhis.dashboard.Dashboard in project dhis2-core by dhis2.
the class AclServiceTest method testAllowDashboardPublic.
@Test
public void testAllowDashboardPublic() {
User user1 = createUser("user1", "F_DASHBOARD_PUBLIC_ADD");
manager.save(user1);
Dashboard dashboard = new Dashboard("Dashboard");
dashboard.setPublicAccess(AccessStringHelper.DEFAULT);
dashboard.setUser(user1);
aclService.canWrite(user1, dashboard);
manager.save(dashboard);
dashboard.setPublicAccess(AccessStringHelper.READ_WRITE);
assertTrue(aclService.canUpdate(user1, dashboard));
manager.update(dashboard);
}
use of org.hisp.dhis.dashboard.Dashboard in project dhis2-core by dhis2.
the class AclServiceTest method testUserCanUpdateDashboard.
@Test
public void testUserCanUpdateDashboard() {
User user1 = createUser('A');
User user2 = createUser('B');
manager.save(user1);
manager.save(user2);
Dashboard dashboard = new Dashboard("Dashboard");
dashboard.setUser(user1);
manager.save(dashboard);
assertTrue(aclService.canRead(user1, dashboard));
assertTrue(aclService.canUpdate(user1, dashboard));
assertTrue(aclService.canDelete(user1, dashboard));
assertTrue(aclService.canManage(user1, dashboard));
assertFalse(aclService.canRead(user2, dashboard));
assertFalse(aclService.canUpdate(user2, dashboard));
assertFalse(aclService.canDelete(user2, dashboard));
assertFalse(aclService.canManage(user2, dashboard));
}
use of org.hisp.dhis.dashboard.Dashboard in project dhis2-core by dhis2.
the class DefaultDashboardService method addItemContent.
@Override
public DashboardItem addItemContent(String dashboardUid, DashboardItemType type, String contentUid) {
Dashboard dashboard = getDashboard(dashboardUid);
if (dashboard == null) {
return null;
}
DashboardItem item = new DashboardItem();
if (DashboardItemType.CHART.equals(type)) {
item.setChart(objectManager.get(Chart.class, contentUid));
dashboard.getItems().add(0, item);
} else if (DashboardItemType.EVENT_CHART.equals(type)) {
item.setEventChart(objectManager.get(EventChart.class, contentUid));
dashboard.getItems().add(0, item);
} else if (DashboardItemType.MAP.equals(type)) {
item.setMap(objectManager.get(Map.class, contentUid));
dashboard.getItems().add(0, item);
} else if (DashboardItemType.REPORT_TABLE.equals(type)) {
item.setReportTable(objectManager.get(ReportTable.class, contentUid));
dashboard.getItems().add(0, item);
} else if (DashboardItemType.EVENT_REPORT.equals(type)) {
item.setEventReport(objectManager.get(EventReport.class, contentUid));
dashboard.getItems().add(0, item);
} else if (DashboardItemType.MESSAGES.equals(type)) {
item.setMessages(true);
dashboard.getItems().add(0, item);
} else if (DashboardItemType.APP.equals(type)) {
item.setAppKey(contentUid);
dashboard.getItems().add(0, item);
} else // Link item
{
DashboardItem availableItem = dashboard.getAvailableItemByType(type);
item = availableItem == null ? new DashboardItem() : availableItem;
if (DashboardItemType.USERS.equals(type)) {
item.getUsers().add(objectManager.get(User.class, contentUid));
} else if (DashboardItemType.REPORTS.equals(type)) {
item.getReports().add(objectManager.get(Report.class, contentUid));
} else if (DashboardItemType.RESOURCES.equals(type)) {
item.getResources().add(objectManager.get(Document.class, contentUid));
}
if (availableItem == null) {
dashboard.getItems().add(0, item);
}
}
if (dashboard.getItemCount() > Dashboard.MAX_ITEMS) {
return null;
}
updateDashboard(dashboard);
return item;
}
Aggregations