diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/Translator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/Translator.java index c2bcef7cbcd5e281d48bf10daa478bb90f8c7b36..7a369f651a028d8f7ee1c0f99a28714e05b21730 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/Translator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/Translator.java @@ -16,6 +16,7 @@ package ch.systemsx.cisd.openbis.generic.server.api.v1; +import java.util.Collections; import java.util.List; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet; @@ -26,6 +27,8 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Experiment.ExperimentInitializer; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyType.PropertyTypeInitializer; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyTypeGroup; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyTypeGroup.PropertyTypeGroupInitializer; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Role; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample.SampleInitializer; @@ -101,16 +104,30 @@ public class Translator List<ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypePropertyType> dstpts = privateDataSetType.getAssignedPropertyTypes(); + Collections.sort(dstpts); + + String sectionName = null; + PropertyTypeGroupInitializer groupInitializer = new PropertyTypeGroupInitializer(); for (ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypePropertyType dstpt : dstpts) { + String thisSectionName = dstpt.getSection(); + if (thisSectionName != null && false == thisSectionName.equals(sectionName)) + { + // Start a new section + initializer.addPropertyTypeGroup(new PropertyTypeGroup(groupInitializer)); + groupInitializer = new PropertyTypeGroupInitializer(); + sectionName = thisSectionName; + } PropertyTypeInitializer ptInitializer = new PropertyTypeInitializer(); ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType propertyType = dstpt.getPropertyType(); ptInitializer.setCode(propertyType.getCode()); ptInitializer.setLabel(propertyType.getLabel()); ptInitializer.setDescription(propertyType.getDescription()); - initializer.addPropertyType(new PropertyType(ptInitializer)); + groupInitializer.addPropertyType(new PropertyType(ptInitializer)); } + // Finally set the group + initializer.addPropertyTypeGroup(new PropertyTypeGroup(groupInitializer)); return new DataSetType(initializer); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetType.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetType.java index 5059eac4205d5b5a207b5c229970932440fd823c..6ab2082a6358a7973318beb4340c0b02c2247b3e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetType.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetType.java @@ -44,7 +44,8 @@ public final class DataSetType implements Serializable { private String code; - private ArrayList<PropertyType> propertyTypes = new ArrayList<PropertyType>(); + private ArrayList<PropertyTypeGroup> propertyTypeGroups = + new ArrayList<PropertyTypeGroup>(); public String getCode() { @@ -56,20 +57,20 @@ public final class DataSetType implements Serializable this.code = code; } - public ArrayList<PropertyType> getPropertyTypes() + public ArrayList<PropertyTypeGroup> getPropertyTypeGroups() { - return propertyTypes; + return propertyTypeGroups; } - public void addPropertyType(PropertyType propertyType) + public void addPropertyTypeGroup(PropertyTypeGroup propertyType) { - propertyTypes.add(propertyType); + propertyTypeGroups.add(propertyType); } } private final String code; - private final ArrayList<PropertyType> propertyTypes; + private final ArrayList<PropertyTypeGroup> propertyTypeGroups; /** * Creates a new instance with the provided initializer @@ -81,7 +82,7 @@ public final class DataSetType implements Serializable checkValidString(initializer.getCode(), "Unspecified code."); this.code = initializer.getCode(); - this.propertyTypes = initializer.getPropertyTypes(); + this.propertyTypeGroups = initializer.getPropertyTypeGroups(); } private void checkValidString(String string, String message) throws IllegalArgumentException @@ -93,16 +94,20 @@ public final class DataSetType implements Serializable } /** - * Returns the sample code; + * Returns the data set code. */ public String getCode() { return code; } - public List<PropertyType> getPropertyTypes() + /** + * Return the grouped property types for this data set type. (Groups are referred to as sections + * elsewhere). + */ + public List<PropertyTypeGroup> getPropertyTypeGroups() { - return propertyTypes; + return propertyTypeGroups; } @Override @@ -136,7 +141,7 @@ public final class DataSetType implements Serializable { ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); builder.append(getCode()); - builder.append(getPropertyTypes()); + builder.append(getPropertyTypeGroups()); return builder.toString(); } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/PropertyType.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/PropertyType.java index f7d9014220f1642d05fb7bca75362f087c25e8d2..5e70eb6ae67f68b964d6a6c849dde8d35b3d5c25 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/PropertyType.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/PropertyType.java @@ -109,18 +109,24 @@ public final class PropertyType implements Serializable } /** - * Returns the sample code; + * Return the code of this property type. */ public String getCode() { return code; } + /** + * Return the label shown in forms. + */ public String getLabel() { return label; } + /** + * Return the extended description. May be null. + */ public String getDescription() { return description; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/PropertyTypeGroup.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/PropertyTypeGroup.java new file mode 100644 index 0000000000000000000000000000000000000000..2f5859dae80f5754bb5f90767eaa5391bb0bb79a --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/PropertyTypeGroup.java @@ -0,0 +1,133 @@ +/* + * Copyright 2010 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.shared.api.v1.dto; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +/** + * Immutable value object representing a data set type. + * + * @author Chandrasekhar Ramakrishnan + */ +public final class PropertyTypeGroup implements Serializable +{ + private static final long serialVersionUID = 1L; + + /** + * Class used to initialize a new data set instance. Necessary since all the fields of a DataSet + * are final. + * + * @author Chandrasekhar Ramakrishnan + */ + public static final class PropertyTypeGroupInitializer + { + private String name; + + private ArrayList<PropertyType> propertyTypes = new ArrayList<PropertyType>(); + + public String getName() + { + return name; + } + + public void setName(String code) + { + this.name = code; + } + + public ArrayList<PropertyType> getPropertyTypes() + { + return propertyTypes; + } + + public void addPropertyType(PropertyType propertyType) + { + propertyTypes.add(propertyType); + } + } + + private final String name; + + private final ArrayList<PropertyType> propertyTypes; + + /** + * Creates a new instance with the provided initializer + * + * @throws IllegalArgumentException if some of the required information is not provided. + */ + public PropertyTypeGroup(PropertyTypeGroupInitializer initializer) + { + this.name = initializer.getName(); + + this.propertyTypes = initializer.getPropertyTypes(); + } + + /** + * Returns the name of this group (section). May be null. + */ + public String getName() + { + return name; + } + + public List<PropertyType> getPropertyTypes() + { + return propertyTypes; + } + + @Override + public boolean equals(Object obj) + { + if (obj == this) + { + return true; + } + if (obj instanceof PropertyTypeGroup == false) + { + return false; + } + + EqualsBuilder builder = new EqualsBuilder(); + PropertyTypeGroup other = (PropertyTypeGroup) obj; + builder.append(getName(), other.getName()); + return builder.isEquals(); + } + + @Override + public int hashCode() + { + HashCodeBuilder builder = new HashCodeBuilder(); + builder.append(getName()); + return builder.toHashCode(); + } + + @Override + public String toString() + { + ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); + builder.append(getName()); + builder.append(getPropertyTypes()); + return builder.toString(); + } +} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetTypeTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetTypeTest.java index a96f1c84fef1fd6863022d6eda2f44e1a38af4c6..b19de1188d3d63b8e19eb840b23c747f1c5b92e9 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetTypeTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetTypeTest.java @@ -22,6 +22,7 @@ import org.testng.annotations.Test; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetType.DataSetTypeInitializer; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyType.PropertyTypeInitializer; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyTypeGroup.PropertyTypeGroupInitializer; /** * @author Chandrasekhar Ramakrishnan @@ -37,17 +38,20 @@ public class DataSetTypeTest extends AssertJUnit { DataSetTypeInitializer initializer = new DataSetTypeInitializer(); initializer.setCode(DATA_SET_TYPE_CODE); + PropertyTypeGroupInitializer groupInitializer = new PropertyTypeGroupInitializer(); PropertyTypeInitializer propTypeInitializer = new PropertyTypeInitializer(); propTypeInitializer.setCode("PROP1"); propTypeInitializer.setLabel("Property 1"); - initializer.addPropertyType(new PropertyType(propTypeInitializer)); + groupInitializer.addPropertyType(new PropertyType(propTypeInitializer)); propTypeInitializer.setCode("PROP2"); propTypeInitializer.setLabel("Property 2"); propTypeInitializer.setDescription("Property 2 Description"); - initializer.addPropertyType(new PropertyType(propTypeInitializer)); + groupInitializer.addPropertyType(new PropertyType(propTypeInitializer)); + + initializer.addPropertyTypeGroup(new PropertyTypeGroup(groupInitializer)); dataSetType = new DataSetType(initializer); } @@ -64,10 +68,12 @@ public class DataSetTypeTest extends AssertJUnit { DataSetTypeInitializer initializer = new DataSetTypeInitializer(); initializer.setCode(DATA_SET_TYPE_CODE); + PropertyTypeGroupInitializer groupInitializer = new PropertyTypeGroupInitializer(); PropertyTypeInitializer propTypeInitializer = new PropertyTypeInitializer(); propTypeInitializer.setCode("PROP200"); propTypeInitializer.setLabel("Property 200"); - initializer.addPropertyType(new PropertyType(propTypeInitializer)); + groupInitializer.addPropertyType(new PropertyType(propTypeInitializer)); + initializer.addPropertyTypeGroup(new PropertyTypeGroup(groupInitializer)); DataSetType myDataSetType = new DataSetType(initializer); assertTrue("Data sets with the same code should be equal.", @@ -83,10 +89,12 @@ public class DataSetTypeTest extends AssertJUnit initializer = new DataSetTypeInitializer(); initializer.setCode("code-2"); + groupInitializer = new PropertyTypeGroupInitializer(); propTypeInitializer = new PropertyTypeInitializer(); propTypeInitializer.setCode("PROP1"); propTypeInitializer.setLabel("Property 1"); - initializer.addPropertyType(new PropertyType(propTypeInitializer)); + groupInitializer.addPropertyType(new PropertyType(propTypeInitializer)); + initializer.addPropertyTypeGroup(new PropertyTypeGroup(groupInitializer)); propTypeInitializer.setCode("PROP2"); propTypeInitializer.setLabel("Property 2"); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationServiceTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationServiceTest.java index 9e028d68c872b372326b5061eb86082d5689d58f..36204a2a003850cb32222784e076660f1d445d4c 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationServiceTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationServiceTest.java @@ -37,6 +37,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetType; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Project; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyType; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyTypeGroup; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Role; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria; @@ -225,12 +226,28 @@ public class GeneralInformationServiceTest extends SystemTestCase assertEquals(3, dataSetTypes.size()); DataSetType dataSetType; - PropertyType propertyType; dataSetType = dataSetTypes.get(0); assertEquals("HCS_IMAGE", dataSetType.getCode()); - List<PropertyType> propertyTypes = dataSetType.getPropertyTypes(); + + List<PropertyTypeGroup> propertyTypeGroups = dataSetType.getPropertyTypeGroups(); + assertEquals(1, propertyTypeGroups.size()); + + PropertyTypeGroup propertyTypeGroup = propertyTypeGroups.get(0); + assertEquals(null, propertyTypeGroup.getName()); + + List<PropertyType> propertyTypes = propertyTypeGroup.getPropertyTypes(); + assertEquals(4, propertyTypes.size()); + + PropertyType propertyType; propertyType = propertyTypes.get(0); assertEquals("COMMENT", propertyType.getCode()); assertEquals("Comment", propertyType.getLabel()); + assertEquals("Any other comments", propertyType.getDescription()); + + propertyType = propertyTypes.get(1); + assertEquals("ANY_MATERIAL", propertyType.getCode()); + assertEquals("any_material", propertyType.getLabel()); + assertEquals("any_material", propertyType.getDescription()); + } }