Author: kwright
Date: Sat Jun 22 12:53:16 2013
New Revision: 1495720
URL: http://svn.apache.org/r1495720
Log:
Refactor JSON parsing.
Added:
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraQueryResults.java
(with props)
Modified:
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraIssue.java
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraJSONResponse.java
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraRepositoryConnector.java
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraSession.java
Modified:
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraIssue.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraIssue.java?rev=1495720&r1=1495719&r2=1495720&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraIssue.java
(original)
+++
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraIssue.java
Sat Jun 22 12:53:16 2013
@@ -19,194 +19,150 @@
package org.apache.manifoldcf.crawler.connectors.jira;
+import org.apache.manifoldcf.core.common.*;
+
import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
-import java.io.IOException;
-import org.json.simple.parser.ContentHandler;
-import org.json.simple.parser.ParseException;
+import org.json.simple.JSONObject;
+import org.json.simple.JSONArray;
/** An instance of this class represents a Jira issue, and the parser hooks
* needed to extract the data from the JSON event stream we use to parse it.
*/
public class JiraIssue extends JiraJSONResponse {
- // Things we want to parse from a JSON issue response
- protected Date createdDate;
- protected Date updatedDate;
- // Can't use streaming for these; we need the entire object BEFORE we start
- // looking at content.
- protected String description;
- protected String summary;
- protected Map<String,String> metadataMap = new HashMap<String,String>();
-
// Specific keys we care about
private final static String KEY_FIELDS = "fields";
+ private final static String KEY_KEY = "key";
+ private final static String KEY_SELF = "self";
private final static String KEY_CREATED = "created";
private final static String KEY_UPDATED = "updated";
private final static String KEY_DESCRIPTION = "description";
private final static String KEY_SUMMARY = "summary";
- // Parsing
- private List<String> currentKeys = new ArrayList<String>();
-
public JiraIssue() {
+ super();
}
+ public String getKey() {
+ Object key = object.get(KEY_KEY);
+ if (key == null)
+ return null;
+ return key.toString();
+ }
+
+ public String getSelf() {
+ Object key = object.get(KEY_SELF);
+ if (key == null)
+ return null;
+ return key.toString();
+ }
+
public Date getCreatedDate() {
- return createdDate;
+ JSONObject fields = (JSONObject)object.get(KEY_FIELDS);
+ if (fields == null)
+ return null;
+ JSONObject createdDate = (JSONObject)fields.get(KEY_CREATED);
+ if (createdDate == null)
+ return null;
+ return DateParser.parseISO8601Date(createdDate.toString());
}
public Date getUpdatedDate() {
- return updatedDate;
+ JSONObject fields = (JSONObject)object.get(KEY_FIELDS);
+ if (fields == null)
+ return null;
+ JSONObject updatedDate = (JSONObject)fields.get(KEY_UPDATED);
+ if (updatedDate == null)
+ return null;
+ return DateParser.parseISO8601Date(updatedDate.toString());
}
public String getDescription() {
- return description;
+ JSONObject fields = (JSONObject)object.get(KEY_FIELDS);
+ if (fields == null)
+ return null;
+ JSONObject description = (JSONObject)fields.get(KEY_DESCRIPTION);
+ if (description == null)
+ return null;
+ return description.toString();
}
public String getSummary() {
- return summary;
+ JSONObject fields = (JSONObject)object.get(KEY_FIELDS);
+ if (fields == null)
+ return null;
+ JSONObject summary = (JSONObject)fields.get(KEY_DESCRIPTION);
+ if (summary == null)
+ return null;
+ return summary.toString();
}
- public Map<String,String> getMetadata() {
- return metadataMap;
+ public Map<String,String[]> getMetadata() {
+ Map<String,List<String>> map = new HashMap<String,List<String>>();
+ JSONObject fields = (JSONObject)object.get(KEY_FIELDS);
+ if (fields != null)
+ addMetadataToMap("", fields, map);
+
+ // Now convert to a form more suited for RepositoryDocument
+ Map<String,String[]> rmap = new HashMap<String,String[]>();
+ for (String key : map.keySet()) {
+ List<String> values = map.get(key);
+ String[] valueArray = values.toArray(new String[0]);
+ rmap.put(key,valueArray);
+ }
+ return rmap;
}
-
- /*
- protected static HashMap<String, String> addMetaDataToMap(String parent,
JSONObject cval, HashMap<String, String> currentMap) {
- String append="";
- if (parent.length() > 0) {
- append=parent+"_";
+
+ protected static void addMetadataToMap(String parent, Object cval,
Map<String,List<String>> currentMap) {
+
+ if (cval == null)
+ return;
+
+ // See if it is a basic type
+ if (cval instanceof String || cval instanceof Number || cval instanceof
Boolean) {
+ List<String> current = currentMap.get(parent);
+ if (current == null) {
+ current = new ArrayList<String>();
+ currentMap.put(parent,current);
+ }
+ current.add(cval.toString());
+ return;
}
- for (Object key : cval.keySet()) {
- Object value = cval.get(key);
- if (value == null) {
- continue;
+
+ // See if it is an array
+ if (cval instanceof JSONArray) {
+ JSONArray ja = (JSONArray)cval;
+ for (Object subpiece : ja) {
+ addMetadataToMap(parent, subpiece, currentMap);
}
- //System.out.println(key);
- if (JSONObject.class.isInstance(value)) {
- currentMap = addMetaDataToMap(append + key, (JSONObject) value,
currentMap);
- } else if (JSONArray.class.isInstance(value)) {
- for (Object subpiece : (JSONArray) (value)) {
- if (String.class.isInstance(subpiece)) {
- currentMap.put(append + key, subpiece.toString());
- } else {
- currentMap = addMetaDataToMap(append + key, (JSONObject) subpiece,
currentMap);
- }
+ return;
+ }
+
+ // See if it is a JSONObject
+ if (cval instanceof JSONObject) {
+ JSONObject jo = (JSONObject)cval;
+ String append="";
+ if (parent.length() > 0) {
+ append=parent+"_";
+ }
+ for (Object key : jo.keySet()) {
+ Object value = jo.get(key);
+ if (value == null) {
+ continue;
}
- } else {
- currentMap.put(append+key + "", value.toString());
+ String newKey = append + key;
+ addMetadataToMap(newKey, value, currentMap);
}
+ return;
}
- return currentMap;
- }
- */
-
- /**
- * Receive notification of the beginning of a JSON object.
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- * - JSONParser will stop and throw the same exception to the caller
when receiving this exception.
- * @see #endJSON
- */
- @Override
- public boolean startObject() throws ParseException, IOException {
- return super.startObject();
- }
-
- /**
- * Receive notification of the end of a JSON object.
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- *
- * @see #startObject
- */
- @Override
- public boolean endObject() throws ParseException, IOException {
- return super.endObject();
- }
-
- /**
- * Receive notification of the beginning of a JSON object entry.
- *
- * @param key - Key of a JSON object entry.
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- *
- * @see #endObjectEntry
- */
- @Override
- public boolean startObjectEntry(String key) throws ParseException,
IOException {
- currentKeys.add(key);
- return super.startObjectEntry(key);
- }
-
- /**
- * Receive notification of the end of the value of previous object entry.
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- *
- * @see #startObjectEntry
- */
- @Override
- public boolean endObjectEntry() throws ParseException, IOException {
- currentKeys.remove(currentKeys.size()-1);
- return super.endObjectEntry();
- }
-
- /**
- * Receive notification of the beginning of a JSON array.
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- *
- * @see #endArray
- */
- @Override
- public boolean startArray() throws ParseException, IOException {
- return super.startArray();
- }
-
- /**
- * Receive notification of the end of a JSON array.
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- *
- * @see #startArray
- */
- @Override
- public boolean endArray() throws ParseException, IOException {
- return super.endArray();
- }
-
- /**
- * Receive notification of the JSON primitive values:
- * java.lang.String,
- * java.lang.Number,
- * java.lang.Boolean
- * null
- *
- * @param value - Instance of the following:
- * java.lang.String,
- * java.lang.Number,
- * java.lang.Boolean
- * null
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- */
- @Override
- public boolean primitive(Object value) throws ParseException, IOException {
- return super.primitive(value);
+
+
+ throw new IllegalArgumentException("Unknown object to addMetadataToMap:
"+cval.getClass().getName());
}
}
Modified:
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraJSONResponse.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraJSONResponse.java?rev=1495720&r1=1495719&r2=1495720&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraJSONResponse.java
(original)
+++
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraJSONResponse.java
Sat Jun 22 12:53:16 2013
@@ -19,138 +19,28 @@
package org.apache.manifoldcf.crawler.connectors.jira;
-import java.io.IOException;
-import org.json.simple.parser.ContentHandler;
-import org.json.simple.parser.ParseException;
+import org.json.simple.JSONObject;
/** An instance of this class represents a Jira JSON object, and the parser
hooks
-* needed to extract the data from the JSON event stream we use to parse it. It
-* is meant to be overridden (selectively) by derived classes.
+* needed to understand it.
+*
+* If we needed streaming anywhere, this would implement
org.json.simple.parser.ContentHandler,
+* where we would extract the data from a JSON event stream. But since we
don't need that
+* functionality, instead we're just going to accept an already-parsed
JSONObject.
+*
+* This class is meant to be overridden (selectively) by derived classes.
*/
-public class JiraJSONResponse implements ContentHandler {
+public class JiraJSONResponse {
+
+ protected JSONObject object = null;
public JiraJSONResponse() {
}
- /**
- * Receive notification of the beginning of JSON processing.
- * The parser will invoke this method only once.
- *
- * @throws ParseException
- * - JSONParser will stop and throw the same exception
to the caller when receiving this exception.
- */
- @Override
- public void startJSON() throws ParseException, IOException {
- }
-
- /**
- * Receive notification of the end of JSON processing.
- *
- * @throws ParseException
- */
- @Override
- public void endJSON() throws ParseException, IOException {
- }
-
- /**
- * Receive notification of the beginning of a JSON object.
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- * - JSONParser will stop and throw the same exception to the caller
when receiving this exception.
- * @see #endJSON
+ /** Receive a parsed JSON object.
*/
- @Override
- public boolean startObject() throws ParseException, IOException {
- return true;
+ public void acceptJSONObject(JSONObject object) {
+ this.object = object;
}
-
- /**
- * Receive notification of the end of a JSON object.
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- *
- * @see #startObject
- */
- @Override
- public boolean endObject() throws ParseException, IOException {
- return true;
- }
-
- /**
- * Receive notification of the beginning of a JSON object entry.
- *
- * @param key - Key of a JSON object entry.
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- *
- * @see #endObjectEntry
- */
- @Override
- public boolean startObjectEntry(String key) throws ParseException,
IOException {
- return true;
- }
-
- /**
- * Receive notification of the end of the value of previous object entry.
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- *
- * @see #startObjectEntry
- */
- @Override
- public boolean endObjectEntry() throws ParseException, IOException {
- return true;
- }
-
- /**
- * Receive notification of the beginning of a JSON array.
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- *
- * @see #endArray
- */
- @Override
- public boolean startArray() throws ParseException, IOException {
- return true;
- }
-
- /**
- * Receive notification of the end of a JSON array.
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- *
- * @see #startArray
- */
- @Override
- public boolean endArray() throws ParseException, IOException {
- return true;
- }
-
- /**
- * Receive notification of the JSON primitive values:
- * java.lang.String,
- * java.lang.Number,
- * java.lang.Boolean
- * null
- *
- * @param value - Instance of the following:
- * java.lang.String,
- * java.lang.Number,
- * java.lang.Boolean
- * null
- *
- * @return false if the handler wants to stop parsing after return.
- * @throws ParseException
- */
- @Override
- public boolean primitive(Object value) throws ParseException, IOException {
- return true;
- }
-
+
}
Added:
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraQueryResults.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraQueryResults.java?rev=1495720&view=auto
==============================================================================
---
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraQueryResults.java
(added)
+++
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraQueryResults.java
Sat Jun 22 12:53:16 2013
@@ -0,0 +1,58 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.manifoldcf.crawler.connectors.jira;
+
+import org.apache.manifoldcf.core.common.*;
+
+import java.io.IOException;
+
+import org.json.simple.JSONObject;
+import org.json.simple.JSONArray;
+
+/** An instance of this class represents the results of a Jira query, and
+* the ability to parse the corresponding JSON response.
+*/
+public class JiraQueryResults extends JiraJSONResponse {
+
+ // Specific keys we care about
+ private final static String KEY_TOTAL = "total";
+ private final static String KEY_ISSUES = "issues";
+ private final static String KEY_ID = "id";
+
+ public JiraQueryResults() {
+ super();
+ }
+
+ public Long getTotal() {
+ return (Long)object.get(KEY_TOTAL);
+ }
+
+ public void pushIds(XThreadStringBuffer seedBuffer)
+ throws IOException, InterruptedException {
+ JSONArray issues = (JSONArray)object.get(KEY_ISSUES);
+ for (Object issue : issues) {
+ if (issue instanceof JSONObject) {
+ JSONObject jo = (JSONObject)issue;
+ seedBuffer.add(jo.get(KEY_ID).toString());
+ }
+ }
+ }
+
+}
Propchange:
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraQueryResults.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraQueryResults.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified:
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraRepositoryConnector.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraRepositoryConnector.java?rev=1495720&r1=1495719&r2=1495720&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraRepositoryConnector.java
(original)
+++
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraRepositoryConnector.java
Sat Jun 22 12:53:16 2013
@@ -49,8 +49,6 @@ import org.apache.manifoldcf.crawler.int
import org.apache.manifoldcf.crawler.interfaces.IProcessActivity;
import org.apache.manifoldcf.crawler.interfaces.ISeedingActivity;
import java.util.Map.Entry;
-import org.json.simple.JSONObject;
-import org.json.simple.JSONArray;
/**
*
@@ -811,10 +809,10 @@ public class JiraRepositoryConnector ext
}
}
- protected JSONObject getObject(String nodeId)
+ protected JiraIssue getIssue(String nodeId)
throws ManifoldCFException, ServiceInterruption {
getSession();
- GetObjectThread t = new GetObjectThread(nodeId);
+ GetIssueThread t = new GetIssueThread(nodeId);
try {
t.start();
t.join();
@@ -846,13 +844,13 @@ public class JiraRepositoryConnector ext
return t.getResponse();
}
- protected class GetObjectThread extends Thread {
+ protected class GetIssueThread extends Thread {
protected final String nodeId;
protected Throwable exception = null;
- protected JSONObject response = null;
+ protected JiraIssue response = null;
- public GetObjectThread(String nodeId) {
+ public GetIssueThread(String nodeId) {
super();
setDaemon(true);
this.nodeId = nodeId;
@@ -860,13 +858,13 @@ public class JiraRepositoryConnector ext
public void run() {
try {
- response = session.getObject(nodeId);
+ response = session.getIssue(nodeId);
} catch (Throwable e) {
this.exception = e;
}
}
- public JSONObject getResponse() {
+ public JiraIssue getResponse() {
return response;
}
@@ -919,16 +917,15 @@ public class JiraRepositoryConnector ext
+ nodeId + "'");
}
- JSONObject jiraFile = getObject(nodeId);
-
- if (Logging.connectors.isDebugEnabled()) {
- Logging.connectors.debug("JIRA: have this file:\t" +
jiraFile.get("key"));
- }
-
- // its a file
if (!scanOnly[i]) {
doLog = true;
+ JiraIssue jiraFile = getIssue(nodeId);
+
+ if (Logging.connectors.isDebugEnabled()) {
+ Logging.connectors.debug("JIRA: have this file:\t" +
jiraFile.getKey());
+ }
+
// Unpack the version string
ArrayList acls = new ArrayList();
StringBuilder denyAclBuffer = new StringBuilder();
@@ -954,26 +951,23 @@ public class JiraRepositoryConnector ext
// Now do standard stuff
String mimeType = "text/plain";
- JSONObject fields = (JSONObject)jiraFile.get("fields");
- JSONObject createdDate = (JSONObject)fields.get("created");
- JSONObject modifiedDate = (JSONObject)fields.get("updated");
+ Date createdDate = jiraFile.getCreatedDate();
+ Date modifiedDate = jiraFile.getUpdatedDate();
rd.setMimeType(mimeType);
if (createdDate != null)
-
rd.setCreatedDate(DateParser.parseISO8601Date(createdDate.toString()));
+ rd.setCreatedDate(createdDate);
if (modifiedDate != null)
-
rd.setModifiedDate(DateParser.parseISO8601Date(modifiedDate.toString()));
+ rd.setModifiedDate(modifiedDate);
// Get general document metadata
- HashMap<String,String> metadataMap=new HashMap<String, String>();
-
- metadataMap = addMetaDataToMap("", jiraFile, metadataMap);
+ Map<String,String[]> metadataMap = jiraFile.getMetadata();
- for (Entry<String, String> entry : metadataMap.entrySet()) {
+ for (Entry<String, String[]> entry : metadataMap.entrySet()) {
rd.addField(entry.getKey(), entry.getValue());
}
- String documentURI = jiraFile.get("self").toString();
+ String documentURI = jiraFile.getSelf();
String document = getJiraBody(jiraFile);
try {
byte[] documentBytes = document.getBytes("UTF-8");
@@ -999,43 +993,18 @@ public class JiraRepositoryConnector ext
}
}
- protected static HashMap<String, String> addMetaDataToMap(String parent,
JSONObject cval, HashMap<String, String> currentMap) {
- String append="";
- if (parent.length() > 0) {
- append=parent+"_";
- }
- for (Object key : cval.keySet()) {
- Object value = cval.get(key);
- if (value == null) {
- continue;
- }
- //System.out.println(key);
- if (JSONObject.class.isInstance(value)) {
- currentMap = addMetaDataToMap(append + key, (JSONObject) value,
currentMap);
- } else if (JSONArray.class.isInstance(value)) {
- for (Object subpiece : (JSONArray) (value)) {
- if (String.class.isInstance(subpiece)) {
- currentMap.put(append + key, subpiece.toString());
- } else {
- currentMap = addMetaDataToMap(append + key, (JSONObject) subpiece,
currentMap);
- }
- }
- } else {
- currentMap.put(append+key + "", value.toString());
- }
+ protected static String getJiraBody(JiraIssue jiraFile) {
+ String summary = jiraFile.getSummary();
+ String description = jiraFile.getDescription();
+ StringBuilder body = new StringBuilder();
+ if (summary != null)
+ body.append(summary);
+ if (description != null) {
+ if (body.length() > 0)
+ body.append(" : ");
+ body.append(description);
}
- return currentMap;
- }
-
- protected static String getJiraBody(JSONObject jiraFile){
- String body;
- Object possibleBody = ((JSONObject)
jiraFile.get("fields")).get("description");
- if (possibleBody == null) {
- body = ((JSONObject) jiraFile.get("fields")).get("summary").toString();
- } else {
- body = possibleBody.toString();
- }
- return body;
+ return description.toString();
}
/**
@@ -1067,26 +1036,25 @@ public class JiraRepositoryConnector ext
String[] rval = new String[documentIdentifiers.length];
for (int i = 0; i < rval.length; i++) {
- JSONObject jiraFile = getObject(documentIdentifiers[i]);
- String rev =
((JSONObject)jiraFile.get("fields")).get("updated").toString();
- if (StringUtils.isNotEmpty(rev)) {
- StringBuilder sb = new StringBuilder();
-
- // Acls
- packList(sb,acls,'+');
- if (acls.length > 0) {
- sb.append('+');
- pack(sb,defaultAuthorityDenyToken,'+');
- }
- else
- sb.append('-');
- sb.append(rev);
- rval[i] = sb.toString();
- } else {
- //a jira document that doesn't contain versioning information will
NEVER be processed.
- // I don't know what this means, and whether it can ever occur.
- rval[i] = null;
- }
+ JiraIssue jiraFile = getIssue(documentIdentifiers[i]);
+ Date rev = jiraFile.getUpdatedDate();
+ if (rev != null) {
+ StringBuilder sb = new StringBuilder();
+
+ // Acls
+ packList(sb,acls,'+');
+ if (acls.length > 0) {
+ sb.append('+');
+ pack(sb,defaultAuthorityDenyToken,'+');
+ } else
+ sb.append('-');
+ sb.append(rev.toString());
+ rval[i] = sb.toString();
+ } else {
+ //a jira document that doesn't contain versioning information will
NEVER be processed.
+ // I don't know what this means, and whether it can ever occur.
+ rval[i] = null;
+ }
}
return rval;
}
Modified:
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraSession.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraSession.java?rev=1495720&r1=1495719&r2=1495720&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraSession.java
(original)
+++
manifoldcf/branches/CONNECTORS-723/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraSession.java
Sat Jun 22 12:53:16 2013
@@ -172,7 +172,7 @@ public class JiraSession {
return "";
}
- private JSONObject getRest(String rightside) throws IOException {
+ private void getRest(String rightside, JiraJSONResponse response) throws
IOException {
final HttpRequestBase method = new HttpGet(URLbase + apiPost + rightside);
method.addHeader("Accept", "application/json");
@@ -182,7 +182,8 @@ public class JiraSession {
int resultCode = httpResponse.getStatusLine().getStatusCode();
if (resultCode != 200)
throw new IOException("Unexpected result code "+resultCode+":
"+convertToString(httpResponse));
- return convertToJSON(httpResponse);
+ JSONObject jo = convertToJSON(httpResponse);
+ response.acceptJSONObject(jo);
} finally {
method.abort();
}
@@ -193,8 +194,9 @@ public class JiraSession {
*/
public Map<String, String> getRepositoryInfo() throws IOException {
HashMap<String, String> statistics = new HashMap<String, String>();
- JSONObject jsonobj = getRest("search?maxResults=1&jql=");
- statistics.put("Total Issues", jsonobj.get("total") + "");
+ JiraQueryResults qr = new JiraQueryResults();
+ getRest("search?maxResults=1&jql=", qr);
+ statistics.put("Total Issues", qr.getTotal().toString());
return statistics;
}
@@ -203,27 +205,28 @@ public class JiraSession {
*/
public void getSeeds(XThreadStringBuffer idBuffer, String jiraDriveQuery)
throws IOException, InterruptedException {
- JSONObject jsonobj;
- int startAt = 0;
- int setSize = 100;
- Long total = 0l;
+ long startAt = 0L;
+ long setSize = 100L;
+ long totalAmt = 0L;
do {
- jsonobj = getRest("search?maxResults=" + setSize + "&startAt=" + startAt
+ "&jql=" + URLEncoder.encode(jiraDriveQuery, "ISO-8859-1"));
- total = (Long) (jsonobj.get("total"));
- JSONArray issues = (JSONArray) jsonobj.get("issues");
- for (Object issuei : issues) {
- JSONObject issue = (JSONObject) issuei;
- idBuffer.add(issue.get("id") + "");
- }
+ JiraQueryResults qr = new JiraQueryResults();
+ getRest("search?maxResults=" + setSize + "&startAt=" + startAt + "&jql="
+ URLEncoder.encode(jiraDriveQuery, "UTF-8"), qr);
+ Long total = qr.getTotal();
+ if (total == null)
+ return;
+ totalAmt = total.longValue();
+ qr.pushIds(idBuffer);
startAt += setSize;
- } while (startAt < total); //results in a little overlap
+ } while (startAt < totalAmt);
}
/**
- * Get an individual document.
+ * Get an individual issue.
*/
- public JSONObject getObject(String id) throws IOException {
- return getRest("issue/" + id);
+ public JiraIssue getIssue(String id) throws IOException {
+ JiraIssue ji = new JiraIssue();
+ getRest("issue/" + id, ji);
+ return ji;
}