private static void placeParametersOnBinding( final JSONObject requestObject, final Bindings bindings, final boolean parseTypes) { if (requestObject != null) { JSONObject paramMap = requestObject.optJSONObject(PARAMS); if (paramMap != null) { final Iterator keyIterator = paramMap.keys(); while (keyIterator.hasNext()) { final String key = (String) keyIterator.next(); bindings.put(key, ElementHelper.getTypedPropertyValue(paramMap.opt(key), parseTypes)); } } } }
private Collection<Field> parseFieldsJira5x0(JSONObject issueJson) throws JSONException { final JSONObject names = (this.names == null ? issueJson.optJSONObject(NAMES_SECTION) : this.names); final Map<String, String> namesMap = parseNames(names); final JSONObject types = (this.types == null ? issueJson.optJSONObject(SCHEMA_SECTION) : this.types); final Map<String, String> typesMap = parseSchema(types); final JSONObject json = issueJson.getJSONObject(FIELDS); final ArrayList<Field> res = new ArrayList<Field>(json.length()); @SuppressWarnings("unchecked") final Iterator<String> iterator = json.keys(); while (iterator.hasNext()) { final String key = iterator.next(); try { if (SPECIAL_FIELDS.contains(key)) { continue; } final Object value = json.opt(key); res.add( new Field( key, namesMap.get(key), typesMap.get("key"), value != JSONObject.NULL ? value : null)); } catch (final Exception e) { throw new JSONException("Error while parsing [" + key + "] field: " + e.getMessage()) { @Override public Throwable getCause() { return e; } }; } } return res; }
@Nullable private String getOptionalFieldStringUnisex( boolean shouldUseNestedValueJson, JSONObject json, String attributeName) throws JSONException { final JSONObject fieldsJson = json.getJSONObject(FIELDS); if (shouldUseNestedValueJson) { final JSONObject fieldJson = fieldsJson.optJSONObject(attributeName); if (fieldJson != null) { return JsonParseUtil.getOptionalString(fieldJson, VALUE_ATTR); // pre 5.0 way } else { return null; } } return JsonParseUtil.getOptionalString(fieldsJson, attributeName); }
@Nullable private <T> T getOptionalField( boolean shouldUseNestedValue, JSONObject s, final String fieldId, JsonParser<T> jsonParser) throws JSONException { final JSONObject fieldJson = JsonParseUtil.getNestedOptionalObject(s, FIELDS, fieldId); // for fields like assignee (when unassigned) value attribute may be missing completely if (fieldJson != null) { if (shouldUseNestedValue) { final JSONObject valueJsonObject = fieldJson.optJSONObject(VALUE_ATTR); if (valueJsonObject != null) { return jsonParser.parse(valueJsonObject); } } else { return jsonParser.parse(fieldJson); } } return null; }
TaskAttemptInfo(JSONObject jsonObject) throws JSONException { super(jsonObject); Preconditions.checkArgument( jsonObject .getString(Constants.ENTITY_TYPE) .equalsIgnoreCase(Constants.TEZ_TASK_ATTEMPT_ID)); taskAttemptId = StringInterner.weakIntern(jsonObject.optString(Constants.ENTITY)); // Parse additional Info final JSONObject otherInfoNode = jsonObject.getJSONObject(Constants.OTHER_INFO); startTime = otherInfoNode.optLong(Constants.START_TIME); endTime = otherInfoNode.optLong(Constants.FINISH_TIME); diagnostics = otherInfoNode.optString(Constants.DIAGNOSTICS); creationTime = otherInfoNode.optLong(Constants.CREATION_TIME); creationCausalTA = StringInterner.weakIntern(otherInfoNode.optString(Constants.CREATION_CAUSAL_ATTEMPT)); allocationTime = otherInfoNode.optLong(Constants.ALLOCATION_TIME); containerId = StringInterner.weakIntern(otherInfoNode.optString(Constants.CONTAINER_ID)); String id = otherInfoNode.optString(Constants.NODE_ID); nodeId = StringInterner.weakIntern((id != null) ? (id.split(":")[0]) : ""); logUrl = otherInfoNode.optString(Constants.COMPLETED_LOGS_URL); status = StringInterner.weakIntern(otherInfoNode.optString(Constants.STATUS)); container = new Container(containerId, nodeId); if (otherInfoNode.has(Constants.LAST_DATA_EVENTS)) { List<DataDependencyEvent> eventInfo = Utils.parseDataEventDependencyFromJSON( otherInfoNode.optJSONObject(Constants.LAST_DATA_EVENTS)); long lastTime = 0; for (DataDependencyEvent item : eventInfo) { // check these are in time order Preconditions.checkState(lastTime < item.getTimestamp()); lastTime = item.getTimestamp(); lastDataEvents.add(item); } } terminationCause = StringInterner.weakIntern(otherInfoNode.optString(ATSConstants.TASK_ATTEMPT_ERROR_ENUM)); executionTimeInterval = (endTime > startTime) ? (endTime - startTime) : 0; }