RM-1814 (It's possible to add relationship to on hold record)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@93597 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2015-01-16 15:10:44 +00:00
parent d41ddc85e2
commit f1a300d7fe
2 changed files with 95 additions and 0 deletions

View File

@@ -18,6 +18,7 @@
*/ */
package org.alfresco.module.org_alfresco_module_rm.relationship; 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.mandatory;
import static org.alfresco.util.ParameterCheck.mandatoryString; import static org.alfresco.util.ParameterCheck.mandatoryString;
import static org.apache.commons.lang.StringUtils.isBlank; import static org.apache.commons.lang.StringUtils.isBlank;
@@ -29,6 +30,7 @@ import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException; 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.BeforeCreateReference;
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.BeforeRemoveReference; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.BeforeRemoveReference;
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnCreateReference; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnCreateReference;
@@ -417,6 +419,15 @@ public class RelationshipServiceImpl extends RecordsManagementAdminBase implemen
mandatory("source", source); mandatory("source", source);
mandatory("target", target); 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. // Check that the association definition for the given unique name exists.
AssociationDefinition associationDefinition = getAssociationDefinition(uniqueName); AssociationDefinition associationDefinition = getAssociationDefinition(uniqueName);
if (associationDefinition == null) if (associationDefinition == null)

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<Void>()
{
@Override
public Void run()
{
NodeRef hold = holdService.createHold(filePlan, GUID.generate(), GUID.generate(), GUID.generate());
holdService.addToHold(hold, recordTwo);
return null;
}
});
doTestInTransaction(new Test<Void>()
{
@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<Void>()
{
@Override
public Void run()
{
relationshipService.addRelationship("supports", recordOne, recordFour);
return null;
}
});
}
}