Alfresco Remote API, obtener carpeta Company Home

cancel
Showing results for 
Search instead for 
Did you mean: 
witho
Active Member

Alfresco Remote API, obtener carpeta Company Home

Hola,

Estoy creando usuarios de Alfresco desde una clase Java, usando un proyecto open source llamado RAAR (CMA). El caso es que al crear el nuevo usuario quiero configurar su carpeta personal como la carpeta "Company Home" y no consigo obtener la referencia al nodo de esta carpeta. Dejo aquí mi codigo, espero que alguien pueda echarme una mano para hacer esto bien, he probado con metodos como getChildByName y getRootNode pero no consigo nada. Gracias.


                String userName;
      userName = user.getLogin();      
      String passwd = user.getPassword();
      String firstName = user.getFirstName();
      String lastName = user.getLastName();
      String email = user.getEmailAddress();      
                  
      QName firstNameQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}firstName");
      QName lastNameQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}lastName");
      QName passwordQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}password");
      QName emailQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}email");
      QName homeFolderQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}homeFolder");
      
      Map<QName, Serializable> props = null;
      props = new HashMap<QName, Serializable>(5);
      // homeFolder value must be a nodeRef
      props.put(firstNameQName, firstName);
      props.put(lastNameQName, lastName);
      props.put(passwordQName, passwd);
      props.put(emailQName, email);
            
      try{
      
         configurationApplicationContext=WebApplicationContextUtils.getWebApplicationContext(this.getServlet().getServletContext());
         
         authenticationService = (AuthenticationServiceImpl) configurationApplicationContext.getBean("authenticationService");
         peopleService = (PeopleServiceImpl) configurationApplicationContext.getBean("peopleService");
         nodeService = (NodeServiceImpl) configurationApplicationContext.getBean("nodeService");         
         
         ticket = authenticationService.authenticate(repositoryUri, userid, password.toCharArray());   
         
         NodeRef rootNode = nodeService.getRootNode(ticket, new StoreRef("workspace://SpacesStore"));
         
         //NodeRef homeFolder = nodeService.getChildByName(ticket, rootNode, QName.createQName(
                        "{http://www.alfresco.org/model/content/1.0}folder" ), "app:company_home");
         
         props.put(homeFolderQName, rootNode );
         
                  System.out.println("Creating the user called pruebaLray");
                   NodeRef userRef = peopleService.createPerson(ticket, userName, passwd.toCharArray(), props);
1 Reply
witho
Active Member

Re: Alfresco Remote API, obtener carpeta Company Home

Finalmente consegui recoger la referencia al nodo raiz de mi repositorio de Alfreso. Posteo mi codigo por si sirve de ayuda a alguien.


         //Get "Company Home" NodeRef
         
         String queryStr = String.format(FORMAT_QUERY, "/app:company_home");
         
         /**
         * Return a maximum of 100 nodes inside the given folder path
         */
         List<Node> results = searchService.query(ticket, new StoreRef("workspace://SpacesStore"),
               SearchService.QueryLanguage.lucene, queryStr,
               new Vector<QName>(QUERY_PROPERTIES), false, false, false, false,
               null, 100, null);
         
         NodeRef homeFolder = null;
         for(int i=0;i<results.size();i++){
            Map<QName, Serializable> properties = null;            
            properties = results.get(i).getProperties();
            if(properties.containsValue(space)){
               homeFolder = results.get(i).getNodeRef();
            }
         }
         //NodeRef homeFolder = results.get(0).getNodeRef();
         
         props.put(ContentModel.PROP_HOMEFOLDER, homeFolder);
         
         //Create the user in Alfresco and add it to the convenient groups
         
         System.out.println("Creating the user called " + userName);
           NodeRef userRef = peopleService.createPerson(ticket, userName, passwd.toCharArray(), props);

Saludos a todos.