use of com.emc.storageos.db.client.model.ModelObject in project coprhd-controller by CoprHD.
the class CustomServicesViprPrimitiveDAO method bulk.
@Override
public Iterator<CustomServicesPrimitiveRestRep> bulk(final Collection<URI> ids) {
ImmutableList.Builder<CustomServicesPrimitiveRestRep> primitives = ImmutableList.<CustomServicesPrimitiveRestRep>builder();
for (final URI id : ids) {
final CustomServicesViPRPrimitive primitive = PRIMITIVES_MAP.get(id);
final ModelObject model = primitive == null ? null : primitive.asModelObject();
ArgValidator.checkEntityNotNull(model, id, false);
primitives.add(CustomServicesPrimitiveMapper.map(primitive));
}
return primitives.build().iterator();
}
use of com.emc.storageos.db.client.model.ModelObject in project coprhd-controller by CoprHD.
the class CustomServicesPrimitiveService method download.
/**
* Download the resource and set it in the response header
*
* @param id The ID of the resource to download
* @param response HttpServletResponse the servlet response to update with the file octet stream
* @return Response containing the octet stream of the primitive resource
*/
@GET
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Path("resource/{id}/download")
public Response download(@PathParam("id") final URI id, @Context final HttpServletResponse response) {
final CustomServicesResourceDAO<?> dao = getResourceDAOFromID(id);
if (null == dao) {
throw BadRequestException.badRequests.unableToFindEntity(id);
}
final CustomServicesPrimitiveResourceType resource = getResourceNullSafe(id, dao);
final ModelObject model = toModelObject(resource);
ArgValidator.checkEntity(model, id, true);
final byte[] bytes = Base64.decodeBase64(resource.resource());
response.setContentLength(bytes.length);
response.setHeader("Content-Disposition", "attachment; filename=" + resource.name() + resource.suffix());
return Response.ok(bytes).build();
}
Aggregations