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