01-26-2010 09:58 AM
/**
* folderPath e.g. /app:company_home/app:user_homes/cm:Main/cm:Users/cm:Bewerber/cm:Hancock_Paul
* newFoldername e.g. Hancock_Herbie
*/
public static void updateFolderName (String folderPath, String newFoldername){
UpdateResult [] result = null;
//get the reference to the data which should be updated
final Reference reference = new Reference(STORE, null, folderPath);
final Predicate p = new Predicate(new Reference[]{reference},STORE,null);
//create CMLUpdate instance referring to the current data
final CMLUpdate updateFolder = new CMLUpdate( new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, newFoldername)},p,null);
CML cml = new CML();
cml.setUpdate(new CMLUpdate[]{updateFolder});
try {
result = WebServiceFactory.getRepositoryService().update(cml);
// still the old path!
System.out.println("new path: "+result[0].getDestination().getPath());
} catch ( RepositoryFault rf ) {
rf.printStackTrace();
} catch ( RemoteException re ) {
re.printStackTrace();
}
}
01-28-2010 07:25 AM
01-28-2010 07:42 AM
01-28-2010 09:26 AM
/app:company_home/app:user_homes/cm:Main/cm:Users/cm:Bewerber/cm:Hancock_Paul
i excepted the new path
/app:company_home/app:user_homes/cm:Main/cm:Users/cm:Bewerber/cm:Hancock_Herbie
new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, newFoldername)}
01-28-2010 09:51 AM
01-28-2010 10:59 AM
package org.alfresco.sample;
import org.alfresco.webservice.repository.QueryResult;
import org.alfresco.webservice.repository.UpdateResult;
import org.alfresco.webservice.types.CML;
import org.alfresco.webservice.types.CMLMove;
import org.alfresco.webservice.types.CMLUpdate;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.ParentReference;
import org.alfresco.webservice.types.Predicate;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.types.ResultSet;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.Utils;
import org.alfresco.webservice.util.WebServiceFactory;
public class RenameSpaceTest {
public static final Store STORE = new Store(Constants.WORKSPACE_STORE,"SpacesStore");
//the folder which should be renamed
static String OLD_PATH = "/app:company_home/app:user_homes/cm:Users/cm:Candidate/cm:Old";
public static void main(String[] args) throws Exception {
AuthenticationUtils.startSession("admin", "admin");
try {
renameSpace(new Reference(STORE, null, OLD_PATH), "NEW");
} catch (Throwable e) {
e.printStackTrace();
} finally {
// End the session
AuthenticationUtils.endSession();
System.exit(0);
}
}
protected static Reference getParent(Reference space) throws Exception {
QueryResult result = WebServiceFactory.getRepositoryService().queryParents(space);
ResultSet resultset = result.getResultSet();
String first_parent_id = resultset.getRows(0).getNode().getId();
System.out.println("The queried parent id is: " + first_parent_id);
Reference parent = new Reference(STORE, first_parent_id, null);
return parent;
}
protected static void moveSpace(Reference space, Reference dest,String newname) throws Exception {
ParentReference parentDest = ReferenceToParent(dest);
parentDest.setChildName(Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, normilizeNodeName(newname)));
CMLMove move = new CMLMove();
move.setTo(parentDest);
move.setWhere(new Predicate(new Reference[] { space }, STORE, null));
NamedValue[] properties = new NamedValue[] { Utils.createNamedValue(
Constants.PROP_NAME, newname) };
CMLUpdate update = new CMLUpdate();
update.setProperty(properties);
update.setWhere(new Predicate(new Reference[] { space }, STORE, null));
CML cml = new CML();
cml.setMove(new CMLMove[] { move });
cml.setUpdate(new CMLUpdate[] { update });
// Execute the CML move and Update statement
try {
System.out.println("Moving the space with path " + space.getPath()
+ " or id " + space.getUuid() + "\n"
+ "to destination space with path " + dest.getPath()
+ " or id " + dest.getUuid() + "\n" + "by using the name "
+ newname + ".");
UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
//check if the path has changed after the update->
// there is still the old path !
//-> "/app:company_home/app:user_homes/cm:Users/cm:Candidate/cm:Old
System.out.println("destination: " + result[0].getDestination().getPath());
System.out.println("source: " + result[0].getSource().getPath());
} catch (Exception e2) {
System.err.println("Can not move the space.");
throw e2;
}
}
protected static void renameSpace(Reference space, String newName)throws Exception {
Reference parent = getParent(space);
moveSpace(space, parent, newName);
}
protected static ParentReference ReferenceToParent(Reference spaceref) {
ParentReference parent = new ParentReference();
parent.setStore(STORE);
parent.setPath(spaceref.getPath());
parent.setUuid(spaceref.getUuid());
parent.setAssociationType(Constants.ASSOC_CONTAINS);
return parent;
}
// Blanks are allowed in space names but not in paths. Because the path
// should depend on the name we need a version of the name which contains no
// blanks
protected static String normilizeNodeName(String name) {
return name.replace(" ", "_");
}
}
+PATH:/app:company_home/app:user_homes/cm:Users/cm:Candidate/cm:NEW
Failed to resolve to a single NodeRef with parameters (store=workspace:SpacesStore uuid=null path=/app:company_home/app:user_homes/cm:Users/cm:Candidate/cm:NEW), found 0 nodes.</ns1:message>
04-18-2010 11:41 PM
04-27-2010 11:33 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.