use of com.serotonin.m2m2.view.chart.ChartRenderer in project ma-core-public by infiniteautomation.
the class BaseDwr method setChart.
protected static void setChart(DataPointVO point, BasePointState state, HttpServletRequest request, Map<String, Object> model) {
ChartRenderer chartRenderer = point.getChartRenderer();
if (chartRenderer != null) {
chartRenderer.addDataToModel(model, point);
String snippet = chartRenderer.getChartSnippetFilename();
state.setChart(generateContent(request, snippet, model));
}
}
use of com.serotonin.m2m2.view.chart.ChartRenderer in project ma-modules-public by infiniteautomation.
the class ChartRendererFactory method createModel.
/**
* @param vo
* @return
*/
public static BaseChartRendererModel<?> createModel(DataPointVO vo) {
ChartRenderer renderer = vo.getChartRenderer();
if (renderer == null)
return null;
if (renderer.getTypeName().equals(ImageChartRenderer.getDefinition().getName())) {
ImageChartRenderer r = (ImageChartRenderer) renderer;
TimePeriodModel tp = new TimePeriodModel(r.getNumberOfPeriods(), r.getTimePeriod());
ImageChartRendererModel model = new ImageChartRendererModel(tp);
return model;
} else if (renderer.getTypeName().equals(ImageFlipbookRenderer.getDefinition().getName())) {
ImageFlipbookRenderer r = (ImageFlipbookRenderer) renderer;
ImageFlipbookChartRendererModel model = new ImageFlipbookChartRendererModel(r.getLimit());
return model;
} else if (renderer.getTypeName().equals(StatisticsChartRenderer.getDefinition().getName())) {
StatisticsChartRenderer r = (StatisticsChartRenderer) renderer;
TimePeriodModel tp = new TimePeriodModel(r.getNumberOfPeriods(), r.getTimePeriod());
StatisticsChartRendererModel model = new StatisticsChartRendererModel(tp, r.isIncludeSum());
return model;
} else if (renderer.getTypeName().equals(TableChartRenderer.getDefinition().getName())) {
TableChartRenderer r = (TableChartRenderer) renderer;
TableChartRendererModel model = new TableChartRendererModel(r.getLimit());
return model;
} else {
throw new ShouldNeverHappenException("Unknown Chart Renderer: " + renderer.getDef().getName());
}
}
use of com.serotonin.m2m2.view.chart.ChartRenderer in project ma-modules-public by infiniteautomation.
the class VirtualEditDwr method createTestSource.
/**
* Test Method for debugging system.
*/
@DwrPermission(admin = true)
public void createTestSource() {
VirtualDataSourceVO ds = new VirtualDataSourceVO();
DataSourceDefinition def = ModuleRegistry.getDataSourceDefinition("VIRTUAL");
ds = (VirtualDataSourceVO) def.baseCreateDataSourceVO();
ds.setId(Common.NEW_ID);
ds.setXid(DataSourceDao.instance.generateUniqueXid());
ds.setName("Test Virtual");
ds.setEnabled(true);
ds.setUpdatePeriods(5);
ds.setUpdatePeriodType(TimePeriods.SECONDS);
ds.setPolling(true);
ProcessResult response = new ProcessResult();
ds.validate(response);
if (!response.getHasMessages())
Common.runtimeManager.saveDataSource(ds);
else
throw new RuntimeException("Invalid data!");
DataPointDao dpDao = DataPointDao.instance;
// Create Test Points
for (int i = 0; i < 10; i++) {
VirtualPointLocatorVO pointLocator = ds.createPointLocator();
// Create a Random Points
pointLocator.setDataTypeId(DataTypes.NUMERIC);
pointLocator.setChangeTypeId(ChangeTypeVO.Types.RANDOM_ANALOG);
pointLocator.getRandomAnalogChange().setMin(0);
pointLocator.getRandomAnalogChange().setMax(100);
pointLocator.getRandomAnalogChange().setStartValue("1");
pointLocator.setSettable(true);
DataPointVO dp = new DataPointVO();
dp.setXid(dpDao.generateUniqueXid());
dp.setName("Virtual Random " + i);
dp.setDataSourceId(ds.getId());
dp.setDataSourceTypeName(ds.getDefinition().getDataSourceTypeName());
dp.setDeviceName(ds.getName());
dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
dp.defaultTextRenderer();
// Setup the Chart Renderer
ImageChartRenderer chartRenderer = new ImageChartRenderer(TimePeriods.DAYS, 5);
dp.setChartRenderer(chartRenderer);
dp.setPointLocator(pointLocator);
dp.setEnabled(true);
dp.setSettable(true);
dp.setDefaultCacheSize(0);
dp.validate(response);
if (!response.getHasMessages())
Common.runtimeManager.saveDataPoint(dp);
else
throw new RuntimeException("Invalid data!");
}
}
use of com.serotonin.m2m2.view.chart.ChartRenderer 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;
}
}
}
}
Aggregations