use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsDwr method getMaintenanceEvent.
@DwrPermission(admin = true)
public ProcessResult getMaintenanceEvent(int id) {
ProcessResult response = new ProcessResult();
MaintenanceEventVO me;
boolean activated = false;
if (id == Common.NEW_ID) {
DateTime dt = new DateTime();
me = new MaintenanceEventVO();
me.setXid(new MaintenanceEventDao().generateUniqueXid());
me.setActiveYear(dt.getYear());
me.setInactiveYear(dt.getYear());
me.setActiveMonth(dt.getMonthOfYear());
me.setInactiveMonth(dt.getMonthOfYear());
} else {
me = new MaintenanceEventDao().getMaintenanceEvent(id);
MaintenanceEventRT rt = RTMDefinition.instance.getRunningMaintenanceEvent(me.getId());
if (rt != null)
activated = rt.isEventActive();
}
response.addData("me", me);
response.addData("activated", activated);
return response;
}
use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsDwr method toggleMaintenanceEvent.
@DwrPermission(admin = true)
public ProcessResult toggleMaintenanceEvent(int id) {
ProcessResult response = new ProcessResult();
MaintenanceEventRT rt = RTMDefinition.instance.getRunningMaintenanceEvent(id);
boolean activated = false;
if (rt == null)
response.addMessage(new TranslatableMessage("maintenanceEvents.toggle.disabled"));
else
activated = rt.toggle();
response.addData("activated", activated);
return response;
}
use of com.serotonin.m2m2.web.dwr.util.DwrPermission 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.web.dwr.util.DwrPermission 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.web.dwr.util.DwrPermission in project ma-modules-public by infiniteautomation.
the class MBusEditDwr method saveMBusDataSource.
//
//
// MBus stuff
//
@DwrPermission(user = true)
public ProcessResult saveMBusDataSource(String name, String xid, Connection connection, int updatePeriodType, int updatePeriods, boolean quantize) {
MBusDataSourceVO ds = (MBusDataSourceVO) Common.getUser().getEditDataSource();
ds.setXid(xid);
ds.setName(name);
ds.setConnection(connection);
ds.setUpdatePeriodType(updatePeriodType);
ds.setUpdatePeriods(updatePeriods);
ds.setQuantize(quantize);
return tryDataSourceSave(ds);
}
Aggregations