Commit 0cdac8cc authored by Anastasios Poimenidis's avatar Anastasios Poimenidis
Browse files

fix: update logic to reflect relatedParty and various other schema changes

parent 4d5a49cc
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@ import jakarta.transaction.Transactional;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.etsi.osl.hypo.api.tmf.agreement.api.repository.AgreementRepository;
import org.etsi.osl.hypo.api.tmf.agreement.schema.Agreement;
@@ -78,16 +80,15 @@ public class AgreementService {
    }

    private void findRelatedPartyAndAddItToResource(Agreement agreement) {
        List<RelatedPartyEntity> engagedParty = agreement.getEngagedParty();
        Set<RelatedPartyEntity> engagedParty = agreement.getEngagedParty();

        if (CollectionUtils.isNotEmpty(engagedParty)) {
            List<String> partyIds = engagedParty.stream().map(RelatedPartyEntity::getId).toList();
            Set<String> partyIds =
                    engagedParty.stream().map(RelatedPartyEntity::getId).collect(Collectors.toSet());
            // find and relate parties
            List<RelatedPartyEntity> relatedPartyEntities =
                    relatedPartyRepository.findByIdsList(partyIds);
            Set<RelatedPartyEntity> relatedPartyEntities = relatedPartyRepository.findByIdsSet(partyIds);

            engagedParty.clear();
            engagedParty.addAll(relatedPartyEntities);
            agreement.setEngagedParty(relatedPartyEntities);
        }
    }

+7 −6
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@ import jakarta.transaction.Transactional;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.etsi.osl.hypo.api.tmf.agreement.api.repository.AgreementSpecificationRepository;
import org.etsi.osl.hypo.api.tmf.agreement.schema.AgreementSpecification;
@@ -86,16 +88,15 @@ public class AgreementSpecificationService {
    }

    private void findRelatedPartyAndAddItToResource(AgreementSpecification agreementSpecification) {
        List<RelatedPartyEntity> relatedParty = agreementSpecification.getRelatedParty();
        Set<RelatedPartyEntity> relatedParty = agreementSpecification.getRelatedParty();

        if (CollectionUtils.isNotEmpty(relatedParty)) {
            List<String> partyIds = relatedParty.stream().map(RelatedPartyEntity::getId).toList();
            Set<String> partyIds =
                    relatedParty.stream().map(RelatedPartyEntity::getId).collect(Collectors.toSet());
            // find and relate parties
            List<RelatedPartyEntity> relatedPartyEntities =
                    relatedPartyRepository.findByIdsList(partyIds);
            Set<RelatedPartyEntity> relatedPartyEntities = relatedPartyRepository.findByIdsSet(partyIds);

            relatedParty.clear();
            relatedParty.addAll(relatedPartyEntities);
            agreementSpecification.setRelatedParty(relatedPartyEntities);
        }
    }

+12 −18
Original line number Diff line number Diff line
@@ -6,9 +6,11 @@ import static org.etsi.osl.hypo.core.common.constants.ServiceOrderWithPackageMan
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;
import org.apache.commons.lang3.StringUtils;
import org.etsi.osl.hypo.api.tmf.common.api.model.RelatedPartyDTO;
import org.etsi.osl.hypo.api.tmf.party.api.services.OrganizationService;
import org.etsi.osl.hypo.api.tmf.party.organization.schema.Organization;
import org.etsi.osl.hypo.api.tmf.services.catalog.api.services.ServiceCategoryService;
@@ -153,16 +155,12 @@ public class ServiceSpecificationHelpers {
            AtomicReference<Boolean> hasPeeredOrganization) {
        final String serviceSpecificationId = serviceSpecificationRef.getId();

        Optional<ServiceSpecificationEntity> serviceSpecificationEntity =
                serviceSpecificationService.getSpecificationById(serviceSpecificationId);
        Set<RelatedPartyDTO> relatedPartyBySpecificationId =
                serviceSpecificationService.getRelatedPartyBySpecificationId(serviceSpecificationId);

        serviceSpecificationEntity.ifPresent(
                serviceSpecificationEntityPresent -> {
        Optional<Organization> organization =
                            organizationService.getPeeredOrganizationForSpecification(
                                    serviceSpecificationEntityPresent);
                organizationService.getPeeredOrganizationForSpecification(relatedPartyBySpecificationId);
        organization.ifPresent(organizationPresent -> hasPeeredOrganization.set(Boolean.TRUE));
                });
    }

    private void hasPeeredServiceSpecification(
@@ -170,16 +168,12 @@ public class ServiceSpecificationHelpers {
            AtomicReference<Boolean> hasPeeredOrganization) {
        final String serviceSpecificationId = serviceSpecificationRef.getId();

        Optional<ServiceSpecificationEntity> serviceSpecificationEntity =
                serviceSpecificationService.getSpecificationById(serviceSpecificationId);
        Set<RelatedPartyDTO> relatedPartyBySpecificationId =
                serviceSpecificationService.getRelatedPartyBySpecificationId(serviceSpecificationId);

        serviceSpecificationEntity.ifPresent(
                serviceSpecificationEntityPresent -> {
        Optional<Organization> organization =
                            organizationService.getPeeredOrganizationForSpecification(
                                    serviceSpecificationEntityPresent);
                organizationService.getPeeredOrganizationForSpecification(relatedPartyBySpecificationId);
        organization.ifPresent(organizationPresent -> hasPeeredOrganization.set(Boolean.TRUE));
                });
    }

    private boolean isServiceSpecificationContainedInCategory(
+14 −14
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import static org.etsi.osl.hypo.api.tmf.common.constants.OssConstants.PEERED_ORG

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
@@ -81,7 +81,7 @@ public class PeeringHelper {
                organizationId, FIVE_G_SERVICES);

        // find or create categories and populate persisted candidates
        List<ServiceCategoryEntity> serviceCategoryEntitiesPersisted =
        Set<ServiceCategoryEntity> serviceCategoryEntitiesPersisted =
                getPersistedCategories(peeredOrganizationData, serviceCandidateSetPersisted);

        logger.infof("Peering for organization %s: added service categories", organizationId);
@@ -221,10 +221,10 @@ public class PeeringHelper {
        serviceCategoryService.add5GCandidates(serviceCandidateEntities);
    }

    private List<ServiceCategoryEntity> getPersistedCategories(
    private Set<ServiceCategoryEntity> getPersistedCategories(
            PeeredOrganizationData peeredOrganizationData,
            Set<ServiceCandidateEntity> serviceCandidateEntitySet) {
        List<ServiceCategoryEntity> serviceCategoryIds = new ArrayList<>();
        Set<ServiceCategoryEntity> serviceCategoryIds = new HashSet<>();

        List<ServiceCatalog> serviceCatalogs = peeredOrganizationData.getServiceCatalogs();

@@ -237,7 +237,7 @@ public class PeeringHelper {
                    categories.forEach(
                            serviceCategory -> {
                                List<String> serviceSpecificationNames = serviceCategory.getSpecifications();
                                List<String> serviceSpecificationIdsInCategory =
                                Set<String> serviceSpecificationIdsInCategory =
                                        getServiceSpecIds(serviceSpecificationNames, serviceCandidateEntitySet);
                                ServiceCategoryEntity serviceCategoryEntity =
                                        populateCategory(serviceCategory, serviceSpecificationIdsInCategory);
@@ -255,14 +255,14 @@ public class PeeringHelper {
     * @param serviceCandidateEntitySet
     * @return
     */
    private List<String> getServiceSpecIds(
    private Set<String> getServiceSpecIds(
            List<String> serviceSpecificationNames,
            Set<ServiceCandidateEntity> serviceCandidateEntitySet) {

        return serviceCandidateEntitySet.stream()
                .filter(specificationMatchesName(serviceSpecificationNames))
                .map(BaseEntity::getId)
                .toList();
                .collect(Collectors.toSet());
    }

    private static Predicate<ServiceCandidateEntity> specificationMatchesName(
@@ -275,7 +275,7 @@ public class PeeringHelper {
    }

    private ServiceCategoryEntity populateCategory(
            ServiceCategory serviceCategory, List<String> serviceSpecificationIds) {
            ServiceCategory serviceCategory, Set<String> serviceSpecificationIds) {
        ServiceCategoryEntity serviceCategoryEntity = new ServiceCategoryEntity();
        serviceCategoryEntity.setName(serviceCategory.getName());

@@ -285,7 +285,7 @@ public class PeeringHelper {

    private void populateCatalogs(
            PeeredOrganizationData peeredOrganizationData,
            List<ServiceCategoryEntity> serviceCategoryEntities) {
            Set<ServiceCategoryEntity> serviceCategoryEntities) {
        List<ServiceCatalog> serviceCatalogs = peeredOrganizationData.getServiceCatalogs();

        if (CollectionUtils.isEmpty(serviceCatalogs)) return;
@@ -296,19 +296,19 @@ public class PeeringHelper {
                    serviceCatalogEntity.setName(serviceCatalog.getName());

                    List<ServiceCategory> serviceCategoryNames = serviceCatalog.getCategories();
                    List<String> serviceCategoryIds =
                    Set<String> serviceCategoryIds =
                            getServiceCategoryIds(serviceCategoryEntities, serviceCategoryNames);

                    String relatedPartyUUID = peeredOrganizationData.getOrganizationId();
                    List<String> relatedPartyIds = List.of(relatedPartyUUID);
                    Set<String> relatedPartyIds = Set.of(relatedPartyUUID);

                    serviceCatalogService.findOrCreateCatalogEntity(
                            serviceCatalogEntity, serviceCategoryIds, relatedPartyIds);
                });
    }

    private static List<String> getServiceCategoryIds(
            List<ServiceCategoryEntity> serviceCategoryEntities,
    private static Set<String> getServiceCategoryIds(
            Set<ServiceCategoryEntity> serviceCategoryEntities,
            List<ServiceCategory> serviceCategoryNames) {
        return serviceCategoryEntities.stream()
                .filter(
@@ -320,6 +320,6 @@ public class PeeringHelper {
                                                    return name.equalsIgnoreCase(serviceCategoryEntity.getName());
                                                }))
                .map(BaseEntity::getId)
                .toList();
                .collect(Collectors.toSet());
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ public interface UpdateMapper {
    @Mapping(target = "orderItem.entityId", ignore = true)
    @Mapping(target = "orderItem.appointment.entityId", ignore = true)
    @Mapping(target = "orderItem.resourceSpecification.entityId", ignore = true)
    @Mapping(target = "relatedParty", ignore = true)
    @Mapping(target = "orderItem.orderItemRelationship.orderItem.entityId", ignore = true)
    @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
    ResourceOrder updateResourceOrder(
@@ -57,6 +58,7 @@ public interface UpdateMapper {

    @Mapping(target = "entityId", ignore = true)
    @Mapping(target = "resourceSpecification.entityId", ignore = true)
    @Mapping(target = "relatedParty", ignore = true)
    @Mapping(target = "resourceSpecification.resourceRelationship.resource.entityId", ignore = true)
    @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
    Resource updateResource(Resource newResource, @MappingTarget Resource oldResource);
Loading