星期二, 1月 04, 2011

[Alfresco] How to rename User Groups using web services? (4)

重新命名群組,下面程式尚未測試過,僅供參考。


package org.my.self.test;

import java.rmi.RemoteException;

import org.alfresco.webservice.accesscontrol.AccessControlServiceSoapBindingStub;
import org.alfresco.webservice.authentication.AuthenticationFault;
import org.alfresco.webservice.repository.RepositoryFault;
import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
import org.alfresco.webservice.repository.UpdateResult;
import org.alfresco.webservice.types.CML;
import org.alfresco.webservice.types.CMLUpdate;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.Node;
import org.alfresco.webservice.types.Predicate;
import org.alfresco.webservice.types.Query;
import org.alfresco.webservice.types.Reference;
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 TestRenameGroup {

public static void renameGroup(String groupName, String newName) {
String query = "+PATH:\"/sys:system/sys:authorities//*\" + @usr\\:authorityName:\""
+ groupName + "\"";
RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory
.getRepositoryService();
try {
Node[] nodes = repositoryService.get(new Predicate(null, new Store(
"user", "alfrescoUserStore"), new Query(
Constants.QUERY_LANG_LUCENE, query)));

CMLUpdate update = new CMLUpdate(new NamedValue[] {Utils.createNamedValue("{http://www.alfresco.org/model/user/1.0}authorityName", newName)},
new Predicate(new Reference[] { nodes[0].getReference() },
null, null), null);
CML cml = new CML();
cml.setUpdate(new CMLUpdate[]{update});
UpdateResult[] updateResults = repositoryService.update(cml);
for (UpdateResult updateResult : updateResults) {
System.out.println(updateResult.getStatement());
}

} catch (RepositoryFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public static void main(String[] args) {
try {
WebServiceFactory
.setEndpointAddress("http://10.7.16.199:8080/alfresco/api");
AuthenticationUtils.startSession("admin", "admin");

renameGroup("GROUP_NODE_READER_ONLY", "GROUP_NODE_READER_ONLY1");
} catch (AuthenticationFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Reference:
How to rename User Groups using web services? (4)

沒有留言:

張貼留言

留個話吧:)