use of de.symeda.sormas.api.sormastosormas.SormasToSormasDto in project SORMAS-Project by hzi-braunschweig.
the class AbstractSormasToSormasInterface method syncEntityToOrigin.
private void syncEntityToOrigin(ADO entity, SormasToSormasOriginInfo originInfo, ShareTreeCriteria criteria) throws SormasToSormasException {
User currentUser = userService.getCurrentUser();
SormasToSormasOptionsDto options = dataBuilderHelper.createOptionsFromOriginInfoDto(originInfo);
options.setHandOverOwnership(false);
ShareRequestInfo shareRequestInfo = createShareRequestInfoForEntities(DataHelper.createUuid(), ShareRequestStatus.ACCEPTED, options, Collections.singletonList(entity), currentUser, true);
SormasToSormasDto shareData = shareDataBuilder.buildShareData(shareRequestInfo.getShares(), dataBuilderHelper.createSormasToSormasOriginInfo(currentUser, options), shareRequestInfo);
sormasToSormasRestClient.post(originInfo.getOrganizationId(), syncEndpoint, new SyncDataDto(shareData, criteria), null);
// remove existing shares from the request info
shareRequestInfo.setShares(shareRequestInfo.getShares().stream().filter(s -> s.getId() == null).collect(Collectors.toList()));
if (!shareRequestInfo.getShares().isEmpty()) {
shareRequestInfoService.ensurePersisted(shareRequestInfo);
}
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasDto in project SORMAS-Project by hzi-braunschweig.
the class AbstractSormasToSormasInterface method shareEntities.
private void shareEntities(List<String> entityUuids, SormasToSormasOptionsDto options) throws SormasToSormasException {
User currentUser = userService.getCurrentUser();
List<ADO> entities = getEntityService().getByUuids(entityUuids);
validateEntitiesBeforeShare(entities, options.isHandOverOwnership());
ensureConsistentOptions(options);
String requestUuid = DataHelper.createUuid();
ShareRequestInfo requestInfo = createShareRequestInfoForEntities(requestUuid, ShareRequestStatus.ACCEPTED, options, entities, currentUser, false);
SormasToSormasDto dataToSend = shareDataBuilder.buildShareDataForRequest(requestInfo, currentUser);
sormasToSormasRestClient.post(options.getOrganization().getId(), saveEndpoint, dataToSend, null);
shareRequestInfoService.ensurePersisted(requestInfo);
entities.forEach(e -> {
SormasToSormasOriginInfo entityOriginInfo = e.getSormasToSormasOriginInfo();
if (entityOriginInfo != null) {
entityOriginInfo.setOwnershipHandedOver(!options.isHandOverOwnership());
originInfoService.ensurePersisted(entityOriginInfo);
}
});
try {
shareInfoService.handleOwnershipChangeInExternalSurvTool(requestInfo);
} catch (ExternalSurveillanceToolException e) {
LOGGER.error("Failed to delete shared entities in external surveillance tool", e);
throw SormasToSormasException.fromStringPropertyWithWarning(Strings.errorSormasToSormasDeleteFromExternalSurveillanceTool);
}
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasDto in project SORMAS-Project by hzi-braunschweig.
the class AbstractSormasToSormasInterface method getDataForShareRequest.
@Override
public SormasToSormasEncryptedDataDto getDataForShareRequest(SormasToSormasEncryptedDataDto encryptedRequestUuid) throws SormasToSormasException {
User currentUser = userService.getCurrentUser();
String requestUuid = sormasToSormasEncryptionEjb.decryptAndVerify(encryptedRequestUuid, String.class);
ShareRequestInfo requestInfo = shareRequestInfoService.getByUuid(requestUuid);
validateEntitiesBeforeShare(requestInfo.getShares());
SormasToSormasDto shareData = shareDataBuilder.buildShareDataForRequest(requestInfo, currentUser);
return sormasToSormasEncryptionEjb.signAndEncrypt(shareData, requestInfo.getShares().get(0).getOrganizationId());
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasContactFacadeEjbTest method testSaveReturnedContact.
@Test
public void testSaveReturnedContact() throws SormasToSormasException, SormasToSormasValidationException {
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
PersonDto contactPerson = creator.createPerson();
ContactDto contact = creator.createContact(rdcf, officer, contactPerson.toReference());
SampleDto sharedSample = creator.createSample(contact.toReference(), officer, rdcf.facility, null);
SampleDto newSample = createRemoteSample(contact.toReference(), officer, rdcf.facility);
User officerUser = getUserService().getByReferenceDto(officer);
getShareRequestInfoService().persist(createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setContact(getContactService().getByReferenceDto(contact.toReference()))));
getShareRequestInfoService().persist(createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setSample(getSampleService().getByReferenceDto(sharedSample.toReference()))));
contact.setQuarantine(QuarantineType.HOTEL);
Calendar calendar = Calendar.getInstance();
calendar.setTime(contact.getChangeDate());
calendar.add(Calendar.DAY_OF_MONTH, 1);
contact.setChangeDate(calendar.getTime());
SormasToSormasDto shareData = new SormasToSormasDto();
shareData.setOriginInfo(createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, true));
shareData.setContacts(Collections.singletonList(new SormasToSormasContactDto(contactPerson, contact)));
shareData.setSamples(Arrays.asList(new SormasToSormasSampleDto(sharedSample, Collections.emptyList(), Collections.emptyList()), new SormasToSormasSampleDto(newSample, Collections.emptyList(), Collections.emptyList())));
SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
getSormasToSormasContactFacade().saveSharedEntities(encryptedData);
ContactDto returnedContact = getContactFacade().getByUuid(contact.getUuid());
assertThat(returnedContact.getQuarantine(), is(QuarantineType.HOTEL));
assertThat(returnedContact.getReportingUser(), is(officer));
List<SormasToSormasShareInfoDto> contactShares = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().contact(contact.toReference()), 0, 100);
assertThat(contactShares.get(0).isOwnershipHandedOver(), is(false));
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));
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasContactFacadeEjbTest method testShareContact.
@Test
public void testShareContact() throws SormasToSormasException {
useSurveillanceOfficerLogin(rdcf);
PersonDto person = creator.createPerson();
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
ContactDto contact = creator.createContact(officer, officer, person.toReference(), null, new Date(), null, null, rdcf, dto -> dto.setResultingCaseUser(officer));
SormasToSormasOptionsDto options = new SormasToSormasOptionsDto();
options.setOrganization(new SormasServerDescriptor(SECOND_SERVER_ID));
options.setComment("Test comment");
Mockito.when(MockProducer.getSormasToSormasClient().post(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> {
assertThat(invocation.getArgument(0, String.class), is(SECOND_SERVER_ID));
assertThat(invocation.getArgument(1, String.class), is("/sormasToSormas/contacts"));
SormasToSormasDto postBody = invocation.getArgument(2, SormasToSormasDto.class);
assertThat(postBody.getContacts().size(), is(1));
SormasToSormasContactDto sharedContact = postBody.getContacts().get(0);
assertThat(sharedContact.getPerson().getFirstName(), is(person.getFirstName()));
assertThat(sharedContact.getPerson().getLastName(), is(person.getLastName()));
assertThat(sharedContact.getEntity().getUuid(), is(contact.getUuid()));
// users should be cleaned up
assertThat(sharedContact.getEntity().getReportingUser(), is(nullValue()));
assertThat(sharedContact.getEntity().getContactOfficer(), is(nullValue()));
assertThat(sharedContact.getEntity().getResultingCaseUser(), is(nullValue()));
// share information
assertThat(postBody.getOriginInfo().getOrganizationId(), is(DEFAULT_SERVER_ID));
assertThat(postBody.getOriginInfo().getSenderName(), is("Surv Off"));
assertThat(postBody.getOriginInfo().getComment(), is("Test comment"));
return Response.noContent().build();
});
getSormasToSormasContactFacade().share(Collections.singletonList(contact.getUuid()), options);
List<SormasToSormasShareInfoDto> shareInfoList = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().contact(contact.toReference()), 0, 100);
assertThat(shareInfoList.size(), is(1));
assertThat(shareInfoList.get(0).getTargetDescriptor().getId(), is(SECOND_SERVER_ID));
assertThat(shareInfoList.get(0).getSender().getCaption(), is("Surv OFF - Surveillance Officer"));
assertThat(shareInfoList.get(0).getComment(), is("Test comment"));
}
Aggregations