cancel
Showing results for 
Search instead for 
Did you mean: 

How to rename authorityDisplayName Group using web services?

relax
Champ in-the-making
Champ in-the-making
Hello,
I create a User Groups using a web service. Then I would like to rename the group created by another name using web service.
Post http://forums.alfresco.com/en/viewtopic.php?f=35&t=21490 talking about AuthorityService.

Is there a way to find AuthorityServiceImpl using web service?

Is there another method to rename User Groups using web service?

Thank you!

This is the code to create a User Group:

public StringBuilder createGroup(String alfrescoAxisUrl,
         String parentGroupName, String groupName)
         throws AccessControlFault, RemoteException {

      StringBuilder stringBuilder = new StringBuilder();

      AccessControlServiceSoapBindingStub accessControlService = WebServiceFactory
            .getAccessControlService(alfrescoAxisUrl);
      // test if exist group name
      AuthorityFilter authorityFilter = new AuthorityFilter();
      authorityFilter.setAuthorityType(GROUP);

      String[] allAuthorities = accessControlService
            .getAllAuthorities(authorityFilter);

      Boolean existGroup = ArrayUtils.contains(allAuthorities,
            Constants.GROUP_PREFIX + groupName);

      if (!existGroup) {
         NewAuthority newAuthorityGroup = new NewAuthority(GROUP, groupName);
         NewAuthority[] newAuthorities = { newAuthorityGroup };

         if (parentGroupName != null) {
            parentGroupName = Constants.GROUP_PREFIX + parentGroupName;
         }
         accessControlService.createAuthorities(parentGroupName,
               newAuthorities);
         stringBuilder.append("parentGroupName = ");
         stringBuilder.append(parentGroupName);
         stringBuilder.append(", groupName = ");
         stringBuilder.append(groupName);
         logger.info(stringBuilder.toString());
      } else {
         stringBuilder.append("group = ");
         stringBuilder.append(groupName);
         stringBuilder.append(" already exists");
         logger.info(stringBuilder.toString());
      }
      stringBuilder.append("\n");
      return stringBuilder;
   }
12 REPLIES 12

mrogers
Star Contributor
Star Contributor
I don't think you can change the "groupName".    

You can change a group's "display name" through the "groups" web script or the authority service.

relax
Champ in-the-making
Champ in-the-making
Hello,
problem centered, I would like to change a group's "display name" using web service.

Is there a method to invoke a web script programmatically, in a java class?

Thank you.

relax
Champ in-the-making
Champ in-the-making
Hello,
what are the steps to invoke

Update the details of a group
PUT /alfresco/wcservice/api/groups/{shortName}

in mode PUT?

mdavid_cu
Champ in-the-making
Champ in-the-making
Another way to rename groups' "display name"  using web services can be something like that



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();
      }
   }
}

relax
Champ in-the-making
Champ in-the-making
Hello,
thank you for your response. I would like to rename the group "test" in "test123". My java main is
public static void main(String[] args) {
      try {
         WebServiceFactory
               .setEndpointAddress("http://192.168.11.235:8080/alfresco/api");
         AuthenticationUtils.startSession("admin", "admin");
         renameGroup1("test", "test12345");
         AuthenticationUtils.endSession();
      } catch (AuthenticationFault e) {
         e.printStackTrace();
      }
   }
but I have a java.lang.NullPointerException
Exception in thread "main" java.lang.NullPointerException
   at it.eng.alfresco.webservice.space.creation.test.TestRenameGroup.renameGroup1(TestRenameGroup.java:73)
   at it.eng.alfresco.webservice.space.creation.test.TestRenameGroup.main(TestRenameGroup.java:97)

Node[] nodes is null.

Is there a parameter that I must change in renameGroup method?

Is there, perhaps, a problem in the query?

Regards

relax
Champ in-the-making
Champ in-the-making
Hello,
after some tests, I suppose this a problem in group's authorityDisplayName.
This is the step of test in Alfresco 3.2r2.

1. Login as alfresco admin
2. Create a rootGroup named test
3. This is the principal properties that I see in Alfresco Node Browser for group test
Properties
Reference: workspace://SpacesStore/1fe88e02-6e91-4c6d-8c88-f4d3114c1112
Name: {http://www.alfresco.org/model/content/1.0}authorityName   
Value: GROUP_test
Name: {http://www.alfresco.org/model/system/1.0}store-identifier   
Value: SpacesStore
Name: {http://www.alfresco.org/model/content/1.0}authorityDisplayName   
Value: test
Name: {http://www.alfresco.org/model/system/1.0}store-protocol   
Value: workspace
4. I start the web service java main for rename authorityDisplayName property
public class TestRenameGroup {
    public static void renameGroup5(String uuid, String authorityDisplayName) {
      RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory
            .getRepositoryService();
      try {
         Store store = new Store("workspace", "SpacesStore");
         Reference reference = new Reference(store, uuid, null);
         Reference[] references = { reference };
         NamedValue[] namedValues = new NamedValue[] { Utils.createNamedValue("{http://www.alfresco.org/model/content/1.0}authorityDisplayName", authorityDisplayName) };
         Predicate predicate = new Predicate(references, store, null);
         CMLUpdate update = new CMLUpdate(namedValues, predicate, 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) {
         e.printStackTrace();
      } catch (RemoteException e) {
         e.printStackTrace();
      }
   }
   public static void main(String[] args) {
      try {
         WebServiceFactory
               .setEndpointAddress("http://192.168.11.235:8080/alfresco/api");
         AuthenticationUtils.startSession("admin", "admin");
         renameGroup5("1fe88e02-6e91-4c6d-8c88-f4d3114c1112", "Test2_A");
         AuthenticationUtils.endSession();
      } catch (AuthenticationFault e) {
         e.printStackTrace();
      }
   }
}
5. This is the principal properties that I see in Alfresco Node Browser for group test now!
Properties
Reference: workspace://SpacesStore/1fe88e02-6e91-4c6d-8c88-f4d3114c1112
Name: {http://www.alfresco.org/model/content/1.0}authorityName   
Value: GROUP_test
Name: {http://www.alfresco.org/model/system/1.0}store-identifier   
Value: SpacesStore
Name: {http://www.alfresco.org/model/content/1.0}authorityDisplayName   
Value: Test2_A
Name: {http://www.alfresco.org/model/system/1.0}store-protocol   
Value: workspace
6. Logout Alfresco
7. Login as alfresco admin
8. Go in Manage User Groups
9. I see the display name group test.
It's not display name Test2_A.

Why?

This problem there is also I use web script, see

http://forums.alfresco.com/en/viewtopic.php?f=36&t=25023

Thank you.

mdavid_cu
Champ in-the-making
Champ in-the-making
Try to rename parameter's value
    {http://www.alfresco.org/model/content/1.0}authorityName

Note: the value of this parameter must be added the prefix: "GROUP_"+the_new_value

relax
Champ in-the-making
Champ in-the-making
Hello,
I try to rename parameter's value {http://www.alfresco.org/model/content/1.0}authorityName
with authorityName = "GROUP_"+the_new_value
but I have a java.lang.UnsupportedOperationException: The name of an authority can not be changed

AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
faultSubcode:
faultString:
faultActor:
faultNode:
faultDetail:
   {http://www.alfresco.org/ws/service/repository/1.0}RepositoryFault:<ns1:errorCode>0</ns1:errorCode><ns1:message>java.lang.UnsupportedOperationException: The name of an authority can not be changed</ns1:message>
   {http://xml.apache.org/axis/}exceptionName:org.alfresco.repo.webservice.repository.RepositoryFault
   {http://xml.apache.org/axis/}stackTrace:
   at org.alfresco.repo.webservice.repository.RepositoryWebService.update(RepositoryWebService.java:341)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
   at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
   at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
   at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
   at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
   at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
   at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
   at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
   at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
   at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Thread.java:619)

   {http://xml.apache.org/axis/}hostname:ubuntu-desktop


   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
   at java.lang.Class.newInstance0(Class.java:355)
   at java.lang.Class.newInstance(Class.java:308)
   at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:104)
   at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:90)
   at org.alfresco.webservice.repository.RepositoryFault.getDeserializer(RepositoryFault.java:146)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.axis.encoding.ser.BaseDeserializerFactory.getSpecialized(BaseDeserializerFactory.java:154)
   at org.apache.axis.encoding.ser.BaseDeserializerFactory.getDeserializerAs(BaseDeserializerFactory.java:84)
   at org.apache.axis.encoding.DeserializationContext.getDeserializer(DeserializationContext.java:464)
   at org.apache.axis.encoding.DeserializationContext.getDeserializerForType(DeserializationContext.java:547)
   at org.apache.axis.message.SOAPFaultDetailsBuilder.onStartChild(SOAPFaultDetailsBuilder.java:157)
   at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
   at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
   at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
   at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
   at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
   at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
   at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
   at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
   at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
   at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
   at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
   at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
   at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
   at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
   at org.apache.axis.client.Call.invoke(Call.java:2767)
   at org.apache.axis.client.Call.invoke(Call.java:2443)
   at org.apache.axis.client.Call.invoke(Call.java:2366)
   at org.apache.axis.client.Call.invoke(Call.java:1812)
   at org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub.update(RepositoryServiceSoapBindingStub.java:986)
   at it.eng.alfresco.webservice.space.creation.test.TestRenameGroup.renameGroup5(TestRenameGroup.java:57)
   at it.eng.alfresco.webservice.space.creation.test.TestRenameGroup.main(TestRenameGroup.java:37)

dward
Champ on-the-rise
Champ on-the-rise
The first test was correct. Alfresco Explorer doesn't display authority display names. Only Share.