Search in sources :

Example 6 with CatalogQueryException

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

the class CatalogDbAdapterRest method updateProcessingFlagsValueImpl.

public Response updateProcessingFlagsValueImpl(String flag, ProcessingFlags updatedProcessingFlag) {
    ProcessingFlags processingFlags = null;
    logger.debug("Flag is: " + flag);
    int respStatus = HttpStatus.SC_OK;
    try {
        if (updatedProcessingFlag == null) {
            logger.debug("No valid updatedProcessingFlag is provided");
            throw new RuntimeException("No valid updatedProcessingFlag is provided");
        }
        String value = updatedProcessingFlag.getValue();
        if (value == null || (!value.equalsIgnoreCase("YES") && !value.equalsIgnoreCase("NO"))) {
            logger.debug("Value " + value + " is invalid, only yes/no are allowed");
            throw new RuntimeException("Invalid value specified");
        }
        processingFlags = processingFlagsRepo.findByFlag(flag);
        if (processingFlags == null) {
            logger.debug("ProcessingFlag not found");
            respStatus = HttpStatus.SC_NOT_FOUND;
        } else {
            logger.debug("ProcessingFlags processingFlags = {}", processingFlags.toString());
            processingFlags.setValue(value);
            processingFlagsRepo.saveAndFlush(processingFlags);
            return Response.status(respStatus).entity(null).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();
    }
    return Response.status(HttpStatus.SC_NOT_FOUND).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).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 7 with CatalogQueryException

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

the class CatalogDbAdapterRest method getAllProcessingFlagsImpl.

public Response getAllProcessingFlagsImpl() {
    List<ProcessingFlags> processingFlags = null;
    int respStatus = HttpStatus.SC_OK;
    try {
        processingFlags = processingFlagsRepo.findAll();
        if (processingFlags == null) {
            logger.debug("ProcessingFlags 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 8 with CatalogQueryException

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

the class CatalogDbAdapterRest method resourceRecipe.

/**
 * Get the resource recipe info from catalog <br>
 *
 * @param rmUuid resource model uuid
 * @return the recipe information of the resource.
 * @since ONAP Beijing Release
 */
@GET
@Path("resourceRecipe")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response resourceRecipe(@QueryParam("resourceModelUuid") String rmUuid, @QueryParam("action") String action) {
    int respStatus = HttpStatus.SC_OK;
    String entity = "";
    try {
        if (rmUuid != null && !"".equals(rmUuid)) {
            logger.debug("Query recipe by resource model uuid: {}", rmUuid);
            // check vnf and network and ar, the resource could be any resource.
            Recipe recipe = null;
            VnfResource vnf = vnfResourceRepo.findResourceByModelUUID(rmUuid);
            if (vnf != null) {
                recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(vnf.getModelName(), action, vnf.getModelVersion());
                // for network service fetch the default recipe
                if (recipe == null && vnf.getSubCategory().equalsIgnoreCase(NETWORK_SERVICE)) {
                    recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndAction("NS_DEFAULT", action);
                }
            }
            if (null == recipe) {
                NetworkResource nResource = networkResourceRepo.findResourceByModelUUID(rmUuid);
                if (nResource != null) {
                    recipe = networkRecipeRepo.findFirstByModelNameAndActionAndVersionStr(nResource.getModelName(), action, nResource.getModelVersion());
                    // for network fetch the default recipe
                    if (recipe == null) {
                        recipe = networkRecipeRepo.findFirstByModelNameAndAction("SDNC_DEFAULT", action);
                    }
                }
            }
            if (null == recipe) {
                AllottedResource arResource = arResourceRepo.findResourceByModelUUID(rmUuid);
                if (arResource != null) {
                    recipe = arRecipeRepo.findByModelNameAndActionAndVersion(arResource.getModelName(), action, arResource.getModelVersion());
                }
            }
            if (null == recipe) {
                InstanceGroup grpResource = instanceGroupRepository.findByModelUUID(rmUuid);
                if (grpResource != null) {
                    recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(grpResource.getModelName(), action, grpResource.getModelVersion());
                }
            }
            if (recipe != null) {
                QueryResourceRecipe resourceRecipe = new QueryResourceRecipe(recipe);
                entity = resourceRecipe.JSON2(false, false);
            } 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 recipe by resource 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 : NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) VnfResource(org.onap.so.db.catalog.beans.VnfResource) QueryResourceRecipe(org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe) VnfRecipe(org.onap.so.db.catalog.beans.VnfRecipe) Recipe(org.onap.so.db.catalog.beans.Recipe) QueryResourceRecipe(org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) AllottedResource(org.onap.so.db.catalog.beans.AllottedResource) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) InstanceGroup(org.onap.so.db.catalog.beans.InstanceGroup) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with CatalogQueryException

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

the class CatalogDbAdapterRest method serviceVnfsImpl.

public Response serviceVnfsImpl(String version, boolean isArray, String vnfUuid, String serviceModelUUID, String smiUuid, String smVer, String smName, String filter) {
    QueryServiceVnfs qryResp = null;
    int respStatus = HttpStatus.SC_OK;
    List<VnfResourceCustomization> ret = new ArrayList<>();
    Service service = null;
    try {
        if (vnfUuid != null && !"".equals(vnfUuid))
            ret = vnfCustomizationRepo.findByModelCustomizationUUID(vnfUuid);
        else if (serviceModelUUID != null && !"".equals(serviceModelUUID))
            service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(serviceModelUUID);
        else if (smiUuid != null && !"".equals(smiUuid))
            if (smVer != null && !"".equals(smVer))
                service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, smiUuid);
            else
                service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(smiUuid);
        else if (smName != null && !"".equals(smName)) {
            if (smVer != null && !"".equals(smVer))
                service = serviceRepo.findByModelNameAndModelVersion(smName, smVer);
            else
                service = serviceRepo.findFirstByModelNameOrderByModelVersionDesc(smName);
        } else {
            throw (new Exception(NO_MATCHING_PARAMETERS));
        }
        if (service == null && ret.isEmpty()) {
            respStatus = HttpStatus.SC_NOT_FOUND;
            qryResp = new QueryServiceVnfs();
        } else if (service == null && !ret.isEmpty()) {
            if (StringUtils.isNotEmpty(filter) && RESOURCE_INPUT_FILTER.equalsIgnoreCase(filter)) {
                ret.forEach(vnfCustomization -> vnfCustomization.setResourceInput(null));
            }
            qryResp = new QueryServiceVnfs(ret);
        } else if (service != null) {
            ret = service.getVnfCustomizations();
            if (StringUtils.isNotEmpty(filter) && RESOURCE_INPUT_FILTER.equalsIgnoreCase(filter)) {
                ret.forEach(vnfCustomization -> vnfCustomization.setResourceInput(null));
            }
            qryResp = new QueryServiceVnfs(ret);
        }
        logger.debug("serviceVnfs qryResp= {}", qryResp);
        return respond(version, respStatus, isArray, qryResp);
    } catch (Exception e) {
        logger.error("Exception - queryServiceVnfs", 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 : VnfRecipe(org.onap.so.db.catalog.beans.VnfRecipe) QueryServiceMacroHolder(org.onap.so.adapters.catalogdb.catalogrest.QueryServiceMacroHolder) NetworkRecipeRepository(org.onap.so.db.catalog.data.repository.NetworkRecipeRepository) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) VfModule(org.onap.so.db.catalog.beans.VfModule) LoggerFactory(org.slf4j.LoggerFactory) HttpStatus(org.apache.http.HttpStatus) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) VnfRecipeRepository(org.onap.so.db.catalog.data.repository.VnfRecipeRepository) QueryServiceNetworks(org.onap.so.adapters.catalogdb.catalogrest.QueryServiceNetworks) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Service(org.onap.so.db.catalog.beans.Service) VFModuleRepository(org.onap.so.db.catalog.data.repository.VFModuleRepository) NetworkResourceRepository(org.onap.so.db.catalog.data.repository.NetworkResourceRepository) ProcessingFlagsRepository(org.onap.so.db.catalog.data.repository.ProcessingFlagsRepository) QueryServiceCsar(org.onap.so.adapters.catalogdb.catalogrest.QueryServiceCsar) GenericEntity(javax.ws.rs.core.GenericEntity) QueryServiceVnfs(org.onap.so.adapters.catalogdb.catalogrest.QueryServiceVnfs) ProcessingFlags(org.onap.so.db.catalog.beans.ProcessingFlags) List(java.util.List) AllottedResource(org.onap.so.db.catalog.beans.AllottedResource) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) NetworkResourceCustomizationRepository(org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository) NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) VnfCustomizationRepository(org.onap.so.db.catalog.data.repository.VnfCustomizationRepository) QueryAllottedResourceCustomization(org.onap.so.adapters.catalogdb.catalogrest.QueryAllottedResourceCustomization) Recipe(org.onap.so.db.catalog.beans.Recipe) PathParam(javax.ws.rs.PathParam) QueryVfModule(org.onap.so.adapters.catalogdb.catalogrest.QueryVfModule) GET(javax.ws.rs.GET) InstanceGroupRepository(org.onap.so.db.catalog.data.repository.InstanceGroupRepository) CatalogQuery(org.onap.so.adapters.catalogdb.catalogrest.CatalogQuery) ArrayList(java.util.ArrayList) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) AllottedResourceCustomizationRepository(org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository) CatalogQueryExceptionCategory(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryExceptionCategory) AllottedResourceRepository(org.onap.so.db.catalog.data.repository.AllottedResourceRepository) VnfResource(org.onap.so.db.catalog.beans.VnfResource) VfModuleCustomization(org.onap.so.db.catalog.beans.VfModuleCustomization) Logger(org.slf4j.Logger) ServiceMacroHolder(org.onap.so.db.catalog.rest.beans.ServiceMacroHolder) QueryResourceRecipe(org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe) InstanceGroup(org.onap.so.db.catalog.beans.InstanceGroup) VnfResourceRepository(org.onap.so.db.catalog.data.repository.VnfResourceRepository) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) Component(org.springframework.stereotype.Component) ArRecipeRepository(org.onap.so.db.catalog.data.repository.ArRecipeRepository) ServiceRepository(org.onap.so.db.catalog.data.repository.ServiceRepository) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization) PUT(javax.ws.rs.PUT) ToscaCsarRepository(org.onap.so.db.catalog.data.repository.ToscaCsarRepository) Transactional(org.springframework.transaction.annotation.Transactional) ArrayList(java.util.ArrayList) Service(org.onap.so.db.catalog.beans.Service) QueryServiceVnfs(org.onap.so.adapters.catalogdb.catalogrest.QueryServiceVnfs) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException)

Example 10 with CatalogQueryException

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

the class CatalogDbAdapterRest method serviceAllottedResourcesImpl.

public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid, String serviceModelInvariantUuid, String smVer) {
    QueryAllottedResourceCustomization qryResp;
    int respStatus = HttpStatus.SC_OK;
    String uuid = "";
    List<AllottedResourceCustomization> ret = new ArrayList<>();
    Service service = null;
    try {
        if (smUuid != null && !"".equals(smUuid)) {
            uuid = smUuid;
            service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(uuid);
        } else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
            uuid = serviceModelInvariantUuid;
            if (smVer != null && !"".equals(smVer)) {
                service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, uuid);
            } else {
                service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
            }
        } else if (aUuid != null && !"".equals(aUuid)) {
            uuid = aUuid;
            ret = allottedCustomizationRepo.findByModelCustomizationUUID(uuid);
        } else {
            throw (new Exception(NO_MATCHING_PARAMETERS));
        }
        if (service != null)
            ret = service.getAllottedCustomizations();
        if (ret == null || ret.isEmpty()) {
            logger.debug("AllottedResourceCustomization not found");
            respStatus = HttpStatus.SC_NOT_FOUND;
            qryResp = new QueryAllottedResourceCustomization();
        } else {
            qryResp = new QueryAllottedResourceCustomization(ret);
            logger.debug("AllottedResourceCustomization qryResp= {}", qryResp);
        }
        return respond(version, respStatus, isArray, qryResp);
    } catch (Exception e) {
        logger.error("Exception - queryAllottedResourceCustomization", 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 : ArrayList(java.util.ArrayList) Service(org.onap.so.db.catalog.beans.Service) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) QueryAllottedResourceCustomization(org.onap.so.adapters.catalogdb.catalogrest.QueryAllottedResourceCustomization) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) QueryAllottedResourceCustomization(org.onap.so.adapters.catalogdb.catalogrest.QueryAllottedResourceCustomization) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization)

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