/** * Creates an instance of {@link RepositoryBrowser} from a form submission. * * @since 1.227 */ public static <T extends RepositoryBrowser> T createInstance(Class<T> type, StaplerRequest req, JSONObject parent, String fieldName) throws FormException { JSONObject o = (JSONObject)parent.get(fieldName); if(o==null) return null; return req.bindJSON(type,o); } }
/** * Accept anything as value for the {@link #REDACT_KEY} but only process the first level of an array and the string value. */ private Set<String> retrieveRedactedKeys(JSONObject jsonObject) { Set<String> redactedKeySet = new HashSet<>(); if (jsonObject.has(REDACT_KEY)) { Object value = jsonObject.get(REDACT_KEY); if (value instanceof JSONArray) { for (Object o : jsonObject.getJSONArray(REDACT_KEY)) { if (o instanceof String) { redactedKeySet.add((String) o); } else { // array, object, null, number, boolean LOGGER.log(Level.WARNING, "Unsupported type " + o.getClass().getName() + " for " + REDACT_KEY + ", please use either a single String value or an Array"); } } } else if (value instanceof String) { redactedKeySet.add((String) value); } else { // object, null, number, boolean LOGGER.log(Level.WARNING, "Unsupported type " + value.getClass().getName() + " for " + REDACT_KEY + ", please use either a single String value or an Array"); } } return redactedKeySet; }
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { connections = req.bindJSONToList(GitLabConnection.class, json.get("connections")); useAuthenticatedEndpoint = json.getBoolean("useAuthenticatedEndpoint"); refreshConnectionMap(); save(); return super.configure(req, json); }
/** * Accepts submission from the configuration page. */ @RequirePOST public synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { JSONObject src = req.getSubmittedForm(); String newName = src.getString("name"), redirect = "."; XmlFile oldFile = null; if(!name.equals(newName)) { Jenkins.checkGoodName(newName); oldFile = getConfigFile(); // rename getParent().logRecorders.remove(name); this.name = newName; getParent().logRecorders.put(name,this); redirect = "../" + Util.rawEncode(newName) + '/'; } List<Target> newTargets = req.bindJSONToList(Target.class, src.get("targets")); for (Target t : newTargets) t.enable(); targets.replaceBy(newTargets); save(); if (oldFile!=null) oldFile.delete(); rsp.sendRedirect2(redirect); }
/** * Retrieves the property of the given object and returns it as a list of {@link JSONObject}. * * <p> * If the value doesn't exist, this method returns an empty list. If the value is * a {@link JSONObject}, this method will return a singleton list. If it's a {@link JSONArray}, * the contents will be returned as a list. * * <p> * Because of the way structured form submission work, this is convenient way of * handling repeated multi-value entries. * * @since 1.233 */ public static List<JSONObject> toList(JSONObject parent, String propertyName) { Object v = parent.get(propertyName); if(v==null) return Collections.emptyList(); if(v instanceof JSONObject) return Collections.singletonList((JSONObject)v); if(v instanceof JSONArray) return (List)(JSONArray)v; throw new IllegalArgumentException(); } }
JSONArray a = JSONArray.fromObject(formData.get("parameter"));
Object protocols = json.get("agentProtocol"); if (protocols instanceof JSONArray) { for (int i = 0; i < ((JSONArray) protocols).size(); i++) {
/** * Used to build {@link Describable} instance list from {@code <f:hetero-list>} tag. * * @param req * Request that represents the form submission. * @param formData * Structured form data that represents the contains data for the list of describables. * @param key * The JSON property name for 'formData' that represents the data for the list of describables. * @param descriptors * List of descriptors to create instances from. * @return * Can be empty but never null. */ public static <T extends Describable<T>> List<T> newInstancesFromHeteroList(StaplerRequest req, JSONObject formData, String key, Collection<? extends Descriptor<T>> descriptors) throws FormException { return newInstancesFromHeteroList(req,formData.get(key),descriptors); }
@Override @SuppressWarnings("unchecked") // cast to T[] public boolean configure(StaplerRequest req, JSONObject json) throws FormException { setInstallations(req.bindJSONToList(clazz, json.get("tool")).toArray((T[]) Array.newInstance(clazz, 0))); return true; }
/** * Allow user to rename tokens */ @Override public UserProperty reconfigure(StaplerRequest req, @CheckForNull JSONObject form) throws FormException { if(form == null){ return this; } Object tokenStoreData = form.get("tokenStore"); Map<String, JSONObject> tokenStoreTypedData = convertToTokenMap(tokenStoreData); this.tokenStore.reconfigure(tokenStoreTypedData); return this; }
@SuppressWarnings("unchecked") private JSONObject copyAndSanitizeObject(JSONObject jsonObject) { Set<String> redactedKeySet = retrieveRedactedKeys(jsonObject); JSONObject result = new JSONObject(); jsonObject.keySet().forEach(keyObject -> { String key = keyObject.toString(); if (redactedKeySet.contains(key)) { result.accumulate(key, REDACT_VALUE); } else { Object value = jsonObject.get(keyObject); result.accumulate(key, copyAndSanitize(value)); } }); return result; }
/** * Retrieve the specified attribute as a generic object. * * @param name The name of the attribute to retrieve. * @return The value of the attribute. */ public Object getAttribute(String name) { return attributes.get(name); }
/** * Creates an instance of {@link RepositoryBrowser} from a form submission. * * @since 1.227 */ public static <T extends RepositoryBrowser> T createInstance(Class<T> type, StaplerRequest req, JSONObject parent, String fieldName) throws FormException { JSONObject o = (JSONObject)parent.get(fieldName); if(o==null) return null; return req.bindJSON(type,o); } }
/** * Deserialize the json to extract standard attributes and keep a reference of * other attributes. * * @param json The JSON object to read. */ @Override void deserialize(JSONObject json) throws JiraException { super.deserialize(json); this.description = Field.getString(json.get("description")); this.subTask = Field.getBoolean(json.get("subtask")); }
@Override @SuppressWarnings("unchecked") // cast to T[] public boolean configure(StaplerRequest req, JSONObject json) throws FormException { setInstallations(req.bindJSONToList(clazz, json.get("tool")).toArray((T[]) Array.newInstance(clazz, 0))); return true; }
/** * Deserialize the json to extract standard attributes and keep a reference of * other attributes. * * @param json The JSON object to read. */ @Override void deserialize(JSONObject json) throws JiraException { super.deserialize(json); this.description = Field.getString(json.get("description")); }
/** * Deserialize the json to extract standard attributes and keep a reference of * other attributes. * * @param json The JSON object to read. */ @Override void deserialize(JSONObject json) throws JiraException { super.deserialize(json); this.key = Field.getString(json.get("key")); }
@Override protected void deserialize(JSONObject json) throws JiraException { super.deserialize(json); type = Field.getString(json.get("type")); }
@Test public void testFetchDiffWithValidResponse() throws Exception { JSONObject realResponse = TestUtils.getJSONFromFile(getClass(), "validFetchDiffResponse"); mockConduitResponse(differentialClient, realResponse); JSONObject response = differentialClient.fetchDiff(); assertEquals("world", response.get("hello")); }