use of org.hisp.dhis.dashboard.DashboardItem in project dhis2-core by dhis2.
the class DashboardController method postJsonItemContent.
@RequestMapping(value = "/{dashboardUid}/items/content", method = RequestMethod.POST)
public void postJsonItemContent(HttpServletResponse response, HttpServletRequest request, @PathVariable String dashboardUid, @RequestParam DashboardItemType type, @RequestParam("id") String contentUid) throws Exception {
Dashboard dashboard = dashboardService.getDashboard(dashboardUid);
if (dashboard == null) {
throw new WebMessageException(WebMessageUtils.notFound("Dashboard does not exist: " + dashboardUid));
}
if (!aclService.canUpdate(currentUserService.getCurrentUser(), dashboard)) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this dashboard.");
}
DashboardItem item = dashboardService.addItemContent(dashboardUid, type, contentUid);
if (item == null) {
throw new WebMessageException(WebMessageUtils.conflict("Max number of dashboard items reached: " + MAX_ITEMS));
} else {
response.addHeader("Location", DashboardItemSchemaDescriptor.API_ENDPOINT + "/" + item.getUid());
webMessageService.send(WebMessageUtils.created("Dashboard item created"), response, request);
}
}
use of org.hisp.dhis.dashboard.DashboardItem in project dhis2-core by dhis2.
the class DefaultPushAnalysisService method generateHtmlReport.
@Override
public String generateHtmlReport(PushAnalysis pushAnalysis, User user, JobConfiguration jobId) throws IOException {
if (jobId == null) {
jobId = new JobConfiguration("inMemoryGenerateHtmlReport", JobType.PUSH_ANALYSIS, currentUserService.getCurrentUser().getUid(), true);
notifier.clear(jobId);
}
user = user == null ? currentUserService.getCurrentUser() : user;
log(jobId, NotificationLevel.INFO, "Generating PushAnalysis for user '" + user.getUsername() + "'.", false, null);
// ----------------------------------------------------------------------
// Pre-process the dashboardItem and store them as Strings
// ----------------------------------------------------------------------
HashMap<String, String> itemHtml = new HashMap<>();
HashMap<String, String> itemLink = new HashMap<>();
for (DashboardItem item : pushAnalysis.getDashboard().getItems()) {
// In normal conditions all DashboardItem has a type.
if (item.getType() != null) {
itemHtml.put(item.getUid(), getItemHtml(item, user, jobId));
itemLink.put(item.getUid(), getItemLink(item));
}
}
DateFormat dateFormat = new SimpleDateFormat("MMMM dd, yyyy");
itemHtml.put("date", dateFormat.format(Calendar.getInstance().getTime()));
itemHtml.put("instanceBaseUrl", dhisConfigurationProvider.getServerBaseUrl());
itemHtml.put("instanceName", systemSettingManager.getStringSetting(SettingKey.APPLICATION_TITLE));
// ----------------------------------------------------------------------
// Set up template context, including pre-processed dashboard items
// ----------------------------------------------------------------------
final VelocityContext context = new VelocityContext();
context.put("pushAnalysis", pushAnalysis);
context.put("itemHtml", itemHtml);
context.put("itemLink", itemLink);
context.put("encoder", encoder);
// ----------------------------------------------------------------------
// Render template and return result after removing newline characters
// ----------------------------------------------------------------------
StringWriter stringWriter = new StringWriter();
new VelocityManager().getEngine().getTemplate("push-analysis-main-html.vm").merge(context, stringWriter);
log(jobId, NotificationLevel.INFO, "Finished generating PushAnalysis for user '" + user.getUsername() + "'.", false, null);
return stringWriter.toString().replaceAll("\\R", "");
}
use of org.hisp.dhis.dashboard.DashboardItem in project dhis2-core by dhis2.
the class DashboardCascadeSharingTest method testUserGroup.
@Test
void testUserGroup() {
Map mapA = createMap("A");
mapA.setSharing(defaultSharing());
objectManager.save(mapA, false);
Map mapB = createMap("A");
mapB.setSharing(defaultSharing());
objectManager.save(mapB, false);
DashboardItem itemA = createDashboardItem("A");
itemA.setMap(mapA);
DashboardItem itemB = createDashboardItem("B");
itemB.setMap(mapB);
Dashboard dashboard = createDashboard("A", sharingUserGroupA);
dashboard.getItems().add(itemB);
dashboard.getItems().add(itemA);
objectManager.save(dashboard, false);
CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, CascadeSharingParameters.builder().build());
assertEquals(0, report.getErrorReports().size());
assertEquals(1, report.getUpdateObjects().size());
assertTrue(aclService.canRead(userA, mapA));
assertTrue(aclService.canRead(userA, mapB));
}
use of org.hisp.dhis.dashboard.DashboardItem in project dhis2-core by dhis2.
the class DashboardCascadeSharingTest method testAtomicTrue.
@Test
void testAtomicTrue() {
Map mapA = createMap("A");
mapA.setSharing(sharingReadWriteForUserB);
objectManager.save(mapA, false);
assertFalse(aclService.canRead(userA, mapA));
Map mapB = createMap("A");
mapB.setSharing(defaultSharing());
objectManager.save(mapB, false);
DashboardItem itemB = createDashboardItem("B");
itemB.setMap(mapB);
DashboardItem itemA = createDashboardItem("A");
itemA.setMap(mapA);
Dashboard dashboard = createDashboard("A", sharingReadForUserA);
dashboard.getItems().add(itemA);
dashboard.getItems().add(itemB);
objectManager.save(dashboard, false);
assertFalse(aclService.canRead(userA, mapA));
CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, CascadeSharingParameters.builder().atomic(true).user(userB).build());
assertEquals(1, report.getErrorReports().size());
assertEquals(0, report.getUpdateObjects().size());
assertFalse(aclService.canRead(userA, mapA));
assertFalse(aclService.canRead(userA, mapB));
}
use of org.hisp.dhis.dashboard.DashboardItem in project dhis2-core by dhis2.
the class DashboardItemController method putDashboardItemShape.
@PutMapping("/{uid}/shape/{shape}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void putDashboardItemShape(@PathVariable String uid, @PathVariable DashboardItemShape shape, @CurrentUser User currentUser, HttpServletRequest request, HttpServletResponse response) throws Exception {
DashboardItem item = dashboardService.getDashboardItem(uid);
if (item == null) {
throw new WebMessageException(notFound("Dashboard item does not exist: " + uid));
}
Dashboard dashboard = dashboardService.getDashboardFromDashboardItem(item);
if (!aclService.canUpdate(currentUser, dashboard)) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this dashboard.");
}
item.setShape(shape);
dashboardService.updateDashboardItem(item);
}
Aggregations