Search in sources :

Example 11 with DataPointPropertiesTemplateVO

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;
}
Also used : TableChartRenderer(com.serotonin.m2m2.view.chart.TableChartRenderer) BinaryTextRenderer(com.serotonin.m2m2.view.text.BinaryTextRenderer)

Example 12 with DataPointPropertiesTemplateVO

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;
}
Also used : AnalogRenderer(com.serotonin.m2m2.view.text.AnalogRenderer) ImageChartRenderer(com.serotonin.m2m2.view.chart.ImageChartRenderer)

Example 13 with DataPointPropertiesTemplateVO

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));
        }
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) LicenseViolatedException(com.serotonin.m2m2.LicenseViolatedException) DataPointPropertiesTemplateVO(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage)

Example 14 with DataPointPropertiesTemplateVO

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();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) DataPointModel(com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel) User(com.serotonin.m2m2.vo.User) PlainRenderer(com.serotonin.m2m2.view.text.PlainRenderer) DataPointPropertiesTemplateVO(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) RestMessage(com.serotonin.m2m2.web.mvc.rest.v1.message.RestMessage) List(java.util.List) ArrayList(java.util.ArrayList) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with DataPointPropertiesTemplateVO

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;
}
Also used : TableChartRenderer(com.serotonin.m2m2.view.chart.TableChartRenderer) PlainRenderer(com.serotonin.m2m2.view.text.PlainRenderer)

Aggregations

DataPointPropertiesTemplateVO (com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO)13 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)10 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)8 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)8 PlainRenderer (com.serotonin.m2m2.view.text.PlainRenderer)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)4 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 LicenseViolatedException (com.serotonin.m2m2.LicenseViolatedException)3 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)3 TableChartRenderer (com.serotonin.m2m2.view.chart.TableChartRenderer)3 User (com.serotonin.m2m2.vo.User)3 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)3 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)3 RestMessage (com.serotonin.m2m2.web.mvc.rest.v1.message.RestMessage)3 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)3 DataPointModel (com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel)3 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3