Search in sources :

Example 1 with CatalogQueryException

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

the class CatalogDbAdapterRest method getProcessingFlagsImpl.

public Response getProcessingFlagsImpl(String flag) {
    ProcessingFlags processingFlags = null;
    logger.debug("Flag is: " + flag);
    int respStatus = HttpStatus.SC_OK;
    try {
        processingFlags = processingFlagsRepo.findByFlag(flag);
        if (processingFlags == null) {
            logger.debug("ProcessingFlag not found");
            respStatus = HttpStatus.SC_NOT_FOUND;
        } else {
            logger.debug("ProcessingFlags processingFlags = {}", processingFlags.toString());
        }
        return Response.status(respStatus).entity(processingFlags).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
    } catch (Exception e) {
        logger.error("Exception - queryProcesssingFlags", 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 : ProcessingFlags(org.onap.so.db.catalog.beans.ProcessingFlags) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException)

Example 2 with CatalogQueryException

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

the class CatalogDbAdapterRest method serviceNetworksImpl.

public Response serviceNetworksImpl(String version, boolean isArray, String networkModelCustomizationUuid, String networkType, String serviceModelUuid, String serviceModelInvariantUuid, String serviceModelVersion) {
    QueryServiceNetworks qryResp;
    int respStatus = HttpStatus.SC_OK;
    String uuid = "";
    List<NetworkResourceCustomization> ret = new ArrayList<>();
    Service service = null;
    try {
        if (networkModelCustomizationUuid != null && !"".equals(networkModelCustomizationUuid)) {
            uuid = networkModelCustomizationUuid;
            ret = networkCustomizationRepo.findByModelCustomizationUUID(networkModelCustomizationUuid);
        } else if (networkType != null && !"".equals(networkType)) {
            uuid = networkType;
            NetworkResource networkResources = networkResourceRepo.findFirstByModelNameOrderByModelVersionDesc(networkType);
            if (networkResources != null)
                ret = networkResources.getNetworkResourceCustomization();
        } else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
            uuid = serviceModelInvariantUuid;
            if (serviceModelVersion != null && !"".equals(serviceModelVersion)) {
                service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(serviceModelVersion, uuid);
            } else {
                service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
            }
        } else if (serviceModelUuid != null && !"".equals(serviceModelUuid)) {
            uuid = serviceModelUuid;
            service = serviceRepo.findOneByModelUUID(serviceModelUuid);
        } else {
            throw (new Exception(NO_MATCHING_PARAMETERS));
        }
        if (service != null)
            ret = service.getNetworkCustomizations();
        if (ret == null || ret.isEmpty()) {
            logger.debug("serviceNetworks not found");
            respStatus = HttpStatus.SC_NOT_FOUND;
            qryResp = new QueryServiceNetworks();
        } else {
            qryResp = new QueryServiceNetworks(ret);
            logger.debug("serviceNetworks found qryResp= {}", qryResp);
        }
        return respond(version, respStatus, isArray, qryResp);
    } catch (Exception e) {
        logger.error("Exception - queryServiceNetworks", 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 : NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) ArrayList(java.util.ArrayList) Service(org.onap.so.db.catalog.beans.Service) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) QueryServiceNetworks(org.onap.so.adapters.catalogdb.catalogrest.QueryServiceNetworks) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException)

Example 3 with CatalogQueryException

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

the class CatalogDbAdapterRest method vfModules.

@GET
@Path("vfModules")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Transactional(readOnly = true)
public Response vfModules(@QueryParam("vfModuleModelName") String vfModuleModelName) {
    QueryVfModule qryResp;
    int respStatus = HttpStatus.SC_OK;
    List<VfModuleCustomization> ret = null;
    try {
        if (vfModuleModelName != null && !"".equals(vfModuleModelName)) {
            VfModule vfModule = vfModuleRepo.findFirstByModelNameOrderByModelVersionDesc(vfModuleModelName);
            if (vfModule != null)
                ret = vfModule.getVfModuleCustomization();
        } else {
            throw (new Exception(NO_MATCHING_PARAMETERS));
        }
        if (ret == null || ret.isEmpty()) {
            logger.debug("vfModules not found");
            respStatus = HttpStatus.SC_NOT_FOUND;
            qryResp = new QueryVfModule();
        } else {
            qryResp = new QueryVfModule(ret);
            if (logger.isDebugEnabled())
                logger.debug("vfModules tojsonstring is: {}", qryResp.JSON2(false, false));
        }
        return Response.status(respStatus).entity(qryResp.JSON2(false, false)).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
    } catch (Exception e) {
        logger.error("Exception during query VfModules by vfModuleModuleName: ", 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 : QueryVfModule(org.onap.so.adapters.catalogdb.catalogrest.QueryVfModule) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) VfModuleCustomization(org.onap.so.db.catalog.beans.VfModuleCustomization) VfModule(org.onap.so.db.catalog.beans.VfModule) QueryVfModule(org.onap.so.adapters.catalogdb.catalogrest.QueryVfModule) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with CatalogQueryException

use of org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException 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)

Example 5 with CatalogQueryException

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

the class CatalogDbAdapterRest method serviceToscaCsar.

/**
 * Get the tosca csar info from catalog <br>
 *
 * @param smUuid service model uuid
 * @return the tosca csar information of the serivce.
 * @since ONAP Beijing Release
 */
@GET
@Path("serviceToscaCsar")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response serviceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) {
    int respStatus = HttpStatus.SC_OK;
    String entity = "";
    try {
        if (smUuid != null && !"".equals(smUuid)) {
            logger.debug("Query Csar by service model uuid: {}", smUuid);
            Service service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(smUuid);
            if (service != null) {
                ToscaCsar toscaCsar = service.getCsar();
                if (toscaCsar != null) {
                    QueryServiceCsar serviceCsar = new QueryServiceCsar(toscaCsar);
                    entity = serviceCsar.JSON2(false, false);
                } else {
                    respStatus = HttpStatus.SC_NOT_FOUND;
                }
            } else {
                respStatus = HttpStatus.SC_NOT_FOUND;
            }
        } else {
            throw (new Exception("Incoming parameter is null or blank"));
        }
        return Response.status(respStatus).entity(entity).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
    } catch (Exception e) {
        logger.error("Exception during query csar by service model uuid: ", 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 : Service(org.onap.so.db.catalog.beans.Service) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar) QueryServiceCsar(org.onap.so.adapters.catalogdb.catalogrest.QueryServiceCsar) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

CatalogQueryException (org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException)10 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 Service (org.onap.so.db.catalog.beans.Service)5 ArrayList (java.util.ArrayList)4 ProcessingFlags (org.onap.so.db.catalog.beans.ProcessingFlags)4 NetworkResource (org.onap.so.db.catalog.beans.NetworkResource)3 QueryAllottedResourceCustomization (org.onap.so.adapters.catalogdb.catalogrest.QueryAllottedResourceCustomization)2 QueryResourceRecipe (org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe)2 QueryServiceCsar (org.onap.so.adapters.catalogdb.catalogrest.QueryServiceCsar)2 QueryServiceMacroHolder (org.onap.so.adapters.catalogdb.catalogrest.QueryServiceMacroHolder)2 QueryServiceNetworks (org.onap.so.adapters.catalogdb.catalogrest.QueryServiceNetworks)2 QueryVfModule (org.onap.so.adapters.catalogdb.catalogrest.QueryVfModule)2 AllottedResource (org.onap.so.db.catalog.beans.AllottedResource)2 AllottedResourceCustomization (org.onap.so.db.catalog.beans.AllottedResourceCustomization)2 InstanceGroup (org.onap.so.db.catalog.beans.InstanceGroup)2 NetworkResourceCustomization (org.onap.so.db.catalog.beans.NetworkResourceCustomization)2 Recipe (org.onap.so.db.catalog.beans.Recipe)2 ToscaCsar (org.onap.so.db.catalog.beans.ToscaCsar)2