Skip to content
Snippets Groups Projects
Commit 1cc99f41 authored by cramakri's avatar cramakri
Browse files

LMS-2735 Include container information in the DTOs. Necessary for InfectX

SVN: 24100
parent 7202ecd7
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample.SampleInitializ ...@@ -47,6 +47,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample.SampleInitializ
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Vocabulary; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Vocabulary;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Vocabulary.VocabularyInitializer; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Vocabulary.VocabularyInitializer;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.VocabularyTerm; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.VocabularyTerm;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ContainerDataSet;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
...@@ -331,6 +332,21 @@ public class Translator ...@@ -331,6 +332,21 @@ public class Translator
initializer.putProperty(prop.getPropertyType().getCode(), prop.tryGetAsString()); initializer.putProperty(prop.getPropertyType().getCode(), prop.tryGetAsString());
} }
initializer.setContainerDataSet(externalDatum.isContainer());
if (externalDatum.isContainer())
{
// Recursively translate any contained data sets
ContainerDataSet containerDataSet = externalDatum.tryGetAsContainerDataSet();
ArrayList<DataSet> containedDataSetCodes =
new ArrayList<DataSet>(containerDataSet.getContainedDataSets().size());
for (ExternalData containedDataSet : containerDataSet.getContainedDataSets())
{
containedDataSetCodes.add(translate(containedDataSet, connectionsToGet));
}
initializer.setContainedDataSets(containedDataSetCodes);
}
initializer.setRetrievedConnections(connectionsToGet); initializer.setRetrievedConnections(connectionsToGet);
for (Connections connection : connectionsToGet) for (Connections connection : connectionsToGet)
{ {
......
...@@ -24,12 +24,12 @@ import org.testng.AssertJUnit; ...@@ -24,12 +24,12 @@ import org.testng.AssertJUnit;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.Translator;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet.Connections; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet.Connections;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.ContainerDataSetBuilder;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.DataSetBuilder; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.DataSetBuilder;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.ExperimentBuilder; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.ExperimentBuilder;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.SampleBuilder; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.SampleBuilder;
...@@ -43,6 +43,8 @@ public class TranslatorTest extends AssertJUnit ...@@ -43,6 +43,8 @@ public class TranslatorTest extends AssertJUnit
private DataSetBuilder ds2; private DataSetBuilder ds2;
private ContainerDataSetBuilder dsContainer;
@BeforeMethod @BeforeMethod
public void setUp() public void setUp()
{ {
...@@ -55,6 +57,25 @@ public class TranslatorTest extends AssertJUnit ...@@ -55,6 +57,25 @@ public class TranslatorTest extends AssertJUnit
ds2 = ds2 =
new DataSetBuilder().code("ds2").type("T2").experiment(experiment) new DataSetBuilder().code("ds2").type("T2").experiment(experiment)
.property("B", "true"); .property("B", "true");
dsContainer =
new ContainerDataSetBuilder().code("ds-container").type("T3")
.experiment(experiment).sample(sample).contains(ds1.getDataSet())
.contains(ds2.getDataSet());
}
@Test
public void testTranslateContainerDataSetWithNoConnectionsAndRetrievingNoConnections()
{
DataSet translated =
Translator.translate(dsContainer.getContainerDataSet(),
EnumSet.noneOf(DataSet.Connections.class));
assertTrue(translated.isContainerDataSet());
assertBasicAttributes(ds1.getDataSet(), translated.getContainedDataSets().get(0));
assertBasicAttributes(ds2.getDataSet(), translated.getContainedDataSets().get(1));
assertChildrenNotRetrieved(translated);
assertParentsNotRetrieved(translated);
} }
@Test @Test
...@@ -143,6 +164,7 @@ public class TranslatorTest extends AssertJUnit ...@@ -143,6 +164,7 @@ public class TranslatorTest extends AssertJUnit
translatedProperties.get(property.getPropertyType().getCode())); translatedProperties.get(property.getPropertyType().getCode()));
} }
assertEquals(originalProperties.size(), translatedProperties.size()); assertEquals(originalProperties.size(), translatedProperties.size());
assertEquals(originalDataSet.isContainer(), translatedDataSet.isContainerDataSet());
} }
private void assertChildrenNotRetrieved(DataSet dataSet) private void assertChildrenNotRetrieved(DataSet dataSet)
......
/*
* 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.shared.basic.dto.builders;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSet;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataStore;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
/**
* @author Chandrasekhar Ramakrishnan
*/
public abstract class AbstractDataSetBuilder<T extends AbstractDataSetBuilder<?>>
{
protected final ExternalData dataSet;
/**
* Return this object typed to the concrete class. This is a subclass responsibility.
*/
abstract protected T asConcreteSubclass();
/**
* Constructor that takes a concrete data set class as an argument.
*/
protected AbstractDataSetBuilder(ExternalData concreteDataSet)
{
super();
this.dataSet = concreteDataSet;
dataSet.setDataSetProperties(new ArrayList<IEntityProperty>());
}
public T code(String code)
{
dataSet.setCode(code);
return asConcreteSubclass();
}
public T type(String dataSetTypeCode)
{
dataSet.setDataSetType(new DataSetType(dataSetTypeCode));
return asConcreteSubclass();
}
public T experiment(Experiment experiment)
{
dataSet.setExperiment(experiment);
return asConcreteSubclass();
}
public T sample(Sample sample)
{
dataSet.setSample(sample);
return asConcreteSubclass();
}
public T store(DataStore dataStore)
{
dataSet.setDataStore(dataStore);
return asConcreteSubclass();
}
public T size(long size)
{
dataSet.setSize(size);
return asConcreteSubclass();
}
public PropertyBuilder property(String key)
{
List<IEntityProperty> properties = dataSet.getProperties();
PropertyBuilder propertyBuilder = new PropertyBuilder(key);
properties.add(propertyBuilder.getProperty());
return propertyBuilder;
}
public T property(String key, String value)
{
property(key).value(value);
return asConcreteSubclass();
}
public T registrationDate(Date registrationDate)
{
dataSet.setRegistrationDate(registrationDate);
return asConcreteSubclass();
}
public T modificationDate(Date modificationDate)
{
dataSet.setModificationDate(modificationDate);
return asConcreteSubclass();
}
public T parent(DataSet parent)
{
Collection<ExternalData> parents = dataSet.getParents();
if (parents == null)
{
parents = new ArrayList<ExternalData>();
dataSet.setParents(parents);
}
parents.add(parent);
return asConcreteSubclass();
}
public T child(DataSet child)
{
List<ExternalData> children = dataSet.getChildren();
if (children == null)
{
children = new ArrayList<ExternalData>();
dataSet.setChildren(children);
}
children.add(child);
return asConcreteSubclass();
}
}
\ No newline at end of file
/*
* Copyright 2011 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.basic.dto.builders;
import java.util.ArrayList;
import java.util.List;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ContainerDataSet;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSet;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
/**
* Builder class for creating an instance of {@link DataSet} or {@link ContainerDataSet}.
*
* @author Franz-Josef Elmer
*/
public class ContainerDataSetBuilder extends AbstractDataSetBuilder<ContainerDataSetBuilder>
{
public ContainerDataSetBuilder()
{
super(new ContainerDataSet());
}
public ContainerDataSetBuilder(long id)
{
this();
dataSet.setId(id);
}
public final ContainerDataSet getContainerDataSet()
{
return dataSet.tryGetAsContainerDataSet();
}
public ContainerDataSetBuilder contains(DataSet contained)
{
List<ExternalData> containedDataSets =
dataSet.tryGetAsContainerDataSet().getContainedDataSets();
if (containedDataSets == null)
{
containedDataSets = new ArrayList<ExternalData>();
dataSet.tryGetAsContainerDataSet().setContainedDataSets(containedDataSets);
}
containedDataSets.add(contained);
return asConcreteSubclass();
}
@Override
protected ContainerDataSetBuilder asConcreteSubclass()
{
return this;
}
}
...@@ -16,34 +16,21 @@ ...@@ -16,34 +16,21 @@
package ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders; package ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders;
import java.util.ArrayList; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ContainerDataSet;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSet;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataStore;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.FileFormatType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.FileFormatType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
/** /**
* Builder class for creating an instance of {@link DataSet}. * Builder class for creating an instance of {@link DataSet} or {@link ContainerDataSet}.
* *
* @author Franz-Josef Elmer * @author Franz-Josef Elmer
*/ */
public class DataSetBuilder public class DataSetBuilder extends AbstractDataSetBuilder<DataSetBuilder>
{ {
private final DataSet dataSet;
public DataSetBuilder() public DataSetBuilder()
{ {
dataSet = new DataSet(); super(new DataSet());
dataSet.setDataSetProperties(new ArrayList<IEntityProperty>());
} }
public DataSetBuilder(long id) public DataSetBuilder(long id)
...@@ -52,119 +39,38 @@ public class DataSetBuilder ...@@ -52,119 +39,38 @@ public class DataSetBuilder
dataSet.setId(id); dataSet.setId(id);
} }
public DataSetBuilder code(String code)
{
dataSet.setCode(code);
return this;
}
public DataSetBuilder type(String dataSetTypeCode)
{
dataSet.setDataSetType(new DataSetType(dataSetTypeCode));
return this;
}
public DataSetBuilder location(String location) public DataSetBuilder location(String location)
{ {
dataSet.setLocation(location); dataSet.tryGetAsDataSet().setLocation(location);
return this;
}
public DataSetBuilder experiment(Experiment experiment)
{
dataSet.setExperiment(experiment);
return this;
}
public DataSetBuilder sample(Sample sample)
{
dataSet.setSample(sample);
return this;
}
public DataSetBuilder store(DataStore dataStore)
{
dataSet.setDataStore(dataStore);
return this; return this;
} }
public DataSetBuilder shareID(String shareID) public DataSetBuilder shareID(String shareID)
{ {
dataSet.setShareId(shareID); dataSet.tryGetAsDataSet().setShareId(shareID);
return this; return this;
} }
public DataSetBuilder fileFormat(String fileFormatType) public DataSetBuilder fileFormat(String fileFormatType)
{ {
dataSet.setFileFormatType(new FileFormatType(fileFormatType)); dataSet.tryGetAsDataSet().setFileFormatType(new FileFormatType(fileFormatType));
return this; return this;
} }
public DataSetBuilder status(DataSetArchivingStatus status) public DataSetBuilder status(DataSetArchivingStatus status)
{ {
dataSet.setStatus(status); dataSet.tryGetAsDataSet().setStatus(status);
return this;
}
public DataSetBuilder size(long size)
{
dataSet.setSize(size);
return this;
}
public PropertyBuilder property(String key)
{
List<IEntityProperty> properties = dataSet.getProperties();
PropertyBuilder propertyBuilder = new PropertyBuilder(key);
properties.add(propertyBuilder.getProperty());
return propertyBuilder;
}
public DataSetBuilder property(String key, String value)
{
property(key).value(value);
return this;
}
public DataSetBuilder registrationDate(Date registrationDate)
{
dataSet.setRegistrationDate(registrationDate);
return this;
}
public DataSetBuilder modificationDate(Date modificationDate)
{
dataSet.setModificationDate(modificationDate);
return this; return this;
} }
public DataSetBuilder parent(DataSet parent) public final DataSet getDataSet()
{ {
Collection<ExternalData> parents = dataSet.getParents(); return dataSet.tryGetAsDataSet();
if (parents == null)
{
parents = new ArrayList<ExternalData>();
dataSet.setParents(parents);
}
parents.add(parent);
return this;
} }
public DataSetBuilder child(DataSet child) @Override
protected DataSetBuilder asConcreteSubclass()
{ {
List<ExternalData> children = dataSet.getChildren();
if (children == null)
{
children = new ArrayList<ExternalData>();
dataSet.setChildren(children);
}
children.add(child);
return this; return this;
} }
public final DataSet getDataSet()
{
return dataSet;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment