use of com.serotonin.InvalidArgumentException in project ma-modules-public by infiniteautomation.
the class ReportsDwr method validateData.
private void validateData(ProcessResult response, String name, List<ReportPointVO> points, int dateRangeType, int relativeDateType, int previousPeriodCount, int pastPeriodCount) {
if (StringUtils.isBlank(name))
response.addContextualMessage("name", "reports.validate.required");
if (StringValidation.isLengthGreaterThan(name, 100))
response.addContextualMessage("name", "reports.validate.longerThan100");
if (points.isEmpty())
response.addContextualMessage("points", "reports.validate.needPoint");
if (dateRangeType != ReportVO.DATE_RANGE_TYPE_RELATIVE && dateRangeType != ReportVO.DATE_RANGE_TYPE_SPECIFIC)
response.addGenericMessage("reports.validate.invalidDateRangeType");
if (relativeDateType != ReportVO.RELATIVE_DATE_TYPE_PAST && relativeDateType != ReportVO.RELATIVE_DATE_TYPE_PREVIOUS)
response.addGenericMessage("reports.validate.invalidRelativeDateType");
if (previousPeriodCount < 1)
response.addContextualMessage("previousPeriodCount", "reports.validate.periodCountLessThan1");
if (pastPeriodCount < 1)
response.addContextualMessage("pastPeriodCount", "reports.validate.periodCountLessThan1");
User user = Common.getUser();
DataPointDao dataPointDao = DataPointDao.instance;
for (ReportPointVO point : points) {
Permissions.ensureDataPointReadPermission(user, dataPointDao.getDataPoint(point.getPointId(), false));
try {
if (!StringUtils.isBlank(point.getColour()))
ColorUtils.toColor(point.getColour());
} catch (InvalidArgumentException e) {
response.addContextualMessage("points", "reports.validate.colour", point.getColour());
}
if (point.getWeight() <= 0)
response.addContextualMessage("points", "reports.validate.weight");
}
}
use of com.serotonin.InvalidArgumentException in project ma-core-public by infiniteautomation.
the class DataPointVO method validate.
@Override
public void validate(ProcessResult response) {
super.validate(response);
// xid,name in superclass
if (StringValidation.isLengthGreaterThan(deviceName, 255))
response.addMessage("deviceName", new TranslatableMessage("validate.notLongerThan", 255));
if (pointLocator != null) {
if (pointLocator.getDataTypeId() == DataTypes.NUMERIC && (loggingType == DataPointVO.LoggingTypes.ON_CHANGE || loggingType == DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL)) {
if (tolerance < 0)
response.addContextualMessage("tolerance", "validate.cannotBeNegative");
}
} else {
response.addContextualMessage("pointLocator", "validate.required");
return;
}
if (!LOGGING_TYPE_CODES.isValidId(loggingType))
response.addContextualMessage("loggingType", "validate.invalidValue");
if (!Common.TIME_PERIOD_CODES.isValidId(intervalLoggingPeriodType))
response.addContextualMessage("intervalLoggingPeriodType", "validate.invalidValue");
if (intervalLoggingPeriod <= 0)
response.addContextualMessage("intervalLoggingPeriod", "validate.greaterThanZero");
if (!INTERVAL_LOGGING_TYPE_CODES.isValidId(intervalLoggingType))
response.addContextualMessage("intervalLoggingType", "validate.invalidValue");
if (pointLocator.getDataTypeId() == DataTypes.IMAGE || pointLocator.getDataTypeId() == DataTypes.ALPHANUMERIC) {
if (loggingType == LoggingTypes.INTERVAL && intervalLoggingType != IntervalLoggingTypes.INSTANT)
response.addContextualMessage("intervalLoggingType", "validate.intervalType.incompatible", INTERVAL_LOGGING_TYPE_CODES.getCode(intervalLoggingType), DataTypes.CODES.getCode(pointLocator.getDataTypeId()));
}
if (!Common.TIME_PERIOD_CODES.isValidId(purgeType, TimePeriods.MILLISECONDS, TimePeriods.SECONDS, TimePeriods.MINUTES, TimePeriods.HOURS))
response.addContextualMessage("purgeType", "validate.invalidValue");
if (purgePeriod <= 0)
response.addContextualMessage("purgePeriod", "validate.greaterThanZero");
if (textRenderer == null)
response.addContextualMessage("textRenderer", "validate.required");
if (defaultCacheSize < 0)
response.addContextualMessage("defaultCacheSize", "validate.cannotBeNegative");
if (discardExtremeValues && discardHighLimit <= discardLowLimit)
response.addContextualMessage("discardHighLimit", "validate.greaterThanDiscardLow");
if (pointLocator.getDataTypeId() != DataTypes.NUMERIC && pointLocator.getDataTypeId() != DataTypes.MULTISTATE)
preventSetExtremeValues = false;
if (preventSetExtremeValues && setExtremeHighLimit <= setExtremeLowLimit)
response.addContextualMessage("setExtremeHighLimit", "validate.greaterThanSetExtremeLow");
if (!StringUtils.isBlank(chartColour)) {
try {
ColorUtils.toColor(chartColour);
} catch (InvalidArgumentException e) {
response.addContextualMessage("chartColour", "validate.invalidValue");
}
} else if (chartColour == null) {
response.addContextualMessage("chartColour", "validate.invalidValue");
}
if (!Common.ROLLUP_CODES.isValidId(rollup))
response.addContextualMessage("rollup", "validate.invalidValue");
else if (!validateRollup())
response.addContextualMessage("rollup", "validate.rollup.incompatible", rollup);
pointLocator.validate(response, this);
// Check text renderer type
if (textRenderer != null && !textRenderer.getDef().supports(pointLocator.getDataTypeId()))
response.addGenericMessage("validate.text.incompatible");
// Check chart renderer type
if (chartRenderer != null && !chartRenderer.getDef().supports(pointLocator.getDataTypeId()))
response.addGenericMessage("validate.chart.incompatible");
// Check the plot type
if (!PLOT_TYPE_CODES.isValidId(plotType))
response.addContextualMessage("plotType", "validate.invalidValue");
if (plotType != PlotTypes.STEP && pointLocator.getDataTypeId() != DataTypes.NUMERIC)
response.addContextualMessage("plotType", "validate.invalidValue");
if (!SIMPLIFY_TYPE_CODES.isValidId(simplifyType))
response.addContextualMessage("simplifyType", "validate.invalidValue");
else if (simplifyType == SimplifyTypes.TARGET && simplifyTarget < 10)
response.addContextualMessage("simplifyTarget", "validate.greaterThan", 10);
else if (simplifyType != DataPointVO.SimplifyTypes.NONE && (pointLocator.getDataTypeId() == DataTypes.ALPHANUMERIC || pointLocator.getDataTypeId() == DataTypes.IMAGE))
response.addContextualMessage("simplifyType", "validate.cannotSimplifyType", DataTypes.getDataTypeMessage(pointLocator.getDataTypeId()));
// Validate the unit
try {
if (unit == null) {
// We know the unit is invalid and will try the unitString as a likely invalid source (From DWR only)
// So the other units validate ok
unit = defaultUnit();
UnitUtil.parseLocal(this.unitString);
// Guarantee we fail
throw new Exception("No Unit");
}
} catch (Exception e) {
response.addContextualMessage("unit", "validate.unitInvalid", e.getMessage());
}
try {
if (!validateIntegralUnit()) {
response.addContextualMessage("integralUnit", "validate.unitNotCompatible");
}
} catch (Exception e) {
if (e instanceof IllegalArgumentException) {
response.addContextualMessage("integralUnit", "validate.unitInvalid", ((IllegalArgumentException) e).getCause().getMessage());
} else {
response.addContextualMessage("integralUnit", "validate.unitInvalid", e.getMessage());
}
}
try {
if (!validateRenderedUnit()) {
response.addContextualMessage("renderedUnit", "validate.unitNotCompatible");
}
} catch (Exception e) {
response.addContextualMessage("renderedUnit", "validate.unitInvalid", e.getMessage());
}
if (overrideIntervalLoggingSamples) {
if (intervalLoggingSampleWindowSize <= 0) {
response.addContextualMessage("intervalLoggingSampleWindowSize", "validate.greaterThanZero");
}
}
if ((templateId != null) && (templateId > 0)) {
DataPointPropertiesTemplateVO template = (DataPointPropertiesTemplateVO) TemplateDao.instance.get(templateId);
if (template == null) {
response.addContextualMessage("template", "pointEdit.template.validate.templateNotFound", templateId);
} else if (template.getDataTypeId() != this.pointLocator.getDataTypeId()) {
response.addContextualMessage("template", "pointEdit.template.validate.templateDataTypeNotCompatible");
}
}
Map<String, String> tags = this.tags;
if (tags != null) {
for (Entry<String, String> entry : tags.entrySet()) {
String tagKey = entry.getKey();
if (tagKey == null || entry.getValue() == null) {
response.addContextualMessage("tags", "validate.tagCantBeNull");
break;
}
if (DataPointTagsDao.NAME_TAG_KEY.equals(tagKey) || DataPointTagsDao.DEVICE_TAG_KEY.equals(tagKey)) {
response.addContextualMessage("tags", "validate.invalidTagKey");
break;
}
}
}
}
use of com.serotonin.InvalidArgumentException in project ma-core-public by infiniteautomation.
the class AsyncImageChartServlet method getImageData.
private byte[] getImageData(String imageInfo, HttpServletRequest request) throws IOException {
// Hex colour definitions need to be prefixed with '0x' instead of '#'.
try {
// Remove the / and the .png
imageInfo = imageInfo.substring(1, imageInfo.length() - 4);
// Split by underscore.
String[] imageBits = imageInfo.split("_");
// Get the data.
long from, to;
int pointIdStart;
if (imageBits[0].equals("ft")) {
from = Long.parseLong(imageBits[2]);
to = Long.parseLong(imageBits[3]);
pointIdStart = 4;
} else {
from = Common.timer.currentTimeMillis() - Long.parseLong(imageBits[1]);
to = -1;
pointIdStart = 2;
}
int width = getIntRequestParameter(request, "w", 200);
int height = getIntRequestParameter(request, "h", 100);
TimeZone timeZone = Common.getUserTimeZone(Common.getUser(request));
// Create the datasets
Synchronizer<PointDataRetriever> tasks = new Synchronizer<PointDataRetriever>();
List<Integer> dataPointIds = new ArrayList<Integer>();
for (int i = pointIdStart; i < imageBits.length; i++) {
if (imageBits[i].startsWith("w"))
width = NumberUtils.toInt(imageBits[i].substring(1), width);
else if (imageBits[i].startsWith("h"))
height = NumberUtils.toInt(imageBits[i].substring(1), height);
else {
String dataPointStr = imageBits[i];
Color colour = null;
int dataPointId;
int pipe = dataPointStr.indexOf('|');
if (pipe == -1)
dataPointId = Integer.parseInt(dataPointStr);
else {
try {
String colourStr = dataPointStr.substring(pipe + 1);
if (colourStr.startsWith("0x"))
colourStr = "#" + colourStr.substring(2);
colour = ColorUtils.toColor(colourStr);
} catch (InvalidArgumentException e) {
throw new IOException(e);
}
dataPointId = Integer.parseInt(dataPointStr.substring(0, pipe));
}
dataPointIds.add(dataPointId);
PointDataRetriever pdr = new PointDataRetriever(dataPointId, colour, width * 3, timeZone);
tasks.addTask(pdr);
}
}
if (tasks.getSize() == 0)
return null;
long start = from;
long end = to;
if (from == -1 && to == -1) {
LongPair sae = pointValueDao.getStartAndEndTime(dataPointIds);
start = sae.getL1();
end = sae.getL2();
} else if (from == -1)
start = pointValueDao.getStartTime(dataPointIds);
else if (to == -1)
end = pointValueDao.getEndTime(dataPointIds);
for (PointDataRetriever pdr : tasks.getTasks()) pdr.setRange(start, end);
// Get the timer
tasks.executeAndWait(Providers.get(TimerProvider.class).getTimer());
PointTimeSeriesCollection ptsc = new PointTimeSeriesCollection(timeZone);
for (PointDataRetriever pdr : tasks.getTasks()) pdr.addToCollection(ptsc);
return ImageChartUtils.getChartData(ptsc, width, height, from, to);
} catch (StringIndexOutOfBoundsException e) {
// no op
} catch (NumberFormatException e) {
// no op
} catch (ArrayIndexOutOfBoundsException e) {
// no op
}
return null;
}
use of com.serotonin.InvalidArgumentException in project ma-core-public by infiniteautomation.
the class ImageChartServlet method getImageData.
private byte[] getImageData(String imageInfo, HttpServletRequest request) throws IOException {
// Hex colour definitions need to be prefixed with '0x' instead of '#'.
try {
// Remove the / and the .png
imageInfo = imageInfo.substring(1, imageInfo.length() - 4);
// Split by underscore.
String[] imageBits = imageInfo.split("_");
// Get the data.
long from, to;
int pointIdStart;
if (imageBits[0].equals("ft")) {
from = Long.parseLong(imageBits[2]);
to = Long.parseLong(imageBits[3]);
pointIdStart = 4;
} else {
from = Common.timer.currentTimeMillis() - Long.parseLong(imageBits[1]);
to = -1;
pointIdStart = 2;
}
int width = getIntRequestParameter(request, "w", 200);
int height = getIntRequestParameter(request, "h", 100);
String useCacheString = request.getParameter("useCache");
boolean useCache = false;
if (useCacheString != null && Boolean.valueOf(useCacheString))
useCache = true;
TimeZone timeZone = Common.getUserTimeZone(Common.getUser(request));
// Create the datasets
DataPointVO markerPoint = null;
int pointCount = 0;
PointTimeSeriesCollection ptsc = new PointTimeSeriesCollection(timeZone);
for (int i = pointIdStart; i < imageBits.length; i++) {
if (imageBits[i].startsWith("w"))
width = NumberUtils.toInt(imageBits[i].substring(1), width);
else if (imageBits[i].startsWith("h"))
height = NumberUtils.toInt(imageBits[i].substring(1), height);
else {
String dataPointStr = imageBits[i];
Color colour = null;
int dataPointId;
int pipe = dataPointStr.indexOf('|');
if (pipe == -1)
dataPointId = Integer.parseInt(dataPointStr);
else {
try {
String colourStr = dataPointStr.substring(pipe + 1);
if (colourStr.startsWith("0x"))
colourStr = "#" + colourStr.substring(2);
colour = ColorUtils.toColor(colourStr);
} catch (InvalidArgumentException e) {
throw new IOException(e);
}
dataPointId = Integer.parseInt(dataPointStr.substring(0, pipe));
}
// Get the data.
DataPointVO dp = DataPointDao.instance.getDataPoint(dataPointId);
if (dp != null && dp.getName() != null) {
pointCount++;
markerPoint = dp;
// Get the Color if there wasn't one provided
if (colour == null) {
try {
if (dp.getChartColour() != null)
colour = ColorUtils.toColor(dp.getChartColour());
} catch (InvalidArgumentException e) {
// Munch it
}
}
PointValueFacade pointValueFacade = new PointValueFacade(dataPointId, useCache);
List<PointValueTime> data;
if (from == -1 && to == -1)
data = pointValueFacade.getPointValuesBetween(0, Common.timer.currentTimeMillis(), true, true);
else if (from == -1)
data = pointValueFacade.getPointValuesBetween(0, to, true, true);
else if (to == -1)
data = pointValueFacade.getPointValuesBetween(from, Common.timer.currentTimeMillis(), true, true);
else
data = pointValueFacade.getPointValuesBetween(from, to, true, true);
if (dp.getPointLocator().getDataTypeId() == DataTypes.NUMERIC) {
TimeSeries ts;
if (dp.isUseRenderedUnit()) {
// This works because we enforce that all Units default to the ONE Unit if not used
UnitConverter converter = null;
if (dp.getRenderedUnit() != dp.getUnit())
converter = dp.getUnit().getConverterTo(dp.getRenderedUnit());
ts = new TimeSeries(dp.getExtendedName(), null, dp.getTextRenderer().getMetaText());
double value;
for (PointValueTime pv : data) {
if (pv.getValue() != null) {
if (converter != null)
value = converter.convert(pv.getDoubleValue());
else
value = pv.getDoubleValue();
ImageChartUtils.addMillisecond(ts, pv.getTime(), value);
}
}
} else {
// No renderer, don't need it
ts = new TimeSeries(dp.getExtendedName(), null, dp.getTextRenderer().getMetaText());
for (PointValueTime pv : data) {
if (pv.getValue() != null)
ImageChartUtils.addMillisecond(ts, pv.getTime(), pv.getValue().numberValue());
}
}
ptsc.addNumericTimeSeries(new NumericTimeSeries(dp.getPlotType(), ts, colour, null));
} else {
DiscreteTimeSeries ts = new DiscreteTimeSeries(dp.getExtendedName(), dp.getTextRenderer(), colour, null);
for (PointValueTime pv : data) if (pv.getValue() != null)
ts.addValueTime(pv);
ptsc.addDiscreteTimeSeries(ts);
}
}
}
}
if (pointCount == 1) {
// Only one point. Check for limits to draw as markers.
UnitConverter uc;
if (markerPoint.getUnit() != null && markerPoint.getRenderedUnit() != null)
uc = markerPoint.getUnit().getConverterTo(markerPoint.getRenderedUnit());
else
uc = Unit.ONE.getConverterTo(Unit.ONE);
for (AbstractPointEventDetectorVO<?> ped : markerPoint.getEventDetectors()) {
if (ped.getDefinition().getEventDetectorTypeName().equals(AnalogLowLimitEventDetectorDefinition.TYPE_NAME))
ptsc.addRangeMarker(new ValueMarker(uc.convert(((AnalogLowLimitDetectorVO) ped).getLimit()), lowLimitPaint, limitStroke));
else if (ped.getDefinition().getEventDetectorTypeName().equals(AnalogHighLimitEventDetectorDefinition.TYPE_NAME))
ptsc.addRangeMarker(new ValueMarker(uc.convert(((AnalogHighLimitDetectorVO) ped).getLimit()), highLimitPaint, limitStroke));
}
}
return ImageChartUtils.getChartData(ptsc, width, height, from, to);
} catch (StringIndexOutOfBoundsException e) {
// no op
} catch (NumberFormatException e) {
// no op
} catch (ArrayIndexOutOfBoundsException e) {
// no op
}
return null;
}
use of com.serotonin.InvalidArgumentException in project ma-core-public by infiniteautomation.
the class SystemSettingsDwr method saveColourSettings.
@DwrPermission(admin = true)
public ProcessResult saveColourSettings(String chartBackgroundColour, String plotBackgroundColour, String plotGridlineColour) {
ProcessResult response = new ProcessResult();
try {
ColorUtils.toColor(chartBackgroundColour);
} catch (InvalidArgumentException e) {
response.addContextualMessage(SystemSettingsDao.CHART_BACKGROUND_COLOUR, "systemSettings.validation.invalidColour");
}
try {
ColorUtils.toColor(plotBackgroundColour);
} catch (InvalidArgumentException e) {
response.addContextualMessage(SystemSettingsDao.PLOT_BACKGROUND_COLOUR, "systemSettings.validation.invalidColour");
}
try {
ColorUtils.toColor(plotGridlineColour);
} catch (InvalidArgumentException e) {
response.addContextualMessage(SystemSettingsDao.PLOT_GRIDLINE_COLOUR, "systemSettings.validation.invalidColour");
}
if (!response.getHasMessages()) {
SystemSettingsDao systemSettingsDao = SystemSettingsDao.instance;
systemSettingsDao.setValue(SystemSettingsDao.CHART_BACKGROUND_COLOUR, chartBackgroundColour);
systemSettingsDao.setValue(SystemSettingsDao.PLOT_BACKGROUND_COLOUR, plotBackgroundColour);
systemSettingsDao.setValue(SystemSettingsDao.PLOT_GRIDLINE_COLOUR, plotGridlineColour);
}
return response;
}
Aggregations