Move existing folder in new sub-folder

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

Move existing folder in new sub-folder

Hi, I have following structure in documentLibrary:

n sub folders (with documents) in 1 Folder

PATIENTS  

   | ---- Toto                    (cm:created = 20190526)

   | ---- Titi                      (cm:created = 20190526)

   | -----Tutu                    (cm:created = 20190424)

And I have to change this structure as following:

PATIENTS

   | ---- 2019

   |           | -----04

   |           |           | ------24 

   |           |                     |-------Tutu

   |           | -----05

   |                     | ------26 

   |                                |-------Toto

   |                                |------- Titi

This is what I have tried :

StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
ResultSet  rs = searchService.query(storeRef, SearchService.LANGUAGE_XPATH,
"/app:company_home/st:sites/cm:" + coreServices.getDocumedSiteName() + "/cm:documentLibrary/cmSmiley TongueATIENTS");
for (NodeRef patient : rs.getNodeRefs()) {

      Date datec = (Date) nodeService.getProperty(patient, ContentModel.PROP_CREATED);
      String date = new SimpleDateFormat("yyyyMMdd").format(datec);
      String aaaa = date.substring(0, 4);
      String mm = date.substring(4, 6);
      String jj = date.substring(6, 8);

         // contrôle si rep documentLibrary/PATIENTS/AAAA existe
       NodeRef aaaaNodeRef = nodeService.getChildByName(coreServices.getfolderNode("PATIENTS"),                                                 ContentModel.ASSOC_CONTAINS, aaaa);
        if (aaaaNodeRef == null)
                        aaaaNodeRef = coreServices.createFolder(coreServices.getfolderNode("PATIENTS"), aaaa,                                                 ContentModel.TYPE_FOLDER);

            // contrôle si rep documentLibrary/PATIENTS/AAAA/MM existe
           NodeRef mmNodeRef = nodeService.getChildByName(aaaaNodeRef, ContentModel.ASSOC_CONTAINS, mm);
           if (mmNodeRef == null)
                        mmNodeRef = coreServices.createFolder(aaaaNodeRef, mm, ContentModel.TYPE_FOLDER);

            // contrôle si rep documentLibrary/PATIENTS/AAAA/MM/JJ existe
            NodeRef jjNodeRef = nodeService.getChildByName(mmNodeRef, ContentModel.ASSOC_CONTAINS, jj);
            if (jjNodeRef == null)
                        jjNodeRef = coreServices.createFolder(mmNodeRef, jj, ContentModel.TYPE_FOLDER);

            // On déplace le répertoire du patient dans la nouvelle architecture
            fileFolderService.move(patient, jjNodeRef, null);     ********** FAILED *******

}

aaaa, mm and jj are well extrated but It fails in move instruction with following reason : 

ERROR [node.ibatis.NodeDAOImpl] [http-nio-8080-exec-8] Cyclic parent-child relationship detected: 

What is wrong ?

Question : will titi, toto and tutu nodeRef change ?

Thank you

1 Reply
anakin59490
Established Member II

Re: Move existing folder in new sub-folder

OK , * character is missing:

rs = searchService.query(storeRef, SearchService.LANGUAGE_XPATH,
"/app:company_home/st:sites/cm:" + coreServices.getDocumedSiteName() + "/cm:documentLibrary/cmSmiley TongueATIENTS/*")