Search in sources :

Example 16 with SormasToSormasOriginInfoDto

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

the class SormasToSormasEventFacadeEjbTest method testReturnEvent.

@Test
public void testReturnEvent() 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);
        e.setSormasToSormasOriginInfo(originInfo);
    });
    SormasToSormasShareRequestDto shareRequest = new SormasToSormasShareRequestDto();
    shareRequest.setUuid(DataHelper.createUuid());
    shareRequest.setOriginInfo(event.getSormasToSormasOriginInfo());
    getSormasToSormasShareRequestFacade().saveShareRequest(shareRequest);
    PersonDto person = creator.createPerson();
    EventParticipantDto eventParticipant = creator.createEventParticipant(event.toReference(), person, "Involved", officer, (p) -> p.setSormasToSormasOriginInfo(event.getSormasToSormasOriginInfo()), null);
    SormasToSormasOptionsDto options = new SormasToSormasOptionsDto();
    options.setOrganization(new SormasServerDescriptor(SECOND_SERVER_ID));
    options.setHandOverOwnership(true);
    options.setWithEventParticipants(true);
    options.setComment("Test comment");
    Mockito.when(MockProducer.getSormasToSormasClient().post(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> Response.noContent().build());
    getSormasToSormasEventFacade().share(Collections.singletonList(event.getUuid()), options);
    // event ownership should be lost
    EventDto sharedEvent = getEventFacade().getEventByUuid(event.getUuid(), false);
    assertThat(sharedEvent.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(false));
    // sample ownership should be lost
    EventParticipantDto sharedEventParticipant = getEventParticipantFacade().getEventParticipantByUuid(eventParticipant.getUuid());
    assertThat(sharedEventParticipant.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) 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) SormasToSormasOptionsDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 17 with SormasToSormasOriginInfoDto

use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto 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);
}
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) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) SormasToSormasEventDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) Calendar(java.util.Calendar) 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) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SormasToSormasEventParticipantDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventParticipantDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 18 with SormasToSormasOriginInfoDto

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

the class AbstractSormasToSormasInterface method sendShareRequest.

/**
 * Send a S2S share request for the ADOs identified by the given UUIDs to a remote S2S instance specified by options.
 *
 * @param entityUuids
 *            The entities for which should be delivered to the remote as preview.
 * @param options
 *            S2S request options also including the receiver.
 * @throws SormasToSormasException
 *             Errors out in case validation fails or request cannot be sent.
 */
private void sendShareRequest(List<String> entityUuids, SormasToSormasOptionsDto options) throws SormasToSormasException {
    User currentUser = userService.getCurrentUser();
    List<ADO> entities = getEntityService().getByUuids(entityUuids);
    if (options.isHandOverOwnership()) {
        validateOwnership(entities);
        ensureConsistentOptions(options);
    }
    validateEntitiesBeforeShare(entities, options.isHandOverOwnership());
    String requestUuid = DataHelper.createUuid();
    ShareRequestInfo shareRequestInfo = createShareRequestInfoForEntities(requestUuid, ShareRequestStatus.PENDING, options, entities, currentUser, false);
    ShareRequestPreviews previewsToSend = shareDataBuilder.buildShareDataPreview(shareRequestInfo);
    SormasToSormasOriginInfoDto originInfo = dataBuilderHelper.createSormasToSormasOriginInfo(currentUser, options);
    sormasToSormasRestClient.post(options.getOrganization().getId(), requestEndpoint, new ShareRequestData(requestUuid, previewsToSend, originInfo), null);
    // remove shares to the origin
    shareRequestInfoService.ensurePersisted(shareRequestInfo);
}
Also used : User(de.symeda.sormas.backend.user.User) ShareRequestPreviews(de.symeda.sormas.backend.sormastosormas.share.sharerequest.ShareRequestPreviews) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) ShareRequestData(de.symeda.sormas.backend.sormastosormas.share.ShareRequestData)

Example 19 with SormasToSormasOriginInfoDto

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

the class ReceivedEntitiesProcessor method processReceivedData.

public List<ValidationErrors> processReceivedData(SormasToSormasDto receivedData, ShareDataExistingEntities existingEntities) {
    List<ValidationErrors> validationErrors = new ArrayList<>();
    SormasToSormasOriginInfoDto originInfo = receivedData.getOriginInfo();
    originInfo.setUuid(DataHelper.createUuid());
    originInfo.setChangeDate(new Date());
    ValidationErrors originInfoErrors = validateOriginInfo(originInfo, Captions.sormasToSormasOriginInfo);
    if (originInfoErrors.hasError()) {
        validationErrors.add(originInfoErrors);
    }
    List<SormasToSormasCaseDto> cases = receivedData.getCases();
    if (CollectionUtils.isNotEmpty(cases)) {
        cases.forEach(c -> {
            ValidationErrors caseErrors = caseProcessor.processReceivedData(c, existingEntities.getCases().get(c.getEntity().getUuid()));
            if (caseErrors.hasError()) {
                validationErrors.add(new ValidationErrors(ValidationHelper.buildCaseValidationGroupName(c.getEntity()), caseErrors));
            }
        });
    }
    List<SormasToSormasContactDto> contacts = receivedData.getContacts();
    if (CollectionUtils.isNotEmpty(contacts)) {
        contacts.forEach(c -> {
            ValidationErrors contactErrors = contactProcessor.processReceivedData(c, existingEntities.getContacts().get(c.getEntity().getUuid()));
            if (contactErrors.hasError()) {
                validationErrors.add(new ValidationErrors(ValidationHelper.buildContactValidationGroupName(c.getEntity()), contactErrors));
            }
        });
    }
    List<SormasToSormasEventDto> events = receivedData.getEvents();
    if (CollectionUtils.isNotEmpty(events)) {
        events.forEach(e -> {
            ValidationErrors eventErrors = eventProcessor.processReceivedData(e, existingEntities.getEvents().get(e.getEntity().getUuid()));
            if (eventErrors.hasError()) {
                validationErrors.add(new ValidationErrors(ValidationHelper.buildEventValidationGroupName(e.getEntity()), eventErrors));
            }
        });
    }
    List<SormasToSormasEventParticipantDto> eventParticipants = receivedData.getEventParticipants();
    if (CollectionUtils.isNotEmpty(eventParticipants)) {
        eventParticipants.forEach(ep -> {
            ValidationErrors eventParticipantErrors = eventParticipantProcessor.processReceivedData(ep, existingEntities.getEventParticipants().get(ep.getEntity().getUuid()));
            if (eventParticipantErrors.hasError()) {
                validationErrors.add(new ValidationErrors(ValidationHelper.buildEventParticipantValidationGroupName(ep.getEntity()), eventParticipantErrors));
            }
        });
    }
    List<SormasToSormasSampleDto> samples = receivedData.getSamples();
    if (CollectionUtils.isNotEmpty(samples)) {
        samples.forEach(s -> {
            ValidationErrors contactErrors = sampleProcessor.processReceivedData(s, existingEntities.getSamples().get(s.getEntity().getUuid()));
            if (contactErrors.hasError()) {
                validationErrors.add(new ValidationErrors(ValidationHelper.buildSampleValidationGroupName(s.getEntity()), contactErrors));
            }
        });
    }
    List<SormasToSormasImmunizationDto> immunizations = receivedData.getImmunizations();
    if (CollectionUtils.isNotEmpty(immunizations)) {
        immunizations.forEach(s -> {
            ValidationErrors immunizationErrors = immunizationProcessor.processReceivedData(s, existingEntities.getImmunizations().get(s.getEntity().getUuid()));
            if (immunizationErrors.hasError()) {
                validationErrors.add(new ValidationErrors(ValidationHelper.buildImmunizationValidationGroupName(s.getEntity()), immunizationErrors));
            }
        });
    }
    return validationErrors;
}
Also used : SormasToSormasEventDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto) ValidationErrors(de.symeda.sormas.api.sormastosormas.validation.ValidationErrors) ArrayList(java.util.ArrayList) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) Date(java.util.Date) SormasToSormasCaseDto(de.symeda.sormas.api.sormastosormas.caze.SormasToSormasCaseDto) SormasToSormasEventParticipantDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventParticipantDto) SormasToSormasImmunizationDto(de.symeda.sormas.api.sormastosormas.immunization.SormasToSormasImmunizationDto)

Example 20 with SormasToSormasOriginInfoDto

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

the class SormasToSormasListComponent method reloadList.

public void reloadList() {
    UI currentUI = UI.getCurrent();
    UserDto currentUser = FacadeProvider.getUserFacade().getCurrentUser();
    sormasToSormasList.showPlaceholder(I18nProperties.getString(Strings.sormasToSormasLoadingShares));
    Thread loadSharesThread = new Thread(() -> {
        try {
            I18nProperties.setUserLanguage(currentUser.getLanguage());
            FacadeProvider.getI18nFacade().setUserLanguage(currentUser.getLanguage());
            currentUI.setPollInterval(300);
            List<SormasToSormasShareTree> shareInfos = loadShares.load();
            String currentServerOrgId = FacadeProvider.getSormasToSormasFacade().getOrganizationId();
            List<SormasToSormasShareInfoDto> shareInfoList = getShareInfoList(shareInfos);
            SormasToSormasShareInfoDto ownerShare = getOwnerShare(shareInfos);
            SormasToSormasOriginInfoDto rootOrigin = findRootOriginInfo(shareInfos);
            List<String> directShareUuids = getDirectShares(shareInfos).stream().map(s -> s.getShare().getUuid()).collect(Collectors.toList());
            String ownerOrganizationId = getOwnerOrganizationId(ownerShare, rootOrigin, currentServerOrgId);
            boolean isOwnedByCurrentOrg = currentServerOrgId.equals(ownerOrganizationId);
            boolean isOwnedByOrigin = originInfo != null && originInfo.getOrganizationId().equals(ownerOrganizationId);
            boolean isOwnedByRootOrg = rootOrigin != null && rootOrigin.getOrganizationId().equals(ownerOrganizationId);
            currentUI.access(() -> {
                try {
                    // render origin
                    if (originInfo != null) {
                        HorizontalLayout originLayout = buildSormasOriginInfo(originInfo, isOwnedByOrigin);
                        originLayout.addStyleName(CssStyles.VSPACE_3);
                        addComponent(originLayout, getComponentIndex(sormasToSormasList));
                    }
                    // render the owner of the entity
                    if (!isOwnedByCurrentOrg && !isOwnedByOrigin) {
                        AbstractOrderedLayout ownerLayout = null;
                        if (isOwnedByRootOrg) {
                            ownerLayout = buildSormasOriginInfo(rootOrigin, true);
                        } else if (ownerShare != null && !ownerShare.getTargetDescriptor().getId().equals(currentServerOrgId)) {
                            ownerLayout = buildOwnerShareLayout(ownerShare);
                        }
                        if (ownerLayout != null) {
                            ownerLayout.addStyleName(CssStyles.VSPACE_3);
                            addComponent(ownerLayout, getComponentIndex(sormasToSormasList));
                        }
                    }
                    // show shares to other systems then owner and current one
                    List<SormasToSormasShareListEntryData> listData = shareInfoList.stream().filter(s -> {
                        String shareOrganizationId = s.getTargetDescriptor().getId();
                        if (ownerShare != null && shareOrganizationId.equals(ownerShare.getTargetDescriptor().getId())) {
                            return false;
                        }
                        if (originInfo != null && shareOrganizationId.equals(originInfo.getOrganizationId()) && // show return share
                        !(s.getRequestStatus() == ShareRequestStatus.PENDING && directShareUuids.contains(s.getUuid()))) {
                            return false;
                        }
                        if (isOwnedByRootOrg && shareOrganizationId.equals(rootOrigin.getOrganizationId())) {
                            return false;
                        }
                        return !shareOrganizationId.equals(currentServerOrgId);
                    }).map(s -> {
                        SormasToSormasShareListEntryData entryData = new SormasToSormasShareListEntryData();
                        entryData.shareUuid = s.getUuid();
                        entryData.target = s.getTargetDescriptor().getName();
                        entryData.sender = s.getSender().getShortCaption();
                        entryData.status = s.getRequestStatus();
                        entryData.creationDate = s.getCreationDate();
                        entryData.comment = s.getComment();
                        entryData.ownershipHandedOver = s.isOwnershipHandedOver();
                        entryData.responseComment = s.getResponseComment();
                        entryData.isDirectShare = directShareUuids.contains(s.getUuid());
                        return entryData;
                    }).collect(Collectors.toList());
                    // add the creator of the entity as a share
                    if (!isOwnedByRootOrg && rootOrigin != null && originInfo != null && !rootOrigin.getOrganizationId().equals(currentServerOrgId) && !rootOrigin.getOrganizationId().equals(originInfo.getOrganizationId())) {
                        SormasServerDescriptor serverDescriptor = FacadeProvider.getSormasToSormasFacade().getSormasServerDescriptorById(rootOrigin.getOrganizationId());
                        SormasToSormasShareListEntryData entryData = new SormasToSormasShareListEntryData();
                        entryData.shareUuid = null;
                        entryData.target = serverDescriptor.getName();
                        entryData.sender = rootOrigin.getSenderName();
                        entryData.status = ShareRequestStatus.ACCEPTED;
                        entryData.creationDate = rootOrigin.getCreationDate();
                        entryData.comment = rootOrigin.getComment();
                        entryData.ownershipHandedOver = rootOrigin.isOwnershipHandedOver();
                        listData.add(entryData);
                    }
                    if (shareInfoList.size() > 0) {
                        if (listData.size() > 0) {
                            Label shareListLabel = new Label(I18nProperties.getCaption(Captions.sormasToSormasSharedWith));
                            shareListLabel.addStyleNames(CssStyles.LABEL_BOLD, CssStyles.VSPACE_4);
                            addComponent(shareListLabel, getComponentIndex(sormasToSormasList));
                            sormasToSormasList.setData(listData);
                        } else {
                            sormasToSormasList.setVisible(false);
                        }
                    } else {
                        sormasToSormasList.showPlaceholder(null);
                    }
                } catch (Exception e) {
                    logger.error("Failed to load shares", e);
                    sormasToSormasList.showPlaceholder(I18nProperties.getString(Strings.errorSormasToSormasLoadShares));
                } finally {
                    currentUI.setPollInterval(-1);
                }
            });
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            currentUI.setPollInterval(-1);
            currentUI.access(() -> {
                sormasToSormasList.showPlaceholder(I18nProperties.getString(Strings.errorSormasToSormasLoadShares));
            });
        }
    });
    loadSharesThread.start();
}
Also used : SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) FeatureType(de.symeda.sormas.api.feature.FeatureType) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) PaginationList(de.symeda.sormas.ui.utils.PaginationList) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) Date(java.util.Date) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) DateFormatHelper(de.symeda.sormas.ui.utils.DateFormatHelper) VerticalLayout(com.vaadin.ui.VerticalLayout) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) LoggerFactory(org.slf4j.LoggerFactory) Alignment(com.vaadin.ui.Alignment) UI(com.vaadin.ui.UI) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) CssStyles(de.symeda.sormas.ui.utils.CssStyles) Label(com.vaadin.ui.Label) VaadinIcons(com.vaadin.icons.VaadinIcons) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) ValoTheme(com.vaadin.ui.themes.ValoTheme) Logger(org.slf4j.Logger) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) UserDto(de.symeda.sormas.api.user.UserDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) EventDto(de.symeda.sormas.api.event.EventDto) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) Collectors(java.util.stream.Collectors) Captions(de.symeda.sormas.api.i18n.Captions) Consumer(java.util.function.Consumer) List(java.util.List) Button(com.vaadin.ui.Button) Stream(java.util.stream.Stream) SampleDto(de.symeda.sormas.api.sample.SampleDto) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ContactDto(de.symeda.sormas.api.contact.ContactDto) Optional(java.util.Optional) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) UserDto(de.symeda.sormas.api.user.UserDto) Label(com.vaadin.ui.Label) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree) HorizontalLayout(com.vaadin.ui.HorizontalLayout) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) UI(com.vaadin.ui.UI) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout)

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