Search in sources :

Example 1 with VirtualDataSourceVO

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

the class VirtualEditDwr method saveVirtualDataSource.

@DwrPermission(user = true)
public ProcessResult saveVirtualDataSource(BasicDataSourceVO basic, int updatePeriods, int updatePeriodType, boolean polling) {
    VirtualDataSourceVO ds = (VirtualDataSourceVO) Common.getUser().getEditDataSource();
    setBasicProps(ds, basic);
    ds.setUpdatePeriods(updatePeriods);
    ds.setUpdatePeriodType(updatePeriodType);
    ds.setPolling(polling);
    return tryDataSourceSave(ds);
}
Also used : VirtualDataSourceVO(com.serotonin.m2m2.virtual.vo.VirtualDataSourceVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with VirtualDataSourceVO

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

Aggregations

VirtualDataSourceVO (com.serotonin.m2m2.virtual.vo.VirtualDataSourceVO)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 DataSourceDefinition (com.serotonin.m2m2.module.DataSourceDefinition)1 ImageChartRenderer (com.serotonin.m2m2.view.chart.ImageChartRenderer)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