diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipServiceImpl.java index ece19b58b3..1d3efc1e16 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/relationship/RelationshipServiceImpl.java @@ -18,6 +18,7 @@ */ package org.alfresco.module.org_alfresco_module_rm.relationship; +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_FROZEN; import static org.alfresco.util.ParameterCheck.mandatory; import static org.alfresco.util.ParameterCheck.mandatoryString; import static org.apache.commons.lang.StringUtils.isBlank; @@ -29,6 +30,7 @@ import java.util.Map.Entry; import java.util.Set; import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.BeforeCreateReference; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.BeforeRemoveReference; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnCreateReference; @@ -417,6 +419,15 @@ public class RelationshipServiceImpl extends RecordsManagementAdminBase implemen mandatory("source", source); mandatory("target", target); + if (getNodeService().hasAspect(target, ASPECT_FROZEN)) + { + StringBuilder sb = new StringBuilder(); + sb.append("Relationship cannot be created as the target '"). + append(getNodeService().getProperty(target, ContentModel.PROP_NAME)). + append("' is in a hold."); + throw new AlfrescoRuntimeException(sb.toString()); + } + // Check that the association definition for the given unique name exists. AssociationDefinition associationDefinition = getAssociationDefinition(uniqueName); if (associationDefinition == null) diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM1814Test.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM1814Test.java new file mode 100644 index 0000000000..72a0276b1c --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM1814Test.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2005-2015 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; + +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.util.GUID; + +/** + * Test for RM-1814 + * + * @author Tuna Aksoy + * @since 2.3 + */ +public class RM1814Test extends BaseRMTestCase +{ + @Override + protected boolean isRecordTest() + { + return true; + } + + public void testRM1814() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public Void run() + { + NodeRef hold = holdService.createHold(filePlan, GUID.generate(), GUID.generate(), GUID.generate()); + holdService.addToHold(hold, recordTwo); + return null; + } + }); + + doTestInTransaction(new Test() + { + @Override + public Void run() + { + relationshipService.addRelationship("versions", recordOne, recordThree); + return null; + } + }); + + doTestInTransaction(new FailureTest + ( + "Target node is in a hold." + ) + { + @Override + public void run() throws Exception + { + relationshipService.addRelationship("obsoletes", recordOne, recordTwo); + } + }); + + doTestInTransaction(new Test() + { + @Override + public Void run() + { + relationshipService.addRelationship("supports", recordOne, recordFour); + return null; + } + }); + } +}