Author: jens
Date: Tue Dec 11 05:12:37 2012
New Revision: 1419999
URL: http://svn.apache.org/viewvc?rev=1419999&view=rev
Log:
InMemory: secondary types support: add secondary types in updateProperties
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/DocumentTypeCreationHelper.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java?rev=1419999&r1=1419998&r2=1419999&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
Tue Dec 11 05:12:37 2012
@@ -22,8 +22,10 @@ import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.data.Acl;
@@ -622,6 +624,27 @@ public class InMemoryObjectServiceImpl e
// update properties
boolean hasUpdatedProp = false;
+ // Find secondary type definitions to consider for update
+ List<String> existingSecondaryTypeIds = so.getSecondaryTypeIds();
+ @SuppressWarnings("unchecked")
+ PropertyData<String> pdSec = (PropertyData<String>)
properties.getProperties().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
+ List<String> newSecondaryTypeIds = pdSec == null ? null :
pdSec.getValues();
+ Set<String> secondaryTypeIds = new HashSet<String>();
+ if (null != existingSecondaryTypeIds)
+ secondaryTypeIds.addAll(existingSecondaryTypeIds);
+ if (null != newSecondaryTypeIds)
+ secondaryTypeIds.addAll(newSecondaryTypeIds);
+
+ // Find secondary type definitions to delete
+ // TODO: implement this
+ if (null != newSecondaryTypeIds && newSecondaryTypeIds.size() > 0) {
+ List<String> propertiesIdToDelete =
getListOfPropertiesToDeleteFromRemovedSecondaryTypes(repositoryId, so,
newSecondaryTypeIds);
+ for (String propIdToRemove : propertiesIdToDelete) {
+ so.getProperties().remove(propIdToRemove);
+ }
+ }
+
+ // update properties:
if(properties != null) {
for (String key : properties.getProperties().keySet()) {
if (key.equals(PropertyIds.NAME)) {
@@ -631,7 +654,7 @@ public class InMemoryObjectServiceImpl e
PropertyData<?> value =
properties.getProperties().get(key);
PropertyDefinition<?> propDef =
typeDef.getPropertyDefinitions().get(key);
if (null == propDef && cmis11) {
- TypeDefinition typeDefSecondary=
getSecondaryTypeDefinition(so, key);
+ TypeDefinition typeDefSecondary=
getSecondaryTypeDefinition(repositoryId, secondaryTypeIds, key);
if (null == typeDefSecondary)
throw new CmisInvalidArgumentException("Cannot
update property " + key + ": not contained in type");
propDef =
typeDefSecondary.getPropertyDefinitions().get(key);
@@ -767,7 +790,6 @@ public class InMemoryObjectServiceImpl e
List<BulkUpdateObjectIdAndChangeToken> objectIdAndChangeToken,
Properties properties,
List<String> addSecondaryTypeIds, List<String>
removeSecondaryTypeIds, ExtensionsData extension) {
- // TODO: add support for secondary types
List<BulkUpdateObjectIdAndChangeToken> result = new
ArrayList<BulkUpdateObjectIdAndChangeToken>();
for ( BulkUpdateObjectIdAndChangeToken obj: objectIdAndChangeToken) {
Holder<String> objId = new Holder<String>(obj.getId());
@@ -1248,13 +1270,12 @@ public class InMemoryObjectServiceImpl e
}
}
- private TypeDefinition getSecondaryTypeDefinition(StoredObject so, String
propertyId) {
- List<String> secondaryTypeIds = so.getSecondaryTypeIds();
+ private TypeDefinition getSecondaryTypeDefinition(String repositoryId,
Set<String> secondaryTypeIds, String propertyId) {
if (null == secondaryTypeIds || secondaryTypeIds.isEmpty())
return null;
for (String typeId : secondaryTypeIds) {
- TypeDefinitionContainer typeDefC =
fStoreManager.getTypeById(so.getRepositoryId(), typeId);
+ TypeDefinitionContainer typeDefC =
fStoreManager.getTypeById(repositoryId, typeId);
TypeDefinition typeDef = typeDefC.getTypeDefinition();
if (TypeValidator.typeContainsProperty(typeDef, propertyId)) {
@@ -1264,4 +1285,24 @@ public class InMemoryObjectServiceImpl e
return null;
}
+
+ private List<String>
getListOfPropertiesToDeleteFromRemovedSecondaryTypes(String repositoryId,
StoredObject so,
+ List<String> newSecondaryTypeIds) {
+
+ List<String> propertiesToDelete = new ArrayList<String>(); //
properties id to be removed
+
+ // calculate delta to be removed
+ List<String> existingSecondaryTypeIds = so.getSecondaryTypeIds();
+ List<String> delta = new ArrayList<String>(existingSecondaryTypeIds);
+ delta.removeAll(newSecondaryTypeIds);
+ for (String typeDefId : delta) {
+ TypeDefinitionContainer typeDefC =
fStoreManager.getTypeById(repositoryId, typeDefId);
+ TypeDefinition typeDef = typeDefC.getTypeDefinition();
+
propertiesToDelete.addAll(typeDef.getPropertyDefinitions().keySet());
+ }
+
+ // Note the list may contain too many properties, if the same property
is also in a type not to be removed
+ return propertiesToDelete;
+ }
+
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/DocumentTypeCreationHelper.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/DocumentTypeCreationHelper.java?rev=1419999&r1=1419998&r2=1419999&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/DocumentTypeCreationHelper.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/DocumentTypeCreationHelper.java
Tue Dec 11 05:12:37 2012
@@ -129,7 +129,7 @@ public class DocumentTypeCreationHelper
propertyDefinitions.put(propS.getId(), propS);
propId =
PropertyCreationHelper.createIdDefinition(PropertyIds.SECONDARY_OBJECT_TYPE_IDS,
"Secondary Type Ids",
- Updatability.READONLY);
+ Updatability.READWRITE);
propertyDefinitions.put(propId.getId(), propId);
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java?rev=1419999&r1=1419998&r2=1419999&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
Tue Dec 11 05:12:37 2012
@@ -1186,7 +1186,7 @@ public class ObjectServiceTest extends A
final String primaryPropVal = "Sample Doc String Property";
List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
- properties.add(fFactory.createPropertyIdData(PropertyIds.NAME,
"ObjectWithSecondaryType"));
+ properties.add(fFactory.createPropertyStringData(PropertyIds.NAME,
"ObjectWithSecondaryType"));
properties.add(fFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID,
TEST_DOCUMENT_TYPE_ID));
properties.add(fFactory.createPropertyStringData(TEST_DOCUMENT_STRING_PROP_ID,
primaryPropVal));
properties.add(fFactory.createPropertyIdData(PropertyIds.SECONDARY_OBJECT_TYPE_IDS,
TEST_SECONDARY_TYPE_ID));
@@ -1233,6 +1233,50 @@ public class ObjectServiceTest extends A
}
// TODO: test add secondary type
+ @Test
+ public void testUpdatePropertiesWithTypeCreation () {
+ final String strPropVal = "Secondary";
+ final BigInteger intPropVal = BigInteger.valueOf(100);
+ final String primaryPropVal = "Sample Doc String Property";
+ final String primaryPropVal2 = "Sample Doc String Property updated";
+
+ log.info("starting testUpdatePropertiesWithTypeCreation() ...");
+
+ List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
+ properties.add(fFactory.createPropertyStringData(PropertyIds.NAME,
"SimpleDocument"));
+
properties.add(fFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID,
TEST_DOCUMENT_TYPE_ID));
+
properties.add(fFactory.createPropertyStringData(TEST_DOCUMENT_STRING_PROP_ID,
primaryPropVal));
+ Properties props = fFactory.createPropertiesData(properties);
+
+ String id = fObjSvc.createDocument(fRepositoryId, props,
fRootFolderId, null, VersioningState.NONE, null,
+ null, null, null);
+ assertNotNull(id);
+
+ properties = new ArrayList<PropertyData<?>>();
+
properties.add(fFactory.createPropertyStringData(TEST_DOCUMENT_STRING_PROP_ID,
primaryPropVal2));
+
properties.add(fFactory.createPropertyIdData(PropertyIds.SECONDARY_OBJECT_TYPE_IDS,
TEST_SECONDARY_TYPE_ID));
+
properties.add(fFactory.createPropertyStringData(SECONDARY_STRING_PROP,
strPropVal));
+
properties.add(fFactory.createPropertyIntegerData(SECONDARY_INTEGER_PROP,
intPropVal));
+ props = fFactory.createPropertiesData(properties);
+ fObjSvc.updateProperties(fRepositoryId, new Holder<String>(id), new
Holder<String>(), props, null);
+
+ Properties res = fObjSvc.getProperties(fRepositoryId, id, "*", null);
+ assertNotNull(res.getProperties());
+ Map<String, PropertyData<?>> returnedProps = res.getProperties();
+ assertNotNull(returnedProps);
+ assertEquals(1,
returnedProps.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues().size());
+ String secIds = (String)
returnedProps.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getFirstValue();
+ assertEquals(TEST_SECONDARY_TYPE_ID, secIds);
+ String returnedValueStr = (String)
returnedProps.get(SECONDARY_STRING_PROP).getFirstValue();
+ BigInteger returnedValueInt = (BigInteger)
returnedProps.get(SECONDARY_INTEGER_PROP).getFirstValue();
+ assertEquals(strPropVal, returnedValueStr);
+ assertEquals(intPropVal, returnedValueInt);
+ String returnedPrimaryPropVal = (String)
returnedProps.get(TEST_DOCUMENT_STRING_PROP_ID).getFirstValue();
+ assertEquals(primaryPropVal2, returnedPrimaryPropVal);
+
+ log.info("... finished testUpdatePropertiesWithTypeCreation()");
+ }
+
// TODO: remove secondary type
// TODO: test constraints on secondary types