use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class CaseService method createUserFilter.
@SuppressWarnings("rawtypes")
public Predicate createUserFilter(CriteriaBuilder cb, CriteriaQuery cq, From<?, Case> casePath, CaseUserFilterCriteria userFilterCriteria) {
User currentUser = getCurrentUser();
if (currentUser == null) {
return null;
}
Predicate filterResponsible = null;
Predicate filter = null;
final JurisdictionLevel jurisdictionLevel = currentUser.getCalculatedJurisdictionLevel();
if (jurisdictionLevel != JurisdictionLevel.NATION && !currentUser.hasAnyUserRole(UserRole.REST_USER, UserRole.REST_EXTERNAL_VISITS_USER)) {
// whoever created the case or is assigned to it is allowed to access it
if (userFilterCriteria == null || (userFilterCriteria.getIncludeCasesFromOtherJurisdictions())) {
filterResponsible = cb.equal(casePath.get(Case.REPORTING_USER).get(User.ID), currentUser.getId());
filterResponsible = cb.or(filterResponsible, cb.equal(casePath.get(Case.SURVEILLANCE_OFFICER).get(User.ID), currentUser.getId()));
filterResponsible = cb.or(filterResponsible, cb.equal(casePath.get(Case.CASE_OFFICER).get(User.ID), currentUser.getId()));
}
switch(jurisdictionLevel) {
case REGION:
final Region region = currentUser.getRegion();
if (region != null) {
filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(casePath.get(Case.REGION).get(Region.ID), region.getId()), cb.equal(casePath.get(Case.RESPONSIBLE_REGION).get(Region.ID), region.getId()));
}
break;
case DISTRICT:
final District district = currentUser.getDistrict();
if (district != null) {
filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(casePath.get(Case.DISTRICT).get(District.ID), district.getId()), cb.equal(casePath.get(Case.RESPONSIBLE_DISTRICT).get(District.ID), district.getId()));
}
break;
case HEALTH_FACILITY:
final Facility healthFacility = currentUser.getHealthFacility();
if (healthFacility != null) {
filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(casePath.get(Case.HEALTH_FACILITY).get(Facility.ID), healthFacility.getId()));
}
break;
case COMMUNITY:
final Community community = currentUser.getCommunity();
if (community != null) {
filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(casePath.get(Case.COMMUNITY).get(Community.ID), community.getId()), cb.equal(casePath.get(Case.RESPONSIBLE_COMMUNITY).get(Community.ID), community.getId()));
}
break;
case POINT_OF_ENTRY:
final PointOfEntry pointOfEntry = currentUser.getPointOfEntry();
if (pointOfEntry != null) {
filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(casePath.get(Case.POINT_OF_ENTRY).get(PointOfEntry.ID), pointOfEntry.getId()));
}
break;
case LABORATORY:
final Subquery<Long> sampleSubQuery = cq.subquery(Long.class);
final Root<Sample> sampleRoot = sampleSubQuery.from(Sample.class);
final SampleJoins joins = new SampleJoins(sampleRoot);
final Join cazeJoin = joins.getCaze();
sampleSubQuery.where(cb.and(cb.equal(cazeJoin, casePath), sampleService.createUserFilterWithoutAssociations(cb, joins)));
sampleSubQuery.select(sampleRoot.get(Sample.ID));
filter = CriteriaBuilderHelper.or(cb, filter, cb.exists(sampleSubQuery));
break;
default:
}
// get all cases based on the user's contact association
if (userFilterCriteria == null || (!userFilterCriteria.isExcludeCasesFromContacts() && Boolean.TRUE.equals(userFilterCriteria.getIncludeCasesFromOtherJurisdictions()))) {
filter = CriteriaBuilderHelper.or(cb, filter, contactService.createUserFilterWithoutCase(new ContactQueryContext(cb, cq, casePath.join(Case.CONTACTS, JoinType.LEFT))));
}
// all users (without specific restrictions) get access to cases that have been made available to the whole country
if ((userFilterCriteria == null || userFilterCriteria.getIncludeCasesFromOtherJurisdictions()) && !featureConfigurationFacade.isFeatureDisabled(FeatureType.NATIONAL_CASE_SHARING)) {
filter = CriteriaBuilderHelper.or(cb, filter, cb.isTrue(casePath.get(Case.SHARED_TO_COUNTRY)));
}
}
// only show cases of a specific disease if a limited disease is set
if (currentUser.getLimitedDisease() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(casePath.get(Case.DISEASE), currentUser.getLimitedDisease()));
}
// port health users can only see port health cases
if (UserRole.isPortHealthUser(currentUser.getUserRoles())) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(casePath.get(Case.CASE_ORIGIN), CaseOrigin.POINT_OF_ENTRY));
}
filter = CriteriaBuilderHelper.or(cb, filter, filterResponsible);
return filter;
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class SurveillanceReportFacadeEjb method getIndexList.
@Override
public List<SurveillanceReportDto> getIndexList(SurveillanceReportCriteria criteria, Integer first, Integer max) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SurveillanceReport> cq = cb.createQuery(SurveillanceReport.class);
Root<SurveillanceReport> root = cq.from(SurveillanceReport.class);
Predicate filter = service.buildCriteriaFilter(criteria, cb, root);
if (filter != null) {
cq.where(filter);
}
cq.orderBy(cb.desc(root.get(SurveillanceReport.CREATION_DATE)));
List<SurveillanceReport> resultList = QueryHelper.getResultList(em, cq, first, max);
List<SurveillanceReportDto> reports = resultList.stream().map(SurveillanceReportFacadeEjb::toDto).collect(Collectors.toList());
User currentUser = userService.getCurrentUser();
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
pseudonymizer.pseudonymizeDtoCollection(SurveillanceReportDto.class, reports, reportDto -> {
Optional<SurveillanceReport> report = resultList.stream().filter(r -> r.getUuid().equals(r.getUuid())).findFirst();
return report.isPresent() ? caseService.inJurisdictionOrOwned(report.get().getCaze()) : false;
}, (reportDto, inJurisdiction) -> {
Optional<SurveillanceReport> report = resultList.stream().filter(r -> r.getUuid().equals(r.getUuid())).findFirst();
report.ifPresent(surveillanceReport -> pseudonymizer.pseudonymizeUser(surveillanceReport.getCreatingUser(), currentUser, reportDto::setCreatingUser));
});
return reports;
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class SurveillanceReportFacadeEjb method restorePseudonymizedDto.
private void restorePseudonymizedDto(SurveillanceReportDto dto, SurveillanceReport existingReport, SurveillanceReportDto existingDto) {
if (existingDto != null) {
boolean inJurisdiction = caseService.inJurisdictionOrOwned(existingReport.getCaze());
User currentUser = userService.getCurrentUser();
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
pseudonymizer.restoreUser(existingReport.getCreatingUser(), currentUser, dto, dto::setCreatingUser);
pseudonymizer.restorePseudonymizedValues(SurveillanceReportDto.class, dto, existingDto, inJurisdiction);
}
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class NotificationServiceTest method testSendNotifications_filterUserMessagesByroles.
@Test
public void testSendNotifications_filterUserMessagesByroles() throws NotificationDeliveryFailedException {
TestDataCreator.RDCF rdcf = creator.createRDCF();
UserDto survSup = creator.createUser(rdcf, "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
UserDto caseSup = creator.createUser(rdcf, "Case", "Sup", UserRole.CASE_SUPERVISOR);
UserDto contSup = creator.createUser(rdcf, "Cont", "Sup", UserRole.CONTACT_SUPERVISOR);
User survSupUser = getUserService().getByReferenceDto(survSup.toReference());
User survOffUser = getUserService().getByReferenceDto(caseSup.toReference());
User contSupUser = getUserService().getByReferenceDto(contSup.toReference());
Mockito.doAnswer(invocation -> {
Map<User, String> userMessages = (Map<User, String>) invocation.getArgument(0);
assertThat(userMessages.size(), is(2));
assertThat(userMessages.get(survSupUser), is("Test message SS"));
assertThat(userMessages.get(survOffUser), is("Test message SO"));
return null;
}).when(messagingService).sendEmail(any(), any(), any());
notificationService.sendNotifications(NotificationType.CASE_LAB_RESULT_ARRIVED, MessageSubject.LAB_RESULT_ARRIVED, () -> {
Map<User, String> userMessages = new HashMap<>();
userMessages.put(survOffUser, "Test message SO");
userMessages.put(survSupUser, "Test message SS");
userMessages.put(contSupUser, "Test message CS");
return userMessages;
});
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 NotificationServiceTest method testSendNotifications_additionalUsers.
@Test
public void testSendNotifications_additionalUsers() 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);
User caseSupUser = getUserService().getByReferenceDto(caseSup.toReference());
Mockito.when(userService.getAllByRegionsAndUserRoles(any(), any())).then(invocation -> {
// load only for SURVEILLANCE_SUPERVISOR, so the additional CASE_SUPERVISOR user will be added in the notification service
return getUserService().getAllByRegionsAndUserRoles((List<Region>) invocation.getArgument(0), UserRole.SURVEILLANCE_SUPERVISOR);
});
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.VISIT_COMPLETED, Collections.singletonList(region), Collections.singletonList(caseSupUser), MessageSubject.VISIT_COMPLETED, "Test message");
Mockito.verify(messagingService, Mockito.times(1)).sendEmail(any(), any(), any());
Mockito.verify(messagingService, Mockito.times(1)).sendSms(any(), any(), any());
}
Aggregations