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