use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-core-public by infiniteautomation.
the class MangoTestBase method createMockDataPoint.
protected DataPointVO createMockDataPoint(int id, String xid, String name, String deviceName, boolean enabled, int dataSourceId, String dataSourceXid, MangoPermission readPermission, MangoPermission setPermission, MockPointLocatorVO vo) {
DataPointService service = Common.getBean(DataPointService.class);
DataPointVO dp = new DataPointVO();
dp.setId(id);
dp.setXid(xid);
dp.setName(name);
dp.setDeviceName(deviceName);
dp.setEnabled(enabled);
dp.setPointLocator(vo);
dp.setDataSourceId(dataSourceId);
dp.setDataSourceXid(dataSourceXid);
dp.setReadPermission(readPermission);
dp.setSetPermission(setPermission);
try {
return service.insert(dp);
} catch (ValidationException e) {
StringBuilder failureMessage = new StringBuilder();
for (ProcessMessage m : e.getValidationResult().getMessages()) {
String messagePart = m.getContextKey() + " -> " + m.getContextualMessage().translate(Common.getTranslations()) + "\n";
failureMessage.append(messagePart);
}
fail(failureMessage.toString());
return null;
}
}
use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-core-public by infiniteautomation.
the class MangoTestBase method createMockDataPoint.
protected DataPointVO createMockDataPoint(MockDataSourceVO ds, Consumer<DataPointVO> customizer) {
DataPointService service = Common.getBean(DataPointService.class);
DataPointVO dp = new DataPointVO();
dp.setName(UUID.randomUUID().toString());
dp.setDeviceName(ds.getName());
dp.setPointLocator(new MockPointLocatorVO(DataType.NUMERIC, true));
dp.setDataSourceId(ds.getId());
customizer.accept(dp);
try {
return service.insert(dp);
} catch (ValidationException e) {
fail(e.getValidationErrorMessage(Common.getTranslations()));
return null;
}
}
use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-modules-public by infiniteautomation.
the class PointValueRestController method getStatistics.
@ApiOperation(value = "GET statistics for data point(s) over the given time range", notes = "From time inclusive, To time exclusive. Returns map of xid to Statistics object", response = PointValueTimeModel.class, responseContainer = "Map")
@RequestMapping(method = RequestMethod.GET, value = "/statistics/{xids}")
public Map<String, StreamingPointValueTimeModel> getStatistics(@ApiParam(value = "Point xids", required = true, allowMultiple = true) @PathVariable String[] xids, @ApiParam(value = "From time") @RequestParam(value = "from", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime from, @ApiParam(value = "To time") @RequestParam(value = "to", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime to, @ApiParam(value = "Time zone") @RequestParam(value = "timezone", required = false) String timezone, @ApiParam(value = "Date Time format pattern for timestamps as strings, if not included epoch milli number is used") @RequestParam(value = "dateTimeFormat", required = false) String dateTimeFormat, @ApiParam(value = "Fields to be included in the returned data, default is TIMESTAMP,VALUE") @RequestParam(required = false) PointValueField[] fields, Locale locale) {
var points = Arrays.stream(xids).distinct().map(dataPointService::get).collect(Collectors.toUnmodifiableSet());
var mapperBuilder = new StreamMapperBuilder().withDataPoints(points).withRollup(RollupEnum.ALL).withFields(fields).withDateTimeFormat(dateTimeFormat).withTimezone(timezone, from, to).withLocale(locale).withTimestampSource(TimestampSource.STATISTIC);
var aggregateMapper = mapperBuilder.build(AggregateValueMapper::new);
var rollupPeriod = Duration.between(from, to);
return points.stream().collect(Collectors.toUnmodifiableMap(DataPointVO::getXid, point -> {
var aggregateDao = dao.getAggregateDao();
try (var stream = aggregateDao.query(point, from, to, null, rollupPeriod)) {
return stream.map(aggregateMapper).findAny().orElseThrow();
}
}));
}
use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsRestController method exportQuery.
@ApiOperation(value = "Export formatted for Configuration Import by supplying an RQL query", notes = "User must have read permission")
@RequestMapping(method = RequestMethod.GET, value = "/export", produces = MediaTypes.SEROTONIN_JSON_VALUE)
public Map<String, JsonStreamedArray> exportQuery(HttpServletRequest request, @AuthenticationPrincipal PermissionHolder user) {
ASTNode rql = RQLUtils.parseRQLtoAST(request.getQueryString());
Map<String, JsonStreamedArray> export = new HashMap<>();
if (permissionService.hasPermission(user, dataSourcePermissionDefinition.getPermission())) {
export.put("maintenanceEvents", new StreamedSeroJsonVORqlQuery<>(service, rql, null, null, null));
} else {
export.put("maintenanceEvents", new StreamedSeroJsonVORqlQuery<>(service, rql, null, null, null, item -> {
if (item.getDataPoints().size() > 0) {
DataPointPermissionsCheckCallback callback = new DataPointPermissionsCheckCallback(user, true, permissionService, dataPointService);
dao.getPoints(item.getId(), callback);
if (!callback.hasPermission())
return false;
}
if (item.getDataSources().size() > 0) {
DataSourcePermissionsCheckCallback callback = new DataSourcePermissionsCheckCallback(user, true, permissionService);
dao.getDataSources(item.getId(), callback);
if (!callback.hasPermission())
return false;
}
return true;
}));
}
return export;
}
use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-modules-public by infiniteautomation.
the class MaintenanceEventType method getEventPermission.
@Override
public MangoPermission getEventPermission(Map<String, Object> context, PermissionService service) {
DataSourceService dataSourceService = Common.getBean(DataSourceService.class);
DataPointService dataPointService = Common.getBean(DataPointService.class);
MaintenanceEventsService maintenanceEventService = Common.getBean(MaintenanceEventsService.class);
Set<Role> allRequired = new HashSet<>();
try {
MaintenanceEventVO vo = maintenanceEventService.get(maintenanceId);
try {
for (int dsId : vo.getDataSources()) {
MangoPermission read = dataSourceService.getReadPermission(dsId);
read.getRoles().forEach(allRequired::addAll);
}
} catch (NotFoundException e) {
// Ignore this item
}
try {
for (int dpId : vo.getDataPoints()) {
MangoPermission read = dataPointService.getReadPermission(dpId);
read.getRoles().forEach(allRequired::addAll);
}
} catch (NotFoundException e) {
// Ignore this item
}
} catch (NotFoundException e) {
// Ignore all of it
}
if (allRequired.size() == 0) {
return MangoPermission.superadminOnly();
} else {
return MangoPermission.requireAllRoles(allRequired);
}
}
Aggregations