From c69c9964cc3d00649873499b6145d0281034f95e Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Thu, 26 Sep 2013 01:30:50 +0000 Subject: [PATCH] RM-880: Cannot upload file into RM site over FTP/NFS file protocols * if record has NO_CONTENT when assoc is created, postpone filling untill NO_CONTENT is removed git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@56006 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../record/RecordServiceImpl.java | 65 +++++++++++++++---- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java index 68813e0ad6..0476537018 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java @@ -56,6 +56,7 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.security.permissions.impl.ExtendedPermissionService; +import org.alfresco.repo.transaction.TransactionalResourceHelper; import org.alfresco.service.cmr.dictionary.AspectDefinition; import org.alfresco.service.cmr.dictionary.ClassDefinition; import org.alfresco.service.cmr.dictionary.DictionaryService; @@ -97,7 +98,9 @@ public class RecordServiceImpl implements RecordService, RecordsManagementCustomModel, NodeServicePolicies.OnCreateChildAssociationPolicy, NodeServicePolicies.OnUpdatePropertiesPolicy, - ApplicationContextAware + ApplicationContextAware, + NodeServicePolicies.OnAddAspectPolicy, + NodeServicePolicies.OnRemoveAspectPolicy { /** Logger */ private static Log logger = LogFactory.getLog(RecordServiceImpl.class); @@ -355,21 +358,43 @@ public class RecordServiceImpl implements RecordService, policyComponent.bindClassBehaviour( NodeServicePolicies.OnAddAspectPolicy.QNAME, ContentModel.ASPECT_NO_CONTENT, - new JavaBehaviour(this, "processNoContentAspect", NotificationFrequency.EVERY_EVENT)); + new JavaBehaviour(this, "onAddAspect", NotificationFrequency.EVERY_EVENT)); policyComponent.bindClassBehaviour( NodeServicePolicies.OnRemoveAspectPolicy.QNAME, ContentModel.ASPECT_NO_CONTENT, - new JavaBehaviour(this, "processNoContentAspect", NotificationFrequency.EVERY_EVENT)); + new JavaBehaviour(this, "onRemoveAspect", NotificationFrequency.EVERY_EVENT)); } + /** + * @see org.alfresco.repo.node.NodeServicePolicies.OnRemoveAspectPolicy#onRemoveAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName) + */ + @Override + public void onRemoveAspect(NodeRef nodeRef, QName aspect) + { + if (nodeService.hasAspect(nodeRef, ASPECT_RECORD) == true) + { + switchNames(nodeRef); + } + else + { + // check whether filling is pending aspect removal + Set pendingFilling = TransactionalResourceHelper.getSet("pendingFilling"); + if (pendingFilling.contains(nodeRef) == true) + { + file(nodeRef); + } + } + } + /** * @see org.alfresco.repo.node.NodeServicePolicies.OnAddAspectPolicy#onAddAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName) */ - public void processNoContentAspect(NodeRef nodeRef, QName aspectTypeQName) + @Override + public void onAddAspect(NodeRef nodeRef, QName aspect) { - switchNames(nodeRef); + switchNames(nodeRef); } - + /** * Helper method to switch the name of the record around. Used to support record creation via * file protocols. @@ -393,15 +418,24 @@ public class RecordServiceImpl implements RecordService, } catch (FileExistsException e) { - e.printStackTrace(); + if (logger.isDebugEnabled() == true) + { + logger.debug(e.getMessage()); + } } catch (InvalidNodeRefException e) { - e.printStackTrace(); + if (logger.isDebugEnabled() == true) + { + logger.debug(e.getMessage()); + } } catch (FileNotFoundException e) { - e.printStackTrace(); + if (logger.isDebugEnabled() == true) + { + logger.debug(e.getMessage()); + } } } @@ -424,8 +458,17 @@ public class RecordServiceImpl implements RecordService, nodeService.getType(nodeRef).equals(TYPE_RECORD_FOLDER) == false && nodeService.getType(nodeRef).equals(TYPE_RECORD_CATEGORY) == false) { - // create and file the content as a record - file(nodeRef); + if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT) == true) + { + // we need to postpone filling until the NO_CONTENT aspect is removed + Set pendingFilling = TransactionalResourceHelper.getSet("pendingFilling"); + pendingFilling.add(nodeRef); + } + else + { + // create and file the content as a record + file(nodeRef); + } } return null;