use of com.serotonin.db.pair.StringStringPair in project ma-core-public by infiniteautomation.
the class DataSourceDwr method initDataSourceTypes.
/**
* Init Data Source Types
*
* @return
*/
@DwrPermission(user = true)
public ProcessResult initDataSourceTypes() {
ProcessResult response = new ProcessResult();
User user = Common.getUser();
if (user.isDataSourcePermission()) {
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);
}
return response;
}
use of com.serotonin.db.pair.StringStringPair in project ma-core-public by infiniteautomation.
the class DataSourceDwr method getPollTimes.
/**
* Get the latest poll times and thier durations
* @param id
* @return
*/
@DwrPermission(user = true)
public ProcessResult getPollTimes(int id) {
ProcessResult result = new ProcessResult();
DataSourceRT ds = Common.runtimeManager.getRunningDataSource(id);
List<StringStringPair> polls = new ArrayList<StringStringPair>();
if ((ds != null) && (ds instanceof PollingDataSource)) {
List<LongLongPair> list = ((PollingDataSource) ds).getLatestPollTimes();
String pollTime;
for (LongLongPair poll : list) {
StringBuilder duration = new StringBuilder();
pollTime = Functions.getFullMilliSecondTime(poll.getKey());
if (poll.getValue() >= 0) {
// Format Duration Nicely
Period period = new Period(poll.getValue());
if (period.getHours() >= 1) {
duration.append(translate("common.duration.hours", period.getHours()));
duration.append(SPACE);
}
if (period.getMinutes() >= 1) {
duration.append(translate("common.duration.minutes", period.getMinutes()));
duration.append(SPACE);
}
if (period.getSeconds() >= 1) {
duration.append(translate("common.duration.seconds", period.getSeconds()));
duration.append(SPACE);
}
duration.append(translate("common.duration.millis", period.getMillis()));
} else {
duration.append(translate("event.ds.pollAborted"));
}
StringStringPair pair = new StringStringPair(pollTime, duration.toString());
polls.add(pair);
}
}
List<String> aborts = new ArrayList<String>();
if ((ds != null) && (ds instanceof PollingDataSource)) {
List<Long> list = ((PollingDataSource) ds).getLatestAbortedPollTimes();
String pollTime;
for (Long poll : list) {
pollTime = Functions.getFullMilliSecondTime(poll);
aborts.add(pollTime);
}
}
result.addData("polls", polls);
result.addData("aborts", aborts);
return result;
}
use of com.serotonin.db.pair.StringStringPair in project ma-core-public by infiniteautomation.
the class SystemSettingsDwr method saveSystemPermissions.
@DwrPermission(admin = true)
public void saveSystemPermissions(String datasource, List<StringStringPair> modulePermissions) {
SystemSettingsDao systemSettingsDao = SystemSettingsDao.instance;
systemSettingsDao.setValue(SystemSettingsDao.PERMISSION_DATASOURCE, datasource);
for (StringStringPair p : modulePermissions) {
// Don't allow saving the superadmin permission as it doesn't do anything it's hard coded
if (!p.getKey().equals(SuperadminPermissionDefinition.PERMISSION))
systemSettingsDao.setValue(p.getKey(), p.getValue());
}
}
use of com.serotonin.db.pair.StringStringPair in project ma-core-public by infiniteautomation.
the class ProcessWorkItem method executeProcessCommand.
public static StringStringPair executeProcessCommand(String command, int timeoutSeconds) throws IOException {
Process process = Runtime.getRuntime().exec(command);
InputReader out = new InputReader(process.getInputStream());
InputReader err = new InputReader(process.getErrorStream());
Common.backgroundProcessing.addWorkItem(out);
Common.backgroundProcessing.addWorkItem(err);
if (LOG.isDebugEnabled() && process.getClass().getName().equals("java.lang.UNIXProcess")) {
try {
Field f = process.getClass().getDeclaredField("pid");
f.setAccessible(true);
LOG.debug("Started command " + command + " on unix system, pid is: " + f.getLong(process));
f.setAccessible(false);
} catch (Exception e) {
LOG.debug("Error extracting pid from UNIXProcess object");
}
}
StringStringPair result = new StringStringPair();
try {
ProcessTimeout timeout = new ProcessTimeout(process, command, timeoutSeconds);
Common.backgroundProcessing.addWorkItem(timeout);
process.waitFor();
out.join();
err.join();
process.destroy();
// If we've made it this far, the process exited properly, so kill the timeout thread if it exists.
timeout.interrupt();
String input = out.getInput();
if (!StringUtils.isBlank(input)) {
result.setKey(input);
LOG.info("Process output: '" + input + "'");
}
input = err.getInput();
if (!StringUtils.isBlank(input)) {
result.setValue(input);
LOG.warn("Process error: '" + input + "'");
}
} catch (InterruptedException e) {
throw new IOException("Timeout while running command: '" + command + "'");
}
return result;
}
use of com.serotonin.db.pair.StringStringPair in project ma-core-public by infiniteautomation.
the class ConfigurationExportData method getAllExportDescriptions.
/**
* Get a list of pairs of i18n property and export names for all export items
* @return
*/
public static List<StringStringPair> getAllExportDescriptions() {
List<StringStringPair> elements = new ArrayList<StringStringPair>();
elements.add(new StringStringPair("header.dataSources", DATA_SOURCES));
elements.add(new StringStringPair("header.dataPoints", DATA_POINTS));
elements.add(new StringStringPair("header.eventHandlers", EVENT_HANDLERS));
// TODO reinstate event detectors once there is a non-data-point event detector
// elements.add(new StringStringPair("header.eventDetectors", EVENT_DETECTORS));
elements.add(new StringStringPair("header.jsonData", JSON_DATA));
elements.add(new StringStringPair("header.mailingLists", MAILING_LISTS));
elements.add(new StringStringPair("header.publishers", PUBLISHERS));
elements.add(new StringStringPair("header.pointHierarchy", POINT_HIERARCHY));
elements.add(new StringStringPair("header.systemSettings", SYSTEM_SETTINGS));
elements.add(new StringStringPair("header.pointPropertyTemplates", TEMPLATES));
elements.add(new StringStringPair("header.users", USERS));
elements.add(new StringStringPair("header.virtualSerialPorts", VIRTUAL_SERIAL_PORTS));
for (EmportDefinition def : ModuleRegistry.getDefinitions(EmportDefinition.class)) {
elements.add(new StringStringPair(def.getDescriptionKey(), def.getElementId()));
}
return elements;
}
Aggregations