Search in sources :

Example 1 with PointValueImportResult

use of com.infiniteautomation.mango.rest.v2.model.pointValue.PointValueImportResult in project ma-modules-public by infiniteautomation.

the class PointValueRestController method savePointsValues.

@ApiOperation(value = "Import Point Values for one or many Data Points", notes = "Data Point must exist and user must have write access")
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Collection<PointValueImportResult>> savePointsValues(HttpServletRequest request, @RequestBody(required = true) List<XidPointValueTimeModel> models, @AuthenticationPrincipal User user) {
    // Map of XIDs to results
    Map<String, PointValueImportResult> results = new HashMap<String, PointValueImportResult>();
    for (XidPointValueTimeModel model : models) {
        PointValueImportResult result = results.get(model.getXid());
        if (result == null) {
            result = new PointValueImportResult(model.getXid(), dao, user);
            results.put(model.getXid(), result);
        }
        // Attempt to save it
        result.saveValue(model);
    }
    return ResponseEntity.ok(results.values());
}
Also used : XidPointValueTimeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.XidPointValueTimeModel) HashMap(java.util.HashMap) PointValueImportResult(com.infiniteautomation.mango.rest.v2.model.pointValue.PointValueImportResult) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

PointValueImportResult (com.infiniteautomation.mango.rest.v2.model.pointValue.PointValueImportResult)1 XidPointValueTimeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.XidPointValueTimeModel)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 HashMap (java.util.HashMap)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1