use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsDwr method getMaintenanceEvents.
@DwrPermission(admin = true)
public ProcessResult getMaintenanceEvents() {
ProcessResult response = new ProcessResult();
final Translations translations = getTranslations();
List<MaintenanceEventVO> events = new MaintenanceEventDao().getMaintenanceEvents();
Collections.sort(events, new Comparator<MaintenanceEventVO>() {
@Override
public int compare(MaintenanceEventVO m1, MaintenanceEventVO m2) {
return m1.getDescription().translate(translations).compareTo(m1.getDescription().translate(translations));
}
});
response.addData(MODEL_ATTR_EVENTS, events);
List<IntStringPair> dataSources = new ArrayList<IntStringPair>();
for (DataSourceVO<?> ds : DataSourceDao.instance.getDataSources()) dataSources.add(new IntStringPair(ds.getId(), ds.getName()));
response.addData("dataSources", dataSources);
return response;
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.
the class DataSourceFunctionalTests method testAdminUpdate.
/**
* Test udpating a mock data source
*/
public void testAdminUpdate() {
DataSourceVO ds = DataSourceTestData.mockDataSource();
when(dataSourceDao.getByXid(ds.getXid())).thenReturn(ds);
User adminUser = UserTestData.adminUser();
ObjectWriter writer = this.objectMapper.writerWithView(JsonViews.Test.class);
try {
String userJson = writer.writeValueAsString(new MockDataSourceModel((MockDataSourceVO) ds));
this.mockMvc.perform(put("/v1/dataSources/" + ds.getXid()).content(userJson).contentType(MediaType.APPLICATION_JSON).sessionAttr("sessionUser", adminUser).accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isCreated());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.
the class DataSourceFunctionalTests method testGetDataSource.
public void testGetDataSource() {
User adminUser = UserTestData.adminUser();
DataSourceVO ds = DataSourceTestData.mockDataSource();
when(dataSourceDao.getByXid(ds.getXid())).thenReturn(ds);
try {
MvcResult result = this.mockMvc.perform(get("/v1/dataSources/" + ds.getXid()).sessionAttr("sessionUser", adminUser).accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isOk()).andReturn();
AbstractDataSourceModel model = this.objectMapper.readValue(result.getResponse().getContentAsString(), MockDataSourceModel.class);
assertEquals(model.getName(), ds.asModel().getName());
// Check the size
} catch (Exception e) {
fail(e.getMessage());
}
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.
the class MBusEditDwr method changeMBusAddress.
@DwrPermission(user = true)
public Map<String, Object> changeMBusAddress(int deviceIndex, String newAddress) {
Map<String, Object> result = new HashMap<>();
result.put("deviceIndex", deviceIndex);
MBusDiscovery test = Common.getUser().getTestingUtility(MBusDiscovery.class);
if (test == null) {
return null;
}
try {
final byte oldAddress = test.getDevice(deviceIndex).getAddress();
byte address;
if (newAddress.startsWith("0x")) {
address = (byte) Short.parseShort(newAddress.substring(2), 16);
} else {
address = (byte) Short.parseShort(newAddress);
}
if (test.changeAddress(deviceIndex, address, result)) {
// if address was changed, then change existing datapoints enabled disabled
final DataSourceVO<?> ds = Common.getUser().getEditDataSource();
List<DataPointVO> dpVos = DataPointDao.instance.getDataPoints(ds.getId(), null);
for (DataPointVO dpVo : dpVos) {
final MBusPointLocatorVO pl = dpVo.getPointLocator();
if (pl.getAddress() == oldAddress) {
pl.setAddress(address);
Common.runtimeManager.saveDataPoint(dpVo);
}
}
}
result.put("points", getPoints());
} catch (IOException | InterruptedException e) {
return null;
}
return result;
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.
the class InternalMenuItem method maybeCreatePoints.
/**
*/
private void maybeCreatePoints(boolean safe, DataSourceVO<?> vo) {
Map<String, ValueMonitor<?>> monitors = getAllHomePageMonitors();
Iterator<String> it = monitors.keySet().iterator();
while (it.hasNext()) {
String xid = it.next();
ValueMonitor<?> monitor = monitors.get(xid);
if (monitor != null) {
DataPointVO dp = DataPointDao.instance.getByXid(xid);
if (dp == null) {
InternalPointLocatorVO pl = new InternalPointLocatorVO();
pl.setMonitorId(monitor.getId());
dp = new DataPointVO();
dp.setXid(xid);
dp.setName(monitor.getName().translate(Common.getTranslations()));
dp.setDataSourceId(vo.getId());
dp.setDeviceName(vo.getName());
dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
dp.defaultTextRenderer();
dp.setEnabled(true);
dp.setChartColour("");
dp.setPointLocator(pl);
// Use default template
DataPointPropertiesTemplateVO template = TemplateDao.instance.getDefaultDataPointTemplate(pl.getDataTypeId());
if (template != null) {
template.updateDataPointVO(dp);
dp.setTemplateId(template.getId());
}
// If we are numeric then we want to log on change
switch(pl.getDataTypeId()) {
case DataTypes.NUMERIC:
if (SYSTEM_UPTIME_POINT_XID.equals(xid)) {
// This changes every time, so just do an interval instant
dp.setLoggingType(LoggingTypes.INTERVAL);
dp.setIntervalLoggingPeriodType(Common.TimePeriods.MINUTES);
dp.setIntervalLoggingPeriod(5);
dp.setIntervalLoggingType(DataPointVO.IntervalLoggingTypes.INSTANT);
} else {
// Setup to Log on Change
dp.setLoggingType(LoggingTypes.ON_CHANGE);
}
if (dp.getTextRenderer() instanceof AnalogRenderer && !dp.getXid().equals(SYSTEM_UPTIME_POINT_XID)) {
// This are count points, no need for decimals.
((AnalogRenderer) dp.getTextRenderer()).setFormat("0");
}
// No template in use here
dp.setTemplateId(null);
break;
}
ProcessResult result = new ProcessResult();
dp.validate(result);
if (!result.getHasMessages()) {
if (safe)
DataPointDao.instance.saveDataPoint(dp);
else
Common.runtimeManager.saveDataPoint(dp);
} else {
for (ProcessMessage message : result.getMessages()) {
LOG.error(message.toString(Common.getTranslations()));
}
}
}
}
}
}
Aggregations