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