Search in sources :

Example 1 with NotFoundException

use of org.hisp.dhis.webapi.controller.exception.NotFoundException in project dhis2-core by dhis2.

the class ConfigurationController method setInfrastructuralDataElements.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@PostMapping("/infrastructuralDataElements")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setInfrastructuralDataElements(@RequestBody String uid) throws NotFoundException {
    uid = trim(uid);
    DataElementGroup group = identifiableObjectManager.get(DataElementGroup.class, uid);
    if (group == null) {
        throw new NotFoundException("Data element group", uid);
    }
    Configuration configuration = configurationService.getConfiguration();
    configuration.setInfrastructuralDataElements(group);
    configurationService.setConfiguration(configuration);
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with NotFoundException

use of org.hisp.dhis.webapi.controller.exception.NotFoundException in project dhis2-core by dhis2.

the class ConfigurationController method setSelfRegistrationRole.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@PostMapping("/selfRegistrationRole")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setSelfRegistrationRole(@RequestBody String uid) throws NotFoundException {
    uid = trim(uid);
    UserAuthorityGroup userGroup = identifiableObjectManager.get(UserAuthorityGroup.class, uid);
    if (userGroup == null) {
        throw new NotFoundException("User authority group", uid);
    }
    Configuration configuration = configurationService.getConfiguration();
    configuration.setSelfRegistrationRole(userGroup);
    configurationService.setConfiguration(configuration);
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with NotFoundException

use of org.hisp.dhis.webapi.controller.exception.NotFoundException in project dhis2-core by dhis2.

the class ConfigurationController method setFeedbackRecipients.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@PostMapping("/feedbackRecipients")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setFeedbackRecipients(@RequestBody String uid) throws NotFoundException {
    uid = trim(uid);
    UserGroup group = identifiableObjectManager.get(UserGroup.class, uid);
    if (group == null) {
        throw new NotFoundException("User group", uid);
    }
    Configuration configuration = configurationService.getConfiguration();
    configuration.setFeedbackRecipients(group);
    configurationService.setConfiguration(configuration);
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) UserGroup(org.hisp.dhis.user.UserGroup) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with NotFoundException

use of org.hisp.dhis.webapi.controller.exception.NotFoundException in project dhis2-core by dhis2.

the class ConfigurationController method setFacilityOrgUnitGroupSet.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@PostMapping("/facilityOrgUnitGroupSet")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setFacilityOrgUnitGroupSet(@RequestBody String uid) throws NotFoundException {
    uid = trim(uid);
    OrganisationUnitGroupSet groupSet = identifiableObjectManager.get(OrganisationUnitGroupSet.class, uid);
    if (groupSet == null) {
        throw new NotFoundException("Organisation unit group sets", uid);
    }
    Configuration configuration = configurationService.getConfiguration();
    configuration.setFacilityOrgUnitGroupSet(groupSet);
    configurationService.setConfiguration(configuration);
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with NotFoundException

use of org.hisp.dhis.webapi.controller.exception.NotFoundException in project dhis2-core by dhis2.

the class TrackedEntityInstanceSupportService method getTrackedEntityInstance.

@SneakyThrows
public TrackedEntityInstance getTrackedEntityInstance(String id, String pr, List<String> fields) {
    User user = currentUserService.getCurrentUser();
    TrackedEntityInstanceParams trackedEntityInstanceParams = getTrackedEntityInstanceParams(fields);
    TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(id, trackedEntityInstanceParams);
    if (trackedEntityInstance == null) {
        throw new NotFoundException("TrackedEntityInstance", id);
    }
    if (pr != null) {
        Program program = programService.getProgram(pr);
        if (program == null) {
            throw new NotFoundException("Program", pr);
        }
        List<String> errors = trackerAccessManager.canRead(user, instanceService.getTrackedEntityInstance(trackedEntityInstance.getTrackedEntityInstance()), program, false);
        if (!errors.isEmpty()) {
            if (program.getAccessLevel() == AccessLevel.CLOSED) {
                throw new WebMessageException(unauthorized(TrackerOwnershipManager.PROGRAM_ACCESS_CLOSED));
            }
            throw new WebMessageException(unauthorized(TrackerOwnershipManager.OWNERSHIP_ACCESS_DENIED));
        }
        if (trackedEntityInstanceParams.isIncludeProgramOwners()) {
            List<ProgramOwner> filteredProgramOwners = trackedEntityInstance.getProgramOwners().stream().filter(tei -> tei.getProgram().equals(pr)).collect(Collectors.toList());
            trackedEntityInstance.setProgramOwners(filteredProgramOwners);
        }
    } else {
        // return only tracked entity type attributes
        TrackedEntityType trackedEntityType = trackedEntityTypeService.getTrackedEntityType(trackedEntityInstance.getTrackedEntityType());
        if (trackedEntityType != null) {
            List<String> tetAttributes = trackedEntityType.getTrackedEntityAttributes().stream().map(TrackedEntityAttribute::getUid).collect(Collectors.toList());
            trackedEntityInstance.setAttributes(trackedEntityInstance.getAttributes().stream().filter(att -> tetAttributes.contains(att.getAttribute())).collect(Collectors.toList()));
        }
    }
    return trackedEntityInstance;
}
Also used : ProgramOwner(org.hisp.dhis.dxf2.events.trackedentity.ProgramOwner) TrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService) TrackedEntityTypeService(org.hisp.dhis.trackedentity.TrackedEntityTypeService) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) SneakyThrows(lombok.SneakyThrows) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) RequiredArgsConstructor(lombok.RequiredArgsConstructor) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) Collectors(java.util.stream.Collectors) Program(org.hisp.dhis.program.Program) TrackerOwnershipManager(org.hisp.dhis.trackedentity.TrackerOwnershipManager) List(java.util.List) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Service(org.springframework.stereotype.Service) ProgramOwner(org.hisp.dhis.dxf2.events.trackedentity.ProgramOwner) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) User(org.hisp.dhis.user.User) ProgramService(org.hisp.dhis.program.ProgramService) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) WebMessageUtils.unauthorized(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.unauthorized) AccessLevel(org.hisp.dhis.common.AccessLevel) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Joiner(com.google.common.base.Joiner) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) SneakyThrows(lombok.SneakyThrows)

Aggregations

NotFoundException (org.hisp.dhis.webapi.controller.exception.NotFoundException)16 PostMapping (org.springframework.web.bind.annotation.PostMapping)11 Configuration (org.hisp.dhis.configuration.Configuration)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)10 PotentialDuplicate (org.hisp.dhis.deduplication.PotentialDuplicate)4 PotentialDuplicateConflictException (org.hisp.dhis.deduplication.PotentialDuplicateConflictException)4 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)4 ConflictException (org.hisp.dhis.webapi.controller.exception.ConflictException)4 OperationNotAllowedException (org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException)4 Test (org.junit.jupiter.api.Test)4 List (java.util.List)2 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)2 User (org.hisp.dhis.user.User)2 UserGroup (org.hisp.dhis.user.UserGroup)2 Joiner (com.google.common.base.Joiner)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Deque (java.util.Deque)1