cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to list the content of a folder ?

sam69
Champ in-the-making
Champ in-the-making
Hello !
First of all, I am a newbie in the Alfresco WebServices, but I have already read the WebService Samples.
I can't really find an example to do this simple task:

I want to get all the items (documents and folder) of a specific folder.
I tried that :


RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();      
    Reference reference = new Reference(new Store(StoreEnum.workspace, "SpacesStore")
        , null, "/app:company_home/*[@cm:name=\"" + Data Dictionary + "\"]");
    Predicate predicate = new Predicate(new Reference[]{reference}, null, null);
   
    Node[] nodes = null;
    try
    {
      nodes = repositoryService.get(predicate);

      for (Node n : nodes) {
        System.out.println(n.toString());
        }
      }

And the result is only :
org.alfresco.webservice.types.Node@8f8b47fd
But there are several elements in the folder Data Dictionary 😞

I suspect my Xpath query…
And I think also that there is a better and faster way to do what I want.

Anyone can help me ?

Thanks in advance !

Regards,
Samuel
6 REPLIES 6

andy
Champ on-the-rise
Champ on-the-rise
Hi

"/app:company_home/*[@cm:name=\"" + Data Dictionary + "\"]"

Should find the data dictionary folder (well all folders called DD)

If you want the top level children
"/app:company_home/*[@cm:name=\"" + Data Dictionary + "\"]/*"

If you want all the children
"/app:company_home/*[@cm:name=\"" + Data Dictionary + "\"]//*"

However these queries are not the most efficient.

I would recommend you find the DD node and then run the query in this context with "./*" or ".//*" to find the children or all descendants respectively.

Regards

Andy

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Alternativly you ca n use the queryChildren method on the repository web service.  This will return all the children of a given reference.

It should be a little faster than the query since it uses the underlying API directly, but does not have the flexability of a query.

Cheers,
Roy

sam69
Champ in-the-making
Champ in-the-making
Thaks Andy and rwetherall !

I used both of yours methods 😉 It's work fine when I run this code in a standalone application.

Here is my code if it can help somebody else..

this.authentification.demarrerSession(LOGIN, PASSWORD);

      RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();      
     
      Reference reference = new Reference(new Store(StoreEnum.workspace, "SpacesStore")
          , null, "/app:company_home/*[@cm:name=\"" + NOM_UTILISATEUR_DEPOT_GEDIWEB + "\"]");
      Predicate predicate = new Predicate(new Reference[]{reference}, null, null);       
      Node[] nodes = repositoryService.get(predicate);
     
      // Query pour lister les enfants du noeud Gediweb
      Reference nodeGediweb = nodes[0].getReference();
      String nodeGediwebId = nodeGediweb.getUuid();

      QueryResult rootChildren = WebServiceFactory.getRepositoryService().queryChildren(nodeGediweb);
      ResultSet rootChildrenResults = rootChildren.getResultSet();

      ResultSetRow[] rows = rootChildrenResults.getRows();
      for (int i = 0; i < rows.length; i++)
      { etc….

But now, I am fighting with tomcat, it seems tomcat use it's own (old) library and I have some exception with security 😞

timv
Champ in-the-making
Champ in-the-making
Hi,
when working this way using the webservices api:
Once you got a ResultSetRowNode, how to get to the actual org.alfresco.webservice.types.Node??
I want to fetch the properties of the node..

another thing is, doing this:

   String np = "/app:company_home/cm:Public_x0020_website/cm:Events";
        Store store = new Store(StoreEnum.workspace, "SpacesStore");
        Reference node = new Reference(store, null, np);
        RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();      
        Predicate predicate = new Predicate(new Reference[]{node}, null, null);
        Node[] nodes = null;
        try {
         nodes = repositoryService.get(predicate);
         …
I get an exception that more than one node is found
(Failed to resolve to a single NodeRef with parameters (store=workspaceSmiley FrustratedpacesStore uuid=null path=/app:company_home/cmSmiley Tongueublic_x0020_website/cm:Events/*), found 19 nodes.), what is the logic behind this?
How can I fetch all nodes in a given space and catch their properties?

Thanks,
Tim

shamabbas
Champ in-the-making
Champ in-the-making
Hi all,
I'm trying to upload file but im getting path exception please help me as soon as possible..
I'm using the following code
ParentReference companyHomeParent = new ParentReference(STORE, null, "/app:company_home/cm:" + ISO9075.encode(fileIndex), Constants.ASSOC_CONTAINS, null);

and got the following exception

init:
deps-jar:
wsimport-init:
wsimport-client-RepositoryService:
files are up to date
wsimport-client-ContentService:
files are up to date
wsimport-client-generate:
Compiling 1 source file to C:\Documents and Settings\ehtsham\My Documents\NetBeansProjects\UploadTest\build\classes
compile:
run:
inside alfresco part:…
Connecting to: http://localhost:8080/alfresco
Ticket::TICKET_bd0f745deaf88d459c4dd9b8c2c76be8bdc93029
Association type:::{http://www.alfresco.org/model/content/1.0}contains
ChiledName:::null
Path:::::/app:company_home/cm:null
Creating the document file.txt
Can not create the document.
Error uploading file:::
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.IllegalStateException: Failed to resolve to a single NodeRef with parameters (store=workspace:SpacesStore uuid=null path=/app:company_home/cm:null), found 0 nodes.</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.GeneratedMethodAccessor455.invoke(Unknown Source)
        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:710)
        at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
        at java.lang.Thread.run(Thread.java:619)

        {http://xml.apache.org/axis/}hostname:flying-int-02


        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)
[Ljava.lang.StackTraceElement;@e0a386

session ending
Closing connection.
        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)
The result file index is null
        at org.apache.axis.client.Call.invoke(Call.java:1812)
        at org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub.update(RepositoryServiceSoapBindingStub.java:986)
        at uploadtest.Main.createDocument(Main.java:251)
        at uploadtest.Main.upload(Main.java:99)
        at uploadtest.Main.main(Main.java:298)
BUILD SUCCESSFUL (total time: 4 seconds)

shamabbas
Champ in-the-making
Champ in-the-making
Hi all,
I'm trying to upload file but im getting path exception please help me as soon as possible..
I'm using the following code
ParentReference companyHomeParent = new ParentReference(STORE, null, "/app:company_home/cm:" + ISO9075.encode(fileIndex), Constants.ASSOC_CONTAINS, null);

and got the following exception

init:
deps-jar:
wsimport-init:
wsimport-client-RepositoryService:
files are up to date
wsimport-client-ContentService:
files are up to date
wsimport-client-generate:
Compiling 1 source file to C:\Documents and Settings\ehtsham\My Documents\NetBeansProjects\UploadTest\build\classes
compile:
run:
inside alfresco part:…
Connecting to: http://localhost:8080/alfresco
Ticket::TICKET_bd0f745deaf88d459c4dd9b8c2c76be8bdc93029
Association type:::{http://www.alfresco.org/model/content/1.0}contains
ChiledName:::null
Path:::::/app:company_home/cm:null
Creating the document file.txt
Can not create the document.
Error uploading file:::
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.IllegalStateException: Failed to resolve to a single NodeRef with parameters (store=workspace:SpacesStore uuid=null path=/app:company_home/cm:null), found 0 nodes.</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.GeneratedMethodAccessor455.invoke(Unknown Source)
        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:710)
        at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
        at java.lang.Thread.run(Thread.java:619)

        {http://xml.apache.org/axis/}hostname:flying-int-02


        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)
[Ljava.lang.StackTraceElement;@e0a386

session ending
Closing connection.
        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)
The result file index is null
        at org.apache.axis.client.Call.invoke(Call.java:1812)
        at org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub.update(RepositoryServiceSoapBindingStub.java:986)
        at uploadtest.Main.createDocument(Main.java:251)
        at uploadtest.Main.upload(Main.java:99)
        at uploadtest.Main.main(Main.java:298)
BUILD SUCCESSFUL (total time: 4 seconds)

Thanks in advanceee!!!!!!