use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.
the class DefaultDataPointPropertiesTemplateFactory method createDefaultMultistateTemplate.
protected DataPointPropertiesTemplateVO createDefaultMultistateTemplate() {
DataPointPropertiesTemplateVO defaultMultistatePointTemplate = new DataPointPropertiesTemplateVO();
defaultMultistatePointTemplate.setXid(MULTISTATE_XID);
defaultMultistatePointTemplate.setName("Multistate");
defaultMultistatePointTemplate.setDataTypeId(DataTypes.MULTISTATE);
defaultMultistatePointTemplate.setDefaultTemplate(true);
defaultMultistatePointTemplate.setDefinition(new DataPointPropertiesTemplateDefinition());
defaultMultistatePointTemplate.setChartColour("");
defaultMultistatePointTemplate.setPlotType(PlotTypes.STEP);
defaultMultistatePointTemplate.setLoggingType(LoggingTypes.ON_CHANGE);
defaultMultistatePointTemplate.setDefaultCacheSize(1);
defaultMultistatePointTemplate.setTextRenderer(new PlainRenderer());
TableChartRenderer multistateChartRenderer = new TableChartRenderer();
multistateChartRenderer.setLimit(10);
defaultMultistatePointTemplate.setChartRenderer(multistateChartRenderer);
return defaultMultistatePointTemplate;
}
use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO 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.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.
the class DataPointVO method jsonWrite.
@Override
public void jsonWrite(ObjectWriter writer) throws IOException, JsonException {
super.jsonWrite(writer);
writer.writeEntry("loggingType", LOGGING_TYPE_CODES.getCode(loggingType));
writer.writeEntry("intervalLoggingPeriodType", Common.TIME_PERIOD_CODES.getCode(intervalLoggingPeriodType));
writer.writeEntry("intervalLoggingType", INTERVAL_LOGGING_TYPE_CODES.getCode(intervalLoggingType));
writer.writeEntry("purgeType", Common.TIME_PERIOD_CODES.getCode(purgeType));
writer.writeEntry("pointLocator", pointLocator);
writer.writeEntry("eventDetectors", eventDetectors);
writer.writeEntry("plotType", PLOT_TYPE_CODES.getCode(plotType));
writer.writeEntry("rollup", Common.ROLLUP_CODES.getCode(rollup));
writer.writeEntry("unit", UnitUtil.formatUcum(unit));
if (SystemSettingsDao.getBooleanValue(SystemSettingsDao.EXPORT_HIERARCHY_PATH))
writer.writeEntry("path", PointHierarchy.getFlatPath(id, DataPointDao.instance.getPointHierarchy(true).getRoot()));
if (useIntegralUnit)
writer.writeEntry("integralUnit", UnitUtil.formatUcum(integralUnit));
if (useRenderedUnit)
writer.writeEntry("renderedUnit", UnitUtil.formatUcum(renderedUnit));
if (templateId != null) {
DataPointPropertiesTemplateVO template = (DataPointPropertiesTemplateVO) TemplateDao.instance.get(templateId);
if (template != null)
writer.writeEntry("templateXid", template.getXid());
}
writer.writeEntry("simplifyType", SIMPLIFY_TYPE_CODES.getCode(simplifyType));
if (simplifyType == SimplifyTypes.TARGET)
writer.writeEntry("simplifyTarget", simplifyTarget);
else if (simplifyType == SimplifyTypes.TOLERANCE)
writer.writeEntry("simplifyTolerance", simplifyTolerance);
}
use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.
the class TemplateDao method getDataPointTemplatesByDataTypeId.
/* Data Point Properties Template Queries */
/**
* Get all templates for a given data type
*
* @param dataTypeId
* @return
*/
public List<DataPointPropertiesTemplateVO> getDataPointTemplatesByDataTypeId(int dataTypeId) {
List<DataPointPropertiesTemplateVO> allDataPointTemplates = this.getAllDataPointTemplates();
List<DataPointPropertiesTemplateVO> templates = new ArrayList<DataPointPropertiesTemplateVO>();
for (DataPointPropertiesTemplateVO dataPointTemplate : allDataPointTemplates) {
if (dataPointTemplate.getDataTypeId() == dataTypeId)
templates.add(dataPointTemplate);
}
return templates;
}
use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.
the class TemplateDwr method findPointsWithTemplate.
@DwrPermission(user = true)
public ProcessResult findPointsWithTemplate(DataPointPropertiesTemplateVO vo) {
ProcessResult response = new ProcessResult();
List<DataPointVO> dataPoints = DataPointDao.instance.getByTemplate(vo.getId(), false);
List<DataPointSummary> summaries = new ArrayList<DataPointSummary>(dataPoints.size());
for (DataPointVO dp : dataPoints) summaries.add(new DataPointSummary(dp));
response.addData(DataPointDao.instance.tableName, summaries);
return response;
}
Aggregations