use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class VisitFacadeEjb method getIndexList.
@Override
public List<VisitIndexDto> getIndexList(VisitCriteria visitCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
if (visitCriteria == null || visitCriteria.isEmpty()) {
// Retrieving an index list independent of a contact/case is not possible
return new ArrayList<>();
}
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<VisitIndexDto> cq = cb.createQuery(VisitIndexDto.class);
Root<Visit> visit = cq.from(Visit.class);
Join<Visit, Symptoms> symptoms = visit.join(Visit.SYMPTOMS, JoinType.LEFT);
Join<Visit, Case> caseJoin = visit.join(Visit.CAZE, JoinType.LEFT);
Join<Visit, Contact> contactJoin = visit.join(Visit.CONTACTS, JoinType.LEFT);
Join<Visit, User> visitUser = visit.join(Visit.VISIT_USER, JoinType.LEFT);
cq.multiselect(visit.get(Visit.ID), visit.get(Visit.UUID), visit.get(Visit.VISIT_DATE_TIME), visit.get(Visit.VISIT_STATUS), visit.get(Visit.VISIT_REMARKS), visit.get(Visit.DISEASE), symptoms.get(Symptoms.SYMPTOMATIC), symptoms.get(Symptoms.TEMPERATURE), symptoms.get(Symptoms.TEMPERATURE_SOURCE), visit.get(Visit.ORIGIN), visitUser.get(User.UUID), visitUser.get(User.FIRST_NAME), visitUser.get(User.LAST_NAME), jurisdictionSelector(cq, cb, caseJoin, contactJoin));
cq.distinct(true);
cq.where(visitService.buildCriteriaFilter(visitCriteria, cb, visit));
if (sortProperties != null && sortProperties.size() > 0) {
List<Order> order = new ArrayList<>(sortProperties.size());
for (SortProperty sortProperty : sortProperties) {
Expression<?> expression;
switch(sortProperty.propertyName) {
case VisitIndexDto.VISIT_DATE_TIME:
case VisitIndexDto.VISIT_STATUS:
case VisitIndexDto.VISIT_REMARKS:
case VisitIndexDto.DISEASE:
case VisitIndexDto.ORIGIN:
expression = visit.get(sortProperty.propertyName);
break;
case VisitIndexDto.SYMPTOMATIC:
case VisitIndexDto.TEMPERATURE:
expression = symptoms.get(sortProperty.propertyName);
break;
default:
throw new IllegalArgumentException(sortProperty.propertyName);
}
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
}
cq.orderBy(order);
} else {
cq.orderBy(cb.desc(visit.get(Visit.VISIT_DATE_TIME)));
}
List<VisitIndexDto> indexList = QueryHelper.getResultList(em, cq, first, max);
if (indexList.size() > 0) {
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
indexList.forEach(visitIndex -> pseudonymizer.pseudonymizeDto(VisitIndexDto.class, visitIndex, visitIndex.getInJurisdiction(), null));
}
return indexList;
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class VaccinationFacadeEjb method pseudonymizeDto.
private void pseudonymizeDto(Vaccination source, VaccinationDto dto, Pseudonymizer pseudonymizer) {
if (dto != null) {
boolean inJurisdiction = immunizationService.inJurisdictionOrOwned(source.getImmunization());
pseudonymizer.pseudonymizeDto(VaccinationDto.class, dto, inJurisdiction, c -> {
User currentUser = userService.getCurrentUser();
pseudonymizer.pseudonymizeUser(source.getReportingUser(), currentUser, dto::setReportingUser);
});
}
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testGetAllShares.
@Test
public void testGetAllShares() throws SormasToSormasException {
useSurveillanceOfficerLogin(rdcf);
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
CaseDataDto caze = creator.createCase(officer, creator.createPerson().toReference(), rdcf);
User officerUser = getUserService().getByReferenceDto(officer);
ShareRequestInfo shareRequestInfo = createShareRequestInfo(officerUser, SECOND_SERVER_ID, true, ShareRequestStatus.ACCEPTED, i -> i.setCaze(getCaseService().getByReferenceDto(caze.toReference())));
getShareRequestInfoService().persist(shareRequestInfo);
Mockito.when(MockProducer.getSormasToSormasClient().post(eq(SECOND_SERVER_ID), eq("/sormasToSormas/cases/shares"), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> {
SormasToSormasShareInfoDto shareInfo = new SormasToSormasShareInfoDto();
shareInfo.setTargetDescriptor(new SormasServerDescriptor("dummy SORMAS"));
shareInfo.setOwnershipHandedOver(true);
shareInfo.setComment("re-shared");
return encryptShareDataAsArray(new SormasToSormasShareTree(null, shareInfo, Collections.emptyList(), false));
});
List<SormasToSormasShareTree> shares = getSormasToSormasCaseFacade().getAllShares(caze.getUuid());
assertThat(shares, hasSize(1));
SormasToSormasShareInfoDto fistShare = shares.get(0).getShare();
assertThat(fistShare.getTargetDescriptor().getId(), is(SECOND_SERVER_ID));
assertThat(fistShare.isOwnershipHandedOver(), is(true));
List<SormasToSormasShareTree> reShares = shares.get(0).getReShares();
assertThat(reShares, hasSize(1));
SormasToSormasShareInfoDto reShare = reShares.get(0).getShare();
assertThat(reShare.getTargetDescriptor().getId(), is("dummy SORMAS"));
assertThat(reShare.isOwnershipHandedOver(), is(true));
assertThat(reShare.getComment(), is("re-shared"));
assertThat(reShares.get(0).getReShares(), hasSize(0));
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testGetAllSharesOnMiddleLevel.
@Test
public void testGetAllSharesOnMiddleLevel() throws SormasToSormasException {
useSurveillanceOfficerLogin(rdcf);
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
CaseDataDto caze = creator.createCase(officer, creator.createPerson().toReference(), rdcf, c -> {
SormasToSormasOriginInfoDto originInfo = new SormasToSormasOriginInfoDto();
originInfo.setSenderName("Test Name");
originInfo.setOrganizationId(DEFAULT_SERVER_ID);
originInfo.setOwnershipHandedOver(true);
originInfo.setComment("first share");
c.setSormasToSormasOriginInfo(originInfo);
});
// initial share by the creator of case
SormasToSormasShareInfoDto shareToSecond = createShareInfoDto(officer, SECOND_SERVER_ID, true);
// another share by the creator
SormasToSormasShareInfoDto anotherShareFromDefault = createShareInfoDto(officer, "anotherShareFromDefault", false);
// forwarded by the second system
User officerUser = getUserService().getByReferenceDto(officer);
ShareRequestInfo shareFromSecond = createShareRequestInfo(officerUser, "shareFromSecond", false, ShareRequestStatus.ACCEPTED, i -> i.setCaze(getCaseService().getByReferenceDto(caze.toReference())));
getShareRequestInfoService().persist(shareFromSecond);
// The share tree for the above code is:
// |- default
// |- second
// |- shareFromSecond
// |- another from default
mockSecondServerAccess();
// mock share tree on the case creator system
Mockito.when(MockProducer.getSormasToSormasClient().post(eq(DEFAULT_SERVER_ID), eq("/sormasToSormas/cases/shares"), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> {
List<SormasToSormasShareTree> shareTrees = new ArrayList<>();
shareTrees.add(new SormasToSormasShareTree(null, shareToSecond, Collections.emptyList(), false));
shareTrees.add(new SormasToSormasShareTree(null, anotherShareFromDefault, Collections.emptyList(), false));
return encryptShareData(shareTrees);
});
// Mock shares from "anotherShareFromDefault" -> no more shares
Mockito.when(MockProducer.getSormasToSormasClient().post(eq("anotherShareFromDefault"), eq("/sormasToSormas/cases/shares"), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> encryptShareData(Collections.emptyList()));
// Mock shares from "shareFromSecond" server -> no more shares
Mockito.when(MockProducer.getSormasToSormasClient().post(eq("shareFromSecond"), eq("/sormasToSormas/cases/shares"), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> encryptShareData(Collections.emptyList()));
List<SormasToSormasShareTree> shares = getSormasToSormasCaseFacade().getAllShares(caze.getUuid());
assertThat(shares, hasSize(2));
SormasToSormasShareInfoDto fistShare = shares.get(0).getShare();
assertThat(fistShare.getTargetDescriptor().getId(), is(SECOND_SERVER_ID));
assertThat(fistShare.isOwnershipHandedOver(), is(true));
List<SormasToSormasShareTree> reShares = shares.get(0).getReShares();
assertThat(reShares, hasSize(1));
SormasToSormasShareInfoDto reShare = reShares.get(0).getShare();
assertThat(reShare.getTargetDescriptor().getId(), is("shareFromSecond"));
assertThat(reShare.isOwnershipHandedOver(), is(false));
assertThat(reShares.get(0).getReShares(), hasSize(0));
SormasToSormasShareTree secondReShareFromDefault = shares.get(1);
assertThat(secondReShareFromDefault.getShare().getTargetDescriptor().getId(), is("anotherShareFromDefault"));
assertThat(secondReShareFromDefault.getShare().isOwnershipHandedOver(), is(false));
assertThat(secondReShareFromDefault.getReShares(), hasSize(0));
}
use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testSaveReturnedCase.
@Test
public void testSaveReturnedCase() throws SormasToSormasException {
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
PersonDto person = creator.createPerson();
CaseDataDto caze = creator.createCase(officer, person.toReference(), rdcf);
PersonDto sharedContactPerson = creator.createPerson();
ContactDto sharedContact = creator.createContact(officer, sharedContactPerson.toReference(), caze);
PersonDto newContactPerson = creator.createPerson();
ContactDto newContact = createContactRemoteContact(officer, newContactPerson.toReference(), caze);
ContactDto newContact2 = createContactRemoteContact(officer, newContactPerson.toReference(), caze);
SampleDto sharedSample = creator.createSample(caze.toReference(), officer, rdcf.facility);
SampleDto newSample = createRemoteSample(caze.toReference(), officer, rdcf.facility);
SampleDto newSample2 = createRemoteSample(caze.toReference(), officer, rdcf.facility);
User officerUser = getUserService().getByReferenceDto(officer);
getShareRequestInfoService().persist(createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setCaze(getCaseService().getByReferenceDto(caze.toReference()))));
getShareRequestInfoService().persist(createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setContact(getContactService().getByReferenceDto(sharedContact.toReference()))));
getShareRequestInfoService().persist(createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setSample(getSampleService().getByReferenceDto(sharedSample.toReference()))));
caze.setQuarantine(QuarantineType.HOTEL);
Calendar calendar = Calendar.getInstance();
calendar.setTime(caze.getChangeDate());
calendar.add(Calendar.DAY_OF_MONTH, 1);
caze.setChangeDate(calendar.getTime());
SormasToSormasOriginInfoDto originInfo = createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, true);
SormasToSormasDto shareData = new SormasToSormasDto();
shareData.setOriginInfo(originInfo);
shareData.setCases(Collections.singletonList(new SormasToSormasCaseDto(person, caze)));
shareData.setContacts(Arrays.asList(new SormasToSormasContactDto(sharedContactPerson, sharedContact), new SormasToSormasContactDto(newContactPerson, newContact), new SormasToSormasContactDto(newContactPerson, newContact2)));
shareData.setSamples(Arrays.asList(new SormasToSormasSampleDto(sharedSample, Collections.emptyList(), Collections.emptyList()), new SormasToSormasSampleDto(newSample, Collections.emptyList(), Collections.emptyList()), new SormasToSormasSampleDto(newSample2, Collections.emptyList(), Collections.emptyList())));
SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
try {
getSormasToSormasCaseFacade().saveSharedEntities(encryptedData);
} catch (Exception e) {
e.printStackTrace();
}
CaseDataDto returnedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
assertThat(returnedCase.getQuarantine(), is(QuarantineType.HOTEL));
assertThat(returnedCase.getReportingUser(), is(officer));
List<SormasToSormasShareInfoDto> caseShares = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().caze(caze.toReference()), 0, 100);
assertThat(caseShares.get(0).isOwnershipHandedOver(), is(false));
List<SormasToSormasShareInfoDto> contactShares = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().contact(sharedContact.toReference()), 0, 100);
assertThat(contactShares.get(0).isOwnershipHandedOver(), is(false));
ContactDto returnedNewContact = getContactFacade().getByUuid(newContact.getUuid());
assertThat(returnedNewContact.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(true));
ContactDto returnedNewContact2 = getContactFacade().getByUuid(newContact.getUuid());
assertThat(returnedNewContact2.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(true));
List<SormasToSormasShareInfoDto> sampleShares = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().sample(sharedSample.toReference()), 0, 100);
assertThat(sampleShares.get(0).isOwnershipHandedOver(), is(false));
SampleDto returnedNewSample = getSampleFacade().getSampleByUuid(newSample.getUuid());
assertThat(returnedNewSample.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(true));
SampleDto returnedNewSample2 = getSampleFacade().getSampleByUuid(newSample.getUuid());
assertThat(returnedNewSample2.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(true));
}
Aggregations