Search in sources :

Example 71 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.

the class ConfigurationController method setInfrastructuralIndicators.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@RequestMapping(value = "/infrastructuralIndicators", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setInfrastructuralIndicators(@RequestBody String uid) throws NotFoundException {
    IndicatorGroup group = identifiableObjectManager.get(IndicatorGroup.class, uid);
    if (group == null) {
        throw new NotFoundException("Indicator group", uid);
    }
    Configuration config = configurationService.getConfiguration();
    config.setInfrastructuralIndicators(group);
    configurationService.setConfiguration(config);
}
Also used : IndicatorGroup(org.hisp.dhis.indicator.IndicatorGroup) Configuration(org.hisp.dhis.configuration.Configuration) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 72 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.

the class ConfigurationController method setInfrastructuralPeriodType.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@RequestMapping(value = "/infrastructuralPeriodType", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setInfrastructuralPeriodType(@RequestBody String name) throws NotFoundException {
    PeriodType periodType = PeriodType.getPeriodTypeByName(name);
    if (periodType == null) {
        throw new NotFoundException("Period type", name);
    }
    Configuration config = configurationService.getConfiguration();
    periodType = periodService.reloadPeriodType(periodType);
    config.setInfrastructuralPeriodType(periodType);
    configurationService.setConfiguration(config);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Configuration(org.hisp.dhis.configuration.Configuration) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 73 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.

the class ConfigurationController method setOfflineOrganisationUnitLevel.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@RequestMapping(value = "/offlineOrganisationUnitLevel", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setOfflineOrganisationUnitLevel(@RequestBody String uid) throws NotFoundException {
    OrganisationUnitLevel organisationUnitLevel = identifiableObjectManager.get(OrganisationUnitLevel.class, uid);
    if (organisationUnitLevel == null) {
        throw new NotFoundException("Organisation unit level", uid);
    }
    Configuration config = configurationService.getConfiguration();
    config.setOfflineOrganisationUnitLevel(organisationUnitLevel);
    configurationService.setConfiguration(config);
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 74 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method saveCompleteDataSetRegistration.

@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", value = MULTIPLE_SAVE_RESOURCE_PATH)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void saveCompleteDataSetRegistration(@RequestBody CompleteDataSetRegistrationRequests completeDataSetRegistrationRequests, HttpServletResponse response) throws WebMessageException {
    List<CompleteDataSetRegistration> registrations = new ArrayList<>();
    for (CompleteDataSetRegistrationRequest completeDataSetRegistrationRequest : completeDataSetRegistrationRequests) {
        String ds = completeDataSetRegistrationRequest.getDs();
        DataSet dataSet = dataSetService.getDataSet(ds);
        if (dataSet == null) {
            throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier: " + ds));
        }
        String pe = completeDataSetRegistrationRequest.getPe();
        Period period = PeriodType.getPeriodFromIsoString(pe);
        if (period == null) {
            throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
        }
        String ou = completeDataSetRegistrationRequest.getOu();
        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
        if (organisationUnit == null) {
            throw new WebMessageException(WebMessageUtils.conflict("Illegal organisation unit identifier: " + ou));
        }
        String cc = completeDataSetRegistrationRequest.getCc();
        String cp = completeDataSetRegistrationRequest.getCp();
        DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
        if (attributeOptionCombo == null) {
            return;
        }
        // ---------------------------------------------------------------------
        // Check locked status
        // ---------------------------------------------------------------------
        boolean multiOu = completeDataSetRegistrationRequest.isMultiOu();
        if (dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null, multiOu)) {
            throw new WebMessageException(WebMessageUtils.conflict("Data set is locked: " + ds));
        }
        // ---------------------------------------------------------------------
        // Register as completed data set
        // ---------------------------------------------------------------------
        String sb = completeDataSetRegistrationRequest.getSb();
        String storedBy = (sb == null) ? currentUserService.getCurrentUsername() : sb;
        Date cd = completeDataSetRegistrationRequest.getCd();
        Date completionDate = (cd == null) ? new Date() : cd;
        Set<OrganisationUnit> orgUnits = new HashSet<>();
        orgUnits.add(organisationUnit);
        if (multiOu) {
            orgUnits.addAll(organisationUnit.getChildren());
        }
        addRegistrationsForOrgUnits(registrations, orgUnits, 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) CompleteDataSetRegistrationRequest(org.hisp.dhis.datacompletion.CompleteDataSetRegistrationRequest) Date(java.util.Date) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) HashSet(java.util.HashSet) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 75 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project dhis2-core by dhis2.

the class ConfigurationController method removeSelfRegistrationOrgUnit.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@RequestMapping(value = "/selfRegistrationOrgUnit", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void removeSelfRegistrationOrgUnit() {
    Configuration config = configurationService.getConfiguration();
    config.setSelfRegistrationOrgUnit(null);
    configurationService.setConfiguration(config);
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)149 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)118 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)36 ApiOperation (io.swagger.annotations.ApiOperation)31 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)26 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)19 GetMapping (org.springframework.web.bind.annotation.GetMapping)18 ApiResponses (io.swagger.annotations.ApiResponses)14 User (org.hisp.dhis.user.User)14 Transactional (org.springframework.transaction.annotation.Transactional)14 Date (java.util.Date)13 Configuration (org.hisp.dhis.configuration.Configuration)12 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 Period (org.hisp.dhis.period.Period)11 ArrayList (java.util.ArrayList)10 QualifiedName (com.netflix.metacat.common.QualifiedName)9 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)9 ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)9 Calendar (java.util.Calendar)9 Task (org.flowable.engine.task.Task)8