cancel
Showing results for 
Search instead for 
Did you mean: 

run CMLDelete before CMLCreate

bparis
Champ in-the-making
Champ in-the-making
Hello,

I need to upload a content into the repository via webservices.  
The first time the upload is done, it is ok with the ws services API CMLCreate and WebServiceFactory.getRepositoryService().update.
Once the content already exists in the repository, I get a DuplicateChildNodeNameException exception I can understand…, so I think I am to first delete the existing file using CMLDelete and WebServiceFactory.getRepositoryService().update, then create the new one with
CMLCreate and WebServiceFactory.getRepositoryService().update.

Is there a mean to put both CML (delete and create) in a same CML script, so that the CMLDelete will be executed before the CMLCreate ?

Thanks,
Bernard
1 REPLY 1

bparis
Champ in-the-making
Champ in-the-making
mmmh, it seems CMLUpdate will help a bit :

             Query query = new Query(Constants.QUERY_LANG_LUCENE, "PATH:\"/app:company_home/cm:UCLtest/cm:" + ISO9075.encode(filename) + "\"" );

             ResultSet rs = WebServiceFactory.getRepositoryService().query(storeRef, query, false).getResultSet();
             ResultSetRow[] rsRows = rs.getRows();
             if(rs.getTotalRowCount() > 0)
             {
                System.out.println("will update the file " + rsRows[0].getColumns(1).getValue());
                Reference reference = new Reference(storeRef, rsRows[0].getNode().getId(), null);
                Predicate predicate = new Predicate(new Reference[]{reference}, null, null);
                CMLUpdate update = new CMLUpdate( titledProps, predicate, "1");
                cml.setUpdate(new CMLUpdate[] {update});
                                                                cml.setAddAspect(new CMLAddAspect[] {addAspect});
             }
             else {
                System.out.println("will create the file ");
                   CMLCreate create = new CMLCreate("1", companyHomeParent, null, null, null, Constants.TYPE_CONTENT, contentProps);
                   cml.setCreate(new CMLCreate[] {create});
                   cml.setAddAspect(new CMLAddAspect[] {addAspect});
             }