/** Accepts submission from the configuration page. */ public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { checkPermission(Hudson.ADMINISTER); fullName = req.getParameter("fullName"); description = req.getParameter("description"); JSONObject json = req.getSubmittedForm(); List<UserProperty> props = new ArrayList<UserProperty>(); int i = 0; for (UserPropertyDescriptor d : UserProperty.all()) { UserProperty p = getProperty(d.clazz); JSONObject o = json.optJSONObject("userProperty" + (i++)); if (o != null) { if (p != null) { p = p.reconfigure(req, o); } else { p = d.newInstance(req, o); } p.setUser(this); } if (p != null) props.add(p); } this.properties = props; save(); rsp.sendRedirect("."); }
private JSONResult parse(String jsonString) { JSONResult ret = new JSONResult(); JSON json = JSONSerializer.toJSON(jsonString); JSONObject jo = (JSONObject) json; ret.total = jo.getInt("totalCount"); Set<String> names; JSONArray arrResults = jo.optJSONArray("results"); if (arrResults != null) { names = getArray(arrResults); } else { JSONObject results = jo.optJSONObject("results"); if (results != null) { names = Collections.singleton(getSingle(results)); } else { LOGGER.warn("No results found"); names = Collections.EMPTY_SET; } } ret.names = names; ret.returnedCount = names.size(); return ret; }
/** Accepts submission from the configuration page. */ @RequirePOST public synchronized void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { checkPermission(CONFIGURE); description = req.getParameter("description"); keepDependencies = req.getParameter("keepDependencies") != null; try { JSONObject json = req.getSubmittedForm(); setDisplayName(json.optString("displayNameOrNull")); if (req.getParameter("logrotate") != null) logRotator = LogRotator.DESCRIPTOR.newInstance(req, json.getJSONObject("logrotate")); else logRotator = null; DescribableList<JobProperty<?>, JobPropertyDescriptor> t = new DescribableList<JobProperty<?>, JobPropertyDescriptor>(NOOP, getAllProperties()); t.rebuild( req, json.optJSONObject("properties"), JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass())); properties.clear(); for (JobProperty p : t) { p.setOwner(this); properties.add(p); } submit(req, rsp); save(); ItemListener.fireOnUpdated(this); String newName = req.getParameter("name"); final ProjectNamingStrategy namingStrategy = Jenkins.getInstance().getProjectNamingStrategy(); if (newName != null && !newName.equals(name)) { // check this error early to avoid HTTP response splitting. Jenkins.checkGoodName(newName); namingStrategy.checkName(newName); rsp.sendRedirect("rename?newName=" + URLEncoder.encode(newName, "UTF-8")); } else { if (namingStrategy.isForceExistingJobs()) { namingStrategy.checkName(name); } FormApply.success(".").generateResponse(req, rsp, null); } } catch (JSONException e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("Failed to parse form data. Please report this problem as a bug"); pw.println("JSON=" + req.getSubmittedForm()); pw.println(); e.printStackTrace(pw); rsp.setStatus(SC_BAD_REQUEST); sendError(sw.toString(), req, rsp, true); } }
public List<AbstractFacet> extractFacets( final UpdateInfo updateInfo, final ApiData apiData, ObjectType objectType) { List<AbstractFacet> facets = new ArrayList<AbstractFacet>(); JSONObject response = JSONObject.fromObject(apiData.json).getJSONObject("response"); if (response.has("sleepRecord")) { JSONObject sleepRecords = response.optJSONObject("sleepRecord"); extractStatsData(facets, apiData, sleepRecords); } else if (response.has("sleepStats")) { extractStatsData(facets, apiData, response.getJSONObject("sleepStats")); } return facets; }
/** * Parse a JSON input to construct {@link OwershipDescription}. * * @param formData Object with a data * @return OwnershipDescription * @throws hudson.model.Descriptor.FormException Parsing error */ @Nonnull public static OwnershipDescription parseJSON(JSONObject formData) throws Descriptor.FormException { // Read primary owner String primaryOwner = formData.getString("primaryOwner"); // Read coowners Set<String> coOwnersSet = new TreeSet<String>(); if (formData.has("coOwners")) { JSONObject coOwners = formData.optJSONObject("coOwners"); if (coOwners == null) { for (Object obj : formData.getJSONArray("coOwners")) { addUser(coOwnersSet, (JSONObject) obj); } } else { addUser(coOwnersSet, coOwners); } } return new OwnershipDescription(true, primaryOwner, coOwnersSet); }