Author: fmui
Date: Fri Mar 15 15:45:45 2013
New Revision: 1456994
URL: http://svn.apache.org/r1456994
Log:
CMIS 1.1 AtomPub: added bulk update properties support (untested)
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/Constants.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/BukUpdateConverterTest.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/AtomPubUtils.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/ObjectService.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java?rev=1456994&r1=1456993&r2=1456994&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java
Fri Mar 15 15:45:45 2013
@@ -47,6 +47,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.impl.XMLConstants;
import org.apache.chemistry.opencmis.commons.impl.XMLConverter;
import org.apache.chemistry.opencmis.commons.impl.XMLUtils;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.BulkUpdateImpl;
/**
* Writes a CMIS Atom entry to an output stream.
@@ -60,6 +61,7 @@ public class AtomEntryWriter {
private final ContentStream contentStream;
private final InputStream stream;
private final TypeDefinition typeDef;
+ private final BulkUpdateImpl bulkUpdate;
/**
* Constructor for objects.
@@ -96,6 +98,7 @@ public class AtomEntryWriter {
stream = null;
}
this.typeDef = null;
+ this.bulkUpdate = null;
}
/**
@@ -111,6 +114,23 @@ public class AtomEntryWriter {
this.object = null;
this.contentStream = null;
this.stream = null;
+ this.bulkUpdate = null;
+ }
+
+ /**
+ * Constructor for bulk updates.
+ */
+ public AtomEntryWriter(BulkUpdateImpl bulkUpdate) {
+ if (bulkUpdate == null) {
+ throw new CmisInvalidArgumentException("Bulk update data must not
be null!");
+ }
+
+ this.bulkUpdate = bulkUpdate;
+ this.typeDef = null;
+ this.cmisVersion = CmisVersion.CMIS_1_1;
+ this.object = null;
+ this.contentStream = null;
+ this.stream = null;
}
/**
@@ -170,6 +190,11 @@ public class AtomEntryWriter {
XMLConverter.writeTypeDefinition(writer, cmisVersion,
XMLConstants.NAMESPACE_RESTATOM, typeDef);
}
+ // bulk update
+ if (bulkUpdate != null) {
+ XMLConverter.writeBulkUpdate(writer,
XMLConstants.NAMESPACE_RESTATOM, bulkUpdate);
+ }
+
// end entry
writer.writeEndElement();
@@ -195,6 +220,10 @@ public class AtomEntryWriter {
}
}
+ if (bulkUpdate != null) {
+ result = "Bulk Update Properties";
+ }
+
return result;
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java?rev=1456994&r1=1456993&r2=1456994&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java
Fri Mar 15 15:45:45 2013
@@ -59,6 +59,8 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.impl.MimeHelper;
import org.apache.chemistry.opencmis.commons.impl.ReturnVersion;
import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.BulkUpdateImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.BulkUpdateObjectIdAndChangeTokenImpl;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.FailedToDeleteDataImpl;
import org.apache.chemistry.opencmis.commons.spi.Holder;
@@ -375,7 +377,60 @@ public class ObjectServiceImpl extends A
public List<BulkUpdateObjectIdAndChangeToken> bulkUpdateProperties(String
repositoryId,
List<BulkUpdateObjectIdAndChangeToken> objectIdAndChangeToken,
Properties properties,
List<String> addSecondaryTypeIds, List<String>
removeSecondaryTypeIds, ExtensionsData extension) {
- throw new CmisNotSupportedException("Not supported!");
+ // find link
+ String link = loadCollection(repositoryId,
Constants.COLLECTION_BULK_UPDATE);
+
+ if (link == null) {
+ throw new CmisObjectNotFoundException("Unknown repository or bulk
update properties is not supported!");
+ }
+
+ // set up writer
+ final BulkUpdateImpl bulkUpdate = new BulkUpdateImpl();
+ bulkUpdate.setObjectIdAndChangeToken(objectIdAndChangeToken);
+ bulkUpdate.setProperties(properties);
+ bulkUpdate.setAddSecondaryTypeIds(addSecondaryTypeIds);
+ bulkUpdate.setRemoveSecondaryTypeIds(removeSecondaryTypeIds);
+
+ final AtomEntryWriter entryWriter = new AtomEntryWriter(bulkUpdate);
+
+ // post the new folder object
+ Response resp = post(new UrlBuilder(link), Constants.MEDIATYPE_ENTRY,
new Output() {
+ public void write(OutputStream out) throws Exception {
+ entryWriter.write(out);
+ }
+ });
+
+ AtomFeed feed = parse(resp.getStream(), AtomFeed.class);
+ List<BulkUpdateObjectIdAndChangeToken> result = new
ArrayList<BulkUpdateObjectIdAndChangeToken>(feed
+ .getEntries().size());
+
+ // get the results
+ if (!feed.getEntries().isEmpty()) {
+
+ for (AtomEntry entry : feed.getEntries()) {
+ // walk through the entry
+ // we are not interested in the links this time because they
+ // could belong to a new document version
+ for (AtomElement element : entry.getElements()) {
+ if (element.getObject() instanceof ObjectData) {
+ ObjectData object = (ObjectData) element.getObject();
+ String id = object.getId();
+ if (id != null) {
+ String changeToken = null;
+ PropertyData<?> changeTokenProp =
object.getProperties().getProperties()
+ .get(PropertyIds.CHANGE_TOKEN);
+ if (changeTokenProp instanceof PropertyString) {
+ changeToken = ((PropertyString)
changeTokenProp).getFirstValue();
+ }
+
+ result.add(new
BulkUpdateObjectIdAndChangeTokenImpl(id, changeToken));
+ }
+ }
+ }
+ }
+ }
+
+ return result;
}
public void deleteObject(String repositoryId, String objectId, Boolean
allVersions, ExtensionsData extension) {
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/Constants.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/Constants.java?rev=1456994&r1=1456993&r2=1456994&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/Constants.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/Constants.java
Fri Mar 15 15:45:45 2013
@@ -47,6 +47,7 @@ public final class Constants {
public static final String COLLECTION_QUERY = "query";
public static final String COLLECTION_CHECKEDOUT = "checkedout";
public static final String COLLECTION_UNFILED = "unfiled";
+ public static final String COLLECTION_BULK_UPDATE = "update";
// URI templates
public static final String TEMPLATE_OBJECT_BY_ID = "objectbyid";
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java?rev=1456994&r1=1456993&r2=1456994&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java
Fri Mar 15 15:45:45 2013
@@ -954,16 +954,15 @@ public class XMLConverter {
// --- bulk update ---
// -------------------
- public static void writeBulkUpdate(XMLStreamWriter writer, CmisVersion
cmisVersion, String namespace,
- List<BulkUpdateObjectIdAndChangeToken> objectIdAndChangeToken,
Properties properties,
- List<String> addSecondaryTypeIds, List<String>
removeSecondaryTypeIds) throws XMLStreamException {
- if (objectIdAndChangeToken == null) {
+ public static void writeBulkUpdate(XMLStreamWriter writer, String
namespace, BulkUpdateImpl bulkUpdate)
+ throws XMLStreamException {
+ if (bulkUpdate == null || bulkUpdate.getObjectIdAndChangeToken() ==
null) {
return;
}
writer.writeStartElement(namespace, TAG_BULK_UPDATE);
- for (BulkUpdateObjectIdAndChangeToken idAndToken :
objectIdAndChangeToken) {
+ for (BulkUpdateObjectIdAndChangeToken idAndToken :
bulkUpdate.getObjectIdAndChangeToken()) {
if (idAndToken == null) {
continue;
}
@@ -977,7 +976,8 @@ public class XMLConverter {
writer.writeEndElement();
}
- if (properties != null) {
+ if (bulkUpdate.getProperties() != null) {
+ Properties properties = bulkUpdate.getProperties();
writer.writeStartElement(PREFIX_CMIS, TAG_BULK_UPDATE_PROPERTIES,
NAMESPACE_CMIS);
if (properties.getPropertyList() != null) {
@@ -990,14 +990,14 @@ public class XMLConverter {
writer.writeEndElement();
}
- if (addSecondaryTypeIds != null) {
- for (String id : addSecondaryTypeIds) {
+ if (bulkUpdate.getAddSecondaryTypeIds() != null) {
+ for (String id : bulkUpdate.getAddSecondaryTypeIds()) {
XMLUtils.write(writer, PREFIX_CMIS, NAMESPACE_CMIS,
TAG_BULK_UPDATE_ADD_SECONDARY_TYPES, id);
}
}
- if (removeSecondaryTypeIds != null) {
- for (String id : removeSecondaryTypeIds) {
+ if (bulkUpdate.getRemoveSecondaryTypeIds() != null) {
+ for (String id : bulkUpdate.getRemoveSecondaryTypeIds()) {
XMLUtils.write(writer, PREFIX_CMIS, NAMESPACE_CMIS,
TAG_BULK_UPDATE_REMOVE_SECONDARY_TYPES, id);
}
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/BukUpdateConverterTest.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/BukUpdateConverterTest.java?rev=1456994&r1=1456993&r2=1456994&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/BukUpdateConverterTest.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/BukUpdateConverterTest.java
Fri Mar 15 15:45:45 2013
@@ -80,9 +80,7 @@ public class BukUpdateConverterTest exte
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLStreamWriter writer = createWriter(out);
- XMLConverter.writeBulkUpdate(writer, CmisVersion.CMIS_1_1,
TEST_NAMESPACE,
- bulkUpdate.getObjectIdAndChangeToken(),
bulkUpdate.getProperties(),
- bulkUpdate.getAddSecondaryTypeIds(),
bulkUpdate.getRemoveSecondaryTypeIds());
+ XMLConverter.writeBulkUpdate(writer, TEST_NAMESPACE, bulkUpdate);
closeWriter(writer);
byte[] xml = out.toByteArray();
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=1456994&r1=1456993&r2=1456994&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
Fri Mar 15 15:45:45 2013
@@ -49,6 +49,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.impl.XMLConstraints;
import org.apache.chemistry.opencmis.commons.impl.XMLConverter;
import org.apache.chemistry.opencmis.commons.impl.XMLUtils;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.BulkUpdateImpl;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl;
@@ -70,6 +71,7 @@ public class AtomEntryParser {
private static final String TAG_MEDIATYPE = "mediatype";
private static final String TAG_FILENAME = "filename";
private static final String TAG_TYPE = "type";
+ private static final String TAG_BULK_UPDATE = "bulkUpdate";
private static final String ATTR_SRC = "src";
private static final String ATTR_TYPE = "type";
@@ -87,6 +89,7 @@ public class AtomEntryParser {
private ContentStreamImpl atomContentStream;
private ContentStreamImpl cmisContentStream;
private TypeDefinition typeDef;
+ private BulkUpdateImpl bulkUpdate;
/**
* Constructor.
@@ -184,6 +187,13 @@ public class AtomEntryParser {
}
/**
+ * Returns the bulk update data.
+ */
+ public BulkUpdateImpl getBulkUpdate() {
+ return bulkUpdate;
+ }
+
+ /**
* Parses the stream.
*/
public void parse(InputStream stream) throws Exception {
@@ -239,6 +249,8 @@ public class AtomEntryParser {
parseObject(parser);
} else if (TAG_TYPE.equals(name.getLocalPart())) {
parseTypeDefinition(parser);
+ } else if (TAG_BULK_UPDATE.equals(name.getLocalPart())) {
+ parseBulkUpdate(parser);
} else if (TAG_CONTENT.equals(name.getLocalPart())) {
parseCmisContent(parser);
} else {
@@ -286,6 +298,13 @@ public class AtomEntryParser {
}
/**
+ * Parses a bluk update.
+ */
+ private void parseBulkUpdate(XMLStreamReader parser) throws Exception {
+ bulkUpdate = XMLConverter.convertBulkUpdate(parser);
+ }
+
+ /**
* Extract the content stream.
*/
private void parseAtomContent(XMLStreamReader parser) throws Exception {
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomPubUtils.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/AtomPubUtils.java?rev=1456994&r1=1456993&r2=1456994&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomPubUtils.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomPubUtils.java
Fri Mar 15 15:45:45 2013
@@ -71,6 +71,7 @@ public final class AtomPubUtils {
public static final String RESOURCE_UNFILED = "unfiled";
public static final String RESOURCE_CHANGES = "changes";
public static final String RESOURCE_CONTENT = "content";
+ public static final String RESOURCE_BULK_UPDATE = "update";
public static final String REPOSITORY_PLACEHOLDER = "{repositoryId}";
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=1456994&r1=1456993&r2=1456994&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
Fri Mar 15 15:45:45 2013
@@ -20,6 +20,7 @@ package org.apache.chemistry.opencmis.se
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_ACL;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_ALLOWABLEACIONS;
+import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_BULK_UPDATE;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_CHANGES;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_CHECKEDOUT;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_CHILDREN;
@@ -191,6 +192,7 @@ public class CmisAtomPubServlet extends
dispatcher.addResource(RESOURCE_POLICIES, METHOD_GET,
PolicyService.class, "getAppliedPolicies");
dispatcher.addResource(RESOURCE_POLICIES, METHOD_POST,
PolicyService.class, "applyPolicy");
dispatcher.addResource(RESOURCE_POLICIES, METHOD_DELETE,
PolicyService.class, "removePolicy");
+ dispatcher.addResource(RESOURCE_BULK_UPDATE, METHOD_POST,
ObjectService.class, "bulkUpdateProperties");
} catch (NoSuchMethodException e) {
LOG.error("Cannot initialize dispatcher!", e);
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.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/ObjectService.java?rev=1456994&r1=1456993&r2=1456994&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java
Fri Mar 15 15:45:45 2013
@@ -18,10 +18,12 @@
*/
package org.apache.chemistry.opencmis.server.impl.atompub;
+import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_BULK_UPDATE;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_CONTENT;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_ENTRY;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileBaseUrl;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileUrl;
+import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileUrlBuilder;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.getNamespaces;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.writeObjectEntry;
import static
org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
@@ -34,7 +36,10 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
+import java.util.GregorianCalendar;
+import java.util.List;
import java.util.Map;
+import java.util.TimeZone;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -42,6 +47,7 @@ import javax.xml.stream.XMLStreamWriter;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.data.AllowableActions;
+import
org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.data.FailedToDeleteData;
import org.apache.chemistry.opencmis.commons.data.ObjectData;
@@ -51,6 +57,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+import
org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
import org.apache.chemistry.opencmis.commons.impl.Constants;
import org.apache.chemistry.opencmis.commons.impl.MimeHelper;
@@ -58,7 +65,12 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
import org.apache.chemistry.opencmis.commons.impl.XMLConverter;
import org.apache.chemistry.opencmis.commons.impl.XMLUtils;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.BulkUpdateImpl;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl;
import org.apache.chemistry.opencmis.commons.server.CallContext;
import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
@@ -515,6 +527,75 @@ public final class ObjectService {
}
/**
+ * BulkUpdateProperties.
+ */
+ public static void bulkUpdateProperties(CallContext context, CmisService
service, String repositoryId,
+ HttpServletRequest request, HttpServletResponse response) throws
Exception {
+
+ AtomEntryParser parser = new
AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold(),
+ context.getMaxContentSize(), context.encryptTempFiles());
+ parser.parse(request.getInputStream());
+
+ BulkUpdateImpl bulkUpdate = parser.getBulkUpdate();
+ if (bulkUpdate == null) {
+ throw new CmisInvalidArgumentException("Bulk update data is
missing!");
+ }
+
+ List<BulkUpdateObjectIdAndChangeToken> result =
service.bulkUpdateProperties(repositoryId,
+ bulkUpdate.getObjectIdAndChangeToken(),
bulkUpdate.getProperties(),
+ bulkUpdate.getAddSecondaryTypeIds(),
bulkUpdate.getRemoveSecondaryTypeIds(), null);
+
+ response.setStatus(HttpServletResponse.SC_CREATED);
+ response.setContentType(Constants.MEDIATYPE_FEED);
+
+ // write XML
+ AtomFeed feed = new AtomFeed();
+ feed.startDocument(response.getOutputStream(), getNamespaces(service));
+ feed.startFeed(true);
+
+ // write basic Atom feed elements
+ feed.writeFeedElements(null, null, null, "Bulk Update Properties",
+ new GregorianCalendar(TimeZone.getTimeZone("GMT")), null,
+ (result == null ? null : BigInteger.valueOf(result.size())));
+
+ // write links
+ UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+ feed.writeServiceLink(baseUrl.toString(), repositoryId);
+
+ UrlBuilder selfLink = compileUrlBuilder(baseUrl, RESOURCE_BULK_UPDATE,
null);
+ feed.writeSelfLink(selfLink.toString(), null);
+
+ // write entries
+ if (result != null) {
+ AtomEntry entry = new AtomEntry(feed.getWriter());
+ for (BulkUpdateObjectIdAndChangeToken idAndToken : result) {
+ if ((idAndToken == null) || (idAndToken.getId() == null)) {
+ continue;
+ }
+
+ ObjectDataImpl object = new ObjectDataImpl();
+ PropertiesImpl properties = new PropertiesImpl();
+ object.setProperties(properties);
+
+ properties.addProperty(new
PropertyIdImpl(PropertyIds.OBJECT_ID, idAndToken.getId()));
+
+ if (idAndToken.getChangeToken() != null) {
+ properties
+ .addProperty(new
PropertyStringImpl(PropertyIds.CHANGE_TOKEN, idAndToken.getChangeToken()));
+ }
+
+ writeObjectEntry(service, entry, object, null, repositoryId,
null, null, baseUrl, false,
+ context.getCmisVersion());
+ }
+ }
+
+ // we are done
+ feed.endFeed();
+ feed.endDocument();
+ }
+
+ /**
* Gets the change token from a property set.
*/
private static String extractChangeToken(Properties properties) {
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.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/RepositoryService.java?rev=1456994&r1=1456993&r2=1456994&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java
Fri Mar 15 15:45:45 2013
@@ -19,6 +19,7 @@
package org.apache.chemistry.opencmis.server.impl.atompub;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.PAGE_SIZE;
+import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_BULK_UPDATE;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_CHANGES;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_CHECKEDOUT;
import static
org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_CHILDREN;
@@ -176,9 +177,12 @@ public final class RepositoryService {
if (supportsUnFiling || supportsMultifiling) {
serviceDoc.writeCollection(compileUrl(baseUrl,
RESOURCE_UNFILED, null),
Constants.COLLECTION_UNFILED, "Unfiled
Collection", Constants.MEDIATYPE_CMISATOM);
-
}
+ // - bulk update collection
+ serviceDoc.writeCollection(compileUrl(baseUrl,
RESOURCE_BULK_UPDATE, null),
+ Constants.COLLECTION_BULK_UPDATE, "Bulk Update
Collection", Constants.MEDIATYPE_CMISATOM);
+
// add repository info
serviceDoc.writeRepositoryInfo(infoData, cmisVersion);