use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class YouTrackRepository method getIssues.
public Task[] getIssues(@Nullable String request, int max, long since) throws Exception {
String query = getDefaultSearch();
if (StringUtil.isNotEmpty(request)) {
query += " " + request;
}
String requestUrl = "/rest/project/issues/?filter=" + encodeUrl(query) + "&max=" + max + "&updatedAfter" + since;
HttpMethod method = doREST(requestUrl, false);
try {
InputStream stream = method.getResponseBodyAsStream();
// todo workaround for http://youtrack.jetbrains.net/issue/JT-7984
String s = StreamUtil.readText(stream, CharsetToolkit.UTF8_CHARSET);
for (int i = 0; i < s.length(); i++) {
if (!XMLChar.isValid(s.charAt(i))) {
s = s.replace(s.charAt(i), ' ');
}
}
Element element;
try {
//InputSource source = new InputSource(stream);
//source.setEncoding("UTF-8");
//element = new SAXBuilder(false).build(source).getRootElement();
element = new SAXBuilder(false).build(new StringReader(s)).getRootElement();
} catch (JDOMException e) {
LOG.error("Can't parse YouTrack response for " + requestUrl, e);
throw e;
}
if ("error".equals(element.getName())) {
throw new Exception("Error from YouTrack for " + requestUrl + ": '" + element.getText() + "'");
}
List<Element> children = element.getChildren("issue");
final List<Task> tasks = ContainerUtil.mapNotNull(children, (NullableFunction<Element, Task>) o -> createIssue(o));
return tasks.toArray(new Task[tasks.size()]);
} finally {
method.releaseConnection();
}
}
use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class YouTrackRepository method updateTimeSpent.
@Override
public void updateTimeSpent(@NotNull LocalTask task, @NotNull String timeSpent, @NotNull String comment) throws Exception {
checkVersion();
String command = encodeUrl(String.format("work Today %s %s", timeSpent, comment));
final HttpMethod method = doREST("/rest/issue/execute/" + task.getId() + "?command=" + command, true);
try {
if (method.getStatusCode() != 200) {
InputStream stream = method.getResponseBodyAsStream();
String message = new SAXBuilder(false).build(stream).getRootElement().getText();
throw new Exception(message);
}
} finally {
method.releaseConnection();
}
}
use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class LighthouseRepository method getIssues.
@Override
public Task[] getIssues(@Nullable String query, int max, long since) throws Exception {
String url = "/projects/" + myProjectId + "/tickets.xml";
url += "?q=" + encodeUrl("state:open sort:updated ");
if (!StringUtil.isEmpty(query)) {
url += encodeUrl(query);
}
final List<Task> tasks = new ArrayList<>();
int page = 1;
final HttpClient client = login();
while (tasks.size() < max) {
HttpMethod method = doREST(url + "&page=" + page, false, client);
InputStream stream = method.getResponseBodyAsStream();
Element element = new SAXBuilder(false).build(stream).getRootElement();
if ("nil-classes".equals(element.getName()))
break;
if (!"tickets".equals(element.getName())) {
LOG.warn("Error fetching issues for: " + url + ", HTTP status code: " + method.getStatusCode());
throw new Exception("Error fetching issues for: " + url + ", HTTP status code: " + method.getStatusCode() + "\n" + element.getText());
}
List<Element> children = element.getChildren("ticket");
List<Task> taskList = ContainerUtil.mapNotNull(children, (NullableFunction<Element, Task>) o -> createIssue(o));
tasks.addAll(taskList);
page++;
}
return tasks.toArray(new Task[tasks.size()]);
}
use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class LighthouseRepository method findTask.
@Nullable
@Override
public Task findTask(@NotNull String id) throws Exception {
final String[] split = id.split("\\-");
final String projectId = split[0];
final String realId = split[1];
if (!Comparing.strEqual(projectId, myProjectId))
return null;
HttpMethod method = doREST("/projects/" + myProjectId + "/tickets/" + realId + ".xml", false, login());
InputStream stream = method.getResponseBodyAsStream();
Element element = new SAXBuilder(false).build(stream).getRootElement();
return element.getName().equals("ticket") ? createIssue(element) : null;
}
use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class PivotalTrackerRepository method getStories.
private List<Element> getStories(@Nullable final String query, final int max) throws Exception {
String url = API_URL + "/projects/" + myProjectId + "/stories";
url += "?filter=" + encodeUrl("state:started,unstarted,unscheduled,rejected");
if (!StringUtil.isEmpty(query)) {
url += encodeUrl(" \"" + query + '"');
}
if (max >= 0) {
url += "&limit=" + encodeUrl(String.valueOf(max));
}
LOG.info("Getting all the stories with url: " + url);
final HttpMethod method = doREST(url, HTTPMethod.GET);
final InputStream stream = method.getResponseBodyAsStream();
final Element element = new SAXBuilder(false).build(stream).getRootElement();
if (!"stories".equals(element.getName())) {
LOG.warn("Error fetching issues for: " + url + ", HTTP status code: " + method.getStatusCode());
throw new Exception("Error fetching issues for: " + url + ", HTTP status code: " + method.getStatusCode() + "\n" + element.getText());
}
return element.getChildren("story");
}
Aggregations