use of org.openremote.model.attribute.MetaItem in project openremote by openremote.
the class MacroConfiguration method validateMacroConfiguration.
public static boolean validateMacroConfiguration(AssetAttribute attribute, AttributeValidationResult result) {
boolean failure = false;
if (!isMacroConfiguration(attribute)) {
failure = true;
if (result != null) {
result.addAttributeFailure(new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_MISMATCH, PROTOCOL_NAME));
}
}
int actionCount = 0;
if (attribute.getMeta() != null && !attribute.getMeta().isEmpty()) {
for (int i = 0; i < attribute.getMeta().size(); i++) {
MetaItem metaItem = attribute.getMeta().get(i);
if (isMetaNameEqualTo(metaItem, META_MACRO_ACTION)) {
actionCount++;
if (!MacroAction.fromValue(metaItem.getValue().orElse(null)).isPresent()) {
failure = true;
if (result == null) {
break;
}
result.addMetaFailure(i, new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_VALUE_MISMATCH, "Macro Action"));
}
}
}
}
if (actionCount == 0) {
failure = true;
if (result != null) {
result.addMetaFailure(new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_MISSING, META_MACRO_ACTION));
}
}
return !failure;
}
use of org.openremote.model.attribute.MetaItem in project openremote by openremote.
the class TimerConfiguration method validateTimerConfiguration.
public static boolean validateTimerConfiguration(AssetAttribute attribute, AttributeValidationResult result) {
boolean failure = false;
if (!isTimerConfiguration(attribute)) {
failure = true;
if (result != null) {
result.addAttributeFailure(new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_MISMATCH, PROTOCOL_NAME));
}
}
boolean actionFound = false;
boolean cronFound = false;
if (attribute.getMeta() != null && !attribute.getMeta().isEmpty()) {
for (int i = 0; i < attribute.getMeta().size(); i++) {
MetaItem metaItem = attribute.getMeta().get(i);
if (isMetaNameEqualTo(metaItem, META_TIMER_ACTION)) {
actionFound = true;
if (!getAction(metaItem).isPresent()) {
failure = true;
if (result == null) {
break;
}
result.addMetaFailure(i, new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_VALUE_MISMATCH, "Timer Action"));
}
} else if (isMetaNameEqualTo(metaItem, META_TIMER_CRON_EXPRESSION)) {
cronFound = true;
if (!metaItem.getValueAsString().map(TimerProtocol::createCronExpression).isPresent()) {
failure = true;
if (result == null) {
break;
}
result.addMetaFailure(i, new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_VALUE_MISMATCH, "Timer Cron Expression"));
}
}
}
}
if (!cronFound) {
failure = true;
if (result != null) {
result.addMetaFailure(new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_MISSING, META_TIMER_CRON_EXPRESSION));
}
}
if (!actionFound) {
failure = true;
if (result != null) {
result.addMetaFailure(new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_MISSING, META_TIMER_ACTION));
}
}
return !failure;
}
use of org.openremote.model.attribute.MetaItem in project openremote by openremote.
the class VelbusConfiguration method validateSerialConfiguration.
public static boolean validateSerialConfiguration(AssetAttribute protocolConfiguration, AttributeValidationResult result) {
boolean failure = false;
if (!isSerialConfiguration(protocolConfiguration)) {
failure = true;
if (result != null) {
result.addAttributeFailure(new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_MISMATCH, VelbusSerialProtocol.PROTOCOL_NAME));
}
}
boolean portFound = false;
if (protocolConfiguration.getMeta() != null && !protocolConfiguration.getMeta().isEmpty()) {
for (int i = 0; i < protocolConfiguration.getMeta().size(); i++) {
MetaItem metaItem = protocolConfiguration.getMeta().get(i);
if (isMetaNameEqualTo(metaItem, VelbusSerialProtocol.META_VELBUS_SERIAL_PORT)) {
portFound = true;
if (isNullOrEmpty(metaItem.getValueAsString().orElse(null))) {
failure = true;
if (result == null) {
break;
}
result.addMetaFailure(i, new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_VALUE_IS_REQUIRED, ValueType.STRING.name()));
}
} else if (isMetaNameEqualTo(metaItem, VelbusSerialProtocol.META_VELBUS_SERIAL_BAUDRATE)) {
int baudrate = metaItem.getValueAsInteger().orElse(0);
if (baudrate <= 0) {
failure = true;
if (result == null) {
break;
}
result.addMetaFailure(i, new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_MISMATCH));
}
}
}
}
if (!portFound) {
failure = true;
if (result != null) {
result.addMetaFailure(new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_MISSING, VelbusSocketProtocol.META_VELBUS_SOCKET_PORT));
}
}
return !failure;
}
use of org.openremote.model.attribute.MetaItem in project openremote by openremote.
the class VelbusConfiguration method validateSocketConfiguration.
public static boolean validateSocketConfiguration(AssetAttribute attribute, AttributeValidationResult result) {
boolean failure = false;
if (!isSocketConfiguration(attribute)) {
failure = true;
if (result != null) {
result.addAttributeFailure(new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_MISMATCH, VelbusSocketProtocol.PROTOCOL_NAME));
}
}
boolean hostFound = false;
boolean portFound = false;
if (attribute.getMeta() != null && !attribute.getMeta().isEmpty()) {
for (int i = 0; i < attribute.getMeta().size(); i++) {
MetaItem metaItem = attribute.getMeta().get(i);
if (isMetaNameEqualTo(metaItem, VelbusSocketProtocol.META_VELBUS_SOCKET_HOST)) {
hostFound = true;
if (isNullOrEmpty(metaItem.getValueAsString().orElse(null))) {
failure = true;
if (result == null) {
break;
}
result.addMetaFailure(i, new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_VALUE_IS_REQUIRED, ValueType.STRING.name()));
}
} else if (isMetaNameEqualTo(metaItem, VelbusSocketProtocol.META_VELBUS_SOCKET_PORT)) {
portFound = true;
int port = metaItem.getValueAsInteger().orElse(0);
if (port <= 0 || port > 65536) {
failure = true;
if (result == null) {
break;
}
result.addMetaFailure(i, new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_MISMATCH, "1-65536"));
}
}
}
}
if (!hostFound) {
failure = true;
if (result != null) {
result.addMetaFailure(new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_MISSING, VelbusSocketProtocol.META_VELBUS_SOCKET_HOST));
}
}
if (!portFound) {
failure = true;
if (result != null) {
result.addMetaFailure(new ValidationFailure(MetaItem.MetaItemFailureReason.META_ITEM_MISSING, VelbusSocketProtocol.META_VELBUS_SOCKET_PORT));
}
}
return !failure;
}
use of org.openremote.model.attribute.MetaItem in project openremote by openremote.
the class MetaEditor method buildItemList.
protected void buildItemList() {
itemListPanel.clear();
List<MetaItem> items = attribute.getMeta();
for (MetaItem item : items) {
addItem(item, true);
}
}
Aggregations