Skip to content
Snippets Groups Projects
Commit c83cd028 authored by tpylak's avatar tpylak
Browse files

LMS-2080 fix: setting dataset properties

SVN: 20160
parent 5917504d
No related branches found
No related tags found
No related merge requests found
...@@ -17,12 +17,16 @@ ...@@ -17,12 +17,16 @@
package ch.systemsx.cisd.etlserver.registrator; package ch.systemsx.cisd.etlserver.registrator;
import java.io.File; import java.io.File;
import java.util.List;
import ch.systemsx.cisd.etlserver.ITypeExtractor; import ch.systemsx.cisd.etlserver.ITypeExtractor;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType;
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.LocatorType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.LocatorType;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExtractableData;
import ch.systemsx.cisd.openbis.generic.shared.dto.NewProperty;
import ch.systemsx.cisd.openbis.generic.shared.util.EntityHelper;
/** /**
* @author Chandrasekhar Ramakrishnan * @author Chandrasekhar Ramakrishnan
...@@ -133,4 +137,26 @@ public class DataSetRegistrationDetails<T extends DataSetInformation> implements ...@@ -133,4 +137,26 @@ public class DataSetRegistrationDetails<T extends DataSetInformation> implements
{ {
this.dataSetInformation = dataSetInformation; this.dataSetInformation = dataSetInformation;
} }
public void setPropertyValue(String propertyCode, String propertyValue)
{
ExtractableData datasetExtractableData = dataSetInformation.getExtractableData();
List<NewProperty> properties = datasetExtractableData.getDataSetProperties();
NewProperty property = EntityHelper.tryFindProperty(properties, propertyCode);
if (property != null)
{
property.setValue(propertyValue);
} else
{
properties.add(new NewProperty(propertyCode, propertyValue));
}
}
public String getPropertyValue(String propertyCode)
{
NewProperty property =
EntityHelper.tryFindProperty(dataSetInformation.getExtractableData()
.getDataSetProperties(), propertyCode);
return (property != null) ? property.getValue() : null;
}
} }
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package ch.systemsx.cisd.etlserver.registrator.api.v1.impl; package ch.systemsx.cisd.etlserver.registrator.api.v1.impl;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -95,8 +94,9 @@ public class ConversionUtils ...@@ -95,8 +94,9 @@ public class ConversionUtils
return sampleUpdate; return sampleUpdate;
} }
public static NewExternalData convertToNewExternalData(DataSetRegistrationDetails<?> registrationDetails, public static NewExternalData convertToNewExternalData(
String dataStoreCode, StorageFormat storageFormat, String dataFileRelativePath) DataSetRegistrationDetails<?> registrationDetails, String dataStoreCode,
StorageFormat storageFormat, String dataFileRelativePath)
{ {
DataSetInformation dataSetInformation = registrationDetails.getDataSetInformation(); DataSetInformation dataSetInformation = registrationDetails.getDataSetInformation();
final NewExternalData data = new NewExternalData(); final NewExternalData data = new NewExternalData();
...@@ -118,16 +118,8 @@ public class ConversionUtils ...@@ -118,16 +118,8 @@ public class ConversionUtils
data.setLocation(dataFileRelativePath.substring(data.getShareId().length() + 1)); data.setLocation(dataFileRelativePath.substring(data.getShareId().length() + 1));
data.setStorageFormat(storageFormat); data.setStorageFormat(storageFormat);
List<NewProperty> newProperties = new ArrayList<NewProperty>(); List<NewProperty> newProperties =
IEntityProperty[] properties = dataSetInformation.getProperties(); dataSetInformation.getExtractableData().getDataSetProperties();
for (int i = 0; i < properties.length; i++)
{
IEntityProperty prop = properties[i];
NewProperty newProp =
new NewProperty(prop.getPropertyType().getCode(), prop.getValue());
newProperties.add(newProp);
}
data.getExtractableData().setDataSetProperties(newProperties); data.getExtractableData().setDataSetProperties(newProperties);
return data; return data;
......
...@@ -25,11 +25,9 @@ import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperimentImmutable; ...@@ -25,11 +25,9 @@ import ch.systemsx.cisd.etlserver.registrator.api.v1.IExperimentImmutable;
import ch.systemsx.cisd.etlserver.registrator.api.v1.ISampleImmutable; import ch.systemsx.cisd.etlserver.registrator.api.v1.ISampleImmutable;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
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.Space; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory;
import ch.systemsx.cisd.openbis.generic.shared.util.EntityHelper;
/** /**
* A generic class that represents a data set for the registration API. Can be subclassed. * A generic class that represents a data set for the registration API. Can be subclassed.
...@@ -164,28 +162,11 @@ public class DataSet<T extends DataSetInformation> implements IDataSet ...@@ -164,28 +162,11 @@ public class DataSet<T extends DataSetInformation> implements IDataSet
public String getPropertyValue(String propertyCode) public String getPropertyValue(String propertyCode)
{ {
T dataSetInfo = registrationDetails.getDataSetInformation(); return registrationDetails.getPropertyValue(propertyCode);
IEntityProperty property =
EntityHelper.tryFindProperty(dataSetInfo.getProperties(), propertyCode);
return (property != null) ? property.getValue() : null;
} }
public void setPropertyValue(String propertyCode, String propertyValue) public void setPropertyValue(String propertyCode, String propertyValue)
{ {
T dataSetInfo = registrationDetails.getDataSetInformation(); registrationDetails.setPropertyValue(propertyCode, propertyValue);
IEntityProperty[] properties = dataSetInfo.getProperties();
IEntityProperty property = EntityHelper.tryFindProperty(properties, propertyCode);
if (property != null)
{
property.setValue(propertyValue);
} else
{
IEntityProperty[] newProperties = new IEntityProperty[properties.length + 1];
System.arraycopy(properties, 0, newProperties, 0, properties.length);
newProperties[properties.length] =
EntityHelper.createNewProperty(propertyCode, propertyValue);
dataSetInfo.setProperties(newProperties);
}
} }
} }
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package ch.systemsx.cisd.openbis.generic.shared.util; package ch.systemsx.cisd.openbis.generic.shared.util;
import java.util.List;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty;
...@@ -26,6 +28,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; ...@@ -26,6 +28,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
import ch.systemsx.cisd.openbis.generic.shared.dto.NewProperty;
/** /**
* @author Izabela Adamczyk * @author Izabela Adamczyk
...@@ -93,6 +96,18 @@ public class EntityHelper ...@@ -93,6 +96,18 @@ public class EntityHelper
return null; return null;
} }
public static NewProperty tryFindProperty(List<NewProperty> properties, String propertyCode)
{
for (final NewProperty property : properties)
{
if (property.getPropertyCode().equalsIgnoreCase(propertyCode))
{
return property;
}
}
return null;
}
public static String tryFindPropertyValue(IEntityPropertiesHolder holder, String propertyCode) public static String tryFindPropertyValue(IEntityPropertiesHolder holder, String propertyCode)
{ {
IEntityProperty property = null; IEntityProperty property = null;
...@@ -114,14 +129,14 @@ public class EntityHelper ...@@ -114,14 +129,14 @@ public class EntityHelper
{ {
IEntityProperty property = tryFindProperty(holder.getProperties(), propertyCode); IEntityProperty property = tryFindProperty(holder.getProperties(), propertyCode);
if (property == null) { if (property == null)
{
property = createNewProperty(propertyCode); property = createNewProperty(propertyCode);
holder.getProperties().add(property); holder.getProperties().add(property);
} }
property.setValue(propertyValue); property.setValue(propertyValue);
} }
public static IEntityProperty createNewProperty(String propertyCode, String propertyValue) public static IEntityProperty createNewProperty(String propertyCode, String propertyValue)
{ {
IEntityProperty property = createNewProperty(propertyCode); IEntityProperty property = createNewProperty(propertyCode);
...@@ -137,5 +152,4 @@ public class EntityHelper ...@@ -137,5 +152,4 @@ public class EntityHelper
property.setPropertyType(propertyType); property.setPropertyType(propertyType);
return property; return property;
} }
} }
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