Search in sources :

Example 6 with PlainRenderer

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();
}
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 7 with PlainRenderer

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

Example 8 with PlainRenderer

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

Aggregations

PlainRenderer (com.serotonin.m2m2.view.text.PlainRenderer)7 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)4 DataPointPropertiesTemplateVO (com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 User (com.serotonin.m2m2.vo.User)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 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 LicenseViolatedException (com.serotonin.m2m2.LicenseViolatedException)2 TableChartRenderer (com.serotonin.m2m2.view.chart.TableChartRenderer)2 AnalogRenderer (com.serotonin.m2m2.view.text.AnalogRenderer)2 BinaryTextRenderer (com.serotonin.m2m2.view.text.BinaryTextRenderer)2 MultistateRenderer (com.serotonin.m2m2.view.text.MultistateRenderer)2 RangeRenderer (com.serotonin.m2m2.view.text.RangeRenderer)2 TimeRenderer (com.serotonin.m2m2.view.text.TimeRenderer)2 URI (java.net.URI)2