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