ds.setName("Test Virtual");
ds.setEnabled(true);
ds.setUpdatePeriods(5);
ds.setUpdatePeriodType(TimePeriods.SECONDS);
ProcessResult response = new ProcessResult();
ds.validate(response);
if(!response.getHasMessages())
Common.runtimeManager.saveDataSource(ds);
else
throw new RuntimeException("Invalid data!");
DataPointDao dpDao = new DataPointDao();
//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<PointEventDetectorVO>(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!");
}