Search in sources :

Example 1 with PointHierarchyModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.PointHierarchyModel 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 2 with PointHierarchyModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.PointHierarchyModel 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 3 with PointHierarchyModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.PointHierarchyModel 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)

Example 4 with PointHierarchyModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.PointHierarchyModel in project ma-modules-public by infiniteautomation.

the class PointHierarchyRestController method getPointHierarchy.

// private static Log LOG = LogFactory.getLog(PointHierarchyRestController.class);
/**
 * Get the entire Point Hierarchy
 * @param request
 * @return
 */
@ApiOperation(value = "Get full point hierarchy", notes = "Hierarchy based on user priviledges")
@RequestMapping(method = RequestMethod.GET, value = "/full", produces = { "application/json" })
public ResponseEntity<JsonStream<PointHierarchyModel>> getPointHierarchy(@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);
        PointHiearchyFolderStream stream = new PointHiearchyFolderStream(ph.getRoot(), 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) JsonStream(com.serotonin.m2m2.web.mvc.rest.v1.model.JsonStream) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

User (com.serotonin.m2m2.vo.User)4 PointHierarchy (com.serotonin.m2m2.vo.hierarchy.PointHierarchy)4 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)4 JsonStream (com.serotonin.m2m2.web.mvc.rest.v1.model.JsonStream)4 PointHierarchyModel (com.serotonin.m2m2.web.mvc.rest.v1.model.PointHierarchyModel)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 PointFolder (com.serotonin.m2m2.vo.hierarchy.PointFolder)2