You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fg...@apache.org on 2010/01/15 17:54:21 UTC
svn commit: r899710 - in /incubator/chemistry/trunk/chemistry:
chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/
chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/
chemistry-atompub/src/main/java/org/a...
Author: fguillaume
Date: Fri Jan 15 16:54:20 2010
New Revision: 899710
URL: http://svn.apache.org/viewvc?rev=899710&view=rev
Log:
Implement move for Simple and AtomPub client and server
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/APPObject.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.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/SimpleObject.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=899710&r1=899709&r2=899710&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 Fri Jan 15 16:54:20 2010
@@ -679,8 +679,37 @@
public ObjectId moveObject(ObjectId object, ObjectId targetFolder,
ObjectId sourceFolder) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ APPObjectEntry entry = getObjectEntry(object);
+ Request req = new Request(getPostHref(targetFolder));
+ req.setHeader("Content-Type", AtomPub.MEDIA_TYPE_ATOM_ENTRY);
+ req.setParameter(AtomPubCMIS.PARAM_SOURCE_FOLDER_ID,
+ sourceFolder == null ? "" : sourceFolder.getId());
+ Response resp = connector.postObject(req, entry);
+ if (resp.getStatusCode() != 201) { // Created
+ throw new ContentManagerException(
+ "Remote server returned error code: "
+ + resp.getStatusCode());
+ }
+ ReadContext ctx = new ReadContext(this);
+ APPObjectEntry newEntry = (APPObjectEntry) resp.getObject(ctx);
+ // newEntry SHOULD be returned (AtomPub 9.2)...
+ String loc = resp.getHeader("Location");
+ if (loc == null) {
+ throw new ContentManagerException(
+ "Remote server failed to return a Location header");
+ }
+ if (newEntry == null || !loc.equals(resp.getHeader("Content-Location"))) {
+ // (Content-Location defined by AtomPub 9.2)
+ // fetch actual new entry from Location header
+ // TODO could fetch only a subset of the properties, if deemed ok
+ newEntry = (APPObjectEntry) connector.getObject(ctx, loc);
+ if (newEntry == null) {
+ throw new ContentManagerException(
+ "Remote server failed to return an entry for Location: "
+ + loc);
+ }
+ }
+ return newEntry;
}
public void deleteObject(ObjectId object, boolean allVersions) {
Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java?rev=899710&r1=899709&r2=899710&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java Fri Jan 15 16:54:20 2010
@@ -88,23 +88,15 @@
*/
public void move(Folder targetFolder, Folder sourceFolder) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ entry.connection.moveObject(entry, targetFolder, sourceFolder);
}
public void delete() {
- Request req = new Request(entry.getEditLink());
- Response resp = entry.connection.getConnector().delete(req);
- if (!resp.isOk()) {
- throw new ContentManagerException(
- "Remote server returned error code: "
- + resp.getStatusCode());
- }
+ entry.connection.deleteObject(entry, false);
}
public void unfile() {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ entry.connection.removeObjectFromFolder(entry, null);
}
public ContentStream getContentStream(String contentStreamId)
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=899710&r1=899709&r2=899710&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 Fri Jan 15 16:54:20 2010
@@ -480,35 +480,50 @@
@Override
public ResponseContext postEntry(RequestContext request) {
- // TODO parameter sourceFolderId
// TODO parameter versioningState
SPI spi = repository.getSPI();
try {
PropertiesAndStream posted = extractCMISProperties(request, null);
-
ObjectId folderId = spi.newObjectId(id);
+ String sourceFolderId = request.getTarget().getParameter(
+ AtomPubCMIS.PARAM_SOURCE_FOLDER_ID);
+ boolean isMove = sourceFolderId != null;
ObjectId objectId;
- String typeId = (String) posted.properties.get(Property.TYPE_ID);
- BaseType baseType = repository.getType(typeId).getBaseType();
- switch (baseType) {
- case DOCUMENT:
- String filename = (String) posted.properties.get(Property.CONTENT_STREAM_FILE_NAME);
- if (filename == null) {
- filename = (String) posted.properties.get(Property.NAME);
+ if (isMove) {
+ if ("null".equals(sourceFolderId) || "".equals(sourceFolderId)) {
+ sourceFolderId = null;
+ }
+ String oid = (String) posted.properties.get(Property.ID);
+ if (oid == null) {
+ throw new ResponseContextException("Missing id", 400);
+ }
+ objectId = spi.newObjectId(oid);
+ ObjectId sourceFolder = sourceFolderId == null ? null
+ : spi.newObjectId(sourceFolderId);
+ objectId = spi.moveObject(objectId, folderId, sourceFolder);
+ } else {
+ String typeId = (String) posted.properties.get(Property.TYPE_ID);
+ BaseType baseType = repository.getType(typeId).getBaseType();
+ switch (baseType) {
+ case DOCUMENT:
+ String filename = (String) posted.properties.get(Property.CONTENT_STREAM_FILE_NAME);
+ if (filename == null) {
+ filename = (String) posted.properties.get(Property.NAME);
+ }
+ ContentStream contentStream = posted.stream == null ? null
+ : new SimpleContentStream(posted.stream,
+ posted.mimeType, filename);
+ VersioningState versioningState = null; // TODO
+ objectId = spi.createDocument(posted.properties, folderId,
+ contentStream, versioningState);
+ break;
+ case FOLDER:
+ objectId = spi.createFolder(posted.properties, folderId);
+ break;
+ default:
+ throw new UnsupportedOperationException("not implemented: "
+ + baseType);
}
- ContentStream contentStream = posted.stream == null ? null
- : new SimpleContentStream(posted.stream,
- posted.mimeType, filename);
- VersioningState versioningState = null; // TODO
- objectId = spi.createDocument(posted.properties, folderId,
- contentStream, versioningState);
- break;
- case FOLDER:
- objectId = spi.createFolder(posted.properties, folderId);
- break;
- default:
- throw new UnsupportedOperationException("not implemented: "
- + baseType);
}
// prepare the updated entry to return in the response
@@ -526,6 +541,8 @@
return buildCreateEntryResponse(link, entry);
} catch (ResponseContextException e) {
return createErrorResponse(e);
+ } catch (ConstraintViolationException e) {
+ return createErrorResponse(new ResponseContextException(400, e));
} catch (CMISRuntimeException e) {
return createErrorResponse(new ResponseContextException(500, e));
} catch (Exception e) {
Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java?rev=899710&r1=899709&r2=899710&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java Fri Jan 15 16:54:20 2010
@@ -156,6 +156,8 @@
public static final String PARAM_UNFILE_OBJECTS = "unfileObjects";
+ public static final String PARAM_SOURCE_FOLDER_ID = "sourceFolderId";
+
/*
* ----- URI Template Types -----
*/
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=899710&r1=899709&r2=899710&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 Fri Jan 15 16:54:20 2010
@@ -219,7 +219,6 @@
if (baseTypeId != BaseType.FOLDER.getId()) {
throw new IllegalArgumentException("Not a folder: " + id);
}
-
}
public ObjectEntry getFolderParent(ObjectId folder, String filter) {
@@ -239,8 +238,8 @@
return null;
}
if (parents.size() > 1) {
- throw new AssertionError(folder + " has " + parents.size()
- + " parents");
+ throw new ConstraintViolationException(folder + " has "
+ + parents.size() + " parents");
}
String parentId = parents.iterator().next();
return new SimpleObjectEntry(repository.datas.get(parentId), this);
@@ -616,15 +615,49 @@
public ObjectId moveObject(ObjectId object, ObjectId targetFolder,
ObjectId sourceFolder) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ String id = object.getId();
+ if (repository.rootId.equals(id)) {
+ throw new IllegalArgumentException("Cannot move root");
+ }
+ SimpleData data = repository.datas.get(id);
+ if (data == null) {
+ throw new ObjectNotFoundException(object.getId());
+ }
+ checkFolder(targetFolder);
+ Set<String> parents = repository.parents.get(id);
+ String sourceFolderId;
+ if (sourceFolder == null) {
+ if (parents.size() > 1) {
+ throw new ConstraintViolationException("Object "
+ + object.getId() + " has " + parents.size()
+ + " parents");
+ } else if (!parents.isEmpty()) {
+ sourceFolderId = parents.iterator().next();
+ } else {
+ sourceFolderId = null;
+ }
+ } else {
+ sourceFolderId = sourceFolder.getId();
+ if (!parents.contains(sourceFolderId)) {
+ throw new ConstraintViolationException("Object " + id
+ + " is not filed in " + sourceFolderId);
+ }
+ }
+ if (sourceFolderId != null) {
+ parents.remove(sourceFolderId);
+ repository.children.get(sourceFolderId).remove(id);
+ }
+ String targetFolderId = targetFolder.getId();
+ parents.add(targetFolderId);
+ repository.children.get(targetFolderId).add(id);
+ return object;
}
public void deleteObject(ObjectId object, boolean allVersions) {
// TODO allVersions
String id = object.getId();
if (repository.rootId.equals(id)) {
- throw new ConstraintViolationException("Cannot delete root");
+ throw new IllegalArgumentException("Cannot delete root");
}
SimpleData data = repository.datas.get(id);
if (data == null) {
@@ -659,7 +692,7 @@
boolean allVersions = false; // TODO add in signature?
String id = folder.getId();
if (repository.rootId.equals(id)) {
- throw new ConstraintViolationException("Cannot delete root");
+ throw new IllegalArgumentException("Cannot delete root");
}
SimpleData data = repository.datas.get(id);
if (data == null) {
Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java?rev=899710&r1=899709&r2=899710&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java Fri Jan 15 16:54:20 2010
@@ -17,7 +17,9 @@
package org.apache.chemistry.impl.simple;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -25,6 +27,7 @@
import org.apache.chemistry.CMISObject;
import org.apache.chemistry.ContentStream;
import org.apache.chemistry.Folder;
+import org.apache.chemistry.NameConstraintViolationException;
import org.apache.chemistry.Policy;
import org.apache.chemistry.Property;
import org.apache.chemistry.PropertyDefinition;
@@ -65,9 +68,9 @@
}
}
- public void move(Folder targetFolder, Folder sourceFolder) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ public void move(Folder targetFolder, Folder sourceFolder)
+ throws NameConstraintViolationException, UpdateConflictException {
+ entry.connection.getSPI().moveObject(this, targetFolder, sourceFolder);
}
public void delete() throws UpdateConflictException {
@@ -94,8 +97,17 @@
}
public Collection<Folder> getParents() {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ SimpleConnection connection = (SimpleConnection) entry.connection;
+ Set<String> parents = connection.repository.parents.get(getId());
+ if (parents == SimpleRepository.NO_PARENT) {
+ return Collections.emptyList();
+ }
+ List<Folder> list = new ArrayList<Folder>(parents.size());
+ for (String pid : parents) {
+ SimpleData data = connection.repository.datas.get(pid);
+ list.add(new SimpleFolder(new SimpleObjectEntry(data, connection)));
+ }
+ return list;
}
public List<Relationship> getRelationships(RelationshipDirection direction,
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=899710&r1=899709&r2=899710&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 Fri Jan 15 16:54:20 2010
@@ -374,7 +374,6 @@
}
}
-
public void testTrees() throws Exception {
List<ObjectEntry> list;
@@ -401,7 +400,6 @@
assertEquals(5, list.size());
}
-
public void testGetFolderParent() {
Folder root = conn.getRootFolder();
assertNull(spi.getFolderParent(root, null));
@@ -642,4 +640,30 @@
doc.save();
}
+ public void testMoveSPI() throws Exception {
+ ObjectEntry fold = spi.getObjectByPath("/folder 1", null);
+ ObjectEntry doc = spi.getObjectByPath("/folder 1/folder 2/doc 3", null);
+ ObjectId res = spi.moveObject(doc, fold, null);
+ assertEquals(doc.getId(), res.getId());
+ doc = spi.getObjectByPath("/folder 1/folder 2/doc 3", null);
+ assertNull(doc);
+ doc = spi.getObjectByPath("/folder 1/doc 3", null);
+ assertNotNull(doc);
+ }
+
+ public void testMove() throws Exception {
+ ObjectEntry foldid = spi.getObjectByPath("/folder 1", null);
+ Folder fold = (Folder) conn.getObject(foldid);
+
+ ObjectEntry docid = spi.getObjectByPath("/folder 1/folder 2/doc 3",
+ null);
+ Document doc = (Document) conn.getObject(docid);
+ doc.move(fold, null);
+ assertEquals(docid.getId(), doc.getId());
+ ObjectEntry d = spi.getObjectByPath("/folder 1/folder 2/doc 3", null);
+ assertNull(d);
+ d = spi.getObjectByPath("/folder 1/doc 3", null);
+ assertNotNull(d);
+ }
+
}