cancel
Showing results for 
Search instead for 
Did you mean: 

Getting property definitions through Dictionary Web Service

8alery
Champ in-the-making
Champ in-the-making
Hello,

first of all I'm using C# and I'm trying to get properties definitions and properties values of my custom type using Web Services. I use Repository Service to get values and Dictionary Service to get property definitions, but it don't work the way I need.
I have reference to the instance of my custom type, but I don't know its properties, so I tried something like this:

Predicate predicate = new Predicate();
predicate.Items = new Object[] { reference };
Node[] nodes = WebServiceFactory.getRepositoryService().get(predicate);

foreach (NamedValue nv in nodes[0].properties)
{
      string propValue = nv.value;
      PropertyDefinition [] propDefinitions = WebServiceFactory.getDictionaryService().getProperties(new string[] { nv.name} );
      string propTitle = propDefinitions[0].title;
      string propDataType = propdefinitions[0].dataType;    
}
But I get exception at this line:
PropertyDefinition [] propDefinitions = WebServiceFactory.getDictionaryService().getProperties(new string[] { nv.name} );

Stack trace for exception look like this:
in System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
in System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
in Alfresco.DictionaryService.getProperties(String[] propertyNames) in ….
7 REPLIES 7

steffen
Champ in-the-making
Champ in-the-making
hi 8alery,

the stacktrace you posted is stripped and the exception is missing. Could you post the complete trace? Without an exception it's difficult to tell what's worng.

regards

steffen

mdavid_cu
Champ in-the-making
Champ in-the-making
Hi, there is not special treatment for the dictionary service, your principal problem if in the value of the parameters passed to the method "getClasses". The ClassPredicate's name attribute must be a name in the contracted mode, (prefix:name). Obviously you are setting the extended mode ({uri}name). So I suggest this other way, it is not so efficiently but it will help you to get the property definition from a node directly.


public static void getPropertiesDefinition(String nodeName) {

      DictionaryServiceSoapBindingStub dictionaryService = WebServiceFactory
            .getDictionaryService();
      try {
         
         ClassDefinition[] definitions = dictionaryService.getClasses(null,
               null);

         PropertyDefinition[] properties = null;

         for (ClassDefinition classDefinition : definitions) {

            if (classDefinition.getName().equals(nodeName)) {
               properties = classDefinition.getProperties();
               break;
            }
         }
         
         for (PropertyDefinition propertyDefinition : properties) {
            System.out.println(propertyDefinition.getName());
         }

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

   public static void main(String[] args) {
      try {
         final String repositoryPath = "http://10.7.16.199:8080/alfresco/api";
         final String userName = "admin";
         final String passwd = "admin";

         WebServiceFactory.setEndpointAddress(repositoryPath);
         AuthenticationUtils.startSession(userName, passwd);         
         getPropertiesDefinition(Constants.TYPE_CONTENT);

      } catch (AuthenticationFault e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } finally {
         AuthenticationUtils.endSession();
      }
   }

Sorry for the JAVA code, I figured out, that C# don't be far away of this syntax code.
I hope helps.

themarcuz
Champ in-the-making
Champ in-the-making
How have you been able to translate namespace into prefix using web service?
I have to check out what properties are of type date for a node, but I cannot get the properties name in prefix:name format…

sgomez
Champ in-the-making
Champ in-the-making
Once you have the qname, you can manually create the string:

System.out.println(qname.getNamespaceURI() + ":" + qname.getLocalName());

Hope this helps

prateekgoyal
Champ in-the-making
Champ in-the-making
Hi @ 8alery,
Can you please show me the snippet of your code, actually i have the similar problem.
I want to search a node based the type definition, like if i have created a custom model definition alfresco for e.g "{Insurance.new.model}". This uri is defined in my custom model xml file.
Now i want to search all those documents in the reposotiry which are attached with this definition.
Can you please guide me to the steps for doing this.
I am using web service api and java.

Thanks,

rooper3546
Champ in-the-making
Champ in-the-making
I had the same problem  with types names, I used "{namespace}name" form. I replace it with "prefix:name" and now it is working…thanks..

shiva
Champ in-the-making
Champ in-the-making
Hi,

I am using dictionary service for getting properties of custom content model.I am using dictionaryService.getProperties() method in my java file but unable to get the properties.
It shows an error model does not exist. here i attach code

public Map<String,Object> executeImpl(WebScriptRequest req, Status status,Cache cache) {
      
      String CustomType=req.getParameter("CustomType");
      QName prefix =QName.createQName("{http://www.alfresco.org/model/content/1.0}content");
      
      Collection<QName> s = dictionaryService.getProperties(prefix);
         
      Map<String, Object> mapResult = new HashMap<String, Object>();
      mapResult.put("Result",s.size());
         
      return mapResult;
      
         
   }
I am displaying the result in .json file.
If any help provided it would be great help for me