Search in sources :

Example 1 with PurgeFilter

use of com.serotonin.m2m2.module.definitions.actions.PurgeFilter in project ma-core-public by infiniteautomation.

the class DataPurge method purgePoint.

private void purgePoint(DataPointVO dataPoint, boolean countPointValues) {
    if (dataPoint.getLoggingType() == DataPointVO.LoggingTypes.NONE) {
        // If there is no logging, then there should be no data, unless logging was just changed to none. In either
        // case, it's ok to delete everything.
        log.info("Purging all data for data point with id " + dataPoint.getId() + " because it is set to logging type NONE.");
        if (Common.runtimeManager.getState() == RuntimeManager.RUNNING) {
            if (countPointValues)
                deletedSamples += Common.runtimeManager.purgeDataPointValues(dataPoint.getId());
            else {
                if (Common.runtimeManager.purgeDataPointValuesWithoutCount(dataPoint.getId()))
                    anyDeletedSamples = true;
            }
        }
    } else {
        // Determine the purging properties to use.
        int purgeType;
        int purgePeriod;
        if (dataPoint.isPurgeOverride()) {
            purgeType = dataPoint.getPurgeType();
            purgePeriod = dataPoint.getPurgePeriod();
        } else {
            // Check the data source level.
            DataSourceVO<?> ds = DataSourceDao.instance.getDataSource(dataPoint.getDataSourceId());
            if (ds.isPurgeOverride()) {
                purgeType = ds.getPurgeType();
                purgePeriod = ds.getPurgePeriod();
            } else {
                // Use the system settings.
                purgeType = SystemSettingsDao.getIntValue(SystemSettingsDao.POINT_DATA_PURGE_PERIOD_TYPE);
                purgePeriod = SystemSettingsDao.getIntValue(SystemSettingsDao.POINT_DATA_PURGE_PERIODS);
            }
        }
        List<PurgeFilter> purgeFilters = new ArrayList<PurgeFilter>();
        for (PurgeFilterDefinition pfd : ModuleRegistry.getDefinitions(PurgeFilterDefinition.class)) purgeFilters.add(pfd.getPurgeFilter());
        // No matter when this purge actually runs, we want it to act like it's midnight.
        DateTime cutoff = new DateTime(runtime);
        cutoff = DateUtils.truncateDateTime(cutoff, Common.TimePeriods.DAYS);
        cutoff = DateUtils.minus(cutoff, purgeType, purgePeriod);
        if (Common.runtimeManager.getState() == RuntimeManager.RUNNING) {
            long millis = cutoff.getMillis();
            for (PurgeFilter pf : purgeFilters) millis = pf.adjustPurgeTime(dataPoint, millis);
            if (countPointValues)
                deletedSamples += Common.runtimeManager.purgeDataPointValues(dataPoint.getId(), cutoff.getMillis());
            else {
                if (Common.runtimeManager.purgeDataPointValuesWithoutCount(dataPoint.getId(), cutoff.getMillis()))
                    anyDeletedSamples = true;
            }
        }
        // If this is an image data type, get the point value ids.
        if (dataPoint.getPointLocator().getDataTypeId() == DataTypes.IMAGE)
            fileIds.addAll(pointValueDao.getFiledataIds(dataPoint.getId()));
    }
}
Also used : PurgeFilterDefinition(com.serotonin.m2m2.module.PurgeFilterDefinition) ArrayList(java.util.ArrayList) PurgeFilter(com.serotonin.m2m2.module.definitions.actions.PurgeFilter) DateTime(org.joda.time.DateTime)

Aggregations

PurgeFilterDefinition (com.serotonin.m2m2.module.PurgeFilterDefinition)1 PurgeFilter (com.serotonin.m2m2.module.definitions.actions.PurgeFilter)1 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1