Search in sources :

Example 31 with DataSourceVO

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;
}
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 32 with DataSourceVO

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());
    }
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) User(com.serotonin.m2m2.vo.User) JsonViews(com.serotonin.m2m2.web.mvc.rest.v1.mapping.JsonViews) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) MockDataSourceModel(com.serotonin.m2m2.web.mvc.rest.v1.model.MockDataSourceModel)

Example 33 with DataSourceVO

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());
    }
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) AbstractDataSourceModel(com.serotonin.m2m2.web.mvc.rest.v1.model.dataSource.AbstractDataSourceModel) User(com.serotonin.m2m2.vo.User) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 34 with DataSourceVO

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;
}
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 35 with DataSourceVO

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()));
                    }
                }
            }
        }
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) DataPointPropertiesTemplateVO(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) AnalogRenderer(com.serotonin.m2m2.view.text.AnalogRenderer) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage) ValueMonitor(com.infiniteautomation.mango.monitor.ValueMonitor)

Aggregations

User (com.serotonin.m2m2.vo.User)31 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)28 ArrayList (java.util.ArrayList)21 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)19 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)18 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)18 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)15 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)15 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)11 List (java.util.List)10 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)9 AbstractDataSourceModel (com.serotonin.m2m2.web.mvc.rest.v1.model.dataSource.AbstractDataSourceModel)8 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)6 MockDataSourceVO (com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO)6 DataPointPropertiesTemplateVO (com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO)6 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)5 URI (java.net.URI)5 HashMap (java.util.HashMap)5