Search in sources :

Example 6 with WebMessageException

use of org.hisp.dhis.dxf2.webmessage.WebMessageException 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 7 with WebMessageException

use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.

the class DataApprovalController method removeApproval.

// -------------------------------------------------------------------------
// Delete
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')")
@RequestMapping(value = APPROVALS_PATH, method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void removeApproval(@RequestParam Set<String> ds, @RequestParam String pe, @RequestParam String ou, HttpServletResponse response) throws WebMessageException {
    Set<DataSet> dataSets = parseDataSetsWithWorkflow(ds);
    if (dataSets.size() != ds.size()) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier in this list: " + ds));
    }
    Period period = getAndValidatePeriod(pe);
    OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
    DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
    User user = currentUserService.getCurrentUser();
    List<DataApproval> dataApprovalList = newArrayList();
    for (DataSet dataSet : dataSets) {
        dataApprovalList.addAll(getApprovalsAsList(dataApprovalLevel, dataSet.getWorkflow(), period, organisationUnit, false, new Date(), user));
    }
    dataApprovalService.unapproveData(dataApprovalList);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) DataApproval(org.hisp.dhis.dataapproval.DataApproval) User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Period(org.hisp.dhis.period.Period) Date(java.util.Date) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with WebMessageException

use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method registerCompleteDataSet.

private CompleteDataSetRegistration registerCompleteDataSet(DataSet dataSet, Period period, OrganisationUnit orgUnit, DataElementCategoryOptionCombo attributeOptionCombo, String storedBy, Date completionDate) throws WebMessageException {
    I18nFormat format = i18nManager.getI18nFormat();
    if (dataSet == null) {
        throw new WebMessageException(WebMessageUtils.conflict("dataSet can not be null."));
    }
    if (period == null) {
        throw new WebMessageException(WebMessageUtils.conflict("period can not be null"));
    }
    if (orgUnit == null) {
        throw new WebMessageException(WebMessageUtils.conflict("organisationUnit can not be null"));
    }
    if (attributeOptionCombo == null) {
        throw new WebMessageException(WebMessageUtils.conflict("attributeOptionCombo can not be null"));
    }
    CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, orgUnit, attributeOptionCombo);
    if (registration == null) {
        registration = new CompleteDataSetRegistration();
        registration.setDataSet(dataSet);
        registration.setPeriod(period);
        registration.setSource(orgUnit);
        registration.setAttributeOptionCombo(attributeOptionCombo);
        registration.setDate(completionDate != null ? completionDate : new Date());
        registration.setStoredBy(storedBy != null ? storedBy : currentUserService.getCurrentUsername());
        registration.setPeriodName(format.formatPeriod(registration.getPeriod()));
        registrationService.saveCompleteDataSetRegistration(registration);
    } else {
        registration.setDate(completionDate != null ? completionDate : new Date());
        registration.setStoredBy(storedBy != null ? storedBy : currentUserService.getCurrentUsername());
        registration.setPeriodName(format.formatPeriod(registration.getPeriod()));
        registrationService.updateCompleteDataSetRegistration(registration);
    }
    return registration;
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) I18nFormat(org.hisp.dhis.i18n.I18nFormat) Date(java.util.Date)

Example 9 with WebMessageException

use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method saveCompleteDataSetRegistration.

// Legacy (<= V25)
@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.POST, produces = "text/plain")
public void saveCompleteDataSetRegistration(@RequestParam String ds, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam(required = false) Date cd, @RequestParam(required = false) String sb, @RequestParam(required = false) boolean multiOu, HttpServletResponse response) throws WebMessageException {
    DataSet dataSet = dataSetService.getDataSet(ds);
    if (dataSet == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier: " + ds));
    }
    Period period = PeriodType.getPeriodFromIsoString(pe);
    if (period == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
    }
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
    if (organisationUnit == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal organisation unit identifier: " + ou));
    }
    DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
    if (attributeOptionCombo == null) {
        return;
    }
    if (dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null, multiOu)) {
        throw new WebMessageException(WebMessageUtils.conflict("Data set is locked: " + ds));
    }
    // ---------------------------------------------------------------------
    // Register as completed data set
    // ---------------------------------------------------------------------
    Set<OrganisationUnit> children = organisationUnit.getChildren();
    String storedBy = (sb == null) ? currentUserService.getCurrentUsername() : sb;
    Date completionDate = (cd == null) ? new Date() : cd;
    List<CompleteDataSetRegistration> registrations = new ArrayList<>();
    if (!multiOu) {
        CompleteDataSetRegistration completeDataSetRegistration = registerCompleteDataSet(dataSet, period, organisationUnit, attributeOptionCombo, storedBy, completionDate);
        if (completeDataSetRegistration != null) {
            registrations.add(completeDataSetRegistration);
        }
    } else {
        addRegistrationsForOrgUnits(registrations, Sets.union(children, Sets.newHashSet(organisationUnit)), dataSet, period, attributeOptionCombo, storedBy, completionDate);
    }
    registrationService.saveCompleteDataSetRegistrations(registrations, true);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Date(java.util.Date) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with WebMessageException

use of org.hisp.dhis.dxf2.webmessage.WebMessageException in project dhis2-core by dhis2.

the class DataSetController method bumpVersion.

@RequestMapping(value = "/{uid}/version", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void bumpVersion(@PathVariable("uid") String uid) throws Exception {
    DataSet dataSet = manager.get(DataSet.class, uid);
    if (dataSet == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Data set does not exist: " + uid));
    }
    dataSet.increaseVersion();
    dataSetService.updateDataSet(dataSet);
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)134 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)118 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)31 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)28 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)27 DataSet (org.hisp.dhis.dataset.DataSet)21 Period (org.hisp.dhis.period.Period)21 User (org.hisp.dhis.user.User)20 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)18 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)15 ArrayList (java.util.ArrayList)14 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)14 Interpretation (org.hisp.dhis.interpretation.Interpretation)13 Date (java.util.Date)9 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)9 InputStream (java.io.InputStream)8 Grid (org.hisp.dhis.common.Grid)8 Event (org.hisp.dhis.dxf2.events.event.Event)8 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)8 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)8