diff --git a/src/main/java/org/caosdb/server/datatype/BooleanValue.java b/src/main/java/org/caosdb/server/datatype/BooleanValue.java index 8fbe6bcb5e47126a349bee84d21c4f2025f727b3..2bcbb48bcaf52ec0ef9a83a6d81d51190d1249ef 100644 --- a/src/main/java/org/caosdb/server/datatype/BooleanValue.java +++ b/src/main/java/org/caosdb/server/datatype/BooleanValue.java @@ -39,6 +39,6 @@ public class BooleanValue extends AbstractEnumValue { } public boolean getValue() { - return toString().equals("TRUE"); + return toDatabaseString().equals("TRUE"); } } diff --git a/src/main/java/org/caosdb/server/grpc/EntityTransactionServiceImpl.java b/src/main/java/org/caosdb/server/grpc/EntityTransactionServiceImpl.java index 32cb1e27e76a469151508ab56c17d207e1ef06f9..ca8f636472dd6b20191cd20abaf57ccd92b5c80c 100644 --- a/src/main/java/org/caosdb/server/grpc/EntityTransactionServiceImpl.java +++ b/src/main/java/org/caosdb/server/grpc/EntityTransactionServiceImpl.java @@ -86,9 +86,11 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa private final FileTransmissionServiceImpl fileTransmissionService; public String getStringUnit(final EntityInterface entity) { - for (final Property p : entity.getProperties()) { + final Iterator<Property> iterator = entity.getProperties().iterator(); + while (iterator.hasNext()) { + final Property p = iterator.next(); if (MagicTypes.UNIT.getId() == p.getId()) { - p.setEntityStatus(EntityStatus.IGNORE); + iterator.remove(); return p.getValue().toString(); } } @@ -115,10 +117,18 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa entityBuilder.setDataType(convert(from.getDatatype())); } if (from.hasValue()) { + try { + from.parseValue(); + } catch (final Message e) { + // ignore. This problem should be handled elsewhere because this is + // only for the serialization of the data and not for the validation. + // In any case, the string representation can be used. + } entityBuilder.setValue(convert(from.getValue())); } - if (from.hasUnit()) { - entityBuilder.setUnit(getStringUnit(from)); + final String unit = getStringUnit(from); + if (unit != null) { + entityBuilder.setUnit(unit); } if (from.hasProperties()) { entityBuilder.addAllProperties(convert(from.getProperties())); @@ -218,10 +228,18 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa if (from.hasDatatype()) { builder.setDataType(convert(from.getDatatype())); } - if (from.hasUnit()) { - builder.setUnit(getStringUnit(from)); + final String unit = getStringUnit(from); + if (unit != null) { + builder.setUnit(unit); } if (from.hasValue()) { + try { + from.parseValue(); + } catch (final Message e) { + // ignore. This problem should be handled elsewhere because this is + // only for the serialization of the data and not for the validation. + // In any case, the string representation can be used. + } builder.setValue(convert(from.getValue())); } builder.setImportance(convert(from.getStatementStatus())); @@ -763,7 +781,9 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa } if (from.getPropertiesCount() > 0) { - entity.getProperties().addAll(convertProperties(from.getPropertiesList())); + final StatementStatus defaultImportance = + entity.getRole() == Role.RecordType ? StatementStatus.RECOMMENDED : StatementStatus.FIX; + entity.getProperties().addAll(convertProperties(from.getPropertiesList(), defaultImportance)); } if (from.getParentsCount() > 0) { entity.getParents().addAll(convertParents(from.getParentsList())); @@ -882,16 +902,18 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa } private Collection<Property> convertProperties( - final List<org.caosdb.api.entity.v1alpha1.Property> propertiesList) { + final List<org.caosdb.api.entity.v1alpha1.Property> propertiesList, + final StatementStatus defaultImportance) { final Collection<Property> result = new LinkedList<>(); propertiesList.forEach( e -> { - result.add(convert(e)); + result.add(convert(e, defaultImportance)); }); return result; } - private Property convert(final org.caosdb.api.entity.v1alpha1.Property e) { + private Property convert( + final org.caosdb.api.entity.v1alpha1.Property e, final StatementStatus defaultImportance) { final Property result = new Property(); try { @@ -912,6 +934,12 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa } if (e.getImportance() != Importance.IMPORTANCE_UNSPECIFIED) { result.setStatementStatus(convert(e.getImportance())); + } else { + result.setStatementStatus(defaultImportance); + } + // TODO remove this hard-coded setting when the API supports flags + if (result.getFlag("inheritance") == null) { + result.setFlag("inheritance", "fix"); } return result;