Search in sources :

Example 1 with DataPointSummary

use of com.serotonin.m2m2.vo.DataPointSummary in project ma-modules-public by infiniteautomation.

the class DataPointSummaryStreamCallback method writeJson.

/**
 * Do the work of writing the VO
 * @param vo
 * @throws IOException
 */
@Override
protected void writeJson(DataPointVO vo) throws IOException {
    try {
        if (Permissions.hasDataPointReadPermission(user, vo)) {
            DataPointSummary model = this.controller.createModel(vo);
            this.jgen.writeObject(model);
        }
    } catch (PermissionException e) {
    // Munched
    }
}
Also used : PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary)

Example 2 with DataPointSummary

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

the class PointFolder method jsonWrite.

// 
// 
// Serialization
// 
@Override
public void jsonWrite(ObjectWriter writer) throws IOException, JsonException {
    DataPointDao dataPointDao = DataPointDao.instance;
    List<String> pointList = new ArrayList<String>();
    for (DataPointSummary p : points) {
        String dpXid = dataPointDao.getXidById(p.getId());
        if (dpXid != null)
            pointList.add(dpXid);
    }
    writer.writeEntry("points", pointList);
}
Also used : DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) ArrayList(java.util.ArrayList)

Example 3 with DataPointSummary

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

the class PointFolder method mergePoints.

/**
 * Merge the Existing points with the new ones using the following rules:
 *
 * Points with same ID will be replaced
 * All new points are added
 * Any existing points not in the new list are kept
 *
 * @param points
 */
public void mergePoints(List<DataPointSummary> points) {
    int existingPointIndex;
    List<DataPointSummary> newPoints = new ArrayList<DataPointSummary>();
    for (DataPointSummary newPoint : points) {
        existingPointIndex = -1;
        // Does this point already exist?
        for (int i = 0; i < this.points.size(); i++) {
            if (this.points.get(i).getId() == newPoint.getId()) {
                existingPointIndex = i;
                break;
            }
        }
        if (existingPointIndex >= 0) {
            // Remove from existing points
            this.points.remove(existingPointIndex);
        }
        // Always add the new points
        newPoints.add(newPoint);
    }
    // Add any remaining existing points
    for (DataPointSummary existingPoint : this.points) {
        newPoints.add(existingPoint);
    }
    // Replace with the new list
    this.points = newPoints;
}
Also used : DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) ArrayList(java.util.ArrayList)

Example 4 with DataPointSummary

use of com.serotonin.m2m2.vo.DataPointSummary 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 5 with DataPointSummary

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

the class ControllerUtils method addPointListDataToModel.

public static List<DataPointSummary> addPointListDataToModel(User user, int pointId, Map<String, Object> model) {
    List<DataPointSummary> allPoints = DataPointDao.instance.getDataPointSummaries(DataPointExtendedNameComparator.instance);
    List<DataPointSummary> userPoints = new LinkedList<>();
    int pointIndex = -1;
    for (DataPointSummary dp : allPoints) {
        if (Permissions.hasDataPointReadPermission(user, dp)) {
            userPoints.add(dp);
            if (dp.getId() == pointId)
                pointIndex = userPoints.size() - 1;
        }
    }
    model.put("userPoints", userPoints);
    // Determine next and previous ids
    if (pointIndex > 0)
        model.put("prevId", userPoints.get(pointIndex - 1).getId());
    if (pointIndex < userPoints.size() - 1)
        model.put("nextId", userPoints.get(pointIndex + 1).getId());
    return userPoints;
}
Also used : DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) LinkedList(java.util.LinkedList)

Aggregations

DataPointSummary (com.serotonin.m2m2.vo.DataPointSummary)15 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)6 ArrayList (java.util.ArrayList)6 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)3 PointFolder (com.serotonin.m2m2.vo.hierarchy.PointFolder)3 PointHierarchy (com.serotonin.m2m2.vo.hierarchy.PointHierarchy)3 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)2 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)2 User (com.serotonin.m2m2.vo.User)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 LinkedHashMap (java.util.LinkedHashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 JsonException (com.serotonin.json.JsonException)1 JsonArray (com.serotonin.json.type.JsonArray)1 JsonValue (com.serotonin.json.type.JsonValue)1 LicenseViolatedException (com.serotonin.m2m2.LicenseViolatedException)1 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)1