Search in sources :

Example 1 with SormasToSormasException

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);
    }
}
Also used : FeatureType(de.symeda.sormas.api.feature.FeatureType) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) Arrays(java.util.Arrays) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException) SormasToSormasShareInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoService) Date(java.util.Date) RESOURCE_PATH(de.symeda.sormas.api.sormastosormas.SormasToSormasApiConstants.RESOURCE_PATH) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) Inject(javax.inject.Inject) SormasToSormasContactFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.entities.contact.SormasToSormasContactFacadeEjb.SormasToSormasContactFacadeEjbLocal) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) SormasToSormasShareable(de.symeda.sormas.backend.sormastosormas.entities.SormasToSormasShareable) SormasToSormasCaseFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.entities.caze.SormasToSormasCaseFacadeEjb.SormasToSormasCaseFacadeEjbLocal) LocalBean(javax.ejb.LocalBean) EJB(javax.ejb.EJB) ConfigFacadeEjb(de.symeda.sormas.backend.common.ConfigFacadeEjb) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) Transactional(javax.transaction.Transactional) SormasToSormasShareRequestDto(de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto) SormasToSormasApiConstants(de.symeda.sormas.api.sormastosormas.SormasToSormasApiConstants) ShareRequestDataType(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestDataType) SormasToSormasEncryptionFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.crypto.SormasToSormasEncryptionFacadeEjb.SormasToSormasEncryptionFacadeEjbLocal) SormasToSormasRestClient(de.symeda.sormas.backend.sormastosormas.rest.SormasToSormasRestClient) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) Collectors(java.util.stream.Collectors) SormasToSormasEntityInterface(de.symeda.sormas.api.sormastosormas.SormasToSormasEntityInterface) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) UserRight(de.symeda.sormas.api.user.UserRight) SormasToSormasShareRequestFacadeEJBLocal(de.symeda.sormas.backend.sormastosormas.share.sharerequest.SormasToSormasShareRequestFacadeEJB.SormasToSormasShareRequestFacadeEJBLocal) List(java.util.List) SormasToSormasFacade(de.symeda.sormas.api.sormastosormas.SormasToSormasFacade) UserService(de.symeda.sormas.backend.user.UserService) SormasToSormasEventFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.entities.event.SormasToSormasEventFacadeEjb.SormasToSormasEventFacadeEjbLocal) ShareRequestInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfoService) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) RequestResponseDataDto(de.symeda.sormas.api.sormastosormas.sharerequest.RequestResponseDataDto) SormasToSormasDiscoveryService(de.symeda.sormas.backend.sormastosormas.access.SormasToSormasDiscoveryService) SormasToSormasOriginInfo(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo) FeatureConfigurationFacadeEjbLocal(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) Transactional(javax.transaction.Transactional)

Example 2 with SormasToSormasException

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);
    }
}
Also used : SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) CmsPlaintext(de.symeda.sormas.backend.crypt.CmsPlaintext) KeyStoreException(java.security.KeyStoreException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 3 with SormasToSormasException

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));
}
Also used : 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) ExposureType(de.symeda.sormas.api.exposure.ExposureType) PersonDto(de.symeda.sormas.api.person.PersonDto) Matchers.nullValue(org.hamcrest.Matchers.nullValue) UserRole(de.symeda.sormas.api.user.UserRole) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) 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) ContactDto(de.symeda.sormas.api.contact.ContactDto) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) Matchers.is(org.hamcrest.Matchers.is) 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) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) RunWith(org.junit.runner.RunWith) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) QuarantineType(de.symeda.sormas.api.contact.QuarantineType) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) Calendar(java.util.Calendar) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AnimalCondition(de.symeda.sormas.api.epidata.AnimalCondition) DataHelper(de.symeda.sormas.api.utils.DataHelper) SormasToSormasShareRequestDto(de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto) Test(org.junit.Test) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) SormasToSormasConfig(de.symeda.sormas.api.sormastosormas.SormasToSormasConfig) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Mockito(org.mockito.Mockito) ExposureDto(de.symeda.sormas.api.exposure.ExposureDto) Disease(de.symeda.sormas.api.Disease) SampleDto(de.symeda.sormas.api.sample.SampleDto) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) Collections(java.util.Collections) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) User(de.symeda.sormas.backend.user.User) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) PersonDto(de.symeda.sormas.api.person.PersonDto) Calendar(java.util.Calendar) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 4 with SormasToSormasException

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));
}
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 SormasToSormasException

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"));
}
Also used : 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) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) UserDto(de.symeda.sormas.api.user.UserDto) 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) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) Date(java.util.Date) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) SormasToSormasOptionsDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto) SormasToSormasEventParticipantDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventParticipantDto) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Aggregations

SormasToSormasException (de.symeda.sormas.api.sormastosormas.SormasToSormasException)17 SormasServerDescriptor (de.symeda.sormas.api.sormastosormas.SormasServerDescriptor)13 SormasToSormasEncryptedDataDto (de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto)13 ShareRequestStatus (de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus)13 Collections (java.util.Collections)13 List (java.util.List)13 Disease (de.symeda.sormas.api.Disease)12 PersonDto (de.symeda.sormas.api.person.PersonDto)12 SormasToSormasOptionsDto (de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto)12 SormasToSormasShareInfoCriteria (de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria)12 SormasToSormasShareInfoDto (de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto)12 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)12 UserRole (de.symeda.sormas.api.user.UserRole)12 DataHelper (de.symeda.sormas.api.utils.DataHelper)12 MockProducer (de.symeda.sormas.backend.MockProducer)12 SormasToSormasTest (de.symeda.sormas.backend.sormastosormas.SormasToSormasTest)12 User (de.symeda.sormas.backend.user.User)12 Response (javax.ws.rs.core.Response)12 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)12 Matchers.hasSize (org.hamcrest.Matchers.hasSize)12