Search in sources :

Example 1 with Dashboard

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);
}
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 Dashboard

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);
}
Also used : Dashboard(org.hisp.dhis.dashboard.Dashboard) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Dashboard

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);
}
Also used : User(org.hisp.dhis.user.User) Dashboard(org.hisp.dhis.dashboard.Dashboard) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 4 with 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));
}
Also used : User(org.hisp.dhis.user.User) Dashboard(org.hisp.dhis.dashboard.Dashboard) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with 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;
}
Also used : User(org.hisp.dhis.user.User) Dashboard(org.hisp.dhis.dashboard.Dashboard) DashboardItem(org.hisp.dhis.dashboard.DashboardItem) Document(org.hisp.dhis.document.Document) Map(org.hisp.dhis.mapping.Map) EventReport(org.hisp.dhis.eventreport.EventReport) EventChart(org.hisp.dhis.eventchart.EventChart) Chart(org.hisp.dhis.chart.Chart)

Aggregations

Dashboard (org.hisp.dhis.dashboard.Dashboard)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)7 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)7 DashboardItem (org.hisp.dhis.dashboard.DashboardItem)6 User (org.hisp.dhis.user.User)6 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 Test (org.junit.Test)5 Query (org.hibernate.Query)1 Chart (org.hisp.dhis.chart.Chart)1 Document (org.hisp.dhis.document.Document)1 EventChart (org.hisp.dhis.eventchart.EventChart)1 EventReport (org.hisp.dhis.eventreport.EventReport)1 Map (org.hisp.dhis.mapping.Map)1 UserGroup (org.hisp.dhis.user.UserGroup)1 UserGroupAccess (org.hisp.dhis.user.UserGroupAccess)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1