mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Revert "RM-2606 Classify the head of the version history."
This reverts commit ffc29c05d4643780c9dcbb568eb0a89838009886. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@113431 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -196,7 +196,6 @@
|
|||||||
<property name="classificationServiceBootstrap" ref="classificationServiceBootstrap"/>
|
<property name="classificationServiceBootstrap" ref="classificationServiceBootstrap"/>
|
||||||
<property name="freezeService" ref="FreezeService"/>
|
<property name="freezeService" ref="FreezeService"/>
|
||||||
<property name="referredMetadataService" ref="mr.ReferredMetadataService" />
|
<property name="referredMetadataService" ref="mr.ReferredMetadataService" />
|
||||||
<property name="versionService" ref="VersionService" />
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="ContentClassificationService" class="org.springframework.aop.framework.ProxyFactoryBean">
|
<bean id="ContentClassificationService" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||||
|
@@ -23,13 +23,6 @@ import static org.alfresco.module.org_alfresco_module_rm.util.RMParameterCheck.c
|
|||||||
import static org.alfresco.util.ParameterCheck.mandatory;
|
import static org.alfresco.util.ParameterCheck.mandatory;
|
||||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.model.QuickShareModel;
|
import org.alfresco.model.QuickShareModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.InvalidNode;
|
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.InvalidNode;
|
||||||
@@ -42,14 +35,15 @@ import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl;
|
|||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||||
import org.alfresco.repo.version.common.VersionUtil;
|
|
||||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.version.Version;
|
|
||||||
import org.alfresco.service.cmr.version.VersionHistory;
|
|
||||||
import org.alfresco.service.cmr.version.VersionService;
|
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A service to handle the classification of content.
|
* A service to handle the classification of content.
|
||||||
*
|
*
|
||||||
@@ -59,24 +53,22 @@ import org.alfresco.service.namespace.QName;
|
|||||||
public class ContentClassificationServiceImpl extends ServiceBaseImpl
|
public class ContentClassificationServiceImpl extends ServiceBaseImpl
|
||||||
implements ContentClassificationService, ClassifiedContentModel
|
implements ContentClassificationService, ClassifiedContentModel
|
||||||
{
|
{
|
||||||
/** A set containing the property names reserved for use by the version service. */
|
|
||||||
private static final Set<String> RESERVED_PROPERTIES = Sets.newHashSet(VersionUtil.RESERVED_PROPERTY_NAMES);
|
|
||||||
|
|
||||||
private ClassificationLevelManager levelManager;
|
private ClassificationLevelManager levelManager;
|
||||||
private ClassificationReasonManager reasonManager;
|
private ClassificationReasonManager reasonManager;
|
||||||
private SecurityClearanceService securityClearanceService;
|
private SecurityClearanceService securityClearanceService;
|
||||||
private ClassificationServiceBootstrap classificationServiceBootstrap;
|
private ClassificationServiceBootstrap classificationServiceBootstrap;
|
||||||
private FreezeService freezeService;
|
private FreezeService freezeService;
|
||||||
private ReferredMetadataService referredMetadataService;
|
private ReferredMetadataService referredMetadataService;
|
||||||
private VersionService versionService;
|
|
||||||
|
|
||||||
public void setLevelManager(ClassificationLevelManager levelManager) { this.levelManager = levelManager; }
|
public void setLevelManager(ClassificationLevelManager levelManager) { this.levelManager = levelManager; }
|
||||||
public void setReasonManager(ClassificationReasonManager reasonManager) { this.reasonManager = reasonManager; }
|
public void setReasonManager(ClassificationReasonManager reasonManager) { this.reasonManager = reasonManager; }
|
||||||
public void setSecurityClearanceService(SecurityClearanceService securityClearanceService) { this.securityClearanceService = securityClearanceService; }
|
public void setSecurityClearanceService(SecurityClearanceService securityClearanceService) { this.securityClearanceService = securityClearanceService; }
|
||||||
public void setClassificationServiceBootstrap(ClassificationServiceBootstrap classificationServiceBootstrap) { this.classificationServiceBootstrap = classificationServiceBootstrap; }
|
public void setClassificationServiceBootstrap(ClassificationServiceBootstrap classificationServiceBootstrap) { this.classificationServiceBootstrap = classificationServiceBootstrap; }
|
||||||
public void setFreezeService(FreezeService service) { this.freezeService = service; }
|
public void setFreezeService(FreezeService service) { this.freezeService = service; }
|
||||||
public void setReferredMetadataService(ReferredMetadataService service) { this.referredMetadataService = service; }
|
public void setReferredMetadataService(ReferredMetadataService service)
|
||||||
public void setVersionService(VersionService service) { this.versionService = service; }
|
{
|
||||||
|
this.referredMetadataService = service;
|
||||||
|
}
|
||||||
|
|
||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
@@ -138,55 +130,11 @@ public class ContentClassificationServiceImpl extends ServiceBaseImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
nodeService.addAspect(content, ASPECT_CLASSIFIED, properties);
|
nodeService.addAspect(content, ASPECT_CLASSIFIED, properties);
|
||||||
|
|
||||||
// Classify the version history if one exists.
|
|
||||||
if (versionService.isVersioned(content))
|
|
||||||
{
|
|
||||||
replaceHeadOfVersionHistory(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensure that the latest version in the version store is classified. This it to ensure that if someone
|
|
||||||
* tries to access the content from the version store directly then they are not able to download it.
|
|
||||||
*
|
|
||||||
* @param content The node being classified.
|
|
||||||
*/
|
|
||||||
protected void replaceHeadOfVersionHistory(final NodeRef content)
|
|
||||||
{
|
|
||||||
VersionHistory versionHistory = versionService.getVersionHistory(content);
|
|
||||||
Version headVersion = versionHistory.getHeadVersion();
|
|
||||||
boolean onlyOneVersion = headVersion.equals(versionHistory.getRootVersion());
|
|
||||||
Map<QName, Serializable> headProperties = nodeService.getProperties(headVersion.getVersionedNodeRef());
|
|
||||||
Map<String, Serializable> versionProperties = headVersion.getVersionProperties();
|
|
||||||
|
|
||||||
// Delete the head version, as we cannot add aspects to historical content.
|
|
||||||
versionService.deleteVersion(content, headVersion);
|
|
||||||
|
|
||||||
if (onlyOneVersion)
|
|
||||||
{
|
|
||||||
// Recreate the initial entry in the version store.
|
|
||||||
versionService.ensureVersioningEnabled(content, headProperties);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Recreate the version (without the reserved properties - which are added by the version service).
|
|
||||||
Map<String, Serializable> newProperties = new HashMap<String, Serializable>();
|
|
||||||
for (Map.Entry<String, Serializable> entry : versionProperties.entrySet())
|
|
||||||
{
|
|
||||||
if (!RESERVED_PROPERTIES.contains(entry.getKey()))
|
|
||||||
{
|
|
||||||
newProperties.put(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
versionService.createVersion(content, newProperties);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the properties contained in the {@link ClassificationAspectProperties}.
|
* Validate the properties contained in the {@link ClassificationAspectProperties}.
|
||||||
*
|
*
|
||||||
@@ -278,14 +226,14 @@ public class ContentClassificationServiceImpl extends ServiceBaseImpl
|
|||||||
@Override
|
@Override
|
||||||
public boolean hasClearance(NodeRef nodeRef)
|
public boolean hasClearance(NodeRef nodeRef)
|
||||||
{
|
{
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
if (nodeService.exists(nodeRef))
|
if (nodeService.exists(nodeRef))
|
||||||
{
|
{
|
||||||
// Get the node's current classification
|
// Get the node's current classification
|
||||||
ClassificationLevel currentClassification = getCurrentClassification(nodeRef);
|
ClassificationLevel currentClassification = getCurrentClassification(nodeRef);
|
||||||
result = securityClearanceService.isCurrentUserClearedForClassification(currentClassification.getId());
|
result = securityClearanceService.isCurrentUserClearedForClassification(currentClassification.getId());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
@@ -31,14 +32,12 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.model.QuickShareModel;
|
import org.alfresco.model.QuickShareModel;
|
||||||
@@ -50,14 +49,10 @@ import org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferredMetad
|
|||||||
import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper;
|
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.AuthenticationUtil;
|
||||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||||
import org.alfresco.repo.version.VersionBaseModel;
|
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
||||||
import org.alfresco.service.cmr.version.Version;
|
|
||||||
import org.alfresco.service.cmr.version.VersionHistory;
|
|
||||||
import org.alfresco.service.cmr.version.VersionService;
|
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -87,7 +82,6 @@ public class ContentClassificationServiceImplUnitTest implements ClassifiedConte
|
|||||||
@Mock SecurityClearanceService mockSecurityClearanceService;
|
@Mock SecurityClearanceService mockSecurityClearanceService;
|
||||||
@Mock AuthenticationUtil mockAuthenticationUtil;
|
@Mock AuthenticationUtil mockAuthenticationUtil;
|
||||||
@Mock ReferredMetadataService mockReferredMetadataService;
|
@Mock ReferredMetadataService mockReferredMetadataService;
|
||||||
@Mock VersionService mockVersionService;
|
|
||||||
@Mock ClassificationAspectProperties mockPropertiesDTO;
|
@Mock ClassificationAspectProperties mockPropertiesDTO;
|
||||||
@Captor ArgumentCaptor<Map<QName, Serializable>> propertiesCaptor;
|
@Captor ArgumentCaptor<Map<QName, Serializable>> propertiesCaptor;
|
||||||
|
|
||||||
@@ -385,53 +379,4 @@ public class ContentClassificationServiceImplUnitTest implements ClassifiedConte
|
|||||||
|
|
||||||
assertFalse(contentClassificationServiceImpl.isClassified(nodeRef));
|
assertFalse(contentClassificationServiceImpl.isClassified(nodeRef));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check that replacing the only version will use ensureVersioningEnabled. */
|
|
||||||
@Test public void replaceHeadOfVersionHistory_onlyOneVersion()
|
|
||||||
{
|
|
||||||
NodeRef content = new NodeRef("fake://content/");
|
|
||||||
VersionHistory mockVersionHistory = mock(VersionHistory.class);
|
|
||||||
when(mockVersionService.getVersionHistory(content)).thenReturn(mockVersionHistory);
|
|
||||||
Version mockVersion = mock(Version.class);
|
|
||||||
when(mockVersionHistory.getHeadVersion()).thenReturn(mockVersion);
|
|
||||||
when(mockVersionHistory.getRootVersion()).thenReturn(mockVersion);
|
|
||||||
NodeRef versionedNodeRef = new NodeRef("fake://versionedNodeRef/");
|
|
||||||
when(mockVersion.getVersionedNodeRef()).thenReturn(versionedNodeRef);
|
|
||||||
Map<QName, Serializable> properties = new HashMap<>();
|
|
||||||
when(mockNodeService.getProperties(versionedNodeRef)).thenReturn(properties);
|
|
||||||
|
|
||||||
// Call the method under test.
|
|
||||||
contentClassificationServiceImpl.replaceHeadOfVersionHistory(content);
|
|
||||||
|
|
||||||
verify(mockVersionService).deleteVersion(content, mockVersion);
|
|
||||||
verify(mockVersionService).ensureVersioningEnabled(content, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check that when replacing a later version than the initial one, the entry in the version history is deleted and
|
|
||||||
* recreated. Ensure that properties from {link VersionUtil.RESERVED_PROPERTY_NAMES} are removed from the properties
|
|
||||||
* before calling {@link VersionService.createVersion}.
|
|
||||||
*/
|
|
||||||
@Test public void replaceHeadOfVersionHistory_twoVersions()
|
|
||||||
{
|
|
||||||
NodeRef content = new NodeRef("fake://content/");
|
|
||||||
VersionHistory mockVersionHistory = mock(VersionHistory.class);
|
|
||||||
when(mockVersionService.getVersionHistory(content)).thenReturn(mockVersionHistory);
|
|
||||||
Version mockHeadVersion = mock(Version.class);
|
|
||||||
when(mockVersionHistory.getHeadVersion()).thenReturn(mockHeadVersion);
|
|
||||||
Version mockRootVersion = mock(Version.class);
|
|
||||||
when(mockVersionHistory.getRootVersion()).thenReturn(mockRootVersion);
|
|
||||||
Map<String, Serializable> versionProperties = ImmutableMap.of("ClassificationKey", "ClassificationValue",
|
|
||||||
"VersionNumber", "1.1",
|
|
||||||
VersionBaseModel.PROP_CREATED_DATE, "DateToBeIgnored");
|
|
||||||
when(mockHeadVersion.getVersionProperties()).thenReturn(versionProperties);
|
|
||||||
|
|
||||||
// Call the method under test.
|
|
||||||
contentClassificationServiceImpl.replaceHeadOfVersionHistory(content);
|
|
||||||
|
|
||||||
verify(mockVersionService).deleteVersion(content, mockHeadVersion);
|
|
||||||
Map<String, Serializable> expectedVersionProperties = ImmutableMap.of("ClassificationKey", "ClassificationValue",
|
|
||||||
"VersionNumber", "1.1");
|
|
||||||
verify(mockVersionService).createVersion(content, expectedVersionProperties);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user