Search in sources :

Example 16 with DwrPermission

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;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DateTime(org.joda.time.DateTime) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 17 with DwrPermission

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;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 18 with DwrPermission

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;
}
Also used : IntStringPair(com.serotonin.db.pair.IntStringPair) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) Translations(com.serotonin.m2m2.i18n.Translations) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 19 with DwrPermission

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;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) HashMap(java.util.HashMap) IOException(java.io.IOException) MBusPointLocatorVO(com.serotonin.m2m2.mbus.MBusPointLocatorVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 20 with DwrPermission

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);
}
Also used : MBusDataSourceVO(com.serotonin.m2m2.mbus.MBusDataSourceVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)220 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)126 User (com.serotonin.m2m2.vo.User)56 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)47 ArrayList (java.util.ArrayList)35 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)24 HashMap (java.util.HashMap)21 StringStringPair (com.serotonin.db.pair.StringStringPair)11 SystemSettingsDao (com.serotonin.m2m2.db.dao.SystemSettingsDao)11 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)10 IOException (java.io.IOException)9 DateTime (org.joda.time.DateTime)9 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)9 AbstractVO (com.serotonin.m2m2.vo.AbstractVO)8 AnonymousUser (com.serotonin.m2m2.vo.AnonymousUser)8 LinkedHashMap (java.util.LinkedHashMap)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)7 ShareUser (com.serotonin.m2m2.view.ShareUser)7 ResultsWithTotal (com.serotonin.m2m2.db.dao.ResultsWithTotal)6 ReportVO (com.serotonin.m2m2.reports.vo.ReportVO)6