Search in sources :

Example 1 with ServerMapping

use of org.openmuc.framework.config.ServerMapping in project OpenMUC by isc-konstanz.

the class ChannelConfigImpl method deleteServerMappings.

@Override
public void deleteServerMappings(String id) {
    if (serverMappings != null) {
        List<ServerMapping> newMappings = new ArrayList<>();
        for (ServerMapping serverMapping : serverMappings) {
            if (!serverMapping.getId().equals(id)) {
                newMappings.add(serverMapping);
            }
        }
        serverMappings = newMappings;
    }
}
Also used : ServerMapping(org.openmuc.framework.config.ServerMapping) ArrayList(java.util.ArrayList)

Example 2 with ServerMapping

use of org.openmuc.framework.config.ServerMapping in project OpenMUC by isc-konstanz.

the class RestChannelMapper method setChannelConfig.

public static void setChannelConfig(ChannelConfig cc, RestChannelConfig rcc, String idFromUrl) throws IdCollisionException, RestConfigIsNotCorrectException {
    if (cc == null) {
        throw new RestConfigIsNotCorrectException("ChannelConfig is null!");
    }
    if (rcc == null) {
        throw new RestConfigIsNotCorrectException();
    }
    if (rcc.getId() != null && !rcc.getId().isEmpty() && !idFromUrl.equals(rcc.getId())) {
        cc.setId(rcc.getId());
    }
    cc.setDescription(rcc.getDescription());
    cc.setAddress(rcc.getAddress());
    cc.setSettings(rcc.getSettings());
    List<ServerMapping> serverMappings = rcc.getServerMappings();
    if (serverMappings != null) {
        for (ServerMapping serverMapping : cc.getServerMappings()) {
            cc.deleteServerMappings(serverMapping.getId());
        }
        for (ServerMapping restServerMapping : serverMappings) {
            cc.addServerMapping(restServerMapping);
        }
    }
    cc.setUnit(rcc.getUnit());
    cc.setValueType(rcc.getValueType());
    cc.setValueTypeLength(rcc.getValueTypeLength());
    cc.setValueOffset(rcc.getValueOffset());
    cc.setScalingFactor(rcc.getScalingFactor());
    cc.setListening(rcc.isListening());
    cc.setSamplingGroup(rcc.getSamplingGroup());
    cc.setSamplingInterval(rcc.getSamplingInterval());
    cc.setSamplingTimeOffset(rcc.getSamplingTimeOffset());
    cc.setLoggingInterval(rcc.getLoggingInterval());
    cc.setLoggingDelayMaximum(rcc.getLoggingTimeMax());
    cc.setLoggingTimeOffset(rcc.getLoggingTimeOffset());
    cc.setLoggingSettings(rcc.getLoggingSettings());
    cc.setLoggingTolerance(rcc.getLoggingTolerance());
    cc.setloggingAverage(rcc.isloggingAverage());
    cc.setLoggingEvent(rcc.isLoggingEvent());
    cc.setDisabled(rcc.isDisabled());
}
Also used : ServerMapping(org.openmuc.framework.config.ServerMapping) RestConfigIsNotCorrectException(org.openmuc.framework.lib.rest.exceptions.RestConfigIsNotCorrectException)

Example 3 with ServerMapping

use of org.openmuc.framework.config.ServerMapping in project OpenMUC by isc-konstanz.

the class DataManager method notifyServer.

/**
 * Updates a specified ServerService with mapped channels.
 *
 * @param serverService
 *            ServerService object to updating
 */
protected void notifyServer(ServerService serverService) {
    List<ServerMappingContainer> relatedServerMappings = new ArrayList<>();
    for (ChannelConfig config : rootConfig.channelConfigsById.values()) {
        for (ServerMapping serverMapping : config.getServerMappings()) {
            if (serverMapping.getId().equals(serverService.getId())) {
                relatedServerMappings.add(new ServerMappingContainer(this.getChannel(config.getId()), serverMapping));
            }
        }
    }
    serverService.serverMappings(relatedServerMappings);
}
Also used : ChannelConfig(org.openmuc.framework.config.ChannelConfig) ServerMapping(org.openmuc.framework.config.ServerMapping) ServerMappingContainer(org.openmuc.framework.server.spi.ServerMappingContainer) ArrayList(java.util.ArrayList)

Example 4 with ServerMapping

use of org.openmuc.framework.config.ServerMapping in project OpenMUC by isc-konstanz.

the class ChannelConfigImpl method addChannelFromDomNode.

static void addChannelFromDomNode(Node channelConfigNode, DeviceConfig parentConfig) throws ParseException {
    String id = ChannelConfigImpl.getAttributeValue(channelConfigNode, "id");
    if (id == null) {
        throw new ParseException("channel has no id attribute");
    }
    ChannelConfigImpl config;
    try {
        config = (ChannelConfigImpl) parentConfig.addChannel(id);
    } catch (Exception e) {
        throw new ParseException(e);
    }
    NodeList channelChildren = channelConfigNode.getChildNodes();
    try {
        for (int i = 0; i < channelChildren.getLength(); i++) {
            Node childNode = channelChildren.item(i);
            String childName = childNode.getNodeName();
            if (childName.equals("#text")) {
                continue;
            } else if (childName.equals("description")) {
                config.setDescription(childNode.getTextContent());
            } else if (childName.equals("address") || childName.equals("channelAddress")) {
                config.setAddress(childNode.getTextContent());
            } else if (childName.equals("settings") || childName.equals("channelSettings")) {
                config.setSettings(childNode.getTextContent());
            } else if (childName.equals("serverMapping")) {
                NamedNodeMap attributes = childNode.getAttributes();
                Node nameAttribute = attributes.getNamedItem("id");
                if (nameAttribute != null) {
                    config.addServerMapping(new ServerMapping(nameAttribute.getTextContent(), childNode.getTextContent()));
                } else {
                    throw new ParseException("No id attribute specified for serverMapping.");
                }
            } else if (childName.equals("unit")) {
                config.setUnit(childNode.getTextContent());
            } else if (childName.equals("valueType")) {
                String valueTypeString = childNode.getTextContent().toUpperCase();
                try {
                    config.valueType = ValueType.valueOf(valueTypeString);
                } catch (IllegalArgumentException e) {
                    throw new ParseException("found unknown channel value type:" + valueTypeString);
                }
                if (config.valueType == ValueType.BYTE_ARRAY || config.valueType == ValueType.STRING) {
                    String valueTypeLengthString = getAttributeValue(childNode, "length");
                    if (valueTypeLengthString == null) {
                        throw new ParseException("length of " + config.valueType.toString() + " value type was not specified");
                    }
                    config.valueTypeLength = Integer.parseInt(valueTypeLengthString);
                }
            } else if (childName.equals("scalingFactor")) {
                config.setScalingFactor(Double.parseDouble(childNode.getTextContent()));
            } else if (childName.equals("valueOffset")) {
                config.setValueOffset(Double.parseDouble(childNode.getTextContent()));
            } else if (childName.equals("listening")) {
                config.setListening(Boolean.parseBoolean(childNode.getTextContent()));
            } else if (childName.equals("samplingInterval")) {
                config.setSamplingInterval(timeStringToMillis(childNode.getTextContent()));
            } else if (childName.equals("samplingTimeOffset")) {
                config.setSamplingTimeOffset(timeStringToMillis(childNode.getTextContent()));
            } else if (childName.equals("samplingGroup")) {
                config.setSamplingGroup(childNode.getTextContent());
            } else if (childName.equals("loggingInterval")) {
                config.setLoggingInterval(timeStringToMillis(childNode.getTextContent()));
            } else if (childName.equals("loggingDelayMaximum") || childName.equals("loggingDelayMax")) {
                config.setLoggingDelayMaximum(timeStringToMillis(childNode.getTextContent()));
            } else if (childName.equals("loggingTimeOffset")) {
                config.setLoggingTimeOffset(timeStringToMillis(childNode.getTextContent()));
            } else if (childName.equals("loggingSettings")) {
                config.setLoggingSettings(childNode.getTextContent());
                config.setReader(getAttributeValue(childNode, "reader"));
            } else if (childName.equals("loggingTolerance")) {
                config.setLoggingTolerance(Double.parseDouble(childNode.getTextContent()));
            } else if (childName.equals("loggingAverage")) {
                config.setloggingAverage(Boolean.parseBoolean(childNode.getTextContent()));
            } else if (childName.equals("loggingEvent")) {
                config.setLoggingEvent(Boolean.parseBoolean(childNode.getTextContent()));
            } else if (childName.equals("disabled")) {
                config.setDisabled(Boolean.parseBoolean(childNode.getTextContent()));
            } else {
                throw new ParseException("found unknown tag:" + childName);
            }
        }
    } catch (IllegalArgumentException e) {
        throw new ParseException(e);
    } catch (IllegalStateException e) {
        throw new ParseException(e);
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) ServerMapping(org.openmuc.framework.config.ServerMapping) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ParseException(org.openmuc.framework.config.ParseException) ParseException(org.openmuc.framework.config.ParseException) IdCollisionException(org.openmuc.framework.config.IdCollisionException)

Example 5 with ServerMapping

use of org.openmuc.framework.config.ServerMapping in project OpenMUC by isc-konstanz.

the class ChannelConfigImpl method getDomElement.

Element getDomElement(Document document) {
    Element parentElement = document.createElement("channel");
    parentElement.setAttribute("id", id);
    Element childElement;
    if (description != null) {
        childElement = document.createElement("description");
        childElement.setTextContent(description);
        parentElement.appendChild(childElement);
    }
    if (address != null) {
        childElement = document.createElement("address");
        childElement.setTextContent(address);
        parentElement.appendChild(childElement);
    }
    if (serverMappings != null) {
        for (ServerMapping serverMapping : serverMappings) {
            childElement = document.createElement("serverMapping");
            childElement.setAttribute("id", serverMapping.getId());
            childElement.setTextContent(serverMapping.getServerAddress());
            parentElement.appendChild(childElement);
        }
    }
    if (unit != null) {
        childElement = document.createElement("unit");
        childElement.setTextContent(unit);
        parentElement.appendChild(childElement);
    }
    if (valueType != null) {
        childElement = document.createElement("valueType");
        childElement.setTextContent(valueType.toString());
        if (valueTypeLength != null) {
            if (valueType == ValueType.BYTE_ARRAY || valueType == ValueType.STRING) {
                childElement.setAttribute("length", valueTypeLength.toString());
            }
        }
        parentElement.appendChild(childElement);
    }
    if (scalingFactor != null) {
        childElement = document.createElement("scalingFactor");
        childElement.setTextContent(Double.toString(scalingFactor));
        parentElement.appendChild(childElement);
    }
    if (valueOffset != null) {
        childElement = document.createElement("valueOffset");
        childElement.setTextContent(Double.toString(valueOffset));
        parentElement.appendChild(childElement);
    }
    if (listening != null) {
        childElement = document.createElement("listening");
        childElement.setTextContent(listening.toString());
        parentElement.appendChild(childElement);
    }
    if (samplingInterval != null) {
        childElement = document.createElement("samplingInterval");
        childElement.setTextContent(millisToTimeString(samplingInterval));
        parentElement.appendChild(childElement);
    }
    if (samplingTimeOffset != null) {
        childElement = document.createElement("samplingTimeOffset");
        childElement.setTextContent(millisToTimeString(samplingTimeOffset));
        parentElement.appendChild(childElement);
    }
    if (samplingGroup != null) {
        childElement = document.createElement("samplingGroup");
        childElement.setTextContent(samplingGroup);
        parentElement.appendChild(childElement);
    }
    if (settings != null) {
        childElement = document.createElement("settings");
        childElement.setTextContent(settings);
        parentElement.appendChild(childElement);
    }
    if (loggingInterval != null) {
        childElement = document.createElement("loggingInterval");
        childElement.setTextContent(millisToTimeString(loggingInterval));
        parentElement.appendChild(childElement);
    }
    if (loggingDelayMaximum != null) {
        childElement = document.createElement("loggingDelayMaximum");
        childElement.setTextContent(millisToTimeString(loggingDelayMaximum));
        parentElement.appendChild(childElement);
    }
    if (loggingTimeOffset != null) {
        childElement = document.createElement("loggingTimeOffset");
        childElement.setTextContent(millisToTimeString(loggingTimeOffset));
        parentElement.appendChild(childElement);
    }
    if (loggingSettings != null) {
        childElement = document.createElement("loggingSettings");
        childElement.setTextContent(loggingSettings);
        parentElement.appendChild(childElement);
    }
    if (loggingTolerance != null) {
        childElement = document.createElement("loggingTolerance");
        childElement.setTextContent(Double.toString(loggingTolerance));
        parentElement.appendChild(childElement);
    }
    if (loggingAverage != null) {
        childElement = document.createElement("loggingAverage");
        childElement.setTextContent(loggingAverage.toString());
        parentElement.appendChild(childElement);
    }
    if (loggingEvent != null) {
        childElement = document.createElement("loggingEvent");
        childElement.setTextContent(loggingEvent.toString());
        parentElement.appendChild(childElement);
    }
    if (disabled != null) {
        childElement = document.createElement("disabled");
        childElement.setTextContent(disabled.toString());
        parentElement.appendChild(childElement);
    }
    return parentElement;
}
Also used : ServerMapping(org.openmuc.framework.config.ServerMapping) Element(org.w3c.dom.Element)

Aggregations

ServerMapping (org.openmuc.framework.config.ServerMapping)5 ArrayList (java.util.ArrayList)2 ChannelConfig (org.openmuc.framework.config.ChannelConfig)1 IdCollisionException (org.openmuc.framework.config.IdCollisionException)1 ParseException (org.openmuc.framework.config.ParseException)1 RestConfigIsNotCorrectException (org.openmuc.framework.lib.rest.exceptions.RestConfigIsNotCorrectException)1 ServerMappingContainer (org.openmuc.framework.server.spi.ServerMappingContainer)1 Element (org.w3c.dom.Element)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1