diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/AbstractEntityAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/AbstractEntityAdaptor.java index d3975b2495401a11f1e3b53bae1e54e0fb1b2d13..ce02a66c0b05c0cadeffad758d7686d1b16acdce 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/AbstractEntityAdaptor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/AbstractEntityAdaptor.java @@ -42,14 +42,26 @@ public class AbstractEntityAdaptor implements IEntityAdaptor private final String code; + protected final IDynamicPropertyEvaluator evaluator; + public AbstractEntityAdaptor(String code) + { + this(code, null); + } + + public AbstractEntityAdaptor(String code, IDynamicPropertyEvaluator evaluator) { this.code = code; + this.evaluator = evaluator; } - protected void initProperties(IEntityPropertiesHolder propertiesHolder, - IDynamicPropertyEvaluator evaluator) + protected void initProperties(IEntityPropertiesHolder propertiesHolder) { + if (evaluator == null) + { + throw new IllegalStateException( + "Couldn't init properties if the evaluator has not been set"); + } for (EntityPropertyPE property : propertiesHolder.getProperties()) { EntityTypePropertyTypePE etpt = property.getEntityTypePropertyType(); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/EntityAdaptorFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/EntityAdaptorFactory.java index dfffa494409949fae6f99642f3992742ea67c9cd..aab59e2b4c0477d7bed363fb4aa231e35d89c92a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/EntityAdaptorFactory.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/EntityAdaptorFactory.java @@ -17,7 +17,11 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator; import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.IDynamicPropertyEvaluator; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IDataAdaptor; import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IEntityAdaptor; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IExperimentAdaptor; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IMaterialAdaptor; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.ISampleAdaptor; import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; import ch.systemsx.cisd.openbis.generic.shared.dto.IEntityInformationWithPropertiesHolder; @@ -35,6 +39,7 @@ public class EntityAdaptorFactory public static IEntityAdaptor create(IEntityInformationWithPropertiesHolder entity, IDynamicPropertyEvaluator evaluator) { + switch (entity.getEntityKind()) { case SAMPLE: @@ -49,4 +54,24 @@ public class EntityAdaptorFactory throw new UnsupportedOperationException(""); // can't happen } } + + public static IExperimentAdaptor create(ExperimentPE entity, IDynamicPropertyEvaluator evaluator) + { + return new ExperimentAdaptor(entity, evaluator); + } + + public static ISampleAdaptor create(SamplePE entity, IDynamicPropertyEvaluator evaluator) + { + return new SampleAdaptor(entity, evaluator); + } + + public static IDataAdaptor create(DataPE entity, IDynamicPropertyEvaluator evaluator) + { + return new ExternalDataAdaptor(entity, evaluator); + } + + public static IMaterialAdaptor create(MaterialPE entity, IDynamicPropertyEvaluator evaluator) + { + return new MaterialAdaptor(entity, evaluator); + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/ExperimentAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/ExperimentAdaptor.java index 9cb8310a1723d8cd69953fbaa69a7a1e4faeb44f..39ad7d0ee2f256b008614e7167009c3c000e398d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/ExperimentAdaptor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/ExperimentAdaptor.java @@ -18,6 +18,7 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calc import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.IDynamicPropertyEvaluator; import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IEntityAdaptor; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IExperimentAdaptor; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; /** @@ -25,14 +26,14 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; * * @author Piotr Buczek */ -public class ExperimentAdaptor extends AbstractEntityAdaptor +public class ExperimentAdaptor extends AbstractEntityAdaptor implements IExperimentAdaptor { private final ExperimentPE experimentPE; public ExperimentAdaptor(ExperimentPE experimentPE, IDynamicPropertyEvaluator evaluator) { - super(experimentPE.getCode()); - initProperties(experimentPE, evaluator); + super(experimentPE.getCode(), evaluator); + initProperties(experimentPE); this.experimentPE = experimentPE; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/ExternalDataAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/ExternalDataAdaptor.java index 1e4dc659b3be999d60a991e0fce072c07d3a7dbd..8aada43b25f8250b0c77c32707083399faf66e3c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/ExternalDataAdaptor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/ExternalDataAdaptor.java @@ -16,9 +16,15 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator; +import java.util.ArrayList; +import java.util.List; + import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.IDynamicPropertyEvaluator; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IDataAdaptor; import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IEntityAdaptor; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IExperimentAdaptor; import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetRelationshipPE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE; /** @@ -26,14 +32,14 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE; * * @author Piotr Buczek */ -public class ExternalDataAdaptor extends AbstractEntityAdaptor +public class ExternalDataAdaptor extends AbstractEntityAdaptor implements IDataAdaptor { private final DataPE externalDataPE; public ExternalDataAdaptor(DataPE externalDataPE, IDynamicPropertyEvaluator evaluator) { - super(externalDataPE.getCode()); - initProperties(externalDataPE, evaluator); + super(externalDataPE.getCode(), evaluator); + initProperties(externalDataPE); this.externalDataPE = externalDataPE; } @@ -47,4 +53,57 @@ public class ExternalDataAdaptor extends AbstractEntityAdaptor return externalDataPE(); } + @Override + public IExperimentAdaptor experiment() + { + return EntityAdaptorFactory.create(externalDataPE.getExperiment(), evaluator); + } + + @Override + public List<IDataAdaptor> parents() + { + List<IDataAdaptor> list = new ArrayList<IDataAdaptor>(); + for (DataSetRelationshipPE relationship : externalDataPE.getParentRelationships()) + { + DataPE parent = relationship.getParentDataSet(); + list.add(EntityAdaptorFactory.create(parent, evaluator)); + } + return list; + } + + @Override + public List<IDataAdaptor> children() + { + List<IDataAdaptor> list = new ArrayList<IDataAdaptor>(); + for (DataSetRelationshipPE relationship : externalDataPE.getChildRelationships()) + { + DataPE child = relationship.getChildDataSet(); + list.add(EntityAdaptorFactory.create(child, evaluator)); + } + return list; + } + + @Override + public List<IDataAdaptor> contained() + { + List<IDataAdaptor> list = new ArrayList<IDataAdaptor>(); + for (DataPE contained : externalDataPE.getContainedDataSets()) + { + list.add(EntityAdaptorFactory.create(contained, evaluator)); + } + return list; + } + + @Override + public IDataAdaptor container() + { + DataPE container = externalDataPE.getContainer(); + if (container != null) + { + return EntityAdaptorFactory.create(container, evaluator); + } else + { + return null; + } + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/MaterialAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/MaterialAdaptor.java index eca40a96bce9f148cceeddbb713173d0bbb64712..25c235a2f535dc7bcd383899ec4fd7bab3f5b161 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/MaterialAdaptor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/MaterialAdaptor.java @@ -18,6 +18,7 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calc import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.IDynamicPropertyEvaluator; import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IEntityAdaptor; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IMaterialAdaptor; import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE; /** @@ -25,14 +26,14 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE; * * @author Piotr Buczek */ -public class MaterialAdaptor extends AbstractEntityAdaptor +public class MaterialAdaptor extends AbstractEntityAdaptor implements IMaterialAdaptor { private final MaterialPE MaterialPE; public MaterialAdaptor(MaterialPE MaterialPE, IDynamicPropertyEvaluator evaluator) { - super(MaterialPE.getCode()); - initProperties(MaterialPE, evaluator); + super(MaterialPE.getCode(), evaluator); + initProperties(MaterialPE); this.MaterialPE = MaterialPE; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/SampleAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/SampleAdaptor.java index 2d131fd9baad164795efaec518c4011d4e829b6c..c907c9badfd1d4fa9a6a39cc87a216784e0587f2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/SampleAdaptor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/SampleAdaptor.java @@ -16,23 +16,29 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator; +import java.util.ArrayList; +import java.util.List; + import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.IDynamicPropertyEvaluator; import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IEntityAdaptor; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.IExperimentAdaptor; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api.ISampleAdaptor; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.SampleRelationshipPE; /** * {@link IEntityAdaptor} implementation for {@link SamplePE}. * * @author Piotr Buczek */ -public class SampleAdaptor extends AbstractEntityAdaptor +public class SampleAdaptor extends AbstractEntityAdaptor implements ISampleAdaptor { private final SamplePE samplePE; public SampleAdaptor(SamplePE samplePE, IDynamicPropertyEvaluator evaluator) { - super(samplePE.getCode()); - initProperties(samplePE, evaluator); + super(samplePE.getCode(), evaluator); + initProperties(samplePE); this.samplePE = samplePE; } @@ -46,4 +52,57 @@ public class SampleAdaptor extends AbstractEntityAdaptor return samplePE(); } + @Override + public IExperimentAdaptor experiment() + { + return EntityAdaptorFactory.create(samplePE.getExperiment(), evaluator); + } + + @Override + public List<ISampleAdaptor> parents() + { + List<ISampleAdaptor> list = new ArrayList<ISampleAdaptor>(); + for (SamplePE parent : samplePE.getParents()) + { + list.add(EntityAdaptorFactory.create(parent, evaluator)); + } + return list; + } + + @Override + public List<ISampleAdaptor> children() + { + List<ISampleAdaptor> list = new ArrayList<ISampleAdaptor>(); + for (SampleRelationshipPE relationship : samplePE.getChildRelationships()) + { + SamplePE child = relationship.getChildSample(); + list.add(EntityAdaptorFactory.create(child, evaluator)); + } + return list; + } + + @Override + public List<ISampleAdaptor> contained() + { + List<ISampleAdaptor> list = new ArrayList<ISampleAdaptor>(); + for (SamplePE contained : samplePE.getContained()) + { + list.add(EntityAdaptorFactory.create(contained, evaluator)); + } + return list; + } + + @Override + public ISampleAdaptor container() + { + SamplePE container = samplePE.getContainer(); + if (container != null) + { + return EntityAdaptorFactory.create(container, evaluator); + } else + { + return null; + } + } + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/api/IDataAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/api/IDataAdaptor.java new file mode 100644 index 0000000000000000000000000000000000000000..afa771005deb0894bddb1fb276b2be5c1bb6022a --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/api/IDataAdaptor.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api; + +import java.util.List; + +/** + * @author Jakub Straszewski + */ +public interface IDataAdaptor +{ + /** + * Returns the experiment of this data set, or null if not exists. + */ + IExperimentAdaptor experiment(); + + /** + * Returns the list of all parent data sets. + */ + public List<IDataAdaptor> parents(); + + /** + * Returns the list of all child data sets. + */ + public List<IDataAdaptor> children(); + + /** + * Returns the list of contained data sets. + */ + public List<IDataAdaptor> contained(); + + /** + * Returs the container data set, or null if not exists. + */ + public IDataAdaptor container(); +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/api/IExperimentAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/api/IExperimentAdaptor.java new file mode 100644 index 0000000000000000000000000000000000000000..5e5b26d4c0b019699be1666a97a8715fec85fba5 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/api/IExperimentAdaptor.java @@ -0,0 +1,27 @@ +/* + * Copyright 2012 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api; + +/** + * + * + * @author Jakub Straszewski + */ +public interface IExperimentAdaptor +{ + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/api/IMaterialAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/api/IMaterialAdaptor.java new file mode 100644 index 0000000000000000000000000000000000000000..d2a247f2869518029fc654975035acad2a8f4bed --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/api/IMaterialAdaptor.java @@ -0,0 +1,27 @@ +/* + * Copyright 2012 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api; + +/** + * + * + * @author Jakub Straszewski + */ +public interface IMaterialAdaptor +{ + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/api/ISampleAdaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/api/ISampleAdaptor.java new file mode 100644 index 0000000000000000000000000000000000000000..ed64afe8b136cb572429671fde5d740fa5c2b02f --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/dynamic_property/calculator/api/ISampleAdaptor.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.server.dataaccess.dynamic_property.calculator.api; + +import java.util.List; + +/** + * @author Jakub Straszewski + */ +public interface ISampleAdaptor extends IEntityAdaptor +{ + /** + * Returns the experiment of this sample, or null if not exists. + */ + IExperimentAdaptor experiment(); + + /** + * Returns the list of all parent samples. + */ + public List<ISampleAdaptor> parents(); + + /** + * Returns the list of all child samples. + */ + public List<ISampleAdaptor> children(); + + /** + * Returns the list of contained samples. + */ + public List<ISampleAdaptor> contained(); + + /** + * Returs the container sample, or null if not exists. + */ + public ISampleAdaptor container(); + +}