Search in sources :

Example 6 with PointFolder

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

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

the class RealTimeDataPointValueCache method getUserView.

/**
 * Get all the points a user can see based on permissions
 * @param user
 * @return
 */
public List<RealTimeDataPointValue> getUserView(User user) {
    if (cleared) {
        // Reload
        PointHierarchy ph = createPointHierarchy(Common.getTranslations());
        PointFolder root = ph.getRoot();
        // Fill the cache now
        fillCache(root, realTimeData);
        cleared = false;
    }
    List<RealTimeDataPointValue> results = new ArrayList<RealTimeDataPointValue>();
    final boolean admin = Permissions.hasAdmin(user);
    final String permissions = user.getPermissions();
    for (RealTimeDataPointValue rtdpv : this.realTimeData) {
        // Do we have set or read permissions for this point?
        if (admin || Permissions.hasPermission(rtdpv.getSetPermission(), permissions) || Permissions.hasPermission(rtdpv.getReadPermission(), permissions))
            results.add(rtdpv);
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) PointFolder(com.serotonin.m2m2.vo.hierarchy.PointFolder)

Example 8 with PointFolder

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

the class ImportTask method processDataPointPaths.

public void processDataPointPaths(PointHierarchyImporter hierarchyImporter, List<DataPointSummaryPathPair> dpPathPairs) {
    PointFolder root;
    if (hierarchyImporter != null && hierarchyImporter.getHierarchy() != null)
        root = hierarchyImporter.getHierarchy().getRoot();
    else if (dpPathPairs.size() > 0)
        root = DataPointDao.instance.getPointHierarchy(false).getRoot();
    else
        return;
    String pathSeparator = SystemSettingsDao.getValue(SystemSettingsDao.HIERARCHY_PATH_SEPARATOR);
    for (DataPointSummaryPathPair dpp : dpPathPairs) {
        root.removePointRecursively(dpp.getDataPointSummary().getId());
        PointFolder starting = root;
        PointFolder previous = root;
        String[] pathParts = dpp.getPath().split(pathSeparator);
        if (pathParts.length == 1 && StringUtils.isBlank(pathParts[0])) {
            // Check if it's in the root
            root.getPoints().add(dpp.getDataPointSummary());
            continue;
        }
        for (String s : pathParts) {
            if (StringUtils.isBlank(s))
                continue;
            previous = starting;
            starting = starting.getSubfolder(s);
            if (starting == null) {
                PointFolder newFolder = new PointFolder();
                newFolder.setName(s);
                previous.addSubfolder(newFolder);
                starting = newFolder;
            }
        }
        starting.addDataPoint(dpp.getDataPointSummary());
    }
    DataPointDao.instance.savePointHierarchy(root);
    importContext.addSuccessMessage(false, "emport.pointHierarchy.prefix", "");
}
Also used : PointFolder(com.serotonin.m2m2.vo.hierarchy.PointFolder) DataPointSummaryPathPair(com.serotonin.m2m2.web.dwr.emport.importers.DataPointSummaryPathPair)

Example 9 with PointFolder

use of com.serotonin.m2m2.vo.hierarchy.PointFolder 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 10 with PointFolder

use of com.serotonin.m2m2.vo.hierarchy.PointFolder 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

PointFolder (com.serotonin.m2m2.vo.hierarchy.PointFolder)10 PointHierarchy (com.serotonin.m2m2.vo.hierarchy.PointHierarchy)7 DataPointSummary (com.serotonin.m2m2.vo.DataPointSummary)5 ArrayList (java.util.ArrayList)5 User (com.serotonin.m2m2.vo.User)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)2 JsonStream (com.serotonin.m2m2.web.mvc.rest.v1.model.JsonStream)2 PointHierarchyModel (com.serotonin.m2m2.web.mvc.rest.v1.model.PointHierarchyModel)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ExtendedJdbcTemplate (com.serotonin.db.spring.ExtendedJdbcTemplate)1 JsonException (com.serotonin.json.JsonException)1 TypeDefinition (com.serotonin.json.util.TypeDefinition)1 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 IDataPoint (com.serotonin.m2m2.vo.IDataPoint)1