/** * This method returns the first field with specified name. * Names of fields in JIRA do not need to be unique. Therefore this method does not guarantee that you will get what you really want. * It's added just for convenience. For identify fields you should use id rather than name. * * @param name name of the field. * @return the first field matching selected name or <code>null</code> when no field with given name exists for this issue */ @Nullable public IssueField getFieldByName(String name) { for (IssueField issueField : issueFields) { if (issueField.getName().equals(name)) { return issueField; } } return null; }
@Override public String toString() { return Objects.toStringHelper(this). add("id", id). add("name", name). add("type", type). add("value", getValue()). toString(); }
private void updateStreamStatus(Issue issue, com.atlassian.jira.rest.client.api.domain.Issue jiraIssue, Map<String, Version> versionsMap, IssueInputBuilder inputBuilder) throws NotFoundException { String customField = JSON_CUSTOM_FIELD + TARGET_RELEASE; IssueField issueField = jiraIssue.getField(customField); if (issueField == null || (issueField.getType() == null && issueField.getValue() == null)) { String msg = String.format("Unable to set a stream status for issue %1$s as %2$s projects do not utilise field: %3$s", jiraIssue.getKey(), jiraIssue.getProject().getName(), customField); Utils.logWarnMessage(LOG, msg); return; } for (Map.Entry<String, FlagStatus> entry : issue.getStreamStatus().entrySet()) { if (entry.getValue() != FlagStatus.ACCEPTED) { String streamName = entry.getKey(); Version version = versionsMap.get(streamName); if (version != null) { inputBuilder.setFieldInput(new FieldInput(customField, ComplexIssueInputFieldValue.with("value", version.getId()))); } else { throw new NotFoundException("No Stream exists for this project with the name : " + streamName); } } } }
/** * @param id identifier of the field (inaccessible by concrete getter method) * @return field with given id, or <code>null</code> when no field with given id exists for this issue */ @Nullable public IssueField getField(String id) { for (IssueField issueField : issueFields) { if (issueField.getId().equals(id)) { return issueField; } } return null; }
@SuppressWarnings("unchecked") public IssueField parse(JSONObject jsonObject, String id) throws JSONException { String type = jsonObject.getString("type"); final String name = jsonObject.getString("name"); final Object valueObject = jsonObject.opt(VALUE_ATTRIBUTE); final Object value; // @todo ugly hack until https://jdog.atlassian.com/browse/JRADEV-3220 is fixed if ("comment".equals(name)) { type = "com.atlassian.jira.Comment"; } if (valueObject == null) { value = null; } else { final JsonObjectParser valueParser = registeredValueParsers.get(type); if (valueParser != null) { value = valueParser.parse(jsonObject); } else { value = valueObject.toString(); } } return new IssueField(id, name, type, value); }
@Override public String toString() { return MoreObjects.toStringHelper(this). add("id", id). add("name", name). add("type", type). add("value", getValue()). toString(); }
/** * @param id identifier of the field (inaccessible by concrete getter method) * @return field with given id, or <code>null</code> when no field with given id exists for this issue */ @Nullable public IssueField getField(String id) { for (IssueField issueField : issueFields) { if (issueField.getId().equals(id)) { return issueField; } } return null; }
@SuppressWarnings("unchecked") public IssueField parse(JSONObject jsonObject, String id) throws JSONException { String type = jsonObject.getString("type"); final String name = jsonObject.getString("name"); final Object valueObject = jsonObject.opt(VALUE_ATTRIBUTE); final Object value; // @todo ugly hack until https://jdog.atlassian.com/browse/JRADEV-3220 is fixed if ("comment".equals(name)) { type = "com.atlassian.jira.Comment"; } if (valueObject == null) { value = null; } else { final JsonObjectParser valueParser = registeredValueParsers.get(type); if (valueParser != null) { value = valueParser.parse(jsonObject); } else { value = valueObject.toString(); } } return new IssueField(id, name, type, value); }
private void setIssueStream(Issue issue, com.atlassian.jira.rest.client.api.domain.Issue jiraIssue) { try { IssueField jsonField = jiraIssue.getField(JSON_CUSTOM_FIELD + TARGET_RELEASE); if (jsonField == null || jsonField.getValue() == null) { return; } JSONObject value = (JSONObject) jsonField.getValue(); Map<String, FlagStatus> streamStatus; streamStatus = Collections.singletonMap(value.getString("name"), FlagStatus.ACCEPTED); issue.setStreamStatus(streamStatus); } catch (JSONException e) { LOG.error("error setting the stream in " + jiraIssue.getKey(), e); } }
private Collection<IssueField> parseFields(final JSONObject issueJson) throws JSONException { final JSONObject names = (providedNames != null) ? providedNames : issueJson.optJSONObject(NAMES_SECTION); final Map<String, String> namesMap = parseNames(names); final JSONObject schema = (providedSchema != null) ? providedSchema : issueJson.optJSONObject(SCHEMA_SECTION); final Map<String, String> typesMap = parseSchema(schema); final JSONObject json = issueJson.getJSONObject(FIELDS); final ArrayList<IssueField> res = new ArrayList<IssueField>(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; } // TODO: JRJC-122 // we should use fieldParser here (some new version as the old one probably won't work) // enable IssueJsonParserTest#testParseIssueWithUserPickerCustomFieldFilledOut after fixing this final Object value = json.opt(key); res.add(new IssueField(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; }
/** * This method returns the first field with specified name. * Names of fields in JIRA do not need to be unique. Therefore this method does not guarantee that you will get what you really want. * It's added just for convenience. For identify fields you should use id rather than name. * * @param name name of the field. * @return the first field matching selected name or <code>null</code> when no field with given name exists for this issue */ @Nullable public IssueField getFieldByName(String name) { for (IssueField issueField : issueFields) { if (issueField.getName().equals(name)) { return issueField; } } return null; }
private void setPullRequests(JiraIssue issue, com.atlassian.jira.rest.client.api.domain.Issue jiraIssue) { IssueField fieldContent = jiraIssue.getFieldByName("Git Pull Request");//Git Pull Request if ( fieldContent != null ) { extractPullRequests(issue, (JSONArray) fieldContent.getValue()); } }
res.add(new IssueField(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()) {
private void setIssueSprintRelease(JiraIssue issue, com.atlassian.jira.rest.client.api.domain.Issue jiraIssue) { final IssueField issueField = jiraIssue.getFieldByName("Sprint"); if ( issueField != null && issueField.getValue() != null ) { JSONArray fieldValue = (JSONArray) issueField.getValue(); if ( fieldValue.length() > 0 ) issue.setSprintRelease(extractSprintName(fieldValue)); } }
private void setFlag(com.atlassian.jira.rest.client.api.domain.Issue jiraIssue, Stage stage, Flag flag, String fieldname) { if (jiraIssue.getField(fieldname) != null && jiraIssue.getField(fieldname).getValue() != null) stage.setStatus(flag, FlagStatus.getMatchingFlag((String) jiraIssue.getField(fieldname).getValue())); else { stage.setStatus(flag, FlagStatus.NO_SET); } }