From 8d05a1220586d2dc692fb85a3a96a0fd40effd7e Mon Sep 17 00:00:00 2001 From: Ramona Neamtu Date: Wed, 27 Jan 2016 09:58:37 +0000 Subject: [PATCH] Merged 5.0.N (5.0.4) to 5.1.N (5.1.1) 120555: Merged DEV to 5.0.N (5.0.4) 120544 rneamtu: MNT-13723 : Error message not clear, when de-activating a model dynamically deployed and content still exists. - Added externalized error message, generic for both delete and deactivate - Do not merge this forward, it will be merged manually 120572: MNT-13723 : Error message not clear, when de-activating a model dynamically deployed and content still exists. - Fixed failing tests - Do not merge this forward, it will be merged manually git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@121494 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/messages/custommodel-service.properties | 1 + .../alfresco/repo/dictionary/DictionaryModelType.java | 11 ++++++----- .../alfresco/repo/admin/RepoAdminServiceImplTest.java | 9 ++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/config/alfresco/messages/custommodel-service.properties b/config/alfresco/messages/custommodel-service.properties index 74a6f5b663..53e9d644b5 100644 --- a/config/alfresco/messages/custommodel-service.properties +++ b/config/alfresco/messages/custommodel-service.properties @@ -27,6 +27,7 @@ cmm.service.download.create_share_ext_err=We couldn''t create a Share extension cmm.service.download.create_model_copy_err=We couldn''t make a copy of the custom model node. {0} cmm.service.download.create_err=We couldn't create download. cmm.service.constraint.default_prop_value_err=Property default value isn't valid for the defined constraint. +cmm.service.model_in_use=Model ''{0}'' is in use and cannot be deleted or deactivated. # ValueDataTypeValidator messages cmm.value_datatype_validator.unknown_datatype=Property data type ''{0}'' is unknown. diff --git a/source/java/org/alfresco/repo/dictionary/DictionaryModelType.java b/source/java/org/alfresco/repo/dictionary/DictionaryModelType.java index 111fb5b809..a3c2a683a4 100644 --- a/source/java/org/alfresco/repo/dictionary/DictionaryModelType.java +++ b/source/java/org/alfresco/repo/dictionary/DictionaryModelType.java @@ -84,6 +84,8 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda /** The name of the lock used to ensure that DictionaryModelType updates do not run on more than one thread/node at the same time. */ private static final QName LOCK_QNAME = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "DictionaryModelType"); + private static final String MODEL_IN_USE = "cmm.service.model_in_use"; + /** The dictionary DAO */ private DictionaryDAO dictionaryDAO; @@ -342,9 +344,9 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda if (modelName != null) { // Validate model delete against usages - content and/or workflows - if(!modelValidator.canDeleteModel(modelName)) + if (!modelValidator.canDeleteModel(modelName)) { - throw new AlfrescoRuntimeException("Cannot delete model " + modelName + ", it is being used"); + throw AlfrescoRuntimeException.create(MODEL_IN_USE, modelName); } Set pendingModelDeletes = (Set)AlfrescoTransactionSupport.getResource(KEY_PENDING_DELETE_MODELS); @@ -650,10 +652,9 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda if (modelName != null) { // Validate model delete against usages - content and/or workflows - if(!modelValidator.canDeleteModel(modelName)) + if (!modelValidator.canDeleteModel(modelName)) { - throw new AlfrescoRuntimeException("Cannot delete model " - + modelName + ", it is being used"); + throw AlfrescoRuntimeException.create(MODEL_IN_USE, modelName); } // invalidate - to force lazy re-init diff --git a/source/test-java/org/alfresco/repo/admin/RepoAdminServiceImplTest.java b/source/test-java/org/alfresco/repo/admin/RepoAdminServiceImplTest.java index 2fbdd2e768..4bf1e0be81 100644 --- a/source/test-java/org/alfresco/repo/admin/RepoAdminServiceImplTest.java +++ b/source/test-java/org/alfresco/repo/admin/RepoAdminServiceImplTest.java @@ -333,8 +333,7 @@ public class RepoAdminServiceImplTest extends TestCase // expected assertTrue( "Incorrect exception message: " + are.getMessage(), - are.getMessage().contains("Cannot delete model") && - are.getMessage().contains("it is being used")); + are.getMessage().contains(" is in use and cannot be deleted or deactivated.")); } nodeService.deleteNode(node1); @@ -353,7 +352,7 @@ public class RepoAdminServiceImplTest extends TestCase catch (AlfrescoRuntimeException are) { // expected - assertTrue(are.getMessage().contains("Cannot delete model")); + assertTrue(are.getMessage().contains("is in use and cannot be deleted or deactivated.")); } nodeService.deleteNode(archiveNode1); @@ -484,7 +483,7 @@ public class RepoAdminServiceImplTest extends TestCase { // expected assertTrue(are.getMessage().contains("Model undeployment failed")); - assertTrue(are.getCause().getMessage().contains("Cannot delete model")); + assertTrue(are.getCause().getMessage().contains("is in use and cannot be deleted or deactivated.")); } nodeService.deleteNode(node1); @@ -504,7 +503,7 @@ public class RepoAdminServiceImplTest extends TestCase { // expected assertTrue(are.getMessage().contains("Model undeployment failed")); - assertTrue(are.getCause().getMessage().contains("Cannot delete model")); + assertTrue(are.getCause().getMessage().contains("is in use and cannot be deleted or deactivated.")); } nodeService.deleteNode(archiveNode1);