Search in sources :

Example 1 with SormasToSormasOriginInfoDto

use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.

the class SormasToSormasOriginInfoFacadeEjb method toDto.

public static SormasToSormasOriginInfoDto toDto(SormasToSormasOriginInfo source) {
    if (source == null) {
        return null;
    }
    SormasToSormasOriginInfoDto target = new SormasToSormasOriginInfoDto();
    DtoHelper.fillDto(target, source);
    target.setOrganizationId(source.getOrganizationId());
    target.setSenderName(source.getSenderName());
    target.setSenderEmail(source.getSenderEmail());
    target.setSenderPhoneNumber(source.getSenderPhoneNumber());
    target.setOwnershipHandedOver(source.isOwnershipHandedOver());
    target.setWithAssociatedContacts(source.isWithAssociatedContacts());
    target.setWithSamples(source.isWithSamples());
    target.setWithEventParticipants(source.isWithEventParticipants());
    target.setWithImmunizations(source.isWithImmunizations());
    target.setComment(source.getComment());
    return target;
}
Also used : SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto)

Example 2 with SormasToSormasOriginInfoDto

use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.

the class ShareDataBuilderHelper method createSormasToSormasOriginInfo.

public SormasToSormasOriginInfoDto createSormasToSormasOriginInfo(User user, SormasToSormasOptionsDto options) {
    SormasToSormasOriginInfoDto sormasToSormasOriginInfo = new SormasToSormasOriginInfoDto();
    sormasToSormasOriginInfo.setOrganizationId(configFacadeEjb.getS2SConfig().getId());
    sormasToSormasOriginInfo.setSenderName(String.format("%s %s", user.getFirstName(), user.getLastName()));
    sormasToSormasOriginInfo.setSenderEmail(user.getUserEmail());
    sormasToSormasOriginInfo.setSenderPhoneNumber(user.getPhone());
    sormasToSormasOriginInfo.setOwnershipHandedOver(options.isHandOverOwnership());
    sormasToSormasOriginInfo.setWithAssociatedContacts(options.isWithAssociatedContacts());
    sormasToSormasOriginInfo.setWithSamples(options.isWithSamples());
    sormasToSormasOriginInfo.setWithEventParticipants(options.isWithEventParticipants());
    sormasToSormasOriginInfo.setWithImmunizations(options.isWithImmunizations());
    sormasToSormasOriginInfo.setComment(options.getComment());
    return sormasToSormasOriginInfo;
}
Also used : SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto)

Example 3 with SormasToSormasOriginInfoDto

use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.

the class ReceivedEntitiesProcessor method processReceivedRequest.

public List<ValidationErrors> processReceivedRequest(ShareRequestData shareData) {
    List<ValidationErrors> validationErrors = new ArrayList<>();
    SormasToSormasOriginInfoDto originInfo = shareData.getOriginInfo();
    originInfo.setUuid(DataHelper.createUuid());
    originInfo.setChangeDate(new Date());
    ValidationErrors originInfoErrors = validateOriginInfo(originInfo, Captions.sormasToSormasOriginInfo);
    if (originInfoErrors.hasError()) {
        validationErrors.add(new ValidationErrors(new ValidationErrorGroup(Captions.sormasToSormasOriginInfo), originInfoErrors));
    }
    shareData.getPreviews().getCases().forEach(c -> {
        ValidationErrors caseErrors = caseProcessor.processReceivedPreview(c);
        if (caseErrors.hasError()) {
            validationErrors.add(new ValidationErrors(ValidationHelper.buildCaseValidationGroupName(c), caseErrors));
        }
    });
    shareData.getPreviews().getContacts().forEach(c -> {
        ValidationErrors contactErrors = contactProcessor.processReceivedPreview(c);
        if (contactErrors.hasError()) {
            validationErrors.add(new ValidationErrors(ValidationHelper.buildContactValidationGroupName(c), contactErrors));
        }
    });
    shareData.getPreviews().getEvents().forEach(e -> {
        ValidationErrors eventErrors = eventProcessor.processReceivedPreview(e);
        if (eventErrors.hasError()) {
            validationErrors.add(new ValidationErrors(ValidationHelper.buildEventValidationGroupName(e), eventErrors));
        }
    });
    shareData.getPreviews().getEventParticipants().forEach(ep -> {
        ValidationErrors eventParticipantErrors = eventParticipantProcessor.processReceivedPreview(ep);
        if (eventParticipantErrors.hasError()) {
            validationErrors.add(new ValidationErrors(ValidationHelper.buildEventParticipantValidationGroupName(ep), eventParticipantErrors));
        }
    });
    return validationErrors;
}
Also used : ValidationErrorGroup(de.symeda.sormas.api.sormastosormas.validation.ValidationErrorGroup) ValidationErrors(de.symeda.sormas.api.sormastosormas.validation.ValidationErrors) ArrayList(java.util.ArrayList) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) Date(java.util.Date)

Example 4 with SormasToSormasOriginInfoDto

use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto 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));
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Date(java.util.Date) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SormasToSormasOptionsDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SormasToSormasEventParticipantDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventParticipantDto) Matchers.nullValue(org.hamcrest.Matchers.nullValue) EventInvestigationStatus(de.symeda.sormas.api.event.EventInvestigationStatus) UserRole(de.symeda.sormas.api.user.UserRole) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) VaccinationStatus(de.symeda.sormas.api.caze.VaccinationStatus) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) EventDto(de.symeda.sormas.api.event.EventDto) RiskLevel(de.symeda.sormas.api.event.RiskLevel) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) List(java.util.List) User(de.symeda.sormas.backend.user.User) Response(javax.ws.rs.core.Response) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) Matchers.is(org.hamcrest.Matchers.is) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SamplePurpose(de.symeda.sormas.api.sample.SamplePurpose) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) MockProducer(de.symeda.sormas.backend.MockProducer) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) RunWith(org.junit.runner.RunWith) AdditionalTestDto(de.symeda.sormas.api.sample.AdditionalTestDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) EventStatus(de.symeda.sormas.api.event.EventStatus) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) Calendar(java.util.Calendar) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) DataHelper(de.symeda.sormas.api.utils.DataHelper) SormasToSormasEventDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto) SormasToSormasShareRequestDto(de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto) UserDto(de.symeda.sormas.api.user.UserDto) Test(org.junit.Test) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Mockito(org.mockito.Mockito) Disease(de.symeda.sormas.api.Disease) SampleDto(de.symeda.sormas.api.sample.SampleDto) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) EventSourceType(de.symeda.sormas.api.event.EventSourceType) Collections(java.util.Collections) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) PersonDto(de.symeda.sormas.api.person.PersonDto) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) EventDto(de.symeda.sormas.api.event.EventDto) SormasToSormasEventDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) SormasToSormasEventParticipantDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventParticipantDto) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 5 with SormasToSormasOriginInfoDto

use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.

the class SormasToSormasContactFacadeEjbTest method testReturnContact.

@Test
public void testReturnContact() 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(), new Date(), Disease.CORONAVIRUS, rdcf, c -> {
        SormasToSormasOriginInfoDto originInfo = new SormasToSormasOriginInfoDto();
        originInfo.setSenderName("Test Name");
        originInfo.setSenderEmail("test@email.com");
        originInfo.setOrganizationId(DEFAULT_SERVER_ID);
        originInfo.setOwnershipHandedOver(true);
        c.setSormasToSormasOriginInfo(originInfo);
    });
    SormasToSormasShareRequestDto shareRequest = new SormasToSormasShareRequestDto();
    shareRequest.setUuid(DataHelper.createUuid());
    shareRequest.setOriginInfo(contact.getSormasToSormasOriginInfo());
    getSormasToSormasShareRequestFacade().saveShareRequest(shareRequest);
    SampleDto sharedSample = creator.createSample(contact.toReference(), officer, rdcf.facility, s -> s.setSormasToSormasOriginInfo(contact.getSormasToSormasOriginInfo()));
    SormasToSormasOptionsDto options = new SormasToSormasOptionsDto();
    options.setOrganization(new SormasServerDescriptor(SECOND_SERVER_ID));
    options.setHandOverOwnership(true);
    options.setWithSamples(true);
    options.setComment("Test comment");
    Mockito.when(MockProducer.getSormasToSormasClient().put(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> Response.noContent().build());
    getSormasToSormasContactFacade().share(Collections.singletonList(contact.getUuid()), options);
    // contact ownership should be lost
    ContactDto sharedContact = getContactFacade().getByUuid(contact.getUuid());
    assertThat(sharedContact.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
    // sample ownership should be lost
    sharedSample = getSampleFacade().getSampleByUuid(sharedSample.getUuid());
    assertThat(sharedSample.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SormasToSormasShareRequestDto(de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) PersonDto(de.symeda.sormas.api.person.PersonDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) SormasToSormasOptionsDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) Date(java.util.Date) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Aggregations

SormasToSormasOriginInfoDto (de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto)20 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)13 SormasToSormasTest (de.symeda.sormas.backend.sormastosormas.SormasToSormasTest)13 Test (org.junit.Test)13 Date (java.util.Date)12 PersonDto (de.symeda.sormas.api.person.PersonDto)11 SormasServerDescriptor (de.symeda.sormas.api.sormastosormas.SormasServerDescriptor)11 SampleDto (de.symeda.sormas.api.sample.SampleDto)10 SormasToSormasOptionsDto (de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto)10 SormasToSormasSampleDto (de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto)10 SormasToSormasShareRequestDto (de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto)10 SormasToSormasDto (de.symeda.sormas.api.sormastosormas.SormasToSormasDto)9 SormasToSormasEncryptedDataDto (de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto)9 SormasToSormasShareInfoDto (de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto)9 User (de.symeda.sormas.backend.user.User)9 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)8 ContactDto (de.symeda.sormas.api.contact.ContactDto)8 ShareTreeCriteria (de.symeda.sormas.api.sormastosormas.ShareTreeCriteria)8 SormasToSormasContactDto (de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto)8 SormasToSormasShareInfoCriteria (de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria)8