use of kutch.biff.marvin.utility.GenerateDatapointInfo.ListSortMethod in project Board-Instrumentation-Framework by intel.
the class ConfigurationReader method ReadGenerateDatapointInfo.
public static GenerateDatapointInfo ReadGenerateDatapointInfo(FrameworkNode inputNode) {
ArrayList<Pair<String, String>> maskList = new ArrayList<>();
ArrayList<Pair<String, String>> excludeList = new ArrayList<>();
@SuppressWarnings("unused") ListSortMethod sortPolicy = ListSortMethod.ASCENDING;
int precision = -1;
boolean hasListEntry = false;
int listEntry = 0;
if (!inputNode.hasAttribute("Method")) {
LOGGER.severe("GenerateDatapoint did not specify the Method of generate. ");
return null;
}
boolean IsGenerateNamespaceList = inputNode.getAttribute("Method").equalsIgnoreCase("MakeNamespaceList") || inputNode.getAttribute("Method").equalsIgnoreCase("MakeIDList");
String strMethod = inputNode.getAttribute("Method");
Pair<String, String> genDPInfo = getNamespaceAndIdPattern(inputNode, false);
Pair<ValueRange, String> rangeInfo = WidgetBuilder.ReadMinionSrcIndexInfo(inputNode);
if (null == genDPInfo) {
LOGGER.severe("Invalid GenerateDatapoint.");
return null;
}
for (FrameworkNode node : inputNode.getChildNodes(true)) {
if (node.getNodeName().equalsIgnoreCase("InputPattern")) {
Pair<String, String> input = getNamespaceAndIdPattern(node, IsGenerateNamespaceList);
if (null == input) {
LOGGER.severe(String.format("Invalid GenerateDatapoint %s:%s -->%s", genDPInfo.getKey(), genDPInfo.getValue(), node.getAttributeList()));
return null;
}
maskList.add(input);
} else if (node.getNodeName().equalsIgnoreCase("ExcludePattern")) {
Pair<String, String> exclude = getNamespaceAndIdPattern(node, IsGenerateNamespaceList);
if (null == exclude) {
LOGGER.severe(String.format("Invalid GenerateDatapoint %s:%s -->%s", genDPInfo.getKey(), genDPInfo.getValue(), node.getAttributeList()));
return null;
}
excludeList.add(exclude);
} else if (node.getNodeName().equalsIgnoreCase("ListEntry")) {
try {
listEntry = node.getIntegerContent();
hasListEntry = true;
} catch (NumberFormatException ex) {
LOGGER.severe("Invalid ListEntry specified for <GenerateDatapoint>: " + node.getTextContent());
return null;
}
} else if (node.getNodeName().equalsIgnoreCase("Decimals")) {
try {
precision = node.getIntegerContent();
} catch (NumberFormatException ex) {
LOGGER.severe("Invalid Decimals specified for <GenerateDatapoint>: " + node.getTextContent());
return null;
}
} else if (node.getNodeName().equalsIgnoreCase("Refresh")) {
// handle below
} else if (node.getNodeName().equalsIgnoreCase("Sort")) {
if (strMethod.equalsIgnoreCase("MakeList") || strMethod.equalsIgnoreCase("MakeNamespaceList") || strMethod.equalsIgnoreCase("MakeIDList")) {
String strSort = node.getTextContent();
if (strSort.equalsIgnoreCase("Ascending")) {
sortPolicy = ListSortMethod.ASCENDING;
} else if (strSort.equalsIgnoreCase("Descending")) {
sortPolicy = ListSortMethod.DESCENDING;
} else if (strSort.equalsIgnoreCase("None")) {
sortPolicy = ListSortMethod.NONE;
} else {
LOGGER.severe("Invalid Sort Method for Generate Datapoint: " + strSort);
return null;
}
} else {
LOGGER.warning("Specified Sort Method for Generate Datapoint, however " + strMethod + " does not support sorting. Ignoring.");
}
} else {
LOGGER.severe("Unknown entry in <GenerateDatapoint>: " + node.getNodeName());
return null;
}
}
GenerateDatapointInfo info = new GenerateDatapointInfo(genDPInfo.getKey(), genDPInfo.getValue(), maskList, excludeList, rangeInfo.getKey(), rangeInfo.getValue());
if (hasListEntry) {
if (!info.setListEntry(listEntry)) {
LOGGER.severe("Invalid ListEntry specified for <GenerateDatapoint>: " + Integer.toString(listEntry));
return null;
}
if (inputNode.hasAttribute("Separator")) {
String token = inputNode.getAttribute("Separator");
info.setSplitToken(token);
} else {
info.setSplitToken(",");
}
}
if (inputNode.getAttribute("Method").equalsIgnoreCase("Add")) {
info.setMethod(GenerateDatapointInfo.GenerateMethod.ADD);
} else if (inputNode.getAttribute("Method").equalsIgnoreCase("Average")) {
info.setMethod(GenerateDatapointInfo.GenerateMethod.AVERAGE);
} else if (inputNode.getAttribute("Method").equalsIgnoreCase("MakeList")) {
info.setMethod(GenerateDatapointInfo.GenerateMethod.MAKE_LIST);
} else if (inputNode.getAttribute("Method").equalsIgnoreCase("MakeNamespaceList")) {
info.setMethod(GenerateDatapointInfo.GenerateMethod.MAKE_NAMESPACE_LIST);
} else if (inputNode.getAttribute("Method").equalsIgnoreCase("MakeIDList")) {
info.setMethod(GenerateDatapointInfo.GenerateMethod.MAKE_ID_LIST);
} else if (inputNode.getAttribute("Method").equalsIgnoreCase("Proxy")) {
info.setMethod(GenerateDatapointInfo.GenerateMethod.PROXY);
if (inputNode.hasAttribute("ProxyID")) {
String proxyID = inputNode.getAttribute("ProxyID");
info.setProxyID(proxyID);
} else {
LOGGER.warning("GenerateDatapoint [Proxy] did not have a ProxyID, you will be unable to change it with a task.");
String proxyID = Long.toString(new Random().nextLong());
info.setProxyID(proxyID);
}
} else if (inputNode.getAttribute("Method").equalsIgnoreCase("SplitList")) {
info.setMethod(GenerateDatapointInfo.GenerateMethod.SPLIT_LIST);
if (inputNode.hasAttribute("Separator")) {
String token = inputNode.getAttribute("Separator");
info.setSplitToken(token);
} else {
info.setSplitToken(",");
}
} else if (inputNode.getAttribute("Method").equalsIgnoreCase("GetListSize")) {
info.setMethod(GenerateDatapointInfo.GenerateMethod.GET_LIST_SIZE);
} else if (inputNode.getAttribute("Method").equalsIgnoreCase("MakeIndexList")) {
info.setMethod(GenerateDatapointInfo.GenerateMethod.MAKE_INDEX_LIST);
} else {
LOGGER.severe("Invalid Method specified for GenerateDatapoint: " + inputNode.getAttribute("Method"));
return null;
}
if (inputNode.hasAttribute("Scale")) {
try {
double scale = Double.parseDouble(inputNode.getAttribute("Scale"));
info.setScale(scale);
} catch (Exception ex) {
}
}
if (inputNode.hasChild("Refresh")) {
FrameworkNode rfNode = inputNode.getChild("Refresh");
if (rfNode.hasAttribute("Frequency")) {
int freq = rfNode.getIntegerAttribute("Frequency", -1);
if (freq > 0) {
info.setMinFrequency(freq);
} else {
return null;
}
} else {
LOGGER.severe("<GenerateDatapoint> specified <Refresh> without a Frequency.");
return null;
}
if (rfNode.hasAttribute("Policy")) {
String strPolicy = rfNode.getAttribute("Policy");
if (strPolicy.equalsIgnoreCase("REMOVE")) {
info.setPolicy(GenerateDatapointInfo.RefreshPolicy.REMOVE);
} else if (strPolicy.equalsIgnoreCase("REUSE")) {
info.setPolicy(GenerateDatapointInfo.RefreshPolicy.REUSE);
} else if (strPolicy.equalsIgnoreCase("ZERO_OUT")) {
info.setPolicy(GenerateDatapointInfo.RefreshPolicy.ZERO_OUT);
} else {
LOGGER.severe("<GenerateDatapoint> specified invalid <Refresh> without a policy: " + strPolicy);
return null;
}
} else {
LOGGER.severe("<GenerateDatapoint> specified <Refresh> without a Policy.");
return null;
}
}
info.setPrecision(precision);
return info;
}
Aggregations