Search in sources :

Example 11 with StringStringPair

use of com.serotonin.db.pair.StringStringPair in project ma-modules-public by infiniteautomation.

the class GraphicalViewDwr method editInit.

// 
// 
// View editing
// 
@DwrPermission(user = true)
public Map<String, Object> editInit() {
    Map<String, Object> result = new HashMap<String, Object>();
    User user = Common.getUser();
    // Users with which to share.
    // result.put("shareUsers", getShareUsers(user));
    // Users already sharing with.
    // Legacy code, can remove result.put("viewUsers", GraphicalViewsCommon.getUserEditView(user).getViewUsers());
    // View component types
    List<StringStringPair> components = new ArrayList<StringStringPair>();
    for (ImplDefinition impl : ViewComponent.getImplementations()) components.add(new StringStringPair(impl.getName(), translate(impl.getNameKey())));
    result.put("componentTypes", components);
    // Available points
    List<DataPointVO> allPoints = DataPointDao.instance.getDataPoints(DataPointExtendedNameComparator.instance, false);
    List<DataPointBean> availablePoints = new ArrayList<DataPointBean>();
    final boolean admin = Permissions.hasAdmin(user);
    for (DataPointVO dataPoint : allPoints) {
        if (admin || Permissions.hasDataPointReadPermission(user, dataPoint))
            availablePoints.add(new DataPointBean(dataPoint));
    }
    result.put("pointList", availablePoints);
    return result;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) StringStringPair(com.serotonin.db.pair.StringStringPair) ShareUser(com.serotonin.m2m2.view.ShareUser) AnonymousUser(com.serotonin.m2m2.vo.AnonymousUser) User(com.serotonin.m2m2.vo.User) ImplDefinition(com.serotonin.m2m2.view.ImplDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DataPointBean(com.serotonin.m2m2.web.dwr.beans.DataPointBean) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 12 with StringStringPair

use of com.serotonin.db.pair.StringStringPair in project ma-core-public by infiniteautomation.

the class DataPointDwr method getEventDetectorOptions.

/**
 * Get a list of available Point Event Detectors for this point
 *
 * @param vo
 * @return
 */
@DwrPermission(user = true)
public ProcessResult getEventDetectorOptions(int dataTypeId) {
    ProcessResult response = new ProcessResult();
    List<EventDetectorDefinition<?>> definitions = ModuleRegistry.getEventDetectorDefinitions();
    List<StringStringPair> list = new ArrayList<StringStringPair>();
    for (EventDetectorDefinition<?> definition : definitions) {
        AbstractEventDetectorVO<?> vo = definition.baseCreateEventDetectorVO();
        if (vo instanceof AbstractPointEventDetectorVO) {
            AbstractPointEventDetectorVO<?> ped = (AbstractPointEventDetectorVO<?>) vo;
            if (ped.supports(dataTypeId)) {
                list.add(new StringStringPair(definition.getDescriptionKey(), definition.getEventDetectorTypeName()));
            }
        }
    }
    response.addData("options", list);
    return response;
}
Also used : StringStringPair(com.serotonin.db.pair.StringStringPair) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) EventDetectorDefinition(com.serotonin.m2m2.module.EventDetectorDefinition) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 13 with StringStringPair

use of com.serotonin.db.pair.StringStringPair 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;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) 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 14 with StringStringPair

use of com.serotonin.db.pair.StringStringPair in project ma-core-public by infiniteautomation.

the class ModulesDwr method startDownloads.

@DwrPermission(admin = true)
public static String startDownloads(List<StringStringPair> modules, boolean backup, boolean restart) {
    synchronized (UPGRADE_DOWNLOADER_LOCK) {
        if (UPGRADE_DOWNLOADER != null)
            return Common.translate("modules.versionCheck.occupied");
    }
    // Check if the selected modules will result in a version-consistent system.
    try {
        // Create the request
        Map<String, Object> json = new HashMap<>();
        Map<String, String> jsonModules = new HashMap<>();
        json.put("modules", jsonModules);
        Version coreVersion = Common.getVersion();
        jsonModules.put("core", coreVersion.toString());
        for (StringStringPair module : modules) jsonModules.put(module.getKey(), module.getValue());
        StringWriter stringWriter = new StringWriter();
        new JsonWriter(Common.JSON_CONTEXT, stringWriter).writeObject(json);
        String requestData = stringWriter.toString();
        // Send the request
        String baseUrl = Common.envProps.getString("store.url");
        baseUrl += "/servlet/consistencyCheck";
        HttpPost post = new HttpPost(baseUrl);
        post.setEntity(new StringEntity(requestData));
        String responseData = HttpUtils4.getTextContent(Common.getHttpClient(), post, 1);
        // Parse the response
        JsonTypeReader jsonReader = new JsonTypeReader(responseData);
        String result = jsonReader.read().toString();
        if (!"ok".equals(result))
            return result;
    } catch (Exception e) {
        LOG.error("", e);
        return e.getMessage();
    }
    synchronized (UPGRADE_DOWNLOADER_LOCK) {
        // Ensure that 2 downloads cannot start at the same time.
        if (UPGRADE_DOWNLOADER == null) {
            UPGRADE_DOWNLOADER = new UpgradeDownloader(modules, backup, restart, Common.getHttpUser());
            // Clear out common info
            resetUpgradeStatus();
            Common.backgroundProcessing.execute(UPGRADE_DOWNLOADER);
        } else
            return Common.translate("modules.versionCheck.occupied");
    }
    return null;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringStringPair(com.serotonin.db.pair.StringStringPair) HashMap(java.util.HashMap) JsonString(com.serotonin.json.type.JsonString) JsonWriter(com.serotonin.json.JsonWriter) JsonException(com.serotonin.json.JsonException) HttpException(org.apache.http.HttpException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) StringEntity(org.apache.http.entity.StringEntity) StringWriter(java.io.StringWriter) Version(com.github.zafarkhaja.semver.Version) JsonObject(com.serotonin.json.type.JsonObject) JsonTypeReader(com.serotonin.json.type.JsonTypeReader) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 15 with StringStringPair

use of com.serotonin.db.pair.StringStringPair in project ma-core-public by infiniteautomation.

the class TimeZoneUtils method getTimeZoneIdsWithOffset.

public static List<StringStringPair> getTimeZoneIdsWithOffset() {
    List<TzSort> tzs = new ArrayList<TimeZoneUtils.TzSort>();
    String[] ids = TimeZone.getAvailableIDs();
    for (String id : ids) {
        if (id.matches(REGEX)) {
            TzSort t = new TzSort();
            t.offset = TimeZone.getTimeZone(id).getRawOffset();
            t.info = new StringStringPair(id, formatOffset(t.offset) + " " + id);
            tzs.add(t);
        }
    }
    Collections.sort(tzs);
    List<StringStringPair> result = new ArrayList<StringStringPair>();
    for (TzSort t : tzs) result.add(t.info);
    return result;
}
Also used : 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