diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/caveat-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/caveat-context.xml
index 10fe39ed05..7c1a972bc9 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/caveat-context.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/caveat-context.xml
@@ -17,6 +17,7 @@
+
diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/caveat/rm-caveats.json b/rm-server/config/alfresco/module/org_alfresco_module_rm/caveat/rm-caveats.json
index e744ba86f1..388ce2405f 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/caveat/rm-caveats.json
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/caveat/rm-caveats.json
@@ -4,6 +4,10 @@
"displayLabel" : "rm.caveat.classification.label",
"description" : "rm.caveat.classification.description",
"type" : "HIERARCHICAL",
+ "model" :
+ {
+ "property" : "clf:classification"
+ },
"marks" :
[
{
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOCache.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOCache.java
index 2bf24bb478..3f362d3a76 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOCache.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOCache.java
@@ -23,6 +23,9 @@ import com.google.common.collect.ImmutableMap;
import org.alfresco.module.org_alfresco_module_rm.caveat.CaveatException.CaveatGroupNotFound;
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup;
+import org.alfresco.service.namespace.QName;
+
+import java.util.Map;
/**
* A cache that ensures the underlying caveat DAO is only executed once per query.
@@ -62,6 +65,37 @@ public class CaveatDAOCache implements CaveatDAOInterface
return caveatGroup;
}
+ @Override public QName getCaveatGroupProperty(String caveatGroupId)
+ {
+ ensureCachePopulated();
+
+ return getGroupById(caveatGroupId).getModelProperty();
+ }
+
+ @Override public CaveatGroup getCaveatGroupFromProperty(QName propertyName)
+ {
+ ensureCachePopulated();
+
+ CaveatGroup matchingGroup = null;
+ for (Map.Entry entry : caveatGroups.entrySet())
+ {
+ final CaveatGroup potentialMatch = entry.getValue();
+ if (propertyName.equals(getCaveatGroupProperty(potentialMatch.getId())))
+ {
+ matchingGroup = potentialMatch;
+ break;
+ }
+ }
+ if (matchingGroup == null)
+ {
+ throw new CaveatGroupNotFound("No group found for property '" + propertyName + "'");
+ }
+ else
+ {
+ return matchingGroup;
+ }
+ }
+
/** The first call to this method will populate the cache, subsequent calls will do nothing. */
private void ensureCachePopulated()
{
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSON.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSON.java
index 6862572681..69e980cb76 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSON.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSON.java
@@ -19,11 +19,14 @@
package org.alfresco.module.org_alfresco_module_rm.caveat.dao;
+import static org.alfresco.service.namespace.QName.createQName;
+
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import com.google.common.collect.ImmutableMap;
@@ -33,6 +36,8 @@ import org.alfresco.module.org_alfresco_module_rm.caveat.CaveatException.Malform
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup;
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroupType;
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatMark;
+import org.alfresco.service.namespace.NamespaceService;
+import org.alfresco.service.namespace.QName;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
@@ -57,6 +62,10 @@ public class CaveatDAOFromJSON implements CaveatDAOInterface
private static final String DESCRIPTION_JSON_KEY = "description";
/** JSON key for the group type. */
private static final String TYPE_JSON_KEY = "type";
+ /** JSON key for the model object. */
+ private static final String MODEL_JSON_KEY = "model";
+ /** JSON key for the property field. */
+ private static final String PROPERTY_JSON_KEY = "property";
/** JSON key for the caveat marks array. */
private static final String MARKS_JSON_KEY = "marks";
/** JSON key for the mark id. */
@@ -69,12 +78,19 @@ public class CaveatDAOFromJSON implements CaveatDAOInterface
/** The location of the configuration file relative to the classpath. */
private String configLocation;
+ private NamespaceService namespaceService;
+
/** Set the location of the configuration file relative to the classpath. */
public void setConfigLocation(String configLocation)
{
this.configLocation = configLocation;
}
+ public void setNamespaceService(NamespaceService service)
+ {
+ this.namespaceService = service;
+ }
+
/**
* {@inheritDoc}
*
@@ -137,6 +153,24 @@ public class CaveatDAOFromJSON implements CaveatDAOInterface
return caveatGroup;
}
+ @Override public QName getCaveatGroupProperty(String caveatGroupId)
+ {
+ return getGroupById(caveatGroupId).getModelProperty();
+ }
+
+ @Override public CaveatGroup getCaveatGroupFromProperty(QName propertyName)
+ {
+ // FIXME Do we need any validation to ensure that multiple caveat groups don't reuse the same property?
+ for (Map.Entry entry : getCaveatGroups().entrySet())
+ {
+ if (propertyName.equals(entry.getValue().getModelProperty()))
+ {
+ return entry.getValue();
+ }
+ }
+ throw new CaveatGroupNotFound("Caveat Group not found for property '" + propertyName + "'");
+ }
+
/**
* Create a caveat group from the supplied JSON.
*
@@ -149,6 +183,15 @@ public class CaveatDAOFromJSON implements CaveatDAOInterface
String id = jsonGroup.getString(GROUP_ID_JSON_KEY);
String displayLabelKey = jsonGroup.getString(GROUP_DISPLAY_LABEL_JSON_KEY);
String descriptionKey = jsonGroup.getString(DESCRIPTION_JSON_KEY);
+ String modelProperty = null;
+ if (jsonGroup.has(MODEL_JSON_KEY))
+ {
+ JSONObject modelObj = jsonGroup.getJSONObject(MODEL_JSON_KEY);
+ if (modelObj.has(PROPERTY_JSON_KEY))
+ {
+ modelProperty = modelObj.getString(PROPERTY_JSON_KEY);
+ }
+ }
String caveatGroupTypeString = jsonGroup.getString(TYPE_JSON_KEY);
CaveatGroupType caveatGroupType;
try
@@ -180,7 +223,9 @@ public class CaveatDAOFromJSON implements CaveatDAOInterface
}
// Instantiate the group (and associate the marks with the group).
- CaveatGroup caveatGroup = new CaveatGroup(id, displayLabelKey, descriptionKey, caveatGroupType, caveatMarks);
+ CaveatGroup caveatGroup = new CaveatGroup(id, displayLabelKey, descriptionKey,
+ modelProperty == null ? null : createQName(modelProperty, namespaceService),
+ caveatGroupType, caveatMarks);
return caveatGroup;
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOInterface.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOInterface.java
index 612a246729..fa0eaea65a 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOInterface.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOInterface.java
@@ -22,6 +22,7 @@ package org.alfresco.module.org_alfresco_module_rm.caveat.dao;
import com.google.common.collect.ImmutableMap;
import org.alfresco.module.org_alfresco_module_rm.caveat.CaveatException.CaveatGroupNotFound;
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup;
+import org.alfresco.service.namespace.QName;
/**
* An object responsible for providing access to the configured caveat groups and marks.
@@ -44,4 +45,21 @@ public interface CaveatDAOInterface
* @throws CaveatGroupNotFound if the caveat group is not found.
*/
CaveatGroup getGroupById(String groupId) throws CaveatGroupNotFound;
+
+ /**
+ * Gets the property that relates to a {@link CaveatGroup}.
+ *
+ * @param caveatGroupId
+ * @return
+ * @throws CaveatGroupNotFound if a matching {@link CaveatGroup} could not be found.
+ */
+ QName getCaveatGroupProperty(String caveatGroupId);
+
+ /**
+ * Gets the {@link CaveatGroup} that relates to a property.
+ *
+ * @return the matching {@link CaveatGroup} if there is one.
+ * @throws CaveatGroupNotFound if there was no matching group.
+ */
+ CaveatGroup getCaveatGroupFromProperty(QName propertyName);
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/scheme/CaveatGroup.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/scheme/CaveatGroup.java
index 93dbb5170a..eb20d2c34c 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/scheme/CaveatGroup.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/scheme/CaveatGroup.java
@@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableMap.Builder;
import org.alfresco.module.org_alfresco_module_rm.caveat.CaveatException.CaveatMarkNotFound;
import org.alfresco.module.org_alfresco_module_rm.util.CoreServicesExtras;
import org.alfresco.module.org_alfresco_module_rm.util.RMParameterCheck;
+import org.alfresco.service.namespace.QName;
import org.apache.commons.lang.StringUtils;
import org.springframework.extensions.surf.util.ParameterCheck;
@@ -49,6 +50,8 @@ public class CaveatGroup implements Serializable
private final String displayLabelKey;
/** The key to retrieve the I18n'ed description of the caveat group. */
private final String descriptionKey;
+ /** The model property in which this caveat group will store marks on objects. */
+ private final QName modelProperty;
/** The relationship between marks in the group. */
private final CaveatGroupType caveatGroupType;
/** The marks that are contained in this group, ordered according to the list supplied in the constructor. */
@@ -64,9 +67,9 @@ public class CaveatGroup implements Serializable
* @param caveatGroupType The relationship between marks in the group.
* @param caveatMarks The marks that are contained in this group.
*/
- public CaveatGroup(String id, CaveatGroupType caveatGroupType, List caveatMarks)
+ public CaveatGroup(String id, QName modelProperty, CaveatGroupType caveatGroupType, List caveatMarks)
{
- this(id, null, null, caveatGroupType, caveatMarks);
+ this(id, null, null, modelProperty, caveatGroupType, caveatMarks);
}
/**
@@ -82,8 +85,9 @@ public class CaveatGroup implements Serializable
* @param caveatGroupType The relationship between marks in the group.
* @param caveatMarks The marks that are contained in this group.
*/
- public CaveatGroup(String id, String displayLabelKey, String descriptionKey, CaveatGroupType caveatGroupType,
- List caveatMarks)
+ public CaveatGroup(String id, String displayLabelKey, String descriptionKey,
+ QName modelProperty, CaveatGroupType caveatGroupType,
+ List caveatMarks)
{
RMParameterCheck.checkNotBlank("id", id);
ParameterCheck.mandatory("caveatGroupType", caveatGroupType);
@@ -101,6 +105,7 @@ public class CaveatGroup implements Serializable
this.id = id;
this.displayLabelKey = displayLabelKey;
this.descriptionKey = descriptionKey;
+ this.modelProperty = modelProperty;
this.caveatGroupType = caveatGroupType;
for (CaveatMark caveatMark : caveatMarks)
{
@@ -149,6 +154,12 @@ public class CaveatGroup implements Serializable
return CoreServicesExtras.getI18NMessageOrKey(descriptionKey);
}
+ /** Gets the content model property in which the caveat marks will be recorded. */
+ public QName getModelProperty()
+ {
+ return modelProperty;
+ }
+
/**
* Indicates how the marks in the caveat groups are related.
*/
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSONUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSONUnitTest.java
index 150c556df1..758a5a15ef 100644
--- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSONUnitTest.java
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSONUnitTest.java
@@ -21,11 +21,16 @@ package org.alfresco.module.org_alfresco_module_rm.caveat.dao;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.caveat.CaveatException.MalformedConfiguration;
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup;
+import org.alfresco.service.namespace.NamespaceService;
+import org.junit.Before;
import org.junit.Test;
/**
@@ -39,6 +44,14 @@ public class CaveatDAOFromJSONUnitTest
/** The class under test. */
CaveatDAOFromJSON caveatDAOFromJSON = new CaveatDAOFromJSON();
+ @Before public void initClassUnderTest()
+ {
+ NamespaceService namespaceService = mock(NamespaceService.class);
+ when(namespaceService.getNamespaceURI(anyString())).thenReturn("{mockedNamespace}");
+
+ caveatDAOFromJSON.setNamespaceService(namespaceService);
+ }
+
/** Test that loading the default caveat configuration file doesn't throw any exceptions. */
@Test
public void testGetCaveatGroups_defaultConfiguration()
diff --git a/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-duplicateGroupId.json b/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-duplicateGroupId.json
index ebe080ef9c..1dbad1fee3 100644
--- a/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-duplicateGroupId.json
+++ b/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-duplicateGroupId.json
@@ -4,6 +4,10 @@
"displayLabel" : "rm.caveat.classification.group",
"description" : "rm.caveat.classification.description",
"type" : "HIERARCHICAL",
+ "model" :
+ {
+ "property" : "clf:classification"
+ },
"marks" :
[
{
diff --git a/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-duplicateMarkId.json b/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-duplicateMarkId.json
index 45be6742ed..f0b7e86b32 100644
--- a/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-duplicateMarkId.json
+++ b/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-duplicateMarkId.json
@@ -4,6 +4,10 @@
"displayLabel" : "rm.caveat.classification.group",
"description" : "rm.caveat.classification.description",
"type" : "HIERARCHICAL",
+ "model" :
+ {
+ "property" : "clf:classification"
+ },
"marks" :
[
{
diff --git a/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-duplicateMarkIdInDifferentGroups.json b/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-duplicateMarkIdInDifferentGroups.json
index c9fc56cab3..9a9849290a 100644
--- a/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-duplicateMarkIdInDifferentGroups.json
+++ b/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-duplicateMarkIdInDifferentGroups.json
@@ -4,6 +4,10 @@
"displayLabel" : "rm.caveat.classification.group",
"description" : "rm.caveat.classification.description",
"type" : "HIERARCHICAL",
+ "model" :
+ {
+ "property" : "clf:classification"
+ },
"marks" :
[
{
diff --git a/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-malformedJSON.json b/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-malformedJSON.json
index 0b8e302ce2..b8a2232143 100644
--- a/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-malformedJSON.json
+++ b/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-malformedJSON.json
@@ -4,6 +4,10 @@
"displayLabel" : "rm.caveat.classification.group",
"description" : "rm.caveat.classification.description",
"type" : "HIERARCHICAL",
+ "model" :
+ {
+ "property" : "clf:classification"
+ },
"marks" :
[[
{
diff --git a/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-missingMarkId.json b/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-missingMarkId.json
index 01a5d8f985..84783ad7ed 100644
--- a/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-missingMarkId.json
+++ b/rm-server/unit-test/resources/alfresco/caveat/rm-caveats-missingMarkId.json
@@ -4,6 +4,10 @@
"displayLabel" : "rm.caveat.classification.group",
"description" : "rm.caveat.classification.description",
"type" : "HIERARCHICAL",
+ "model" :
+ {
+ "property" : "clf:classification"
+ },
"marks" :
[
{