Skip to content
Snippets Groups Projects
Commit 8381f42f authored by izabel's avatar izabel
Browse files

fix: material property type translator

SVN: 10514
parent 651a9a51
No related branches found
No related tags found
No related merge requests found
......@@ -16,10 +16,14 @@
package ch.systemsx.cisd.openbis.generic.client.web.server.translator;
import java.util.Set;
import org.apache.commons.lang.StringEscapeUtils;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType;
import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialTypePropertyTypePE;
import ch.systemsx.cisd.openbis.generic.shared.util.HibernateUtils;
/**
* Translates {@link MaterialTypePE} to {@link MaterialType}.
......@@ -34,6 +38,11 @@ public class MaterialTypeTranslator
}
public static MaterialType translate(MaterialTypePE entityTypeOrNull)
{
return translate(entityTypeOrNull, true);
}
public static MaterialType translate(MaterialTypePE entityTypeOrNull, boolean withProperties)
{
if (entityTypeOrNull == null)
{
......@@ -44,11 +53,24 @@ public class MaterialTypeTranslator
result.setDescription(StringEscapeUtils.escapeHtml(entityTypeOrNull.getDescription()));
result.setDatabaseInstance(DatabaseInstanceTranslator.translate(entityTypeOrNull
.getDatabaseInstance()));
if (withProperties == false)
{
unsetMaterialTypes(entityTypeOrNull.getMaterialTypePropertyTypes());
}
result.setMaterialTypePropertyTypes(MaterialTypePropertyTypeTranslator.translate(
entityTypeOrNull.getMaterialTypePropertyTypes(), result));
return result;
}
private static void unsetMaterialTypes(Set<MaterialTypePropertyTypePE> materialTypePropertyTypes)
{
if ((HibernateUtils.isInitialized(materialTypePropertyTypes)))
for (MaterialTypePropertyTypePE mtpt : materialTypePropertyTypes)
{
mtpt.getPropertyType().setMaterialType(null);
}
}
public static MaterialTypePE translate(MaterialType type)
{
final MaterialTypePE result = new MaterialTypePE();
......
......@@ -59,15 +59,8 @@ public final class PropertyTypeTranslator
result.setLabel(StringEscapeUtils.escapeHtml(propertyType.getLabel()));
result.setDataType(DataTypeTranslator.translate(propertyType.getType()));
result.setVocabulary(VocabularyTranslator.translate(propertyType.getVocabulary()));
if (materialType == null)
{
result
.setMaterialType(MaterialTypeTranslator.translate(propertyType
.getMaterialType()));
} else
{
result.setMaterialType(materialType);
}
result.setMaterialType(MaterialTypeTranslator.translate(propertyType.getMaterialType(),
false));
result.setDescription(StringEscapeUtils.escapeHtml(propertyType.getDescription()));
result.setSampleTypePropertyTypes(SampleTypePropertyTypeTranslator.translate(propertyType
.getSampleTypePropertyTypes(), result));
......
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