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;
}
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;
}
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", "");
}
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());
}
}
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();
}
Aggregations