use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-core-public by infiniteautomation.
the class EventType method getDataSource.
protected DataSourceVO<?> getDataSource(JsonObject json, String name) throws JsonException {
String xid = json.getString(name);
if (xid == null)
throw new TranslatableJsonException("emport.error.eventType.missing.reference", name);
DataSourceVO<?> ds = DataSourceDao.instance.getDataSource(xid);
if (ds == null)
throw new TranslatableJsonException("emport.error.eventType.invalid.reference", name, xid);
return ds;
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-core-public by infiniteautomation.
the class PointValueEmporter method importRow.
/*
* (non-Javadoc)
* @see com.serotonin.m2m2.vo.emport.AbstractSheetEmporter#importRow(org.apache.poi.ss.usermodel.Row)
*/
@Override
protected void importRow(Row rowData) throws SpreadsheetException {
int cellNum = 0;
// Data Point XID
Cell xidCell = rowData.getCell(cellNum++);
if (xidCell == null)
throw new SpreadsheetException(rowData.getRowNum(), "emport.error.xidRequired");
if ((xidCell.getStringCellValue() == null) || (xidCell.getStringCellValue().isEmpty()))
throw new SpreadsheetException("emport.error.xidRequired");
// First Check to see if we already have a point
String xid = xidCell.getStringCellValue();
DataPointVO dp = voMap.get(xid);
DataPointRT dpRt = rtMap.get(xid);
// We will always have the vo in the map but the RT may be null if the point isn't running
if (dp == null) {
dp = dataPointDao.getDataPoint(xid);
if (dp == null)
throw new SpreadsheetException(rowData.getRowNum(), "emport.error.missingPoint", xid);
dpRt = Common.runtimeManager.getDataPoint(dp.getId());
rtMap.put(xid, dpRt);
voMap.put(xid, dp);
}
PointValueTime pvt;
// Cell Device name (Not using Here)
cellNum++;
// Cell Point name (Not using Here)
cellNum++;
// Cell Time
Date time = rowData.getCell(cellNum++).getDateCellValue();
// delete/add column
Cell modifyCell = rowData.getCell(7);
boolean add = false;
boolean delete = false;
if (modifyCell != null) {
String modification = (String) modifyCell.getStringCellValue();
if (modification.equalsIgnoreCase("delete")) {
delete = true;
} else if (modification.equalsIgnoreCase("add")) {
add = true;
} else {
throw new SpreadsheetException(rowData.getRowNum(), "emport.spreadsheet.modifyCellUnknown");
}
}
// What do we do with the row
if (delete) {
if (time == null) {
throw new SpreadsheetException(rowData.getRowNum(), "emport.error.deleteNew", "no timestamp, unable to delete");
} else {
try {
this.rowsDeleted += Common.runtimeManager.purgeDataPointValue(dp.getId(), time.getTime());
} catch (Exception e) {
if (e instanceof DataIntegrityViolationException)
throw new SpreadsheetException(rowData.getRowNum(), "emport.error.unableToDeleteDueToConstraints");
else
throw new SpreadsheetException(rowData.getRowNum(), "emport.error.unableToDelete", e.getMessage());
}
}
// Done now
return;
} else if (add) {
// Cell Value
Cell cell;
cell = rowData.getCell(cellNum++);
// Create a data value
DataValue dataValue;
switch(dp.getPointLocator().getDataTypeId()) {
case DataTypes.ALPHANUMERIC:
dataValue = new AlphanumericValue(cell.getStringCellValue());
break;
case DataTypes.BINARY:
switch(cell.getCellType()) {
case Cell.CELL_TYPE_BOOLEAN:
dataValue = new BinaryValue(new Boolean(cell.getBooleanCellValue()));
break;
case Cell.CELL_TYPE_NUMERIC:
if (cell.getNumericCellValue() == 0)
dataValue = new BinaryValue(new Boolean(false));
else
dataValue = new BinaryValue(new Boolean(true));
break;
case Cell.CELL_TYPE_STRING:
if (cell.getStringCellValue().equalsIgnoreCase("false"))
dataValue = new BinaryValue(new Boolean(false));
else
dataValue = new BinaryValue(new Boolean(true));
break;
default:
throw new SpreadsheetException(rowData.getRowNum(), "common.default", "Invalid cell type for extracting boolean");
}
break;
case DataTypes.MULTISTATE:
dataValue = new MultistateValue((int) cell.getNumericCellValue());
break;
case DataTypes.NUMERIC:
dataValue = new NumericValue(cell.getNumericCellValue());
break;
default:
throw new SpreadsheetException(rowData.getRowNum(), "emport.spreadsheet.unsupportedDataType", dp.getPointLocator().getDataTypeId());
}
// Cell Rendered Value (Not using yet)
cellNum++;
// Cell Annotation
Cell annotationRow = rowData.getCell(cellNum++);
if (annotationRow != null) {
String annotation = annotationRow.getStringCellValue();
// TODO These methods here do not allow updating the Annotation. We need to be a set point source for that to work
TranslatableMessage sourceMessage = new TranslatableMessage("common.default", annotation);
pvt = new AnnotatedPointValueTime(dataValue, time.getTime(), sourceMessage);
} else {
pvt = new PointValueTime(dataValue, time.getTime());
}
// Save to cache if running
if (dpRt != null)
dpRt.savePointValueDirectToCache(pvt, null, true, true);
else {
if (pointValueDao instanceof EnhancedPointValueDao) {
DataSourceVO<?> ds = getDataSource(dp.getDataSourceId());
((EnhancedPointValueDao) pointValueDao).savePointValueAsync(dp, ds, pvt, null);
} else {
pointValueDao.savePointValueAsync(dp.getId(), pvt, null);
}
}
// Increment our counter
this.rowsAdded++;
}
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.
the class SerialDataSourceTestData method getNewlineTerminated.
public static DataPointRT getNewlineTerminated(DataSourceVO<?> ds) {
DataPointVO vo = new DataPointVO();
vo.setName("newlineTerminated");
vo.setXid("newlineTerminated");
vo.setId(currentId++);
SerialPointLocatorVO plVo = new SerialPointLocatorVO();
plVo.setDataTypeId(DataTypes.ALPHANUMERIC);
plVo.setValueRegex(PATTERNS.get(vo.getName()));
plVo.setValueIndex(2);
plVo.setPointIdentifier("");
vo.setPointLocator(plVo);
return new DataPointRT(vo, plVo.createRuntime(), ds, null, null);
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.
the class SerialDataSourceTestData method getMatchAllPoint.
// ========== POINT CREATION METHODS ===========
public static DataPointRT getMatchAllPoint(DataSourceVO<?> ds) {
DataPointVO vo = new DataPointVO();
vo.setName("matchAll");
vo.setXid("matchAll");
vo.setId(currentId++);
vo.setUnitString("");
SerialPointLocatorVO plVo = new SerialPointLocatorVO();
plVo.setDataTypeId(DataTypes.ALPHANUMERIC);
plVo.setValueRegex(PATTERNS.get(vo.getName()));
plVo.setValueIndex(2);
plVo.setPointIdentifier("");
vo.setPointLocator(plVo);
return new DataPointRT(vo, plVo.createRuntime(), ds, null, null);
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.
the class PointValueRestController method getLatestPointValuesForDataSourceAsSingleArray.
/**
* Get the latest point values a set of points return as map of xid to array of values
*
* @param xid
* @param limit
* @return
*/
@ApiOperation(value = "Get Latest Point Values for all points on a data source directly from the Runtime Manager, this makes Cached and Intra-Interval data available.", notes = "Default limit 100, time descending order, Default to return cached data. Returns as single time ordered array.")
@RequestMapping(method = RequestMethod.GET, value = "/{dataSourceXid}/latest-data-source-single-array", produces = { "application/json", "text/csv" })
public ResponseEntity<QueryArrayStream<PointValueTimeModel>> getLatestPointValuesForDataSourceAsSingleArray(HttpServletRequest request, @ApiParam(value = "Data source xid", required = true, allowMultiple = false) @PathVariable String dataSourceXid, @ApiParam(value = "Return rendered value as String", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean useRendered, @ApiParam(value = "Return converted value using displayed unit", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean unitConversion, @ApiParam(value = "Limit results", allowMultiple = false, defaultValue = "100") @RequestParam(value = "limit", defaultValue = "100") int limit, @ApiParam(value = "Return cached data?", allowMultiple = false, defaultValue = "true") @RequestParam(value = "useCache", defaultValue = "true") boolean useCache, @ApiParam(value = "Date Time format pattern for timestamps as strings, if not included epoch milli number is used", required = false, allowMultiple = false) @RequestParam(value = "dateTimeFormat", required = false) String dateTimeFormat, @ApiParam(value = "Time zone of output, used if formatted times are returned", required = false, allowMultiple = false) @RequestParam(value = "timezone", required = false) String timezone) {
RestProcessResult<QueryArrayStream<PointValueTimeModel>> result = new RestProcessResult<QueryArrayStream<PointValueTimeModel>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
DataSourceVO<?> ds = DataSourceDao.instance.getByXid(dataSourceXid);
if (ds == null)
throw new NotFoundRestException();
if (dateTimeFormat != null) {
try {
DateTimeFormatter.ofPattern(dateTimeFormat);
} catch (IllegalArgumentException e) {
RestValidationResult vr = new RestValidationResult();
vr.addError("validate.invalidValue", "dateTimeFormat");
throw new ValidationFailedRestException(vr);
}
}
if (timezone != null) {
try {
ZoneId.of(timezone);
} catch (Exception e) {
RestValidationResult vr = new RestValidationResult();
vr.addError("validate.invalidValue", "timezone");
throw new ValidationFailedRestException(vr);
}
}
List<DataPointVO> points = DataPointDao.instance.getDataPointsForDataSourceStart(ds.getId());
Map<Integer, DataPointVO> pointIdMap = new HashMap<Integer, DataPointVO>(points.size());
for (DataPointVO vo : points) {
if (Permissions.hasDataPointReadPermission(user, vo))
pointIdMap.put(vo.getId(), vo);
else {
// Abort, invalid permissions
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
}
// Do we have any valid points?
if (pointIdMap.size() == 0) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
try {
IdPointValueTimeLatestPointValueFacadeStream pvtDatabaseStream = new IdPointValueTimeLatestPointValueFacadeStream(pointIdMap, useRendered, unitConversion, limit, useCache, dateTimeFormat, timezone);
return result.createResponseEntity(pvtDatabaseStream);
} catch (PermissionException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} else {
return result.createResponseEntity();
}
}
Aggregations