[Resolu] Transaction didn't commit

cancel
Showing results for 
Search instead for 
Did you mean: 
huberd
Member II

[Resolu] Transaction didn't commit

Bonjour,

Lorsque je lance mon étape d'approbation de mon worklflow

   <!–**************************–> 
   <!–**     <Task Node>      **–>
   <!–**      published       **–>
   <!–**************************–>    
   <task-node name="published">
      <task name="lwf:publishedTask" swimlane="initiator"/>
     
      <event type="node-enter">
         <action class="org.alfresco.community.repo.workflow.jbpm.Actions"/>
      </event>    
     
      <transition to="end"/>
     
   </task-node>  

j'obtiens le message d'erreur suivant sur mon ecran

Une erreur système s'est produite pendant l'opération : Transaction didn't commit: Failed to execute transaction-level behaviour public abstract void org.alfresco.repo.node.NodeServicePolicies$OnAddAspectPolicy.onAddAspect(org.alfresco.service.cmr.repository.NodeRef,org.alfresco.service.namespace.QName) in transaction 5672394d-8bf8-11de-b5c8-0dbbf99be43b 

et voici le log associé
22:56:53,235 ERROR [ui.common.Utils] Une erreur système s'est produite pendant l'opération : Transaction didn't commit: Failed to execute transaction-level behaviour public abstract void org.alfresco.repo.node.NodeServicePolicies$OnAddAspectPolicy.onAddAspect(org.alfresco.service.cmr.repository.NodeRef,org.alfresco.service.namespace.QName) in transaction b966b38e-8d02-11de-9cda-5182e1603f3e
javax.transaction.RollbackException: Transaction didn't commit: Failed to execute transaction-level behaviour public abstract void org.alfresco.repo.node.NodeServicePolicies$OnAddAspectPolicy.onAddAspect(org.alfresco.service.cmr.repository.NodeRef,org.alfresco.service.namespace.QName) in transaction b966b38e-8d02-11de-9cda-5182e1603f3e
   at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:430)
   at org.alfresco.web.bean.workflow.ManageTaskDialog.transition(ManageTaskDialog.java:393)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
   at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
   at javax.faces.component.UICommand.broadcast(UICommand.java:109)
   at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
   at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
   at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
   at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.alfresco.web.app.servlet.NTLMAuthenticationFilter.doFilter(NTLMAuthenticationFilter.java:329)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
   at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:834)
   at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
   at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1286)
   at java.lang.Thread.run(Unknown Source)
Caused by: org.alfresco.error.AlfrescoRuntimeException: Failed to execute transaction-level behaviour public abstract void org.alfresco.repo.node.NodeServicePolicies$OnAddAspectPolicy.onAddAspect(org.alfresco.service.cmr.repository.NodeRef,org.alfresco.service.namespace.QName) in transaction b966b38e-8d02-11de-9cda-5182e1603f3e
   at org.alfresco.repo.policy.TransactionBehaviourQueue.execute(TransactionBehaviourQueue.java:201)
   at org.alfresco.repo.policy.TransactionBehaviourQueue.beforeCommit(TransactionBehaviourQueue.java:133)
   at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.beforeCommit(AlfrescoTransactionSupport.java:626)
   at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:48)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:821)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:637)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:624)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:307)
   at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:420)
   … 29 more
Caused by: org.alfresco.repo.security.permissions.AccessDeniedException: Accès interdit.  Vous n'avez pas la permission de réaliser cette opération.
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:53)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
   at $Proxy2.addAspect(Unknown Source)
   at org.alfresco.repo.version.VersionServiceImpl.createVersion(VersionServiceImpl.java:302)
   at org.alfresco.repo.version.VersionServiceImpl.createVersion(VersionServiceImpl.java:183)
   at org.alfresco.repo.version.VersionableAspect.onAddAspect(VersionableAspect.java:208)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.alfresco.repo.policy.JavaBehaviour$JavaMethodInvocationHandler.invoke(JavaBehaviour.java:179)
   at $Proxy32.onAddAspect(Unknown Source)
   at sun.reflect.GeneratedMethodAccessor351.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.alfresco.repo.policy.TransactionBehaviourQueue.execute(TransactionBehaviourQueue.java:189)
   … 37 more
Caused by: net.sf.acegisecurity.AccessDeniedException: Access is denied.
   at net.sf.acegisecurity.vote.AffirmativeBased.decide(AffirmativeBased.java:86)
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:394)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   … 59 more


Le code de l'action est le suivant :

public class Actions extends JBPMSpringActionHandler { 

   private static final long serialVersionUID = 1L;

   private static final Logger logger = Logger.getLogger(Actions.class);

   private BeanFactory factory;

   /** NodeService bean reference */
   private static NodeService nodeService;

   /** AuthorityService bean reference */
   protected static AuthorityService authorityService;

   /** PermissionService bean reference */
   protected static PermissionService permissionService;

   /** personService bean reference */
   protected static PersonService personService;

   /** JavaMailSender bean reference */
   protected static JavaMailSender mailSender;

   /** WorkflowService bean reference */
   private static WorkflowService workflowService;

   /** Helper providing template based mailing facilities */
   protected static TemplateMailHelperBean mailHelper;

   /** list of user/group wrapper objects */
   protected static List<UserGroup> usersGroup = null;

   //private static AuthorityDAO authorityDAO;
   private static OwnableService ownableService;
   private static NamespaceService namespaceService;
   private static ContentService contentService;
   private static CheckOutCheckInService checkOutCheckInService;
   private static VersionService versionService;
   private static FileFolderService fileFolderService;
   //private static MimetypeService mimetypeService;
   private static CopyService copyService;
   

   /** current User */
   private String currentUser = null;


   // Common Properties
   //private static final String BASE_RESOURCE_NAME = "alfresco.messages.notify.notifyMessages-messages";


   // NODE TYPE
   private static final String START_STATE="StartState";
   private static final String NODE = "Node";
   private static final String END_STATE="EndState";


   // NODE NAME
   private static final String NODE_START_NAME ="start";
   private static final String NODE_STARTREVIEW_NAME="startreview";
   private static final String NODE_STARTAPPROVAL_NAME ="startapproval";
   private static final String NODE_END_NAME ="end";

   // TASKS NODE NAME
   private static final String TASK_NODE_REVIEW_NAME ="review";
   @SuppressWarnings("unused")
   private static final String TASK_NODE_APPROVED_AND_PUBLISHED_NAME = "approvedandpublished";
   private static final String TASK_NODE_APPROVAL_NAME = "approval";
   private static final String TASK_NODE_PUBLISHED_NAME ="published";
   private static final String TASK_NODE_REJECTED_NAME ="rejected";

   // Common Properties
   private static final String BASE_RESOURCE_NAME = "alfresco.messages.notify.notifyMessages-messages";
   private static final String COMMON_HEADER = "common-header";
   private static final String COMMON_FOOTER = "common-footer";

   //private static final String MAIL_SUBJECT = "subject_update";
   //private static final String MAIL_BODY_HEADER = "body_header";
   //private static final String MAIL_BODY_MSG = "body_update";

   // Reject
   private static final String REJECT_SUBJECT = "reject-subject";
   private static final String REJECT_BODY = "reject-body";

   // Review
   @SuppressWarnings("unused")
   private static final String REVIEW_SUBJECT = "review-subject";
   @SuppressWarnings("unused")
   private static final String REVIEW_BODY = "review-body";
   //private static final String REVIEWED_SUBJECT = "reviewed-subject";
   //private static final String REVIEWED_BODY = "reviewed-body";

   // Approval
   private static final String APPROVAL_SUBJECT = "approval-subject";
   private static final String APPROVAL_BODY = "approval-body";
   private static final String APPROVED_SUBJECT = "approved-subject";
   private static final String APPROVED_BODY = "approved-body";

   // Published
   @SuppressWarnings("unused")
   private static final String PUBLISHED_SUBJECT = "published-subject";
   @SuppressWarnings("unused")
   private static final String PUBLISHED_BODY = "published-body";
   @SuppressWarnings("unused")
   private static final String PUBLISHED_SUBJECT_NEW = "published-subject-new";
   @SuppressWarnings("unused")
   private static final String PUBLISHED_BODY_NEW = "published-body-new";
   @SuppressWarnings("unused")
   private static final String PUBLISHED_SUBJECT_UPDATE = "published-subject-update";
   @SuppressWarnings("unused")
   private static final String PUBLISHED_BODY_UPDATE = "published-body-update";

   private WorkflowInstance workflowInstance = null;
   private String workflowInstanceId = null;
   private static TaskInstance taskInstance = null;
   private static String initiator = null;
   private static String actor = null;
   private static Set pooledActors = null;

   @Override
   protected void initialiseHandler(BeanFactory factory) {
      this.factory = factory;
      mailSender = (JavaMailSender) this.factory.getBean("mailService");
      nodeService = (NodeService) this.factory.getBean("nodeService");
      authorityService = (AuthorityService) this.factory.getBean("authorityService");
      personService = (PersonService) this.factory.getBean("personService");
      permissionService = (PermissionService) this.factory.getBean("permissionService");
      workflowService = (WorkflowService) this.factory.getBean("WorkflowService");
      //authorityDAO = (AuthorityDAO)this.factory.getBean("authorityDAO");
      ownableService = (OwnableService)this.factory.getBean("ownableService");
      namespaceService = (NamespaceService) this.factory.getBean("namespaceService");
      //mimetypeService = (MimetypeService)this.factory.getBean("mimetypeService");
      contentService = (ContentService) this.factory.getBean("contentService");
      checkOutCheckInService = (CheckOutCheckInService) this.factory.getBean("checkOutCheckInService");
      versionService = (VersionService) this.factory.getBean("versionService");
      fileFolderService = (FileFolderService) this.factory.getBean("fileFolderService");
      copyService = (CopyService)this.factory.getBean("copyService"); 
   }

   public void execute(ExecutionContext executionContext) throws Exception {
      MyLogger.debugInfo("org.alfresco.community.repo.workflow.jbpm.Actions", -1, 1);

      try {
         Object res = executionContext.getContextInstance().getVariable("bpm_package");
         if(res == null) {
            //never enters here
            logger.fatal("bpm_package is null");
            return;
         }

         final NodeRef nodeRef = ((JBPMNode) res).getNodeRef();    
         if(nodeRef == null) {
            //never enters here
            logger.fatal("NodeRef is null");
            return;
         }

         // Change Current User by SYSTEM User
         currentUser=AuthenticationUtil.getCurrentUserName();
         AuthenticationUtil.setSystemUserAsCurrentUser();

         NodeRef docNodeRef = null;
         docNodeRef = RepositoryUtils.getChild(nodeRef);

         FacesContext context = FacesContext.getCurrentInstance();
         String from = Application.getClientConfig(context).getFromEmailAddress();
         Message message = null;

         // Register the bundle
         I18NUtil.registerResourceBundle(BASE_RESOURCE_NAME);

         // Prepare mail
         mailHelper = new TemplateMailHelperBean();
         mailHelper.setMailSender(mailSender);
         mailHelper.setNodeService(nodeService);

         workflowInstanceId = (String)nodeService.getProperty(nodeRef, WorkflowModel.PROP_WORKFLOW_INSTANCE_ID);
         workflowInstance = workflowService.getWorkflowById(workflowInstanceId);

         initiator = getInitiator();
         //System.out.println("INITIATOR ======> " + initiator);
         //System.out.println("CURRENT USER ===> " + currentUser);

         WorkflowPath workflowPath = null;
         List<WorkflowPath> cmrPaths = workflowService.getWorkflowPaths(workflowInstance.id);
         for (WorkflowPath cmrPath : cmrPaths)
         {
            //System.out.println("WPATH:       " + cmrPath);
            //System.out.println("NODE NAME:   " + cmrPath.node.name);
            //System.out.println("IS TASKNODE: " + cmrPath.node.isTaskNode);
            //System.out.println("TYPE:        " + cmrPath.node.type);
            //System.out.println("TITLE:       " + cmrPath.node.title);
            //System.out.println("TRANSITION:  " + cmrPath.node.transitions);
            workflowPath = cmrPath;
         }
         if(workflowPath.node.isTaskNode) {
            taskInstance = executionContext.getTaskInstance();
            if(taskInstance != null) {
               //System.out.println("==> Task ID: " + taskInstance.getId());
               if(taskInstance.getActorId() != null) {
                  actor = taskInstance.getActorId();   
                  //System.out.println("==> This is an actor: " + actor);
               }
               else
                  if(taskInstance.getPooledActors() != null) {
                     pooledActors = taskInstance.getPooledActors();
                     //System.out.println("==> This is a pooledActors: " + pooledActors);
                  }
            }
         }
         /******************************/
         /*        <StartState>        */
         /*            start           */
         /******************************/
         if(workflowPath.node.name.equals(NODE_START_NAME) && workflowPath.node.type.equals(START_STATE)) {
            MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);

            // Lock document for the current workflow
            Document.addAspectWorkflowNodeRef(docNodeRef);

            // Backup Owner et remove it
            if(!Document.hasAspectSaveOwner(docNodeRef)) {
               disabledPermissions(docNodeRef);
               removeOwner(docNodeRef);
            }

            // Add Aspect Contant Base Ref
            NodeRef baseSpaceNodeRef = RepositoryUtils.getParent(docNodeRef, 2);
            Document.addAspectContentsNodeRef(docNodeRef);
            Document.setPropertyContentBaseNodeRef(docNodeRef, baseSpaceNodeRef);
         }


         /******************************/
         /*           <Node>           */ // A revoir
         /*         startreview        */
         /******************************/
         if(workflowPath.node.name.equals(NODE_STARTREVIEW_NAME) && workflowPath.node.type.equals(NODE)) {
            MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);
         }


         /******************************/
         /*         <TaskNode>         */ // A revoir
         /*           review           */
         /******************************/
         if(workflowPath.node.name.equals(TASK_NODE_REVIEW_NAME) && workflowPath.node.isTaskNode) {
            //System.out.println("*****************");
            //System.out.println("*  REVIEW NODE  *");
            //System.out.println("*****************");
            MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);
            //System.out.println("** END REVIEW NODE **");
         }


         /******************************/
         /*           <Node>           */
         /*        startapproval       */
         /******************************/
         if(workflowPath.node.name.equals(NODE_STARTAPPROVAL_NAME) && workflowPath.node.type.equals(NODE)) {
            MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);

            // Move document to Review and Approval space
            NodeRef destNodeRef = null;
            NodeRef nodeBaseRef = RepositoryUtils.getParent(docNodeRef, 2);
            destNodeRef = nodeService.getChildByName(nodeBaseRef, ContentModel.ASSOC_CONTAINS, CommunityConstante.SPACE_REVIEW_AND_APPROVAL);
            RepositoryUtils.moveContent(docNodeRef, destNodeRef);

            // Get Group of Approbators
            String path = null;
            String groupName = null;
            List<ChildAssociationRef> childRefs = nodeService.getChildAssocs(nodeRef);
            for (ChildAssociationRef tchildRef : childRefs) {
               final NodeRef childRef = tchildRef.getChildRef();
               path = nodeService.getPath(childRef).toPrefixString(namespaceService);
            }
            path = path.replace(CommunityConstante.SPACECHAR," ");
            String[] Valeurs = path.split("/cm:");
            groupName = CommunityConstante.GROUP_BASE + Valeurs[2].substring(0, 2) + "-" + Valeurs[3].substring(0, 3) + "-" + CommunityConstante.GROUP_APPROBATORS;
            executionContext.getContextInstance().setVariable("group",groupName);

            MyLogger.debugInfo("Set Permissions for " + groupName, 2, 3);
            // Add CONSUMER permission for the group workflow actor
            permissionService.setPermission(docNodeRef, groupName,PermissionService.CONSUMER,true);
            permissionService.deletePermission(docNodeRef, initiator, PermissionService.EDITOR);

            // Change document status
            Document.setPropertyStatus(docNodeRef, CommunityConstante.STATUS_APPROVAL);
         }


         /******************************/
         /*         <TaskNode>         */
         /*          approval          */
         /******************************/
         if(workflowPath.node.name.equals(TASK_NODE_APPROVAL_NAME) && workflowPath.node.isTaskNode) {
            if(currentUser.equals(initiator)) {
               MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);   

               // Notify Group of Approbators
               message = new Message(from, APPROVAL_SUBJECT, COMMON_HEADER, APPROVAL_BODY, COMMON_FOOTER);
               if(pooledActors != null)
               {
                  Iterator iter = pooledActors.iterator();
                  while (iter.hasNext()) {
                     PooledActor pooledActor = (PooledActor) iter.next();
                     Set<String> users = authorityService.getContainedAuthorities(AuthorityType.USER, pooledActor.getActorId(), false);
                     usersGroup = new ArrayList<UserGroup>(8);
                     for (String userAuth : users)
                     {
                        if (personService.personExists(userAuth) == true)
                        {
                           if(searchUser(userAuth) == false) {
                              usersGroup.add(new UserGroup(userAuth));
                           }
                        }
                     }
                     notifyUsers(docNodeRef, usersGroup, message);
                  }
               }   
            }
         }


         /******************************/
         /*         <Task Node>        */
         /*          rejected          */
         /******************************/
         if(workflowPath.node.name.equals(TASK_NODE_REJECTED_NAME) && workflowPath.node.isTaskNode) {
            MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);

            // Move document to Draft space
            NodeRef destNodeRef = null;
            NodeRef nodeBaseRef = RepositoryUtils.getParent(docNodeRef, 2);
            destNodeRef = nodeService.getChildByName(nodeBaseRef, ContentModel.ASSOC_CONTAINS, CommunityConstante.SPACE_DRAFTS);
            RepositoryUtils.moveContent(docNodeRef, destNodeRef);

            // Permissions
            String groupName = (String) executionContext.getContextInstance().getVariable("group");
            permissionService.deletePermission(docNodeRef, groupName,PermissionService.CONSUMER);
            permissionService.setPermission(docNodeRef, initiator, PermissionService.EDITOR, true);

            // Change document status
            Document.setPropertyStatus(docNodeRef, CommunityConstante.STATUS_DRAFT);

            // Notify Initiator
            message = new Message(from, REJECT_SUBJECT, COMMON_HEADER, REJECT_BODY, COMMON_FOOTER);
            notifyUser(docNodeRef, initiator, message);
            //System.out.println("** END REJECTED NODE **");
         }


         // Approved Node



         /******************************/
         /*         <Task Node>        */
         /*          published         */
         /******************************/
         if(workflowPath.node.name.equals(TASK_NODE_PUBLISHED_NAME) && workflowPath.node.isTaskNode) {
            //System.out.println("********************");
            //System.out.println("*  PUBLISHED NODE  *");
            //System.out.println("********************");
            MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);

            // Remove Permissions
            String groupName = (String) executionContext.getContextInstance().getVariable("group");
            permissionService.deletePermission(docNodeRef, groupName,PermissionService.CONSUMER);

            // Add Aspect Quality
            Document.addAspectQualityExt(docNodeRef);

            // Approved the document
            approvedContent(docNodeRef, nodeRef);
            
            // Published Content
            publishedContent(RepositoryUtils.getChild(nodeRef), nodeRef);

            // Send notification for approved message
            message = new Message(from, APPROVED_SUBJECT, COMMON_HEADER, APPROVED_BODY, COMMON_FOOTER);
            notifyUser(RepositoryUtils.getChild(nodeRef), initiator, message);            
            
            //message = new Message(from, PUBLISHED_SUBJECT, COMMON_HEADER, PUBLISHED_BODY, COMMON_FOOTER);
            //notifyUser(docNodeRef, initiator, message);

            // Notify All person in ACL
            if(Document.getPropertyVersion(RepositoryUtils.getChild(nodeRef)).equals("1.0")) {
               //System.out.println("NEW VERSION PUB: " + Document.getPropertyVersion(docNodeRef));
               message = new Message(from, PUBLISHED_SUBJECT_NEW, COMMON_HEADER, PUBLISHED_BODY_NEW, COMMON_FOOTER);
            }
            else {
               //System.out.println("VERSION PUB: " + Document.getPropertyVersion(docNodeRef));
               message = new Message(from, PUBLISHED_SUBJECT_UPDATE, COMMON_HEADER, PUBLISHED_BODY_UPDATE, COMMON_FOOTER);
            }
            //System.out.println("** END PUBLISHED NODE **");
         }


         // Approved and Published Node

         /******************************/
         /*         <EndState>         */
         /*             end            */
         /******************************/
         if(workflowPath.node.name.equals(NODE_END_NAME) && workflowPath.node.type.equals(END_STATE)) {
            MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);

            // Unlock document for the current workflow
            Document.removeAspectWorkflowNodeRef(docNodeRef);

            if(Document.getPropertyVersion(docNodeRef) == "1.0") {
               enabledPermission(docNodeRef);
               restoreOwner(docNodeRef);   
            }
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
      finally {
         // Restore Current User
         AuthenticationUtil.setCurrentUser(currentUser);
      }
      MyLogger.debugInfo("org.alfresco.community.repo.workflow.jbpm.Actions", 1, 1);
   }



   private static void approvedContent(NodeRef contentNodeRef, NodeRef workflowNodeRef)
   {
      MyLogger.debugInfo("org.alfresco.community.repo.workflow.jbpm.Actions.approvedContent", -1, 1);

      // try to cancel checkout of the working copy    
        //FacesContext context = FacesContext.getCurrentInstance();
        //UserTransaction tx = null;
      //try {
         //tx = Repository.getUserTransaction(context, false);
            //tx.begin();
           
         ContentInfo contentInfo = new ContentInfo(contentNodeRef, // nodeRef
               RepositoryUtils.getParent(contentNodeRef, 2), // baseNodeRef
               Document.getPropertyContentOriginalNodeRef(contentNodeRef), // approveNodeRef
               nodeService.getChildByName(RepositoryUtils.getParent(contentNodeRef, 2), ContentModel.ASSOC_CONTAINS, CommunityConstante.SPACE_APPROVED), // destApprovedNodeRef
               null, // publishedNodeRef
               null, // destpublished
               Document.getPropertyWorkingCopyNodeRef(contentNodeRef), // WorkingNodeRef
               Document.getPropertyName(contentNodeRef), // name,                        
               Document.getPropertyQualityReference(contentNodeRef), // reference
               Document.getPropertyApprobatorName(contentNodeRef), // approbator
               Document.getPropertyQualityAgreement(contentNodeRef), // agreement
               Document.getPropertyPdfConvert(contentNodeRef), // pdfoption
               Document.getPropertyRevisor(contentNodeRef), // revisor
               Document.getPropertyVersion(contentNodeRef), // version
               Document.getPropertyAuthor(contentNodeRef), // author
               Document.getPropertySaveOwner(contentNodeRef),  // owner
               Document.getPropertyStatus(contentNodeRef)); // status

         contentInfo.printAll(); // Debug only
         /**
          * Check if a working copy exist
          */
//          Check by contentNodeRed and explore node to detect the working copie
         if(Document.hasAspectWorkingCopyNodeRef(contentInfo.getNodeRef()) == true) {
            MyLogger.debugInfo("The current version is a working copy",2 ,3);

            // Add Major version aspect ==> only on the copy
            Document.addAspectMajorVersion(contentInfo.getNodeRef());

            if(Document.hasAspectQualityExt(contentInfo.getNodeRef())) {
               MyLogger.debugInfo("Make Agreement in the Copy", 2, 3);
               Reference.putAgreement(contentInfo.getNodeRef(), Reference.makeAgreement(contentInfo.getApprovedNodeRef()));
            }

            // Copy Working Copy Content to CheckOut Content
            ContentReader tempReader = contentService.getReader(contentInfo.getNodeRef(), ContentModel.PROP_CONTENT);                       
            ContentWriter tempWriter = contentService.getWriter(contentInfo.getWorkingNodeRef(), ContentModel.PROP_CONTENT, true);
            tempWriter.putContent(tempReader);

            // Get Version
            Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(1);
            if(Document.getPropertyMajorVersion(contentInfo.getNodeRef()) == true) {
               MyLogger.debugInfo("The New Version is a Major Version",2 ,3);
               versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
            }
            else {
               MyLogger.debugInfo("The New Version is a Minor Version",2 ,3);
               versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
            }
            Document.setPropertyApprobatorName(contentInfo.getWorkingNodeRef(), contentInfo.getApprobator());

            // Set Approbator and Updator Name in document
            //String description =  "Updated by " + contentInfo.getRevisor() +
            String description =  "Updated by " + contentInfo.getRevisor() + //Document.getPropertyModifier(contentInfo.getApprovedNodeRef()) +
                                  " & Approved by " + contentInfo.getApprobator();
            versionProperties.put(Version.PROP_DESCRIPTION, description);

            
            //System.out.println("Working copy: " + Document.getPropertyName(contentInfo.getWorkingNodeRef()));
            // Check In
            MyLogger.debugInfo("Check In Approved Document",2 ,3);
            checkOutCheckInService.checkin(contentInfo.getWorkingNodeRef(),versionProperties);

            // Add Version in custom Version properies
            MyLogger.debugInfo("Set Custom Versionning",2 ,3);
            String curentversion = versionService.getCurrentVersion(contentInfo.getApprovedNodeRef()).getVersionLabel();
            Document.setPropertyVersion(contentInfo.getApprovedNodeRef(), curentversion);

            //Document.addAspectModifier(approvedNodeRef);
            Document.setPropertyModifier(contentInfo.getApprovedNodeRef(), contentInfo.getRevisor());

            // Update Status property on the approved document and on the copy
            Document.setPropertyStatus(contentInfo.getApprovedNodeRef(), CommunityConstante.STATUS_APPROVED);
            //Document.setPropertyStatus(contentNodeRef, CommunityConstante.STATUS_APPROVED);

            //Document.getPropertyQualityReference(contentNodeRef);
            Document.getPropertyQualityReference(contentInfo.getApprovedNodeRef());

            // Update Quality agreement on the original node
            MyLogger.debugInfo("Get The Quality Agreement from the Working Copy",2 ,3);
            Document.setPropertyQualityAgreement(contentInfo.getApprovedNodeRef(), Document.getPropertyQualityAgreement(contentInfo.getNodeRef()));
            Document.removeAspectWorkflowNodeRef(contentInfo.getApprovedNodeRef());

            Document.removeAspectWorkingCopyNodeRef(contentInfo.getApprovedNodeRef());

            MyLogger.debugInfo("Delete Working Copy", 2, 3);
            nodeService.removeChild(workflowNodeRef, contentInfo.getNodeRef());
            //System.out.println("Doc name: " + Document.getPropertyName(contentInfo.getNodeRef()));
            //System.out.println("Src doc:  " + RepositoryUtils.getParent(contentInfo.getNodeRef(),1));
            fileFolderService.delete(contentInfo.getNodeRef());
            Document.removeAspectWorkflowNodeRef(contentInfo.getApprovedNodeRef());
            nodeService.addChild(workflowNodeRef, contentInfo.getApprovedNodeRef(),
                  ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
                  QName.createValidLocalName((String)nodeService.getProperty(
                        contentInfo.getApprovedNodeRef(), ContentModel.PROP_NAME))));   
         }
         else {
            MyLogger.debugInfo("The Current Version is an Original",2 ,3);

            if(Document.hasAspectQualityExt(contentInfo.getNodeRef())) {
               MyLogger.debugInfo("Make Agreement for new document", 2, 3);
               Reference.putAgreement(contentInfo.getNodeRef(), Reference.makeAgreement(contentInfo.getNodeRef()));
            }

            // Add Custom Versionning
            Document.addAspectVersion(contentInfo.getNodeRef());

            // Add Version in custom Version properies
            MyLogger.debugInfo("Set Custom Versionning",2 ,3);
            Version version = versionService.getCurrentVersion(contentInfo.getNodeRef());
            if (version == null) {
               Map<String, Serializable> versionDetails = new HashMap<String, Serializable>(1);
               String description =  "Created by " + contentInfo.getAuthor() +
                                          " & Approved by " + contentInfo.getApprobator();
               versionDetails.put(Version.PROP_DESCRIPTION, description);
               versionService.createVersion(contentInfo.getNodeRef(), versionDetails);
            }
            nodeService.setProperty(contentInfo.getNodeRef(), ContentModel.PROP_AUTO_VERSION, true);

            String curentversion = versionService.getCurrentVersion(contentInfo.getNodeRef()).getVersionLabel();
            Document.setPropertyVersion(contentInfo.getNodeRef(), curentversion);

            // Rename document with Indice reference
            Document.addAspectQuality(contentInfo.getNodeRef());
            Document.setPropertyQualityReference(contentInfo.getNodeRef(), Reference.makeQuality(contentInfo.getNodeRef()));
            String docname = Document.getIndice(contentInfo.getNodeRef()) + " - " + contentInfo.getName(); //Document.getPropertyName(contentInfo.getNodeRef());
            try {
               fileFolderService.rename(contentInfo.getNodeRef(), docname);
               nodeService.setProperty(contentInfo.getNodeRef(), ContentModel.PROP_NAME,docname);
            }
            catch (Exception e){
               logger.error(e.getMessage());
            }

            // Move Document ==> only on the first draft
            RepositoryUtils.moveContent(contentInfo.getNodeRef(), contentInfo.getDestApprovedNodeRef()); //destNodeRef);

            // Update Status property
            Document.setPropertyStatus(contentInfo.getNodeRef(), CommunityConstante.STATUS_APPROVED);
            Document.removeAspectWorkflowNodeRef(contentInfo.getNodeRef());
            
            // commit the transaction
            //tx.commit();
         }   
      //} catch (Exception e) {
         // TODO: handle exception
      //   e.printStackTrace();
         //try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
      //}
      MyLogger.debugInfo("org.alfresco.community.repo.workflow.jbpm.Actions.approvedContent", 1, 1);
   }


   private static void publishedContent(NodeRef contentNodeRef, NodeRef workflowNodeRef) throws COSVisitorException, IOException // throws COSVisitorException, IOException
   {
      MyLogger.debugInfo("org.alfresco.community.repo.workflow.jbpm.Actions.publishedContent", -1, 1);
      // Variables
      //NodeRef nodeBase;
      //boolean pdfconvert = false;   
      //Map<String, Serializable> versionDetails = new HashMap<String, Serializable>(1);
      
      // try to cancel checkout of the working copy    
        //FacesContext context = FacesContext.getCurrentInstance();
        //UserTransaction tx = null;
      //try {
         //tx = Repository.getUserTransaction(context, false);
            //tx.begin();
           
         ContentInfo contentInfo = new ContentInfo(contentNodeRef, // nodeRef
               RepositoryUtils.getParent(contentNodeRef, 2), // baseNodeRef
               null, // approveNodeRef
               null, // destApprovedNodeRef
               Document.getPropertyContentPublishedNodeRef(contentNodeRef), // publishedNodeRef
               nodeService.getChildByName(RepositoryUtils.getParent(contentNodeRef, 2),ContentModel.ASSOC_CONTAINS, CommunityConstante.SPACE_PUBLISHED), // destpublished
               null, // WorkingNodeRef
               Document.getPropertyName(contentNodeRef), // name,                        
               Document.getPropertyQualityReference(contentNodeRef), // reference
               Document.getPropertyApprobatorName(contentNodeRef), // approbator
               Document.getPropertyQualityAgreement(contentNodeRef), // agreement
               Document.getPropertyPdfConvert(contentNodeRef), // pdfoption
               Document.getPropertyRevisor(contentNodeRef), // revisor
               Document.getPropertyVersion(contentNodeRef), // version
               Document.getPropertyAuthor(contentNodeRef), // author
               Document.getPropertySaveOwner(contentNodeRef),  // owner
               Document.getPropertyStatus(contentNodeRef)); // status

         contentInfo.printAll(); // Debug only

         //String description = null;
         if(contentInfo.getPublishedNodeRef() == null)
         {
            MyLogger.debugInfo("Publish the new document", 2, 3);

            // Check if document need to be converted in PDF
            //if(Document.hasAspectPdfConvert(contentInfo.getNodeRef()) == true) {
            //   pdfconvert = Document.getPropertyPdfConvert(contentInfo.getNodeRef());
            //}

            String mymetype;
            //if(pdfconvert == true) {
            if(contentInfo.getPDFOption() == true) {
               mymetype = MimetypeMap.MIMETYPE_PDF;
               MyLogger.debugInfo("set MimeType of Copy to " + mymetype, 2, 3);
            }
            else {
               mymetype = contentService.getWriter(contentInfo.getNodeRef(), ContentModel.PROP_CONTENT, true).getMimetype().toString();
               MyLogger.debugInfo("set MimeType of Copy to " + mymetype, 2, 3);
            }

            contentInfo.setPublishedNodeRef(makeCopy(contentInfo.getNodeRef(), contentInfo.getDestPublishedNodeRef(), mymetype));

            // Set Default permission for Approbator group
            permissionService.setPermission(contentInfo.getPublishedNodeRef(), Document.getApprobatorGroup(contentInfo.getPublishedNodeRef()), PermissionService.CONSUMER,true);

            // Add versionnable on the new document
            //Document.addAspectVersionable(contentInfo.getPublishedNodeRef());

            // Backup Published noderef in approved document
            Document.setPropertyContentPublishedNodeRef(contentInfo.getNodeRef(), contentInfo.getPublishedNodeRef());
            Document.setPropertySaveOwner(contentInfo.getPublishedNodeRef(), contentInfo.getOwner());
            
            //description = "Created by " + contentInfo.getAuthor() +
               //              " & Approved by " + contentInfo.getApprobator();
         }
         else
         {
            MyLogger.debugInfo("The document is already published", 2, 3);

//            Check out of published document if versionning is enabled –> (option non testée)
//            NodeRef originalPublishedNodeRef = null;
//            if(GetConfig.publishedVersionning()) {
//            if(Document.hasAspectVersionable(contentInfo.getPublishedNodeRef())) {
//            MyLogger.debugInfo("Check Out Published Document", 2, 3);
//            originalPublishedNodeRef = contentInfo.getPublishedNodeRef();
//            contentInfo.setPublishedNodeRef(checkOutCheckInService.checkout(contentInfo.getPublishedNodeRef(),contentInfo.getDestPublishedNodeRef(),ContentModel.ASSOC_CONTAINS,QName.createQName("{copy}workingCopy")));                     
//            }
//            }   
            //description = "Updated by " + contentInfo.getRevisor() +
               //              " & Approved by " + contentInfo.getApprobator();
//             Add Modifier in published document. Requiered for PDF
            Document.addAspectModifier(contentInfo.getPublishedNodeRef());
            Document.setPropertyModifier(contentInfo.getPublishedNodeRef(), contentInfo.getRevisor());
         }
         Document.removeAspectMajorVersion(contentInfo.getNodeRef());
         
         // Remove versionning
         if(Document.hasAspectVersionable(contentInfo.getPublishedNodeRef()))
         {
            MyLogger.debugInfo("Remove versionnable aspect", 2, 3);
             versionService.deleteVersionHistory(contentInfo.getPublishedNodeRef());
            Document.removeAspectVersionable(contentInfo.getPublishedNodeRef());
         }

//         Convertir en PDF si demandé
         //if(pdfconvert != true) {
         if(contentInfo.getPDFOption() != true) {   
//            Copy current approved Content to Published Content
            MyLogger.debugInfo("Published Document in Original Format", 2, 3);
            ContentReader tempReader = contentService.getReader(contentInfo.getNodeRef(), ContentModel.PROP_CONTENT);                       
            ContentWriter tempWriter = contentService.getWriter(contentInfo.getPublishedNodeRef(), ContentModel.PROP_CONTENT, true);
            tempWriter.putContent(tempReader);
         }
         else {
            MyLogger.debugInfo("Published Document in PDF", 2, 3);
            PDFTools.makePDF(contentInfo.getNodeRef(), contentInfo.getPublishedNodeRef());
         }


//         Ajouter la référence si le conversion PDF demandé et si document déjà en PDF
         if((contentInfo.getPDFOption() == true ||
               contentService.getWriter(contentInfo.getNodeRef(), ContentModel.PROP_CONTENT, true).getMimetype().toString().equals(MimetypeMap.MIMETYPE_PDF)
         ) && contentInfo.getAgreement() != null)
         {
            // System.out.println("(PDF Convert = True or MimeType = PDF) and Agreement != null");
//            Insert Reference in PDF File Content
            MyLogger.debugInfo("Add Full Quatity Reference in Published Document", 2, 3);
            Document.setPropertyQualityAgreement(contentInfo.getPublishedNodeRef(), Document.getPropertyQualityAgreement(contentInfo.getNodeRef()));
            PDFTools.addReference(contentInfo.getPublishedNodeRef(), Document.getFullReference(contentInfo.getNodeRef()), contentInfo.getApprobator());
         }


//         Update properties
         Document.setPropertyQualityReference(contentInfo.getPublishedNodeRef(), contentInfo.getReference());
         Document.setPropertyApprobatorName(contentInfo.getPublishedNodeRef(), contentInfo.getApprobator());
         Document.setPropertyStatus(contentInfo.getPublishedNodeRef(), CommunityConstante.STATUS_PUBLISHED);
         Document.setPropertyVersion(contentInfo.getPublishedNodeRef(), contentInfo.getVersion());

         Document.removeAspectRevisor(contentInfo.getNodeRef());

//         Add Current Version number
//         NodeRef approvedNodeRef = Document.getPropertyContentOriginalNodeRef(contentInfo.getPublishedNodeRef());
//         String curentversion = versionService.getCurrentVersion(approvedNodeRef).getVersionLabel();

//         Update version in published document
         //MyLogger.debugInfo("Published Versionning is enabled", 2, 3);
         //versionDetails.put(Version.PROP_DESCRIPTION, description);
         //versionService.createVersion(contentInfo.getPublishedNodeRef(), versionDetails);
         //nodeService.setProperty(contentInfo.getPublishedNodeRef(), ContentModel.PROP_VERSION_LABEL, contentInfo.getVersion());

//         Change the curent document by the new published in the workflow
         if(contentInfo.getPublishedNodeRef() != null) {
            nodeService.removeChild(workflowNodeRef, contentInfo.getNodeRef());
            nodeService.addChild(workflowNodeRef, contentInfo.getPublishedNodeRef(),
                  ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
                        QName.createValidLocalName((String)nodeService.getProperty(
                              contentInfo.getPublishedNodeRef(), ContentModel.PROP_NAME))));   
         }
         
         //commit the transaction
         //tx.commit();         
//      } catch (Exception e) {
         // TODO: handle exception
   //      e.printStackTrace();
         //try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
      //}
      MyLogger.debugInfo("org.alfresco.community.repo.workflow.jbpm.Actions.publishedContent", 1, 1);   

}

   // Make a copy of document passed in argument on Publish Space
    protected static NodeRef makeCopy(NodeRef nodeRef, NodeRef destNodeRef, String mymetype) {
       //System.out.println("MAKE COPY OF ORIGINAL DOCUMENT IN PUBLISH SPACE");
       // Get the overwrite value
        boolean overwrite = true;
        NodeRef copyNodeRef = null;
       
      String originalName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
      String newName = PDFTools.transformName(originalName, mymetype, true);
      
      // Since we are overwriting we need to figure out whether the destination node exists
      if (overwrite == true) {
         // Try and find copies of the actioned upon node reference
         List<NodeRef> copies = copyService.getCopies(nodeRef);
         if (copies != null && copies.isEmpty() == false) {
            for (NodeRef copy : copies) {
               // Ignore if the copie is a working copy
               if (nodeService.hasAspect(copy, ContentModel.ASPECT_WORKING_COPY) == false) {
                  // We can assume that we are looking for a node created by this action so the primary parent will
                  // match the destination folder ans the name will be the same
                  NodeRef parent = nodeService.getPrimaryParent(copy).getParentRef();
                  String copyName = (String)nodeService.getProperty(copy, ContentModel.PROP_NAME);
                  if(parent.equals(destNodeRef) == true && copyName.equals(newName) == true) {
                     if (copyNodeRef == null) {
                        copyNodeRef = copy;
                     } else {
                        throw new RuleServiceException(CommunityConstante.ERR_OVERWRITE);
                     }
                  }
               }
            }
         }
      }
      
      boolean newCopy = false;
      if (copyNodeRef == null) {
         String docName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);   
         String qname = QName.createValidLocalName(docName);
         copyNodeRef = copyService.copy(nodeRef, destNodeRef,ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname), false);
         newCopy = true;
      }
      
      if (newCopy == true) {
         nodeService.setProperty(copyNodeRef, ContentModel.PROP_NAME, newName);
         String originalTitle = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
         if(originalTitle != null && originalTitle.length() > 0) {
            String newTitle = PDFTools.transformName(originalTitle,mymetype,false);
            nodeService.setProperty(copyNodeRef, ContentModel.PROP_TITLE, newTitle);
            MyLogger.debugInfo("Set Author in Published Doc", 2, 3);
            Document.setPropertyAuthor(copyNodeRef, Document.getPropertyAuthor(nodeRef));
            MyLogger.debugInfo("Set Original Reference Node in Published Doc", 2, 3);
            Document.addAspectContentOriginalNodeRef(copyNodeRef);
            Document.setPropertyContentOriginalNodeRef(copyNodeRef, nodeRef);
            Document.setPropertySaveOwner(copyNodeRef, Document.getPropertySaveOwner(nodeRef));
            //ownableService.takeOwnership(copyNodeRef);
            if(Document.hasAspectQuality(nodeRef)) {
               Document.addAspectQuality(copyNodeRef);
            }
            Document.addAspectVersion(copyNodeRef);
         }
      }
       return copyNodeRef;
    }

Après de multiple tests, il semblerait que le problème provienne de la copie de mon document apprové

String docName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);   
         String qname = QName.createValidLocalName(docName);
         copyNodeRef = copyService.copy(nodeRef, destNodeRef,ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname), false);

Je ne comprends pas pourquoi il refuse de copier mon document lorsque la validation est réalisée par un utilisateur quelconque, alors que toutes les opérations sont réalisées en tant que System. Par contre si c'est l'utilisateur admin qui gère la tâche du workflow, il n'y a pas de problème.
4 Replies
jayjayecl
Active Member II

Re: [Resolu] Transaction didn't commit

Bonjour,
Pourriez-vous supprimer la partie


currentUser=AuthenticationUtil.getCurrentUserName();
AuthenticationUtil.setSystemUserAsCurrentUser();

Ainsi que le "rétablissement" du currentUser dans le block finally.

A la place, tenter l'approche "Job" suivante :


AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() {
   public Object doWork() throws Exception {
      /*
       *  YOUR CODE HERE
       */
       return null;
   }
}, "admin");

Je pense que cela aura plus de chances de fonctionner.

Bonne chance
huberd
Member II

Re: [Resolu] Transaction didn't commit

Bonjour,
Pourriez-vous supprimer la partie


currentUser=AuthenticationUtil.getCurrentUserName();
AuthenticationUtil.setSystemUserAsCurrentUser();

Ainsi que le "rétablissement" du currentUser dans le block finally.

A la place, tenter l'approche "Job" suivante :


AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() {
   public Object doWork() throws Exception {
      /*
       *  YOUR CODE HERE
       */
       return null;
   }
}, "admin");

Je pense que cela aura plus de chances de fonctionner.

Bonne chance

Merci pour l'info, mais cela ne marche pas non plus


         currentUser=AuthenticationUtil.getCurrentUserName();
         //AuthenticationUtil.setSystemUserAsCurrentUser();
               
         AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() {
            public Object doWork() throws Exception {
               /*
                *  YOUR CODE HERE
                */
               NodeRef docNodeRef = null;
               docNodeRef = RepositoryUtils.getChild(nodeRef);

               FacesContext context = FacesContext.getCurrentInstance();
               String from = Application.getClientConfig(context).getFromEmailAddress();
               Message message = null;

               // Register the bundle
               I18NUtil.registerResourceBundle(BASE_RESOURCE_NAME);

               // Prepare mail
               mailHelper = new TemplateMailHelperBean();
               mailHelper.setMailSender(mailSender);
               mailHelper.setNodeService(nodeService);

               workflowInstanceId = (String)nodeService.getProperty(nodeRef, WorkflowModel.PROP_WORKFLOW_INSTANCE_ID);
               workflowInstance = workflowService.getWorkflowById(workflowInstanceId);

               initiator = getInitiator();
               //System.out.println("INITIATOR ======> " + initiator);
               //System.out.println("CURRENT USER ===> " + currentUser);

               WorkflowPath workflowPath = null;
               List<WorkflowPath> cmrPaths = workflowService.getWorkflowPaths(workflowInstance.id);
               for (WorkflowPath cmrPath : cmrPaths)
               {
                  //System.out.println("WPATH:       " + cmrPath);
                  //System.out.println("NODE NAME:   " + cmrPath.node.name);
                  //System.out.println("IS TASKNODE: " + cmrPath.node.isTaskNode);
                  //System.out.println("TYPE:        " + cmrPath.node.type);
                  //System.out.println("TITLE:       " + cmrPath.node.title);
                  //System.out.println("TRANSITION:  " + cmrPath.node.transitions);
                  workflowPath = cmrPath;
               }
               if(workflowPath.node.isTaskNode) {
                  taskInstance = executionContext.getTaskInstance();
                  if(taskInstance != null) {
                     //System.out.println("==> Task ID: " + taskInstance.getId());
                     if(taskInstance.getActorId() != null) {
                        actor = taskInstance.getActorId();   
                        //System.out.println("==> This is an actor: " + actor);
                     }
                     else
                        if(taskInstance.getPooledActors() != null) {
                           pooledActors = taskInstance.getPooledActors();
                           //System.out.println("==> This is a pooledActors: " + pooledActors);
                        }
                  }
               }

//               System.out.println("TRANSITION : " + workflowPath.node.transitions);
//               WorkflowTransition[] wfTransitions = workflowPath.node.transitions;    
//               String wfTransitionId = null;
//               WorkflowTransition wfTransition = wfTransitions[0];
//               wfTransitionId = wfTransition.id;
//               System.out.println("TRANSITION (Id / Title): " + wfTransitionId + " / " + wfTransitions[0].title);

//               if (transitionName == null || transitionName.trim().length()==0)
//               {        
//               WorkflowTransition wfTransition = wfTransitions[0];        
//               wfTransitionId = wfTransition.id;    
//               }
//               else
//               {        
//               int i = 0;  
//               for (i = 0; i<wfTransitions.length; i++) { 
//               if (wfTransitions[i].title.equals(transitionName)) break;      
//               }       
//               if (i > wfTransitions.length) throw new Exception("Failed to find transition with nanme '"+transitionName+"'");  
//               WorkflowTransition wfTransition = wfTransitions[i];   
//               wfTransitionId = wfTransition.id;    
//               }     
//               wfPath = workflowService.signal(wfPathId, wfTransitionId); 
//               return wfPath;


               /******************************/
               /*        <StartState>        */
               /*            start           */
               /******************************/
               if(workflowPath.node.name.equals(NODE_START_NAME) && workflowPath.node.type.equals(START_STATE)) {
                  MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);

                  // Lock document for the current workflow
                  Document.addAspectWorkflowNodeRef(docNodeRef);

                  // Backup Owner et remove it
                  if(!Document.hasAspectSaveOwner(docNodeRef)) {
                     disabledPermissions(docNodeRef);
                     removeOwner(docNodeRef);
                  }

                  // Add Aspect Contant Base Ref
                  NodeRef baseSpaceNodeRef = RepositoryUtils.getParent(docNodeRef, 2);
                  Document.addAspectContentsNodeRef(docNodeRef);
                  Document.setPropertyContentBaseNodeRef(docNodeRef, baseSpaceNodeRef);
               }


               /******************************/
               /*           <Node>           */ // A revoir
               /*         startreview        */
               /******************************/
               if(workflowPath.node.name.equals(NODE_STARTREVIEW_NAME) && workflowPath.node.type.equals(NODE)) {
                  MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);
               }


               /******************************/
               /*         <TaskNode>         */ // A revoir
               /*           review           */
               /******************************/
               if(workflowPath.node.name.equals(TASK_NODE_REVIEW_NAME) && workflowPath.node.isTaskNode) {
                  //System.out.println("*****************");
                  //System.out.println("*  REVIEW NODE  *");
                  //System.out.println("*****************");
                  MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);
                  //System.out.println("** END REVIEW NODE **");
               }


               /******************************/
               /*           <Node>           */
               /*        startapproval       */
               /******************************/
               if(workflowPath.node.name.equals(NODE_STARTAPPROVAL_NAME) && workflowPath.node.type.equals(NODE)) {
                  MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);

                  // Move document to Review and Approval space
                  NodeRef destNodeRef = null;
                  NodeRef nodeBaseRef = RepositoryUtils.getParent(docNodeRef, 2);
                  destNodeRef = nodeService.getChildByName(nodeBaseRef, ContentModel.ASSOC_CONTAINS, CommunityConstante.SPACE_REVIEW_AND_APPROVAL);
                  RepositoryUtils.moveContent(docNodeRef, destNodeRef);

                  // Get Group of Approbators
                  String path = null;
                  String groupName = null;
                  List<ChildAssociationRef> childRefs = nodeService.getChildAssocs(nodeRef);
                  for (ChildAssociationRef tchildRef : childRefs) {
                     final NodeRef childRef = tchildRef.getChildRef();
                     path = nodeService.getPath(childRef).toPrefixString(namespaceService);
                  }
                  path = path.replace(CommunityConstante.SPACECHAR," ");
                  String[] Valeurs = path.split("/cm:");
                  groupName = CommunityConstante.GROUP_BASE + Valeurs[2].substring(0, 2) + "-" + Valeurs[3].substring(0, 3) + "-" + CommunityConstante.GROUP_APPROBATORS;
                  executionContext.getContextInstance().setVariable("group",groupName);

                  MyLogger.debugInfo("Set Permissions for " + groupName, 2, 3);
                  // Add CONSUMER permission for the group workflow actor
                  permissionService.setPermission(docNodeRef, groupName,PermissionService.CONSUMER,true);
                  permissionService.deletePermission(docNodeRef, initiator, PermissionService.EDITOR);

                  // Change document status
                  Document.setPropertyStatus(docNodeRef, CommunityConstante.STATUS_APPROVAL);
               }


               /******************************/
               /*         <TaskNode>         */
               /*          approval          */
               /******************************/
               if(workflowPath.node.name.equals(TASK_NODE_APPROVAL_NAME) && workflowPath.node.isTaskNode) {
                  if(currentUser.equals(initiator)) {
                     MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);   

                     // Notify Group of Approbators
                     message = new Message(from, APPROVAL_SUBJECT, COMMON_HEADER, APPROVAL_BODY, COMMON_FOOTER);
                     if(pooledActors != null)
                     {
                        Iterator iter = pooledActors.iterator();
                        while (iter.hasNext()) {
                           PooledActor pooledActor = (PooledActor) iter.next();
                           Set<String> users = authorityService.getContainedAuthorities(AuthorityType.USER, pooledActor.getActorId(), false);
                           usersGroup = new ArrayList<UserGroup>(8);
                           for (String userAuth : users)
                           {
                              if (personService.personExists(userAuth) == true)
                              {
                                 if(searchUser(userAuth) == false) {
                                    usersGroup.add(new UserGroup(userAuth));
                                 }
                              }
                           }
                           notifyUsers(docNodeRef, usersGroup, message);
                        }
                     }   
                  }
               }


               /******************************/
               /*         <Task Node>        */
               /*          rejected          */
               /******************************/
               if(workflowPath.node.name.equals(TASK_NODE_REJECTED_NAME) && workflowPath.node.isTaskNode) {
                  MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);

                  // Move document to Draft space
                  NodeRef destNodeRef = null;
                  NodeRef nodeBaseRef = RepositoryUtils.getParent(docNodeRef, 2);
                  destNodeRef = nodeService.getChildByName(nodeBaseRef, ContentModel.ASSOC_CONTAINS, CommunityConstante.SPACE_DRAFTS);
                  RepositoryUtils.moveContent(docNodeRef, destNodeRef);

                  // Permissions
                  String groupName = (String) executionContext.getContextInstance().getVariable("group");
                  permissionService.deletePermission(docNodeRef, groupName,PermissionService.CONSUMER);
                  permissionService.setPermission(docNodeRef, initiator, PermissionService.EDITOR, true);

                  // Change document status
                  Document.setPropertyStatus(docNodeRef, CommunityConstante.STATUS_DRAFT);

                  // Notify Initiator
                  message = new Message(from, REJECT_SUBJECT, COMMON_HEADER, REJECT_BODY, COMMON_FOOTER);
                  notifyUser(docNodeRef, initiator, message);
                  //System.out.println("** END REJECTED NODE **");
               }


               // Approved Node



               /******************************/
               /*         <Task Node>        */
               /*          published         */
               /******************************/
               if(workflowPath.node.name.equals(TASK_NODE_PUBLISHED_NAME) && workflowPath.node.isTaskNode) {
                  //System.out.println("********************");
                  //System.out.println("*  PUBLISHED NODE  *");
                  //System.out.println("********************");
                  MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);

                  // Remove Permissions
                  String groupName = (String) executionContext.getContextInstance().getVariable("group");
                  permissionService.deletePermission(docNodeRef, groupName,PermissionService.CONSUMER);

                  // Add Aspect Quality
                  Document.addAspectQualityExt(docNodeRef);

                  // Approved the document
                  approvedContent(docNodeRef, nodeRef);
                  
                  // Published Content
                  publishedContent(RepositoryUtils.getChild(nodeRef), nodeRef);

                  // Send notification for approved message
                  message = new Message(from, APPROVED_SUBJECT, COMMON_HEADER, APPROVED_BODY, COMMON_FOOTER);
                  notifyUser(RepositoryUtils.getChild(nodeRef), initiator, message);            
                  
                  //message = new Message(from, PUBLISHED_SUBJECT, COMMON_HEADER, PUBLISHED_BODY, COMMON_FOOTER);
                  //notifyUser(docNodeRef, initiator, message);

                  // Notify All person in ACL
                  if(Document.getPropertyVersion(RepositoryUtils.getChild(nodeRef)).equals("1.0")) {
                     //System.out.println("NEW VERSION PUB: " + Document.getPropertyVersion(docNodeRef));
                     message = new Message(from, PUBLISHED_SUBJECT_NEW, COMMON_HEADER, PUBLISHED_BODY_NEW, COMMON_FOOTER);
                  }
                  else {
                     //System.out.println("VERSION PUB: " + Document.getPropertyVersion(docNodeRef));
                     message = new Message(from, PUBLISHED_SUBJECT_UPDATE, COMMON_HEADER, PUBLISHED_BODY_UPDATE, COMMON_FOOTER);
                  }
                  //System.out.println("** END PUBLISHED NODE **");
               }


               // Approved and Published Node

               /******************************/
               /*         <EndState>         */
               /*             end            */
               /******************************/
               if(workflowPath.node.name.equals(NODE_END_NAME) && workflowPath.node.type.equals(END_STATE)) {
                  MyLogger.writeInfo(workflowPath.node.type, workflowPath.node.name,  false);

                  // Unlock document for the current workflow
                  Document.removeAspectWorkflowNodeRef(docNodeRef);

                  if(Document.getPropertyVersion(docNodeRef) == "1.0") {
                     enabledPermission(docNodeRef);
                     restoreOwner(docNodeRef);   
                  }
               }
               return null;
            }
         }, "admin");

L'erreur est la suivante

11:13:27,655 ERROR [ui.common.Utils] Une erreur système s'est produite pendant l'opération : Transaction didn't commit: Failed to execute transaction-level behaviour public abstract void org.alfresco.repo.node.NodeServicePolicies$OnAddAspectPolicy.onAddAspect(org.alfresco.service.cmr.repository.NodeRef,org.alfresco.service.namespace.QName) in transaction a175fc60-8d69-11de-8d12-71d0f1cb1192
javax.transaction.RollbackException: Transaction didn't commit: Failed to execute transaction-level behaviour public abstract void org.alfresco.repo.node.NodeServicePolicies$OnAddAspectPolicy.onAddAspect(org.alfresco.service.cmr.repository.NodeRef,org.alfresco.service.namespace.QName) in transaction a175fc60-8d69-11de-8d12-71d0f1cb1192
   at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:430)
   at org.alfresco.web.bean.workflow.ManageTaskDialog.transition(ManageTaskDialog.java:393)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
   at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
   at javax.faces.component.UICommand.broadcast(UICommand.java:109)
   at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
   at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
   at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
   at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.alfresco.web.app.servlet.NTLMAuthenticationFilter.doFilter(NTLMAuthenticationFilter.java:329)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
   at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:834)
   at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
   at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1286)
   at java.lang.Thread.run(Unknown Source)
Caused by: org.alfresco.error.AlfrescoRuntimeException: Failed to execute transaction-level behaviour public abstract void org.alfresco.repo.node.NodeServicePolicies$OnAddAspectPolicy.onAddAspect(org.alfresco.service.cmr.repository.NodeRef,org.alfresco.service.namespace.QName) in transaction a175fc60-8d69-11de-8d12-71d0f1cb1192
   at org.alfresco.repo.policy.TransactionBehaviourQueue.execute(TransactionBehaviourQueue.java:201)
   at org.alfresco.repo.policy.TransactionBehaviourQueue.beforeCommit(TransactionBehaviourQueue.java:133)
   at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.beforeCommit(AlfrescoTransactionSupport.java:626)
   at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:48)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:821)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:637)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:624)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:307)
   at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:420)
   … 29 more
Caused by: org.alfresco.repo.security.permissions.AccessDeniedException: Accès interdit.  Vous n'avez pas la permission de réaliser cette opération.
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:53)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
   at $Proxy2.addAspect(Unknown Source)
   at org.alfresco.repo.version.VersionServiceImpl.createVersion(VersionServiceImpl.java:302)
   at org.alfresco.repo.version.VersionServiceImpl.createVersion(VersionServiceImpl.java:183)
   at org.alfresco.repo.version.VersionableAspect.onAddAspect(VersionableAspect.java:208)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.alfresco.repo.policy.JavaBehaviour$JavaMethodInvocationHandler.invoke(JavaBehaviour.java:179)
   at $Proxy32.onAddAspect(Unknown Source)
   at sun.reflect.GeneratedMethodAccessor351.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.alfresco.repo.policy.TransactionBehaviourQueue.execute(TransactionBehaviourQueue.java:189)
   … 37 more
Caused by: net.sf.acegisecurity.AccessDeniedException: Access is denied.
   at net.sf.acegisecurity.vote.AffirmativeBased.decide(AffirmativeBased.java:86)
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:394)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   … 59 more
jayjayecl
Active Member II

Re: [Resolu] Transaction didn't commit

Quel type d'authentification avez-vous ?
Peut-etre que le compte "admin" ne fonctionne pas car vous etes sous auth LDAP ou autre.
En ce cas, tentez de remplacer "admin" par "System"
huberd
Member II

Re: [Resolu] Transaction didn't commit

Quel type d'authentification avez-vous ?
Peut-etre que le compte "admin" ne fonctionne pas car vous etes sous auth LDAP ou autre.
En ce cas, tentez de remplacer "admin" par "System"

idem, même problème.
Authentification Active Directory.