当前位置: 首页>>代码示例>>Java>>正文


Java JSONUtils类代码示例

本文整理汇总了Java中com.tw.go.plugin.util.JSONUtils的典型用法代码示例。如果您正苦于以下问题:Java JSONUtils类的具体用法?Java JSONUtils怎么用?Java JSONUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JSONUtils类属于com.tw.go.plugin.util包,在下文中一共展示了JSONUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: renderJSON

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
private GoPluginApiResponse renderJSON(final int responseCode, final Map<String, String> responseHeaders, Object response) {
    final String json = response == null ? null : JSONUtils.toJSON(response);
    return new GoPluginApiResponse() {
        @Override
        public int responseCode() {
            return responseCode;
        }

        @Override
        public Map<String, String> responseHeaders() {
            return responseHeaders;
        }

        @Override
        public String responseBody() {
            return json;
        }
    };
}
 
开发者ID:gocd-contrib,项目名称:gocd-oauth-login,代码行数:20,代码来源:OAuthLoginPlugin.java

示例2: handleSearchUserRequest

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
private GoPluginApiResponse handleSearchUserRequest(GoPluginApiRequest goPluginApiRequest) {
    Map<String, String> requestBodyMap = (Map<String, String>) JSONUtils.fromJSON(goPluginApiRequest.requestBody());
    String searchTerm = requestBodyMap.get("search-term");
    PluginSettings pluginSettings = getPluginSettings();
    List<User> users = provider.searchUser(pluginSettings, searchTerm);
    if (users == null || users.isEmpty()) {
        return renderJSON(SUCCESS_RESPONSE_CODE, null);
    } else {
        List<Map> searchResults = new ArrayList<Map>();
        for (User user : users) {
            searchResults.add(getUserMap(user));
        }
        return renderJSON(SUCCESS_RESPONSE_CODE, searchResults);
    }
}
 
开发者ID:gocd-contrib,项目名称:gocd-oauth-login,代码行数:16,代码来源:OAuthLoginPlugin.java

示例3: getPluginSettings

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
public PluginSettings getPluginSettings() {
    Map<String, Object> requestMap = new HashMap<String, Object>();
    requestMap.put("plugin-id", provider.getPluginId());
    GoApiResponse response = goApplicationAccessor.submit(createGoApiRequest(GET_PLUGIN_SETTINGS, JSONUtils.toJSON(requestMap)));
    if (response.responseBody() == null || response.responseBody().trim().isEmpty()) {
        throw new RuntimeException("plugin is not configured. please provide plugin settings.");
    }
    return provider.pluginSettings((Map<String, String>) JSONUtils.fromJSON(response.responseBody()));
}
 
开发者ID:gocd-contrib,项目名称:gocd-oauth-login,代码行数:10,代码来源:OAuthLoginPlugin.java

示例4: store

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
private void  store(SocialAuthManager socialAuthManager) {
    Map<String, Object> requestMap = new HashMap<String, Object>();
    requestMap.put("plugin-id", provider.getPluginId());
    Map<String, Object> sessionData = new HashMap<String, Object>();
    String socialAuthManagerStr = serializeObject(socialAuthManager);
    sessionData.put("social-auth-manager", socialAuthManagerStr);
    requestMap.put("session-data", sessionData);
    GoApiRequest goApiRequest = createGoApiRequest(GO_REQUEST_SESSION_PUT, JSONUtils.toJSON(requestMap));
    GoApiResponse response = goApplicationAccessor.submit(goApiRequest);
    // handle error
}
 
开发者ID:gocd-contrib,项目名称:gocd-oauth-login,代码行数:12,代码来源:OAuthLoginPlugin.java

示例5: read

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
private SocialAuthManager read() {
    Map<String, Object> requestMap = new HashMap<String, Object>();
    requestMap.put("plugin-id", provider.getPluginId());
    GoApiRequest goApiRequest = createGoApiRequest(GO_REQUEST_SESSION_GET, JSONUtils.toJSON(requestMap));
    GoApiResponse response = goApplicationAccessor.submit(goApiRequest);
    // handle error
    String responseBody = response.responseBody();
    Map<String, String> sessionData = (Map<String, String>) JSONUtils.fromJSON(responseBody);
    String socialAuthManagerStr = sessionData.get("social-auth-manager");
    return deserializeObject(socialAuthManagerStr);
}
 
开发者ID:gocd-contrib,项目名称:gocd-oauth-login,代码行数:12,代码来源:OAuthLoginPlugin.java

示例6: delete

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
private void delete() {
    Map<String, Object> requestMap = new HashMap<String, Object>();
    requestMap.put("plugin-id", provider.getPluginId());
    GoApiRequest goApiRequest = createGoApiRequest(GO_REQUEST_SESSION_REMOVE, JSONUtils.toJSON(requestMap));
    GoApiResponse response = goApplicationAccessor.submit(goApiRequest);
    // handle error
}
 
开发者ID:gocd-contrib,项目名称:gocd-oauth-login,代码行数:8,代码来源:OAuthLoginPlugin.java

示例7: authenticateUser

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
private void authenticateUser(User user) {
    final Map<String, Object> userMap = new HashMap<String, Object>();
    userMap.put("user", getUserMap(user));
    GoApiRequest authenticateUserRequest = createGoApiRequest(GO_REQUEST_AUTHENTICATE_USER, JSONUtils.toJSON(userMap));
    GoApiResponse authenticateUserResponse = goApplicationAccessor.submit(authenticateUserRequest);
    // handle error
}
 
开发者ID:gocd-contrib,项目名称:gocd-oauth-login,代码行数:8,代码来源:OAuthLoginPlugin.java

示例8: searchUser

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
@Override
public List<User> searchUser(GitLabPluginSettings pluginSettings, String searchTerm) {
    HttpUrl searchBaseUrl = HttpUrl.parse(fullUrl(pluginSettings, "/api/v3/users"));

    HttpUrl url = new HttpUrl.Builder()
            .scheme(searchBaseUrl.scheme())
            .host(searchBaseUrl.host())
            .addPathSegments(searchBaseUrl.encodedPath())
            .addQueryParameter("private_token", pluginSettings.getOauthToken())
            .addQueryParameter("search", searchTerm)
            .build();

    Request request = new Request.Builder().url(url.url()).build();

    try {
        Response response = client.newCall(request).execute();
        List<User> users = new ArrayList<>();

        for (Map<String, String> userParams : (List<Map<String, String>>) JSONUtils.fromJSON(response.body().string())) {
            users.add(new User(userParams.get("email"), userParams.get("name"), userParams.get("email")));
        }
        return users;

    } catch (IOException e) {
        LOGGER.warn("Error occurred while trying to perform user search", e);
        return new ArrayList<>();
    }
}
 
开发者ID:gocd-contrib,项目名称:gocd-oauth-login,代码行数:29,代码来源:GitLabProvider.java

示例9: getPluginSettings

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
public PluginSettings getPluginSettings() {
    Map<String, Object> requestMap = new HashMap<String, Object>();
    requestMap.put("plugin-id", PLUGIN_ID);
    GoApiResponse response = goApplicationAccessor.submit(createGoApiRequest(GET_PLUGIN_SETTINGS, JSONUtils.toJSON(requestMap)));
    if (response.responseBody() == null || response.responseBody().trim().isEmpty()) {
        throw new RuntimeException("plugin is not configured. please provide plugin settings.");
    }
    Map<String, String> responseBodyMap = (Map<String, String>) JSONUtils.fromJSON(response.responseBody());
    return new PluginSettings(responseBodyMap.get(PLUGIN_SETTINGS_SMTP_HOST), Integer.parseInt(responseBodyMap.get(PLUGIN_SETTINGS_SMTP_PORT)),
            Boolean.parseBoolean(responseBodyMap.get(PLUGIN_SETTINGS_IS_TLS)), responseBodyMap.get(PLUGIN_SETTINGS_SENDER_EMAIL_ID),
            responseBodyMap.get(PLUGIN_SETTINGS_SMTP_USERNAME),
            responseBodyMap.get(PLUGIN_SETTINGS_SENDER_PASSWORD), responseBodyMap.get(PLUGIN_SETTINGS_RECEIVER_EMAIL_ID),
            responseBodyMap.get(PLUGIN_SETTINGS_FILTER));
}
 
开发者ID:gocd-contrib,项目名称:email-notifier,代码行数:15,代码来源:EmailNotificationPluginImpl.java

示例10: testSettingsRequest

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
private static GoApiRequest testSettingsRequest() {

        final Map<String, Object> requestMap = new HashMap<String, Object>();
        requestMap.put("plugin-id", "email.notifier");

        final String responseBody = JSONUtils.toJSON(requestMap);

        return new GoApiRequest() {
            @Override
            public String api() {
                return "go.processor.plugin-settings.get";
            }

            @Override
            public String apiVersion() {
                return "1.0";
            }

            @Override
            public GoPluginIdentifier pluginIdentifier() {
                return new GoPluginIdentifier("notification", Collections.singletonList("1.0"));
            }

            @Override
            public Map<String, String> requestParameters() {
                return null;
            }

            @Override
            public Map<String, String> requestHeaders() {
                return null;
            }

            @Override
            public String requestBody() {
                return responseBody;
            }
        };
    }
 
开发者ID:gocd-contrib,项目名称:email-notifier,代码行数:40,代码来源:EmailNotificationPluginImplUnitTest.java

示例11: updateStatus

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
@Override
public void updateStatus(String url, PluginSettings pluginSettings, String branch, String revision, String pipelineInstance,
                                 String result, String trackbackURL) throws Exception {
    GerritPluginSettings settings = (GerritPluginSettings) pluginSettings;

    String endPointToUse = settings.getEndPoint();
    String usernameToUse = settings.getUsername();
    String passwordToUse = settings.getPassword();
    String codeReviewLabel = settings.getReviewLabel();

    if (StringUtils.isEmpty(endPointToUse)) {
        endPointToUse = System.getProperty("go.plugin.build.status.gerrit.endpoint");
    }
    if (StringUtils.isEmpty(usernameToUse)) {
        usernameToUse = System.getProperty("go.plugin.build.status.gerrit.username");
    }
    if (StringUtils.isEmpty(passwordToUse)) {
        passwordToUse = System.getProperty("go.plugin.build.status.gerrit.password");
    }
    if (StringUtils.isEmpty(codeReviewLabel)) {
        codeReviewLabel = System.getProperty("go.plugin.build.status.gerrit.codeReviewLabel");
    }

    String commitDetailsURL = String.format("%s/a/changes/?q=commit:%s", endPointToUse, revision);
    String commitDetailsResponse = httpClient.getRequest(commitDetailsURL, AuthenticationType.DIGEST, usernameToUse, passwordToUse);
    CommitDetails commitDetails = new ResponseParser().parseCommitDetails(commitDetailsResponse);

    Map<String, Object> request = new HashMap<String, Object>();
    request.put("message", String.format("%s: %s", pipelineInstance, trackbackURL));
    Map<String, Object> labels = new HashMap<String, Object>();
    request.put("labels", labels);
    labels.put(codeReviewLabel, getCodeReviewValue(result));
    String updateStatusURL = String.format("%s/a/changes/%s/revisions/%s/review", endPointToUse, commitDetails.getId(), revision);
    httpClient.postRequest(updateStatusURL, AuthenticationType.DIGEST, usernameToUse, passwordToUse, JSONUtils.toJSON(request));
}
 
开发者ID:gocd-contrib,项目名称:gocd-build-status-notifier,代码行数:36,代码来源:GerritProvider.java

示例12: getPluginSettings

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
public PluginSettings getPluginSettings() {
    Map<String, Object> requestMap = new HashMap<String, Object>();
    requestMap.put("plugin-id", provider.pluginId());
    GoApiResponse response = goApplicationAccessor.submit(createGoApiRequest(GET_PLUGIN_SETTINGS, JSONUtils.toJSON(requestMap)));
    Map<String, String> responseBodyMap = response.responseBody() == null ? new HashMap<String, String>() : (Map<String, String>) JSONUtils.fromJSON(response.responseBody());
    return provider.pluginSettings(responseBodyMap);
}
 
开发者ID:gocd-contrib,项目名称:gocd-build-status-notifier,代码行数:8,代码来源:BuildStatusNotifierPlugin.java

示例13: setUp

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
@Before
public void setUp() {
    initMocks(this);

    plugin = new BuildStatusNotifierPlugin();

    DefaultGoApiResponse pluginSettingsResponse = new DefaultGoApiResponse(200);
    pluginSettingsResponse.setResponseBody(JSONUtils.toJSON(new HashMap<String, String>()));
    when(goApplicationAccessor.submit(any(GoApiRequest.class))).thenReturn(pluginSettingsResponse);
    when(provider.pluginId()).thenReturn(GitHubProvider.PLUGIN_ID);
    when(provider.pollerPluginId()).thenReturn(GitHubProvider.GITHUB_PR_POLLER_PLUGIN_ID);

    plugin.initializeGoApplicationAccessor(goApplicationAccessor);
    plugin.setProvider(provider);
}
 
开发者ID:gocd-contrib,项目名称:gocd-build-status-notifier,代码行数:16,代码来源:BuildStatusNotifierPluginTest.java

示例14: handleStageNotification

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
private GoPluginApiResponse handleStageNotification(GoPluginApiRequest goPluginApiRequest) {
    Map<String, Object> dataMap = (Map<String, Object>) JSONUtils.fromJSON(goPluginApiRequest.requestBody());

    int responseCode = SUCCESS_RESPONSE_CODE;
    Map<String, Object> response = new HashMap<String, Object>();
    List<String> messages = new ArrayList<String>();
    try {
        Map<String, Object> pipelineMap = (Map<String, Object>) dataMap.get("pipeline");
        Map<String, Object> stageMap = (Map<String, Object>) pipelineMap.get("stage");


        String pipelineName = (String) pipelineMap.get("name");
        String stageName = (String) stageMap.get("name");
        String stageState = (String) stageMap.get("state");

        String subject = String.format("%s/%s is/has %s", pipelineName, stageName, stageState);
        String body = String.format("State: %s\nResult: %s\nCreate Time: %s\nLast Transition Time: %s", stageState, stageMap.get("result"), stageMap.get("create-time"), stageMap.get("last-transition-time"));

        PluginSettings pluginSettings = getPluginSettings();


        boolean matchesFilter = false;

        List<Filter> filterList = pluginSettings.getFilterList();

        if(filterList.isEmpty()) {
            matchesFilter = true;
        } else {
            for(Filter filter : filterList) {
                if(filter.matches(pipelineName, stageName, stageState)) {
                    matchesFilter = true;
                }
            }
        }

        if(matchesFilter) {
            LOGGER.info("Sending Email for " + subject);

            String receiverEmailIdString = pluginSettings.getReceiverEmailId();

            String[] receiverEmailIds = new String[]{receiverEmailIdString};

            if (receiverEmailIdString.contains(",")) {
                receiverEmailIds = receiverEmailIdString.split(",");
            }

            for (String receiverEmailId : receiverEmailIds) {
                SMTPSettings settings = new SMTPSettings(pluginSettings.getSmtpHost(), pluginSettings.getSmtpPort(), pluginSettings.isTls(), pluginSettings.getSenderEmailId(), pluginSettings.getSmtpUsername(), pluginSettings.getSenderPassword());
                new SMTPMailSender(settings).send(subject, body, receiverEmailId);
            }

            LOGGER.info("Successfully delivered an email.");
        } else {
            LOGGER.info("Skipped email as no filter matched this pipeline/stage/state");
        }

        response.put("status", "success");
    } catch (Exception e) {
        LOGGER.warn("Error occurred while trying to deliver an email.", e);

        responseCode = INTERNAL_ERROR_RESPONSE_CODE;
        response.put("status", "failure");
        if (!isEmpty(e.getMessage())) {
            messages.add(e.getMessage());
        }
    }

    if (!messages.isEmpty()) {
        response.put("messages", messages);
    }
    return renderJSON(responseCode, response);
}
 
开发者ID:gocd-contrib,项目名称:email-notifier,代码行数:73,代码来源:EmailNotificationPluginImpl.java

示例15: handleValidatePluginSettingsConfiguration

import com.tw.go.plugin.util.JSONUtils; //导入依赖的package包/类
private GoPluginApiResponse handleValidatePluginSettingsConfiguration(GoPluginApiRequest goPluginApiRequest) {
    Map<String, Object> fields = (Map<String, Object>) JSONUtils.fromJSON(goPluginApiRequest.requestBody());
    List<Map<String, Object>> response = provider.validateConfig((Map<String, Object>) fields.get("plugin-settings"));
    return renderJSON(SUCCESS_RESPONSE_CODE, response);
}
 
开发者ID:gocd-contrib,项目名称:gocd-build-status-notifier,代码行数:6,代码来源:BuildStatusNotifierPlugin.java


注:本文中的com.tw.go.plugin.util.JSONUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。