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);
}
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);
}
}
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);
}
});
}
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);
}
Aggregations