Search in sources :

Example 1 with VirtualPointLocatorVO

use of com.serotonin.m2m2.virtual.vo.VirtualPointLocatorVO in project ma-modules-public by infiniteautomation.

the class VirtualEditDwr method createTestSource.

/**
 * Test Method for debugging system.
 */
@DwrPermission(admin = true)
public void createTestSource() {
    VirtualDataSourceVO ds = new VirtualDataSourceVO();
    DataSourceDefinition def = ModuleRegistry.getDataSourceDefinition("VIRTUAL");
    ds = (VirtualDataSourceVO) def.baseCreateDataSourceVO();
    ds.setId(Common.NEW_ID);
    ds.setXid(DataSourceDao.instance.generateUniqueXid());
    ds.setName("Test Virtual");
    ds.setEnabled(true);
    ds.setUpdatePeriods(5);
    ds.setUpdatePeriodType(TimePeriods.SECONDS);
    ds.setPolling(true);
    ProcessResult response = new ProcessResult();
    ds.validate(response);
    if (!response.getHasMessages())
        Common.runtimeManager.saveDataSource(ds);
    else
        throw new RuntimeException("Invalid data!");
    DataPointDao dpDao = DataPointDao.instance;
    // Create Test Points
    for (int i = 0; i < 10; i++) {
        VirtualPointLocatorVO pointLocator = ds.createPointLocator();
        // Create a Random Points
        pointLocator.setDataTypeId(DataTypes.NUMERIC);
        pointLocator.setChangeTypeId(ChangeTypeVO.Types.RANDOM_ANALOG);
        pointLocator.getRandomAnalogChange().setMin(0);
        pointLocator.getRandomAnalogChange().setMax(100);
        pointLocator.getRandomAnalogChange().setStartValue("1");
        pointLocator.setSettable(true);
        DataPointVO dp = new DataPointVO();
        dp.setXid(dpDao.generateUniqueXid());
        dp.setName("Virtual Random " + i);
        dp.setDataSourceId(ds.getId());
        dp.setDataSourceTypeName(ds.getDefinition().getDataSourceTypeName());
        dp.setDeviceName(ds.getName());
        dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
        dp.defaultTextRenderer();
        // Setup the Chart Renderer
        ImageChartRenderer chartRenderer = new ImageChartRenderer(TimePeriods.DAYS, 5);
        dp.setChartRenderer(chartRenderer);
        dp.setPointLocator(pointLocator);
        dp.setEnabled(true);
        dp.setSettable(true);
        dp.setDefaultCacheSize(0);
        dp.validate(response);
        if (!response.getHasMessages())
            Common.runtimeManager.saveDataPoint(dp);
        else
            throw new RuntimeException("Invalid data!");
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) DataSourceDefinition(com.serotonin.m2m2.module.DataSourceDefinition) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) VirtualDataSourceVO(com.serotonin.m2m2.virtual.vo.VirtualDataSourceVO) VirtualPointLocatorVO(com.serotonin.m2m2.virtual.vo.VirtualPointLocatorVO) ImageChartRenderer(com.serotonin.m2m2.view.chart.ImageChartRenderer) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with VirtualPointLocatorVO

use of com.serotonin.m2m2.virtual.vo.VirtualPointLocatorVO in project ma-modules-public by infiniteautomation.

the class VirtualPointLocatorVO method createRuntime.

@Override
public PointLocatorRT<VirtualPointLocatorVO> createRuntime() {
    ChangeTypeRT changeType = getChangeType().createRuntime();
    String startValue = getChangeType().getStartValue();
    DataValue startObject;
    if (dataTypeId == DataTypes.BINARY)
        startObject = BinaryValue.parseBinary(startValue);
    else if (dataTypeId == DataTypes.MULTISTATE) {
        try {
            startObject = MultistateValue.parseMultistate(startValue);
        } catch (NumberFormatException e) {
            startObject = new MultistateValue(0);
        }
    } else if (dataTypeId == DataTypes.NUMERIC) {
        try {
            startObject = NumericValue.parseNumeric(startValue);
        } catch (NumberFormatException e) {
            startObject = new NumericValue(0);
        }
    } else {
        if (startValue == null)
            startObject = new AlphanumericValue("");
        else
            startObject = new AlphanumericValue(startValue);
    }
    return new VirtualPointLocatorRT(this, changeType, startObject, isSettable());
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) VirtualPointLocatorRT(com.serotonin.m2m2.virtual.rt.VirtualPointLocatorRT) ChangeTypeRT(com.serotonin.m2m2.virtual.rt.ChangeTypeRT) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue)

Aggregations

DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 DataSourceDefinition (com.serotonin.m2m2.module.DataSourceDefinition)1 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)1 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)1 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)1 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)1 ImageChartRenderer (com.serotonin.m2m2.view.chart.ImageChartRenderer)1 ChangeTypeRT (com.serotonin.m2m2.virtual.rt.ChangeTypeRT)1 VirtualPointLocatorRT (com.serotonin.m2m2.virtual.rt.VirtualPointLocatorRT)1 VirtualDataSourceVO (com.serotonin.m2m2.virtual.vo.VirtualDataSourceVO)1 VirtualPointLocatorVO (com.serotonin.m2m2.virtual.vo.VirtualPointLocatorVO)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)1 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)1