use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class DataPointDao method deleteDataPoints.
public void deleteDataPoints(final int dataSourceId) {
List<DataPointVO> old = getDataPoints(dataSourceId, null, true);
for (DataPointVO dp : old) {
for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.beforeDelete(dp.getId());
}
getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
@SuppressWarnings("synthetic-access")
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
List<Integer> pointIds = queryForList("select id from dataPoints where dataSourceId=?", new Object[] { dataSourceId }, Integer.class);
if (pointIds.size() > 0)
deleteDataPointImpl(createDelimitedList(new HashSet<>(pointIds), ",", null));
}
});
for (DataPointVO dp : old) {
for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.afterDelete(dp.getId());
AuditEventType.raiseDeletedEvent(AuditEventType.TYPE_DATA_POINT, dp);
this.countMonitor.decrement();
}
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class DataPointDao method insertDataPoint.
void insertDataPoint(final DataPointVO dp) {
for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.beforeInsert(dp);
// Create a default text renderer
if (dp.getTextRenderer() == null)
dp.defaultTextRenderer();
dp.setId(ejt.doInsert(//
"insert into dataPoints (xid, dataSourceId, name, deviceName, enabled, pointFolderId, loggingType, " + //
"intervalLoggingPeriodType, intervalLoggingPeriod, intervalLoggingType, tolerance, " + //
"purgeOverride, purgeType, purgePeriod, defaultCacheSize, discardExtremeValues, " + //
"engineeringUnits, readPermission, setPermission, templateId, rollup, dataTypeId, data) " + //
"values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", new Object[] { dp.getXid(), dp.getDataSourceId(), dp.getName(), dp.getDeviceName(), boolToChar(dp.isEnabled()), dp.getPointFolderId(), dp.getLoggingType(), dp.getIntervalLoggingPeriodType(), dp.getIntervalLoggingPeriod(), dp.getIntervalLoggingType(), dp.getTolerance(), boolToChar(dp.isPurgeOverride()), dp.getPurgeType(), dp.getPurgePeriod(), dp.getDefaultCacheSize(), boolToChar(dp.isDiscardExtremeValues()), dp.getEngineeringUnits(), dp.getReadPermission(), dp.getSetPermission(), dp.getTemplateId(), dp.getRollup(), dp.getPointLocator().getDataTypeId(), //
SerializationHelper.writeObject(dp) }, new int[] { Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.CHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.DOUBLE, Types.CHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.CHAR, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.BINARY }));
// Save the relational information.
saveRelationalData(dp, true);
AuditEventType.raiseAddedEvent(AuditEventType.TYPE_DATA_POINT, dp);
for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.afterInsert(dp);
this.countMonitor.increment();
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class DataPointDao method deleteDataPoint.
public void deleteDataPoint(final int dataPointId) {
DataPointVO dp = getDataPoint(dataPointId);
if (dp != null) {
for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.beforeDelete(dataPointId);
getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
deleteDataPointImpl(Integer.toString(dataPointId));
}
});
for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.afterDelete(dataPointId);
AuditEventType.raiseDeletedEvent(AuditEventType.TYPE_DATA_POINT, dp);
countMonitor.decrement();
}
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class DeltamationCommon method validatePoint.
public static DataPointVO validatePoint(int pointId, String name, ProcessResult response, Integer dataType, boolean requireSettable) {
DataPointDao points = DataPointDao.instance;
DataPointVO point = points.getDataPoint(pointId);
if (point == null) {
response.addContextualMessage(name, "validate.noPoint");
return null;
}
if (requireSettable && !point.getPointLocator().isSettable()) {
response.addContextualMessage(name, "validate.pointNotSettable", point.getName());
}
if (dataType != null && point.getPointLocator().getDataTypeId() != dataType) {
response.addContextualMessage(name, "validate.pointWrongType", point.getName());
}
return point;
}
use of com.serotonin.m2m2.vo.DataPointVO 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++;
}
}
Aggregations