Search in sources :

Example 76 with Value

use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.

the class SettingValueFactory method newBooleanSettingValue.

/**
 * Constructs a new {@code Boolean} setting value from the supplied key and string value.
 *
 * @param key         the setting key
 * @param stringValue the value as string
 *
 * @return the implementation specific {@code SettingValue}
 */
default SettingValue<Boolean> newBooleanSettingValue(String key, String stringValue) {
    Boolean value;
    if (nullOrEmpty(stringValue)) {
        return newBooleanSettingValue(key, Boolean.FALSE);
    }
    String lc = stringValue.trim().toLowerCase(Locale.ROOT);
    switch(lc) {
        case "true":
        case "yes":
        case "on":
        case "1":
            return newBooleanSettingValue(key, Boolean.TRUE);
        case "false":
        case "no":
        case "off":
        case "0":
            return newBooleanSettingValue(key, Boolean.FALSE);
        default:
            throw new ConfigurationError(String.format("'%s' is not a valid boolean value", stringValue));
    }
}
Also used : MultilingualString(org.n52.janmayen.i18n.MultilingualString)

Example 77 with Value

use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.

the class SettingsServiceImpl method configure.

private void configure(Object object, boolean persist) throws ConfigurationError {
    Class<?> clazz = object.getClass();
    if (clazz.getAnnotation(Configurable.class) == null) {
        return;
    }
    LOG.debug("Configuring object {}", object);
    for (Method method : clazz.getMethods()) {
        Setting s = method.getAnnotation(Setting.class);
        if (s != null) {
            String key = s.value();
            if (key == null || key.isEmpty()) {
                throw new ConfigurationError(String.format("Invalid value for @Setting: '%s'", key));
            } else if (getDefinitionByKey(key) == null && s.required()) {
                throw noSettingDefinitionFound(key);
            } else if (method.getParameterTypes().length != 1) {
                throw new ConfigurationError(String.format("Method %s annotated with @Setting in %s has a invalid method signature", method, clazz));
            } else if (!Modifier.isPublic(method.getModifiers())) {
                throw new ConfigurationError(String.format("Non-public method %s annotated with @Setting in %s", method, clazz));
            } else {
                configure(new ConfigurableObject(method, object, key, s.required()), persist);
            }
        }
    }
}
Also used : Setting(org.n52.faroe.annotation.Setting) Configurable(org.n52.faroe.annotation.Configurable) Method(java.lang.reflect.Method)

Example 78 with Value

use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.

the class SweHelper method createBlock.

@SuppressFBWarnings("BC_VACUOUS_INSTANCEOF")
private List<String> createBlock(SweAbstractDataComponent elementType, Time phenomenonTime, String phenID, Value<?> value) {
    if (elementType instanceof SweDataRecord) {
        SweDataRecord elementTypeRecord = (SweDataRecord) elementType;
        List<String> block = new ArrayList<>(elementTypeRecord.getFields().size());
        if (!(value instanceof NilTemplateValue)) {
            elementTypeRecord.getFields().forEach(field -> {
                if (field.getElement() instanceof SweTime || field.getElement() instanceof SweTimeRange) {
                    block.add(DateTimeHelper.format(phenomenonTime));
                } else if (field.getElement() instanceof SweAbstractDataComponent && field.getElement().getDefinition().equals(phenID)) {
                    block.add(value.getValue().toString());
                } else if (field.getElement() instanceof SweObservableProperty) {
                    block.add(phenID);
                }
            });
        }
        return block;
    }
    String exceptionMsg = String.format("Type of ElementType is not supported: %s", elementType != null ? elementType.getClass().getName() : "null");
    LOGGER.debug(exceptionMsg);
    throw new IllegalArgumentException(exceptionMsg);
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) ArrayList(java.util.ArrayList) NilTemplateValue(org.n52.shetland.ogc.om.values.NilTemplateValue) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) SweObservableProperty(org.n52.shetland.ogc.swe.simpleType.SweObservableProperty) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 79 with Value

use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.

the class FieldDecoder method decodeTime.

protected SweAbstractDataComponent decodeTime(JsonNode node) throws DecodingException {
    SweTime swe = new SweTime();
    if (node.hasNonNull(JSONConstants.VALUE)) {
        String value = node.path(JSONConstants.VALUE).textValue();
        swe.setValue(parseDateTime(value));
    }
    return swe.setUom(node.path(JSONConstants.UOM).textValue());
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime)

Example 80 with Value

use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.

the class ObservationDecoder method parseNamedValueValue.

private NamedValue<?> parseNamedValueValue(JsonNode value) throws DecodingException {
    if (value.isTextual()) {
        NamedValue<W3CHrefAttribute> nv = new NamedValue<>();
        nv.setValue(new HrefAttributeValue(new W3CHrefAttribute(value.asText())));
        return nv;
    } else if (value.isBoolean()) {
        NamedValue<Boolean> nv = new NamedValue<>();
        nv.setValue(new BooleanValue(value.asBoolean()));
        return nv;
    } else if (value.isInt()) {
        NamedValue<Integer> nv = new NamedValue<>();
        nv.setValue(new CountValue(value.asInt()));
        return nv;
    } else if (value.isObject()) {
        if (value.has(JSONConstants.CODESPACE)) {
            NamedValue<String> nv = new NamedValue<>();
            nv.setValue(parseCategroyValue(value));
            return nv;
        } else if (value.has(JSONConstants.UOM)) {
            NamedValue<BigDecimal> nv = new NamedValue<>();
            nv.setValue(parseQuantityValue(value));
            return nv;
        } else if (value.has(JSONConstants.COORDINATES)) {
            NamedValue<Geometry> nv = new NamedValue<>();
            nv.setValue(new GeometryValue(geometryDecoder.decodeJSON(value, false)));
            return nv;
        }
    }
    throw new DecodingException("%s is not yet supported", value.toString());
}
Also used : NamedValue(org.n52.shetland.ogc.om.NamedValue) DecodingException(org.n52.svalbard.decode.exception.DecodingException) W3CHrefAttribute(org.n52.shetland.w3c.xlink.W3CHrefAttribute) BigDecimal(java.math.BigDecimal) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) HrefAttributeValue(org.n52.shetland.ogc.om.values.HrefAttributeValue)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)28 Test (org.junit.Test)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)20 IoParameters (org.n52.io.request.IoParameters)19 SweField (org.n52.shetland.ogc.swe.SweField)16 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)13 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)13 RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)12 List (java.util.List)9 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)9 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)7 CategoryValue (org.n52.shetland.ogc.om.values.CategoryValue)7 CountValue (org.n52.shetland.ogc.om.values.CountValue)7 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)7 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)7 DecodingException (org.n52.svalbard.decode.exception.DecodingException)7 DateTime (org.joda.time.DateTime)6 ModelAndView (org.springframework.web.servlet.ModelAndView)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ArrayList (java.util.ArrayList)5