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));
}
}
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);
}
}
}
}
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);
}
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());
}
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());
}
Aggregations