use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class NotificationServiceTest method testSendNotifications_loadUsersByRoles.
@Test
public void testSendNotifications_loadUsersByRoles() throws NotificationDeliveryFailedException {
TestDataCreator.RDCF rdcf = creator.createRDCF();
Region region = getRegionService().getByReferenceDto(rdcf.region);
UserDto survSup = creator.createUser(rdcf, "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
UserDto caseSup = creator.createUser(rdcf, "Case", "Sup", UserRole.CASE_SUPERVISOR);
Mockito.when(userService.getAllByRegionsAndUserRoles(any(), any())).then(invocation -> {
return getUserService().getAllByRegionsAndUserRoles((List<Region>) invocation.getArgument(0), (UserRole) invocation.getArgument(1), (UserRole) invocation.getArgument(2));
});
Mockito.doAnswer(invocation -> {
Map<User, String> userMessages = (Map<User, String>) invocation.getArgument(0);
assertThat(userMessages.size(), is(2));
assertThat(userMessages.get(getUserService().getByReferenceDto(survSup.toReference())), is("Test message"));
assertThat(userMessages.get(getUserService().getByReferenceDto(caseSup.toReference())), is("Test message"));
return null;
}).when(messagingService).sendEmail(any(), any(), any());
notificationService.sendNotifications(NotificationType.CASE_LAB_RESULT_ARRIVED, Collections.singletonList(region), null, MessageSubject.LAB_RESULT_ARRIVED, "Test message");
Mockito.verify(messagingService, Mockito.times(1)).sendEmail(any(), any(), any());
Mockito.verify(messagingService, Mockito.times(1)).sendSms(any(), any(), any());
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class DirectoryImmunizationService method createUserFilter.
private Predicate createUserFilter(DirectoryImmunizationQueryContext<DirectoryImmunization> qc) {
final User currentUser = userService.getCurrentUser();
final CriteriaBuilder cb = qc.getCriteriaBuilder();
Predicate filter;
if (!featureConfigurationFacade.isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) {
filter = DirectoryImmunizationJurisdictionPredicateValidator.of(qc, currentUser).inJurisdictionOrOwned();
} else {
filter = CriteriaBuilderHelper.or(qc.getCriteriaBuilder(), qc.getCriteriaBuilder().equal(qc.getRoot().get(Immunization.REPORTING_USER), currentUser), PersonJurisdictionPredicateValidator.of(qc.getQuery(), qc.getCriteriaBuilder(), new PersonJoins<>(((DirectoryImmunizationJoins<DirectoryImmunization>) qc.getJoins()).getPerson()), currentUser, false).inJurisdictionOrOwned());
}
if (currentUser.getLimitedDisease() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(qc.getRoot().get(Contact.DISEASE), currentUser.getLimitedDisease()));
}
return filter;
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationFacadeEjb method restorePseudonymizedDto.
protected void restorePseudonymizedDto(ImmunizationDto dto, ImmunizationDto existingDto, Immunization entity, Pseudonymizer pseudonymizer) {
if (existingDto != null) {
final boolean inJurisdiction = service.inJurisdictionOrOwned(entity);
final User currentUser = userService.getCurrentUser();
pseudonymizer.restoreUser(entity.getReportingUser(), currentUser, dto, dto::setReportingUser);
pseudonymizer.restorePseudonymizedValues(ImmunizationDto.class, dto, existingDto, inJurisdiction);
}
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class AbstractInfrastructureFacadeEjb method doSave.
protected DTO doSave(DTO dtoToSave, boolean allowMerge, boolean includeArchived, boolean checkChangeDate, String duplicateErrorMessageProperty) {
if (dtoToSave == null) {
return null;
}
ADO existingEntity = service.getByUuid(dtoToSave.getUuid());
final User currentUser = userService.getCurrentUser();
if (currentUser != null) {
if (existingEntity == null && !userService.hasRight(UserRight.INFRASTRUCTURE_CREATE)) {
throw new UnsupportedOperationException("User " + currentUser.getUuid() + " is not allowed to create infrastructure data.");
}
if (existingEntity != null && !userService.hasRight(UserRight.INFRASTRUCTURE_EDIT)) {
throw new UnsupportedOperationException("User " + currentUser.getUuid() + " is not allowed to edit infrastructure data.");
}
}
if (existingEntity == null) {
List<ADO> duplicates = findDuplicates(dtoToSave, includeArchived);
if (!duplicates.isEmpty()) {
if (allowMerge) {
return mergeAndPersist(dtoToSave, duplicates, checkChangeDate);
} else {
throw new ValidationRuntimeException(I18nProperties.getValidationError(duplicateErrorMessageProperty));
}
}
}
return persistEntity(dtoToSave, existingEntity, checkChangeDate);
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class ExportFacadeEjb method getExportConfigurations.
@Override
public List<ExportConfigurationDto> getExportConfigurations(ExportConfigurationCriteria criteria, boolean isPublic) {
User user = userService.getCurrentUser();
if (user == null) {
return Collections.emptyList();
}
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<ExportConfiguration> cq = cb.createQuery(ExportConfiguration.class);
Root<ExportConfiguration> config = cq.from(ExportConfiguration.class);
Predicate criteriaFilters = buildExportConfigurationCriteriaFilter(criteria, cb, config);
Predicate filters;
if (isPublic) {
filters = CriteriaBuilderHelper.and(cb, criteriaFilters, cb.equal(config.get(ExportConfiguration.SHARED_TO_PUBLIC), true), cb.notEqual(config.get(ExportConfiguration.USER), user));
} else {
filters = CriteriaBuilderHelper.and(cb, criteriaFilters, cb.equal(config.get(ExportConfiguration.USER), user));
}
cq.where(filters);
cq.orderBy(cb.desc(config.get(ExportConfiguration.CHANGE_DATE)));
return em.createQuery(cq).getResultList().stream().map(ExportFacadeEjb::toExportConfigurationDto).collect(Collectors.toList());
}
Aggregations