RM-577: Code refactoring

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@46157 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2013-02-03 21:22:23 +00:00
parent 4bc75f4db9
commit 5c785ae22e
7 changed files with 79 additions and 66 deletions

View File

@@ -20,19 +20,13 @@ package org.alfresco.module.org_alfresco_module_rm.action.dm;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
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.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -56,11 +50,8 @@ public class HideRecordAction extends ActionExecuterAbstractBase implements Reco
/** Node service */
private NodeService nodeService;
/** Permission service */
private PermissionService permissionService;
/** Extended security service */
private ExtendedSecurityService extendedSecurityService;
/** Record service */
private RecordService recordService;
/**
* @param nodeService node service
@@ -71,19 +62,11 @@ public class HideRecordAction extends ActionExecuterAbstractBase implements Reco
}
/**
* @param permissionService permission service
* @param recordService record service
*/
public void setPermissionService(PermissionService permissionService)
public void setRecordService(RecordService recordService)
{
this.permissionService = permissionService;
}
/**
* @param extendedSecurityService extended security service
*/
public void setExtendedSecurityService(ExtendedSecurityService extendedSecurityService)
{
this.extendedSecurityService = extendedSecurityService;
this.recordService = recordService;
}
/**
@@ -94,41 +77,16 @@ public class HideRecordAction extends ActionExecuterAbstractBase implements Reco
{
if (nodeService.hasAspect(actionedUponNodeRef, ASPECT_RECORD) == false)
{
// We cannot hide a document which is not a record
// we cannot hide a document which is not a record
if (logger.isDebugEnabled() == true)
{
logger.debug("Cannot hide the document, because '" + actionedUponNodeRef.toString() + "' is not a record.");
}
}
else if (permissionService.hasPermission(actionedUponNodeRef, PermissionService.WRITE) != AccessStatus.ALLOWED)
{
// We do a sanity check to ensure that the user has at least write permissions on the record
throw new AccessDeniedException("Cannot hide record, because the user '" + AuthenticationUtil.getFullyAuthenticatedUser() + "' does not have write permissions on the record '" + actionedUponNodeRef.toString() + "'.");
}
else if (nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_HIDDEN) == true)
{
// We cannot hide records which are already hidden
if (logger.isDebugEnabled() == true)
{
logger.debug("Cannot hide record, because '" + actionedUponNodeRef.toString() + "' is already hidden.");
}
}
else
{
// remove the child association
NodeRef originatingLocation = (NodeRef) nodeService.getProperty(actionedUponNodeRef, PROP_RECORD_ORIGINATING_LOCATION);
List<ChildAssociationRef> parentAssocs = nodeService.getParentAssocs(actionedUponNodeRef);
for (ChildAssociationRef childAssociationRef : parentAssocs)
{
if (childAssociationRef.isPrimary() == false && childAssociationRef.getParentRef().equals(originatingLocation))
{
nodeService.removeChildAssociation(childAssociationRef);
break;
}
}
// remove the extended security from the node ... this prevents the users from continuing to see the record in searchs and other linked locations
extendedSecurityService.removeAllExtendedReaders(actionedUponNodeRef);
// hide the record from the collaboration site
recordService.hideRecord(actionedUponNodeRef);
}
}

View File

@@ -54,12 +54,12 @@ import org.springframework.extensions.surf.util.I18NUtil;
/**
* Freeze Service Implementation
*
*
* @author Roy Wetherall
* @author Tuna Askoy
* @author Tuna Aksoy
* @since 2.1
*/
public class FreezeServiceImpl implements FreezeService,
public class FreezeServiceImpl implements FreezeService,
RecordsManagementModel,
NodeServicePolicies.BeforeDeleteNodePolicy
{
@@ -168,7 +168,7 @@ public class FreezeServiceImpl implements FreezeService,
/**
* Checks the children for frozen nodes. Throws security error if any are
* found.
*
*
* @param assocs
*/
private void checkChildren(List<ChildAssociationRef> assocs)
@@ -568,7 +568,7 @@ public class FreezeServiceImpl implements FreezeService,
/**
* Creates a hold using the given nodeRef and reason
*
*
* @param nodeRef the nodeRef which will be frozen
* @param reason the reason why the record will be frozen
* @return NodeRef of the created hold
@@ -610,7 +610,7 @@ public class FreezeServiceImpl implements FreezeService,
* Removes a freeze from a node. The unfrozen node is automatically removed
* from the hold(s) it is in. If the hold is subsequently empty, the hold is
* automatically deleted.
*
*
* @param nodeRef node reference
*/
private void removeFreeze(NodeRef nodeRef)
@@ -673,7 +673,7 @@ public class FreezeServiceImpl implements FreezeService,
/**
* Removes a freeze from a node from the given hold
*
*
* @param nodeRef node reference
* @param hold hold
*/

View File

@@ -58,7 +58,7 @@ public interface RecordService
/**
* Creates a new unfiled record from an existing node.
* <p>
* Note that the node reference of the record will be the same as the origional
* Note that the node reference of the record will be the same as the original
* document.
*
* @param filePlan The filePlan in which the record should be placed
@@ -83,10 +83,17 @@ public interface RecordService
boolean isFiled(NodeRef record);
/**
* Rejects a node with the provided reason
* Hides a record within a collaboration site
*
* @param nodeRef node reference
* @param reason reject reason
* @param nodeRef The record which should be hidden
*/
void hideRecord(NodeRef nodeRef);
/**
* Rejects a record with the provided reason
*
* @param nodeRef The record which will be rejected
* @param reason The reason for rejection
*/
void rejectRecord(NodeRef nodeRef, String reason);
}

View File

@@ -445,6 +445,54 @@ public class RecordServiceImpl implements RecordService,
}
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#hideRecord(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public void hideRecord(final NodeRef nodeRef)
{
ParameterCheck.mandatory("NodeRef", nodeRef);
// first we do a sanity check to ensure that the user has at least write permissions on the record
if (permissionService.hasPermission(nodeRef, PermissionService.WRITE) != AccessStatus.ALLOWED)
{
throw new AccessDeniedException(
"Cannot hide record, because the user '"
+ AuthenticationUtil.getRunAsUser()
+ "' does not have write permissions on the record '"
+ nodeRef.toString() + "'.");
}
// do the work of hiding the record as the system user
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
// remove the child association
NodeRef originatingLocation = (NodeRef) nodeService.getProperty(nodeRef, PROP_RECORD_ORIGINATING_LOCATION);
List<ChildAssociationRef> parentAssocs = nodeService.getParentAssocs(nodeRef);
for (ChildAssociationRef childAssociationRef : parentAssocs)
{
if (childAssociationRef.isPrimary() == false && childAssociationRef.getParentRef().equals(originatingLocation))
{
nodeService.removeChildAssociation(childAssociationRef);
break;
}
}
// remove the extended security from the node
// this prevents the users from continuing to see the record in searchs and other linked locations
extendedSecurityService.removeAllExtendedReaders(nodeRef);
return null;
}
});
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#rejectRecord(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
*/
@Override
public void rejectRecord(final NodeRef nodeRef, final String reason)
{