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;
}
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());
}
}
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);
}
}
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());
}
}
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
}
Aggregations