cancel
Showing results for 
Search instead for 
Did you mean: 

Undeploy workflow on Alfresco Community Edition(5.0.c)

satheeshkumar
Champ in-the-making
Champ in-the-making
Hi all.

I'm learning workflow process development for alfresco (community edition 5.0.c).
Have deployed simple workflow on alfresco using bootstrap method.
Now I need to undeploy it, but can not find how to do it.

I have removed xml files but workflow is shown in "Start Workflow" menu anyway.
there is no workflow console for community edition.

Undeploy workflow on Alfresco Community Edition.

I tried this link http://<host>:<port>/alfresco/faces/jsp/admin/workflow-console.jsp

It leads to 404 Page, I guess, the Explorer interface is removed Alfresco Community 5.0.c, so it might have causing this issue.
Can someone help me how to undeploy workflow in this 5.0.c version.
12 REPLIES 12

s_palyukh
Star Contributor
Star Contributor
All admin consoles are gone in Alfresco 5… http://ecmarchitect.com/archives/2014/11/06/3962

The beans to use them are all still present in the Community codeline - it's just the JSF based UI that is missing. It means that you can write some code to undeploy your workflow model.

There are methods to deploy and undeploy workflow definitions in WorkflowService:


public WorkflowDeployment deployDefinition(String engineId, InputStream workflowDefinition, String mimetype);

public void undeployDefinition(String workflowDefinitionId);

priyesh
Champ in-the-making
Champ in-the-making
Thanks for your answer.But, will you please elaborate about where to write the above mentioned methods?

For those, who want a code snippet, here you go.

I just created a Java class which extends BaseProcessorExtension, configured in the bean and injected ServiceRegistry and accessed the method(undeployUnUsedDefinitions(true)) via Rule(Execute Script). I hope this helps.
Let me know if it still not clear.
I have excluded few Workflows which came along with Alfresco.

UnDeploy Code Snippet!!!

public void undeployUnUsedDefinitions(boolean deleteFlag){
      WorkflowService wfService = getServiceRegistry().getWorkflowService();
      List<WorkflowDefinition> workFlowDefinitions = wfService.getAllDefinitions();
      for(WorkflowDefinition wfd : workFlowDefinitions){
         String wfId = wfd.getId();
         
         List<String> excludeList = new ArrayList<String>();
         excludeList.add("activiti$activitiAdhoc:1:4");
         excludeList.add("activiti$activitiInvitationModerated:1:23");
         excludeList.add("activiti$activitiInvitationNominated:1:26");
         excludeList.add("activiti$activitiParallelGroupReview:1:20");
         excludeList.add("activiti$activitiParallelReview:1:16");
         excludeList.add("activiti$activitiReview:1:8");
         excludeList.add("activiti$activitiReviewPooled:1:12");
         
         
         logger.debug("WorkFlowDefinition IDs :"+wfId);
         
         if(deleteFlag){
            if(excludeList.contains(wfId)){
               logger.info("WorkFlowDefinitionID belongs to the sample and should not be deleted wfID: "+wfId);
            }
            else{
               wfService.undeployDefinition(wfId);
               logger.info("WorkFlowDefinitionID deleted successfully wfID: "+wfId);
            }
            
         }
         
      }
   }

I am new on Alfresco,
so i do not know how to run this java code to undeploy workflow
Please Help
Thanks in Advance

s_palyukh
Star Contributor
Star Contributor
You have several ways:

1) Create custom Java Bean that will be available in JS API (http://wiki.alfresco.com/wiki/4.0_JavaScript_API#Adding_Custom_Script_APIs) and implement logic to undeploy workflow
2) Create Java based webscript that will be called by HTTP request and where you implement logic to undeploy workflow (https://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples)

priyesh
Champ in-the-making
Champ in-the-making
Thank You,
I think my problem would be solved.

maulikjajal
Champ in-the-making
Champ in-the-making
Can you give me some tutorial or example to how to done this ???

This is how I did,

Created a utility class for undeploying the workflow definitions,

package org.hc.utils;

import java.util.ArrayList;
import java.util.List;

import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.apache.log4j.Logger;

public class HCWorkFlowUtility {
   protected static Logger logger = Logger.getLogger(HCWorkFlowUtility.class);

   private static ServiceRegistry serviceRegistry;

   public static void undeployUnUsedDefinitions(boolean deleteFlag) {
      WorkflowService wfService = getServiceRegistry().getWorkflowService();
      List<WorkflowDefinition> workFlowDefinitions = wfService
            .getAllDefinitions();
      for (WorkflowDefinition wfd : workFlowDefinitions) {
         String wfId = wfd.getId();

         List<String> excludeList = new ArrayList<String>();
         excludeList.add("activiti$activitiAdhoc:1:4");
         excludeList.add("activiti$activitiInvitationModerated:1:23");
         excludeList.add("activiti$activitiInvitationNominated:1:26");
         excludeList.add("activiti$activitiParallelGroupReview:1:20");
         excludeList.add("activiti$activitiParallelReview:1:16");
         excludeList.add("activiti$activitiReview:1:8");
         excludeList.add("activiti$activitiReviewPooled:1:12");

         logger.debug("WorkFlowDefinition IDs :" + wfId);

         if (excludeList.contains(wfId)) {
            logger.info("WorkFlowDefinitionID belongs to the sample and will not be deleted wfID: "
                  + wfId);
         } else {
            if (deleteFlag) {
               wfService.undeployDefinition(wfId);
               logger.warn("WorkFlowDefinitionID deleted successfully wfID: "
                     + wfId);
            } else {
               logger.warn("WorkFlowDefinitionID can be deleted, wfID: "
                     + wfId);
            }
         }
      }
   }

   public static ServiceRegistry getServiceRegistry() {
      return serviceRegistry;
   }

   public static void setServiceRegistry(ServiceRegistry serviceRegistry) {
      HCWorkFlowUtility.serviceRegistry = serviceRegistry;
   }

}



Created a Java backed Webscript for accessing from UI,


package org.hc.javabackedwebscripts.content;

import java.util.HashMap;
import java.util.Map;

import org.alfresco.error.AlfrescoRuntimeException;
import org.apache.log4j.Logger;
import org.hc.utils.HCWorkFlowUtility;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;

public class UnDeployWorkflows extends DeclarativeWebScript {
   protected Logger logger = Logger.getLogger(UnDeployWorkflows.class);

   @Override
   protected Map<String, Object> executeImpl(WebScriptRequest req,
         Status status, Cache cache) {

      String deleteStr = req.getParameter("delete");

      boolean deleteFlag = Boolean.valueOf(deleteStr);

      try {
         HCWorkFlowUtility.undeployUnUsedDefinitions(deleteFlag);
      } catch (Exception e) {
         logger.error("Error occured while deleting the old workflows. Please see the log for more details!");
         throw new AlfrescoRuntimeException(e.getMessage());
      }

      Map<String, Object> model = new HashMap<>();
      String resultMessage = null;
      if (deleteFlag) {
         resultMessage = "All the old workflows have been successfully deleted, please see the log for the list of worklflows deleted.";
      } else {
         resultMessage = "All the old workflows have been successfully printed in the log, please see the log for the list.";
      }
      model.put("resultMessage", resultMessage);

      return model;

   }
}



Register the beans like this,



<bean id="${project.artifactId}_hcWorkFlowUtility" class="org.hc.utils.HCWorkFlowUtility">      
       <property name="serviceRegistry" ref="ServiceRegistry"/>
</bean>
<bean id="webscript.workflow.undeploy-workflow.get" class="org.hc.javabackedwebscripts.content.UnDeployWorkflows" parent="webscript"/>



Create a web script, under /config/alfresco/extension/templates/webscripts/workflow/



/** undeploy-workflow.get.desc.xml **/
<webscript>
   <shortname>Undeploys the deployed workflows</shortname>
   <description>This undeploys the deployed workflows based the flag set in it.</description>
   <url>/undeploy-workflow?delete={deleteFlag}</url>
   <format default="json">extension</format>
   <authentication>admin</authentication>
</webscript>

/** undeploy-workflow.get.json.ftl **/

{   
   result:
   [
      {
         undeployResult: "${resultMessage!'Result Message Not Found'}"
      }
   ]   
}




Once you successfully deployed these stuff, you can access them via,
http://<host>:<port>/alfresco/service/undeploy-workflow?delete={deleteFlag}
Where deleteFlag, if set to true will undeploys the workflows. if set to false it just prints the workflows in the log.

Note: Before you access this link, you will have to login as "admin".

Hope the information provided is useful, if so "Please mark the comment as useful".

After following all the above steps, I am struck by the following error:

{
    "status" :
  {
    "code" : 500,
    "name" : "Internal Error",
    "description" : "An error inside the HTTP server which prevented it from fulfilling the request."
  }, 
 
  "message" : "02110001 Wrapped Exception (with status template): 02110011 \r\n### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: update or delete on table \"act_re_procdef\" violates foreign key constraint \"act_fk_exe_procdef\" on table \"act_ru_execution\"\n  Detail: Key (id_)=(activitiInvitationNominated:1:26) is still referenced from table \"act_ru_execution\".\r\n### The error may involve org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity.deleteProcessDefinitionsByDeploymentId-Inline\r\n### The error occurred while setting parameters\r\n### SQL: delete from ACT_RE_PROCDEF where DEPLOYMENT_ID_ = ?\r\n### Cause: org.postgresql.util.PSQLException: ERROR: update or delete on table \"act_re_procdef\" violates foreign key constraint \"act_fk_exe_procdef\" on table \"act_ru_execution\"\n  Detail: Key (id_)=(activitiInvitationNominated:1:26) is still referenced from table \"act_ru_execution\".", 
  "exception" : "org.springframework.extensions.webscripts.WebScriptException - 02110001 Wrapped Exception (with status template): 02110011 \r\n### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: update or delete on table \"act_re_procdef\" violates foreign key constraint \"act_fk_exe_procdef\" on table \"act_ru_execution\"\n  Detail: Key (id_)=(activitiInvitationNominated:1:26) is still referenced from table \"act_ru_execution\".\r\n### The error may involve org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity.deleteProcessDefinitionsByDeploymentId-Inline\r\n### The error occurred while setting parameters\r\n### SQL: delete from ACT_RE_PROCDEF where DEPLOYMENT_ID_ = ?\r\n### Cause: org.postgresql.util.PSQLException: ERROR: update or delete on table \"act_re_procdef\" violates foreign key constraint \"act_fk_exe_procdef\" on table \"act_ru_execution\"\n  Detail: Key (id_)=(activitiInvitationNominated:1:26) is still referenced from table \"act_ru_execution\".",
 
  "callstack" :
  [
       ""      ,"org.alfresco.error.AlfrescoRuntimeException: 02110011 \r\n### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: update or delete on table \"act_re_procdef\" violates foreign key constraint \"act_fk_exe_procdef\" on table \"act_ru_execution\"\n  Detail: Key (id_)=(activitiInvitationNominated:1:26) is still referenced from table \"act_ru_execution\".\r\n### The error may involve org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity.deleteProcessDefinitionsByDeploymentId-Inline\r\n### The error occurred while setting parameters\r\n### SQL: delete from ACT_RE_PROCDEF where DEPLOYMENT_ID_ = ?\r\n### Cause: org.postgresql.util.PSQLException: ERROR: update or delete on table \"act_re_procdef\" violates foreign key constraint \"act_fk_exe_procdef\" on table \"act_ru_execution\"\n  Detail: Key (id_)=(activitiInvitationNominated:1:26) is still referenced from table \"act_ru_execution\"."
      ,"org.hc.javabackedwebscripts.content.UnDeployWorkflows.executeImpl(UnDeployWorkflows.java:29)"
      ,"org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:64)"
      ,"org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:470)"
      ,"org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:454)"
      ,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:532)"
      ,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:600)"
      ,"org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:380)"
      ,"org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:261)"
      ,"org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)"
      ,"org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)"
      ,"org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)"
      ,"javax.servlet.http.HttpServlet.service(HttpServlet.java:727)"
      ,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)"
      ,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)"
      ,"org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)"
      ,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)"
      ,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)"
      ,"org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)"
      ,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)"
      ,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)"
      ,"org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)"
      ,"org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)"
      ,"org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)"
      ,"org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)"
      ,"org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)"
      ,"org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)"
      ,"org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)"
      ,"org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)"
      ,"org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)"
      ,"org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)"
      ,"org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)"
      ,"org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)"
      ,"java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)"
      ,"java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)"
      ,"java.lang.Thread.run(Unknown Source)"
      ,"org.springframework.extensions.webscripts.WebScriptException: 02110001 Wrapped Exception (with status template): 02110011 \r\n### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: update or delete on table \"act_re_procdef\" violates foreign key constraint \"act_fk_exe_procdef\" on table \"act_ru_execution\"\n  Detail: Key (id_)=(activitiInvitationNominated:1:26) is still referenced from table \"act_ru_execution\".\r\n### The error may involve org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity.deleteProcessDefinitionsByDeploymentId-Inline\r\n### The error occurred while setting parameters\r\n### SQL: delete from ACT_RE_PROCDEF where DEPLOYMENT_ID_ = ?\r\n### Cause: org.postgresql.util.PSQLException: ERROR: update or delete on table \"act_re_procdef\" violates foreign key constraint \"act_fk_exe_procdef\" on table \"act_ru_execution\"\n  Detail: Key (id_)=(activitiInvitationNominated:1:26) is still referenced from table \"act_ru_execution\"."
      ,"org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1126)"

  ],
 
  "server" : "Community v5.0.0 (c r91299-b145) schema 8,009",
  "time" : "Mar 11, 2015 10:55:54 AM"
}

  
Please help. Thanks in advance.