Search in sources :

Example 1 with CustomServicesPrimitiveResourceType

use of com.emc.storageos.primitives.CustomServicesPrimitiveResourceType in project coprhd-controller by CoprHD.

the class CustomServicesPrimitiveService method upload.

/**
 * Upload a resource
 *
 * @param request HttpServletRequest containing the file octet stream
 * @param type The type of the primitive file resource
 * @param name The user defined name of the resource
 * @return A rest response containing details of the resource that was created
 */
@POST
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Consumes({ MediaType.APPLICATION_OCTET_STREAM })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/resource")
public CustomServicesPrimitiveResourceRestRep upload(@Context final HttpServletRequest request, @QueryParam("type") final String type, @QueryParam("name") final String name, @QueryParam("parentId") final String parentId) {
    ArgValidator.checkFieldNotNull(type, "type");
    ArgValidator.checkFieldNotNull(name, "name");
    final CustomServicesResourceDAO<?> dao = getResourceDAO(type, true);
    final byte[] stream = UploadHelper.read(request);
    final CustomServicesPrimitiveResourceType resource = dao.createResource(name, stream, parentId);
    return CustomServicesPrimitiveMapper.map(resource);
}
Also used : CustomServicesPrimitiveResourceType(com.emc.storageos.primitives.CustomServicesPrimitiveResourceType) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with CustomServicesPrimitiveResourceType

use of com.emc.storageos.primitives.CustomServicesPrimitiveResourceType in project coprhd-controller by CoprHD.

the class WorkflowHelper method addResource.

private static void addResource(Builder builder, NamedURI id, CustomServicesResourceDAOs resourceDAOs) {
    final CustomServicesResourceDAO<?> dao = resourceDAOs.getByModel(URIUtil.getTypeName(id.getURI()));
    if (null == dao) {
        throw new RuntimeException("Resource type for " + id + " not found");
    }
    final CustomServicesPrimitiveResourceType resource = dao.getResource(id.getURI());
    if (null == resource) {
        throw new RuntimeException("Resource " + id + " not found");
    }
    builder.addResource(new ResourcePackage(CustomServicesPrimitiveMapper.map(resource), resource.resource()));
    for (final NamedElement related : dao.listRelatedResources(id.getURI())) {
        addResource(builder, new NamedURI(related.getId(), related.getName()), resourceDAOs);
    }
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) ResourcePackage(com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage) CustomServicesPrimitiveResourceType(com.emc.storageos.primitives.CustomServicesPrimitiveResourceType) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Example 3 with CustomServicesPrimitiveResourceType

use of com.emc.storageos.primitives.CustomServicesPrimitiveResourceType 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)

Example 4 with CustomServicesPrimitiveResourceType

use of com.emc.storageos.primitives.CustomServicesPrimitiveResourceType in project coprhd-controller by CoprHD.

the class CustomServicesPrimitiveService method updateResource.

/**
 * Update a primitive resource
 *
 * @param id the ID of the primitivie to be updated
 * @param name The user defined name of the resource to be updated
 * @return
 */
@PUT
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("resource/{id}")
public CustomServicesPrimitiveResourceRestRep updateResource(@Context final HttpServletRequest request, @PathParam("id") final URI id, @QueryParam("name") final String name, @QueryParam("parentId") final String parentId) {
    final CustomServicesResourceDAO<?> dao = getResourceDAOFromID(id);
    if (null == dao) {
        throw APIException.notFound.unableToFindEntityInURL(id);
    }
    final byte[] stream = UploadHelper.read(request);
    final CustomServicesPrimitiveResourceType resource = dao.updateResource(id, name, (stream == null || stream.length == 0) ? null : stream, parentId);
    return CustomServicesPrimitiveMapper.map(resource);
}
Also used : CustomServicesPrimitiveResourceType(com.emc.storageos.primitives.CustomServicesPrimitiveResourceType) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

CustomServicesPrimitiveResourceType (com.emc.storageos.primitives.CustomServicesPrimitiveResourceType)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)2 ResourcePackage (com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage)1 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)1 ModelObject (com.emc.storageos.db.client.model.ModelObject)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1