use of org.hisp.dhis.dashboard.DashboardItem 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.DashboardItem in project dhis2-core by dhis2.
the class DefaultDashboardService method addItemContent.
@Override
@Transactional(readOnly = true)
public DashboardItem addItemContent(String dashboardUid, DashboardItemType type, String contentUid) {
Dashboard dashboard = getDashboard(dashboardUid);
if (dashboard == null) {
return null;
}
DashboardItem item = new DashboardItem();
if (DashboardItemType.VISUALIZATION.equals(type)) {
item.setVisualization(objectManager.get(Visualization.class, contentUid));
dashboard.getItems().add(0, item);
}
if (DashboardItemType.EVENT_VISUALIZATION.equals(type)) {
item.setEventVisualization(objectManager.get(EventVisualization.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.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;
}
use of org.hisp.dhis.dashboard.DashboardItem in project dhis2-core by dhis2.
the class CascadeSharingTest method createDashboardWithItem.
protected Dashboard createDashboardWithItem(String name, Sharing sharing) {
DashboardItem dashboardItem = createDashboardItem("A");
Dashboard dashboard = new Dashboard();
dashboard.setName("dashboard" + name);
dashboard.setSharing(sharing);
dashboard.getItems().add(dashboardItem);
return dashboard;
}
use of org.hisp.dhis.dashboard.DashboardItem in project dhis2-core by dhis2.
the class CascadeSharingTest method createDashboardItem.
protected DashboardItem createDashboardItem(String name) {
DashboardItem dashboardItem = new DashboardItem();
dashboardItem.setName("dashboardItem" + name);
dashboardItem.setAutoFields();
return dashboardItem;
}
use of org.hisp.dhis.dashboard.DashboardItem in project dhis2-core by dhis2.
the class DashboardCascadeSharingTest method testAtomicFalse.
@Test
void testAtomicFalse() {
Map mapA = createMap("A");
mapA.setSharing(sharingReadWriteForUserB);
objectManager.save(mapA, false);
Map mapB = createMap("A");
mapB.setSharing(defaultSharing());
objectManager.save(mapB, false);
DashboardItem itemB = createDashboardItem("B");
itemB.setMap(mapB);
Dashboard dashboard = createDashboardWithItem("A", sharingReadForUserA);
dashboard.getItems().get(0).setMap(mapA);
dashboard.getItems().add(itemB);
objectManager.save(dashboard, false);
CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, CascadeSharingParameters.builder().atomic(false).user(userB).build());
assertEquals(1, report.getErrorReports().size());
assertEquals(1, report.getUpdateObjects().size());
assertTrue(aclService.canRead(userA, mapA));
assertFalse(aclService.canRead(userA, mapB));
}
Aggregations