use of de.symeda.sormas.api.sormastosormas.SormasServerDescriptor in project SORMAS-Project by hzi-braunschweig.
the class ShareDataBuilderHelper method createOptionsFromOriginInfoDto.
public SormasToSormasOptionsDto createOptionsFromOriginInfoDto(SormasToSormasOriginInfo originInfo) {
SormasToSormasOptionsDto options = new SormasToSormasOptionsDto();
options.setOrganization(new SormasServerDescriptor(originInfo.getOrganizationId()));
options.setHandOverOwnership(originInfo.isOwnershipHandedOver());
options.setWithAssociatedContacts(originInfo.isWithAssociatedContacts());
options.setWithSamples(originInfo.isWithSamples());
options.setWithEventParticipants(originInfo.isWithEventParticipants());
options.setComment(originInfo.getComment());
return options;
}
use of de.symeda.sormas.api.sormastosormas.SormasServerDescriptor 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"));
}
use of de.symeda.sormas.api.sormastosormas.SormasServerDescriptor 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"));
}
use of de.symeda.sormas.api.sormastosormas.SormasServerDescriptor in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventFacadeEjbTest method testShareEvent.
@Test
public void testShareEvent() throws SormasToSormasException {
UserDto user = creator.createUser(rdcf, UserRole.NATIONAL_USER);
useSurveillanceOfficerLogin(rdcf);
Date dateNow = new Date();
EventDto event = creator.createEvent(EventStatus.SCREENING, EventInvestigationStatus.ONGOING, "Test event title", "Test description", user.toReference(), (e) -> {
e.setRiskLevel(RiskLevel.MODERATE);
e.setMultiDayEvent(true);
e.setStartDate(dateNow);
e.setEndDate(dateNow);
e.setSrcType(EventSourceType.MEDIA_NEWS);
e.setSrcMediaWebsite("Test media name");
e.setSrcMediaName("Test media website");
e.setSrcMediaDetails("Test media details");
e.getEventLocation().setRegion(rdcf.region);
e.getEventLocation().setDistrict(rdcf.district);
});
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/events"));
SormasToSormasDto postBody = invocation.getArgument(2, SormasToSormasDto.class);
assertThat(postBody.getEvents().size(), is(1));
SormasToSormasEventDto sharedEventData = postBody.getEvents().get(0);
EventDto sharedEvent = sharedEventData.getEntity();
assertThat(sharedEvent.getEventTitle(), is("Test event title"));
assertThat(sharedEvent.getEventDesc(), is("Test description"));
assertThat(sharedEvent.getEventStatus(), is(EventStatus.SCREENING));
assertThat(sharedEvent.getEventInvestigationStatus(), is(EventInvestigationStatus.ONGOING));
assertThat(sharedEvent.getRiskLevel(), is(RiskLevel.MODERATE));
assertThat(sharedEvent.isMultiDayEvent(), is(true));
assertThat(sharedEvent.getStartDate().getTime(), is(dateNow.getTime()));
assertThat(sharedEvent.getEndDate().getTime(), is(dateNow.getTime()));
assertThat(sharedEvent.getSrcType(), is(EventSourceType.MEDIA_NEWS));
assertThat(sharedEvent.getSrcMediaWebsite(), is("Test media name"));
assertThat(sharedEvent.getSrcMediaName(), is("Test media website"));
assertThat(sharedEvent.getSrcMediaDetails(), is("Test media details"));
// 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();
});
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"));
}
use of de.symeda.sormas.api.sormastosormas.SormasServerDescriptor in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testGetReShares.
@Test
public void testGetReShares() 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(false);
shareInfo.setComment("re-shared");
return encryptShareDataAsArray(new SormasToSormasShareTree(null, shareInfo, Collections.emptyList(), false));
});
Mockito.when(MockProducer.getSormasToSormasClient().post(eq("dummy SORMAS"), eq("/sormasToSormas/cases/shares"), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> encryptShareData(Collections.emptyList()));
mockS2Snetwork();
SormasToSormasEncryptedDataDto encryptedCriteria = encryptShareData(new ShareTreeCriteria(caze.getUuid(), null, false));
SormasToSormasEncryptedDataDto encryptedShares = getSormasToSormasCaseFacade().getShareTrees(encryptedCriteria);
mockDefaultServerAccess();
SormasToSormasShareTree[] shares = getSormasToSormasEncryptionFacade().decryptAndVerify(new SormasToSormasEncryptedDataDto(SECOND_SERVER_ID, encryptedShares.getData()), SormasToSormasShareTree[].class);
assertThat(shares, arrayWithSize(1));
assertThat(shares[0].getShare().getTargetDescriptor().getId(), is(SECOND_SERVER_ID));
assertThat(shares[0].getShare().isOwnershipHandedOver(), is(true));
assertThat(shares[0].getReShares().get(0).getShare().getTargetDescriptor().getId(), is("dummy SORMAS"));
assertThat(shares[0].getReShares().get(0).getShare().isOwnershipHandedOver(), is(false));
assertThat(shares[0].getReShares().get(0).getReShares(), hasSize(0));
}
Aggregations