Search in sources :

Example 1 with StringStringPair

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;
}
Also used : StringStringPair(com.serotonin.db.pair.StringStringPair) User(com.serotonin.m2m2.vo.User) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with StringStringPair

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;
}
Also used : StringStringPair(com.serotonin.db.pair.StringStringPair) LongLongPair(com.serotonin.db.pair.LongLongPair) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) DataSourceRT(com.serotonin.m2m2.rt.dataSource.DataSourceRT) PollingDataSource(com.serotonin.m2m2.rt.dataSource.PollingDataSource) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 3 with StringStringPair

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());
    }
}
Also used : StringStringPair(com.serotonin.db.pair.StringStringPair) SystemSettingsDao(com.serotonin.m2m2.db.dao.SystemSettingsDao) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 4 with StringStringPair

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;
}
Also used : Field(java.lang.reflect.Field) StringStringPair(com.serotonin.db.pair.StringStringPair) IOException(java.io.IOException) IOException(java.io.IOException)

Example 5 with StringStringPair

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;
}
Also used : EmportDefinition(com.serotonin.m2m2.module.EmportDefinition) StringStringPair(com.serotonin.db.pair.StringStringPair) ArrayList(java.util.ArrayList)

Aggregations

StringStringPair (com.serotonin.db.pair.StringStringPair)17 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)11 ArrayList (java.util.ArrayList)11 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)9 User (com.serotonin.m2m2.vo.User)5 JsonObject (com.serotonin.json.type.JsonObject)2 JsonString (com.serotonin.json.type.JsonString)2 ShareUser (com.serotonin.m2m2.view.ShareUser)2 AnonymousUser (com.serotonin.m2m2.vo.AnonymousUser)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Version (com.github.zafarkhaja.semver.Version)1 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)1 LongLongPair (com.serotonin.db.pair.LongLongPair)1 JsonException (com.serotonin.json.JsonException)1 JsonWriter (com.serotonin.json.JsonWriter)1 JsonTypeReader (com.serotonin.json.type.JsonTypeReader)1 SystemSettingsDao (com.serotonin.m2m2.db.dao.SystemSettingsDao)1 SimpleCompoundComponent (com.serotonin.m2m2.gviews.component.SimpleCompoundComponent)1