Search in sources :

Example 1 with PointValueTimeDeleteResult

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

the class PointValueModificationRestController method deletePointValues.

@ApiOperation(value = "Delete Point Values for one or many Data Points", notes = "Data Point must exist and user must have write access")
@RequestMapping(method = RequestMethod.DELETE, value = "/delete")
@Async
public CompletableFuture<List<PointValueTimeDeleteResult>> deletePointValues(@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, PointValueTimeDelete> results = new HashMap<>();
            stream.forEachOrdered((pvt) -> {
                var entry = results.computeIfAbsent(pvt.getXid(), (xidKey) -> new PointValueTimeDelete(pvt.getXid(), fireEvents, user));
                entry.deleteValue(pvt.getTimestamp());
            });
            return results.values().stream().map(v -> new PointValueTimeDeleteResult(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) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PointValueTimeDeleteResult(com.infiniteautomation.mango.rest.latest.model.pointValue.emport.PointValueTimeDeleteResult) CompletionException(java.util.concurrent.CompletionException) CompletionException(java.util.concurrent.CompletionException) Async(org.springframework.scheduling.annotation.Async) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with PointValueTimeDeleteResult

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

the class PointValueModificationRestController method deletePointValues.

@ApiOperation(value = "Delete Point Values for one or many Data Points", notes = "Data Point must exist and user must have write access")
@RequestMapping(method = RequestMethod.DELETE, value = "/delete")
@Async
public CompletableFuture<List<PointValueTimeDeleteResult>> deletePointValues(@RequestBody Stream<XidPointValueTimeModel> stream, @AuthenticationPrincipal PermissionHolder user) {
    return CompletableFuture.supplyAsync(() -> {
        try {
            PointValueDao pointValueDao = Common.getBean(PointValueDao.class);
            Map<String, PointValueTimeDelete> results = new HashMap<>();
            stream.forEach((pvt) -> {
                results.compute(pvt.getXid(), (xidKey, entry) -> {
                    if (entry == null) {
                        entry = new PointValueTimeDelete(pvt.getXid(), pointValueDao, dataPointDao, user);
                    }
                    entry.deleteValue(pvt.getTimestamp());
                    return entry;
                });
            });
            return results.values().stream().map((v) -> {
                return new PointValueTimeDeleteResult(v.xid, v.totalProcessed, v.totalSkipped, v.result);
            }).collect(Collectors.toList());
        } catch (Exception e) {
            throw new CompletionException(e);
        }
    });
}
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) Common(com.serotonin.m2m2.Common) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) 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) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PointValueTimeDeleteResult(com.infiniteautomation.mango.rest.latest.model.pointValue.emport.PointValueTimeDeleteResult) CompletionException(java.util.concurrent.CompletionException) CompletionException(java.util.concurrent.CompletionException) 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)2 PointValueTimeDeleteResult (com.infiniteautomation.mango.rest.latest.model.pointValue.emport.PointValueTimeDeleteResult)2 PointValueTimeImportResult (com.infiniteautomation.mango.rest.latest.model.pointValue.emport.PointValueTimeImportResult)2 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)2 DataType (com.serotonin.m2m2.DataType)2 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)2 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)2 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)2 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)2 FireEvents (com.serotonin.m2m2.rt.dataImage.DataPointRT.FireEvents)2 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)2 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)2 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)2 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)2 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)2 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)2