From eae627ac5af402c2695bb12e29bde98e8c3c17a7 Mon Sep 17 00:00:00 2001 From: kaloyane <kaloyane> Date: Wed, 8 Jun 2011 08:59:08 +0000 Subject: [PATCH] [LMS-2282] add validation for the container-component relationship on save. It is now possible to get things wrong because the Jython dropbox allows to create new data sets with defined code. SVN: 21640 --- .../openbis/generic/server/business/bo/DataBO.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataBO.java index 4a96455c36a..e13c669478f 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataBO.java @@ -406,6 +406,12 @@ public class DataBO extends AbstractDataSetBusinessObject implements IDataBO // have at least one child so cycles need to be checked when they are updated. validateRelationshipGraph(data.getParents()); + if (data.isContainer()) + { + Collection<String> componentCodes = Code.extractCodes(data.getContainedDataSets()); + validateContainerRelationshipGraph(componentCodes); + } + data.setPlaceholder(false); data.setId(HibernateUtils.getId(placeholder)); data.setRegistrationDate(new Date()); @@ -582,7 +588,10 @@ public class DataBO extends AbstractDataSetBusinessObject implements IDataBO private void validateContainerRelationshipGraph(Collection<String> componentCodes) { - if (componentCodes.contains(data.getCode())) + if (componentCodes.isEmpty()) + { + return; + } else if (componentCodes.contains(data.getCode())) { throw new UserFailureException("Data set '" + data.getCode() + "' cannot contain itself as a component neither directly nor via subordinate components."); -- GitLab