Search in sources :

Example 1 with PointHierarchy

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

the class PointHierarchyImporter method importImpl.

@Override
protected void importImpl() {
    try {
        PointHierarchy hierarchy = ctx.getDataPointDao().getPointHierarchy(false);
        @SuppressWarnings("unchecked") List<PointFolder> subfolders = (List<PointFolder>) ctx.getReader().read(new TypeDefinition(List.class, PointFolder.class), json);
        // Merge the new subfolders into the existing point heirarchy.
        hierarchy.mergeFolders(subfolders);
        ph = hierarchy;
    } catch (TranslatableJsonException e) {
        addFailureMessage("emport.pointHierarchy.prefix", e.getMsg());
    } catch (JsonException e) {
        addFailureMessage("emport.pointHierarchy.prefix", getJsonExceptionMessage(e));
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) PointFolder(com.serotonin.m2m2.vo.hierarchy.PointFolder) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) List(java.util.List) TypeDefinition(com.serotonin.json.util.TypeDefinition)

Example 2 with PointHierarchy

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

the class RealTimeDataPointValueCache method createPointHierarchy.

/**
 * Create a point hierarchy for this user out of all points they can read
 *
 * @param translations
 * @param user
 * @return
 */
private static PointHierarchy createPointHierarchy(Translations translations) {
    // Create a point hierarchy for the user.
    PointHierarchy ph = DataPointDao.instance.getPointHierarchy(true).copyFoldersOnly();
    List<DataPointVO> points = DataPointDao.instance.getDataPoints(DataPointExtendedNameComparator.instance, false);
    for (DataPointVO point : points) {
        ph.addDataPoint(point.getPointFolderId(), new DataPointSummary(point));
    }
    ph.parseEmptyFolders();
    return ph;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy)

Example 3 with PointHierarchy

use of com.serotonin.m2m2.vo.hierarchy.PointHierarchy in project ma-modules-public by infiniteautomation.

the class PointHierarchyRestController method getFolder.

/**
 * Get the folder via a name
 * @param folderName
 * @param request
 * @return
 */
@ApiOperation(value = "Get point hierarchy folder by name", notes = "Points returned based on user priviledges")
@RequestMapping(method = RequestMethod.GET, value = "/by-name/{folderName}", produces = { "application/json" })
public ResponseEntity<JsonStream<PointHierarchyModel>> getFolder(@PathVariable String folderName, @RequestParam(name = "subfolders", defaultValue = "true") boolean getSubFolders, @RequestParam(name = "points", defaultValue = "true") boolean getPoints, HttpServletRequest request) {
    RestProcessResult<JsonStream<PointHierarchyModel>> result = new RestProcessResult<JsonStream<PointHierarchyModel>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        PointHierarchy ph = DataPointDao.instance.getPointHierarchy(true);
        PointFolder folder = ph.getRoot();
        PointFolder desiredFolder = null;
        if (folder.getName().equals(folderName))
            desiredFolder = folder;
        else
            desiredFolder = recursiveFolderSearch(folder, folderName);
        if (desiredFolder == null) {
            result.addRestMessage(getDoesNotExistMessage());
            return result.createResponseEntity();
        } else {
            PointHiearchyFolderStream stream = new PointHiearchyFolderStream(desiredFolder, user, getSubFolders, getPoints);
            return result.createResponseEntity(stream);
        }
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) PointHierarchyModel(com.serotonin.m2m2.web.mvc.rest.v1.model.PointHierarchyModel) User(com.serotonin.m2m2.vo.User) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) PointFolder(com.serotonin.m2m2.vo.hierarchy.PointFolder) JsonStream(com.serotonin.m2m2.web.mvc.rest.v1.model.JsonStream) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with PointHierarchy

use of com.serotonin.m2m2.vo.hierarchy.PointHierarchy in project ma-modules-public by infiniteautomation.

the class PointHierarchyRestController method getFolder.

/**
 * Get the folder via a path
 * @param folderPath
 * @param request
 * @return
 */
@ApiOperation(value = "Get point hierarchy folder by path", notes = "Points returned based on user priviledges")
@RequestMapping(method = RequestMethod.GET, value = "/by-path/{folderPath}", produces = { "application/json" })
public ResponseEntity<JsonStream<PointHierarchyModel>> getFolder(@PathVariable List<String> folderPath, @RequestParam(name = "subfolders", defaultValue = "true") boolean getSubFolders, @RequestParam(name = "points", defaultValue = "true") boolean getPoints, HttpServletRequest request) {
    RestProcessResult<JsonStream<PointHierarchyModel>> result = new RestProcessResult<JsonStream<PointHierarchyModel>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        PointHierarchy ph = DataPointDao.instance.getPointHierarchy(true);
        PointHierarchyPathStream stream = new PointHierarchyPathStream(ph.getRoot(), user, getSubFolders, getPoints, folderPath);
        return result.createResponseEntity(stream);
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) PointHierarchyModel(com.serotonin.m2m2.web.mvc.rest.v1.model.PointHierarchyModel) User(com.serotonin.m2m2.vo.User) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) JsonStream(com.serotonin.m2m2.web.mvc.rest.v1.model.JsonStream) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with PointHierarchy

use of com.serotonin.m2m2.vo.hierarchy.PointHierarchy in project ma-modules-public by infiniteautomation.

the class PointHierarchyRestController method getFolder.

/**
 * Get the folder via an Id
 * @param folderName
 * @param request
 * @return
 */
@ApiOperation(value = "Get point hierarchy folder by ID", notes = "Points returned based on user priviledges")
@RequestMapping(method = RequestMethod.GET, value = "/by-id/{folderId}", produces = { "application/json" })
public ResponseEntity<JsonStream<PointHierarchyModel>> getFolder(@PathVariable Integer folderId, @RequestParam(name = "subfolders", defaultValue = "true") boolean getSubFolders, @RequestParam(name = "points", defaultValue = "true") boolean getPoints, HttpServletRequest request) {
    RestProcessResult<JsonStream<PointHierarchyModel>> result = new RestProcessResult<JsonStream<PointHierarchyModel>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        PointHierarchy ph = DataPointDao.instance.getPointHierarchy(true);
        PointFolder folder = ph.getRoot();
        PointFolder desiredFolder = null;
        if (folder.getId() == folderId)
            desiredFolder = folder;
        else
            desiredFolder = recursiveFolderSearch(folder, folderId);
        if (desiredFolder == null) {
            result.addRestMessage(getDoesNotExistMessage());
            return result.createResponseEntity();
        } else {
            PointHiearchyFolderStream stream = new PointHiearchyFolderStream(desiredFolder, user, getSubFolders, getPoints);
            return result.createResponseEntity(stream);
        }
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) PointHierarchyModel(com.serotonin.m2m2.web.mvc.rest.v1.model.PointHierarchyModel) User(com.serotonin.m2m2.vo.User) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) PointFolder(com.serotonin.m2m2.vo.hierarchy.PointFolder) JsonStream(com.serotonin.m2m2.web.mvc.rest.v1.model.JsonStream) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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