use of com.emc.sa.asset.AssetOptionsContext in project coprhd-controller by CoprHD.
the class AssetOptionService method createAssetOptionsContext.
private AssetOptionsContext createAssetOptionsContext(AssetOptionsRequest request) {
StorageOSUser user = getUserFromContext();
AssetOptionsContext context = assetOptionsManager.createDefaultContext(user);
// Override the tenant if specified in the request
URI tenantId = request.getTenantId();
if (tenantId != null) {
verifyAuthorizedInTenantOrg(tenantId, user);
context.setTenant(tenantId);
}
return context;
}
use of com.emc.sa.asset.AssetOptionsContext 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);
}
}
Aggregations