chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r785746 - in /incubator/chemistry/trunk/chemistry: chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/ chemistry-atompub-client/sr...
Date Wed, 17 Jun 2009 18:15:11 GMT
Author: fguillaume
Date: Wed Jun 17 18:15:04 2009
New Revision: 785746

URL: http://svn.apache.org/viewvc?rev=785746&view=rev
Log:
implemented query support for AtomPub server and client, im-memory backend assumes very simple
queries for now

Added:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/QueryWriter.java
  (with props)
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISQueryFeed.java
  (with props)
    incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/QueryElement.java
  (with props)
Modified:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/DefaultIOProvider.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientConnector.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/CMIS.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleType.java
    incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java?rev=785746&r1=785745&r2=785746&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
Wed Jun 17 18:15:04 2009
@@ -20,6 +20,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -350,14 +351,27 @@
             boolean searchAllVersions, boolean includeAllowableActions,
             boolean includeRelationships, int maxItems, int skipCount,
             boolean[] hasMoreItems) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+        String href = repository.getCollectionHref(CMIS.COL_QUERY);
+        Response resp = connector.postQuery(new Request(href), statement);
+        if (!resp.isOk()) {
+            throw new ContentManagerException(
+                    "Remote server returned error code: "
+                            + resp.getStatusCode());
+        }
+        List<ObjectEntry> objects = resp.getObjectFeed(new ReadContext(this));
+        return objects;
     }
 
     public Collection<CMISObject> query(String statement,
             boolean searchAllVersions) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+        boolean[] hasMoreItems = new boolean[1];
+        Collection<ObjectEntry> res = query(statement, searchAllVersions,
+                false, false, 0, 0, hasMoreItems);
+        List<CMISObject> objects = new ArrayList<CMISObject>(res.size());
+        for (ObjectEntry e : res) {
+            objects.add(APPObject.construct((APPObjectEntry) e));
+        }
+        return objects;
     }
 
     /*

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/DefaultIOProvider.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/DefaultIOProvider.java?rev=785746&r1=785745&r2=785746&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/DefaultIOProvider.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/DefaultIOProvider.java
Wed Jun 17 18:15:04 2009
@@ -27,6 +27,7 @@
 import org.apache.chemistry.atompub.client.APPServiceDocumentReader;
 import org.apache.chemistry.atompub.client.TypeEntryReader;
 import org.apache.chemistry.atompub.client.TypeFeedReader;
+import org.apache.chemistry.atompub.client.stax.QueryWriter;
 import org.apache.chemistry.atompub.client.stax.EntryReader;
 import org.apache.chemistry.atompub.client.stax.FeedReader;
 import org.apache.chemistry.atompub.client.stax.ServiceDocumentReader;
@@ -50,6 +51,8 @@
 
     protected APPObjectEntryWriter objectWriter = new APPObjectEntryWriter();
 
+    protected QueryWriter queryWriter = new QueryWriter();
+
     public EntryReader<? extends ObjectEntry> getObjectEntryReader() {
         return objectReader;
     }
@@ -75,7 +78,7 @@
     }
 
     public XmlObjectWriter<String> getQueryWriter() {
-        throw new UnsupportedOperationException("Not yet implemented");
+        return queryWriter;
     }
 
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientConnector.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientConnector.java?rev=785746&r1=785745&r2=785746&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientConnector.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientConnector.java
Wed Jun 17 18:15:04 2009
@@ -121,7 +121,9 @@
             PostMethod method = new PostMethod(request.getUrl());
             setMethodParams(method, request);
             setMethodHeaders(method, request);
-            method.setRequestEntity(new ObjectRequestEntity<T>(writer, object));
+            method.setRequestEntity(new XmlObjectWriterRequestEntity<T>(writer,
+                    object));
+            method.setContentChunked(true);
             client.executeMethod(method);
             return new HttpClientResponse(method, io);
         } catch (Exception e) {
@@ -135,7 +137,8 @@
             PutMethod method = new PutMethod(request.getUrl());
             setMethodParams(method, request);
             setMethodHeaders(method, request);
-            method.setRequestEntity(new ObjectRequestEntity<T>(writer, object));
+            method.setRequestEntity(new XmlObjectWriterRequestEntity<T>(writer,
+                    object));
             client.executeMethod(method);
             return new HttpClientResponse(method, io);
         } catch (Exception e) {
@@ -221,13 +224,14 @@
         return post(req, io.getQueryWriter(), query);
     }
 
-    public static class ObjectRequestEntity<T> implements RequestEntity {
+    public static class XmlObjectWriterRequestEntity<T> implements
+            RequestEntity {
 
         protected XmlObjectWriter<T> writer;
 
         protected T obj;
 
-        public ObjectRequestEntity(XmlObjectWriter<T> writer, T obj) {
+        public XmlObjectWriterRequestEntity(XmlObjectWriter<T> writer, T obj) {
             this.writer = writer;
             this.obj = obj;
         }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java?rev=785746&r1=785745&r2=785746&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java
Wed Jun 17 18:15:04 2009
@@ -119,6 +119,11 @@
             T object, XmlProperty p, Type entryType) {
         PropertyDefinition def = entryType.getPropertyDefinition(p.getName());
         if (def == null) {
+            if (p.getName().equals("ContentStreamURI")) {
+                // ignore, old Alfresco compat
+                // see org.apache.chemistry.atompub.abdera.PropertiesElement
+                return;
+            }
             throw new ParseException("No such property definition: "
                     + p.getName() + " in type: " + entryType);
         }

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/QueryWriter.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/QueryWriter.java?rev=785746&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/QueryWriter.java
(added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/QueryWriter.java
Wed Jun 17 18:15:04 2009
@@ -0,0 +1,47 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Authors:
+ *     Florent Guillaume, Nuxeo
+ */
+package org.apache.chemistry.atompub.client.stax;
+
+import java.io.IOException;
+
+import org.apache.chemistry.atompub.CMIS;
+import org.apache.chemistry.xml.stax.XMLWriter;
+
+/**
+ * Writer for the body of a CMIS query.
+ */
+public class QueryWriter extends AbstractXmlObjectWriter<String> {
+
+    @Override
+    public String getContentType() {
+        return "application/cmisquery+xml";
+    }
+
+    @Override
+    public void write(String statement, XMLWriter xw) throws IOException {
+        xw.start().putXmlns(CMIS.CMIS_PREFIX, CMIS.CMIS_NS);
+        xw.element(CMIS.QUERY);
+        xw.start();
+        xw.element(CMIS.STATEMENT).econtent(statement);
+        xw.element(CMIS.SEARCH_ALL_VERSIONS).content("false");
+        xw.element(CMIS.PAGE_SIZE).content("0");
+        xw.element(CMIS.SKIP_COUNT).content("0");
+        xw.end();
+        xw.end();
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/QueryWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/QueryWriter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/QueryWriter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java?rev=785746&r1=785745&r2=785746&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
Wed Jun 17 18:15:04 2009
@@ -84,10 +84,6 @@
         return "urn:x-children:" + id;
     }
 
-    public String getTitle(RequestContext request) {
-        return "Children";
-    }
-
     @Override
     public String getAuthor(RequestContext request) {
         return "system";
@@ -105,6 +101,14 @@
     }
 
     /*
+     * ----- CollectionInfo -----
+     */
+
+    public String getTitle(RequestContext request) {
+        return name + " collection";
+    }
+
+    /*
      * ----- AbstractEntityCollectionAdapter -----
      */
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java?rev=785746&r1=785745&r2=785746&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java
Wed Jun 17 18:15:04 2009
@@ -80,8 +80,8 @@
                 "{target_base}/{collection}{-prefix|/|id}");
         targetResolver.setPattern("/checkedout", TargetType.TYPE_COLLECTION);
         targetResolver.setPattern("/unfiled", TargetType.TYPE_COLLECTION);
-        targetResolver.setPattern("/query", //
-                TargetType.TYPE_COLLECTION);
+        targetResolver.setPattern("/query",
+                CMISQueryFeed.TARGET_TYPE_CMIS_QUERY);
         targetResolver.setPattern("/types(\\?.*)?", //
                 TargetType.TYPE_COLLECTION);
         // per-object collections
@@ -127,8 +127,7 @@
         ci = new CMISTypesCollection(CMIS.COL_TYPES_DESCENDANTS, repository);
         workspaceInfo.addCollection(ci);
 
-        workspaceInfo.addCollection(new CMISCollectionForOther(CMIS.COL_QUERY,
-                "query", null, repository));
+        workspaceInfo.addCollection(new CMISQueryFeed(repository));
 
         workspaceManager = new CMISWorkspaceManager(this);
         workspaceManager.addWorkspace(workspaceInfo);

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISQueryFeed.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISQueryFeed.java?rev=785746&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISQueryFeed.java
(added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISQueryFeed.java
Wed Jun 17 18:15:04 2009
@@ -0,0 +1,108 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Authors:
+ *     Florent Guillaume, Nuxeo
+ */
+package org.apache.chemistry.atompub.server;
+
+import java.util.Collection;
+
+import org.apache.abdera.model.Element;
+import org.apache.abdera.protocol.server.ProviderHelper;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.ResponseContext;
+import org.apache.abdera.protocol.server.TargetType;
+import org.apache.abdera.protocol.server.context.ResponseContextException;
+import org.apache.axiom.om.OMDocument;
+import org.apache.chemistry.ObjectEntry;
+import org.apache.chemistry.Repository;
+import org.apache.chemistry.SPI;
+import org.apache.chemistry.atompub.CMIS;
+import org.apache.chemistry.atompub.abdera.QueryElement;
+
+/**
+ * CMIS Feed for a query.
+ */
+public class CMISQueryFeed extends CMISObjectsCollection {
+
+    public static final TargetType TARGET_TYPE_CMIS_QUERY = TargetType.get(
+            "CMISQUERY", true);
+
+    protected String statement;
+
+    public CMISQueryFeed(Repository repository) {
+        super(CMIS.COL_QUERY, "query", null, repository);
+    }
+
+    /*
+     * ----- AbstractCollectionAdapter -----
+     */
+
+    @Override
+    public String getId(RequestContext request) {
+        return "urn:id:1234collid";
+    }
+
+    // called by AbstractProvider.process if unknown TargetType
+    @Override
+    public ResponseContext extensionRequest(RequestContext request) {
+        if (request.getTarget().getType() != TARGET_TYPE_CMIS_QUERY) {
+            return ProviderHelper.notsupported(request);
+        }
+        if (request.getMethod().equalsIgnoreCase("POST")) {
+            return postEntry(request);
+        } else {
+            // stupid signature prevents use of varargs...
+            return ProviderHelper.notallowed(request, new String[] { "POST" });
+        }
+    }
+
+    /*
+     * ----- AbstractEntityCollectionAdapter -----
+     */
+
+    @Override
+    public ResponseContext postEntry(RequestContext request) {
+        OMDocument document;
+        try {
+            document = (OMDocument) request.getDocument(request.getAbdera().getParser());
+        } catch (Exception e) {
+            return createErrorResponse(new ResponseContextException(500, e));
+        }
+        if (document == null) {
+            return null;
+        }
+        Element element = (Element) document.getOMDocumentElement();
+        QueryElement q = new QueryElement(element);
+        statement = q.getStatement();
+        return getFeed(request); // calls getEntries
+    }
+
+    @Override
+    public Iterable<ObjectEntry> getEntries(RequestContext request)
+            throws ResponseContextException {
+        SPI spi = repository.getSPI(); // TODO XXX connection leak
+        boolean searchAllVersions = false;
+        boolean includeAllowableActions = false;
+        boolean includeRelationships = false;
+        int maxItems = 0;
+        int skipCount = 0;
+        boolean[] hasMoreItems = new boolean[1];
+        Collection<ObjectEntry> results = spi.query(statement,
+                searchAllVersions, includeAllowableActions,
+                includeRelationships, maxItems, skipCount, hasMoreItems);
+        return results;
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISQueryFeed.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISQueryFeed.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java?rev=785746&r1=785745&r2=785746&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java
Wed Jun 17 18:15:04 2009
@@ -58,6 +58,9 @@
         if (paths.startsWith("/unfiled/")) {
             return new CMISCollectionForOther(null, "unfiled", null, repository);
         }
+        if (paths.startsWith("/query/")) {
+            return new CMISQueryFeed(repository);
+        }
         return null;
     }
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/CMIS.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/CMIS.java?rev=785746&r1=785745&r2=785746&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/CMIS.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/CMIS.java
Wed Jun 17 18:15:04 2009
@@ -173,6 +173,16 @@
 
     public static final QName ALLOWABLE_ACTIONS = CMISName("allowableActions");
 
+    public static final QName QUERY = CMISName("query");
+
+    public static final QName STATEMENT = CMISName("statement");
+
+    public static final QName SEARCH_ALL_VERSIONS = CMISName("searchAllVersions");
+
+    public static final QName PAGE_SIZE = CMISName("pageSize");
+
+    public static final QName SKIP_COUNT = CMISName("skipCount");
+
     /*
      * ----- CMIS Collection Types -----
      */

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/QueryElement.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/QueryElement.java?rev=785746&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/QueryElement.java
(added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/QueryElement.java
Wed Jun 17 18:15:04 2009
@@ -0,0 +1,68 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Authors:
+ *     Florent Guillaume, Nuxeo
+ */
+package org.apache.chemistry.atompub.abdera;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.ElementWrapper;
+import org.apache.abdera.model.ExtensibleElementWrapper;
+import org.apache.abdera.parser.stax.FOMElement;
+import org.apache.axiom.om.OMElement;
+import org.apache.chemistry.atompub.CMIS;
+
+/**
+ * Element wrapping for a CMIS query.
+ */
+public class QueryElement extends ExtensibleElementWrapper {
+
+    /**
+     * Constructor used when parsing XML.
+     */
+    public QueryElement(Element internal) {
+        super(internal);
+    }
+
+    /**
+     * Constructor used when generating XML.
+     */
+    public QueryElement(Factory factory) {
+        super(factory, CMIS.QUERY);
+    }
+
+    protected String getChildElementText(QName name) {
+        OMElement child = ((FOMElement) getInternal()).getFirstChildWithName(name);
+        return child == null ? null : child.getText();
+    }
+
+    public String getStatement() {
+        return getChildElementText(CMIS.STATEMENT);
+    }
+
+    public void setStatement(String statement) {
+        addExtension(new StatementElement(getFactory(), statement));
+    }
+
+    protected static class StatementElement extends ElementWrapper {
+        public StatementElement(Factory factory, String statement) {
+            super(factory, CMIS.STATEMENT);
+            setText(statement);
+        }
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/QueryElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/QueryElement.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java?rev=785746&r1=785745&r2=785746&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
Wed Jun 17 18:15:04 2009
@@ -28,6 +28,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.chemistry.BaseType;
 import org.apache.chemistry.CMISObject;
@@ -245,13 +247,20 @@
             String orderBy, boolean[] hasMoreItems) {
         // TODO type and orderBy
         Set<String> ids = repository.children.get(folder.getId());
-        int total = ids.size();
-        List<ObjectEntry> all = new ArrayList<ObjectEntry>(total);
+        List<ObjectEntry> all = new ArrayList<ObjectEntry>(ids.size());
         for (String id : ids) {
             SimpleData data = repository.datas.get(id);
             all.add(new SimpleObjectEntry(data, this));
         }
+        return subList(all, maxItems, skipCount, hasMoreItems);
+    }
 
+    /**
+     * Extracts part of a list according to given parameters.
+     */
+    protected static List<ObjectEntry> subList(List<ObjectEntry> all,
+            int maxItems, int skipCount, boolean[] hasMoreItems) {
+        int total = all.size();
         int fromIndex = skipCount;
         if (fromIndex < 0 || fromIndex > total) {
             hasMoreItems[0] = false;
@@ -492,14 +501,43 @@
             boolean searchAllVersions, boolean includeAllowableActions,
             boolean includeRelationships, int maxItems, int skipCount,
             boolean[] hasMoreItems) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+
+        // TODO temporary implementation for unit testing of protocols
+
+        Matcher m = Pattern.compile("SELECT\\s+([*\\w, ]+)\\s+FROM\\s+(\\w+)",
+                Pattern.CASE_INSENSITIVE).matcher(statement);
+        if (!m.matches()) {
+            throw new RuntimeException("Cannot parse query: " + statement);
+        }
+        String props = m.group(1);
+        if (!"*".equals(props)) {
+            throw new RuntimeException(
+                    "Invalid query, must select all properties: " + statement);
+        }
+        String type = m.group(2);
+
+        List<ObjectEntry> all = new ArrayList<ObjectEntry>();
+        for (SimpleData data : repository.datas.values()) {
+            // TODO type inheritance not taken into account
+            String t = (String) data.get(SimpleProperty.TYPE_ID);
+            if (!t.equalsIgnoreCase(type)) {
+                continue;
+            }
+            all.add(new SimpleObjectEntry(data, this));
+        }
+        return subList(all, maxItems, skipCount, hasMoreItems);
     }
 
     public Collection<CMISObject> query(String statement,
             boolean searchAllVersions) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+        boolean[] hasMoreItems = new boolean[1];
+        Collection<ObjectEntry> res = query(statement, searchAllVersions,
+                false, false, 0, 0, hasMoreItems);
+        List<CMISObject> objects = new ArrayList<CMISObject>(res.size());
+        for (ObjectEntry e : res) {
+            objects.add(SimpleObject.construct((SimpleObjectEntry) e));
+        }
+        return objects;
     }
 
     /*

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleType.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleType.java?rev=785746&r1=785745&r2=785746&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleType.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleType.java
Wed Jun 17 18:15:04 2009
@@ -318,7 +318,7 @@
         }
     }
 
-    protected static List<PropertyDefinition> getBasePropertyDefinitions(
+    public static List<PropertyDefinition> getBasePropertyDefinitions(
             BaseType baseType) {
         switch (baseType) {
         case DOCUMENT:

Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java?rev=785746&r1=785745&r2=785746&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
Wed Jun 17 18:15:04 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.chemistry.test;
 
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
@@ -58,4 +59,13 @@
         assertEquals(1, entries.size());
     }
 
+    public void testQuery() {
+        Connection conn = repository.getConnection(null);
+        Collection<CMISObject> res = conn.query("SELECT * FROM doc", false);
+        assertNotNull(res);
+        assertEquals(4, res.size());
+        res = conn.query("SELECT * FROM fold", false);
+        assertEquals(2, res.size());
+    }
+
 }



Mime
View raw message