Search in sources :

Example 1 with XidPointValueTimeModel

use of com.infiniteautomation.mango.rest.latest.model.pointValue.XidPointValueTimeModel 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 XidPointValueTimeModel

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

the class PointValueTimeStreamCsvMessageConverter method readJavaType.

private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
    Class<?> deserializationView = null;
    if (inputMessage instanceof MappingJacksonInputMessage) {
        deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView();
    }
    ObjectReader reader;
    if (deserializationView != null) {
        reader = this.objectMapper.readerWithView(deserializationView);
    } else {
        reader = this.objectMapper.reader();
    }
    // TODO detect type/schema for the callback
    // could use the type if we add generics to PointValueTimeImportStream
    reader = reader.forType(XidPointValueTimeModel.class);
    CsvSchema schema = CsvSchema.emptySchema().withHeader().withStrictHeaders(false);
    ObjectReader csvReader = reader.with(schema);
    try {
        MappingIterator<XidPointValueTimeModel> iterator = csvReader.readValues(inputMessage.getBody());
        CsvSchema fullSchema = (CsvSchema) iterator.getParser().getSchema();
        if (fullSchema.column(PointValueField.VALUE.getFieldName()) == null) {
            throw new IOException("Missing required column " + PointValueField.VALUE.getFieldName());
        } else if (fullSchema.column(PointValueField.XID.getFieldName()) == null) {
            throw new IOException("Missing required column " + PointValueField.XID.getFieldName());
        } else if (fullSchema.column(PointValueField.TIMESTAMP.getFieldName()) == null) {
            throw new IOException("Missing required column " + PointValueField.TIMESTAMP.getFieldName());
        }
        fullSchema.column("xid");
        Stream<XidPointValueTimeModel> stream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false);
        return stream;
    } catch (IOException ex) {
        throw new HttpMessageNotReadableException("Could not read document: " + ex.getMessage(), ex, inputMessage);
    }
}
Also used : CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) XidPointValueTimeModel(com.infiniteautomation.mango.rest.latest.model.pointValue.XidPointValueTimeModel) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) MappingJacksonInputMessage(org.springframework.http.converter.json.MappingJacksonInputMessage) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException)

Example 3 with XidPointValueTimeModel

use of com.infiniteautomation.mango.rest.latest.model.pointValue.XidPointValueTimeModel 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)

Example 4 with XidPointValueTimeModel

use of com.infiniteautomation.mango.rest.latest.model.pointValue.XidPointValueTimeModel 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)4 PointValueTimeDeleteResult (com.infiniteautomation.mango.rest.latest.model.pointValue.emport.PointValueTimeDeleteResult)3 PointValueTimeImportResult (com.infiniteautomation.mango.rest.latest.model.pointValue.emport.PointValueTimeImportResult)3 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)3 DataType (com.serotonin.m2m2.DataType)3 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)3 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)3 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)3 FireEvents (com.serotonin.m2m2.rt.dataImage.DataPointRT.FireEvents)3 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)3 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)3 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)3 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)3 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)3 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)3 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)3