use of de.symeda.sormas.api.utils.AccessDeniedException in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjb method save.
@RolesAllowed({ UserRight._CONTACT_CREATE, UserRight._CONTACT_EDIT })
public ContactDto save(ContactDto dto, boolean handleChanges, boolean handleCaseChanges, boolean checkChangeDate, boolean internal) {
final Contact existingContact = dto.getUuid() != null ? service.getByUuid(dto.getUuid()) : null;
if (internal && existingContact != null && !service.isContactEditAllowed(existingContact).equals(EditPermissionType.ALLOWED)) {
throw new AccessDeniedException(I18nProperties.getString(Strings.errorContactNotEditable));
}
final ContactDto existingContactDto = toDto(existingContact);
restorePseudonymizedDto(dto, existingContactDto, existingContact, Pseudonymizer.getDefault(userService::hasRight));
validateUserRights(dto, existingContactDto);
validate(dto);
externalJournalService.handleExternalJournalPersonUpdateAsync(dto.getPerson());
// taking this out because it may lead to server problems
// case disease can change over time and there is currently no mechanism that would delete all related contacts
// in this case the best solution is to only keep this hidden from the UI and still allow it in the backend
// if (!DiseaseHelper.hasContactFollowUp(entity.getCaze().getDisease(), entity.getCaze().getPlagueType())) {
// throw new UnsupportedOperationException("Contact creation is not allowed for diseases that don't have contact follow-up.");
// }
Contact entity = fillOrBuildEntity(dto, existingContact, checkChangeDate);
service.ensurePersisted(entity);
if (existingContact == null && featureConfigurationFacade.isTaskGenerationFeatureEnabled(TaskType.CONTACT_INVESTIGATION)) {
createInvestigationTask(entity);
}
if (handleChanges) {
entity.setCompleteness(calculateCompleteness(entity));
updateContactVisitAssociations(existingContactDto, entity);
final boolean convertedToCase = (existingContactDto == null || existingContactDto.getResultingCase() == null) && entity.getResultingCase() != null;
final boolean dropped = entity.getContactStatus() == ContactStatus.DROPPED && (existingContactDto == null || existingContactDto.getContactStatus() != ContactStatus.DROPPED);
if (dropped || convertedToCase) {
service.cancelFollowUp(entity, I18nProperties.getString(convertedToCase ? Strings.messageSystemFollowUpCanceled : Strings.messageSystemFollowUpCanceledByDropping));
} else {
service.updateFollowUpDetails(entity, existingContactDto != null && entity.getFollowUpStatus() != existingContactDto.getFollowUpStatus());
}
service.udpateContactStatus(entity);
if (handleCaseChanges && entity.getCaze() != null) {
caseFacade.onCaseChanged(caseFacade.toDto(entity.getCaze()), entity.getCaze(), internal);
}
onContactChanged(existingContactDto, entity, internal);
}
return toDto(entity);
}
use of de.symeda.sormas.api.utils.AccessDeniedException in project SORMAS-Project by hzi-braunschweig.
the class EventFacadeEjb method save.
@RolesAllowed({ UserRight._EVENT_CREATE, UserRight._EVENT_EDIT })
public EventDto save(@NotNull EventDto dto, boolean checkChangeDate, boolean internal) {
Event existingEvent = dto.getUuid() != null ? service.getByUuid(dto.getUuid()) : null;
if (internal && existingEvent != null && !service.isEventEditAllowed(existingEvent).equals(EditPermissionType.ALLOWED)) {
throw new AccessDeniedException(I18nProperties.getString(Strings.errorEventNotEditable));
}
EventDto existingDto = toDto(existingEvent);
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
restorePseudonymizedDto(dto, existingDto, existingEvent, pseudonymizer);
if (dto.getReportDateTime() == null) {
throw new ValidationRuntimeException(I18nProperties.getValidationError(Validations.validReportDateTime));
}
Event event = fillOrBuildEntity(dto, existingEvent, checkChangeDate);
service.ensurePersisted(event);
onEventChange(toDto(event), internal);
return convertToDto(event, pseudonymizer);
}
use of de.symeda.sormas.api.utils.AccessDeniedException in project SORMAS-Project by hzi-braunschweig.
the class AbstractCoreFacadeEjb method doSave.
@DenyAll
public DTO doSave(@Valid @NotNull DTO dto) {
ADO existingAdo = dto.getUuid() != null ? service.getByUuid(dto.getUuid()) : null;
if (existingAdo != null && !service.getEditPermissionType(existingAdo).equals(EditPermissionType.ALLOWED)) {
throw new AccessDeniedException(I18nProperties.getString(Strings.errorEntityNotEditable));
}
DTO existingDto = toDto(existingAdo);
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
restorePseudonymizedDto(dto, existingDto, existingAdo, pseudonymizer);
validate(dto);
existingAdo = fillOrBuildEntity(dto, existingAdo, true);
service.ensurePersisted(existingAdo);
return convertToDto(existingAdo, pseudonymizer);
}
use of de.symeda.sormas.api.utils.AccessDeniedException in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationFacadeEjb method save.
@RolesAllowed({ UserRight._IMMUNIZATION_CREATE, UserRight._IMMUNIZATION_EDIT })
public ImmunizationDto save(@Valid @NotNull ImmunizationDto dto, boolean checkChangeDate, boolean internal) {
Immunization existingImmunization = service.getByUuid(dto.getUuid());
if (internal && existingImmunization != null && !service.isImmunizationEditAllowed(existingImmunization).equals(EditPermissionType.ALLOWED)) {
throw new AccessDeniedException(I18nProperties.getString(Strings.errorImmunizationNotEditable));
}
ImmunizationDto existingDto = toDto(existingImmunization);
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
restorePseudonymizedDto(dto, existingDto, existingImmunization, pseudonymizer);
validate(dto);
Immunization immunization = fillOrBuildEntity(dto, existingImmunization, checkChangeDate);
service.updateImmunizationStatusBasedOnVaccinations(immunization);
immunization.getVaccinations().forEach(vaccination -> {
VaccinationDto existingVaccination = null;
if (existingDto != null) {
existingVaccination = existingDto.getVaccinations().stream().filter(vaccinationDto -> vaccination.getUuid().equals(vaccinationDto.getUuid())).findAny().orElse(null);
}
Date oldVaccinationDate = existingVaccination != null ? existingVaccination.getVaccinationDate() : null;
vaccinationFacade.updateVaccinationStatuses(vaccination.getVaccinationDate(), oldVaccinationDate, immunization.getPerson().getId(), immunization.getDisease());
});
service.ensurePersisted(immunization);
if (existingImmunization != null && internal && sormasToSormasFacade.isFeatureConfigured()) {
syncSharesAsync(existingImmunization);
}
return convertToDto(immunization, pseudonymizer);
}
use of de.symeda.sormas.api.utils.AccessDeniedException in project SORMAS-Project by hzi-braunschweig.
the class SampleFacadeEjb method saveSample.
@RolesAllowed({ UserRight._SAMPLE_CREATE, UserRight._SAMPLE_EDIT })
public SampleDto saveSample(@Valid SampleDto dto, boolean handleChanges, boolean checkChangeDate, boolean internal) {
Sample existingSample = sampleService.getByUuid(dto.getUuid());
if (internal && existingSample != null && !sampleService.isSampleEditAllowed(existingSample)) {
throw new AccessDeniedException(I18nProperties.getString(Strings.errorSampleNotEditable));
}
SampleDto existingSampleDto = toDto(existingSample);
restorePseudonymizedDto(dto, existingSample, existingSampleDto);
Sample sample = fromDto(dto, checkChangeDate);
// Set defaults for testing requests
if (sample.getPathogenTestingRequested() == null) {
sample.setPathogenTestingRequested(false);
}
if (sample.getAdditionalTestingRequested() == null) {
sample.setAdditionalTestingRequested(false);
}
sampleService.ensurePersisted(sample);
if (handleChanges) {
onSampleChanged(existingSampleDto, sample, internal);
}
return toDto(sample);
}
Aggregations