Search in sources :

Example 16 with PointValueTimeModel

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

the class PointValueRestController method putPointsValues.

@ApiOperation(value = "Update one or many data point's current value", notes = "Each data point must exist and be enabled")
@RequestMapping(method = RequestMethod.PUT, produces = { "application/json" }, consumes = { "application/json" })
public ResponseEntity<List<XidPointValueTimeModel>> putPointsValues(HttpServletRequest request, @RequestBody(required = true) List<XidPointValueTimeModel> models, @ApiParam(value = "Return converted value using displayed unit", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean unitConversion) throws RestValidationFailedException {
    RestProcessResult<List<XidPointValueTimeModel>> result = new RestProcessResult<List<XidPointValueTimeModel>>(HttpStatus.OK);
    List<XidPointValueTimeModel> setValues = new ArrayList<XidPointValueTimeModel>();
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        for (XidPointValueTimeModel model : models) {
            RestProcessResult<PointValueTimeModel> pointResult = setPointValue(user, model.getXid(), model, unitConversion, ServletUriComponentsBuilder.fromContextPath(request));
            if (pointResult.getHighestStatus().value() == HttpStatus.CREATED.value()) {
                // Save the model for later
                setValues.add(model);
            }
            for (RestMessage message : pointResult.getRestMessages()) {
                result.addRestMessage(message);
            }
        }
        if (setValues.size() > 0)
            return result.createResponseEntity(setValues);
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) XidPointValueTimeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.XidPointValueTimeModel) User(com.serotonin.m2m2.vo.User) XidPointValueTimeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.XidPointValueTimeModel) RecentPointValueTimeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.RecentPointValueTimeModel) PointValueTimeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeModel) RestMessage(com.serotonin.m2m2.web.mvc.rest.v1.message.RestMessage) 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)

Aggregations

PointValueTimeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeModel)11 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)8 User (com.serotonin.m2m2.vo.User)8 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)8 RecentPointValueTimeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.RecentPointValueTimeModel)8 XidPointValueTimeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.XidPointValueTimeModel)8 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)6 ValidationFailedRestException (com.infiniteautomation.mango.rest.v2.exception.ValidationFailedRestException)6 RTException (com.serotonin.m2m2.rt.RTException)6 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)6 RestValidationFailedException (com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException)6 RestValidationResult (com.infiniteautomation.mango.rest.v2.model.RestValidationResult)5 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)5 QueryArrayStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)3 TimePeriod (com.serotonin.m2m2.web.mvc.rest.v1.model.time.TimePeriod)3 ArrayList (java.util.ArrayList)3