use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class SampleFacadeEjb method restorePseudonymizedDto.
private void restorePseudonymizedDto(SampleDto dto, Sample existingSample, SampleDto existingSampleDto) {
if (existingSampleDto != null) {
boolean inJurisdiction = sampleService.inJurisdictionOrOwned(existingSample).getInJurisdiction();
User currentUser = userService.getCurrentUser();
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
pseudonymizer.restoreUser(existingSample.getReportingUser(), currentUser, dto, dto::setReportingUser);
pseudonymizer.restorePseudonymizedValues(SampleDto.class, dto, existingSampleDto, inJurisdiction);
}
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class SampleFacadeEjb method deleteSamples.
public List<String> deleteSamples(List<String> sampleUuids) {
User user = userService.getCurrentUser();
if (!userRoleConfigFacade.getEffectiveUserRights(user.getUserRoles().toArray(new UserRole[user.getUserRoles().size()])).contains(UserRight.SAMPLE_DELETE)) {
throw new UnsupportedOperationException("User " + user.getUuid() + " is not allowed to delete samples.");
}
List<String> deletedSampleUuids = new ArrayList<>();
List<Sample> samplesToBeDeleted = sampleService.getByUuids(sampleUuids);
if (samplesToBeDeleted != null) {
samplesToBeDeleted.forEach(sampleToBeDeleted -> {
if (!sampleToBeDeleted.isDeleted()) {
sampleService.delete(sampleToBeDeleted);
deletedSampleUuids.add(sampleToBeDeleted.getUuid());
}
});
}
return deletedSampleUuids;
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class PersonService method getAllAfter.
@Override
public // todo refactor this to use the create user filter form persons
List<Person> getAllAfter(Date date, Integer batchSize, String lastSynchronizedUuid) {
User user = getCurrentUser();
CriteriaBuilder cb = em.getCriteriaBuilder();
// persons by LGA
CriteriaQuery<Person> personsQuery = cb.createQuery(Person.class);
Root<Person> personsRoot = personsQuery.from(Person.class);
Join<Person, Location> address = personsRoot.join(Person.ADDRESS);
Predicate lgaFilter = cb.equal(address.get(Location.DISTRICT), user.getDistrict());
// date range
if (date != null) {
Predicate dateFilter = createChangeDateFilter(cb, personsRoot, DateHelper.toTimestampUpper(date), lastSynchronizedUuid);
lgaFilter = cb.and(lgaFilter, dateFilter);
}
personsQuery.where(lgaFilter);
List<Person> lgaResultList = getBatchedQueryResults(cb, personsQuery, personsRoot, batchSize);
// persons by case
CriteriaQuery<Person> casePersonsQuery = cb.createQuery(Person.class);
Root<Case> casePersonsRoot = casePersonsQuery.from(Case.class);
Join<Person, Person> casePersonsSelect = casePersonsRoot.join(Case.PERSON);
casePersonsSelect.fetch(Person.ADDRESS);
casePersonsQuery.select(casePersonsSelect);
Predicate casePersonsFilter = caseService.createUserFilter(cb, casePersonsQuery, casePersonsRoot);
// date range
if (date != null) {
Predicate dateFilter = createChangeDateFilter(cb, casePersonsSelect, DateHelper.toTimestampUpper(date), lastSynchronizedUuid);
if (batchSize == null) {
// include case change dates: When a case is relocated it may become available to another user and this will have to include the person as-well
Predicate caseDateFilter = caseService.createChangeDateFilter(cb, casePersonsRoot, DateHelper.toTimestampUpper(date));
dateFilter = cb.or(dateFilter, caseDateFilter);
}
if (casePersonsFilter != null) {
casePersonsFilter = cb.and(casePersonsFilter, dateFilter);
} else {
casePersonsFilter = dateFilter;
}
}
if (casePersonsFilter != null) {
casePersonsQuery.where(casePersonsFilter);
}
casePersonsQuery.distinct(true);
List<Person> casePersonsResultList = getBatchedQueryResults(cb, casePersonsQuery, casePersonsSelect, batchSize);
// persons by contact
CriteriaQuery<Person> contactPersonsQuery = cb.createQuery(Person.class);
Root<Contact> contactPersonsRoot = contactPersonsQuery.from(Contact.class);
Join<Person, Person> contactPersonsSelect = contactPersonsRoot.join(Contact.PERSON);
contactPersonsSelect.fetch(Person.ADDRESS);
contactPersonsQuery.select(contactPersonsSelect);
Predicate contactPersonsFilter = contactService.createUserFilter(cb, contactPersonsQuery, contactPersonsRoot);
// date range
if (date != null) {
Predicate dateFilter = createChangeDateFilter(cb, contactPersonsSelect, DateHelper.toTimestampUpper(date), lastSynchronizedUuid);
if (batchSize == null) {
Predicate contactDateFilter = contactService.createChangeDateFilter(cb, contactPersonsRoot, date);
dateFilter = cb.or(dateFilter, contactDateFilter);
}
contactPersonsFilter = and(cb, contactPersonsFilter, dateFilter);
}
if (contactPersonsFilter != null) {
contactPersonsQuery.where(contactPersonsFilter);
}
contactPersonsQuery.distinct(true);
List<Person> contactPersonsResultList = getBatchedQueryResults(cb, contactPersonsQuery, contactPersonsSelect, batchSize);
// persons by event participant
CriteriaQuery<Person> eventPersonsQuery = cb.createQuery(Person.class);
Root<EventParticipant> eventPersonsRoot = eventPersonsQuery.from(EventParticipant.class);
Join<Person, Person> eventPersonsSelect = eventPersonsRoot.join(EventParticipant.PERSON);
eventPersonsSelect.fetch(Person.ADDRESS);
eventPersonsQuery.select(eventPersonsSelect);
Predicate eventPersonsFilter = eventParticipantService.createUserFilter(cb, eventPersonsQuery, eventPersonsRoot);
// date range
if (date != null) {
Predicate dateFilter = createChangeDateFilter(cb, eventPersonsSelect, DateHelper.toTimestampUpper(date), lastSynchronizedUuid);
if (batchSize == null) {
Predicate eventParticipantDateFilter = eventParticipantService.createChangeDateFilter(cb, eventPersonsRoot, DateHelper.toTimestampUpper(date));
dateFilter = cb.or(dateFilter, eventParticipantDateFilter);
}
eventPersonsFilter = and(cb, eventPersonsFilter, dateFilter);
}
if (eventPersonsFilter != null) {
eventPersonsQuery.where(eventPersonsFilter);
}
eventPersonsQuery.distinct(true);
List<Person> eventPersonsResultList = getBatchedQueryResults(cb, eventPersonsQuery, eventPersonsSelect, batchSize);
// persons by immunization
List<Person> immunizationPersonsResultList = new ArrayList<>();
if (!featureConfigurationFacade.isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) {
CriteriaQuery<Person> immunizationPersonsQuery = cb.createQuery(Person.class);
Root<Immunization> immunizationPersonsRoot = immunizationPersonsQuery.from(Immunization.class);
Join<Immunization, Person> immunizationPersonsSelect = immunizationPersonsRoot.join(Immunization.PERSON);
immunizationPersonsSelect.fetch(Person.ADDRESS);
immunizationPersonsQuery.select(immunizationPersonsSelect);
Predicate immunizationPersonsFilter = immunizationService.createUserFilter(cb, immunizationPersonsQuery, immunizationPersonsRoot);
// date range
if (date != null) {
Predicate dateFilter = createChangeDateFilter(cb, immunizationPersonsSelect, DateHelper.toTimestampUpper(date), lastSynchronizedUuid);
if (batchSize == null) {
Predicate immunizationDateFilter = immunizationService.createChangeDateFilter(cb, immunizationPersonsRoot, DateHelper.toTimestampUpper(date));
dateFilter = cb.or(dateFilter, immunizationDateFilter);
}
immunizationPersonsFilter = and(cb, immunizationPersonsFilter, dateFilter);
}
if (immunizationPersonsFilter != null) {
immunizationPersonsQuery.where(immunizationPersonsFilter);
}
immunizationPersonsQuery.distinct(true);
immunizationPersonsResultList = getBatchedQueryResults(cb, immunizationPersonsQuery, immunizationPersonsSelect, batchSize);
}
List<Person> travelEntryPersonsResultList = new ArrayList<>();
// if a batch size is given, this is a sync from the mobile app where travel entries are not relevant for now
if (batchSize == null) {
// persons by travel entries
CriteriaQuery<Person> tepQuery = cb.createQuery(Person.class);
Root<TravelEntry> tepRoot = tepQuery.from(TravelEntry.class);
Join<TravelEntry, Person> tepSelect = tepRoot.join(TravelEntry.PERSON);
tepSelect.fetch(Person.ADDRESS);
tepQuery.select(tepSelect);
Predicate tepFilter = travelEntryService.createUserFilter(cb, tepQuery, tepRoot);
// date range
if (date != null) {
Predicate dateFilter = createChangeDateFilter(cb, tepSelect, DateHelper.toTimestampUpper(date));
Predicate travelEntryDateFilter = travelEntryService.createChangeDateFilter(cb, tepRoot, DateHelper.toTimestampUpper(date));
tepFilter = and(cb, tepFilter, cb.or(dateFilter, travelEntryDateFilter));
}
if (tepFilter != null) {
tepQuery.where(tepFilter);
}
tepQuery.distinct(true);
travelEntryPersonsResultList = em.createQuery(tepQuery).getResultList();
}
return Stream.of(lgaResultList, casePersonsResultList, contactPersonsResultList, eventPersonsResultList, immunizationPersonsResultList, travelEntryPersonsResultList).flatMap(List<Person>::stream).distinct().sorted(new ChangeDateUuidComparator<>()).limit(batchSize == null ? Long.MAX_VALUE : batchSize).collect(Collectors.toList());
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class WeeklyReportService method filterWeeklyReportUsers.
/**
* Filters users analogous to reportingUsers in ::createUserFilter
*
* @see /sormas-backend/doc/UserDataAccess.md
*/
public Stream<User> filterWeeklyReportUsers(User user, Stream<User> usersStream) {
if (user == null) {
return usersStream;
}
final JurisdictionLevel jurisdictionLevel = user.getCalculatedJurisdictionLevel();
// National users can access all reports in the system
if (jurisdictionLevel == JurisdictionLevel.NATION && !UserRole.isPortHealthUser(user.getUserRoles())) {
return usersStream;
}
// Whoever created the weekly report is allowed to access it
java.util.function.Predicate<User> constraints = user::equals;
// Supervisors see all reports from users in their region
if (user.getRegion() != null && jurisdictionLevel == JurisdictionLevel.REGION) {
constraints = constraints.or(u -> user.getRegion().equals(u.getRegion()));
}
// Officers see all reports from their assigned informants
if (user.hasAnyUserRole(UserRole.SURVEILLANCE_OFFICER)) {
constraints = constraints.or(u -> user.equals(u.getAssociatedOfficer()));
}
return usersStream.filter(constraints);
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class SampleService method createUserFilter.
@SuppressWarnings("rawtypes")
public Predicate createUserFilter(CriteriaQuery cq, CriteriaBuilder cb, SampleJoins joins, SampleCriteria criteria) {
Predicate filter = createUserFilterWithoutAssociations(cb, joins);
User currentUser = getCurrentUser();
final JurisdictionLevel jurisdictionLevel = currentUser.getCalculatedJurisdictionLevel();
if (jurisdictionLevel == JurisdictionLevel.LABORATORY || jurisdictionLevel == JurisdictionLevel.EXTERNAL_LABORATORY) {
return filter;
}
if (criteria != null && criteria.getSampleAssociationType() != null && criteria.getSampleAssociationType() != SampleAssociationType.ALL) {
final SampleAssociationType sampleAssociationType = criteria.getSampleAssociationType();
if (sampleAssociationType == SampleAssociationType.CASE) {
filter = CriteriaBuilderHelper.or(cb, filter, caseService.createUserFilter(cb, cq, joins.getCaze(), null));
} else if (sampleAssociationType == SampleAssociationType.CONTACT) {
filter = CriteriaBuilderHelper.or(cb, filter, contactService.createUserFilterForJoin(cb, cq, joins.getContact()));
} else if (sampleAssociationType == SampleAssociationType.EVENT_PARTICIPANT) {
filter = CriteriaBuilderHelper.or(cb, filter, eventParticipantService.createUserFilterForJoin(cb, cq, joins.getEventParticipant()));
}
} else if (currentUser.getLimitedDisease() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, CriteriaBuilderHelper.or(cb, caseService.createUserFilter(cb, cq, joins.getCaze(), null), contactService.createUserFilterForJoin(cb, cq, joins.getContact()), eventParticipantService.createUserFilterForJoin(cb, cq, joins.getEventParticipant())));
} else {
filter = CriteriaBuilderHelper.or(cb, filter, caseService.createUserFilter(cb, cq, joins.getCaze(), null), contactService.createUserFilterForJoin(cb, cq, joins.getContact()), eventParticipantService.createUserFilterForJoin(cb, cq, joins.getEventParticipant()));
}
return filter;
}
Aggregations