Search in sources :

Example 1 with DataPointChangeDefinition

use of com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition 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();
}
Also used : DataPointChangeDefinition(com.serotonin.m2m2.module.DataPointChangeDefinition)

Example 2 with DataPointChangeDefinition

use of com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition 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();
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointChangeDefinition(com.serotonin.m2m2.module.DataPointChangeDefinition) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 3 with DataPointChangeDefinition

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));
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointChangeDefinition(com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition) NoDataFoundException(org.jooq.exception.NoDataFoundException) ModuleNotLoadedException(com.serotonin.ModuleNotLoadedException) LicenseViolatedException(com.serotonin.m2m2.LicenseViolatedException)

Example 4 with DataPointChangeDefinition

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;
}
Also used : DataPointChangeDefinition(com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 5 with DataPointChangeDefinition

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;
}
Also used : DataPointChangeDefinition(com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Aggregations

DataPointChangeDefinition (com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition)4 DataPointChangeDefinition (com.serotonin.m2m2.module.DataPointChangeDefinition)3 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)3 DataPointWithEventDetectors (com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors)2 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)2 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)1 ModuleNotLoadedException (com.serotonin.ModuleNotLoadedException)1 LicenseViolatedException (com.serotonin.m2m2.LicenseViolatedException)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 ArrayList (java.util.ArrayList)1 NoDataFoundException (org.jooq.exception.NoDataFoundException)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1