Search in sources :

Example 21 with DataPointPropertiesTemplateVO

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

the class TemplateDwr method updateDataPointsUsingTemplate.

/**
 * Update all data points tied to this template.
 *
 * PRE-The Template must have been validated
 *
 * @param vo
 * @param response
 */
protected void updateDataPointsUsingTemplate(DataPointPropertiesTemplateVO vo, ProcessResult response) {
    // Update all data points and let the user know which ones were updated
    List<DataPointVO> templatedPoints = DataPointDao.instance.getByTemplate(vo.getId());
    List<String> xidsUpdated = new ArrayList<String>();
    // Map of XID to why
    Map<String, String> failedXidMap = new HashMap<String, String>();
    for (DataPointVO templatedPoint : templatedPoints) {
        try {
            vo.updateDataPointVO(templatedPoint);
            Common.runtimeManager.saveDataPoint(templatedPoint);
            xidsUpdated.add(templatedPoint.getXid());
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            failedXidMap.put(templatedPoint.getXid(), e.getMessage());
            response.addMessage(new TranslatableMessage("common.default", e.getMessage()));
        }
    }
    response.addData("updatedXids", xidsUpdated);
    response.addData("failedXids", failedXidMap);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DuplicateKeyException(org.springframework.dao.DuplicateKeyException)

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