From 2ca633319d6ace06beb345f76896bf7f57116ccb Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Wed, 3 Jun 2015 09:46:09 +0000 Subject: [PATCH] RM-2247 (Add classification banner to document details) RM-2248 (Add classification banner to record details) +review RM git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@105441 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../rm-ui-evaluators-context.xml | 9 ++ .../app/ClassificationPropertyDecorator.java | 75 +++++++++++++++ .../ClassificationPropertyDecoratorTest.java | 94 +++++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 rm-server/source/java/org/alfresco/repo/jscript/app/ClassificationPropertyDecorator.java create mode 100644 rm-server/unit-test/java/org/alfresco/repo/jscript/app/ClassificationPropertyDecoratorTest.java 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 7580c546df..b23d53b94f 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 @@ -922,4 +922,13 @@ + + + + + + \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/repo/jscript/app/ClassificationPropertyDecorator.java b/rm-server/source/java/org/alfresco/repo/jscript/app/ClassificationPropertyDecorator.java new file mode 100644 index 0000000000..1e73d0af58 --- /dev/null +++ b/rm-server/source/java/org/alfresco/repo/jscript/app/ClassificationPropertyDecorator.java @@ -0,0 +1,75 @@ +/* + * 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.ClassificationSchemeService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; +import org.json.simple.JSONAware; +import org.json.simple.JSONObject; + +/** + * Classification property decorator + * + * @author Tuna Aksoy + * @since 3.0 + */ +public class ClassificationPropertyDecorator extends BasePropertyDecorator +{ + /** Constants */ + private static final String ID = "id"; + private static final String LABEL = "label"; + + /** 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); + JSONObject jsonObj = new JSONObject(); + String currentClassificationId = value.toString(); + jsonObj.put(ID, currentClassificationId); + jsonObj.put(LABEL, getClassificationSchemeService().getClassificationLevelById(currentClassificationId).getDisplayLabel()); + return jsonObj; + } +} 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/ClassificationPropertyDecoratorTest.java new file mode 100644 index 0000000000..aab94ad030 --- /dev/null +++ b/rm-server/unit-test/java/org/alfresco/repo/jscript/app/ClassificationPropertyDecoratorTest.java @@ -0,0 +1,94 @@ +/* + * 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.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.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.mockito.Mock; + +/** + * Classification property decorator test + * + * @author Tuna Aksoy + * @since 3.0 + */ +public class ClassificationPropertyDecoratorTest extends BaseUnitTest +{ + /** Constants */ + private static final String ID = "id"; + private static final String LABEL = "label"; + + /** Classification property decorator */ + private ClassificationPropertyDecorator decorator; + + /** 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 + public void testDecoratorWithoutClassificationId() + { + exception.expect(IllegalArgumentException.class); + decorator.decorate(null, null, null); + } + + /** + * Given that a classification id is supplied + * When decorated + * Then the result is a {@link JSONObject} containing the classification id and display label + */ + @Test + public void testDecoratorWithClassificationId() + { + String classificationLevelId = generate(); + String classificationDisplayLabel = generate(); + ClassificationLevel classificationLevel = new ClassificationLevel(classificationLevelId, classificationDisplayLabel); + doReturn(classificationLevel).when(mockedClassificationSchemeService).getClassificationLevelById(classificationLevelId); + + JSONObject decoratedProperty = (JSONObject) decorator.decorate(null, null, classificationLevelId); + assertNotNull(decoratedProperty); + assertEquals(classificationLevelId, decoratedProperty.get(ID)); + assertEquals(classificationDisplayLabel, decoratedProperty.get(LABEL)); + } +}