Search in sources :

Example 1 with WFDirectory

use of com.emc.storageos.db.client.model.uimodels.WFDirectory in project coprhd-controller by CoprHD.

the class CustomServicesWorkflowService method importWorkflow.

@POST
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Consumes({ MediaType.APPLICATION_OCTET_STREAM })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/import")
public CustomServicesWorkflowRestRep importWorkflow(@Context final HttpServletRequest request, @QueryParam("directory") final URI directory) {
    final WFDirectory wfDirectory;
    if (URIUtil.isNull(directory) || directory.toString().isEmpty()) {
        wfDirectory = NO_DIR;
    } else {
        wfDirectory = wfDirectoryManager.getWFDirectoryById(directory);
    }
    final InputStream in;
    try {
        in = request.getInputStream();
    } catch (final IOException e) {
        throw APIException.internalServerErrors.genericApisvcError("Failed to open servlet input stream", e);
    }
    return map(WorkflowHelper.importWorkflow(in, wfDirectory, client, daos, resourceDAOs));
}
Also used : WFDirectory(com.emc.storageos.db.client.model.uimodels.WFDirectory) InputStream(java.io.InputStream) IOException(java.io.IOException) 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 WFDirectory

use of com.emc.storageos.db.client.model.uimodels.WFDirectory in project coprhd-controller by CoprHD.

the class WFDirectoryService method createWFDirectory.

/**
 * Create workflow directory
 *
 * @prereq none
 * @brief Create workflow directory
 * @return Created workflow directory
 */
@POST
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public WFDirectoryRestRep createWFDirectory(WFDirectoryParam wfDirectoryParam) {
    log.info("Creating wf directory");
    // Check for null fields
    // get,set workflows
    WFDirectory wfDirectory = new WFDirectory();
    final String createParamLabel = wfDirectoryParam.getName();
    final URI parentId = wfDirectoryParam.getParent() == null ? getRootLevelParentId() : wfDirectoryParam.getParent();
    if (null != wfDirectoryParam.getParent()) {
        checkWFDirExists(wfDirectoryParam.getParent());
    }
    if (StringUtils.isNotBlank(createParamLabel)) {
        checkDuplicateLabel(createParamLabel.trim(), parentId);
    } else {
        throw APIException.badRequests.requiredParameterMissingOrEmpty("name");
    }
    wfDirectory.setLabel(wfDirectoryParam.getName());
    wfDirectory.setParent(parentId);
    wfDirectory.setWorkflows(StringSetUtil.uriListToStringSet(wfDirectoryParam.getWorkflows()));
    wfDirectoryManager.createWFDirectory(wfDirectory);
    return map(wfDirectory);
}
Also used : WFDirectory(com.emc.storageos.db.client.model.uimodels.WFDirectory) URI(java.net.URI) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with WFDirectory

use of com.emc.storageos.db.client.model.uimodels.WFDirectory in project coprhd-controller by CoprHD.

the class WorkflowDirectoryManagerImpl method deleteDirectoryAndChildren.

private boolean deleteDirectoryAndChildren(URI id) {
    WFDirectory wfDirectory = client.wfDirectory().findById(id);
    if (null == wfDirectory) {
        throw APIException.notFound.unableToFindEntityInURL(id);
    }
    List<WFDirectory> children = getWFDirectoryChildren(id);
    // start deleting from inner nodes
    if (CollectionUtils.isEmpty(children)) {
        // delete only if the wfDirectory does not have any children
        client.delete(wfDirectory);
        return true;
    } else {
        for (final WFDirectory child : children) {
            deleteDirectoryAndChildren(child.getId());
        }
        // all children deleted. delete the empty folder
        client.delete(wfDirectory);
    }
    return true;
}
Also used : WFDirectory(com.emc.storageos.db.client.model.uimodels.WFDirectory)

Example 4 with WFDirectory

use of com.emc.storageos.db.client.model.uimodels.WFDirectory in project coprhd-controller by CoprHD.

the class WFDirectoryService method getWorkflowDirectories.

/**
 * Get workflow directories
 *
 * @prereq none
 * @brief Get workflow directories
 * @return List of workflow directories
 */
@GET
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public WFDirectoryList getWorkflowDirectories() {
    List<WFDirectory> wfDirectories = wfDirectoryManager.getWFDirectories();
    WFDirectoryList wfDirectoryList = new WFDirectoryList();
    for (WFDirectory dir : wfDirectories) {
        NamedRelatedResourceRep wfDirectoryRestRep = toNamedRelatedResource(ResourceTypeEnum.WF_DIRECTORY, dir.getId(), dir.getLabel());
        wfDirectoryList.getWFDirectories().add(wfDirectoryRestRep);
    }
    return wfDirectoryList;
}
Also used : WFDirectory(com.emc.storageos.db.client.model.uimodels.WFDirectory) WFDirectoryList(com.emc.vipr.model.catalog.WFDirectoryList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 5 with WFDirectory

use of com.emc.storageos.db.client.model.uimodels.WFDirectory in project coprhd-controller by CoprHD.

the class WFDirectoryService method updateWFDirectory.

/**
 * Update workflow directory (name, parent, workflows)
 *
 * @prereq none
 * @brief Update workflow directory
 * @return Updated workflow directory
 */
@PUT
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
public WFDirectoryRestRep updateWFDirectory(@PathParam("id") URI id, WFDirectoryUpdateParam param) {
    WFDirectory wfDirectory = checkWFDirExists(id);
    // update object
    if (StringUtils.isNotBlank(param.getName())) {
        final String label = param.getName().trim();
        if (!label.equalsIgnoreCase(wfDirectory.getLabel())) {
            final URI parentId = param.getParent() == null ? wfDirectory.getParent() : param.getParent();
            checkDuplicateLabel(label, parentId);
            wfDirectory.setLabel(param.getName());
        }
    }
    if (null != param.getParent()) {
        // no need to set the parent to getRootLevelParentId() since this would have been set during creation
        checkWFDirExists(param.getParent());
        wfDirectory.setParent(param.getParent());
    }
    if (null != param.getWorkflows()) {
        wfDirectory.addWorkflows(param.getWorkflows().getAdd());
        wfDirectory.removeWorkflows(param.getWorkflows().getRemove());
        log.debug(wfDirectory.getWorkflows().toString());
    }
    wfDirectoryManager.updateWFDirectory(wfDirectory);
    return map(wfDirectory);
}
Also used : WFDirectory(com.emc.storageos.db.client.model.uimodels.WFDirectory) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

WFDirectory (com.emc.storageos.db.client.model.uimodels.WFDirectory)7 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 Produces (javax.ws.rs.Produces)4 URI (java.net.URI)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)1 WFBulkRep (com.emc.vipr.model.catalog.WFBulkRep)1 WFDirectoryList (com.emc.vipr.model.catalog.WFDirectoryList)1 WFDirectoryRestRep (com.emc.vipr.model.catalog.WFDirectoryRestRep)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1