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);