Search in sources :

Example 11 with PointFolder

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

the class DataPointDao method addFoldersToHeirarchy.

private void addFoldersToHeirarchy(PointHierarchy ph, int parentId, Map<Integer, List<PointFolder>> folders) {
    List<PointFolder> folderList = folders.remove(parentId);
    if (folderList == null)
        return;
    for (PointFolder f : folderList) {
        ph.addPointFolder(f, parentId);
        addFoldersToHeirarchy(ph, f.getId(), folders);
    }
}
Also used : PointFolder(com.serotonin.m2m2.vo.hierarchy.PointFolder)

Example 12 with PointFolder

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

the class DataPointDao method savePointHierarchy.

public synchronized void savePointHierarchy(final PointFolder root) {
    // Assign ids to the folders.
    final List<Object> params = new ArrayList<>();
    final AtomicInteger folderId = new AtomicInteger(getMaxFolderId(root));
    for (PointFolder sf : root.getSubfolders()) assignFolderIds(sf, 0, folderId, params);
    cachedPointHierarchy = new PointHierarchy(root);
    final ExtendedJdbcTemplate ejt2 = ejt;
    getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            // Dump the hierarchy table.
            ejt2.update("DELETE FROM dataPointHierarchy");
            // Reset the current point folders values in the points.
            ejt2.update("UPDATE dataPoints SET pointFolderId=0");
            // Save the point folders.
            if (folderId.get() > 0) {
                StringBuilder sql = new StringBuilder();
                sql.append("INSERT INTO dataPointHierarchy (id, parentId, name) VALUES ");
                for (int i = 0; i < params.size() / 3; i++) {
                    // three fields per folder
                    if (i > 0)
                        sql.append(",");
                    sql.append("(?,?,?)");
                }
                ejt2.update(sql.toString(), params.toArray(new Object[params.size()]));
            }
            // Save the folder ids for the points.
            savePointsInFolder(root);
            PointHierarchyEventDispatcher.firePointHierarchySaved(root);
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) ExtendedJdbcTemplate(com.serotonin.db.spring.ExtendedJdbcTemplate) PointFolder(com.serotonin.m2m2.vo.hierarchy.PointFolder) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

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