Search in sources :

Example 71 with JSONObject

use of net.sf.json.JSONObject in project topcom-cloud by 545314690.

the class WechatUtil method main.

public static void main(String[] args) {
    JSONObject result1 = new JSONObject();
    result1.put("value", "北京发生13级地震目前无人生还");
    result1.put("color", "#173177");
    JSONObject result2 = new JSONObject();
    result2.put("value", "上海发生19级地震目前无人生还");
    result2.put("color", "#666666");
    JSONObject result3 = new JSONObject();
    result1.put("value", "西安发生27级地震目前无人生还");
    result1.put("color", "#888888");
    JSONObject name = new JSONObject();
    name.put("value", "boos");
    name.put("color", "#888888");
    JSONObject num = new JSONObject();
    num.put("value", "11231");
    num.put("color", "#111111");
    JSONObject data = new JSONObject();
    data.put("result1", result1);
    data.put("result2", result2);
    data.put("result", result3);
    data.put("name", name);
    data.put("num", num);
    JSONObject param = new JSONObject();
    param.put("data", data);
    param.put("touser", "ozC850c9D3CCDlkd017cEP62xYWw");
    param.put("template_id", "N_sOGso5v-NU7esOVO2iU9lGsvWooiz7MbJ4IQmHE5w");
    param.put("url", "http://tcbds.xicp.io:8090/yuqing/module/login.html");
    WechatUtil wechatUtil = new WechatUtil();
    wechatUtil.sendTemplate(param);
    List<String> userList = wechatUtil.getUserList();
    SubscriptionFollower subscriptionFollower = wechatUtil.getUserInfo(userList.get(0));
    System.out.println(subscriptionFollower);
}
Also used : SubscriptionFollower(com.topcom.cms.yuqing.domain.SubscriptionFollower) JSONObject(net.sf.json.JSONObject)

Example 72 with JSONObject

use of net.sf.json.JSONObject in project topcom-cloud by 545314690.

the class WechatUtil method getUserList.

public List<String> getUserList(String openid) {
    String accessToken = getAccessToken();
    Map<String, String> paramMap = new HashMap<>();
    paramMap.put(ACCESS_TOKEN, accessToken);
    paramMap.put(NEXT_OPENID, openid);
    String result = HttpUtil.doGet(WEB_CHAT_USER_GETLIST_URL, paramMap);
    JSONObject userListJson = JSONObject.fromObject(result);
    JSONObject dataJson = userListJson.getJSONObject("data");
    if (dataJson.size() == 0) {
        return null;
    } else
        return dataJson.getJSONArray("openid");
}
Also used : JSONObject(net.sf.json.JSONObject) HashMap(java.util.HashMap)

Example 73 with JSONObject

use of net.sf.json.JSONObject in project support-core-plugin by jenkinsci.

the class SupportAction method doGenerateAllBundles.

@RequirePOST
public void doGenerateAllBundles(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
    final Jenkins instance = Jenkins.getInstance();
    instance.getAuthorizationStrategy().getACL(instance).checkPermission(CREATE_BUNDLE);
    JSONObject json = req.getSubmittedForm();
    if (!json.has("components")) {
        rsp.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }
    logger.fine("Parsing request...");
    Set<String> remove = new HashSet<String>();
    for (Selection s : req.bindJSONToList(Selection.class, json.get("components"))) {
        if (!s.isSelected()) {
            logger.log(Level.FINER, "Excluding ''{0}'' from list of components to include", s.getName());
            remove.add(s.getName());
        }
    }
    logger.fine("Selecting components...");
    final List<Component> components = new ArrayList<Component>(getComponents());
    for (Iterator<Component> iterator = components.iterator(); iterator.hasNext(); ) {
        Component c = iterator.next();
        if (remove.contains(c.getId()) || !c.isEnabled()) {
            iterator.remove();
        }
    }
    final SupportPlugin supportPlugin = SupportPlugin.getInstance();
    if (supportPlugin != null) {
        supportPlugin.setExcludedComponents(remove);
    }
    logger.fine("Preparing response...");
    rsp.setContentType("application/zip");
    rsp.addHeader("Content-Disposition", "inline; filename=" + SupportPlugin.getBundleFileName() + ";");
    final ServletOutputStream servletOutputStream = rsp.getOutputStream();
    try {
        SupportPlugin.setRequesterAuthentication(Jenkins.getAuthentication());
        try {
            SecurityContext old = ACL.impersonate(ACL.SYSTEM);
            try {
                SupportPlugin.writeBundle(servletOutputStream, components);
            } catch (IOException e) {
                logger.log(Level.FINE, e.getMessage(), e);
            } finally {
                SecurityContextHolder.setContext(old);
            }
        } finally {
            SupportPlugin.clearRequesterAuthentication();
        }
    } finally {
        logger.fine("Response completed");
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Jenkins(jenkins.model.Jenkins) JSONObject(net.sf.json.JSONObject) SecurityContext(org.acegisecurity.context.SecurityContext) Component(com.cloudbees.jenkins.support.api.Component) HashSet(java.util.HashSet) RequirePOST(org.kohsuke.stapler.interceptor.RequirePOST)

Example 74 with JSONObject

use of net.sf.json.JSONObject in project support-core-plugin by jenkinsci.

the class SupportAction method doDeleteBundles.

@RequirePOST
public void doDeleteBundles(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
    JSONObject json = req.getSubmittedForm();
    if (!json.has("bundles")) {
        rsp.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }
    Set<String> bundlesToDelete = new HashSet<>();
    for (Selection s : req.bindJSONToList(Selection.class, json.get("bundles"))) {
        if (s.isSelected()) {
            bundlesToDelete.add(s.getName());
        }
    }
    File rootDirectory = SupportPlugin.getRootDirectory();
    for (String bundleToDelete : bundlesToDelete) {
        File fileToDelete = new File(rootDirectory, bundleToDelete);
        logger.fine("Trying to delete bundle file " + fileToDelete.getAbsolutePath());
        try {
            if (fileToDelete.delete()) {
                logger.info("Bundle " + fileToDelete.getAbsolutePath() + " successfully delete.");
            } else {
                logger.log(Level.SEVERE, "Unable to delete file " + fileToDelete.getAbsolutePath());
            }
        } catch (RuntimeException e) {
            logger.log(Level.SEVERE, "Unable to delete file " + fileToDelete.getAbsolutePath(), e);
        }
    }
    rsp.sendRedirect("");
}
Also used : JSONObject(net.sf.json.JSONObject) File(java.io.File) HashSet(java.util.HashSet) RequirePOST(org.kohsuke.stapler.interceptor.RequirePOST)

Example 75 with JSONObject

use of net.sf.json.JSONObject in project telegram-notifications-plugin by jenkinsci.

the class UserApprover method approve.

public ApprovalType approve(JSONObject formData) {
    ApprovalType approvalType;
    JSONObject approval = (JSONObject) formData.get("approval");
    if (approval == null) {
        approvalType = ApprovalType.ALL;
    } else {
        String value = approval.getString("value");
        approvalType = ApprovalType.valueOf(value);
    }
    JSONArray loaded;
    if (approval == null) {
        loaded = null;
    } else {
        try {
            // Only one user is subscriber
            JSONObject users = approval.getJSONObject("users");
            loaded = new JSONArray();
            loaded.add(users);
        } catch (JSONException e) {
            // More than one subscribers
            loaded = approval.getJSONArray("users");
        }
    }
    Map<User, Boolean> userBooleanMap = new HashMap<>();
    switch(approvalType) {
        case MANUAL:
            userBooleanMap = collectUsersToApprove(loaded);
            break;
        case ALL:
            userBooleanMap = users.stream().collect(Collectors.toMap(Function.identity(), e -> true));
            break;
    }
    userBooleanMap.forEach(this::updateUserApproval);
    return approvalType;
}
Also used : JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray) JSONException(net.sf.json.JSONException)

Aggregations

JSONObject (net.sf.json.JSONObject)493 Test (org.junit.Test)99 JSONArray (net.sf.json.JSONArray)94 IOException (java.io.IOException)49 HashMap (java.util.HashMap)48 ArrayList (java.util.ArrayList)36 JSON (net.sf.json.JSON)26 PrintWriter (java.io.PrintWriter)25 Map (java.util.Map)23 File (java.io.File)21 InputStream (java.io.InputStream)18 URISyntaxException (java.net.URISyntaxException)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 JsonConfig (net.sf.json.JsonConfig)14 FreeStyleBuild (hudson.model.FreeStyleBuild)13 URI (java.net.URI)13 URL (java.net.URL)13 JSONException (net.sf.json.JSONException)13 Context (org.zaproxy.zap.model.Context)12 Transactional (org.springframework.transaction.annotation.Transactional)11