Author: fmui
Date: Wed Sep 29 13:07:36 2010
New Revision: 1002599
URL: http://svn.apache.org/viewvc?rev=1002599&view=rev
Log:
improved service wrapper (added check for cmis:objectTypeId)
Modified:
incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/AbstractCmisService.java
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CmisServiceWrapper.java
Modified:
incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/AbstractCmisService.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/AbstractCmisService.java?rev=1002599&r1=1002598&r2=1002599&view=diff
==============================================================================
---
incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/AbstractCmisService.java
(original)
+++
incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/server/AbstractCmisService.java
Wed Sep 29 13:07:36 2010
@@ -277,18 +277,18 @@ public abstract class AbstractCmisServic
}
// check object type id
- PropertyData<?> baseTypeIdProperty =
properties.getProperties().get(PropertyIds.OBJECT_TYPE_ID);
- if (baseTypeIdProperty == null || !(baseTypeIdProperty.getFirstValue()
instanceof String)) {
+ PropertyData<?> obbjectTypeIdProperty =
properties.getProperties().get(PropertyIds.OBJECT_TYPE_ID);
+ if (obbjectTypeIdProperty == null ||
!(obbjectTypeIdProperty.getFirstValue() instanceof String)) {
throw new CmisInvalidArgumentException("Property '" +
PropertyIds.OBJECT_TYPE_ID + "' must be set!");
}
// get the type
- String baseTypeId = baseTypeIdProperty.getFirstValue().toString();
- TypeDefinition baseType = getTypeDefinition(repositoryId, baseTypeId,
null);
+ String objectTypeId = obbjectTypeIdProperty.getFirstValue().toString();
+ TypeDefinition type = getTypeDefinition(repositoryId, objectTypeId,
null);
// create object
String newId = null;
- switch (baseType.getBaseTypeId()) {
+ switch (type.getBaseTypeId()) {
case CMIS_DOCUMENT:
newId = createDocument(repositoryId, properties, folderId,
contentStream, versioningState, policies, null,
null, extension);
Modified:
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CmisServiceWrapper.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CmisServiceWrapper.java?rev=1002599&r1=1002598&r2=1002599&view=diff
==============================================================================
---
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CmisServiceWrapper.java
(original)
+++
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CmisServiceWrapper.java
Wed Sep 29 13:07:36 2010
@@ -1,4 +1,5 @@
package org.apache.chemistry.opencmis.server.support;
+
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -20,10 +21,10 @@ package org.apache.chemistry.opencmis.se
*
*/
-
import java.math.BigInteger;
import java.util.List;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.data.Acl;
import org.apache.chemistry.opencmis.commons.data.AllowableActions;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
@@ -35,6 +36,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.data.ObjectList;
import org.apache.chemistry.opencmis.commons.data.ObjectParentData;
import org.apache.chemistry.opencmis.commons.data.Properties;
+import org.apache.chemistry.opencmis.commons.data.PropertyData;
import org.apache.chemistry.opencmis.commons.data.RenditionData;
import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
@@ -210,6 +212,29 @@ public class CmisServiceWrapper<T extend
}
/**
+ * Throws an exception if the given property isn't set or of the wrong
type.
+ */
+ protected void checkProperty(Properties properties, String propertyId,
Class<?> clazz) {
+ if (properties.getProperties() == null) {
+ throw new CmisInvalidArgumentException("Property " + propertyId +
" must be set!");
+ }
+
+ PropertyData<?> property = properties.getProperties().get(propertyId);
+ if (property == null) {
+ throw new CmisInvalidArgumentException("Property " + propertyId +
" must be set!");
+ }
+
+ Object value = property.getFirstValue();
+ if (value == null) {
+ throw new CmisInvalidArgumentException("Property " + propertyId +
" must have a value!");
+ }
+
+ if (clazz.isAssignableFrom(value.getClass())) {
+ throw new CmisInvalidArgumentException("Property " + propertyId +
" has the wrong type!");
+ }
+ }
+
+ /**
* Throws an exception if the given content object is <code>null</code>.
*/
protected void checkContentStream(ContentStream content) {
@@ -618,6 +643,7 @@ public class CmisServiceWrapper<T extend
VersioningState versioningState, List<String> policies,
ExtensionsData extension) {
checkRepositoryId(repositoryId);
checkProperties(properties);
+ checkProperty(properties, PropertyIds.OBJECT_TYPE_ID, String.class);
versioningState = getDefault(versioningState);
try {
@@ -633,6 +659,7 @@ public class CmisServiceWrapper<T extend
Acl removeAces, ExtensionsData extension) {
checkRepositoryId(repositoryId);
checkProperties(properties);
+ checkProperty(properties, PropertyIds.OBJECT_TYPE_ID, String.class);
versioningState = getDefault(versioningState);
try {
@@ -662,6 +689,7 @@ public class CmisServiceWrapper<T extend
Acl addAces, Acl removeAces, ExtensionsData extension) {
checkRepositoryId(repositoryId);
checkProperties(properties);
+ checkProperty(properties, PropertyIds.OBJECT_TYPE_ID, String.class);
checkId("Folder Id", folderId);
try {
@@ -675,6 +703,7 @@ public class CmisServiceWrapper<T extend
Acl addAces, Acl removeAces, ExtensionsData extension) {
checkRepositoryId(repositoryId);
checkProperties(properties);
+ checkProperty(properties, PropertyIds.OBJECT_TYPE_ID, String.class);
try {
return service.createPolicy(repositoryId, properties, folderId,
policies, addAces, removeAces, extension);
@@ -687,6 +716,7 @@ public class CmisServiceWrapper<T extend
Acl removeAces, ExtensionsData extension) {
checkRepositoryId(repositoryId);
checkProperties(properties);
+ checkProperty(properties, PropertyIds.OBJECT_TYPE_ID, String.class);
try {
return service.createRelationship(repositoryId, properties,
policies, addAces, removeAces, extension);