mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
This is the RM-specific parts of the refactor for classified renditions - see RM-2549.
This builds on the separate MetadataReferral services to link renditions to classified source nodes via a new classifiedRendition aspect which defines a new classifiedRendition assoc. The spring bean 'classifiedRenditionAssoc' defines that only the clf:classified aspect and its metadata will be linked. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/classified_renditions@111643 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -45,6 +45,7 @@ import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationE
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.LevelIdNotFound;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.freeze.FreezeService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferredMetadataService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
@@ -80,6 +81,7 @@ public class ContentClassificationServiceImplUnitTest implements ClassifiedConte
|
||||
@Mock FreezeService mockFreezeService;
|
||||
@Mock SecurityClearanceService mockSecurityClearanceService;
|
||||
@Mock AuthenticationUtil mockAuthenticationUtil;
|
||||
@Mock ReferredMetadataService mockReferredMetadataService;
|
||||
@Mock ClassificationAspectProperties mockPropertiesDTO;
|
||||
@Captor ArgumentCaptor<Map<QName, Serializable>> propertiesCaptor;
|
||||
|
||||
|
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.module.org_alfresco_module_rm.model.clf;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
import org.alfresco.model.RenditionModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.clf.aspect.ClassifiedAspect;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.CoreServicesExtras;
|
||||
import org.alfresco.service.cmr.rendition.RenditionService;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ClassifiedRenditions}.
|
||||
*
|
||||
* @since 3.0.a
|
||||
*/
|
||||
public class ClassifiedRenditionsUnitTest implements ClassifiedContentModel
|
||||
{
|
||||
private static final NodeRef SOURCE_NODE = new NodeRef("node://ref/");
|
||||
private static final NodeRef RENDITION_1 = new NodeRef("node://rendition1/");
|
||||
private static final NodeRef RENDITION_2 = new NodeRef("node://rendition2/");
|
||||
|
||||
@InjectMocks ClassifiedAspect classifiedAspect;
|
||||
|
||||
@Mock AuthenticationUtil mockAuthenticationUtil;
|
||||
@Mock ContentClassificationService mockContentClassificationService;
|
||||
@Mock CoreServicesExtras mockCoreServicesExtras;
|
||||
@Mock NodeService mockNodeService;
|
||||
@Mock RenditionService mockRenditionService;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
initMocks(this);
|
||||
|
||||
MockAuthenticationUtilHelper.setup(mockAuthenticationUtil);
|
||||
}
|
||||
|
||||
@Test public void newRenditionOfClassifiedNodeShouldItselfBeClassified()
|
||||
{
|
||||
when(mockRenditionService.getRenditions(SOURCE_NODE))
|
||||
.thenReturn(asList(rendition(SOURCE_NODE, RENDITION_1), rendition(SOURCE_NODE, RENDITION_2)));
|
||||
when(mockRenditionService.getSourceNode(RENDITION_1)).thenReturn(rendition(SOURCE_NODE, RENDITION_1));
|
||||
when(mockRenditionService.getSourceNode(RENDITION_2)).thenReturn(rendition(SOURCE_NODE, RENDITION_2));
|
||||
when(mockContentClassificationService.isClassified(SOURCE_NODE)).thenReturn(true);
|
||||
|
||||
final ClassifiedRenditions behaviour = new ClassifiedRenditions();
|
||||
behaviour.setAuthenticationUtil(mockAuthenticationUtil);
|
||||
behaviour.setContentClassificationService(mockContentClassificationService);
|
||||
behaviour.setCoreServicesExtras(mockCoreServicesExtras);
|
||||
behaviour.setNodeService(mockNodeService);
|
||||
behaviour.setRenditionService(mockRenditionService);
|
||||
|
||||
behaviour.onAddAspect(RENDITION_2, RenditionModel.ASPECT_RENDITION);
|
||||
|
||||
verify(mockCoreServicesExtras).copyAspect(SOURCE_NODE, RENDITION_2, ClassifiedContentModel.ASPECT_CLASSIFIED);
|
||||
}
|
||||
|
||||
/** Creates a test Rendition ChildAssociationRef. */
|
||||
private ChildAssociationRef rendition(NodeRef source, NodeRef rendition)
|
||||
{
|
||||
return new ChildAssociationRef(RenditionModel.ASSOC_RENDITION, source, RenditionModel.ASSOC_RENDITION, rendition);
|
||||
}
|
||||
}
|
@@ -19,52 +19,46 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.model.clf.aspect;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.RenditionModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.MissingDowngradeInstructions;
|
||||
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.classification.model.ClassifiedContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.CoreServicesExtras;
|
||||
import org.alfresco.service.cmr.rendition.RenditionService;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link ClassifiedAspect}.
|
||||
*
|
||||
* @author Tom Page
|
||||
* @since 3.0.a
|
||||
* @author Neil Mc Erlean
|
||||
* @since 2.4.a
|
||||
*/
|
||||
public class ClassifiedAspectUnitTest implements ClassifiedContentModel
|
||||
{
|
||||
private static final NodeRef NODE_REF = new NodeRef("node://Ref/");
|
||||
private static final NodeRef RENDITION_1 = new NodeRef("node://rendition1/");
|
||||
private static final NodeRef RENDITION_2 = new NodeRef("node://rendition2/");
|
||||
private static final ClassificationLevel TOP_SECRET = new ClassificationLevel("Top Secret", "Top Secret");
|
||||
private static final ClassificationLevel SECRET = new ClassificationLevel("Secret", "Secret");
|
||||
|
||||
@InjectMocks ClassifiedAspect classifiedAspect;
|
||||
@Mock ClassificationSchemeService mockClassificationSchemeService;
|
||||
@Mock CoreServicesExtras mockCoreServicesExtras;
|
||||
@Mock NodeService mockNodeService;
|
||||
@Mock RenditionService mockRenditionService;
|
||||
@Mock ReferralAdminService mockReferralAdminService;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
@@ -135,50 +129,20 @@ public class ClassifiedAspectUnitTest implements ClassifiedContentModel
|
||||
classifiedAspect.checkConsistencyOfProperties(NODE_REF);
|
||||
}
|
||||
|
||||
/** Check that when a node is classified, its renditions are also classified. */
|
||||
@Test public void classificationOfNodeShouldClassifyRenditions()
|
||||
@Test public void newlyClassifiedNodeShouldLinkItsMetadataToAllRenditions()
|
||||
{
|
||||
for (NodeRef n : asList(NODE_REF, RENDITION_1, RENDITION_2))
|
||||
{
|
||||
when(mockNodeService.hasAspect(n, ASPECT_CLASSIFIED)).thenReturn(true);
|
||||
}
|
||||
when(mockClassificationSchemeService.getClassificationLevelById(eq("Top Secret"))).thenReturn(TOP_SECRET);
|
||||
when(mockClassificationSchemeService.getClassificationLevelById(eq("Secret"))).thenReturn(SECRET);
|
||||
when(mockClassificationSchemeService.getReclassification(any(), any())).thenReturn(ClassificationSchemeService.Reclassification.DOWNGRADE);
|
||||
when(mockRenditionService.getRenditions(eq(NODE_REF)))
|
||||
when(mockRenditionService.getRenditions(NODE_REF))
|
||||
.thenReturn(asList(rendition(NODE_REF, RENDITION_1), rendition(NODE_REF, RENDITION_2)));
|
||||
for (final NodeRef rendition : asList(RENDITION_1, RENDITION_2))
|
||||
{
|
||||
when(mockRenditionService.getSourceNode(rendition)).thenReturn(rendition(NODE_REF, rendition));
|
||||
}
|
||||
|
||||
classifiedAspect.onAddAspect(NODE_REF, ASPECT_CLASSIFIED);
|
||||
|
||||
for (NodeRef rendition : asList(RENDITION_1, RENDITION_2))
|
||||
{
|
||||
verify(mockCoreServicesExtras).copyAspect(NODE_REF, rendition, ClassifiedContentModel.ASPECT_CLASSIFIED);
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void reclassificationOfNodeShouldReclassifyRenditions()
|
||||
{
|
||||
for (NodeRef n : asList(NODE_REF, RENDITION_1, RENDITION_2))
|
||||
{
|
||||
when(mockNodeService.hasAspect(n, ASPECT_CLASSIFIED)).thenReturn(true);
|
||||
}
|
||||
when(mockClassificationSchemeService.getClassificationLevelById("Top Secret")).thenReturn(TOP_SECRET);
|
||||
when(mockClassificationSchemeService.getClassificationLevelById("Secret")).thenReturn(SECRET);
|
||||
when(mockClassificationSchemeService.getReclassification(any(), any())).thenReturn(ClassificationSchemeService.Reclassification.DOWNGRADE);
|
||||
when(mockRenditionService.getRenditions(eq(NODE_REF)))
|
||||
.thenReturn(asList(rendition(NODE_REF, RENDITION_1), rendition(NODE_REF, RENDITION_2)));
|
||||
|
||||
Map<QName, Serializable> oldProps = new HashMap<>();
|
||||
oldProps.put(PROP_CLASSIFIED_BY, "userone");
|
||||
oldProps.put(PROP_CURRENT_CLASSIFICATION, "Top Secret");
|
||||
Map<QName, Serializable> newProps = new HashMap<>(oldProps);
|
||||
newProps.put(PROP_CURRENT_CLASSIFICATION, "Secret");
|
||||
|
||||
classifiedAspect.onUpdateProperties(NODE_REF, oldProps, newProps);
|
||||
|
||||
for (NodeRef rendition : asList(RENDITION_1, RENDITION_2))
|
||||
{
|
||||
verify(mockCoreServicesExtras).copyAspect(NODE_REF, rendition, ClassifiedContentModel.ASPECT_CLASSIFIED);
|
||||
verify(mockReferralAdminService).attachReferrer(rendition, NODE_REF, ASSOC_CLASSIFIED_RENDITION);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user