Search in sources :

Example 1 with QueryServiceMacroHolder

use of org.onap.so.adapters.catalogdb.catalogrest.QueryServiceMacroHolder in project so by onap.

the class CatalogDbAdapterRest method serviceResources.

@GET
@Path("serviceResources")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Transactional(readOnly = true)
public Response serviceResources(@PathParam("version") String version, @QueryParam("serviceModelUuid") String modelUUID, @QueryParam("serviceModelInvariantUuid") String modelInvariantUUID, @QueryParam("serviceModelVersion") String modelVersion, @QueryParam("filter") String filter) {
    QueryServiceMacroHolder qryResp;
    int respStatus = HttpStatus.SC_OK;
    String uuid = "";
    ServiceMacroHolder ret = new ServiceMacroHolder();
    try {
        if (modelUUID != null && !"".equals(modelUUID)) {
            uuid = modelUUID;
            logger.debug("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: {}", uuid);
            Service serv = serviceRepo.findOneByModelUUID(uuid);
            if (serv != null) {
                ret.setNetworkResourceCustomizations(new ArrayList(serv.getNetworkCustomizations()));
                if (StringUtils.isNotEmpty(filter) && RESOURCE_INPUT_FILTER.equalsIgnoreCase(filter)) {
                    serv.getVnfCustomizations().forEach(vnfCustomization -> vnfCustomization.setResourceInput(null));
                }
                ret.setVnfResourceCustomizations(new ArrayList(serv.getVnfCustomizations()));
                ret.setAllottedResourceCustomizations(new ArrayList(serv.getAllottedCustomizations()));
            }
            ret.setService(serv);
        } else if (modelInvariantUUID != null && !"".equals(modelInvariantUUID)) {
            uuid = modelInvariantUUID;
            if (modelVersion != null && !"".equals(modelVersion)) {
                logger.debug("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: {}  serviceModelVersion: {}", uuid, modelVersion);
                Service serv = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(modelVersion, uuid);
                ret.setService(serv);
            } else {
                logger.debug("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: {}", uuid);
                Service serv = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
                ret.setService(serv);
            }
        } else {
            throw (new Exception(NO_MATCHING_PARAMETERS));
        }
        if (ret.getService() == null) {
            logger.debug("serviceMacroHolder not found");
            respStatus = HttpStatus.SC_NOT_FOUND;
            qryResp = new QueryServiceMacroHolder();
        } else {
            qryResp = new QueryServiceMacroHolder(ret);
            logger.debug("serviceMacroHolder qryResp= {}", qryResp);
        }
        return respond(version, respStatus, IS_ARRAY, qryResp);
    } catch (Exception e) {
        logger.error("Exception - queryServiceMacroHolder", e);
        CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(new GenericEntity<CatalogQueryException>(excResp) {
        }).build();
    }
}
Also used : QueryServiceMacroHolder(org.onap.so.adapters.catalogdb.catalogrest.QueryServiceMacroHolder) ArrayList(java.util.ArrayList) Service(org.onap.so.db.catalog.beans.Service) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) QueryServiceMacroHolder(org.onap.so.adapters.catalogdb.catalogrest.QueryServiceMacroHolder) ServiceMacroHolder(org.onap.so.db.catalog.rest.beans.ServiceMacroHolder) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 CatalogQueryException (org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException)1 QueryServiceMacroHolder (org.onap.so.adapters.catalogdb.catalogrest.QueryServiceMacroHolder)1 Service (org.onap.so.db.catalog.beans.Service)1 ServiceMacroHolder (org.onap.so.db.catalog.rest.beans.ServiceMacroHolder)1 Transactional (org.springframework.transaction.annotation.Transactional)1