Search in sources :

Example 61 with RestProcessResult

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

the class DeviceNameController method deviceNamesByDataSourceXid.

@ApiOperation(value = "List device names by data source XID", response = String.class, responseContainer = "Set")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/by-data-source-xid/{xid}")
public ResponseEntity<Set<String>> deviceNamesByDataSourceXid(@PathVariable String xid, @RequestParam(value = "contains", required = false) String contains, HttpServletRequest request) {
    RestProcessResult<Set<String>> result = new RestProcessResult<Set<String>>(HttpStatus.OK);
    final User user = this.checkUser(request, result);
    if (result.isOk()) {
        DeviceAndPermissionCallback callback = new DeviceAndPermissionCallback(user);
        if (contains != null) {
            DataPointDao.instance.query(SELECT_DEVICENAME_JOIN_DATASOURCE + " WHERE ds.xid=? AND pt.deviceName LIKE ?", new Object[] { xid, "%" + contains + "%" }, DEVICE_AND_PERMISSION_MAPPER, callback);
        } else {
            DataPointDao.instance.query(SELECT_DEVICENAME_JOIN_DATASOURCE + " WHERE ds.xid=?", new Object[] { xid }, DEVICE_AND_PERMISSION_MAPPER, callback);
        }
        return result.createResponseEntity(callback.results);
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) Set(java.util.Set) TreeSet(java.util.TreeSet) ResultSet(java.sql.ResultSet) User(com.serotonin.m2m2.vo.User) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 62 with RestProcessResult

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

the class DeviceNameController method deviceNames.

@ApiOperation(value = "List device names", response = String.class, responseContainer = "Set")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<Set<String>> deviceNames(@RequestParam(value = "contains", required = false) String contains, HttpServletRequest request) {
    RestProcessResult<Set<String>> result = new RestProcessResult<Set<String>>(HttpStatus.OK);
    final User user = this.checkUser(request, result);
    if (result.isOk()) {
        DeviceAndPermissionCallback callback = new DeviceAndPermissionCallback(user);
        if (contains != null) {
            DataPointDao.instance.query(SELECT_DEVICENAME + " WHERE pt.deviceName LIKE ?", new Object[] { "%" + contains + "%" }, DEVICE_AND_PERMISSION_MAPPER, callback);
        } else {
            DataPointDao.instance.query(SELECT_DEVICENAME, new Object[] {}, DEVICE_AND_PERMISSION_MAPPER, callback);
        }
        return result.createResponseEntity(callback.results);
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) Set(java.util.Set) TreeSet(java.util.TreeSet) ResultSet(java.sql.ResultSet) User(com.serotonin.m2m2.vo.User) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 63 with RestProcessResult

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

the class EventsRestController method getById.

@ApiOperation(value = "Get event by ID", notes = "")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/{id}")
public ResponseEntity<EventInstanceModel> getById(@ApiParam(value = "Valid Event ID", required = true, allowMultiple = false) @PathVariable Integer id, HttpServletRequest request) {
    RestProcessResult<EventInstanceModel> result = new RestProcessResult<EventInstanceModel>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        EventInstanceVO vo = EventInstanceDao.instance.get(id);
        if (vo == null) {
            result.addRestMessage(getDoesNotExistMessage());
            return result.createResponseEntity();
        }
        if (!Permissions.hasEventTypePermission(user, vo.getEventType())) {
            result.addRestMessage(getUnauthorizedMessage());
            return result.createResponseEntity();
        }
        EventInstanceModel model = new EventInstanceModel(vo);
        return result.createResponseEntity(model);
    }
    return result.createResponseEntity();
}
Also used : EventInstanceModel(com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventInstanceModel) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 64 with RestProcessResult

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

the class EventsRestController method getActiveSummary.

@ApiOperation(value = "Get the active events summary", notes = "List of counts for all active events by type and the most recent active alarm for each.")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/active-summary")
public ResponseEntity<List<EventLevelSummaryModel>> getActiveSummary(HttpServletRequest request) {
    RestProcessResult<List<EventLevelSummaryModel>> result = new RestProcessResult<List<EventLevelSummaryModel>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        List<EventLevelSummaryModel> list = new ArrayList<EventLevelSummaryModel>();
        // This query is slow the first time as it must fill the UserEventCache
        List<EventInstance> events = Common.eventManager.getAllActiveUserEvents(user.getId());
        int lifeSafetyTotal = 0;
        EventInstance lifeSafetyEvent = null;
        int criticalTotal = 0;
        EventInstance criticalEvent = null;
        int urgentTotal = 0;
        EventInstance urgentEvent = null;
        int warningTotal = 0;
        EventInstance warningEvent = null;
        int importantTotal = 0;
        EventInstance importantEvent = null;
        int informationTotal = 0;
        EventInstance informationEvent = null;
        int noneTotal = 0;
        EventInstance noneEvent = null;
        int doNotLogTotal = 0;
        EventInstance doNotLogEvent = null;
        for (EventInstance event : events) {
            switch(event.getAlarmLevel()) {
                case AlarmLevels.LIFE_SAFETY:
                    lifeSafetyTotal++;
                    lifeSafetyEvent = event;
                    break;
                case AlarmLevels.CRITICAL:
                    criticalTotal++;
                    criticalEvent = event;
                    break;
                case AlarmLevels.URGENT:
                    urgentTotal++;
                    urgentEvent = event;
                    break;
                case AlarmLevels.WARNING:
                    warningTotal++;
                    warningEvent = event;
                    break;
                case AlarmLevels.IMPORTANT:
                    importantTotal++;
                    importantEvent = event;
                    break;
                case AlarmLevels.INFORMATION:
                    informationTotal++;
                    informationEvent = event;
                    break;
                case AlarmLevels.NONE:
                    noneTotal++;
                    noneEvent = event;
                    break;
                case AlarmLevels.DO_NOT_LOG:
                    doNotLogTotal++;
                    doNotLogEvent = event;
                    break;
            }
        }
        EventInstanceModel model;
        // Life Safety
        if (lifeSafetyEvent != null)
            model = new EventInstanceModel(lifeSafetyEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.LIFE_SAFETY), lifeSafetyTotal, model));
        // Critical Events
        if (criticalEvent != null)
            model = new EventInstanceModel(criticalEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.CRITICAL), criticalTotal, model));
        // Urgent Events
        if (urgentEvent != null)
            model = new EventInstanceModel(urgentEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.URGENT), urgentTotal, model));
        // Warning Events
        if (warningEvent != null)
            model = new EventInstanceModel(warningEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.WARNING), warningTotal, model));
        // Important Events
        if (importantEvent != null)
            model = new EventInstanceModel(importantEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.IMPORTANT), importantTotal, model));
        // Information Events
        if (informationEvent != null)
            model = new EventInstanceModel(informationEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.INFORMATION), informationTotal, model));
        // None Events
        if (noneEvent != null)
            model = new EventInstanceModel(noneEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.NONE), noneTotal, model));
        // Do Not Log Events
        if (doNotLogEvent != null)
            model = new EventInstanceModel(doNotLogEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.DO_NOT_LOG), doNotLogTotal, model));
        return result.createResponseEntity(list);
    }
    return result.createResponseEntity();
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) EventInstanceModel(com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventInstanceModel) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) EventLevelSummaryModel(com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventLevelSummaryModel) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 65 with RestProcessResult

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

the class EventsRestController method query.

@ApiOperation(value = "Query Events", notes = "Query by posting AST Model", response = EventInstanceModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/query")
public ResponseEntity<QueryDataPageStream<EventInstanceVO>> query(@ApiParam(value = "Query", required = true) @RequestBody(required = true) ASTNode query, HttpServletRequest request) {
    RestProcessResult<QueryDataPageStream<EventInstanceVO>> result = new RestProcessResult<QueryDataPageStream<EventInstanceVO>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        query = addAndRestriction(query, new ASTNode("eq", "userId", user.getId()));
        return result.createResponseEntity(getPageStream(query));
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) QueryDataPageStream(com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) User(com.serotonin.m2m2.vo.User) ASTNode(net.jazdw.rql.parser.ASTNode) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)132 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)125 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)125 User (com.serotonin.m2m2.vo.User)113 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)33 ArrayList (java.util.ArrayList)30 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)29 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)28 List (java.util.List)27 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)23 ASTNode (net.jazdw.rql.parser.ASTNode)23 RestValidationFailedException (com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException)22 URI (java.net.URI)18 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)15 HashMap (java.util.HashMap)14 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)13 ValidationFailedRestException (com.infiniteautomation.mango.rest.v2.exception.ValidationFailedRestException)11 RTException (com.serotonin.m2m2.rt.RTException)11 DataPointModel (com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel)11 QueryDataPageStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream)11