Author: fmui
Date: Thu Aug 14 14:36:45 2014
New Revision: 1617958
URL: http://svn.apache.org/r1617958
Log:
CMIS-835: AtomPub server: fixed "up" links in folder entries
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AbstractAtomPubServiceCall.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/NavigationService.java
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AbstractAtomPubServiceCall.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AbstractAtomPubServiceCall.java?rev=1617958&r1=1617957&r2=1617958&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AbstractAtomPubServiceCall.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AbstractAtomPubServiceCall.java
Thu Aug 14 14:36:45 2014
@@ -59,6 +59,7 @@ public abstract class AbstractAtomPubSer
public static final String RESOURCE_TYPES = "types";
public static final String RESOURCE_TYPESDESC = "typedesc";
public static final String RESOURCE_ENTRY = "entry";
+ public static final String RESOURCE_PARENT = "parent";
public static final String RESOURCE_PARENTS = "parents";
public static final String RESOURCE_VERSIONS = "versions";
public static final String RESOURCE_ALLOWABLEACIONS = "allowableactions";
@@ -188,7 +189,11 @@ public abstract class AbstractAtomPubSer
entry.writeAllowableActionsLink(compileUrl(baseUrl,
RESOURCE_ALLOWABLEACIONS, info.getId()));
if (info.hasParent()) {
- entry.writeUpLink(compileUrl(baseUrl, RESOURCE_PARENTS,
info.getId()), Constants.MEDIATYPE_FEED);
+ if (info.getBaseType() == BaseTypeId.CMIS_FOLDER) {
+ entry.writeUpLink(compileUrl(baseUrl, RESOURCE_PARENT,
info.getId()), Constants.MEDIATYPE_ENTRY);
+ } else {
+ entry.writeUpLink(compileUrl(baseUrl, RESOURCE_PARENTS,
info.getId()), Constants.MEDIATYPE_FEED);
+ }
}
if (info.getBaseType() == BaseTypeId.CMIS_FOLDER) {
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java?rev=1617958&r1=1617957&r2=1617958&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
Thu Aug 14 14:36:45 2014
@@ -450,7 +450,6 @@ public final class AtomEntryParser {
*/
private ThresholdOutputStream readBase64(XMLStreamReader parser) throws
XMLStreamException, IOException {
ThresholdOutputStream bufferStream = streamFactory.newOutputStream();
- @SuppressWarnings("resource")
Base64.OutputStream b64stream = new Base64.OutputStream(bufferStream,
Base64.DECODE);
XMLUtils.next(parser);
@@ -472,6 +471,8 @@ public final class AtomEntryParser {
cappedStream.deductBytes(len);
}
} else if (event == XMLStreamReader.START_ELEMENT) {
+ b64stream.close();
+ bufferStream.destroy();
throw new CmisInvalidArgumentException("Unexpected tag: "
+ parser.getName());
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java?rev=1617958&r1=1617957&r2=1617958&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
Thu Aug 14 14:36:45 2014
@@ -30,6 +30,7 @@ import static org.apache.chemistry.openc
import static
org.apache.chemistry.opencmis.server.impl.atompub.AbstractAtomPubServiceCall.RESOURCE_FOLDERTREE;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AbstractAtomPubServiceCall.RESOURCE_OBJECTBYID;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AbstractAtomPubServiceCall.RESOURCE_OBJECTBYPATH;
+import static
org.apache.chemistry.opencmis.server.impl.atompub.AbstractAtomPubServiceCall.RESOURCE_PARENT;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AbstractAtomPubServiceCall.RESOURCE_PARENTS;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AbstractAtomPubServiceCall.RESOURCE_POLICIES;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AbstractAtomPubServiceCall.RESOURCE_QUERY;
@@ -128,6 +129,7 @@ public class CmisAtomPubServlet extends
addResource(RESOURCE_CHILDREN, METHOD_GET, new
NavigationService.GetChildren());
addResource(RESOURCE_DESCENDANTS, METHOD_GET, new
NavigationService.GetDescendants());
addResource(RESOURCE_FOLDERTREE, METHOD_GET, new
NavigationService.GetFolderTree());
+ addResource(RESOURCE_PARENT, METHOD_GET, new
NavigationService.GetFolderParent());
addResource(RESOURCE_PARENTS, METHOD_GET, new
NavigationService.GetObjectParents());
addResource(RESOURCE_CHECKEDOUT, METHOD_GET, new
NavigationService.GetCheckedOutDocs());
addResource(RESOURCE_ENTRY, METHOD_GET, new ObjectService.GetObject());
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/NavigationService.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/NavigationService.java?rev=1617958&r1=1617957&r2=1617958&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/NavigationService.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/NavigationService.java
Thu Aug 14 14:36:45 2014
@@ -398,6 +398,57 @@ public class NavigationService {
/**
* Object parents feed GET.
*/
+ public static class GetFolderParent extends AbstractAtomPubServiceCall {
+ public void serve(CallContext context, CmisService service, String
repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ assert context != null;
+ assert service != null;
+ assert repositoryId != null;
+ assert request != null;
+ assert response != null;
+
+ // get parameters
+ String folderId = getStringParameter(request, Constants.PARAM_ID);
+ String filter = getStringParameter(request,
Constants.PARAM_FILTER);
+
+ // execute
+ if (stopBeforeService(service)) {
+ return;
+ }
+
+ ObjectData object = service.getFolderParent(repositoryId,
folderId, filter, null);
+
+ if (stopAfterService(service)) {
+ return;
+ }
+
+ if (object == null) {
+ throw new CmisRuntimeException("Object is null!");
+ }
+
+ ObjectInfo objectInfo = service.getObjectInfo(repositoryId,
folderId);
+ if (objectInfo == null) {
+ throw new CmisRuntimeException("Object Info is missing!");
+ }
+
+ // set headers
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.setContentType(Constants.MEDIATYPE_ENTRY);
+
+ // write XML
+ UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+ AtomEntry entry = new AtomEntry();
+ entry.startDocument(response.getOutputStream(),
getNamespaces(service));
+ writeObjectEntry(service, entry, object, null, repositoryId, null,
null, baseUrl, true,
+ context.getCmisVersion());
+ entry.endDocument();
+ }
+ }
+
+ /**
+ * Object parents feed GET.
+ */
public static class GetObjectParents extends AbstractAtomPubServiceCall {
public void serve(CallContext context, CmisService service, String
repositoryId, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java?rev=1617958&r1=1617957&r2=1617958&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
Thu Aug 14 14:36:45 2014
@@ -18,8 +18,8 @@
*/
package org.apache.chemistry.opencmis.tck.impl;
-import static org.apache.chemistry.opencmis.commons.impl.CollectionsHelper.*;
-
+import static
org.apache.chemistry.opencmis.commons.impl.CollectionsHelper.isNotEmpty;
+import static
org.apache.chemistry.opencmis.commons.impl.CollectionsHelper.isNullOrEmpty;
import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.INFO;
import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.OK;
@@ -1976,6 +1976,33 @@ public abstract class AbstractSessionTes
f = createResult(FAILURE, "Child has no parents! Id: " +
child.getId());
addResult(results, assertListNotEmpty(parents, null, f));
+ if (child instanceof Folder) {
+ f = createResult(FAILURE,
+ "Child is a folder and has more than one
parent! Id: " + child.getId());
+ addResult(results, assertIsFalse(parents.size() > 1,
null, f));
+
+ Folder folderParent = ((Folder)
child).getFolderParent();
+ if (folderParent == null) {
+ addResult(
+ results,
+ createResult(
+ FAILURE,
+ "getFolderParent() returns null
for a non-root folder object! Id: "
+ + child.getId()));
+ } else {
+ f = createResult(FAILURE,
+ "getFolderParent() returns wrong parent
object! Id: " + child.getId());
+ addResult(results, assertEquals(folder.getId(),
folderParent.getId(), null, f));
+
+ if (parents.size() > 0 && parents.get(0) != null) {
+ f = createResult(FAILURE,
+ "getFolderParent() and getParents()
return different parents for a folder object! Id: "
+ + child.getId());
+ addResult(results,
assertEquals(parents.get(0).getId(), folderParent.getId(), null, f));
+ }
+ }
+ }
+
boolean foundParent = false;
for (Folder parent : parents) {
if (parent == null) {
@@ -1988,10 +2015,11 @@ public abstract class AbstractSessionTes
}
if (!foundParent) {
- f = createResult(FAILURE, "Folder is not found in
childs parents! Id: " + child.getId());
- addResult(results, assertListNotEmpty(parents, null,
f));
+ addResult(
+ results,
+ createResult(FAILURE,
+ "Parent folder is not in parents of
the child! Id: " + child.getId()));
}
-
}
// get object by id and compare