use of de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventFacadeEjbTest method testSyncRecursively.
@Test
public void testSyncRecursively() throws SormasToSormasException, SormasToSormasValidationException {
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
EventDto event = creator.createEvent(EventStatus.SCREENING, EventInvestigationStatus.ONGOING, "Test event title", "Test description", officer, e -> {
SormasToSormasOriginInfoDto originInfo = new SormasToSormasOriginInfoDto();
originInfo.setSenderName("Test Name");
originInfo.setSenderEmail("test@email.com");
originInfo.setOrganizationId(DEFAULT_SERVER_ID);
originInfo.setWithEventParticipants(true);
originInfo.setOwnershipHandedOver(false);
e.setSormasToSormasOriginInfo(originInfo);
});
EventParticipantDto eventParticipant = creator.createEventParticipant(event.toReference(), creator.createPerson(), "Involved", officer, (ep) -> ep.setSormasToSormasOriginInfo(event.getSormasToSormasOriginInfo()), 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 = createEventParticipantDto(event.toReference(), UserDto.build().toReference(), rdcf);
event.setEventDesc("Test updated description");
eventParticipant.getPerson().setBirthName("Test birth name");
Calendar calendar = Calendar.getInstance();
calendar.setTime(event.getChangeDate());
calendar.add(Calendar.DAY_OF_MONTH, 1);
event.setChangeDate(calendar.getTime());
SormasToSormasDto shareData = new SormasToSormasDto();
SormasToSormasOriginInfoDto originInfo = createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, false);
originInfo.setWithEventParticipants(true);
shareData.setOriginInfo(originInfo);
shareData.setEvents(Collections.singletonList(new SormasToSormasEventDto(event)));
shareData.setEventParticipants(Arrays.asList(new SormasToSormasEventParticipantDto(eventParticipant), new SormasToSormasEventParticipantDto(newEventParticipant)));
SormasToSormasEncryptedDataDto encryptedData = encryptShareData(new SyncDataDto(shareData, new ShareTreeCriteria(event.getUuid(), null, false)));
Mockito.when(MockProducer.getManagedScheduledExecutorService().schedule(ArgumentMatchers.any(Runnable.class), ArgumentMatchers.anyLong(), ArgumentMatchers.any())).then(invocation -> {
((Runnable) invocation.getArgument(0)).run();
Mockito.verify(MockProducer.getSormasToSormasClient(), Mockito.times(1)).post(eq(DEFAULT_SERVER_ID), ArgumentMatchers.contains("/events/sync"), ArgumentMatchers.any(), ArgumentMatchers.any());
Mockito.verify(MockProducer.getSormasToSormasClient(), Mockito.times(1)).post(eq(SECOND_SERVER_ID), ArgumentMatchers.contains("/events/sync"), ArgumentMatchers.any(), ArgumentMatchers.any());
return null;
});
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(SECOND_SERVER_ID));
assertThat(syncData.getCriteria().isForwardOnly(), is(false));
assertThat(syncData.getShareData().getEvents().get(0).getEntity().getUuid(), is(event.getUuid()));
assertThat(syncData.getShareData().getEventParticipants(), hasSize(2));
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()));
assertThat(syncData.getShareData().getEventParticipants(), hasSize(1));
return Response.noContent().build();
});
getSormasToSormasEventFacade().saveSyncedEntity(encryptedData);
}
use of de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto in project SORMAS-Project by hzi-braunschweig.
the class ProcessedEntitiesPersister method persistSharedData.
public void persistSharedData(SormasToSormasDto processedData, SormasToSormasOriginInfoDto originInfo, ShareDataExistingEntities existingEntities) throws SormasToSormasValidationException {
List<SormasToSormasCaseDto> cases = processedData.getCases();
if (CollectionUtils.isNotEmpty(cases)) {
for (SormasToSormasCaseDto c : cases) {
caseDataPersister.persistSharedData(c, originInfo, existingEntities.getCases().get(c.getEntity().getUuid()));
}
}
List<SormasToSormasContactDto> contacts = processedData.getContacts();
if (CollectionUtils.isNotEmpty(contacts)) {
for (SormasToSormasContactDto c : contacts) {
contactDataPersister.persistSharedData(c, originInfo, existingEntities.getContacts().get(c.getEntity().getUuid()));
}
}
List<SormasToSormasEventDto> events = processedData.getEvents();
if (CollectionUtils.isNotEmpty(events)) {
for (SormasToSormasEventDto e : events) {
eventDataPersister.persistSharedData(e, originInfo, existingEntities.getEvents().get(e.getEntity().getUuid()));
}
}
List<SormasToSormasEventParticipantDto> eventParticipants = processedData.getEventParticipants();
if (CollectionUtils.isNotEmpty(eventParticipants)) {
for (SormasToSormasEventParticipantDto ep : eventParticipants) {
eventParticipantDataPersister.persistSharedData(ep, originInfo, existingEntities.getEventParticipants().get(ep.getEntity().getUuid()));
}
}
List<SormasToSormasSampleDto> samples = processedData.getSamples();
if (CollectionUtils.isNotEmpty(samples)) {
for (SormasToSormasSampleDto s : samples) {
sampleDataPersister.persistSharedData(s, originInfo, existingEntities.getSamples().get(s.getEntity().getUuid()));
}
}
List<SormasToSormasImmunizationDto> immunizations = processedData.getImmunizations();
if (CollectionUtils.isNotEmpty(immunizations)) {
for (SormasToSormasImmunizationDto s : immunizations) {
immunizationDataPersister.persistSharedData(s, originInfo, existingEntities.getImmunizations().get(s.getEntity().getUuid()));
}
}
}
use of de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto in project SORMAS-Project by hzi-braunschweig.
the class ProcessedEntitiesPersister method persistSyncData.
public void persistSyncData(SormasToSormasDto processedData, SormasToSormasOriginInfoDto originInfoDto, ShareTreeCriteria shareTreeCriteria, ShareDataExistingEntities existingEntities) throws SormasToSormasValidationException {
List<SormasToSormasCaseDto> cases = processedData.getCases();
if (CollectionUtils.isNotEmpty(cases)) {
for (SormasToSormasCaseDto c : cases) {
caseDataPersister.persistSyncData(c, originInfoDto, existingEntities.getCases().get(c.getEntity().getUuid()));
}
}
List<SormasToSormasContactDto> contacts = processedData.getContacts();
if (CollectionUtils.isNotEmpty(contacts)) {
for (SormasToSormasContactDto c : contacts) {
contactDataPersister.persistSyncData(c, originInfoDto, existingEntities.getContacts().get(c.getEntity().getUuid()));
}
}
List<SormasToSormasEventDto> events = processedData.getEvents();
if (CollectionUtils.isNotEmpty(events)) {
for (SormasToSormasEventDto e : events) {
eventDataPersister.persistSyncData(e, originInfoDto, existingEntities.getEvents().get(e.getEntity().getUuid()));
}
}
List<SormasToSormasEventParticipantDto> eventParticipants = processedData.getEventParticipants();
if (CollectionUtils.isNotEmpty(eventParticipants)) {
for (SormasToSormasEventParticipantDto ep : eventParticipants) {
eventParticipantDataPersister.persistSyncData(ep, originInfoDto, existingEntities.getEventParticipants().get(ep.getEntity().getUuid()));
}
}
List<SormasToSormasSampleDto> samples = processedData.getSamples();
if (CollectionUtils.isNotEmpty(samples)) {
for (SormasToSormasSampleDto s : samples) {
sampleDataPersister.persistSyncData(s, originInfoDto, existingEntities.getSamples().get(s.getEntity().getUuid()));
}
}
List<SormasToSormasImmunizationDto> immunizations = processedData.getImmunizations();
if (CollectionUtils.isNotEmpty(immunizations)) {
for (SormasToSormasImmunizationDto i : immunizations) {
immunizationDataPersister.persistSyncData(i, originInfoDto, existingEntities.getImmunizations().get(i.getEntity().getUuid()));
}
}
if (CollectionUtils.isNotEmpty(cases)) {
caseFacade.syncSharesAsync(shareTreeCriteria);
} else if (CollectionUtils.isNotEmpty(contacts)) {
contactFacade.syncSharesAsync(shareTreeCriteria);
}
if (CollectionUtils.isNotEmpty(events)) {
eventFacade.syncSharesAsync(shareTreeCriteria);
}
}
use of de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto in project SORMAS-Project by hzi-braunschweig.
the class ShareDataBuilder method buildShareData.
public SormasToSormasDto buildShareData(List<SormasToSormasShareInfo> shares, SormasToSormasOriginInfoDto originInfo, ShareRequestInfo requestInfo) throws SormasToSormasException {
List<SormasToSormasCaseDto> cases = new ArrayList<>();
List<SormasToSormasContactDto> contacts = new ArrayList<>();
List<SormasToSormasSampleDto> samples = new ArrayList<>();
List<SormasToSormasEventDto> events = new ArrayList<>();
List<SormasToSormasEventParticipantDto> eventParticipants = new ArrayList<>();
List<SormasToSormasImmunizationDto> immunizations = new ArrayList<>();
List<ValidationErrors> validationErrors = new ArrayList<>();
shares.forEach(s -> {
if (s.getCaze() != null) {
try {
cases.add(caseShareDataBuilder.buildShareData(s.getCaze(), requestInfo));
} catch (SormasToSormasValidationException e) {
validationErrors.addAll(e.getErrors());
}
}
if (s.getContact() != null) {
try {
contacts.add(contactShareDataBuilder.buildShareData(s.getContact(), requestInfo));
} catch (SormasToSormasValidationException e) {
validationErrors.addAll(e.getErrors());
}
}
if (s.getSample() != null) {
try {
samples.add(sampleShareDataBuilder.buildShareData(s.getSample(), requestInfo));
} catch (SormasToSormasValidationException e) {
validationErrors.addAll(e.getErrors());
}
}
if (s.getEvent() != null) {
try {
events.add(eventShareDataBuilder.buildShareData(s.getEvent(), requestInfo));
} catch (SormasToSormasValidationException e) {
validationErrors.addAll(e.getErrors());
}
}
if (s.getEventParticipant() != null) {
try {
eventParticipants.add(eventParticipantShareDataBuilder.buildShareData(s.getEventParticipant(), requestInfo));
} catch (SormasToSormasValidationException e) {
validationErrors.addAll(e.getErrors());
}
}
if (s.getImmunization() != null) {
try {
immunizations.add(immunizationShareDataBuilder.buildShareData(s.getImmunization(), requestInfo));
} catch (SormasToSormasValidationException e) {
validationErrors.addAll(e.getErrors());
}
}
});
if (!validationErrors.isEmpty()) {
throw SormasToSormasException.fromStringProperty(validationErrors, Strings.errorSormasToSormasShare);
}
SormasToSormasDto dto = new SormasToSormasDto();
dto.setOriginInfo(originInfo);
dto.setCases(cases);
dto.setContacts(contacts);
dto.setSamples(samples);
dto.setEvents(events);
dto.setEventParticipants(eventParticipants);
dto.setImmunizations(immunizations);
return dto;
}
use of de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto in project SORMAS-Project by hzi-braunschweig.
the class ReceivedEventProcessor method handleReceivedData.
@Override
public void handleReceivedData(SormasToSormasEventDto sharedData, Event existingData) {
handleIgnoredProperties(sharedData.getEntity(), eventFacade.toDto(existingData));
EventDto event = sharedData.getEntity();
updateReportingUser(event, existingData);
if (existingData == null || existingData.getResponsibleUser() == null) {
event.setResponsibleUser(userService.getCurrentUser().toReference());
} else {
event.setResponsibleUser(existingData.getResponsibleUser().toReference());
}
}
Aggregations