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);
}
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);
}
}
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();
}
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);
}
Aggregations