Search in sources :

Example 1 with AssetOptionsResponse

use of com.emc.vipr.model.catalog.AssetOptionsResponse in project coprhd-controller by CoprHD.

the class AssetOptionService method getAssetOptions.

@POST
@Path("/{assetType}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public AssetOptionsResponse getAssetOptions(@PathParam("assetType") String assetType, AssetOptionsRequest request) {
    final Map<String, String> availableAssets = request.getAvailableAssets();
    final AssetOptionsContext context = createAssetOptionsContext(request);
    final Map<String, String> sanitizedAvailableAssets = SecurityUtils.stripMapXSS(availableAssets);
    final String sanitizedAssetType = SecurityUtils.stripXSS(assetType);
    log.info("Retrieving asset options for " + sanitizedAssetType + " with available assets : " + StringUtils.join(sanitizedAvailableAssets.keySet(), ", "));
    try {
        List<AssetOption> options = assetOptionsManager.getOptions(context, sanitizedAssetType, sanitizedAvailableAssets);
        AssetOptionsResponse response = new AssetOptionsResponse();
        response.setAssetType(sanitizedAssetType);
        response.setAvailableAssets(sanitizedAvailableAssets);
        response.setOptions(options);
        return response;
    } catch (IllegalStateException e) {
        Response response = Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).type(MediaType.TEXT_PLAIN).build();
        throw new WebApplicationException(response);
    } catch (ViPRHttpException e) {
        if (e.getHttpCode() == 404) {
            Response response = Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).type(MediaType.TEXT_PLAIN).build();
            throw new WebApplicationException(response);
        }
        throw new WebApplicationException(e);
    }
}
Also used : AssetDependencyResponse(com.emc.vipr.model.catalog.AssetDependencyResponse) Response(javax.ws.rs.core.Response) AssetOptionsResponse(com.emc.vipr.model.catalog.AssetOptionsResponse) AssetOption(com.emc.vipr.model.catalog.AssetOption) WebApplicationException(javax.ws.rs.WebApplicationException) AssetOptionsResponse(com.emc.vipr.model.catalog.AssetOptionsResponse) AssetOptionsContext(com.emc.sa.asset.AssetOptionsContext) ViPRHttpException(com.emc.vipr.client.exceptions.ViPRHttpException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

AssetOptionsContext (com.emc.sa.asset.AssetOptionsContext)1 ViPRHttpException (com.emc.vipr.client.exceptions.ViPRHttpException)1 AssetDependencyResponse (com.emc.vipr.model.catalog.AssetDependencyResponse)1 AssetOption (com.emc.vipr.model.catalog.AssetOption)1 AssetOptionsResponse (com.emc.vipr.model.catalog.AssetOptionsResponse)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1