use of de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto 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.event.SormasToSormasEventDto in project SORMAS-Project by hzi-braunschweig.
the class InfraValidationSoundnessTest method testShareEventValidation.
@Test
public void testShareEventValidation() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
class EventDtoRootNode extends DtoRootNode<SormasToSormasEventDto> {
public EventDtoRootNode(SormasToSormasEventDto dtoUnderTest) {
super(dtoUnderTest);
}
}
class EventPreviewRootNode extends DtoRootNode<SormasToSormasEventPreview> {
public EventPreviewRootNode(SormasToSormasEventPreview dtoUnderTest) {
super(dtoUnderTest);
}
}
before();
SormasToSormasEventDto eventDto = new SormasToSormasEventDto();
EventDtoRootNode rootNode = new EventDtoRootNode(eventDto);
assertValidationDto(eventDto, rootNode, eventDtoValidator);
SormasToSormasEventPreview eventPreview = new SormasToSormasEventPreview();
EventPreviewRootNode previewRootNode = new EventPreviewRootNode(eventPreview);
assertValidationPreview(eventPreview, previewRootNode, eventDtoValidator);
}
use of de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto in project SORMAS-Project by hzi-braunschweig.
the class ProcessedEventDataPersister method persistSharedData.
@Override
public void persistSharedData(SormasToSormasEventDto processedData, Event existingEvent) throws SormasToSormasValidationException {
EventDto event = processedData.getEntity();
handleValidationError(() -> eventFacade.save(event, false, false), Captions.CaseData, buildCaseValidationGroupName(event));
}
use of de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventDtoValidator method validate.
@Override
public ValidationErrors validate(SormasToSormasEventDto sharedData, ValidationDirection direction) {
EventDto event = sharedData.getEntity();
ValidationErrors validationErrors = new ValidationErrors(buildEventValidationGroupName(event));
validateLocation(event.getEventLocation(), Captions.Event, validationErrors, direction);
return validationErrors;
}
use of de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasEventFacadeEjbTest method testSaveSyncedEvent.
@Test
public void testSaveSyncedEvent() 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.setOwnershipHandedOver(false);
e.setSormasToSormasOriginInfo(originInfo);
});
EventParticipantDto eventParticipant = creator.createEventParticipant(event.toReference(), creator.createPerson(), "Involved", officer, (ep) -> ep.setSormasToSormasOriginInfo(event.getSormasToSormasOriginInfo()), null);
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();
shareData.setOriginInfo(createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, false));
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)));
getSormasToSormasEventFacade().saveSyncedEntity(encryptedData);
EventDto syncedEvent = getEventFacade().getEventByUuid(event.getUuid(), false);
assertThat(syncedEvent.getEventDesc(), is("Test updated description"));
assertThat(syncedEvent.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
EventParticipantDto syncedEventParticipant = getEventParticipantFacade().getEventParticipantByUuid(eventParticipant.getUuid());
assertThat(syncedEventParticipant.getPerson().getBirthName(), is("Test birth name"));
assertThat(syncedEventParticipant.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
EventParticipantDto returnedNewEventParticipant = getEventParticipantFacade().getEventParticipantByUuid(newEventParticipant.getUuid());
assertThat(returnedNewEventParticipant.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
}
Aggregations