use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class PointValueTimeWriter method writeNonNull.
/**
* Write a Data Value that if null contains an annotation saying there is no data at this point in time
* - useful for Rollups with gaps in the data
* @param value
* @param time
* @throws ConversionException
* @throws IOException
*/
public void writeNonNull(DataValue value, Long time, DataPointVO vo) throws ConversionException, IOException {
if (time == null)
throw new ShouldNeverHappenException("Time cannot be null");
if (value == null) {
if (useRendered) {
this.writePointValueTime(new AlphanumericValue(""), time, this.noDataMessage, vo);
} else {
this.writePointValueTime(0.0D, time, this.noDataMessage, vo);
}
} else {
if (useRendered) {
// Convert to Alphanumeric Value
String textValue = Functions.getRenderedText(vo, new PointValueTime(value, time));
this.writePointValueTime(new AlphanumericValue(textValue), time, null, vo);
} else if (unitConversion) {
// Convert Value, must be numeric
if (value instanceof NumericValue)
this.writePointValueTime(vo.getUnit().getConverterTo(vo.getRenderedUnit()).convert(value.getDoubleValue()), time, null, vo);
else
this.writePointValueTime(value, time, null, vo);
} else {
this.writePointValueTime(value, time, null, vo);
}
}
}
use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class MangoLogFilePatternReceiver method initialize.
/**
* Build the regular expression needed to parse log entries
*/
protected void initialize() {
if (host == null && path == null) {
try {
URL url = new URL(fileURL);
host = url.getHost();
path = url.getPath();
} catch (MalformedURLException e1) {
throw new ShouldNeverHappenException(e1);
}
}
if (host == null || host.trim().equals("")) {
host = DEFAULT_HOST;
}
if (path == null || path.trim().equals("")) {
path = fileURL;
}
currentMap = new HashMap<String, String>();
additionalLines = new ArrayList<String>();
matchingKeywords = new ArrayList<String>();
if (timestampFormat != null) {
dateFormat = new SimpleDateFormat(quoteTimeStampChars(timestampFormat));
timestampPatternText = convertTimestamp();
}
// if custom level definitions exist, parse them
updateCustomLevelDefinitionMap();
List<String> buildingKeywords = new ArrayList<String>();
String newPattern = logFormat;
int index = 0;
String current = newPattern;
// build a list of property names and temporarily replace the property with an empty string,
// we'll rebuild the pattern later
List<String> propertyNames = new ArrayList<String>();
while (index > -1) {
if (current.indexOf(PROP_START) > -1 && current.indexOf(PROP_END) > -1) {
index = current.indexOf(PROP_START);
String longPropertyName = current.substring(current.indexOf(PROP_START), current.indexOf(PROP_END) + 1);
String shortProp = getShortPropertyName(longPropertyName);
buildingKeywords.add(shortProp);
propertyNames.add(longPropertyName);
current = current.substring(longPropertyName.length() + 1 + index);
newPattern = singleReplace(newPattern, longPropertyName, new Integer(buildingKeywords.size() - 1).toString());
} else {
// no properties
index = -1;
}
}
/*
* we're using a treemap, so the index will be used as the key to ensure keywords are
* ordered correctly
*
* examine pattern, adding keywords to an index-based map patterns can contain only one of
* these per entry...properties are the only 'keyword' that can occur multiple times in an
* entry
*/
Iterator<String> iter = keywords.iterator();
while (iter.hasNext()) {
String keyword = (String) iter.next();
int index2 = newPattern.indexOf(keyword);
if (index2 > -1) {
buildingKeywords.add(keyword);
newPattern = singleReplace(newPattern, keyword, new Integer(buildingKeywords.size() - 1).toString());
}
}
String buildingInt = "";
for (int i = 0; i < newPattern.length(); i++) {
String thisValue = String.valueOf(newPattern.substring(i, i + 1));
if (isInteger(thisValue)) {
buildingInt = buildingInt + thisValue;
} else {
if (isInteger(buildingInt)) {
matchingKeywords.add(buildingKeywords.get(Integer.parseInt(buildingInt)));
}
// reset
buildingInt = "";
}
}
// if the very last value is an int, make sure to add it
if (isInteger(buildingInt)) {
matchingKeywords.add(buildingKeywords.get(Integer.parseInt(buildingInt)));
}
newPattern = replaceMetaChars(newPattern);
// compress one or more spaces in the pattern into the [ ]+ regexp
// (supports padding of level in log files)
newPattern = newPattern.replaceAll(MULTIPLE_SPACES_REGEXP, MULTIPLE_SPACES_REGEXP);
newPattern = newPattern.replaceAll(Pattern.quote(PATTERN_WILDCARD), REGEXP_DEFAULT_WILDCARD);
// use buildingKeywords here to ensure correct order
for (int i = 0; i < buildingKeywords.size(); i++) {
String keyword = (String) buildingKeywords.get(i);
// make the final keyword greedy (we're assuming it's the message)
if (i == (buildingKeywords.size() - 1)) {
newPattern = singleReplace(newPattern, String.valueOf(i), GREEDY_GROUP);
} else if (TIMESTAMP.equals(keyword)) {
newPattern = singleReplace(newPattern, String.valueOf(i), "(" + timestampPatternText + ")");
} else if (LOGGER.equals(keyword) || LEVEL.equals(keyword)) {
newPattern = singleReplace(newPattern, String.valueOf(i), NOSPACE_GROUP);
} else if (CLASS.equals(keyword)) {
// We want to capture . in the classname (Specific for Mango's Log format)
// newPattern = singleReplace(newPattern, String.valueOf(i), GREEDY_GROUP);
newPattern = singleReplace(newPattern, String.valueOf(i), "([^:]+)");
} else if (METHOD.equals(keyword)) {
newPattern = singleReplace(newPattern, String.valueOf(i), "([^:]+)");
} else if (LINE.equals(keyword)) {
newPattern = singleReplace(newPattern, String.valueOf(i), "(\\d+)");
} else {
newPattern = singleReplace(newPattern, String.valueOf(i), DEFAULT_GROUP);
}
}
regexp = newPattern;
getLogger().debug("regexp is " + regexp);
}
use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class TextRendererFactory method updateDataPoint.
/**
* @param data
* @param renderer
*/
public static void updateDataPoint(DataPointVO vo, BaseTextRendererModel<?> baseRendererModel) {
if (baseRendererModel.getType().equals(AnalogRenderer.getDefinition().getName())) {
AnalogTextRendererModel model = (AnalogTextRendererModel) baseRendererModel;
AnalogRenderer r = new AnalogRenderer();
r.setUseUnitAsSuffix(model.isUseUnitAsSuffix());
r.setUnit(UnitUtil.parseLocal(model.getUnit()));
r.setRenderedUnit(UnitUtil.parseLocal(model.getRenderedUnit()));
r.setFormat(model.getFormat());
r.setSuffix(model.getSuffix());
vo.setTextRenderer(r);
} else if (baseRendererModel.getType().equals(BinaryTextRenderer.getDefinition().getName())) {
BinaryTextRendererModel model = (BinaryTextRendererModel) baseRendererModel;
BinaryTextRenderer btr = new BinaryTextRenderer();
btr.setOneColour(model.getOneColour());
btr.setOneLabel(model.getOneLabel());
btr.setZeroColour(model.getZeroColour());
btr.setZeroLabel(model.getZeroLabel());
vo.setTextRenderer(btr);
} else if (baseRendererModel.getType().equals(MultistateRenderer.getDefinition().getName())) {
MultistateRenderer r = new MultistateRenderer();
MultistateTextRendererModel model = (MultistateTextRendererModel) baseRendererModel;
r.setMultistateValues(model.getMultistateValues());
vo.setTextRenderer(r);
} else if (baseRendererModel.getType().equals(NoneRenderer.getDefinition().getName())) {
NoneRenderer r = new NoneRenderer();
vo.setTextRenderer(r);
} else if (baseRendererModel.getType().equals(PlainRenderer.getDefinition().getName())) {
PlainTextRendererModel model = (PlainTextRendererModel) baseRendererModel;
PlainRenderer r = new PlainRenderer();
r.setUseUnitAsSuffix(model.isUseUnitAsSuffix());
r.setUnit(UnitUtil.parseLocal(model.getUnit()));
r.setRenderedUnit(UnitUtil.parseLocal(model.getRenderedUnit()));
r.setSuffix(model.getSuffix());
vo.setTextRenderer(r);
} else if (baseRendererModel.getType().equals(RangeRenderer.getDefinition().getName())) {
RangeTextRendererModel model = (RangeTextRendererModel) baseRendererModel;
RangeRenderer r = new RangeRenderer();
r.setUseUnitAsSuffix(model.isUseUnitAsSuffix());
r.setUnit(UnitUtil.parseLocal(model.getUnit()));
r.setRenderedUnit(UnitUtil.parseLocal(model.getRenderedUnit()));
r.setFormat(model.getFormat());
r.setRangeValues(model.getRangeValues());
vo.setTextRenderer(r);
} else if (baseRendererModel.getType().equals(TimeRenderer.getDefinition().getName())) {
TimeRenderer r = new TimeRenderer();
TimeTextRendererModel model = (TimeTextRendererModel) baseRendererModel;
r.setFormat(model.getFormat());
r.setConversionExponent(model.getConversionExponent());
vo.setTextRenderer(r);
} else {
throw new ShouldNeverHappenException("Unknown Text Renderer: " + baseRendererModel.getType());
}
}
use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class TextRendererFactory method createModel.
/**
* @param vo
* @return
*/
public static BaseTextRendererModel<?> createModel(DataPointVO vo) {
TextRenderer renderer = vo.getTextRenderer();
// For when a VO is created that has no renderer
if (renderer == null)
return new NoneTextRendererModel();
if (renderer.getTypeName().equals(AnalogRenderer.getDefinition().getName())) {
AnalogRenderer r = (AnalogRenderer) renderer;
AnalogTextRendererModel model = new AnalogTextRendererModel(r.isUseUnitAsSuffix(), UnitUtil.formatLocal(r.getUnit()), UnitUtil.formatLocal(r.getRenderedUnit()), r.getFormat(), r.getSuffix());
return model;
} else if (renderer.getTypeName().equals(BinaryTextRenderer.getDefinition().getName())) {
BinaryTextRendererModel model = new BinaryTextRendererModel();
BinaryTextRenderer btr = (BinaryTextRenderer) renderer;
model.setOneColour(btr.getOneColour());
model.setOneLabel(btr.getOneLabel());
model.setZeroColour(btr.getZeroColour());
model.setZeroLabel(btr.getZeroLabel());
return model;
} else if (renderer.getTypeName().equals(MultistateRenderer.getDefinition().getName())) {
MultistateRenderer r = (MultistateRenderer) renderer;
MultistateTextRendererModel model = new MultistateTextRendererModel(r.getMultistateValues());
return model;
} else if (renderer.getTypeName().equals(NoneRenderer.getDefinition().getName())) {
return new NoneTextRendererModel();
}
if (renderer.getTypeName().equals(PlainRenderer.getDefinition().getName())) {
PlainRenderer r = (PlainRenderer) renderer;
PlainTextRendererModel model = new PlainTextRendererModel(r.isUseUnitAsSuffix(), UnitUtil.formatLocal(r.getUnit()), UnitUtil.formatLocal(r.getRenderedUnit()), r.getSuffix());
return model;
} else if (renderer.getTypeName().equals(RangeRenderer.getDefinition().getName())) {
RangeRenderer r = (RangeRenderer) renderer;
RangeTextRendererModel model = new RangeTextRendererModel(r.isUseUnitAsSuffix(), UnitUtil.formatLocal(r.getUnit()), UnitUtil.formatLocal(r.getRenderedUnit()), r.getFormat(), r.getRangeValues());
return model;
} else if (renderer.getTypeName().equals(TimeRenderer.getDefinition().getName())) {
TimeRenderer r = (TimeRenderer) renderer;
TimeTextRendererModel model = new TimeTextRendererModel(r.getFormat(), r.getConversionExponent());
return model;
} else {
throw new ShouldNeverHappenException("Unknown Text Renderer: " + renderer.getDef().getName());
}
}
use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.
the class ChartRendererFactory method updateDataPoint.
/**
* @param data
* @param renderer
*/
public static void updateDataPoint(DataPointVO vo, BaseChartRendererModel<?> baseRendererModel) {
if (baseRendererModel == null)
// Nothing to do
return;
if (baseRendererModel.getType().equals(ImageChartRenderer.getDefinition().getName())) {
ImageChartRendererModel model = (ImageChartRendererModel) baseRendererModel;
ImageChartRenderer r = new ImageChartRenderer();
r.setNumberOfPeriods(model.getTimePeriod().getPeriods());
r.setTimePeriod(Common.TIME_PERIOD_CODES.getId(model.getTimePeriod().getPeriodType()));
vo.setChartRenderer(r);
} else if (baseRendererModel.getType().equals(ImageFlipbookRenderer.getDefinition().getName())) {
ImageFlipbookChartRendererModel model = (ImageFlipbookChartRendererModel) baseRendererModel;
ImageFlipbookRenderer r = new ImageFlipbookRenderer();
r.setLimit(model.getLimit());
vo.setChartRenderer(r);
} else if (baseRendererModel.getType().equals(StatisticsChartRenderer.getDefinition().getName())) {
StatisticsChartRendererModel model = (StatisticsChartRendererModel) baseRendererModel;
StatisticsChartRenderer r = new StatisticsChartRenderer();
r.setNumberOfPeriods(model.getTimePeriod().getPeriods());
r.setTimePeriod(Common.TIME_PERIOD_CODES.getId(model.getTimePeriod().getPeriodType()));
r.setIncludeSum(model.isIncludeSum());
vo.setChartRenderer(r);
} else if (baseRendererModel.getType().equals(TableChartRenderer.getDefinition().getName())) {
TableChartRendererModel model = (TableChartRendererModel) baseRendererModel;
TableChartRenderer r = new TableChartRenderer();
r.setLimit(model.getLimit());
vo.setChartRenderer(r);
} else {
throw new ShouldNeverHappenException("Unknown Chart Renderer: " + baseRendererModel.getType());
}
}
Aggregations