Loading .gitlab-ci.yml +1 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ dev_tests_job: stage: dev_test tags: - hypo image: labs.etsi.org:5050/osl/hypo/code/org.etsi.osl.hypo.ops/cicd/integration.tests/maven:3.8.3-openjdk-17-slim image: labs.etsi.org:5050/osl/hypo/code/org.etsi.osl.hypo.ops/cicd/integration.tests/maven:3.9.16-eclipse-temurin-17 before_script: - curl -fsSL https://get.docker.com -o get-docker.sh Loading pom.xml +1 −7 Original line number Diff line number Diff line Loading @@ -196,13 +196,7 @@ <dependency> <groupId>org.etsi.osl.hypo.api</groupId> <artifactId>tmf.schema</artifactId> <version>2.4.1</version> </dependency> <dependency> <groupId>org.etsi.osl.hypo.api</groupId> <artifactId>tmf.common</artifactId> <version>1.1.0</version> <version>2.5.2</version> </dependency> <dependency> Loading src/main/java/org/etsi/osl/hypo/api/tmf/agreement/api/services/AgreementService.java +18 −18 Original line number Diff line number Diff line Loading @@ -6,6 +6,9 @@ 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; import org.etsi.osl.hypo.api.tmf.common.api.mapper.UpdateMapper; Loading Loading @@ -70,26 +73,23 @@ public class AgreementService { @Transactional public Agreement createAgreement(Agreement agreement) { checkIfTmfIdExists(agreement.getTmfId()); if (agreement.getEngagedParty() != null && !agreement.getEngagedParty().isEmpty()) { agreement = findRelatedPartyAndAddItToResource(agreement); } checkIfIdExists(agreement.getId()); findRelatedPartyAndAddItToResource(agreement); agreementRepository.persist(agreement); return agreement; } private Agreement findRelatedPartyAndAddItToResource(Agreement agreement) { List<String> partyIds = agreement.getEngagedParty().stream().map(RelatedPartyEntity::getTmfId).toList(); private void findRelatedPartyAndAddItToResource(Agreement agreement) { Set<RelatedPartyEntity> engagedParty = agreement.getEngagedParty(); if (CollectionUtils.isNotEmpty(engagedParty)) { 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); agreement.getEngagedParty().clear(); agreement.getEngagedParty().addAll(relatedPartyEntities); return agreement; agreement.setEngagedParty(relatedPartyEntities); } } @Transactional Loading Loading @@ -117,13 +117,13 @@ public class AgreementService { return agreement; } private void checkIfTmfIdExists(String tmfId) { if (tmfIdExists(tmfId)) { throw new DuplicateKeyException(AGREEMENT_WITH_ID + tmfId + " already exists"); private void checkIfIdExists(String id) { if (iddExists(id)) { throw new DuplicateKeyException(AGREEMENT_WITH_ID + id + " already exists"); } } public boolean tmfIdExists(String id) { public boolean iddExists(String id) { return agreementRepository.findById(id).isPresent(); } } src/main/java/org/etsi/osl/hypo/api/tmf/agreement/api/services/AgreementSpecificationService.java +18 −20 Original line number Diff line number Diff line Loading @@ -6,6 +6,9 @@ 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; import org.etsi.osl.hypo.api.tmf.common.api.mapper.UpdateMapper; Loading Loading @@ -76,30 +79,25 @@ public class AgreementSpecificationService { @Transactional public AgreementSpecification createAgreementSpecification( AgreementSpecification agreementSpecification) { checkIfTmfIdExists(agreementSpecification.getTmfId()); checkIfIdExists(agreementSpecification.getId()); if (agreementSpecification.getRelatedParty() != null && !agreementSpecification.getRelatedParty().isEmpty()) { agreementSpecification = findRelatedPartyAndAddItToResource(agreementSpecification); } findRelatedPartyAndAddItToResource(agreementSpecification); agreementSpecificationRepository.persist(agreementSpecification); return agreementSpecification; } private AgreementSpecification findRelatedPartyAndAddItToResource( AgreementSpecification agreementSpecification) { List<String> partyIds = agreementSpecification.getRelatedParty().stream() .map(RelatedPartyEntity::getTmfId) .toList(); private void findRelatedPartyAndAddItToResource(AgreementSpecification agreementSpecification) { Set<RelatedPartyEntity> relatedParty = agreementSpecification.getRelatedParty(); if (CollectionUtils.isNotEmpty(relatedParty)) { 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); agreementSpecification.getRelatedParty().clear(); agreementSpecification.getRelatedParty().addAll(relatedPartyEntities); return agreementSpecification; agreementSpecification.setRelatedParty(relatedPartyEntities); } } @Transactional Loading Loading @@ -130,13 +128,13 @@ public class AgreementSpecificationService { return agreementSpecification; } private void checkIfTmfIdExists(String tmfId) { if (tmfIdExists(tmfId)) { throw new DuplicateKeyException(AGREEMENT_SPECIFICATION_WITH_ID + tmfId + " already exists"); private void checkIfIdExists(String id) { if (idExists(id)) { throw new DuplicateKeyException(AGREEMENT_SPECIFICATION_WITH_ID + id + " already exists"); } } public boolean tmfIdExists(String id) { public boolean idExists(String id) { return agreementSpecificationRepository.findById(id).isPresent(); } } src/main/java/org/etsi/osl/hypo/api/tmf/common/api/helpers/ServiceSpecificationHelpers.java→src/main/java/org/etsi/osl/hypo/api/tmf/common/api/helpers/ServiceCatalogHelper.java +190 −27 Original line number Diff line number Diff line Loading @@ -5,42 +5,70 @@ import static org.etsi.osl.hypo.core.common.constants.ServiceOrderWithPackageMan import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Strings; import org.etsi.osl.hypo.api.tmf.common.api.model.RelatedPartyDTO; import org.etsi.osl.hypo.api.tmf.common.schema.RelatedPartyEntity; 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.repository.ServiceSpecificationRepository; import org.etsi.osl.hypo.api.tmf.services.catalog.api.services.ServiceCategoryService; import org.etsi.osl.hypo.api.tmf.services.catalog.api.services.ServiceSpecificationService; import org.etsi.osl.hypo.api.tmf.services.catalog.schema.ServiceCandidateEntity; import org.etsi.osl.hypo.api.tmf.services.catalog.schema.ServiceCategoryEntity; import org.etsi.osl.hypo.api.tmf.services.catalog.schema.ServiceSpecificationEntity; import org.etsi.osl.hypo.api.tmf.services.common.schema.ServiceRefOrValue; import org.etsi.osl.hypo.api.tmf.services.common.model.ServiceRefOrValue; import org.etsi.osl.hypo.api.tmf.services.common.schema.ServiceSpecificationRef; import org.etsi.osl.hypo.api.tmf.services.common.service.RelatedPartyHelper; import org.etsi.osl.hypo.api.tmf.services.inventory.api.mappers.ServiceMapper; import org.etsi.osl.hypo.api.tmf.services.inventory.schema.Service; import org.etsi.osl.hypo.api.tmf.services.model.ServiceWithPeeredOrganization; import org.etsi.osl.hypo.api.tmf.services.order.model.common.ServiceOrderItem; import org.etsi.osl.hypo.api.tmf.services.order.schema.ServiceOrderItemEntity; @ApplicationScoped public class ServiceSpecificationHelpers { public class ServiceCatalogHelper { private final ServiceCategoryService serviceCategoryService; private final ServiceSpecificationService serviceSpecificationService; private final ServiceSpecificationRepository serviceSpecificationRepository; private final OrganizationService organizationService; private final RelatedPartyHelper relatedPartyHelper; private final ServiceMapper serviceMapper; @Inject public ServiceSpecificationHelpers( public ServiceCatalogHelper( ServiceCategoryService serviceCategoryService, ServiceSpecificationService serviceInventoryService, OrganizationService organizationService) { ServiceSpecificationRepository serviceSpecificationRepository, OrganizationService organizationService, RelatedPartyHelper relatedPartyHelper, ServiceMapper serviceMapper) { this.serviceCategoryService = serviceCategoryService; this.serviceSpecificationService = serviceInventoryService; this.serviceSpecificationRepository = serviceSpecificationRepository; this.organizationService = organizationService; this.relatedPartyHelper = relatedPartyHelper; this.serviceMapper = serviceMapper; } public boolean hasSpecificationOrParentSpecificationByName( Service service, String serviceSpecificationName) { ServiceSpecificationRef serviceSpecificationRef, String serviceSpecificationName) { return serviceSpecificationService.serviceSpecificationMatchesByNameOrParentName( service, serviceSpecificationName); serviceSpecificationRef, serviceSpecificationName); } public List<Service> filterKubernetesServices(List<Service> services, Boolean isKubernetes) { return isKubernetes != null && isKubernetes ? services.stream().filter(this::hasSpecificationKubernetesCFS).toList() : services; } public boolean hasSpecificationKubernetesCFS(Service service) { Loading @@ -58,6 +86,22 @@ public class ServiceSpecificationHelpers { return isK8sSpecification.get(); } public boolean hasSpecificationKubernetesCFS(ServiceSpecificationRef serviceSpecificationRef) { AtomicReference<Boolean> isK8sSpecification = new AtomicReference<>(); isK8sSpecification.set(Boolean.FALSE); Optional<ServiceCategoryEntity> optionalServiceCategoryEntity = serviceCategoryService.findServiceCategoryByName(K8S_SERVICES); optionalServiceCategoryEntity.ifPresent( serviceCategoryEntity -> isK8sSpecification.set( isServiceSpecificationContainedInCategory( serviceSpecificationRef, serviceCategoryEntity))); return isK8sSpecification.get(); } public boolean isSpecificationKubernetesCFS( ServiceSpecificationEntity serviceSpecificationEntity) { AtomicReference<Boolean> isK8sSpecification = new AtomicReference<>(); Loading @@ -81,6 +125,13 @@ public class ServiceSpecificationHelpers { && service.getServiceSpecification().getName().equals(STANDALONE_K8SAAS_CFS); } public boolean hasSpecificationKubernetesRegistrationCFS( ServiceSpecificationRef serviceSpecificationRef) { return serviceSpecificationRef != null && serviceSpecificationRef.getName() != null && serviceSpecificationRef.getName().equals(STANDALONE_K8SAAS_CFS); } public boolean hasSpecificationKubernetesCFS(ServiceRefOrValue serviceRefOrValue) { AtomicReference<Boolean> isK8sSpecification = new AtomicReference<>(); isK8sSpecification.set(Boolean.FALSE); Loading @@ -97,16 +148,13 @@ public class ServiceSpecificationHelpers { return isK8sSpecification.get(); } public boolean hasPeeredSpecification(Service service) { if (service == null || service.getServiceSpecification() == null) { public boolean hasPeeredSpecification(ServiceSpecificationRef serviceSpecificationRef) { if (serviceSpecificationRef == null) { return false; } AtomicReference<Boolean> hasPeeredOrganization = new AtomicReference<>(); hasPeeredOrganization.set(Boolean.FALSE); ServiceSpecificationRef serviceSpecificationRef = service.getServiceSpecification(); hasPeeredServiceSpecification(serviceSpecificationRef, hasPeeredOrganization); return hasPeeredOrganization.get(); Loading @@ -120,7 +168,8 @@ public class ServiceSpecificationHelpers { AtomicReference<Boolean> hasPeeredOrganization = new AtomicReference<>(); hasPeeredOrganization.set(Boolean.FALSE); ServiceSpecificationRef serviceSpecificationRef = serviceRefOrValue.getServiceSpecification(); org.etsi.osl.hypo.api.tmf.common.model.ServiceSpecificationRef serviceSpecificationRef = serviceRefOrValue.getServiceSpecification(); hasPeeredServiceSpecification(serviceSpecificationRef, hasPeeredOrganization); Loading @@ -130,18 +179,27 @@ public class ServiceSpecificationHelpers { private void hasPeeredServiceSpecification( ServiceSpecificationRef serviceSpecificationRef, AtomicReference<Boolean> hasPeeredOrganization) { final String serviceSpecificationId = serviceSpecificationRef.getTmfId(); 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.getPeeredOrganizationForRelatedPartySet(relatedPartyBySpecificationId); organization.ifPresent(organizationPresent -> hasPeeredOrganization.set(Boolean.TRUE)); } private void hasPeeredServiceSpecification( org.etsi.osl.hypo.api.tmf.common.model.ServiceSpecificationRef serviceSpecificationRef, AtomicReference<Boolean> hasPeeredOrganization) { final String serviceSpecificationId = serviceSpecificationRef.getId(); Set<RelatedPartyDTO> relatedPartyBySpecificationId = serviceSpecificationService.getRelatedPartyBySpecificationId(serviceSpecificationId); Optional<Organization> organization = organizationService.getPeeredOrganizationForRelatedPartySet(relatedPartyBySpecificationId); organization.ifPresent(organizationPresent -> hasPeeredOrganization.set(Boolean.TRUE)); }); } private boolean isServiceSpecificationContainedInCategory( Loading @@ -151,6 +209,14 @@ public class ServiceSpecificationHelpers { .anyMatch(getServiceSpecificationEntityPredicate(serviceRefOrValue)); } private boolean isServiceSpecificationContainedInCategory( ServiceSpecificationRef serviceSpecificationRef, ServiceCategoryEntity serviceCategoryEntity) { return serviceCategoryEntity.getServiceCandidates().stream() .map(ServiceCandidateEntity::getServiceSpecification) .anyMatch(getServiceSpecificationEntityPredicate(serviceSpecificationRef)); } private boolean isServiceSpecificationContainedInCategory( ServiceSpecificationEntity serviceSpecificationEntity, ServiceCategoryEntity serviceCategoryEntity) { Loading @@ -170,23 +236,120 @@ public class ServiceSpecificationHelpers { ServiceRefOrValue serviceRefOrValue) { return serviceSpecificationEntity -> serviceSpecificationEntity .getTmfId() .equals(serviceRefOrValue.getServiceSpecification().getTmfId()); .getId() .equals(serviceRefOrValue.getServiceSpecification().getId()); } private Predicate<ServiceSpecificationEntity> getServiceSpecificationEntityPredicate( ServiceSpecificationRef serviceSpecificationRef) { return serviceSpecificationEntity -> { String serviceSpecificationEntityId = serviceSpecificationEntity.getId(); return StringUtils.isNotBlank(serviceSpecificationEntityId) && serviceSpecificationEntityId.equals(serviceSpecificationRef.getId()); }; } private Predicate<ServiceSpecificationEntity> getServiceSpecificationEntityPredicate( ServiceSpecificationEntity serviceSpecificationEntityProvided) { return serviceSpecificationEntity -> serviceSpecificationEntity.getTmfId().equals(serviceSpecificationEntityProvided.getTmfId()); serviceSpecificationEntity.getId().equals(serviceSpecificationEntityProvided.getId()); } private Predicate<ServiceSpecificationEntity> getServiceSpecificationEntityPredicate( Service service) { return serviceSpecificationEntity -> service.getServiceSpecification() != null && service.getServiceSpecification().getTmfId() != null && StringUtils.equals( serviceSpecificationEntity.getTmfId(), service.getServiceSpecification().getTmfId()); && service.getServiceSpecification().getId() != null && Strings.CS.equals( serviceSpecificationEntity.getId(), service.getServiceSpecification().getId()); } public List<ServiceWithPeeredOrganization> filterKubernetesServicesWithPeeredOrganization( List<Service> services, Boolean isKubernetes) { return services.stream() .filter( service -> { boolean hasToBeKubernetesService = isKubernetes != null && isKubernetes && (this.hasSpecificationKubernetesCFS(service) || this.hasSpecificationKubernetesRegistrationCFS(service)); boolean doesNotHaveTobeKubernetesService = isKubernetes == null || !isKubernetes; return hasToBeKubernetesService || doesNotHaveTobeKubernetesService; }) .map( service -> { ServiceWithPeeredOrganization serviceWithPeeredOrganization = serviceMapper.toServiceWithPeeredOrganizationInfo(service); this.populateServiceWithPeeredOrganizationInfo(serviceWithPeeredOrganization); return serviceWithPeeredOrganization; }) .toList(); } private void populateServiceWithPeeredOrganizationInfo( ServiceWithPeeredOrganization serviceWithPeeredOrganization) { org.etsi.osl.hypo.api.tmf.common.model.ServiceSpecificationRef serviceSpecificationRef = serviceWithPeeredOrganization.getServiceSpecification(); if (Objects.nonNull(serviceSpecificationRef)) { Set<RelatedPartyDTO> relatedParties = serviceSpecificationService.getRelatedPartyBySpecificationId( serviceSpecificationRef.getId()); String relatedPartyId = CollectionUtils.isNotEmpty(relatedParties) ? relatedParties.iterator().next().getId() : null; if (Objects.nonNull(relatedPartyId)) { relatedPartyHelper .getOptionalOrganizationById(relatedPartyId) .ifPresent( organization -> { if (relatedPartyHelper.isPeeredOrganization(organization)) { serviceWithPeeredOrganization.setOrganizationProvider(organization.getName()); } }); } } } public List<ServiceSpecificationEntity> getServiceSpecificationEntitiesByOrganizationId( String organizationId) { return serviceSpecificationRepository.findServiceSpecificationIdsByOrganizationId( organizationId); } public Optional<ServiceSpecificationEntity> findSpecificationById(String specificationId) { return serviceSpecificationRepository.findById(specificationId); } public Predicate<ServiceOrderItemEntity> getServiceOrderItemByServiceSpecificationNameOrParentName(String serviceSpecificationName) { return serviceOrderItem -> { ServiceSpecificationRef serviceSpecificationRef = serviceOrderItem.getService().getServiceSpecification(); return serviceSpecificationService.serviceSpecificationMatchesByNameOrParentName( serviceSpecificationRef, serviceSpecificationName); }; } public Predicate<ServiceOrderItem> getServiceOrderItemByServiceSpecification( String serviceSpecificationName) { return serviceOrderItem -> { org.etsi.osl.hypo.api.tmf.common.model.ServiceSpecificationRef serviceSpecificationRef = serviceOrderItem.getService().getServiceSpecification(); return serviceSpecificationService.serviceSpecificationMatchesOrParentMatches( serviceSpecificationRef, serviceSpecificationName); }; } public List<RelatedPartyEntity> findAllRelatedPartyListByIds(List<String> relatedPartyIds) { return relatedPartyHelper.getRelatedPartiesByIds(relatedPartyIds); } public Set<RelatedPartyEntity> findAllRelatedPartySetByIds(Set<String> relatedPartyIds) { return relatedPartyHelper.getRelatedPartySetByIds(relatedPartyIds); } } Loading
.gitlab-ci.yml +1 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ dev_tests_job: stage: dev_test tags: - hypo image: labs.etsi.org:5050/osl/hypo/code/org.etsi.osl.hypo.ops/cicd/integration.tests/maven:3.8.3-openjdk-17-slim image: labs.etsi.org:5050/osl/hypo/code/org.etsi.osl.hypo.ops/cicd/integration.tests/maven:3.9.16-eclipse-temurin-17 before_script: - curl -fsSL https://get.docker.com -o get-docker.sh Loading
pom.xml +1 −7 Original line number Diff line number Diff line Loading @@ -196,13 +196,7 @@ <dependency> <groupId>org.etsi.osl.hypo.api</groupId> <artifactId>tmf.schema</artifactId> <version>2.4.1</version> </dependency> <dependency> <groupId>org.etsi.osl.hypo.api</groupId> <artifactId>tmf.common</artifactId> <version>1.1.0</version> <version>2.5.2</version> </dependency> <dependency> Loading
src/main/java/org/etsi/osl/hypo/api/tmf/agreement/api/services/AgreementService.java +18 −18 Original line number Diff line number Diff line Loading @@ -6,6 +6,9 @@ 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; import org.etsi.osl.hypo.api.tmf.common.api.mapper.UpdateMapper; Loading Loading @@ -70,26 +73,23 @@ public class AgreementService { @Transactional public Agreement createAgreement(Agreement agreement) { checkIfTmfIdExists(agreement.getTmfId()); if (agreement.getEngagedParty() != null && !agreement.getEngagedParty().isEmpty()) { agreement = findRelatedPartyAndAddItToResource(agreement); } checkIfIdExists(agreement.getId()); findRelatedPartyAndAddItToResource(agreement); agreementRepository.persist(agreement); return agreement; } private Agreement findRelatedPartyAndAddItToResource(Agreement agreement) { List<String> partyIds = agreement.getEngagedParty().stream().map(RelatedPartyEntity::getTmfId).toList(); private void findRelatedPartyAndAddItToResource(Agreement agreement) { Set<RelatedPartyEntity> engagedParty = agreement.getEngagedParty(); if (CollectionUtils.isNotEmpty(engagedParty)) { 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); agreement.getEngagedParty().clear(); agreement.getEngagedParty().addAll(relatedPartyEntities); return agreement; agreement.setEngagedParty(relatedPartyEntities); } } @Transactional Loading Loading @@ -117,13 +117,13 @@ public class AgreementService { return agreement; } private void checkIfTmfIdExists(String tmfId) { if (tmfIdExists(tmfId)) { throw new DuplicateKeyException(AGREEMENT_WITH_ID + tmfId + " already exists"); private void checkIfIdExists(String id) { if (iddExists(id)) { throw new DuplicateKeyException(AGREEMENT_WITH_ID + id + " already exists"); } } public boolean tmfIdExists(String id) { public boolean iddExists(String id) { return agreementRepository.findById(id).isPresent(); } }
src/main/java/org/etsi/osl/hypo/api/tmf/agreement/api/services/AgreementSpecificationService.java +18 −20 Original line number Diff line number Diff line Loading @@ -6,6 +6,9 @@ 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; import org.etsi.osl.hypo.api.tmf.common.api.mapper.UpdateMapper; Loading Loading @@ -76,30 +79,25 @@ public class AgreementSpecificationService { @Transactional public AgreementSpecification createAgreementSpecification( AgreementSpecification agreementSpecification) { checkIfTmfIdExists(agreementSpecification.getTmfId()); checkIfIdExists(agreementSpecification.getId()); if (agreementSpecification.getRelatedParty() != null && !agreementSpecification.getRelatedParty().isEmpty()) { agreementSpecification = findRelatedPartyAndAddItToResource(agreementSpecification); } findRelatedPartyAndAddItToResource(agreementSpecification); agreementSpecificationRepository.persist(agreementSpecification); return agreementSpecification; } private AgreementSpecification findRelatedPartyAndAddItToResource( AgreementSpecification agreementSpecification) { List<String> partyIds = agreementSpecification.getRelatedParty().stream() .map(RelatedPartyEntity::getTmfId) .toList(); private void findRelatedPartyAndAddItToResource(AgreementSpecification agreementSpecification) { Set<RelatedPartyEntity> relatedParty = agreementSpecification.getRelatedParty(); if (CollectionUtils.isNotEmpty(relatedParty)) { 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); agreementSpecification.getRelatedParty().clear(); agreementSpecification.getRelatedParty().addAll(relatedPartyEntities); return agreementSpecification; agreementSpecification.setRelatedParty(relatedPartyEntities); } } @Transactional Loading Loading @@ -130,13 +128,13 @@ public class AgreementSpecificationService { return agreementSpecification; } private void checkIfTmfIdExists(String tmfId) { if (tmfIdExists(tmfId)) { throw new DuplicateKeyException(AGREEMENT_SPECIFICATION_WITH_ID + tmfId + " already exists"); private void checkIfIdExists(String id) { if (idExists(id)) { throw new DuplicateKeyException(AGREEMENT_SPECIFICATION_WITH_ID + id + " already exists"); } } public boolean tmfIdExists(String id) { public boolean idExists(String id) { return agreementSpecificationRepository.findById(id).isPresent(); } }
src/main/java/org/etsi/osl/hypo/api/tmf/common/api/helpers/ServiceSpecificationHelpers.java→src/main/java/org/etsi/osl/hypo/api/tmf/common/api/helpers/ServiceCatalogHelper.java +190 −27 Original line number Diff line number Diff line Loading @@ -5,42 +5,70 @@ import static org.etsi.osl.hypo.core.common.constants.ServiceOrderWithPackageMan import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Strings; import org.etsi.osl.hypo.api.tmf.common.api.model.RelatedPartyDTO; import org.etsi.osl.hypo.api.tmf.common.schema.RelatedPartyEntity; 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.repository.ServiceSpecificationRepository; import org.etsi.osl.hypo.api.tmf.services.catalog.api.services.ServiceCategoryService; import org.etsi.osl.hypo.api.tmf.services.catalog.api.services.ServiceSpecificationService; import org.etsi.osl.hypo.api.tmf.services.catalog.schema.ServiceCandidateEntity; import org.etsi.osl.hypo.api.tmf.services.catalog.schema.ServiceCategoryEntity; import org.etsi.osl.hypo.api.tmf.services.catalog.schema.ServiceSpecificationEntity; import org.etsi.osl.hypo.api.tmf.services.common.schema.ServiceRefOrValue; import org.etsi.osl.hypo.api.tmf.services.common.model.ServiceRefOrValue; import org.etsi.osl.hypo.api.tmf.services.common.schema.ServiceSpecificationRef; import org.etsi.osl.hypo.api.tmf.services.common.service.RelatedPartyHelper; import org.etsi.osl.hypo.api.tmf.services.inventory.api.mappers.ServiceMapper; import org.etsi.osl.hypo.api.tmf.services.inventory.schema.Service; import org.etsi.osl.hypo.api.tmf.services.model.ServiceWithPeeredOrganization; import org.etsi.osl.hypo.api.tmf.services.order.model.common.ServiceOrderItem; import org.etsi.osl.hypo.api.tmf.services.order.schema.ServiceOrderItemEntity; @ApplicationScoped public class ServiceSpecificationHelpers { public class ServiceCatalogHelper { private final ServiceCategoryService serviceCategoryService; private final ServiceSpecificationService serviceSpecificationService; private final ServiceSpecificationRepository serviceSpecificationRepository; private final OrganizationService organizationService; private final RelatedPartyHelper relatedPartyHelper; private final ServiceMapper serviceMapper; @Inject public ServiceSpecificationHelpers( public ServiceCatalogHelper( ServiceCategoryService serviceCategoryService, ServiceSpecificationService serviceInventoryService, OrganizationService organizationService) { ServiceSpecificationRepository serviceSpecificationRepository, OrganizationService organizationService, RelatedPartyHelper relatedPartyHelper, ServiceMapper serviceMapper) { this.serviceCategoryService = serviceCategoryService; this.serviceSpecificationService = serviceInventoryService; this.serviceSpecificationRepository = serviceSpecificationRepository; this.organizationService = organizationService; this.relatedPartyHelper = relatedPartyHelper; this.serviceMapper = serviceMapper; } public boolean hasSpecificationOrParentSpecificationByName( Service service, String serviceSpecificationName) { ServiceSpecificationRef serviceSpecificationRef, String serviceSpecificationName) { return serviceSpecificationService.serviceSpecificationMatchesByNameOrParentName( service, serviceSpecificationName); serviceSpecificationRef, serviceSpecificationName); } public List<Service> filterKubernetesServices(List<Service> services, Boolean isKubernetes) { return isKubernetes != null && isKubernetes ? services.stream().filter(this::hasSpecificationKubernetesCFS).toList() : services; } public boolean hasSpecificationKubernetesCFS(Service service) { Loading @@ -58,6 +86,22 @@ public class ServiceSpecificationHelpers { return isK8sSpecification.get(); } public boolean hasSpecificationKubernetesCFS(ServiceSpecificationRef serviceSpecificationRef) { AtomicReference<Boolean> isK8sSpecification = new AtomicReference<>(); isK8sSpecification.set(Boolean.FALSE); Optional<ServiceCategoryEntity> optionalServiceCategoryEntity = serviceCategoryService.findServiceCategoryByName(K8S_SERVICES); optionalServiceCategoryEntity.ifPresent( serviceCategoryEntity -> isK8sSpecification.set( isServiceSpecificationContainedInCategory( serviceSpecificationRef, serviceCategoryEntity))); return isK8sSpecification.get(); } public boolean isSpecificationKubernetesCFS( ServiceSpecificationEntity serviceSpecificationEntity) { AtomicReference<Boolean> isK8sSpecification = new AtomicReference<>(); Loading @@ -81,6 +125,13 @@ public class ServiceSpecificationHelpers { && service.getServiceSpecification().getName().equals(STANDALONE_K8SAAS_CFS); } public boolean hasSpecificationKubernetesRegistrationCFS( ServiceSpecificationRef serviceSpecificationRef) { return serviceSpecificationRef != null && serviceSpecificationRef.getName() != null && serviceSpecificationRef.getName().equals(STANDALONE_K8SAAS_CFS); } public boolean hasSpecificationKubernetesCFS(ServiceRefOrValue serviceRefOrValue) { AtomicReference<Boolean> isK8sSpecification = new AtomicReference<>(); isK8sSpecification.set(Boolean.FALSE); Loading @@ -97,16 +148,13 @@ public class ServiceSpecificationHelpers { return isK8sSpecification.get(); } public boolean hasPeeredSpecification(Service service) { if (service == null || service.getServiceSpecification() == null) { public boolean hasPeeredSpecification(ServiceSpecificationRef serviceSpecificationRef) { if (serviceSpecificationRef == null) { return false; } AtomicReference<Boolean> hasPeeredOrganization = new AtomicReference<>(); hasPeeredOrganization.set(Boolean.FALSE); ServiceSpecificationRef serviceSpecificationRef = service.getServiceSpecification(); hasPeeredServiceSpecification(serviceSpecificationRef, hasPeeredOrganization); return hasPeeredOrganization.get(); Loading @@ -120,7 +168,8 @@ public class ServiceSpecificationHelpers { AtomicReference<Boolean> hasPeeredOrganization = new AtomicReference<>(); hasPeeredOrganization.set(Boolean.FALSE); ServiceSpecificationRef serviceSpecificationRef = serviceRefOrValue.getServiceSpecification(); org.etsi.osl.hypo.api.tmf.common.model.ServiceSpecificationRef serviceSpecificationRef = serviceRefOrValue.getServiceSpecification(); hasPeeredServiceSpecification(serviceSpecificationRef, hasPeeredOrganization); Loading @@ -130,18 +179,27 @@ public class ServiceSpecificationHelpers { private void hasPeeredServiceSpecification( ServiceSpecificationRef serviceSpecificationRef, AtomicReference<Boolean> hasPeeredOrganization) { final String serviceSpecificationId = serviceSpecificationRef.getTmfId(); 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.getPeeredOrganizationForRelatedPartySet(relatedPartyBySpecificationId); organization.ifPresent(organizationPresent -> hasPeeredOrganization.set(Boolean.TRUE)); } private void hasPeeredServiceSpecification( org.etsi.osl.hypo.api.tmf.common.model.ServiceSpecificationRef serviceSpecificationRef, AtomicReference<Boolean> hasPeeredOrganization) { final String serviceSpecificationId = serviceSpecificationRef.getId(); Set<RelatedPartyDTO> relatedPartyBySpecificationId = serviceSpecificationService.getRelatedPartyBySpecificationId(serviceSpecificationId); Optional<Organization> organization = organizationService.getPeeredOrganizationForRelatedPartySet(relatedPartyBySpecificationId); organization.ifPresent(organizationPresent -> hasPeeredOrganization.set(Boolean.TRUE)); }); } private boolean isServiceSpecificationContainedInCategory( Loading @@ -151,6 +209,14 @@ public class ServiceSpecificationHelpers { .anyMatch(getServiceSpecificationEntityPredicate(serviceRefOrValue)); } private boolean isServiceSpecificationContainedInCategory( ServiceSpecificationRef serviceSpecificationRef, ServiceCategoryEntity serviceCategoryEntity) { return serviceCategoryEntity.getServiceCandidates().stream() .map(ServiceCandidateEntity::getServiceSpecification) .anyMatch(getServiceSpecificationEntityPredicate(serviceSpecificationRef)); } private boolean isServiceSpecificationContainedInCategory( ServiceSpecificationEntity serviceSpecificationEntity, ServiceCategoryEntity serviceCategoryEntity) { Loading @@ -170,23 +236,120 @@ public class ServiceSpecificationHelpers { ServiceRefOrValue serviceRefOrValue) { return serviceSpecificationEntity -> serviceSpecificationEntity .getTmfId() .equals(serviceRefOrValue.getServiceSpecification().getTmfId()); .getId() .equals(serviceRefOrValue.getServiceSpecification().getId()); } private Predicate<ServiceSpecificationEntity> getServiceSpecificationEntityPredicate( ServiceSpecificationRef serviceSpecificationRef) { return serviceSpecificationEntity -> { String serviceSpecificationEntityId = serviceSpecificationEntity.getId(); return StringUtils.isNotBlank(serviceSpecificationEntityId) && serviceSpecificationEntityId.equals(serviceSpecificationRef.getId()); }; } private Predicate<ServiceSpecificationEntity> getServiceSpecificationEntityPredicate( ServiceSpecificationEntity serviceSpecificationEntityProvided) { return serviceSpecificationEntity -> serviceSpecificationEntity.getTmfId().equals(serviceSpecificationEntityProvided.getTmfId()); serviceSpecificationEntity.getId().equals(serviceSpecificationEntityProvided.getId()); } private Predicate<ServiceSpecificationEntity> getServiceSpecificationEntityPredicate( Service service) { return serviceSpecificationEntity -> service.getServiceSpecification() != null && service.getServiceSpecification().getTmfId() != null && StringUtils.equals( serviceSpecificationEntity.getTmfId(), service.getServiceSpecification().getTmfId()); && service.getServiceSpecification().getId() != null && Strings.CS.equals( serviceSpecificationEntity.getId(), service.getServiceSpecification().getId()); } public List<ServiceWithPeeredOrganization> filterKubernetesServicesWithPeeredOrganization( List<Service> services, Boolean isKubernetes) { return services.stream() .filter( service -> { boolean hasToBeKubernetesService = isKubernetes != null && isKubernetes && (this.hasSpecificationKubernetesCFS(service) || this.hasSpecificationKubernetesRegistrationCFS(service)); boolean doesNotHaveTobeKubernetesService = isKubernetes == null || !isKubernetes; return hasToBeKubernetesService || doesNotHaveTobeKubernetesService; }) .map( service -> { ServiceWithPeeredOrganization serviceWithPeeredOrganization = serviceMapper.toServiceWithPeeredOrganizationInfo(service); this.populateServiceWithPeeredOrganizationInfo(serviceWithPeeredOrganization); return serviceWithPeeredOrganization; }) .toList(); } private void populateServiceWithPeeredOrganizationInfo( ServiceWithPeeredOrganization serviceWithPeeredOrganization) { org.etsi.osl.hypo.api.tmf.common.model.ServiceSpecificationRef serviceSpecificationRef = serviceWithPeeredOrganization.getServiceSpecification(); if (Objects.nonNull(serviceSpecificationRef)) { Set<RelatedPartyDTO> relatedParties = serviceSpecificationService.getRelatedPartyBySpecificationId( serviceSpecificationRef.getId()); String relatedPartyId = CollectionUtils.isNotEmpty(relatedParties) ? relatedParties.iterator().next().getId() : null; if (Objects.nonNull(relatedPartyId)) { relatedPartyHelper .getOptionalOrganizationById(relatedPartyId) .ifPresent( organization -> { if (relatedPartyHelper.isPeeredOrganization(organization)) { serviceWithPeeredOrganization.setOrganizationProvider(organization.getName()); } }); } } } public List<ServiceSpecificationEntity> getServiceSpecificationEntitiesByOrganizationId( String organizationId) { return serviceSpecificationRepository.findServiceSpecificationIdsByOrganizationId( organizationId); } public Optional<ServiceSpecificationEntity> findSpecificationById(String specificationId) { return serviceSpecificationRepository.findById(specificationId); } public Predicate<ServiceOrderItemEntity> getServiceOrderItemByServiceSpecificationNameOrParentName(String serviceSpecificationName) { return serviceOrderItem -> { ServiceSpecificationRef serviceSpecificationRef = serviceOrderItem.getService().getServiceSpecification(); return serviceSpecificationService.serviceSpecificationMatchesByNameOrParentName( serviceSpecificationRef, serviceSpecificationName); }; } public Predicate<ServiceOrderItem> getServiceOrderItemByServiceSpecification( String serviceSpecificationName) { return serviceOrderItem -> { org.etsi.osl.hypo.api.tmf.common.model.ServiceSpecificationRef serviceSpecificationRef = serviceOrderItem.getService().getServiceSpecification(); return serviceSpecificationService.serviceSpecificationMatchesOrParentMatches( serviceSpecificationRef, serviceSpecificationName); }; } public List<RelatedPartyEntity> findAllRelatedPartyListByIds(List<String> relatedPartyIds) { return relatedPartyHelper.getRelatedPartiesByIds(relatedPartyIds); } public Set<RelatedPartyEntity> findAllRelatedPartySetByIds(Set<String> relatedPartyIds) { return relatedPartyHelper.getRelatedPartySetByIds(relatedPartyIds); } }