Search in sources :

Example 1 with ShareRequestDataType

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

the class ImmunizationFacadeEjb method syncSharesAsync.

@RolesAllowed(UserRight._IMMUNIZATION_EDIT)
public void syncSharesAsync(Immunization immunization) {
    // sync case/contact/event this immunization was shared with
    List<DataHelper.Pair<ShareRequestDataType, ShareTreeCriteria>> syncParams = immunization.getSormasToSormasShares().stream().map(immunizationShare -> ShareInfoHelper.getLatestAcceptedRequest(immunizationShare.getRequests().stream()).orElse(null)).filter(Objects::nonNull).map(ShareRequestInfo::getShares).flatMap(Collection::stream).map(s -> {
        if (s.getCaze() != null) {
            return new DataHelper.Pair<>(ShareRequestDataType.CASE, new ShareTreeCriteria(s.getCaze().getUuid()));
        }
        if (s.getContact() != null) {
            return new DataHelper.Pair<>(ShareRequestDataType.CONTACT, new ShareTreeCriteria(s.getContact().getUuid()));
        }
        if (s.getEvent() != null) {
            return new DataHelper.Pair<>(ShareRequestDataType.EVENT, new ShareTreeCriteria(s.getContact().getUuid()));
        }
        return null;
    }).filter(Objects::nonNull).collect(Collectors.toList());
    executorService.schedule(() -> {
        try {
            syncParams.forEach((p -> {
                if (p.getElement0() == ShareRequestDataType.CASE) {
                    sormasToSormasCaseFacade.syncShares(p.getElement1());
                }
                if (p.getElement0() == ShareRequestDataType.CONTACT) {
                    sormasToSormasContactFacade.syncShares(p.getElement1());
                }
                if (p.getElement0() == ShareRequestDataType.EVENT) {
                    sormasToSormasEventFacadeEjbLocal.syncShares(p.getElement1());
                }
            }));
        } catch (Exception e) {
            logger.error("Failed to sync shares of immunization", e);
        }
    }, 5, TimeUnit.SECONDS);
}
Also used : ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) RolesAllowed(javax.annotation.security.RolesAllowed) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) PathogenTestFacadeEjb(de.symeda.sormas.backend.sample.PathogenTestFacadeEjb) LoggerFactory(org.slf4j.LoggerFactory) ImmunizationFacade(de.symeda.sormas.api.immunization.ImmunizationFacade) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) CommunityFacadeEjb(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) AccessDeniedException(de.symeda.sormas.api.utils.AccessDeniedException) DistrictService(de.symeda.sormas.backend.infrastructure.district.DistrictService) PersonDto(de.symeda.sormas.api.person.PersonDto) CountryService(de.symeda.sormas.backend.infrastructure.country.CountryService) Valid(javax.validation.Valid) EntityDto(de.symeda.sormas.api.EntityDto) AbstractCoreFacadeEjb(de.symeda.sormas.backend.common.AbstractCoreFacadeEjb) CaseOutcome(de.symeda.sormas.api.caze.CaseOutcome) Page(de.symeda.sormas.api.common.Page) TransactionAttributeType(javax.ejb.TransactionAttributeType) ImmunizationReferenceDto(de.symeda.sormas.api.immunization.ImmunizationReferenceDto) SormasToSormasCaseFacadeEjb(de.symeda.sormas.backend.sormastosormas.entities.caze.SormasToSormasCaseFacadeEjb) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ImmunizationListEntryDto(de.symeda.sormas.api.immunization.ImmunizationListEntryDto) Vaccination(de.symeda.sormas.backend.vaccination.Vaccination) ImmunizationListCriteria(de.symeda.sormas.api.immunization.ImmunizationListCriteria) SormasToSormasOriginInfoFacadeEjb(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb) ManagedScheduledExecutorService(javax.enterprise.concurrent.ManagedScheduledExecutorService) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) FacilityService(de.symeda.sormas.backend.infrastructure.facility.FacilityService) CaseService(de.symeda.sormas.backend.caze.CaseService) CountryFacadeEjb(de.symeda.sormas.backend.infrastructure.country.CountryFacadeEjb) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) CommunityService(de.symeda.sormas.backend.infrastructure.community.CommunityService) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) ShareRequestDataType(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestDataType) Resource(javax.annotation.Resource) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) NotNull(javax.validation.constraints.NotNull) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) List(java.util.List) ImmunizationCriteria(de.symeda.sormas.api.immunization.ImmunizationCriteria) UserService(de.symeda.sormas.backend.user.UserService) DistrictFacadeEjb(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb) User(de.symeda.sormas.backend.user.User) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) EditPermissionType(de.symeda.sormas.api.EditPermissionType) LocalDate(java.time.LocalDate) CoreEntityType(de.symeda.sormas.api.common.CoreEntityType) SormasToSormasContactFacadeEjb(de.symeda.sormas.backend.sormastosormas.entities.contact.SormasToSormasContactFacadeEjb) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) DateHelper(de.symeda.sormas.api.utils.DateHelper) FacilityFacadeEjb(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb) CaseFacadeEjb(de.symeda.sormas.backend.caze.CaseFacadeEjb) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) Inject(javax.inject.Inject) DeletionDetails(de.symeda.sormas.api.common.DeletionDetails) TransactionAttribute(javax.ejb.TransactionAttribute) LocalBean(javax.ejb.LocalBean) SampleFacadeEjb(de.symeda.sormas.backend.sample.SampleFacadeEjb) VaccinationFacadeEjbLocal(de.symeda.sormas.backend.vaccination.VaccinationFacadeEjb.VaccinationFacadeEjbLocal) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) Logger(org.slf4j.Logger) Validations(de.symeda.sormas.api.i18n.Validations) DataHelper(de.symeda.sormas.api.utils.DataHelper) PersonFacadeEjb(de.symeda.sormas.backend.person.PersonFacadeEjb) SormasToSormasFacadeEjb(de.symeda.sormas.backend.sormastosormas.SormasToSormasFacadeEjb) ImmunizationIndexDto(de.symeda.sormas.api.immunization.ImmunizationIndexDto) PersonService(de.symeda.sormas.backend.person.PersonService) SortProperty(de.symeda.sormas.api.utils.SortProperty) RegionFacadeEjb(de.symeda.sormas.backend.infrastructure.region.RegionFacadeEjb) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) Captions(de.symeda.sormas.api.i18n.Captions) TimeUnit(java.util.concurrent.TimeUnit) UserRight(de.symeda.sormas.api.user.UserRight) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) ImmunizationSimilarityCriteria(de.symeda.sormas.api.immunization.ImmunizationSimilarityCriteria) ImmunizationStatus(de.symeda.sormas.api.immunization.ImmunizationStatus) ShareInfoHelper(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareInfoHelper) Comparator(java.util.Comparator) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) SormasToSormasEventFacadeEjb(de.symeda.sormas.backend.sormastosormas.entities.event.SormasToSormasEventFacadeEjb) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) AccessDeniedException(de.symeda.sormas.api.utils.AccessDeniedException) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) RolesAllowed(javax.annotation.security.RolesAllowed)

Aggregations

EditPermissionType (de.symeda.sormas.api.EditPermissionType)1 EntityDto (de.symeda.sormas.api.EntityDto)1 CaseCriteria (de.symeda.sormas.api.caze.CaseCriteria)1 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 CaseOutcome (de.symeda.sormas.api.caze.CaseOutcome)1 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)1 CoreEntityType (de.symeda.sormas.api.common.CoreEntityType)1 DeletionDetails (de.symeda.sormas.api.common.DeletionDetails)1 Page (de.symeda.sormas.api.common.Page)1 Captions (de.symeda.sormas.api.i18n.Captions)1 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)1 Strings (de.symeda.sormas.api.i18n.Strings)1 Validations (de.symeda.sormas.api.i18n.Validations)1 ImmunizationCriteria (de.symeda.sormas.api.immunization.ImmunizationCriteria)1 ImmunizationDto (de.symeda.sormas.api.immunization.ImmunizationDto)1 ImmunizationFacade (de.symeda.sormas.api.immunization.ImmunizationFacade)1 ImmunizationIndexDto (de.symeda.sormas.api.immunization.ImmunizationIndexDto)1 ImmunizationListCriteria (de.symeda.sormas.api.immunization.ImmunizationListCriteria)1 ImmunizationListEntryDto (de.symeda.sormas.api.immunization.ImmunizationListEntryDto)1 ImmunizationManagementStatus (de.symeda.sormas.api.immunization.ImmunizationManagementStatus)1