Search in sources :

Example 11 with ValueProperties

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);
}
Also used : Type(eu.esdihumboldt.util.validator.NumberValidator.Type) ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) NumberValidator(eu.esdihumboldt.util.validator.NumberValidator) BigDecimal(java.math.BigDecimal)

Example 12 with ValueProperties

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;
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) Value(eu.esdihumboldt.hale.common.core.io.Value) Nullable(javax.annotation.Nullable)

Example 13 with ValueProperties

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;
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList)

Example 14 with ValueProperties

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);
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) DatabaseTable(eu.esdihumboldt.hale.io.jdbc.constraints.DatabaseTable)

Example 15 with ValueProperties

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;
    }
}
Also used : Function(com.google.common.base.Function) ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList)

Aggregations

ValueProperties (eu.esdihumboldt.hale.common.core.io.ValueProperties)26 Value (eu.esdihumboldt.hale.common.core.io.Value)11 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)8 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)4 Function (com.google.common.base.Function)1 Reference (eu.esdihumboldt.hale.common.schema.model.constraint.property.Reference)1 Enumeration (eu.esdihumboldt.hale.common.schema.model.constraint.type.Enumeration)1 GeometryMetadata (eu.esdihumboldt.hale.common.schema.model.constraint.type.GeometryMetadata)1 DatabaseTable (eu.esdihumboldt.hale.io.jdbc.constraints.DatabaseTable)1 SQLArray (eu.esdihumboldt.hale.io.jdbc.constraints.SQLArray)1 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)1 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)1 DynamicScrolledComposite (eu.esdihumboldt.hale.ui.util.components.DynamicScrolledComposite)1 DigitCountValidator (eu.esdihumboldt.util.validator.DigitCountValidator)1 Type (eu.esdihumboldt.util.validator.DigitCountValidator.Type)1 LengthValidator (eu.esdihumboldt.util.validator.LengthValidator)1 Type (eu.esdihumboldt.util.validator.LengthValidator.Type)1 NumberValidator (eu.esdihumboldt.util.validator.NumberValidator)1 Type (eu.esdihumboldt.util.validator.NumberValidator.Type)1 BigDecimal (java.math.BigDecimal)1