use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.
the class DefaultDataPointPropertiesTemplateFactory method createDefaultBinaryTemplate.
protected DataPointPropertiesTemplateVO createDefaultBinaryTemplate() {
DataPointPropertiesTemplateVO defaultBinaryPointTemplate = new DataPointPropertiesTemplateVO();
defaultBinaryPointTemplate.setXid(BINARY_XID);
defaultBinaryPointTemplate.setName("Binary");
defaultBinaryPointTemplate.setDataTypeId(DataTypes.BINARY);
defaultBinaryPointTemplate.setDefaultTemplate(true);
defaultBinaryPointTemplate.setDefinition(new DataPointPropertiesTemplateDefinition());
defaultBinaryPointTemplate.setChartColour("");
defaultBinaryPointTemplate.setPlotType(PlotTypes.STEP);
defaultBinaryPointTemplate.setLoggingType(LoggingTypes.ON_CHANGE);
defaultBinaryPointTemplate.setDefaultCacheSize(1);
BinaryTextRenderer binaryRenderer = new BinaryTextRenderer();
binaryRenderer.setOneColour("black");
binaryRenderer.setOneLabel("one");
binaryRenderer.setZeroColour("blue");
binaryRenderer.setZeroLabel("zero");
defaultBinaryPointTemplate.setTextRenderer(binaryRenderer);
TableChartRenderer binaryChartRenderer = new TableChartRenderer();
binaryChartRenderer.setLimit(10);
defaultBinaryPointTemplate.setChartRenderer(binaryChartRenderer);
return defaultBinaryPointTemplate;
}
use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.
the class DefaultDataPointPropertiesTemplateFactory method createDefaultNumericTemplate.
protected DataPointPropertiesTemplateVO createDefaultNumericTemplate() {
DataPointPropertiesTemplateVO defaultNumericPointTemplate = new DataPointPropertiesTemplateVO();
defaultNumericPointTemplate.setXid(NUMERIC_XID);
defaultNumericPointTemplate.setName("Numeric");
defaultNumericPointTemplate.setDefaultTemplate(true);
defaultNumericPointTemplate.setDataTypeId(DataTypes.NUMERIC);
defaultNumericPointTemplate.setDefinition(new DataPointPropertiesTemplateDefinition());
defaultNumericPointTemplate.setChartColour("");
defaultNumericPointTemplate.setPlotType(PlotTypes.SPLINE);
defaultNumericPointTemplate.setLoggingType(LoggingTypes.INTERVAL);
defaultNumericPointTemplate.setIntervalLoggingPeriod(1);
defaultNumericPointTemplate.setIntervalLoggingPeriodType(TimePeriods.MINUTES);
defaultNumericPointTemplate.setIntervalLoggingType(IntervalLoggingTypes.AVERAGE);
defaultNumericPointTemplate.setDefaultCacheSize(1);
AnalogRenderer numericTextRenderer = new AnalogRenderer();
numericTextRenderer.setFormat("0.00");
defaultNumericPointTemplate.setTextRenderer(numericTextRenderer);
ImageChartRenderer numericChartRenderer = new ImageChartRenderer();
numericChartRenderer.setTimePeriod(TimePeriods.DAYS);
numericChartRenderer.setNumberOfPeriods(1);
defaultNumericPointTemplate.setChartRenderer(numericChartRenderer);
return defaultNumericPointTemplate;
}
use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.
the class DataPointImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
DataPointVO vo = null;
DataSourceVO<?> dsvo = null;
if (StringUtils.isBlank(xid))
xid = ctx.getDataPointDao().generateUniqueXid();
else
vo = ctx.getDataPointDao().getDataPoint(xid);
if (vo == null) {
// Locate the data source for the point.
String dsxid = json.getString("dataSourceXid");
dsvo = ctx.getDataSourceDao().getDataSource(dsxid);
if (dsvo == null)
addFailureMessage("emport.dataPoint.badReference", xid);
else {
vo = new DataPointVO();
vo.setXid(xid);
vo.setDataSourceId(dsvo.getId());
vo.setDataSourceXid(dsxid);
vo.setPointLocator(dsvo.createPointLocator());
vo.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
// Not needed as it will be set via the template or JSON or it exists in the DB already: vo.setTextRenderer(new PlainRenderer());
}
}
if (vo != null) {
try {
DataPointPropertiesTemplateVO template = null;
if (json.containsKey("templateXid")) {
String templateXid = json.getString("templateXid");
if (!StringUtils.isEmpty(templateXid))
template = (DataPointPropertiesTemplateVO) TemplateDao.instance.getByXid(templateXid);
}
// Read into the VO to get all properties
ctx.getReader().readInto(vo, json);
// Override the settings if we need to
if (template != null) {
template.updateDataPointVO(vo);
}
// If the name is not provided, default to the XID
if (StringUtils.isBlank(vo.getName()))
vo.setName(xid);
// If the chart colour is null provide default of '' to handle legacy code that sets colour to null
if (vo.getChartColour() == null)
vo.setChartColour("");
// Now validate it. Use a new response object so we can distinguish errors in this vo from
// other errors.
ProcessResult voResponse = new ProcessResult();
vo.validate(voResponse);
if (voResponse.getHasMessages())
setValidationMessages(voResponse, "emport.dataPoint.prefix", xid);
else {
// We will always override the DS Info with the one from the XID Lookup
dsvo = ctx.getDataSourceDao().getDataSource(vo.getDataSourceXid());
if (dsvo == null)
addFailureMessage("emport.dataPoint.badReference", xid);
else {
// Compare this point to the existing point in DB to ensure
// that we aren't moving a point to a different type of Data Source
DataPointVO oldPoint = ctx.getDataPointDao().getDataPoint(vo.getId(), false);
// Does the old point have a different data source?
if (oldPoint != null && (oldPoint.getDataSourceId() != dsvo.getId())) {
vo.setDataSourceId(dsvo.getId());
vo.setDataSourceName(dsvo.getName());
}
}
boolean isNew = vo.isNew();
try {
if (Common.runtimeManager.getState() == RuntimeManager.RUNNING) {
Common.runtimeManager.saveDataPoint(vo);
if (hierarchyList != null && json.containsKey(PATH)) {
String path = json.getString(PATH);
if (StringUtils.isNotEmpty(path))
hierarchyList.add(new DataPointSummaryPathPair(new DataPointSummary(vo), path));
}
addSuccessMessage(isNew, "emport.dataPoint.prefix", xid);
} else {
addFailureMessage(new ProcessMessage("Runtime Manager not running point with xid: " + xid + " not saved."));
}
} catch (LicenseViolatedException e) {
addFailureMessage(new ProcessMessage(e.getErrorMessage()));
}
}
} catch (TranslatableJsonException e) {
addFailureMessage("emport.dataPoint.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.dataPoint.prefix", xid, getJsonExceptionMessage(e));
}
}
}
use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-modules-public by infiniteautomation.
the class DataPointRestController method saveDataPoints.
@ApiOperation(value = "Insert/Update multiple data points", notes = "CSV content must be limited to 1 type of data source.")
@RequestMapping(method = RequestMethod.PUT, consumes = { "application/json;charset=UTF-8", "text/csv;charset=UTF-8" }, produces = { "application/json", "application/sero-json" })
public ResponseEntity<List<DataPointModel>> saveDataPoints(@ApiParam(value = "List of updated data point models", required = true) @RequestBody(required = true) List<DataPointModel> models, UriComponentsBuilder builder, HttpServletRequest request) {
RestProcessResult<List<DataPointModel>> result = new RestProcessResult<List<DataPointModel>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
boolean contentTypeCsv = false;
if (request.getContentType().toLowerCase().contains("text/csv"))
contentTypeCsv = true;
DataPointModel first;
DataSourceVO<?> ds = null;
if (models.size() > 0) {
first = models.get(0);
ds = DataSourceDao.instance.getByXid(first.getDataSourceXid());
}
for (DataPointModel model : models) {
DataPointVO vo = model.getData();
DataSourceVO<?> myDataSource = DataSourceDao.instance.getByXid(vo.getDataSourceXid());
if (myDataSource == null) {
model.addValidationMessage("validate.invalidReference", RestMessageLevel.ERROR, "dataSourceXid");
continue;
}
// If we don't have a reference data source we need to set one
if (ds == null) {
ds = myDataSource;
}
// First check to see that the data source types match
if (!ds.getDefinition().getDataSourceTypeName().equals(myDataSource.getDefinition().getDataSourceTypeName())) {
model.addValidationMessage("validate.incompatibleDataSourceType", RestMessageLevel.ERROR, "dataSourceXid");
continue;
}
// Set the ID for the data source
vo.setDataSourceId(myDataSource.getId());
// Are we a new one?
DataPointVO existingDp = DataPointDao.instance.getByXid(vo.getXid());
boolean updated = true;
if (existingDp == null) {
updated = false;
} else {
// Must Do this as ID is NOT in the model
vo.setId(existingDp.getId());
// Set all properties that are not in the template or the spreadsheet
vo.setPointFolderId(existingDp.getPointFolderId());
// Use ID to get detectors
DataPointDao.instance.setEventDetectors(vo);
}
// Check permissions
try {
if (!Permissions.hasDataPointReadPermission(user, vo)) {
// TODO add what point
result.addRestMessage(getUnauthorizedMessage());
continue;
}
} catch (PermissionException e) {
// TODO add what point
result.addRestMessage(getUnauthorizedMessage());
continue;
}
if (vo.getTextRenderer() == null) {
vo.setTextRenderer(new PlainRenderer());
}
if (vo.getChartColour() == null) {
vo.setChartColour("");
}
// Check the Template and see if we need to use it
if (model.getTemplateXid() != null) {
DataPointPropertiesTemplateVO template = (DataPointPropertiesTemplateVO) TemplateDao.instance.getByXid(model.getTemplateXid());
if (template != null) {
template.updateDataPointVO(vo);
template.updateDataPointVO(model.getData());
} else {
model.addValidationMessage("validate.invalidReference", RestMessageLevel.ERROR, "templateXid");
result.addRestMessage(new RestMessage(HttpStatus.NOT_ACCEPTABLE, new TranslatableMessage("emport.dataPoint.badReference", model.getTemplateXid())));
continue;
}
} else {
// We need to update the various pieces
if (updated) {
DataPointPropertiesTemplateVO tempTemplate = new DataPointPropertiesTemplateVO();
tempTemplate.updateTemplate(existingDp);
tempTemplate.updateDataPointVO(vo);
// Kludge to allow this template to not be our real template
vo.setTemplateId(null);
} else {
if (contentTypeCsv) {
model.addValidationMessage("validate.required", RestMessageLevel.ERROR, "templateXid");
result.addRestMessage(this.getValidationFailedError());
continue;
}
}
}
if (StringUtils.isEmpty(vo.getXid()))
vo.setXid(DataPointDao.instance.generateUniqueXid());
// allow empty string, but if its null use the data source name
if (vo.getDeviceName() == null) {
vo.setDeviceName(myDataSource.getName());
}
if (model.validate()) {
if (updated)
model.addValidationMessage("common.updated", RestMessageLevel.INFORMATION, "all");
else
model.addValidationMessage("common.saved", RestMessageLevel.INFORMATION, "all");
// Save it
Common.runtimeManager.saveDataPoint(vo);
}
}
return result.createResponseEntity(models);
}
// Not logged in
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.
the class DefaultDataPointPropertiesTemplateFactory method createDefaultAlphanumericTemplate.
protected DataPointPropertiesTemplateVO createDefaultAlphanumericTemplate() {
DataPointPropertiesTemplateVO defaultAlphanumericPointTemplate = new DataPointPropertiesTemplateVO();
defaultAlphanumericPointTemplate.setXid(ALPHANUMERIC_XID);
defaultAlphanumericPointTemplate.setName("Alphanumeric");
defaultAlphanumericPointTemplate.setDataTypeId(DataTypes.ALPHANUMERIC);
defaultAlphanumericPointTemplate.setDefaultTemplate(true);
defaultAlphanumericPointTemplate.setDefinition(new DataPointPropertiesTemplateDefinition());
defaultAlphanumericPointTemplate.setChartColour("");
defaultAlphanumericPointTemplate.setPlotType(PlotTypes.STEP);
defaultAlphanumericPointTemplate.setLoggingType(LoggingTypes.ON_CHANGE);
defaultAlphanumericPointTemplate.setDefaultCacheSize(1);
defaultAlphanumericPointTemplate.setTextRenderer(new PlainRenderer());
TableChartRenderer alphaChartRenderer = new TableChartRenderer();
alphaChartRenderer.setLimit(10);
defaultAlphanumericPointTemplate.setChartRenderer(alphaChartRenderer);
return defaultAlphanumericPointTemplate;
}
Aggregations