mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-2562: Deleting record from versions produces inconsistent behaviour
* Version history shows destroyed version despite meta-data shell of version record still being present (RM-2839) * Integration tests (RM-2842) +review RM-223 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.3@119506 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -29,6 +29,7 @@ import org.alfresco.module.org_alfresco_module_rm.action.RMDispositionActionExec
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition;
|
||||
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
|
||||
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService;
|
||||
import org.alfresco.repo.content.cleanup.EagerContentStoreCleaner;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
@@ -36,6 +37,7 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
@@ -54,6 +56,9 @@ public class DestroyAction extends RMDispositionActionExecuterAbstractBase
|
||||
|
||||
/** Capability service */
|
||||
private CapabilityService capabilityService;
|
||||
|
||||
/** Recordable version service */
|
||||
private RecordableVersionService recordableVersionService;
|
||||
|
||||
/** Indicates if ghosting is enabled or not */
|
||||
private boolean ghostingEnabled = true;
|
||||
@@ -73,6 +78,14 @@ public class DestroyAction extends RMDispositionActionExecuterAbstractBase
|
||||
{
|
||||
this.capabilityService = capabilityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param recordableVersionService recordable version service
|
||||
*/
|
||||
public void setRecordableVersionService(RecordableVersionService recordableVersionService)
|
||||
{
|
||||
this.recordableVersionService = recordableVersionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ghostingEnabled true if ghosting is enabled, false otherwise
|
||||
@@ -150,6 +163,13 @@ public class DestroyAction extends RMDispositionActionExecuterAbstractBase
|
||||
|
||||
if (isGhostOnDestroySetForAction(action, record))
|
||||
{
|
||||
// mark version as destroyed
|
||||
Version version = recordableVersionService.getRecordedVersion(record);
|
||||
if (version != null)
|
||||
{
|
||||
recordableVersionService.destroyRecordedVersion(version);
|
||||
}
|
||||
|
||||
// Add the ghosted aspect
|
||||
getNodeService().addAspect(record, ASPECT_GHOSTED, null);
|
||||
}
|
||||
|
@@ -18,9 +18,6 @@
|
||||
*/
|
||||
package org.alfresco.module.org_alfresco_module_rm.model.rma.aspect;
|
||||
|
||||
import static org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel.PROP_VERSIONED_NODEREF;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel.PROP_VERSION_LABEL;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
|
||||
@@ -34,9 +31,6 @@ import org.alfresco.repo.policy.annotation.BehaviourKind;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
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.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* rmv:versionRecord behaviour bean
|
||||
@@ -51,22 +45,11 @@ import org.apache.commons.lang.StringUtils;
|
||||
public class VersionRecordAspect extends BaseBehaviourBean
|
||||
implements NodeServicePolicies.BeforeDeleteNodePolicy
|
||||
{
|
||||
/** version service */
|
||||
private VersionService versionService;
|
||||
|
||||
/** recordable version service */
|
||||
private RecordableVersionService recordableVersionService;
|
||||
|
||||
/** relationship service */
|
||||
private RelationshipService relationshipService;
|
||||
|
||||
/**
|
||||
* @param versionService version service
|
||||
*/
|
||||
public void setVersionService(VersionService versionService)
|
||||
{
|
||||
this.versionService = versionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param recordableVersionService recordable version service
|
||||
@@ -93,60 +76,48 @@ public class VersionRecordAspect extends BaseBehaviourBean
|
||||
@Behaviour (kind = BehaviourKind.CLASS)
|
||||
public void beforeDeleteNode(final NodeRef nodeRef)
|
||||
{
|
||||
final NodeRef versionedNodeRef = (NodeRef) nodeService.getProperty(nodeRef, PROP_VERSIONED_NODEREF);
|
||||
if (versionedNodeRef != null)
|
||||
final Version version = recordableVersionService.getRecordedVersion(nodeRef);
|
||||
if (version != null)
|
||||
{
|
||||
String versionLabel = (String) nodeService.getProperty(nodeRef, PROP_VERSION_LABEL);
|
||||
if (StringUtils.isNotBlank(versionLabel))
|
||||
authenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
{
|
||||
final VersionHistory versionHistory = versionService.getVersionHistory(versionedNodeRef);
|
||||
if (versionHistory != null)
|
||||
@Override
|
||||
public Void doWork()
|
||||
{
|
||||
final Version version = versionHistory.getVersion(versionLabel);
|
||||
if (version != null)
|
||||
behaviourFilter.disableBehaviour();
|
||||
try
|
||||
{
|
||||
authenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
// mark the associated version as destroyed
|
||||
recordableVersionService.destroyRecordedVersion(version);
|
||||
|
||||
// re-organise the versions relationships ...
|
||||
// if there is only one "to" reference since a version can only have one predecessor
|
||||
Set<Relationship> tos = relationshipService.getRelationshipsTo(nodeRef, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
if (!tos.isEmpty() && tos.size() == 1)
|
||||
{
|
||||
@Override
|
||||
public Void doWork()
|
||||
// if there is some "from" references
|
||||
Set<Relationship> froms = relationshipService.getRelationshipsFrom(nodeRef, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
if (!froms.isEmpty())
|
||||
{
|
||||
behaviourFilter.disableBehaviour();
|
||||
try
|
||||
// get predecessor version relationship
|
||||
Relationship to = tos.iterator().next();
|
||||
|
||||
for (Relationship from : froms)
|
||||
{
|
||||
// mark the associated version as destroyed
|
||||
recordableVersionService.destroyRecordedVersion(version);
|
||||
|
||||
// re-organise the versions relationships ...
|
||||
// if there is only one "to" reference since a version can only have one predecessor
|
||||
Set<Relationship> tos = relationshipService.getRelationshipsTo(nodeRef, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
if (!tos.isEmpty() && tos.size() == 1)
|
||||
{
|
||||
// if there is some "from" references
|
||||
Set<Relationship> froms = relationshipService.getRelationshipsFrom(nodeRef, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
if (!froms.isEmpty())
|
||||
{
|
||||
// get predecessor version relationship
|
||||
Relationship to = tos.iterator().next();
|
||||
|
||||
for (Relationship from : froms)
|
||||
{
|
||||
// point the "to" the all the "from's"
|
||||
relationshipService.addRelationship(RelationshipService.RELATIONSHIP_VERSIONS, to.getSource(), from.getTarget());
|
||||
}
|
||||
}
|
||||
}
|
||||
// point the "to" the all the "from's"
|
||||
relationshipService.addRelationship(RelationshipService.RELATIONSHIP_VERSIONS, to.getSource(), from.getTarget());
|
||||
}
|
||||
finally
|
||||
{
|
||||
behaviourFilter.enableBehaviour();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
behaviourFilter.enableBehaviour();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -56,6 +56,14 @@ public interface RecordableVersionService
|
||||
*/
|
||||
NodeRef getVersionRecord(Version version);
|
||||
|
||||
/**
|
||||
* Gets the version that relates to the version record
|
||||
*
|
||||
* @param versionRecord version record node reference
|
||||
* @return Version version or null if not found
|
||||
*/
|
||||
Version getRecordedVersion(NodeRef record);
|
||||
|
||||
/**
|
||||
* Creates a record from the latest version, marking it as recorded.
|
||||
* <p>
|
||||
|
@@ -55,6 +55,7 @@ import org.alfresco.service.cmr.version.VersionType;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@@ -503,67 +504,30 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
|
||||
|
||||
return versionRecord;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService#getRecordedVersion(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
protected VersionHistory buildVersionHistory(NodeRef versionHistoryRef, NodeRef nodeRef)
|
||||
public Version getRecordedVersion(NodeRef versionRecord)
|
||||
{
|
||||
VersionHistory versionHistory = super.buildVersionHistory(versionHistoryRef, nodeRef);
|
||||
|
||||
// create an empty version history if appropriate
|
||||
if (versionHistoryRef != null &&
|
||||
nodeRef != null &&
|
||||
versionHistory == null &&
|
||||
getAllVersions(versionHistoryRef).isEmpty() == true)
|
||||
Version version = null;
|
||||
NodeRef versionedNodeRef = (NodeRef) nodeService.getProperty(versionRecord, RecordableVersionModel.PROP_VERSIONED_NODEREF);
|
||||
if (versionedNodeRef != null)
|
||||
{
|
||||
versionHistory = new EmptyVersionHistory();
|
||||
String versionLabel = (String) nodeService.getProperty(versionRecord, RecordableVersionModel.PROP_VERSION_LABEL);
|
||||
if (StringUtils.isNotBlank(versionLabel))
|
||||
{
|
||||
VersionHistory versionHistory = getVersionHistory(versionedNodeRef);
|
||||
if (versionHistory != null)
|
||||
{
|
||||
version = versionHistory.getVersion(versionLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return versionHistory;
|
||||
return version;
|
||||
}
|
||||
|
||||
public class EmptyVersionHistory implements VersionHistory
|
||||
{
|
||||
private static final long serialVersionUID = 3449832161314670033L;
|
||||
|
||||
@Override
|
||||
public Version getRootVersion()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getHeadVersion()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Collection<Version> getAllVersions()
|
||||
{
|
||||
return (Collection<Version>)Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getPredecessor(Version version)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Collection<Version> getSuccessors(Version version)
|
||||
{
|
||||
return (Collection<Version>)Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion(String versionLabel)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Freezes audit aspect properties.
|
||||
*
|
||||
|
Reference in New Issue
Block a user