From 7ebc0dcdd3cc296983689deca5eec3be5e287d87 Mon Sep 17 00:00:00 2001 From: Alexandru Balan Date: Fri, 13 Feb 2015 13:14:12 +0000 Subject: [PATCH] RM-1660 Fixed NPE exception on schema upgrade Also fixed transaction type for the capabilities schema update. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.2@97026 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../patch/AbstractModulePatch.java | 20 +++++- .../patch/common/CapabilityPatch.java | 8 +++ .../patch/v20/RMv2FilePlanNodeRefPatch.java | 62 +++++++++++-------- 3 files changed, 62 insertions(+), 28 deletions(-) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/AbstractModulePatch.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/AbstractModulePatch.java index c5db8b4cc3..54f526acb3 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/AbstractModulePatch.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/AbstractModulePatch.java @@ -58,6 +58,12 @@ public abstract class AbstractModulePatch implements ModulePatch, BeanNameAware /** module patch target module schema number */ private int targetSchema; + + /** if it should use a read only transaction */ + private boolean txnReadOnly = true; + + /** if it should use a new transaction */ + private boolean txnRequiresNew = false; /** * Initiialisation method @@ -66,6 +72,16 @@ public abstract class AbstractModulePatch implements ModulePatch, BeanNameAware { modulePatchExecuter.register(this); } + + protected void setTxnReadOnly(boolean txnReadOnly) + { + this.txnReadOnly = txnReadOnly; + } + + protected void setTxnRequiresNew(boolean txnRequiresNew) + { + this.txnRequiresNew = txnRequiresNew; + } /** * @param modulePatchExecuter module patch executer @@ -216,8 +232,8 @@ public abstract class AbstractModulePatch implements ModulePatch, BeanNameAware // do patch in transaction transactionService.getRetryingTransactionHelper().doInTransaction( new ApplyCallback(), - true, - false); + txnReadOnly, + txnRequiresNew); if (LOGGER.isInfoEnabled()) { diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/common/CapabilityPatch.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/common/CapabilityPatch.java index 0ac771a89d..be8caa2d38 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/common/CapabilityPatch.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/common/CapabilityPatch.java @@ -128,5 +128,13 @@ public abstract class CapabilityPatch extends AbstractModulePatch } } + @Override + public void apply() + { + setTxnReadOnly(false); + setTxnRequiresNew(true); + super.apply(); + } + protected abstract void applyCapabilityPatch(NodeRef filePlan); } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v20/RMv2FilePlanNodeRefPatch.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v20/RMv2FilePlanNodeRefPatch.java index c82e1197cc..30e0dc935e 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v20/RMv2FilePlanNodeRefPatch.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v20/RMv2FilePlanNodeRefPatch.java @@ -126,35 +126,45 @@ public class RMv2FilePlanNodeRefPatch extends ModulePatchComponent NodeRef filePlan = filePlanService.getFilePlan(filePlanComponentNodeRef); - // set the file plan node reference - if (nodeService.getProperty(filePlanComponentNodeRef, PROP_ROOT_NODEREF) == null) - { - nodeService.setProperty(filePlanComponentNodeRef, PROP_ROOT_NODEREF, filePlan); + if(filePlan != null) + { + // set the file plan node reference + if (nodeService.getProperty(filePlanComponentNodeRef, PROP_ROOT_NODEREF) == null) + { + nodeService.setProperty(filePlanComponentNodeRef, PROP_ROOT_NODEREF, filePlan); + } + + // only set the admin permissions on record categories, record folders and records + FilePlanComponentKind kind = filePlanService.getFilePlanComponentKind(filePlanComponentNodeRef); + if (FilePlanComponentKind.RECORD_CATEGORY.equals(kind) || + FilePlanComponentKind.RECORD_FOLDER.equals(kind) || + FilePlanComponentKind.RECORD.equals(kind)) + { + // ensure the that the records management role has read and file on the node + Role adminRole = filePlanRoleService.getRole(filePlan, "Administrator"); + if (adminRole != null) + { + permissionService.setPermission(filePlanComponentNodeRef, adminRole.getRoleGroupName(), RMPermissionModel.FILING, true); + } + + // ensure that the default vital record default values have been set (RM-753) + Serializable vitalRecordIndicator = nodeService.getProperty(filePlanComponentNodeRef, PROP_VITAL_RECORD_INDICATOR); + if (vitalRecordIndicator == null) + { + nodeService.setProperty(filePlanComponentNodeRef, PROP_VITAL_RECORD_INDICATOR, false); + } + Serializable reviewPeriod = nodeService.getProperty(filePlanComponentNodeRef, PROP_REVIEW_PERIOD); + if (reviewPeriod == null) + { + nodeService.setProperty(filePlanComponentNodeRef, PROP_REVIEW_PERIOD, new Period("none|0")); + } + } } - - // only set the admin permissions on record categories, record folders and records - FilePlanComponentKind kind = filePlanService.getFilePlanComponentKind(filePlanComponentNodeRef); - if (FilePlanComponentKind.RECORD_CATEGORY.equals(kind) || - FilePlanComponentKind.RECORD_FOLDER.equals(kind) || - FilePlanComponentKind.RECORD.equals(kind)) + else { - // ensure the that the records management role has read and file on the node - Role adminRole = filePlanRoleService.getRole(filePlan, "Administrator"); - if (adminRole != null) + if (LOGGER.isWarnEnabled()) { - permissionService.setPermission(filePlanComponentNodeRef, adminRole.getRoleGroupName(), RMPermissionModel.FILING, true); - } - - // ensure that the default vital record default values have been set (RM-753) - Serializable vitalRecordIndicator = nodeService.getProperty(filePlanComponentNodeRef, PROP_VITAL_RECORD_INDICATOR); - if (vitalRecordIndicator == null) - { - nodeService.setProperty(filePlanComponentNodeRef, PROP_VITAL_RECORD_INDICATOR, false); - } - Serializable reviewPeriod = nodeService.getProperty(filePlanComponentNodeRef, PROP_REVIEW_PERIOD); - if (reviewPeriod == null) - { - nodeService.setProperty(filePlanComponentNodeRef, PROP_REVIEW_PERIOD, new Period("none|0")); + LOGGER.warn(" ... node " + filePlanComponent.toString() + " was skiped, beacuse there was no associated file plan."); } } }