Search in sources :

Example 1 with PointValueTimeImportResult

use of com.infiniteautomation.mango.rest.latest.model.pointValue.emport.PointValueTimeImportResult in project ma-modules-public by infiniteautomation.

the class PointValueModificationRestController method importPointValues.

@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, value = "/import")
@Async
public CompletableFuture<List<PointValueTimeImportResult>> importPointValues(@ApiParam(value = "Shall data point listeners be notified, default is NEVER") @RequestParam(defaultValue = "NEVER") FireEvents fireEvents, @RequestBody Stream<XidPointValueTimeModel> stream, @AuthenticationPrincipal PermissionHolder user) {
    return CompletableFuture.supplyAsync(() -> {
        try {
            Map<String, PointValueTimeImport> results = new LinkedHashMap<>();
            stream.forEachOrdered((pvt) -> {
                var entry = results.computeIfAbsent(pvt.getXid(), (xidKey) -> new PointValueTimeImport(pvt.getXid(), fireEvents, user));
                entry.saveValue(pvt.getValue(), pvt.getTimestamp(), pvt.getAnnotation());
            });
            return results.values().stream().map(v -> new PointValueTimeImportResult(v.xid, v.totalProcessed, v.totalSkipped, v.result)).collect(Collectors.toList());
        } catch (Exception e) {
            throw new CompletionException(e);
        }
    }, executorService);
}
Also used : Async(org.springframework.scheduling.annotation.Async) RequestParam(org.springframework.web.bind.annotation.RequestParam) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) XidPointValueTimeModel(com.infiniteautomation.mango.rest.latest.model.pointValue.XidPointValueTimeModel) ApiParam(io.swagger.annotations.ApiParam) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PointValueTimeDeleteResult(com.infiniteautomation.mango.rest.latest.model.pointValue.emport.PointValueTimeDeleteResult) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) StringUtils(org.apache.commons.lang3.StringUtils) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueTimeImportResult(com.infiniteautomation.mango.rest.latest.model.pointValue.emport.PointValueTimeImportResult) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) LinkedHashMap(java.util.LinkedHashMap) RequestBody(org.springframework.web.bind.annotation.RequestBody) DataType(com.serotonin.m2m2.DataType) FireEvents(com.serotonin.m2m2.rt.dataImage.DataPointRT.FireEvents) ApiOperation(io.swagger.annotations.ApiOperation) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) Map(java.util.Map) AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) Api(io.swagger.annotations.Api) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) ExecutorService(java.util.concurrent.ExecutorService) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) RuntimeManager(com.serotonin.m2m2.rt.RuntimeManager) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) List(java.util.List) Stream(java.util.stream.Stream) AuthenticationPrincipal(org.springframework.security.core.annotation.AuthenticationPrincipal) PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) CompletionException(java.util.concurrent.CompletionException) PointValueTimeImportResult(com.infiniteautomation.mango.rest.latest.model.pointValue.emport.PointValueTimeImportResult) CompletionException(java.util.concurrent.CompletionException) LinkedHashMap(java.util.LinkedHashMap) Async(org.springframework.scheduling.annotation.Async) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

XidPointValueTimeModel (com.infiniteautomation.mango.rest.latest.model.pointValue.XidPointValueTimeModel)1 PointValueTimeDeleteResult (com.infiniteautomation.mango.rest.latest.model.pointValue.emport.PointValueTimeDeleteResult)1 PointValueTimeImportResult (com.infiniteautomation.mango.rest.latest.model.pointValue.emport.PointValueTimeImportResult)1 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)1 DataType (com.serotonin.m2m2.DataType)1 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)1 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 RuntimeManager (com.serotonin.m2m2.rt.RuntimeManager)1 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)1 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)1 FireEvents (com.serotonin.m2m2.rt.dataImage.DataPointRT.FireEvents)1 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)1 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)1 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)1 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)1 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)1 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1