diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml
index f76d6c5c53..70bd039bf1 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml
@@ -925,12 +925,20 @@
-
+
+
+
+
+
\ No newline at end of file
diff --git a/rm-server/pom.xml b/rm-server/pom.xml
index 2115a712cf..a34d915b1b 100644
--- a/rm-server/pom.xml
+++ b/rm-server/pom.xml
@@ -392,6 +392,12 @@
+
+ com.google.code.gson
+ gson
+ 2.3.1
+
+
org.alfresco
${webapp.id}
diff --git a/rm-server/source/java/org/alfresco/repo/jscript/app/ClassificationReasonsPropertyDecorator.java b/rm-server/source/java/org/alfresco/repo/jscript/app/ClassificationReasonsPropertyDecorator.java
new file mode 100644
index 0000000000..1eef75024d
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/repo/jscript/app/ClassificationReasonsPropertyDecorator.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2005-2015 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ */
+package org.alfresco.repo.jscript.app;
+
+import static org.alfresco.util.ParameterCheck.mandatory;
+
+import java.io.Serializable;
+
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationReason;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.namespace.QName;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONAware;
+import org.json.simple.JSONObject;
+
+import com.google.gson.Gson;
+
+/**
+ * Classification reasons property decorator
+ *
+ * @author Tuna Aksoy
+ * @since 3.0
+ */
+public class ClassificationReasonsPropertyDecorator extends BasePropertyDecorator
+{
+ /** Constants */
+ protected static final String ID = "id";
+ protected static final String LABEL = "label";
+ protected static final String VALUE = "value";
+ protected static final String DISPLAY_LABEL = "displayLabel";
+ protected static final String FULL_REASON = "fullReason";
+
+ /** Classification scheme service */
+ private ClassificationSchemeService classificationSchemeService;
+
+ /**
+ * @return the classificationSchemeService
+ */
+ protected ClassificationSchemeService getClassificationSchemeService()
+ {
+ return this.classificationSchemeService;
+ }
+
+ /**
+ * @param classificationSchemeService the classificationSchemeService to set
+ */
+ public void setClassificationSchemeService(ClassificationSchemeService classificationSchemeService)
+ {
+ this.classificationSchemeService = classificationSchemeService;
+ }
+
+ /**
+ * @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
+ */
+ @SuppressWarnings("unchecked")
+ public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
+ {
+ mandatory("value", value);
+
+ JSONArray jsonArray = new JSONArray();
+
+ JSONArray classificationReasonIds = new Gson().fromJson(value.toString(), JSONArray.class);
+ for (int i = 0; i < classificationReasonIds.size(); i++)
+ {
+ String classificationReasonId = (String) classificationReasonIds.get(i);
+ ClassificationReason classificationReason = getClassificationSchemeService().getClassificationReasonById(classificationReasonId);
+ String classificationReasonDisplayLabel = classificationReason.getDisplayLabel();
+ String classificationFullReason = classificationReasonId + ": " + classificationReasonDisplayLabel;
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put(ID, classificationReasonId);
+ jsonObject.put(LABEL, classificationFullReason);
+ jsonObject.put(VALUE, classificationReasonId);
+ jsonObject.put(DISPLAY_LABEL, classificationReasonDisplayLabel);
+ jsonObject.put(FULL_REASON, classificationFullReason);
+
+ jsonArray.add(jsonObject);
+ }
+
+ return jsonArray;
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/repo/jscript/app/ClassificationPropertyDecorator.java b/rm-server/source/java/org/alfresco/repo/jscript/app/CurrentClassificationPropertyDecorator.java
similarity index 91%
rename from rm-server/source/java/org/alfresco/repo/jscript/app/ClassificationPropertyDecorator.java
rename to rm-server/source/java/org/alfresco/repo/jscript/app/CurrentClassificationPropertyDecorator.java
index 1e73d0af58..a09def68e8 100644
--- a/rm-server/source/java/org/alfresco/repo/jscript/app/ClassificationPropertyDecorator.java
+++ b/rm-server/source/java/org/alfresco/repo/jscript/app/CurrentClassificationPropertyDecorator.java
@@ -29,16 +29,16 @@ import org.json.simple.JSONAware;
import org.json.simple.JSONObject;
/**
- * Classification property decorator
+ * Current classification property decorator
*
* @author Tuna Aksoy
* @since 3.0
*/
-public class ClassificationPropertyDecorator extends BasePropertyDecorator
+public class CurrentClassificationPropertyDecorator extends BasePropertyDecorator
{
/** Constants */
- private static final String ID = "id";
- private static final String LABEL = "label";
+ protected static final String ID = "id";
+ protected static final String LABEL = "label";
/** Classification scheme service */
private ClassificationSchemeService classificationSchemeService;
diff --git a/rm-server/unit-test/java/org/alfresco/repo/jscript/app/ClassificationReasonsPropertyDecoratorUnitTest.java b/rm-server/unit-test/java/org/alfresco/repo/jscript/app/ClassificationReasonsPropertyDecoratorUnitTest.java
new file mode 100644
index 0000000000..d9049c40a9
--- /dev/null
+++ b/rm-server/unit-test/java/org/alfresco/repo/jscript/app/ClassificationReasonsPropertyDecoratorUnitTest.java
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2005-2015 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ */
+package org.alfresco.repo.jscript.app;
+
+import static org.alfresco.repo.jscript.app.ClassificationReasonsPropertyDecorator.DISPLAY_LABEL;
+import static org.alfresco.repo.jscript.app.ClassificationReasonsPropertyDecorator.FULL_REASON;
+import static org.alfresco.repo.jscript.app.ClassificationReasonsPropertyDecorator.ID;
+import static org.alfresco.repo.jscript.app.ClassificationReasonsPropertyDecorator.LABEL;
+import static org.alfresco.repo.jscript.app.ClassificationReasonsPropertyDecorator.VALUE;
+import static org.alfresco.util.GUID.generate;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.doReturn;
+
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationReason;
+import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonSyntaxException;
+
+/**
+ * Classification reasons property decorator unit test
+ *
+ * @author Tuna Aksoy
+ * @since 3.0
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class ClassificationReasonsPropertyDecoratorUnitTest
+{
+ /** Classification reasons property decorator */
+ private @InjectMocks ClassificationReasonsPropertyDecorator decorator = new ClassificationReasonsPropertyDecorator();
+
+ /** Mocked classification scheme service */
+ private @Mock ClassificationSchemeService mockedClassificationSchemeService;
+
+ /**
+ * Given that no classification reason id is supplied
+ * When decorated
+ * Then an {@link IllegalArgumentException} is thrown
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testDecoratorWithoutClassificationId()
+ {
+ decorator.decorate(null, null, null);
+ }
+
+ /**
+ * Given that a classification reason id in an invalid format is supplied
+ * When decorated
+ * Then an {@link JsonSyntaxException} is thrown
+ */
+ @Test(expected = JsonSyntaxException.class)
+ public void testDecoratorWithInvalidClassificationReasonId()
+ {
+ String classificationReasonId = generate();
+ String classificationReasonDisplayLabel = generate();
+
+ ClassificationReason classificationReason = new ClassificationReason(classificationReasonId, classificationReasonDisplayLabel);
+ doReturn(classificationReason).when(mockedClassificationSchemeService).getClassificationReasonById(classificationReasonId);
+
+ decorator.decorate(null, null, classificationReasonId);
+ }
+
+ /**
+ * Given that a classification reason id is supplied
+ * When decorated
+ * Then the result is a {@link JSONArray} containing the classification reason id, label, value, display label and full reason
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDecoratorWithClassificationReasonId()
+ {
+ String classificationReasonId = generate();
+ String classificationReasonDisplayLabel = generate();
+ String classificationFullReason = classificationReasonId + ": " + classificationReasonDisplayLabel;
+
+ ClassificationReason classificationReason = new ClassificationReason(classificationReasonId, classificationReasonDisplayLabel);
+ doReturn(classificationReason).when(mockedClassificationSchemeService).getClassificationReasonById(classificationReasonId);
+
+ JSONArray classificationReasonIds = new JSONArray();
+ classificationReasonIds.add(classificationReasonId);
+
+ JSONArray decoratedProperty = (JSONArray) decorator.decorate(null, null, new Gson().toJson(classificationReasonIds));
+ assertNotNull(decoratedProperty);
+ assertEquals(1, decoratedProperty.size());
+
+ JSONObject jsonObject = (JSONObject) decoratedProperty.get(0);
+ assertNotNull(jsonObject);
+
+ assertEquals(classificationReasonId, jsonObject.get(ID));
+ assertEquals(classificationFullReason, jsonObject.get(LABEL));
+ assertEquals(classificationReasonId, jsonObject.get(VALUE));
+ assertEquals(classificationReasonDisplayLabel, jsonObject.get(DISPLAY_LABEL));
+ assertEquals(classificationFullReason, jsonObject.get(FULL_REASON));
+ }
+
+ /**
+ * Given that two classification reason id are supplied
+ * When decorated
+ * Then the result is a {@link JSONArray} containing the classification reason ids,
+ * labels, values, display labels and full reasons of both classification reasons
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDecorateWithMultipleClassificationReasonIds()
+ {
+ String classificationReasonId1 = generate();
+ String classificationReasonDisplayLabel1 = generate();
+ String classificationFullReason1 = classificationReasonId1 + ": " + classificationReasonDisplayLabel1;
+
+ String classificationReasonId2 = generate();
+ String classificationReasonDisplayLabel2 = generate();
+ String classificationFullReason2 = classificationReasonId2 + ": " + classificationReasonDisplayLabel2;
+
+ ClassificationReason classificationReason1 = new ClassificationReason(classificationReasonId1, classificationReasonDisplayLabel1);
+ ClassificationReason classificationReason2 = new ClassificationReason(classificationReasonId2, classificationReasonDisplayLabel2);
+ doReturn(classificationReason1).when(mockedClassificationSchemeService).getClassificationReasonById(classificationReasonId1);
+ doReturn(classificationReason2).when(mockedClassificationSchemeService).getClassificationReasonById(classificationReasonId2);
+
+ JSONArray classificationReasonIds = new JSONArray();
+ classificationReasonIds.add(classificationReasonId1);
+ classificationReasonIds.add(classificationReasonId2);
+
+ JSONArray decoratedProperty = (JSONArray) decorator.decorate(null, null, new Gson().toJson(classificationReasonIds));
+ assertNotNull(decoratedProperty);
+ assertEquals(2, decoratedProperty.size());
+
+ JSONObject jsonObject1 = (JSONObject) decoratedProperty.get(0);
+ assertNotNull(jsonObject1);
+
+ assertEquals(classificationReasonId1, jsonObject1.get(ID));
+ assertEquals(classificationFullReason1, jsonObject1.get(LABEL));
+ assertEquals(classificationReasonId1, jsonObject1.get(VALUE));
+ assertEquals(classificationReasonDisplayLabel1, jsonObject1.get(DISPLAY_LABEL));
+ assertEquals(classificationFullReason1, jsonObject1.get(FULL_REASON));
+
+ JSONObject jsonObject2 = (JSONObject) decoratedProperty.get(1);
+ assertNotNull(jsonObject2);
+
+ assertEquals(classificationReasonId2, jsonObject2.get(ID));
+ assertEquals(classificationFullReason2, jsonObject2.get(LABEL));
+ assertEquals(classificationReasonId2, jsonObject2.get(VALUE));
+ assertEquals(classificationReasonDisplayLabel2, jsonObject2.get(DISPLAY_LABEL));
+ assertEquals(classificationFullReason2, jsonObject2.get(FULL_REASON));
+ }
+}
\ No newline at end of file
diff --git a/rm-server/unit-test/java/org/alfresco/repo/jscript/app/ClassificationPropertyDecoratorTest.java b/rm-server/unit-test/java/org/alfresco/repo/jscript/app/CurrentClassificationPropertyDecoratorUnitTest.java
similarity index 75%
rename from rm-server/unit-test/java/org/alfresco/repo/jscript/app/ClassificationPropertyDecoratorTest.java
rename to rm-server/unit-test/java/org/alfresco/repo/jscript/app/CurrentClassificationPropertyDecoratorUnitTest.java
index aab94ad030..dd4d5211b7 100644
--- a/rm-server/unit-test/java/org/alfresco/repo/jscript/app/ClassificationPropertyDecoratorTest.java
+++ b/rm-server/unit-test/java/org/alfresco/repo/jscript/app/CurrentClassificationPropertyDecoratorUnitTest.java
@@ -18,6 +18,8 @@
*/
package org.alfresco.repo.jscript.app;
+import static org.alfresco.repo.jscript.app.CurrentClassificationPropertyDecorator.ID;
+import static org.alfresco.repo.jscript.app.CurrentClassificationPropertyDecorator.LABEL;
import static org.alfresco.util.GUID.generate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -25,51 +27,36 @@ import static org.mockito.Mockito.doReturn;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevel;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService;
-import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.json.simple.JSONObject;
-import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
/**
- * Classification property decorator test
+ * Current classification property decorator unit test
*
* @author Tuna Aksoy
* @since 3.0
*/
-public class ClassificationPropertyDecoratorTest extends BaseUnitTest
+@RunWith(MockitoJUnitRunner.class)
+public class CurrentClassificationPropertyDecoratorUnitTest
{
- /** Constants */
- private static final String ID = "id";
- private static final String LABEL = "label";
-
- /** Classification property decorator */
- private ClassificationPropertyDecorator decorator;
+ /** Current classification property decorator */
+ private @InjectMocks CurrentClassificationPropertyDecorator decorator = new CurrentClassificationPropertyDecorator();
/** Mocked classification scheme service */
private @Mock ClassificationSchemeService mockedClassificationSchemeService;
- /**
- * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest#before()
- */
- @Before
- @Override
- public void before() throws Exception
- {
- super.before();
- decorator = new ClassificationPropertyDecorator();
- decorator.setClassificationSchemeService(mockedClassificationSchemeService);
- }
-
/**
* Given that no classification id is supplied
* When decorated
* Then an {@link IllegalArgumentException} is thrown
*/
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void testDecoratorWithoutClassificationId()
{
- exception.expect(IllegalArgumentException.class);
decorator.decorate(null, null, null);
}