Search in sources :

Example 36 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.

the class DataSourceTestData method mockDataSource.

/**
 * Get a test data source
 * @return
 */
public static DataSourceVO<?> mockDataSource() {
    MockDataSourceVO ds = new MockDataSourceVO();
    ds.setId(1);
    ds.setXid("mock-xid");
    ds.setName("Mock Name");
    ds.setPurgeOverride(false);
    ds.setPurgeType(PurgeTypes.YEARS);
    ds.setPurgePeriod(1);
    ds.setEnabled(false);
    return ds;
}
Also used : MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO)

Example 37 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.

the class DataSourceFunctionalTests method testAdminCreate.

/**
 * Test creating a mock data source
 */
public void testAdminCreate() {
    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(post("/v1/dataSources/").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 38 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.

the class InternalMenuItem method maybeInstallSystemMonitor.

/**
 */
private void maybeInstallSystemMonitor(boolean safe) {
    DataSourceVO<?> ds = DataSourceDao.instance.getByXid(SYSTEM_DATASOURCE_XID);
    if (ds == null) {
        // Create Data Source
        DataSourceDefinition def = ModuleRegistry.getDataSourceDefinition(InternalDataSourceDefinition.DATA_SOURCE_TYPE);
        ds = def.baseCreateDataSourceVO();
        InternalDataSourceVO vo = (InternalDataSourceVO) ds;
        vo.setXid(SYSTEM_DATASOURCE_XID);
        vo.setName(SYSTEM_DATASOURCE_DEVICE_NAME);
        vo.setUpdatePeriods(10);
        vo.setUpdatePeriodType(TimePeriods.SECONDS);
        DataSourceDao.instance.saveDataSource(vo);
        // Setup the Points
        maybeCreatePoints(safe, ds);
        // Enable the data source
        if (!safe) {
            vo.setEnabled(true);
            Common.runtimeManager.saveDataSource(vo);
        }
    } else {
        // Ensure all points are added
        maybeCreatePoints(safe, ds);
    }
}
Also used : DataSourceDefinition(com.serotonin.m2m2.module.DataSourceDefinition)

Example 39 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.

the class MaintenanceEventVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    String text = jsonObject.getString("dataSourceXid");
    if (text != null) {
        DataSourceVO<?> ds = DataSourceDao.instance.getDataSource(text);
        if (ds == null)
            throw new TranslatableJsonException("emport.error.maintenanceEvent.invalid", "dataSourceXid", text);
        dataSourceId = ds.getId();
    }
    text = jsonObject.getString("alarmLevel");
    if (text != null) {
        alarmLevel = AlarmLevels.CODES.getId(text);
        if (!AlarmLevels.CODES.isValidId(alarmLevel))
            throw new TranslatableJsonException("emport.error.maintenanceEvent.invalid", "alarmLevel", text, AlarmLevels.CODES.getCodeList());
    }
    text = jsonObject.getString("scheduleType");
    if (text != null) {
        scheduleType = TYPE_CODES.getId(text);
        if (!TYPE_CODES.isValidId(scheduleType))
            throw new TranslatableJsonException("emport.error.maintenanceEvent.invalid", "scheduleType", text, TYPE_CODES.getCodeList());
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 40 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.

the class PointValueFunctionalTests method testGetAllAdmin.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void testGetAllAdmin() {
    List<User> users = new ArrayList<>();
    User adminUser = UserTestData.adminUser();
    users.add(adminUser);
    users.add(UserTestData.newAdminUser());
    users.add(UserTestData.standardUser());
    // Setup our Mock DS
    DataSourceVO ds = DataSourceTestData.mockDataSource();
    // Configure our REST get settings
    String xid = ds.getXid();
    // Date to = new Date();
    // Date from = new Date(to.getTime() - 1000 * 60 * 60);
    // RollupEnum rollup = null;
    // TimePeriodType timePeriodType = null;
    // Integer timePeriods = null;
    // This will ensure that the getUsers() method returns
    // the mock list of users
    when(userDao.getUsers()).thenReturn(users);
    try {
        MvcResult result = this.mockMvc.perform(get("/v1/pointValues" + xid + ".json").sessionAttr("sessionUser", adminUser).param("from", "2014-08-10T00:00:00.000-10:00").param("to", "2014-08-10T00:00:00.000-10:00").accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isOk()).andReturn();
        List<PointValueTimeModel> models = this.objectMapper.readValue(result.getResponse().getContentAsString(), objectMapper.getTypeFactory().constructCollectionType(List.class, PointValueTimeModel.class));
        // Check the size
        assertEquals(users.size(), models.size());
    } catch (Exception e) {
        fail(e.getMessage());
    }
// Check the data
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) User(com.serotonin.m2m2.vo.User) PointValueTimeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeModel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MvcResult(org.springframework.test.web.servlet.MvcResult)

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