Search in sources :

Example 1 with ModelObject

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();
}
Also used : ModelObject(com.emc.storageos.db.client.model.ModelObject) CustomServicesPrimitiveRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep) ImmutableList(com.google.common.collect.ImmutableList) URI(java.net.URI) CustomServicesViPRPrimitive(com.emc.storageos.primitives.java.vipr.CustomServicesViPRPrimitive)

Example 2 with ModelObject

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();
}
Also used : ModelObject(com.emc.storageos.db.client.model.ModelObject) CustomServicesPrimitiveResourceType(com.emc.storageos.primitives.CustomServicesPrimitiveResourceType) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

ModelObject (com.emc.storageos.db.client.model.ModelObject)2 CustomServicesPrimitiveRestRep (com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep)1 CustomServicesPrimitiveResourceType (com.emc.storageos.primitives.CustomServicesPrimitiveResourceType)1 CustomServicesViPRPrimitive (com.emc.storageos.primitives.java.vipr.CustomServicesViPRPrimitive)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 ImmutableList (com.google.common.collect.ImmutableList)1 URI (java.net.URI)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1