use of com.serotonin.m2m2.view.text.PlainRenderer 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.view.text.PlainRenderer 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;
}
use of com.serotonin.m2m2.view.text.PlainRenderer 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;
}
Aggregations