Commit 4d5a49cc authored by Anastasios Poimenidis's avatar Anastasios Poimenidis
Browse files

feat: introduce ServiceOrderDTO and ServiceOrderResponse, change...

feat: introduce ServiceOrderDTO and ServiceOrderResponse, change ServiceOrderResource.java http responses
parent 30cdbca2
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -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.4.4</version>
    </dependency>

    <dependency>
+64 −9
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ import org.etsi.osl.hypo.api.tmf.services.catalog.api.services.ServiceSpecificat
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.inventory.schema.Service;

@@ -38,9 +38,9 @@ public class ServiceSpecificationHelpers {
    }

    public boolean hasSpecificationOrParentSpecificationByName(
            Service service, String serviceSpecificationName) {
            ServiceSpecificationRef serviceSpecificationRef, String serviceSpecificationName) {
        return serviceSpecificationService.serviceSpecificationMatchesByNameOrParentName(
                service, serviceSpecificationName);
                serviceSpecificationRef, serviceSpecificationName);
    }

    public boolean hasSpecificationKubernetesCFS(Service service) {
@@ -58,6 +58,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<>();
@@ -81,6 +97,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);
@@ -97,16 +120,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();
@@ -120,7 +140,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);

@@ -144,6 +165,23 @@ public class ServiceSpecificationHelpers {
                });
    }

    private void hasPeeredServiceSpecification(
            org.etsi.osl.hypo.api.tmf.common.model.ServiceSpecificationRef serviceSpecificationRef,
            AtomicReference<Boolean> hasPeeredOrganization) {
        final String serviceSpecificationId = serviceSpecificationRef.getId();

        Optional<ServiceSpecificationEntity> serviceSpecificationEntity =
                serviceSpecificationService.getSpecificationById(serviceSpecificationId);

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

    private boolean isServiceSpecificationContainedInCategory(
            ServiceRefOrValue serviceRefOrValue, ServiceCategoryEntity serviceCategoryEntity) {
        return serviceCategoryEntity.getServiceCandidates().stream()
@@ -151,6 +189,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) {
@@ -174,6 +220,15 @@ public class ServiceSpecificationHelpers {
                        .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 ->
+18 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.Set;
import org.etsi.osl.hypo.api.tmf.common.schema.Note;
import org.etsi.osl.hypo.api.tmf.services.inventory.schema.Service;
import org.etsi.osl.hypo.api.tmf.services.order.model.ServiceOrderDTO;
import org.etsi.osl.hypo.api.tmf.services.order.schema.ServiceOrder;

public final class ServiceUtilsHelper {
@@ -26,6 +27,23 @@ public final class ServiceUtilsHelper {
        }
    }

    public static void addServiceOrderNoteWithMessage(
            ServiceOrderDTO serviceOrderDTO, String messageNote) {
        org.etsi.osl.hypo.api.tmf.common.model.Note note =
                new org.etsi.osl.hypo.api.tmf.common.model.Note();
        note.setDate(SystemClockHelper.getSystemTimeDate());
        note.setText(messageNote);

        Set<org.etsi.osl.hypo.api.tmf.common.model.Note> notes = serviceOrderDTO.getNote();
        if (notes == null) {
            Set<org.etsi.osl.hypo.api.tmf.common.model.Note> newNotes = new HashSet<>();
            newNotes.add(note);
            serviceOrderDTO.setNote(newNotes);
        } else {
            notes.add(note);
        }
    }

    public static void addServiceOrderNoteWithMessage(ServiceOrder serviceOrder, String messageNote) {
        Note note = new Note();
        note.setDate(SystemClockHelper.getSystemTimeDate());
+16 −1
Original line number Diff line number Diff line
package org.etsi.osl.hypo.api.tmf.common.api.initializer;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Singleton;

@Dependent
public class CommonBeansInitializer {
    final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());
    @Produces
    @Singleton
    public ObjectMapper objectMapper() {
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(new JavaTimeModule());
        mapper.disable(
                SerializationFeature
                        .WRITE_DATES_AS_TIMESTAMPS); // Outputs ISO strings instead of Epoch numbers
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false);
        return mapper;
    }
}
+0 −26
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Named;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.mapstruct.SubclassExhaustiveStrategy;

@@ -62,31 +61,6 @@ public interface UpdateMapper {
    @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
    Resource updateResource(Resource newResource, @MappingTarget Resource oldResource);

    @Mapping(target = "entityId", ignore = true)
    @Mapping(target = "serviceSpecification.entityId", ignore = true)
    @Mapping(target = "serviceRelationship.service.entityId", ignore = true)
    @Mapping(target = "supportingService", ignore = true)
    @Mapping(target = "supportingResource", ignore = true)
    @Mapping(target = "relatedParty", ignore = true)
    @Mapping(target = "note", ignore = true)
    @Mapping(target = "serviceCharacteristic", ignore = true)
    @BeanMapping(
            qualifiedByName = "updateServiceCharacteristics",
            nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
            nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
    void updateService(Service newService, @MappingTarget Service oldService);

    @Mapping(target = "entityId", ignore = true)
    @Mapping(target = "serviceSpecification.entityId", ignore = true)
    @Mapping(target = "serviceRelationship.service.entityId", ignore = true)
    @Mapping(target = "supportingService", ignore = true)
    @Mapping(target = "relatedParty", ignore = true)
    @Mapping(target = "note", ignore = true)
    @BeanMapping(
            nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
            nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
    void updateServiceForBackUp(Service newService, @MappingTarget Service oldService);

    @Mapping(target = "entityId", ignore = true)
    @Mapping(target = "engagedParty.entityId", ignore = true)
    @Mapping(target = "partyRoleSpecification.entityId", ignore = true)
Loading