use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.
the class CCCheckoutFileDialog method checkoutFile.
/**
* Action called upon completion of the Check Out file page
*/
public String checkoutFile(FacesContext context, String outcome) {
boolean checkoutSuccessful = false;
final Node node = property.getDocument();
if (node != null) {
try {
if (logger.isDebugEnabled())
logger.debug("Trying to checkout content node Id: " + node.getId());
// checkout the node content to create a working copy
if (logger.isDebugEnabled()) {
logger.debug("Checkout copy location: " + property.getCopyLocation());
logger.debug("Selected Space Id: " + property.getSelectedSpaceId());
}
NodeRef workingCopyRef = null;
if (property.getCopyLocation().equals(CCProperties.COPYLOCATION_OTHER) && property.getSelectedSpaceId() != null) {
// checkout to a arbituary parent Space
NodeRef destRef = property.getSelectedSpaceId();
ChildAssociationRef childAssocRef = getNodeService().getPrimaryParent(destRef);
workingCopyRef = property.getVersionOperationsService().checkout(node.getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, childAssocRef.getQName());
} else {
// checkout the content to the current space
workingCopyRef = property.getVersionOperationsService().checkout(node.getNodeRef());
// in the resources panel in the manage task dialog
if (property.isWorkflowAction() && property.getWorkflowTaskId() != null && (property.getWorkflowTaskId().equals("null") == false)) {
WorkflowTask task = property.getWorkflowService().getTaskById(property.getWorkflowTaskId());
if (task != null) {
NodeRef workflowPackage = (NodeRef) task.properties.get(WorkflowModel.ASSOC_PACKAGE);
if (workflowPackage != null) {
getNodeService().addChild(workflowPackage, workingCopyRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName((String) getNodeService().getProperty(workingCopyRef, ContentModel.PROP_NAME))));
if (logger.isDebugEnabled())
logger.debug("Added working copy to workflow package: " + workflowPackage);
}
}
}
}
// set the working copy Node instance
Node workingCopy = new Node(workingCopyRef);
property.setWorkingDocument(workingCopy);
// create content URL to the content download servlet with ID
// and expected filename
// the myfile part will be ignored by the servlet but gives the
// browser a hint
String url = DownloadContentServlet.generateDownloadURL(workingCopyRef, workingCopy.getName());
workingCopy.getProperties().put("url", url);
workingCopy.getProperties().put("fileType32", FileTypeImageUtils.getFileTypeImage(workingCopy.getName(), false));
// mark as successful
checkoutSuccessful = true;
} catch (Throwable err) {
Utils.addErrorMessage(Application.getMessage(context, MSG_ERROR_CHECKOUT) + err.getMessage(), err);
ReportedException.throwIfNecessary(err);
}
} else {
logger.warn("WARNING: checkoutFile called without a current Document!");
}
// determine which page to show next if the checkout was successful.
if (checkoutSuccessful) {
// already disappeared!
if (getNodeService().exists(property.getWorkingDocument().getNodeRef())) {
// go to the page that allows the user to download the content
// for editing
// "checkoutFileLink";
outcome = "dialog:checkoutFileLink";
// //checkout-file-link.jsp
// currentAction = Action.CHECKOUT_FILE_LINK;
} else {
// show a page telling the user that the content has already
// been checked in
// "workingCopyMissing";
outcome = "dialog:workingCopyMissing";
// //
// working-copy-missing.jsp
// currentAction = Action.WORKING_COPY_MISSING;
}
}
return outcome;
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.
the class WorkflowUtil method isTaskEditable.
public static boolean isTaskEditable(String taskId, ServletContext sc) {
if (taskId == null || taskId.isEmpty()) {
return false;
}
ServiceRegistry serviceRegistry = Repository.getServiceRegistry(sc);
String username = serviceRegistry.getAuthenticationService().getCurrentUserName();
WorkflowService workflowService = serviceRegistry.getWorkflowService();
WorkflowTask task = workflowService.getTaskById(taskId);
return workflowService.isTaskEditable(task, username);
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.
the class StartWorkflowWizard method finishImpl.
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
if (logger.isDebugEnabled())
logger.debug("Starting workflow: " + this.selectedWorkflow);
// prepare the parameters from the current state of the property sheet
Map<QName, Serializable> params = WorkflowUtil.prepareTaskParams(this.startTaskNode);
if (logger.isDebugEnabled())
logger.debug("Starting workflow with parameters: " + params);
// create a workflow package for the attached items and add them
NodeRef workflowPackage = this.getWorkflowService().createPackage(null);
params.put(WorkflowModel.ASSOC_PACKAGE, workflowPackage);
for (String addedItem : this.packageItemsToAdd) {
NodeRef addedNodeRef = new NodeRef(addedItem);
// MNT-11522. fix bug. add behavior filter for add items in workflow package.
try {
this.getBehaviourFilter().disableBehaviour(addedNodeRef, ContentModel.ASPECT_AUDITABLE);
this.getUnprotectedNodeService().addChild(workflowPackage, addedNodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName((String) this.getNodeService().getProperty(addedNodeRef, ContentModel.PROP_NAME))));
} finally {
this.getBehaviourFilter().enableBehaviour(addedNodeRef, ContentModel.ASPECT_AUDITABLE);
}
}
// setup the context for the workflow (this is the space the workflow was launched from)
Node workflowContext = this.navigator.getCurrentNode();
if (workflowContext != null) {
params.put(WorkflowModel.PROP_CONTEXT, (Serializable) workflowContext.getNodeRef());
}
// start the workflow to get access to the start task
WorkflowPath path = this.getWorkflowService().startWorkflow(this.selectedWorkflow, params);
if (path != null) {
// extract the start task
List<WorkflowTask> tasks = this.getWorkflowService().getTasksForWorkflowPath(path.id);
if (tasks.size() == 1) {
WorkflowTask startTask = tasks.get(0);
if (logger.isDebugEnabled())
logger.debug("Found start task:" + startTask);
if (startTask.state == WorkflowTaskState.IN_PROGRESS) {
// end the start task to trigger the first 'proper'
// task in the workflow
this.getWorkflowService().endTask(startTask.id, null);
}
}
if (logger.isDebugEnabled())
logger.debug("Started workflow: " + this.selectedWorkflow);
}
return outcome;
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.
the class WorkflowBean method getTasksCompleted.
/**
* Returns a list of nodes representing the completed tasks the
* current user has.
*
* @return List of completed tasks
*/
public List<Node> getTasksCompleted() {
if (this.completedTasks == null) {
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = user.getUserName();
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
// get the current in progress tasks for the current user
ClientConfigElement clientConfig = (ClientConfigElement) Application.getConfigService(context).getGlobalConfig().getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID);
WorkflowTaskQuery query = new WorkflowTaskQuery();
query.setActive(null);
query.setActorId(userName);
query.setTaskState(WorkflowTaskState.COMPLETED);
query.setLimit(clientConfig.getTasksCompletedMaxResults());
List<WorkflowTask> tasks = this.getWorkflowService().queryTasks(query);
// create a list of transient nodes to represent
this.completedTasks = new ArrayList<Node>(tasks.size());
for (WorkflowTask task : tasks) {
Node node = createTask(task);
this.completedTasks.add(node);
if (logger.isDebugEnabled())
logger.debug("Added completed task: " + node);
}
// commit the changes
tx.commit();
} catch (Throwable e) {
// rollback the transaction
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception ex) {
}
Utils.addErrorMessage("Failed to get completed tasks: " + e.toString(), e);
}
}
return this.completedTasks;
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.
the class WorkflowBean method getPooledTasks.
/**
* Returns a list of nodes representing the "pooled" to do tasks the
* current user has.
*
* @return List of to do tasks
*/
public List<Node> getPooledTasks() {
if (this.pooledTasks == null) {
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = user.getUserName();
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
// get the current pooled tasks for the current user
List<WorkflowTask> tasks = this.getWorkflowService().getPooledTasks(userName, true);
// create a list of transient nodes to represent
this.pooledTasks = new ArrayList<Node>(tasks.size());
for (WorkflowTask task : tasks) {
Node node = createTask(task);
this.pooledTasks.add(node);
if (logger.isDebugEnabled())
logger.debug("Added pooled task: " + node);
}
// commit the changes
tx.commit();
} catch (Throwable e) {
// rollback the transaction
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception ex) {
}
Utils.addErrorMessage("Failed to get pooled tasks: " + e.toString(), e);
}
}
return this.pooledTasks;
}
Aggregations