Search in sources :

Example 6 with MetaItem

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;
}
Also used : MetaItem(org.openremote.model.attribute.MetaItem) ValidationFailure(org.openremote.model.ValidationFailure)

Example 7 with MetaItem

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;
}
Also used : MetaItem(org.openremote.model.attribute.MetaItem) ValidationFailure(org.openremote.model.ValidationFailure)

Example 8 with MetaItem

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;
}
Also used : MetaItem(org.openremote.model.attribute.MetaItem) ValidationFailure(org.openremote.model.ValidationFailure)

Example 9 with MetaItem

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;
}
Also used : MetaItem(org.openremote.model.attribute.MetaItem) ValidationFailure(org.openremote.model.ValidationFailure)

Example 10 with MetaItem

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);
    }
}
Also used : MetaItem(org.openremote.model.attribute.MetaItem)

Aggregations

MetaItem (org.openremote.model.attribute.MetaItem)11 ValidationFailure (org.openremote.model.ValidationFailure)5 AssetAttribute (org.openremote.model.asset.AssetAttribute)4 java.util (java.util)2 Pair (org.openremote.model.util.Pair)2 Values (org.openremote.model.value.Values)2 Lists (com.google.common.collect.Lists)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 IsWidget (com.google.gwt.user.client.ui.IsWidget)1 HttpHandler (io.undertow.server.HttpHandler)1 Servlets (io.undertow.servlet.Servlets)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 DeploymentManager (io.undertow.servlet.api.DeploymentManager)1 ServletInfo (io.undertow.servlet.api.ServletInfo)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 ServletException (javax.servlet.ServletException)1