Commit 8cd8afff authored by Anastasios Poimenidis's avatar Anastasios Poimenidis
Browse files

refactor: simplify ServiceInventoryService logic

parent 32f6252e
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ 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.api.services.RelatedPartyService;
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;
@@ -26,7 +27,6 @@ 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.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;
@@ -40,7 +40,7 @@ public class ServiceCatalogHelper {
    private final ServiceSpecificationService serviceSpecificationService;
    private final ServiceSpecificationRepository serviceSpecificationRepository;
    private final OrganizationService organizationService;
    private final RelatedPartyHelper relatedPartyHelper;
    private final RelatedPartyService relatedPartyService;
    private final ServiceMapper serviceMapper;

    @Inject
@@ -49,13 +49,13 @@ public class ServiceCatalogHelper {
            ServiceSpecificationService serviceInventoryService,
            ServiceSpecificationRepository serviceSpecificationRepository,
            OrganizationService organizationService,
            RelatedPartyHelper relatedPartyHelper,
            RelatedPartyService relatedPartyService,
            ServiceMapper serviceMapper) {
        this.serviceCategoryService = serviceCategoryService;
        this.serviceSpecificationService = serviceInventoryService;
        this.serviceSpecificationRepository = serviceSpecificationRepository;
        this.organizationService = organizationService;
        this.relatedPartyHelper = relatedPartyHelper;
        this.relatedPartyService = relatedPartyService;
        this.serviceMapper = serviceMapper;
    }

@@ -303,11 +303,11 @@ public class ServiceCatalogHelper {
                            : null;

            if (Objects.nonNull(relatedPartyId)) {
                relatedPartyHelper
                organizationService
                        .getOptionalOrganizationById(relatedPartyId)
                        .ifPresent(
                                organization -> {
                                    if (relatedPartyHelper.isPeeredOrganization(organization)) {
                                    if (organizationService.isPeeredOrganization(organization)) {
                                        serviceWithPeeredOrganization.setOrganizationProvider(organization.getName());
                                    }
                                });
@@ -346,10 +346,10 @@ public class ServiceCatalogHelper {
    }

    public List<RelatedPartyEntity> findAllRelatedPartyListByIds(List<String> relatedPartyIds) {
        return relatedPartyHelper.getRelatedPartiesByIds(relatedPartyIds);
        return relatedPartyService.findAllRelatedPartiesByIds(relatedPartyIds);
    }

    public Set<RelatedPartyEntity> findAllRelatedPartySetByIds(Set<String> relatedPartyIds) {
        return relatedPartyHelper.getRelatedPartySetByIds(relatedPartyIds);
        return relatedPartyService.findAllRelatedPartiesByIds(relatedPartyIds);
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.micrometer.common.util.StringUtils;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.UriInfo;
import java.net.URI;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -264,4 +265,8 @@ public class UtilService {
        String whereClause = String.format(whereClauseFormat, queryQualifier);
        queryBuilder.append(whereClause);
    }

    public static URI getUri(String href, UriInfo uriInfo) {
        return StringUtils.isNotBlank(href) ? URI.create(href) : uriInfo.getAbsolutePath();
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -102,7 +102,8 @@ public class ServiceActivationResource {
                            schema = @Schema(implementation = Service.class, type = SchemaType.ARRAY)))
    public Response getAll(@RestQuery String fields, @Context UriInfo uriInfo) {
        Map<String, String> criteriaParams = UtilService.getRequestedCriteriaForFiltering(uriInfo);
        return Response.ok(serviceInventoryService.getByCriteria(fields, criteriaParams)).build();
        return Response.ok(serviceInventoryService.getServicesByCriteria(fields, criteriaParams))
                .build();
    }

    @GET
+2 −2
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ public class ServiceSpecificationResource {
    @Transactional
    public Response createServiceSpecification(
            @Valid ServiceSpecificationCreateRequest serviceSpecificationCreateRequest) {
        logger.info("Request : " + serviceSpecificationCreateRequest.toString());
        logger.debug("Request : " + serviceSpecificationCreateRequest.toString());
        ServiceSpecification serviceSpecification =
                serviceSpecificationService.getResponseFromCreateRequest(serviceSpecificationCreateRequest);
        return Response.ok(serviceSpecification).status(Response.Status.CREATED).build();
@@ -195,7 +195,7 @@ public class ServiceSpecificationResource {
                            schema = @Schema(implementation = ErrorMessage.class)))
    public Response update(@Valid ServiceSpecificationUpdateRequest specs, @RestPath String id) {
        logger.info("Update service specification with id : " + id);
        logger.info("Request : " + specs.toString());
        logger.debugf("Request : " + specs.toString());
        ServiceSpecification serviceSpecification =
                serviceSpecificationService.getResponseFromUpdateRequest(specs, id);
        return Response.ok(serviceSpecification).build();
+37 −642

File changed.

Preview size limit exceeded, changes collapsed.

Loading