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();
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations