use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-core-public by infiniteautomation.
the class DataSourceEditDwr method exportDataPoint.
@DwrPermission(user = true)
public String exportDataPoint(int dataPointId) {
DataSourceVO<?> ds = Common.getUser().getEditDataSource();
DataPointVO dp = DataPointDao.instance.getDataPoint(dataPointId);
if (dp == null)
return null;
if (dp.getDataSourceId() != ds.getId())
throw new PermissionException(new TranslatableMessage("common.default", "Wrong data source"), Common.getUser());
Map<String, Object> data = new LinkedHashMap<>();
List<DataPointVO> dss = new ArrayList<>();
dss.add(dp);
data.put(ConfigurationExportData.DATA_POINTS, dss);
return EmportDwr.export(data);
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-core-public by infiniteautomation.
the class DataSourceEditDwr method getPoint.
protected DataPointVO getPoint(int pointId, DataPointDefaulter defaulter) {
// Added to allow saving point settings from data point edit view
DataPointVO dp = Common.getUser().getEditPoint();
DataSourceVO<?> ds = Common.getUser().getEditDataSource();
if (ds.getId() == Common.NEW_ID)
throw new ShouldNeverHappenException("Please Save Data Source First.");
if (pointId == Common.NEW_ID) {
String deviceName;
String readPermission = null;
String setPermission = null;
if (dp != null) {
deviceName = dp.getDeviceName();
readPermission = dp.getReadPermission();
setPermission = dp.getSetPermission();
} else {
deviceName = ds.getName();
}
dp = new DataPointVO();
dp.setXid(DataPointDao.instance.generateUniqueXid());
dp.setDeviceName(deviceName);
dp.setId(pointId);
dp.setDataSourceId(ds.getId());
dp.setDataSourceTypeName(ds.getDefinition().getDataSourceTypeName());
dp.setReadPermission(readPermission);
dp.setSetPermission(setPermission);
dp.setPointLocator(ds.createPointLocator());
dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
dp.defaultTextRenderer();
} else {
// retain in the user's editing point
if (dp.getId() != pointId)
dp = DataPointDao.instance.getFull(pointId);
}
// Use the defaulter
if (defaulter != null && dp != null) {
if (dp.getId() == Common.NEW_ID)
defaulter.setDefaultValues(dp);
else
defaulter.updateDefaultValues(dp);
}
// should use for this point. If not we must fail.
if (!(dp.getDataSourceTypeName().equals(ds.getDefinition().getDataSourceTypeName())) || (dp.getDataSourceId() != ds.getId())) {
throw new RuntimeException("Data point type mismatch to data source type, unable to save. Are you working with multiple tabs open?");
}
Common.getUser().setEditPoint(dp);
return dp;
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-core-public by infiniteautomation.
the class DataSourceEditDwr method purgeNow.
//
// Data purge
//
@DwrPermission(user = true)
public long purgeNow(int purgeType, int purgePeriod, boolean allData) {
DataSourceVO<?> ds = Common.getUser().getEditDataSource();
if (ds.getId() == Common.NEW_ID)
return 0;
List<DataPointVO> points = DataPointDao.instance.getDataPoints(ds.getId(), DataPointNameComparator.instance, false);
Long count = 0L;
for (DataPointVO point : points) {
if (allData)
count += Common.runtimeManager.purgeDataPointValues(point.getId());
else
count += Common.runtimeManager.purgeDataPointValues(point.getId(), purgeType, purgePeriod);
}
return count;
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-core-public by infiniteautomation.
the class DataSourceListDwr method dataSourceInfo.
@DwrPermission(user = true)
public ProcessResult dataSourceInfo(int dataSourceId) {
DataSourceVO<?> ds = DataSourceDao.instance.getDataSource(dataSourceId);
Permissions.ensureDataSourcePermission(Common.getUser(), ds);
ProcessResult response = new ProcessResult();
String name = StringUtils.abbreviate(TranslatableMessage.translate(getTranslations(), "common.copyPrefix", ds.getName()), 40);
response.addData("name", name);
response.addData("xid", DataSourceDao.instance.generateUniqueXid());
response.addData("deviceName", name);
return response;
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-core-public by infiniteautomation.
the class DataSourceListDwr method init.
@DwrPermission(user = true)
public ProcessResult init() {
ProcessResult response = new ProcessResult();
User user = Common.getUser();
List<DataSourceVO<?>> allDataSources = Common.runtimeManager.getDataSources();
if (Permissions.hasAdmin(user)) {
response.addData("dataSources", allDataSources);
List<StringStringPair> translatedTypes = new ArrayList<>();
for (String type : ModuleRegistry.getDataSourceDefinitionTypes()) translatedTypes.add(new StringStringPair(type, translate(ModuleRegistry.getDataSourceDefinition(type).getDescriptionKey())));
StringStringPairComparator.sort(translatedTypes);
response.addData("types", translatedTypes);
} else {
List<DataSourceVO<?>> dataSources = new ArrayList<>();
for (DataSourceVO<?> ds : allDataSources) {
if (Permissions.hasDataSourcePermission(user, ds))
dataSources.add(ds);
}
response.addData("dataSources", dataSources);
}
return response;
}
Aggregations