use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class NumberValidatorFactory method restore.
@Override
public Validator restore(Value value) throws Exception {
ValueProperties props = value.as(ValueProperties.class);
Type type = Type.valueOf(props.getSafe(P_TYPE).as(String.class));
BigDecimal val = props.getSafe(P_VALUE).as(BigDecimal.class);
return new NumberValidator(type, val);
}
use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class Message method applyFromValue.
/**
* Apply from a given {@link Value}, if the value represents a
* {@link Message}.
*
* @param value the value to interpret as {@link Message}
* @return this for chaining
*/
@Nullable
public Message applyFromValue(Value value) {
ValueProperties props = value.as(ValueProperties.class);
if (props != null) {
String text = props.get("text").as(String.class);
if (text != null && !text.isEmpty()) {
//
setText(text).setAuthor(//
props.getSafe("author").as(String.class)).setFormat(//
props.getSafe("format").as(String.class)).setCategory(//
props.getSafe("category").as(String.class)).setDismissed(//
props.getSafe("dismissed").as(Boolean.class, false)).setCustomPayload(props.get("payload"));
ValueList tags = props.getSafe("tags").as(ValueList.class);
this.tags.clear();
if (tags != null) {
for (Value tag : tags) {
String tagString = tag.as(String.class);
if (tagString != null) {
addTag(tagString);
}
}
}
ValueList comments = props.getSafe("comments").as(ValueList.class);
this.comments.clear();
if (comments != null) {
for (Value commentVal : comments) {
Optional<Comment> comment = Comment.fromValue(commentVal);
comment.ifPresent(c -> addComment(c));
}
}
}
}
return this;
}
use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class Message method toProperties.
/**
* Convert to a {@link Value}.
*
* @return the value representation of the comment
*/
public ValueProperties toProperties() {
ValueProperties props = new ValueProperties();
if (author != null) {
props.put("author", Value.of(author));
}
if (text != null) {
props.put("text", Value.of(text));
}
if (format != null) {
props.put("format", Value.of(format));
}
if (category != null) {
props.put("category", Value.of(category));
}
if (dismissed) {
props.put("dismissed", Value.of(dismissed));
}
if (customPayload != null) {
props.put("payload", customPayload);
}
if (!tags.isEmpty()) {
ValueList tagList = new ValueList(tags.stream().map(tag -> Value.of(tag)).collect(Collectors.toList()));
props.put("tags", tagList.toValue());
}
if (!comments.isEmpty()) {
ValueList commentList = new ValueList(comments.stream().map(comment -> Value.of(comment)).collect(Collectors.toList()));
props.put("comments", commentList.toValue());
}
return props;
}
use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class DatabaseTableFactory method restore.
@Override
public DatabaseTable restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
String schema = null;
String table = null;
boolean useQuote = true;
ValueProperties props = value.as(ValueProperties.class);
if (props != null) {
schema = props.getSafe(NAME_SCHEMA).as(String.class);
table = props.getSafe(NAME_TABLE).as(String.class);
useQuote = props.getSafe(USE_QUOTE).as(Boolean.class);
}
if (table == null) {
throw new IllegalStateException("Database table constraint w/o table name");
}
return new DatabaseTable(schema, table, useQuote);
}
use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.
the class SQLArrayFactory method store.
@Override
public Value store(SQLArray constraint, TypeReferenceBuilder typeIndex) throws Exception {
ValueProperties props = new ValueProperties();
if (constraint.isArray()) {
// store element class
Class<?> elementType = constraint.getElementType();
if (elementType != null) {
props.put(NAME_ELEMENT_CLASS, Value.of(elementType.getName()));
}
// store element database type name
String typeName = constraint.getElementTypeName();
if (typeName != null) {
props.put(NAME_ELEMENT_TYPE_NAME, Value.of(typeName));
}
// store dimension
props.put(NAME_DIMENSION, Value.of(constraint.getDimension()));
// store array dimension sizes
List<Integer> sizes = constraint.getSizes();
if (sizes != null && !sizes.isEmpty()) {
ValueList sizeList = new ValueList(Collections2.transform(sizes, new Function<Integer, Value>() {
@Override
public Value apply(Integer input) {
return Value.of(input);
}
}));
props.put(NAME_SIZES, Value.complex(sizeList));
}
return props.toValue();
} else {
return null;
}
}
Aggregations