
b4j.core.session.bugzilla.json.BugzillaBugParser Maven / Gradle / Ivy
/*
* This file is part of Bugzilla for Java.
*
* Bugzilla for Java is free software: you can redistribute it
* and/or modify it under the terms of version 3 of the GNU
* Lesser General Public License as published by the Free Software
* Foundation.
*
* Bugzilla for Java is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Bugzilla for Java. If not, see
* .
*/
package b4j.core.session.bugzilla.json;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.LoggerFactory;
import b4j.core.DefaultIssue;
import b4j.core.DefaultLink;
import b4j.core.Issue;
import b4j.core.IssueLink.Type;
import b4j.core.ServerInfo;
import b4j.core.session.bugzilla.async.AsyncBugzillaRestClient;
import b4j.util.BugzillaUtils;
import b4j.util.LazyRetriever;
import com.atlassian.jira.rest.client.internal.json.JsonObjectParser;
/**
* Parses the product for Bugzilla REST API.
* @author ralph
* @since 2.0
*
*/
public class BugzillaBugParser extends AbstractJsonParser implements JsonObjectParser> {
private AsyncBugzillaRestClient mainClient;
private ServerInfo serverInfo = null;
private boolean serverInfoError = false;
/**
* Constructor.
*/
public BugzillaBugParser(AsyncBugzillaRestClient mainClient) {
super(mainClient.getLazyRetriever());
this.mainClient = mainClient;
}
@Override
public Iterable parse(JSONObject json) throws JSONException {
if ((serverInfo == null) && !serverInfoError) try {
serverInfo = mainClient.getMetadataClient().getServerInfo().get();
} catch (Exception e) {
LoggerFactory.getLogger(getClass()).error("Cannot retrieve server info. Issues will omit this information", e);
serverInfoError = true;
}
List rc = new ArrayList();
checkError(json); // Throws exception when error occurred
JSONArray arr = getResult(json).getJSONArray("bugs");
for (int i=0; i getIntCollection(JSONArray arr) throws JSONException {
Collection rc = new ArrayList();
for (int i=0; i getStringCollection(JSONArray arr) throws JSONException {
Collection rc = new ArrayList();
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy