Search in sources :

Example 6 with DataPointPropertiesTemplateVO

use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.

the class DataSourceEditDwr method validatePoint.

protected ProcessResult validatePoint(int id, String xid, String name, PointLocatorVO<?> locator, DataPointDefaulter defaulter, boolean includePointList) {
    ProcessResult response = new ProcessResult();
    // This saving of the point into the User is a bad idea, need to rework to
    // pass the point back and forth to page.
    DataPointVO dp = getPoint(id, defaulter);
    dp.setXid(xid);
    dp.setName(name);
    dp.setPointLocator(locator);
    // Confirm that we are assinging a point to the correct data source
    DataSourceVO<?> ds = DataSourceDao.instance.get(dp.getDataSourceId());
    PointLocatorVO<?> plvo = ds.createPointLocator();
    if (plvo.getClass() != locator.getClass()) {
        response.addGenericMessage("validate.invalidType");
        return response;
    }
    // If we are a new point then only validate the basics
    if (id == Common.NEW_ID) {
        if (StringUtils.isBlank(xid))
            response.addContextualMessage("xid", "validate.required");
        else if (StringValidation.isLengthGreaterThan(xid, 50))
            response.addMessage("xid", new TranslatableMessage("validate.notLongerThan", 50));
        else if (!DataPointDao.instance.isXidUnique(xid, id))
            response.addContextualMessage("xid", "validate.xidUsed");
        if (StringUtils.isBlank(name))
            response.addContextualMessage("name", "validate.required");
        // Load in the default Template
        DataPointPropertiesTemplateVO template = TemplateDao.instance.getDefaultDataPointTemplate(locator.getDataTypeId());
        if (template != null) {
            template.updateDataPointVO(dp);
        }
        // Should really be done elsewhere
        dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>());
    } else if (id == DataPointDwr.COPY_ID) {
        dp.setId(Common.NEW_ID);
        if (StringUtils.isBlank(xid))
            response.addContextualMessage("xid", "validate.required");
        else if (StringValidation.isLengthGreaterThan(xid, 50))
            response.addMessage("xid", new TranslatableMessage("validate.notLongerThan", 50));
        else if (!DataPointDao.instance.isXidUnique(xid, id))
            response.addContextualMessage("xid", "validate.xidUsed");
        if (StringUtils.isBlank(name))
            response.addContextualMessage("name", "validate.required");
    } else {
        // New validation on save for all settings on existing points
        dp.validate(response);
        if (dp.getChartRenderer() != null)
            dp.getChartRenderer().validate(response);
        if (dp.getTextRenderer() != null)
            dp.getTextRenderer().validate(response);
    }
    // Validate Locator
    locator.validate(response, dp);
    if (!response.getHasMessages()) {
        try {
            Common.runtimeManager.saveDataPoint(dp);
        } catch (DuplicateKeyException e) {
            response.addGenericMessage("pointEdit.detectors.duplicateXid");
            return response;
        } catch (LicenseViolatedException e) {
            response.addMessage(e.getErrorMessage());
            return response;
        }
        if (defaulter != null)
            defaulter.postSave(dp);
        response.addData("id", dp.getId());
        response.addData("vo", dp);
        if (includePointList)
            response.addData("points", getPoints());
        // Set the User Point
        Common.getUser().setEditPoint(dp);
    }
    return response;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) LicenseViolatedException(com.serotonin.m2m2.LicenseViolatedException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DataPointPropertiesTemplateVO(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DuplicateKeyException(org.springframework.dao.DuplicateKeyException)

Example 7 with DataPointPropertiesTemplateVO

use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.

the class TemplateDwr method getNewDataPointTemplate.

/**
 * Get a new Data Point Template
 * @return
 */
@DwrPermission(user = true)
public ProcessResult getNewDataPointTemplate() {
    ProcessResult response = new ProcessResult();
    DataPointPropertiesTemplateVO vo = new DataPointPropertiesTemplateVO();
    vo.setDefinition(new DataPointPropertiesTemplateDefinition());
    response.addData("vo", vo);
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DataPointPropertiesTemplateVO(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO) DataPointPropertiesTemplateDefinition(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateDefinition) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 8 with DataPointPropertiesTemplateVO

use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.

the class TemplateDwr method saveDataPointTemplate.

/**
 * Save a Data Point template
 * @return
 */
@DwrPermission(user = true)
public ProcessResult saveDataPointTemplate(DataPointPropertiesTemplateVO vo) {
    ProcessResult response = new ProcessResult();
    if (vo.getXid() == null) {
        vo.setXid(dao.generateUniqueXid());
    }
    // we need a name for validation so set XID and name to the same thing.
    if (StringUtils.isEmpty(vo.getName())) {
        vo.setName(vo.getXid());
    }
    vo.validate(response);
    if (!response.getHasMessages()) {
        try {
            dao.save(vo);
            updateDataPointsUsingTemplate(vo, response);
        } catch (Exception e) {
            // Handle the exceptions.
            LOG.error(e);
            String context = vo.getName();
            if (context == null) {
                context = vo.getXid();
            }
            if (context == null) {
                context = vo.getXid();
            }
            if (context == null) {
                context = Integer.toString(vo.getId());
            }
            if (e instanceof DuplicateKeyException)
                response.addContextualMessage(context, "table.edit.alreadyExists");
            else
                response.addContextualMessage(context, "table.edit.unableToSave", e.getMessage());
        }
    }
    response.addData("vo", vo);
    // Add in case it fails
    response.addData("id", vo.getId());
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 9 with DataPointPropertiesTemplateVO

use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.

the class TemplateDwr method getDataPointTemplates.

/**
 * Save a template
 * @return
 */
@DwrPermission(user = true)
public ProcessResult getDataPointTemplates(int dataTypeId) {
    ProcessResult result = new ProcessResult();
    List<DataPointPropertiesTemplateVO> templates = dao.getDataPointTemplatesByDataTypeId(dataTypeId);
    result.addData(TemplateDao.instance.tableName, templates);
    return result;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DataPointPropertiesTemplateVO(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 10 with DataPointPropertiesTemplateVO

use of com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO in project ma-core-public by infiniteautomation.

the class DefaultDataPointPropertiesTemplateFactory method saveTemplate.

protected void saveTemplate(DataPointPropertiesTemplateVO template) {
    ProcessResult response = new ProcessResult();
    template.validate(response);
    if (!response.getHasMessages()) {
        TemplateDao.instance.save(template);
    } else {
        String output = new String();
        List<ProcessMessage> messages = response.getMessages();
        for (ProcessMessage message : messages) {
            output += message.toString(Common.getTranslations());
            output += "\n";
        }
        throw new ShouldNeverHappenException(output);
    }
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage)

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