AnsweredAssumed Answered

Create folder and subfolder via API Java

Question asked by monocromo on Apr 24, 2013
Latest reply on May 8, 2013 by monocromo
i would like create this structure /cm:documentLibrary/cm:TestPorting/cm:2388/cm:InVigore but i can't. Because when i create  the subfolder "inVigore" i have this error:

org.alfresco.service.cmr.repository.XPathException: 03242678 Error executing xpath: \n /app:company_home/st:sites/cm:prova-italia-spa/cm:documentLibrary/cm:TestPorting/cm:2388/cm:InVigore

This is the code that create the folder:

boolean res = this.createFolder("2388","/app:company_home/st:sites/cm:bosco-italia-spa/cm:documentLibrary/cm:TestPorting");
boolean res1 = this.createFolder("Approvati","/app:company_home/st:sites/cm:bosco-italia-spa/cm:documentLibrary/cm:TestPorting/cm:2388");
boolean res2 = this.createFolder("inVigore","/app:company_home/st:sites/cm:bosco-italia-spa/cm:documentLibrary/cm:TestPorting/cm:2388");

public boolean createFolder(String fileName,String percorso) throws Exception
      // Avvio sessione
        //AuthenticationUtils.startSession(user, password);
           // Referenza al nodo padre in cui inserire il documento
            Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
            ParentReference companyHomeParent = new ParentReference(storeRef, null, percorso, Constants.ASSOC_CONTAINS, Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, "folder"));
            //Richiesta del repository service e del content service
            RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
            ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
            //Vettori delle proprietà
           NamedValue[] contentProps = new NamedValue[1];
          //Assegnazione ai vettori delle proprietà
            contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, fileName);

            //Upload file custom           
            CMLCreate create = new CMLCreate("1", companyHomeParent, null, null, null, Constants.TYPE_FOLDER, contentProps);
            // Blocco create CML
            CML cml = new CML();
            cml.setCreate(new CMLCreate[] {create});
            //Creazione effettiva del nodo
            UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);    
            System.out.println("Cartella creata: " + fileName);
            return true;
        catch(Throwable e)
            return false;
            // Fine della sessione

Where is the problem?
If i create more folder in /cm:documentLibrary/cm:TestPorting/cm:2388 i haven't problem but if i create a folder in cm:2388 java report the above error.