Search in sources :

Example 11 with DataPointSummary

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

the class PointFolder method mergeSubfolders.

/**
 * Merge the subfolders of this point folder with new folders
 * use the following rules:
 *
 * If a local folder exists with the same id as the new subfolder then merge it
 * If no local folder exists for the new subfolder, then add it
 * If a local folders exists that is not in the new subfolders then keep it
 *
 * @param subfolders
 */
public void mergeSubfolders(PointFolder root, List<PointFolder> subfolders) {
    List<PointFolder> newSubfolders = new ArrayList<PointFolder>();
    int pointFolderIndex;
    // Recursively walk through each sub-folder and merge the points in each.
    for (PointFolder newFolder : subfolders) {
        // Remove the new points from anywhere in the hierarchy
        for (DataPointSummary dps : newFolder.getPoints()) {
            root.removePointRecursively(dps.getId());
        }
        pointFolderIndex = -1;
        for (int i = 0; i < this.subfolders.size(); i++) {
            if (this.subfolders.get(i).getName().equals(newFolder.getName())) {
                pointFolderIndex = i;
                break;
            }
        }
        if (pointFolderIndex >= 0) {
            // If a local folder exists for the new sub-folder then merge it
            PointFolder existing = this.subfolders.get(pointFolderIndex);
            // Merge points by moving the existing points into this folder.
            existing.mergePoints(newFolder.getPoints());
            existing.mergeSubfolders(root, newFolder.getSubfolders());
            newSubfolders.add(existing);
            // Remove the existing sub-folder so that when we are done we have the remaining folders to add
            this.subfolders.remove(pointFolderIndex);
        } else {
            // If no local folder exists for the new sub-folder, then add it
            // Be sure to remove any subfolder points from the heirarchy
            root.removePointsRecursively(newFolder.getSubfolders());
            newSubfolders.add(newFolder);
        }
    }
    // These points should all be unique because they were not removed by any new incoming folder
    for (PointFolder remainingFolder : this.subfolders) {
        newSubfolders.add(remainingFolder);
    }
    this.subfolders = newSubfolders;
}
Also used : DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) ArrayList(java.util.ArrayList)

Example 12 with DataPointSummary

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

the class PointFolder method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    JsonArray jsonPoints = jsonObject.getJsonArray("points");
    if (jsonPoints != null) {
        points.clear();
        DataPointDao dataPointDao = DataPointDao.instance;
        for (JsonValue jv : jsonPoints) {
            String xid = jv.toString();
            DataPointVO dp = dataPointDao.getDataPoint(xid);
            if (dp == null)
                throw new TranslatableJsonException("emport.error.missingPoint", xid);
            points.add(new DataPointSummary(dp));
        }
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) JsonValue(com.serotonin.json.type.JsonValue) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 13 with DataPointSummary

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

the class TemplateDwr method findPointsWithTemplate.

@DwrPermission(user = true)
public ProcessResult findPointsWithTemplate(DataPointPropertiesTemplateVO vo) {
    ProcessResult response = new ProcessResult();
    List<DataPointVO> dataPoints = DataPointDao.instance.getByTemplate(vo.getId(), false);
    List<DataPointSummary> summaries = new ArrayList<DataPointSummary>(dataPoints.size());
    for (DataPointVO dp : dataPoints) summaries.add(new DataPointSummary(dp));
    response.addData(DataPointDao.instance.tableName, summaries);
    return response;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 14 with DataPointSummary

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

the class DataPointDao method savePointsInFolder.

void savePointsInFolder(PointFolder folder) {
    // Save the points in the subfolders
    for (PointFolder sf : folder.getSubfolders()) savePointsInFolder(sf);
    // Update the folder references in the points.
    if (!folder.getPoints().isEmpty()) {
        List<Integer> ids = new ArrayList<>(folder.getPoints().size());
        for (DataPointSummary p : folder.getPoints()) ids.add(p.getId());
        ejt.update("UPDATE dataPoints SET pointFolderId=? WHERE id in (" + createDelimitedList(ids, ",", null) + ")", folder.getId());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) ArrayList(java.util.ArrayList) PointFolder(com.serotonin.m2m2.vo.hierarchy.PointFolder)

Example 15 with DataPointSummary

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

the class DataPointDao method getPointHierarchy.

/**
 * Get the point hierarchy from its cached copy.  The read only cached copy should
 * never be modified, if you intend to modify it ensure you pass readOnly=false
 *
 * @param readOnly - do not modify a read only point hierarchy
 * @return
 */
public PointHierarchy getPointHierarchy(boolean readOnly) {
    if (cachedPointHierarchy == null) {
        final Map<Integer, List<PointFolder>> folders = new HashMap<>();
        // Get the folder list.
        ejt.query("select id, parentId, name from dataPointHierarchy order by name", new RowCallbackHandler() {

            @Override
            public void processRow(ResultSet rs) throws SQLException {
                PointFolder f = new PointFolder(rs.getInt(1), rs.getString(3));
                int parentId = rs.getInt(2);
                List<PointFolder> folderList = folders.get(parentId);
                if (folderList == null) {
                    folderList = new LinkedList<>();
                    folders.put(parentId, folderList);
                }
                folderList.add(f);
            }
        });
        // Create the folder hierarchy.
        PointHierarchy ph = new PointHierarchy();
        addFoldersToHeirarchy(ph, 0, folders);
        // Add data points.
        List<DataPointSummary> points = getDataPointSummaries(DataPointExtendedNameComparator.instance);
        for (DataPointSummary dp : points) ph.addDataPoint(dp.getPointFolderId(), dp);
        cachedPointHierarchy = ph;
    }
    if (readOnly)
        return cachedPointHierarchy;
    else
        return cachedPointHierarchy.clone();
}
Also used : DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) PointFolder(com.serotonin.m2m2.vo.hierarchy.PointFolder) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) LinkedList(java.util.LinkedList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSet(java.sql.ResultSet) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

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