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