Récupération de path [Résolu]

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

Récupération de path [Résolu]

Bonjour,

Lorsque je récupère un path avec la fonction suivante :

DocPath = nodeService.getPath(childRef).toString();
j'obtiens le path sous le format suivant :

/{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/content/1....
Quel fonction utiliser pour avoir le résultat suivant :

/app:company_home/cm:LPR/cm:EU_x0020_-_x0020_Group/cm:DSI_x0020_-_x0020_Maintenir_x0020_le_x0020_système_x0020_d_x0027_Information/cm:IOP_x0020_-_x0020_Instruction_x0020_Opératoire/cm:Drafts/cm:_x0030_010_x0020_-_x0020_Manuel_x0020_de_x0020_l_x0027_utilisateur_x0020_-_x0020_Utilisation_x0020_d_x0027_Alfresco.doc
Merci d'avance pour votre aide.
8 Replies
rivarola
Active Member

Re: Récupération de path [Résolu]

l faut appeler
nodeService.getPath(childRef).toPrefixString(namespaceService)
huberd
Member II

Re: Récupération de path [Résolu]

l faut appeler
nodeService.getPath(childRef).toPrefixString(namespaceService)
euh, encore une nouveauté. C'est quoi le namespaceService ? Comment le récupère t'on ?
rivarola
Active Member

Re: Récupération de path [Résolu]

Le NamespaceService sait faire le lien entre les préfixes et les URI définies dans les modèles. Par exemple il sait que le préfixe "cm" correspond à l'URI "http://www.alfresco.org/model/content/1.0".
Pour le récupérer, ça dépend de l'endroit où tu es, mais si tu sais récupérer le NodeService, tu fais la même chose pour le NamespaceService…
huberd
Member II

Re: Récupération de path [Résolu]

Le NamespaceService sait faire le lien entre les préfixes et les URI définies dans les modèles. Par exemple il sait que le préfixe "cm" correspond à l'URI "http://www.alfresco.org/model/content/1.0".
Pour le récupérer, ça dépend de l'endroit où tu es, mais si tu sais récupérer le NodeService, tu fais la même chose pour le NamespaceService…
Ok c'est bon ça marche.

J'ai récuperé mon namespaceService de la sorte :

NamespaceService namespaceService = (NamespaceService) this.factory.getBean("namespaceService");
Maintenant que j'ai mon namespaceService, j'arrive à récuperer le path correctement.

/app:company_home/cm:LPR/cm:EU_x0020_-_x0020_Group/cm:DSI_x0020_-_x0020_Maintenir_x0020_le_x0020_système_x0020_d_x0027_Information/cm:IOP_x0020_-_x0020_Instruction_x0020_Opératoire/cm:Drafts/cm:cm_x003a_cm_x003a_cm_x003a_cm_x003a_0010_x0020_-_x0020_Manuel_x0020_de_x0020_l_x0027_utilisateur_x0020_-_x0020_Utilisation_x0020_d_x0027_Alfresco.doc
Merci pour ton aide précieuse.
huberd
Member II

Re: Récupération de path [Résolu]

Maintenant que j'ai le chemin complet de mon document

/app:company_home/cm:LPR/cm:EU_x0020_-_x0020_Group/cm:DSI_x0020_-_x0020_Maintenir_x0020_le_x0020_système_x0020_d_x0027_Information/cm:IOP_x0020_-_x0020_Instruction_x0020_Opératoire/cm:Drafts/cm:cm_x003a_cm_x003a_cm_x003a_cm_x003a_0010_x0020_-_x0020_Manuel_x0020_de_x0020_l_x0027_utilisateur_x0020_-_x0020_Utilisation_x0020_d_x0027_Alfresco.doc
Comment faire maintenant pour obtenir uniquement le chemin complet sans le nom du document.

/app:company_home/cm:LPR/cm:EU_x0020_-_x0020_Group/cm:DSI_x0020_-_x0020_Maintenir_x0020_le_x0020_système_x0020_d_x0027_Information/cm:IOP_x0020_-_x0020_Instruction_x0020_Opératoire/cm:Drafts
Le code source utilisé est le suivant :

public class ReviewDocuments extends JBPMSpringActionHandler { 

   private static final long serialVersionUID = 1L;

   private static final Logger logger = Logger.getLogger(ReviewDocuments.class);
   
   private BeanFactory factory;
  
   // Property names
   public static final QName PROP_DOCUMENT_NAME = QName.createQName("cm","name");
   public static final QName PROP_DOCUMENT_STATUS = QName.createQName("lpr.model","DocumentStatus");
   public static final String WORKFLOW_USER = "workflow";
   public static final String WORKFLOW_PASSWORD = "password";
  
   // Patameters
   private String status;
     
   @Override
   protected void initialiseHandler(BeanFactory factory) {
      this.factory = factory;  
   }

   public void execute(ExecutionContext executionContext) throws Exception {
     if (status == null) {
         throw new WorkflowException("status has not been provided");
      }
     System.out.println("STATUS en entrée:—–> " + status);
      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;
         }
        
         NodeService nodeService = (NodeService) this.factory.getBean("nodeService");
         NamespaceService namespaceService = (NamespaceService) this.factory.getBean("namespaceService");
        
         String DocPath = null;
         String Path = null;
         List<ChildAssociationRef> childRefs = nodeService.getChildAssocs(nodeRef);
         for (ChildAssociationRef tchildRef : childRefs) {
            final NodeRef childRef = tchildRef.getChildRef();
            Path = nodeService.getPath(childRef).toDisplayPath(nodeService);
             //System.out.println("REPO - Path:     " + Path);
            DocPath = nodeService.getPath(childRef).toString();
            //System.out.println("REPO - Doc path: " + DocPath);
            String PathTest = nodeService.getPath(childRef).toPrefixString(namespaceService);
            System.out.println("REPO - Test path: " + PathTest);
         }

         // Suite du code ….
         …
}
Merci d'avance pour votre aide.

Ce code est executé par le Workflow.
rivarola
Active Member

Re: Récupération de path [Résolu]

Dis-moi si je me trompe mais le chemin complet sans le nom du document, c'est le chemin du primary parent du document, donc dans ton cas nodeRef.
huberd
Member II

Re: Récupération de path [Résolu]

Dis-moi si je me trompe mais le chemin complet sans le nom du document, c'est le chemin du primary parent du document, donc dans ton cas nodeRef.
En faite, j'ai déjà fait le test comme suit :

         String PATH = nodeService.getPath(nodeRef).toPrefixString(namespaceService);
         System.out.println("REPO - PATH du nodeRef: " + PATH);
et en faite j'obtiens le path du noeud de référence, c'est à dire le noeud du Workflow.

REPO - PATH du nodeRef: /sys:system/sys:workflow/cm:packages/cm:pkg_f560d8fa-820e-11dc-aff3-7d021ebb7fcd
huberd
Member II

Re: Récupération de path [Résolu]

j'ai réussis à gruger en récupérant non pas le parent de NodeRef, mais en récupérant le parent de AdminNodeRef (cf code ci-dessous)

public class ReviewDocuments extends JBPMSpringActionHandler { 

   private static final long serialVersionUID = 2L;

   private static final Logger logger = Logger.getLogger(ReviewDocuments.class);
   
   private BeanFactory factory;
   private ServiceRegistry services;
      
   // Property names
   public static final QName PROP_DOCUMENT_NAME = QName.createQName("cm","name");
   public static final QName PROP_DOCUMENT_STATUS = QName.createQName("lpr.model","DocumentStatus");
   public static final String WORKFLOW_USER = "workflow";
   public static final String WORKFLOW_PASSWORD = "password";
  
   // Patameters
   private String status;
   private Element foreach;
     
   @Override
   protected void initialiseHandler(BeanFactory factory) {
      this.factory = factory;  
      services = (ServiceRegistry)factory.getBean(ServiceRegistry.SERVICE_REGISTRY);
   }

   public void execute(ExecutionContext executionContext) throws Exception {
      if (status == null) {
         throw new WorkflowException("status has not been provided");
      }
      System.out.println("STATUS en entrée:———> " + status);
      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;
         }
        
         NodeService nodeService = (NodeService) this.factory.getBean("nodeService");
         NamespaceService namespaceService = (NamespaceService) this.factory.getBean("namespaceService");
         PermissionService permissionService = (PermissionService) this.factory.getBean("permissionService");
        
         String DocPath = null;
         String Path = null;
         List<ChildAssociationRef> childRefs = nodeService.getChildAssocs(nodeRef);
         for (ChildAssociationRef tchildRef : childRefs) {
            final NodeRef childRef = tchildRef.getChildRef();
            DocPath = nodeService.getPath(childRef).toPrefixString(namespaceService);
         }
        
         Repository repository = (Repository)this.factory.getBean("JCR.Repository");
         Session session = null;
         try {
            // Think to add workflow as administrator on the "authority-service-contxt.xml" file on "classalfresco"
            session = repository.login(new SimpleCredentials(WORKFLOW_USER,WORKFLOW_PASSWORD.toCharArray()));

            // access the page via JCR
            Node rootNode = session.getRootNode();
            Node curentNodeRef = rootNode.getNode(DocPath);
                                
            // Convert the JCR Node to an Alfresco Node Reference
            NodeRef AdminNodeRef = JCRNodeRef.getNodeRef(curentNodeRef);
           
            nodeService.setProperty(AdminNodeRef,PROP_DOCUMENT_STATUS,status);
            session.save();
           
            // Change permission
            permissionService.setInheritParentPermissions(AdminNodeRef, false);
            // TEST PERMISSION
            permissionService.setPermission(AdminNodeRef, "user1", PermissionService.CONSUMER, true);
            permissionService.setPermission(AdminNodeRef, "user2", PermissionService.READ_CONTENT, true);
           
            // Get Path for the current Document
            List<ChildAssociationRef> parentRefs = nodeService.getParentAssocs(AdminNodeRef);
            for (ChildAssociationRef tparentRef : parentRefs) {
               final NodeRef parentRef = tparentRef.getParentRef();
               if (nodeService.getPath(parentRef).toPrefixString(namespaceService).startsWith("/app:company")) {
                  Path = nodeService.getPath(parentRef).toPrefixString(namespaceService);
                  //System.out.println("REPO - PARENT PATH: " + Path);
   
               }

            if (status.equals("In Review")) {
                 Path = Path.replace("Drafts","Review");
            }
            else if (status.equals("For Approval")) {
                    Path = Path.replace("Drafts","Pending Approval");
                    Path = Path.replace("Review","Pending Approval");
                 } else if (status.equals("Draft")) {
                             Path = Path.replace("Review","Drafts");
                             Path = Path.replace("Pending Approval","Drafts");
                        }
           
            // Get JCR Node Path Destination
            Node moveFolderNodeRef = rootNode.getNode(Path);
           
            // Convert the JCR Node Path Destination to an Alfresco Node Reference
            NodeRef AdminMoveNodeRef = JCRNodeRef.getNodeRef(moveFolderNodeRef);
           
            // Move Document to In Review folder
            String qname = QName.createValidLocalName(curentNodeRef.getName());
            nodeService.moveNode(AdminNodeRef, AdminMoveNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,qname));
         }
       
         finally {
            session.save();
            session.logout();
         }

      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}