Search in sources :

Example 41 with DataPointVO

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();
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataPointChangeDefinition(com.serotonin.m2m2.module.DataPointChangeDefinition) TransactionStatus(org.springframework.transaction.TransactionStatus) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) HashSet(java.util.HashSet)

Example 42 with DataPointVO

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

Example 43 with DataPointVO

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();
    }
}
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 44 with DataPointVO

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;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao)

Example 45 with DataPointVO

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++;
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) ExportDataValue(com.serotonin.m2m2.vo.export.ExportDataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) SpreadsheetException(com.serotonin.m2m2.vo.emport.SpreadsheetException) Date(java.util.Date) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) SpreadsheetException(com.serotonin.m2m2.vo.emport.SpreadsheetException) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) EnhancedPointValueDao(com.serotonin.m2m2.db.dao.EnhancedPointValueDao) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) Cell(org.apache.poi.ss.usermodel.Cell)

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