use of com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition in project ma-core-public by infiniteautomation.
the class DataPointDao method deleteBatch.
/**
* Delete a batch of data points in bulk (for performance)
*/
protected void deleteBatch(List<DataPointVO> batch, List<Integer> ids, Set<Integer> permissionIds, Set<Integer> seriesIds) {
// delete event handler mappings
create.deleteFrom(eventHandlersMapping).where(eventHandlersMapping.eventTypeName.eq(EventTypeNames.DATA_POINT), eventHandlersMapping.eventTypeRef1.in(ids)).execute();
// delete user comments
create.deleteFrom(userComments).where(userComments.commentType.eq(2), userComments.typeKey.in(ids)).execute();
// delete event detectors
create.deleteFrom(eventDetectors).where(eventDetectors.dataPointId.in(ids)).execute();
for (DataPointVO vo : batch) {
DataSourceDefinition<? extends DataSourceVO> def = ModuleRegistry.getDataSourceDefinition(vo.getPointLocator().getDataSourceType());
if (def != null) {
def.deleteRelationalData(vo);
}
// Run Pre Delete Change definitions
for (DataPointChangeDefinition changeDefinition : changeDefinitions) {
changeDefinition.preDelete(vo);
}
}
// delete the points in bulk
int deleted = create.deleteFrom(table).where(table.id.in(ids)).execute();
if (this.countMonitor != null) {
this.countMonitor.addValue(-deleted);
}
for (Integer id : permissionIds) {
permissionService.deletePermissionId(id);
}
// Try to delete the timeSeries.id row
for (Integer seriesId : seriesIds) {
try {
this.create.deleteFrom(TimeSeries.TIME_SERIES).where(TimeSeries.TIME_SERIES.id.eq(seriesId)).execute();
} catch (Exception e) {
// Probably in use by another point (2 points on the same series)
}
}
// Run Post Delete Change definitions
for (DataPointVO vo : batch) {
for (DataPointChangeDefinition changeDefinition : changeDefinitions) {
changeDefinition.postDelete(vo);
}
}
// Audit Events/Dao events
for (DataPointVO vo : batch) {
publishEvent(createDaoEvent(DaoEventType.DELETE, vo, null));
publishAuditEvent(new DeleteAuditEvent<DataPointVO>(this.auditEventType, Common.getUser(), vo));
}
}
use of com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition in project ma-core-public by infiniteautomation.
the class DataPointService method update.
@Override
protected DataPointVO update(DataPointVO existing, DataPointVO vo) throws PermissionException, ValidationException {
PermissionHolder user = Common.getUser();
ensureEditPermission(user, existing);
vo.setId(existing.getId());
for (DataPointChangeDefinition def : changeDefinitions) {
def.preUpdate(vo);
}
ensureValid(existing, vo);
getRuntimeManager().stopDataPoint(vo.getId());
dao.update(existing, vo);
for (DataPointChangeDefinition def : changeDefinitions) {
def.postUpdate(vo);
}
if (vo.isEnabled()) {
List<AbstractPointEventDetectorVO> detectors = eventDetectorDao.getWithSource(vo.getId(), vo);
getRuntimeManager().startDataPoint(new DataPointWithEventDetectors(vo, detectors));
}
return vo;
}
use of com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition in project ma-core-public by infiniteautomation.
the class DataPointService method delete.
@Override
protected DataPointVO delete(DataPointVO vo) throws PermissionException, NotFoundException {
PermissionHolder user = Common.getUser();
ensureDeletePermission(user, vo);
for (DataPointChangeDefinition def : changeDefinitions) {
def.preDelete(vo);
}
getRuntimeManager().stopDataPoint(vo.getId());
dao.delete(vo);
for (DataPointChangeDefinition def : changeDefinitions) {
def.postDelete(vo);
}
pointValueCache.deleteCache(vo);
getEventManager().cancelEventsForDataPoint(vo.getId());
return vo;
}
use of com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition in project ma-core-public by infiniteautomation.
the class DataPointDao method updateDataPoint.
void updateDataPoint(final DataPointVO dp) {
for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.beforeUpdate(dp);
DataPointVO old = getDataPoint(dp.getId());
// If have a new data type we will wipe our history
if (old.getPointLocator().getDataTypeId() != dp.getPointLocator().getDataTypeId())
Common.databaseProxy.newPointValueDao().deletePointValues(dp.getId());
// Save the VO information.
updateDataPointShallow(dp);
AuditEventType.raiseChangedEvent(AuditEventType.TYPE_DATA_POINT, old, dp);
// Save the relational information.
saveRelationalData(dp, false);
for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.afterUpdate(dp);
}
use of com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition in project ma-core-public by infiniteautomation.
the class DataPointService method insert.
@Override
public DataPointVO insert(DataPointVO vo) throws PermissionException, ValidationException {
PermissionHolder user = Common.getUser();
// Ensure they can create
ensureCreatePermission(user, vo);
// Ensure id is not set
if (vo.getId() != Common.NEW_ID) {
ProcessResult result = new ProcessResult();
result.addContextualMessage("id", "validate.invalidValue");
throw new ValidationException(result);
}
// Generate an Xid if necessary
if (StringUtils.isEmpty(vo.getXid()))
vo.setXid(dao.generateUniqueXid());
for (DataPointChangeDefinition def : changeDefinitions) {
def.preInsert(vo);
}
ensureValid(vo);
dao.insert(vo);
List<AbstractPointEventDetectorVO> detectors = new ArrayList<>();
for (DataPointChangeDefinition def : changeDefinitions) {
for (var detector : def.postInsert(vo)) {
if (detector.isNew()) {
log.warn("Detector added via postInsert hook was not saved");
} else if (detector.getDataPoint().getId() != vo.getId()) {
log.warn("Detector added via postInsert hook was for a different data point");
} else {
detectors.add(detector);
}
}
}
if (vo.isEnabled()) {
// the data point cannot have detectors if it was just inserted, don't query for detectors
getRuntimeManager().startDataPoint(new DataPointWithEventDetectors(vo, detectors));
}
return vo;
}
Aggregations