Search in sources :

Example 36 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO 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)

Example 37 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.

the class JsonEmportScriptUtility method dataPointQuery.

public String dataPointQuery(String query, int prettyIndent) {
    Map<String, Object> data = new LinkedHashMap<>();
    if (admin) {
        ASTNode root = parser.parse(query);
        List<DataPointVO> dataPoints = new ArrayList<>();
        ConditionSortLimitWithTagKeys conditions = DataPointDao.instance.rqlToCondition(root);
        DataPointDao.instance.customizedQuery(conditions, new MappedRowCallback<DataPointVO>() {

            @Override
            public void row(DataPointVO item, int index) {
                dataPoints.add(item);
            }
        });
        data.put(ConfigurationExportData.DATA_POINTS, dataPoints);
    }
    return EmportDwr.export(data, prettyIndent);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ASTNode(net.jazdw.rql.parser.ASTNode) ArrayList(java.util.ArrayList) JsonObject(com.serotonin.json.type.JsonObject) ConditionSortLimitWithTagKeys(com.infiniteautomation.mango.db.query.ConditionSortLimitWithTagKeys) LinkedHashMap(java.util.LinkedHashMap)

Example 38 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.

the class VarNames method contextToString.

public static String contextToString(List<IntStringPair> context) {
    DataPointDao dataPointDao = DataPointDao.instance;
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (IntStringPair ivp : context) {
        DataPointVO dp = dataPointDao.getDataPoint(ivp.getKey(), false);
        if (first)
            first = false;
        else
            sb.append(", ");
        if (dp == null)
            sb.append("?=");
        else
            sb.append(dp.getExtendedName()).append("=");
        sb.append(ivp.getValue());
    }
    return sb.toString();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) IntStringPair(com.serotonin.db.pair.IntStringPair)

Example 39 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.

the class DataPointDao method bulkClearPermissions.

/**
 * @param node
 * @param updateSetPermissions - true will update set, false will update read
 * @return
 */
public long bulkClearPermissions(ASTNode root, boolean updateSetPermissions) {
    long count;
    if (root == null) {
        // All points
        count = ejt.execute(new DataPointPermissionChangePreparedStatementCreator("SELECT dp.id,dp.readPermission,dp.setPermission FROM dataPoints AS dp FOR UPDATE; ", new ArrayList<Object>()), new DataPointPermissionChangeCallback(updateSetPermissions, null));
    } else {
        switch(Common.databaseProxy.getType()) {
            case H2:
            case DERBY:
            case MSSQL:
            case MYSQL:
            case POSTGRES:
            default:
                final SQLStatement select = new SQLStatement("SELECT dp.id,dp.readPermission,dp.setPermission FROM ", COUNT_BASE, this.joins, this.tableName, this.TABLE_PREFIX, true, false, super.getIndexes(), this.databaseType);
                root.accept(new RQLToSQLSelect<DataPointVO>(this), select);
                select.build();
                count = ejt.execute(new DataPointPermissionChangePreparedStatementCreator(select.getSelectSql() + " FOR UPDATE; ", select.getSelectArgs()), new DataPointPermissionChangeCallback(updateSetPermissions, null));
                break;
        }
    }
    return count;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) SQLStatement(com.infiniteautomation.mango.db.query.SQLStatement)

Example 40 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.

the class DataPointDao method bulkUpdatePermissions.

/**
 * @param node
 * @param permissions
 * @param updateSetPermissions - true will update set, false will update read
 * @return
 */
public long bulkUpdatePermissions(ASTNode root, String uncleanPermissions, boolean updateSetPermissions) {
    // Anything to do?
    if (StringUtils.isEmpty(uncleanPermissions))
        return 0;
    // Trim off any ending commas
    if (uncleanPermissions.endsWith(",")) {
        uncleanPermissions = uncleanPermissions.substring(0, uncleanPermissions.length() - 1);
    }
    final String newPermissions = uncleanPermissions;
    long count;
    if (root == null) {
        // All points
        count = ejt.execute(new DataPointPermissionChangePreparedStatementCreator("SELECT dp.id,dp.readPermission,dp.setPermission FROM dataPoints AS dp FOR UPDATE; ", new ArrayList<Object>()), new DataPointPermissionChangeCallback(updateSetPermissions, newPermissions));
    } else {
        switch(Common.databaseProxy.getType()) {
            case H2:
            case DERBY:
            case MSSQL:
            case MYSQL:
            case POSTGRES:
            default:
                final SQLStatement select = new SQLStatement("SELECT dp.id,dp.readPermission,dp.setPermission FROM ", COUNT_BASE, this.joins, this.tableName, this.TABLE_PREFIX, true, false, super.getIndexes(), this.databaseType);
                root.accept(new RQLToSQLSelect<DataPointVO>(this), select);
                select.build();
                count = ejt.execute(new DataPointPermissionChangePreparedStatementCreator(select.getSelectSql() + " FOR UPDATE; ", select.getSelectArgs()), new DataPointPermissionChangeCallback(updateSetPermissions, newPermissions));
                break;
        }
    }
    return count;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) SQLStatement(com.infiniteautomation.mango.db.query.SQLStatement)

Aggregations

DataPointVO (com.serotonin.m2m2.vo.DataPointVO)196 User (com.serotonin.m2m2.vo.User)62 ArrayList (java.util.ArrayList)53 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)48 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)40 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)40 HashMap (java.util.HashMap)35 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)33 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)32 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)30 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)29 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)28 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)26 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)21 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)21 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)16 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)15 List (java.util.List)15 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)14 IOException (java.io.IOException)12