Search in sources :

Example 11 with PointHierarchy

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

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

PointHierarchy (com.serotonin.m2m2.vo.hierarchy.PointHierarchy)11 PointFolder (com.serotonin.m2m2.vo.hierarchy.PointFolder)7 User (com.serotonin.m2m2.vo.User)6 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 JsonStream (com.serotonin.m2m2.web.mvc.rest.v1.model.JsonStream)4 PointHierarchyModel (com.serotonin.m2m2.web.mvc.rest.v1.model.PointHierarchyModel)4 DataPointSummary (com.serotonin.m2m2.vo.DataPointSummary)3 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)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 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)1