Search in sources :

Example 1 with DashboardItem

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);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) Dashboard(org.hisp.dhis.dashboard.Dashboard) DashboardItem(org.hisp.dhis.dashboard.DashboardItem) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with DashboardItem

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;
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) EventReport(org.hisp.dhis.eventreport.EventReport) Report(org.hisp.dhis.report.Report) Dashboard(org.hisp.dhis.dashboard.Dashboard) DashboardItem(org.hisp.dhis.dashboard.DashboardItem) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Map(org.hisp.dhis.mapping.Map) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DashboardItem

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;
}
Also used : Dashboard(org.hisp.dhis.dashboard.Dashboard) DashboardItem(org.hisp.dhis.dashboard.DashboardItem)

Example 4 with DashboardItem

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;
}
Also used : DashboardItem(org.hisp.dhis.dashboard.DashboardItem)

Example 5 with 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));
}
Also used : Dashboard(org.hisp.dhis.dashboard.Dashboard) DashboardItem(org.hisp.dhis.dashboard.DashboardItem) Map(org.hisp.dhis.mapping.Map) Test(org.junit.jupiter.api.Test)

Aggregations

DashboardItem (org.hisp.dhis.dashboard.DashboardItem)16 Dashboard (org.hisp.dhis.dashboard.Dashboard)11 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)6 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Map (org.hisp.dhis.mapping.Map)4 Test (org.junit.jupiter.api.Test)3 StringWriter (java.io.StringWriter)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2 VelocityContext (org.apache.velocity.VelocityContext)2 VelocityManager (org.hisp.dhis.system.velocity.VelocityManager)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 EventReport (org.hisp.dhis.eventreport.EventReport)1 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)1 Report (org.hisp.dhis.report.Report)1 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)1 TaskId (org.hisp.dhis.scheduling.TaskId)1 User (org.hisp.dhis.user.User)1