use of org.openremote.model.value.ArrayValue in project openremote by openremote.
the class Protocol method getLinkedAttributeMessageFilters.
/**
* Extract the {@link MessageFilter}s from the specified {@link Attribute}
*/
static Optional<List<MessageFilter>> getLinkedAttributeMessageFilters(Attribute attribute) {
if (attribute == null) {
return Optional.empty();
}
Optional<ArrayValue> arrayValueOptional = attribute.getMetaItem(META_PROTOCOL_FILTERS).flatMap(AbstractValueHolder::getValueAsArray);
if (!arrayValueOptional.isPresent()) {
return Optional.empty();
}
try {
ArrayValue arrayValue = arrayValueOptional.get();
List<MessageFilter> messageFilters = new ArrayList<>(arrayValue.length());
for (int i = 0; i < arrayValue.length(); i++) {
ObjectValue objValue = arrayValue.getObject(i).orElseThrow(() -> new IllegalArgumentException("Attribute protocol filters meta item is invalid"));
MessageFilter filter = deserialiseMessageFilter(objValue);
messageFilters.add(filter);
}
return messageFilters.isEmpty() ? Optional.empty() : Optional.of(messageFilters);
} catch (IllegalArgumentException e) {
LOG.log(Level.WARNING, e.getMessage(), e);
}
return Optional.empty();
}
use of org.openremote.model.value.ArrayValue in project openremote by openremote.
the class AbstractHttpServerProtocol method createDeployment.
protected ResteasyDeployment createDeployment(Application application, AssetAttribute protocolConfiguration) {
ResteasyDeployment resteasyDeployment = new ResteasyDeployment();
resteasyDeployment.setApplication(application);
List<String> allowedOrigins;
if (devMode) {
allowedOrigins = Collections.singletonList("*");
} else {
Optional<MetaItem> allowedOriginsMeta = protocolConfiguration.getMetaItem(META_PROTOCOL_ALLOWED_ORIGINS);
allowedOrigins = allowedOriginsMeta.flatMap(AbstractValueHolder::getValueAsString).map(Collections::singletonList).orElseGet(() -> allowedOriginsMeta.flatMap(AbstractValueHolder::getValueAsArray).flatMap(arrayValue -> Values.getArrayElements(arrayValue, StringValue.class, true, false, StringValue::getString)).orElse(null));
}
if (allowedOrigins != null) {
String allowedMethods = protocolConfiguration.getMetaItem(META_PROTOCOL_ALLOWED_METHODS).flatMap(AbstractValueHolder::getValueAsString).orElse(DEFAULT_ALLOWED_METHODS);
if (TextUtil.isNullOrEmpty(allowedMethods)) {
throw new IllegalArgumentException("Allowed methods meta item must be a non empty string: " + META_PROTOCOL_ALLOWED_METHODS);
}
CorsFilter corsFilter = new CorsFilter();
corsFilter.getAllowedOrigins().addAll(allowedOrigins);
corsFilter.setAllowedMethods(allowedMethods);
resteasyDeployment.getProviders().add(corsFilter);
}
return resteasyDeployment;
}
use of org.openremote.model.value.ArrayValue in project openremote by openremote.
the class ColorRGB method asArrayValue.
public ArrayValue asArrayValue() {
ArrayValue array = Values.createArray();
array.set(0, Values.create(getRed()));
array.set(1, Values.create(getGreen()));
array.set(2, Values.create(getBlue()));
return array;
}
use of org.openremote.model.value.ArrayValue in project openremote by openremote.
the class MapWidget method flyTo.
public void flyTo(double[] coordinates) {
if (!isMapReady())
throw new IllegalStateException("Map not ready");
if (coordinates == null || coordinates.length != 2)
return;
ObjectValue options = Values.createObject();
ArrayValue center = Values.createArray();
center.set(0, coordinates[0]);
center.set(1, coordinates[1]);
options.put("center", center);
mapboxMap.flyTo(options.asAny());
}
use of org.openremote.model.value.ArrayValue in project openremote by openremote.
the class TypeMapper method toDPTXlator.
@SuppressWarnings("ConstantConditions")
public static DPTXlator toDPTXlator(Datapoint datapoint, Value value) throws Exception {
DPTXlator translator = TranslatorTypes.createTranslator(0, datapoint.getDPT());
if (translator instanceof DPTXlatorBoolean && value != null && value.getType() == ValueType.BOOLEAN) {
((DPTXlatorBoolean) translator).setValue(Values.getBoolean(value).get());
} else if (translator instanceof DPTXlator8BitUnsigned && value != null && value.getType() == ValueType.NUMBER) {
((DPTXlator8BitUnsigned) translator).setValue(Values.getIntegerCoerced(value).orElse(0));
} else if (translator instanceof DPTXlatorRGB && value != null && value.getType() == ValueType.ARRAY) {
ArrayValue arrayValue = Values.getArray(value).get();
((DPTXlatorRGB) translator).setValue(arrayValue.getNumber(0).get().intValue(), arrayValue.getNumber(1).get().intValue(), arrayValue.getNumber(2).get().intValue());
} else {
// TODO depending on the DPT and the value, a more sophisticated translation is needed
translator.setValue(value.toString());
}
return translator;
}
Aggregations