Search in sources :

Example 1 with QueryServiceCsar

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

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 QueryServiceCsar (org.onap.so.adapters.catalogdb.catalogrest.QueryServiceCsar)1 Service (org.onap.so.db.catalog.beans.Service)1 ToscaCsar (org.onap.so.db.catalog.beans.ToscaCsar)1