use of de.symeda.sormas.api.sormastosormas.SormasToSormasException in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasFacadeEjb method revokeShare.
@Override
@Transactional(rollbackOn = Exception.class)
public void revokeShare(String shareInfoUuid) throws SormasToSormasException {
SormasToSormasShareInfo shareInfo = shareInfoService.getByUuid(shareInfoUuid);
List<ShareRequestInfo> pendingRequests = shareInfo.getRequests().stream().filter(r -> r.getRequestStatus() == ShareRequestStatus.PENDING).collect(Collectors.toList());
if (pendingRequests.isEmpty()) {
throw SormasToSormasException.fromStringProperty(Strings.errorSormasToSormasRevokeNotPending);
}
for (ShareRequestInfo request : pendingRequests) {
sormasToSormasRestClient.post(shareInfo.getOrganizationId(), REVOKE_REQUEST_ENDPOINT, Collections.singletonList(request.getUuid()), null);
request.setRequestStatus(ShareRequestStatus.REVOKED);
shareInfoService.ensurePersisted(shareInfo);
}
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasException in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEncryptionFacadeEjb method signAndEncrypt.
@Override
public SormasToSormasEncryptedDataDto signAndEncrypt(Object entities, String recipientId) throws SormasToSormasException {
LOGGER.info("Sign and encrypt data for {}", recipientId);
try {
final String ownId = configFacadeEjb.getS2SConfig().getId();
CmsPlaintext plaintext = new CmsPlaintext(ownId, recipientId, entities);
S2SCertificateConfig config = new S2SCertificateConfig(recipientId);
byte[] encryptedData = CmsCreator.signAndEncrypt(plaintext, config, true);
return new SormasToSormasEncryptedDataDto(ownId, encryptedData);
} catch (Exception e) {
LOGGER.error("Could not sign and encrypt data", e);
throw SormasToSormasException.fromStringProperty(Strings.errorSormasToSormasEncrypt);
}
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasException 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.SormasToSormasException in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventFacadeEjbTest method testSyncEvent.
@Test
public void testSyncEvent() throws SormasToSormasException {
useSurveillanceOfficerLogin(rdcf);
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
EventDto event = creator.createEvent(EventStatus.SCREENING, EventInvestigationStatus.ONGOING, "Test event title", "Test description", officer, e -> {
e.getEventLocation().setRegion(rdcf.region);
e.getEventLocation().setDistrict(rdcf.district);
SormasToSormasOriginInfoDto originInfo = new SormasToSormasOriginInfoDto();
originInfo.setSenderName("Test Name");
originInfo.setSenderEmail("test@email.com");
originInfo.setOrganizationId(DEFAULT_SERVER_ID);
originInfo.setOwnershipHandedOver(true);
originInfo.setWithEventParticipants(true);
e.setSormasToSormasOriginInfo(originInfo);
});
PersonDto person = creator.createPerson();
EventParticipantDto eventParticipant = creator.createEventParticipant(event.toReference(), person, "Involved", officer, ep -> {
SormasToSormasOriginInfoDto originInfo = new SormasToSormasOriginInfoDto();
originInfo.setSenderName("Test Name");
originInfo.setSenderEmail("test@email.com");
originInfo.setOrganizationId(DEFAULT_SERVER_ID);
originInfo.setOwnershipHandedOver(true);
originInfo.setWithEventParticipants(true);
ep.setSormasToSormasOriginInfo(originInfo);
}, null);
ShareRequestInfo shareRequestInfo = createShareRequestInfo(getUserService().getByUuid(officer.getUuid()), SECOND_SERVER_ID, false, ShareRequestStatus.ACCEPTED, i -> i.setEvent(getEventService().getByUuid(event.getUuid())));
shareRequestInfo.setWithEventParticipants(true);
shareRequestInfo.getShares().add(createShareInfo(SECOND_SERVER_ID, false, i -> i.setEventParticipant(getEventParticipantService().getByUuid(eventParticipant.getUuid()))));
getShareRequestInfoService().persist(shareRequestInfo);
EventParticipantDto newEventParticipant = creator.createEventParticipant(event.toReference(), person, "Involved", officer);
Mockito.when(MockProducer.getSormasToSormasClient().post(eq(DEFAULT_SERVER_ID), ArgumentMatchers.contains("/events/sync"), ArgumentMatchers.any(), ArgumentMatchers.any())).then(invocation -> {
SyncDataDto syncData = invocation.getArgument(2);
assertThat(syncData.getCriteria().getEntityUuid(), is(event.getUuid()));
assertThat(syncData.getCriteria().getExceptedOrganizationId(), is(DEFAULT_SERVER_ID));
assertThat(syncData.getCriteria().isForwardOnly(), is(false));
assertThat(syncData.getShareData().getEvents().get(0).getEntity().getUuid(), is(event.getUuid()));
// new event participant should not be shared
assertThat(syncData.getShareData().getEventParticipants(), hasSize(1));
return Response.noContent().build();
});
Mockito.when(MockProducer.getSormasToSormasClient().post(eq(SECOND_SERVER_ID), ArgumentMatchers.contains("/events/sync"), ArgumentMatchers.any(), ArgumentMatchers.any())).then(invocation -> {
SyncDataDto syncData = invocation.getArgument(2);
assertThat(syncData.getCriteria().getEntityUuid(), is(event.getUuid()));
assertThat(syncData.getCriteria().getExceptedOrganizationId(), is(nullValue()));
assertThat(syncData.getCriteria().isForwardOnly(), is(true));
assertThat(syncData.getShareData().getEvents().get(0).getEntity().getUuid(), is(event.getUuid()));
// the new event participant should not be shared
assertThat(syncData.getShareData().getEventParticipants(), hasSize(1));
assertThat(syncData.getShareData().getEventParticipants().get(0).getEntity().getUuid(), is(eventParticipant.getUuid()));
return Response.noContent().build();
});
getSormasToSormasEventFacade().syncShares(new ShareTreeCriteria(event.getUuid(), null, false));
// new event participant should have share info with ownership handed over
List<SormasToSormasShareInfoDto> newEventParticipantShareInfoList = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().eventParticipant(newEventParticipant.toReference()), 0, 100);
assertThat(newEventParticipantShareInfoList, hasSize(0));
}
use of de.symeda.sormas.api.sormastosormas.SormasToSormasException in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventFacadeEjbTest method testShareEventWithSamples.
@Test
public void testShareEventWithSamples() throws SormasToSormasException {
UserDto user = creator.createUser(rdcf, UserRole.NATIONAL_USER);
useSurveillanceOfficerLogin(rdcf);
EventDto event = creator.createEvent(EventStatus.SCREENING, EventInvestigationStatus.ONGOING, "Test event title", "Test description", user.toReference(), (e) -> {
e.getEventLocation().setRegion(rdcf.region);
e.getEventLocation().setDistrict(rdcf.district);
});
EventParticipantDto eventParticipant = creator.createEventParticipant(event.toReference(), creator.createPerson("John", "Doe", p -> p.setBirthName("Test birth name")), "Involved", user.toReference(), (ep) -> {
ep.setRegion(rdcf.region);
ep.setDistrict(rdcf.district);
ep.setVaccinationStatus(VaccinationStatus.VACCINATED);
}, null);
SampleDto sample = creator.createSample(eventParticipant.toReference(), new Date(), new Date(), user.toReference(), SampleMaterial.BLOOD, rdcf.facility);
creator.createPathogenTest(sample.toReference(), PathogenTestType.CULTURE, Disease.CORONAVIRUS, new Date(), rdcf.facility, user.toReference(), PathogenTestResultType.INDETERMINATE, "Test result", true, null);
creator.createAdditionalTest(sample.toReference());
SormasToSormasOptionsDto options = new SormasToSormasOptionsDto();
options.setOrganization(new SormasServerDescriptor(SECOND_SERVER_ID));
options.setWithEventParticipants(true);
options.setWithSamples(true);
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/events"));
SormasToSormasDto postBody = invocation.getArgument(2, SormasToSormasDto.class);
assertThat(postBody.getEvents().size(), is(1));
List<SormasToSormasEventParticipantDto> eventParticipants = postBody.getEventParticipants();
assertThat(eventParticipants, hasSize(1));
List<SormasToSormasSampleDto> samples = postBody.getSamples();
assertThat(samples, hasSize(1));
assertThat(samples.get(0).getPathogenTests(), hasSize(1));
assertThat(samples.get(0).getAdditionalTests(), hasSize(1));
return Response.noContent().build();
});
getSormasToSormasEventFacade().share(Collections.singletonList(event.getUuid()), options);
List<SormasToSormasShareInfoDto> shareInfoList = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().event(event.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