Search in sources :

Example 16 with ValueProperties

use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.

the class SQLArrayFactory method restore.

@Override
public SQLArray restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
    ValueProperties props = value.as(ValueProperties.class);
    if (props != null) {
        // read element class
        Class<?> elementType = null;
        String className = props.getSafe(NAME_ELEMENT_CLASS).as(String.class);
        if (className != null) {
            elementType = resolver.loadClass(className);
        }
        // read element database type name
        String elementTypeName = props.getSafe(NAME_ELEMENT_TYPE_NAME).as(String.class);
        // read dimension
        int dimension = props.getSafe(NAME_DIMENSION).as(Integer.class, 0);
        // read array dimension sizes
        int[] sizes = null;
        ValueList sizeList = props.getSafe(NAME_SIZES).as(ValueList.class);
        if (sizeList != null) {
            sizes = new int[sizeList.size()];
            int index = 0;
            for (Value size : sizeList) {
                sizes[index] = size.as(Integer.class, 0);
                index++;
            }
        }
        return new SQLArray(elementType, elementTypeName, dimension, sizes);
    }
    return SQLArray.NO_ARRAY;
}
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) SQLArray(eu.esdihumboldt.hale.io.jdbc.constraints.SQLArray)

Example 17 with ValueProperties

use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.

the class XmlElementsFactory method valueToElement.

private XmlElement valueToElement(Value val, Definition<?> definition, @SuppressWarnings("unused") TypeResolver typeResolver) {
    ValueProperties props = val.as(ValueProperties.class);
    if (props != null) {
        QName name = props.getSafe("name").as(QName.class);
        if (name != null) {
            QName substitutionGroup = props.getSafe("substitutionGroup").as(QName.class);
            TypeDefinition type = null;
            if (definition instanceof TypeDefinition) {
                type = (TypeDefinition) definition;
            } else {
                log.error("Wrong definition for XmlElements constraint: " + definition);
            }
            return new XmlElement(name, type, substitutionGroup);
        }
    }
    return null;
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) QName(javax.xml.namespace.QName) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 18 with ValueProperties

use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.

the class XmlElementsFactory method elementToValue.

private Value elementToValue(XmlElement element, @SuppressWarnings("unused") TypeReferenceBuilder refBuilder) {
    ValueProperties result = new ValueProperties();
    result.put("name", Value.complex(element.getName()));
    if (element.getSubstitutionGroup() != null) {
        result.put("substitutionGroup", Value.complex(element.getSubstitutionGroup()));
    }
    return result.toValue();
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties)

Example 19 with ValueProperties

use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.

the class ProjectVariables method setVariable.

/**
 * Helper method to store a project variable value.
 *
 * @param name the variable name
 * @param value the variable value
 * @param projectConfiguration the project configuration service
 */
public static void setVariable(String name, Value value, ComplexConfigurationService projectConfiguration) {
    Value variables = projectConfiguration.getProperty(PROJECT_PROPERTY_VARIABLES);
    ValueProperties properties = variables.as(ValueProperties.class);
    if (properties == null) {
        properties = new ValueProperties();
    } else {
        if (variables.getValue() != null) {
            log.error("Unknown representation of project variables");
        }
    }
    properties.put(name, value);
    projectConfiguration.setProperty(PROJECT_PROPERTY_VARIABLES, Value.complex(properties));
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) Value(eu.esdihumboldt.hale.common.core.io.Value)

Example 20 with ValueProperties

use of eu.esdihumboldt.hale.common.core.io.ValueProperties in project hale by halestudio.

the class ProjectVariables method getValue.

/**
 * Get the value for a given variable name.
 *
 * @param name the variable name
 * @return the project variable value or {@link Value#NULL}
 */
public Value getValue(String name) {
    // 1st priority: system property
    String value = System.getProperty(PREFIX_SYSTEM_PROPERTY + name);
    if (value != null) {
        return Value.of(value);
    }
    // 2nd priority: environment variable
    value = System.getenv(PREFIX_ENV + name);
    if (value != null) {
        return Value.of(value);
    }
    // 3rd priority: use value stored in project
    if (projectInfo != null) {
        Value variables = projectInfo.getProperty(PROJECT_PROPERTY_VARIABLES);
        ValueProperties properties = variables.as(ValueProperties.class);
        if (properties != null) {
            return properties.getSafe(name);
        } else {
            if (variables.getValue() != null) {
                log.error("Unknown representation of project variables");
            }
        }
    }
    return Value.NULL;
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) Value(eu.esdihumboldt.hale.common.core.io.Value)

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