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!");
}
}
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());
}
Aggregations