in src/main/java/com/atlassian/uwc/exporters/JiveExporter.java [169:290]
private void exportDocuments() {
if (!this.running) return;
log.debug("Exporting Documents");
if (this.sqlStatements.containsKey("sql.doc") && this.sqlStatements.containsKey("sql.doc.versions")) {
int commentIndex = 0;
int attachmentIndex = 0;
String sqlStatement = this.sqlStatements.get("sql.doc");
try {
ResultSet docResults = sql(sqlStatement);
//get the count data
docResults.last();
int maxDocs = docResults.getRow();
docResults.beforeFirst();
if (maxDocs > 0) testString += "Count: " + maxDocs + "\n";
// go through the results for each page version
int index = 0;
String lastfile = "";
Vector<Long> noResultsIds = new Vector<Long>();
while (docResults.next()) {
if (!this.running) return;
//get basic data
long internalDocId = docResults.getLong("internalDocID");
int latestVersionId = docResults.getInt("versionID");
int containerType = docResults.getInt("containerType");
long containerId = docResults.getLong("containerId");
//filter by container
if (!fromAllowedContainer(containerId, containerType)) {
maxDocs--;
continue;
}
//handle versions
String versionSql = this.sqlStatements.get("sql.doc.versions");
versionSql = versionSql.replaceFirst("\\?", "'"+internalDocId + "'");
ResultSet versionResults = sql(versionSql);
boolean hasresults = false;
while (versionResults.next()) {
hasresults = true;
String title = versionResults.getString("title");
long userid = versionResults.getLong("userId");
String username = ((userid > 0)?getUsername(userid):userid+"");
long creationDate = versionResults.getLong("creationDate");
long modificationDate = versionResults.getLong("modificationDate");
String summary = versionResults.getString("summary");
int versionId = versionResults.getInt("versionID");
String bodyText = getBodyText(internalDocId);
String tags = getTags(internalDocId, DOC_JIVECONSTANT);
if (this.debug && tags != null) {
testString += internalDocId + ": " + tags + "\n";
}
else if (this.debug) {
testString += "|" + internalDocId + "|" + versionId + "|" +
containerType + "|" + containerId + "|" +
username.substring(0,2) + "|" + creationDate + "|" +
modificationDate + "|" +
((summary == null)?"NO":"") + "SUMMARY|" +
((bodyText == null)?"NO":"") + "BODY|" +
"\n";
}
else {
String contentType = "DOC";
String expdir = getExportPath(this.outdir);
String containerdir = createContainerDir(expdir, containerType, containerId);
String filename = createFilename(internalDocId, versionId, contentType, title);
String filepath = expdir + containerdir + filename;
String content = createDocContent(internalDocId, versionId, contentType, title,
containerType, containerId,
username, creationDate, modificationDate, summary, bodyText, tags);
lastfile = filepath;
writeFile(filepath, content, this.encoding);
//export title data (we'll need this in a seperate map file for links and attachments to other pages)
exportTitles(internalDocId, DOC_JIVECONSTANT, containerId, containerType, versionId, title);
}
}
//export comments
commentIndex += exportComments(internalDocId,
containerType, containerId, "doc");
//export attachment data (for use with attachments on the file system)
attachmentIndex += exportAttachments(internalDocId, DOC_JIVECONSTANT);
//do some logging
if (!hasresults) {
noResultsIds.add(internalDocId);
}
if ((index % 100) == 0) {
double percent = Math.round(100*(((double) index)/maxDocs));
log.debug("Exporting " + index + " Documents. " + percent + "%");
}
index++;
}
log.info("Exporting " + index + " Documents. 100.0%");
log.info("Exported " + commentIndex + " comments for document.");
log.info("Exported data for " + attachmentIndex + " attachments.");
log.debug("Lastfile = " + lastfile);
if (noResultsIds.size() > 0) {
int expectedtotal = maxDocs - noResultsIds.size();
String ids = "";
for (Long id : noResultsIds) {
if (!"".equals(ids)) ids += ", ";
ids += id +"";
}
log.info("Some pages had no results. no-results-count = " + noResultsIds.size()
+ "\n"
+ "Expected Total number of files exported: " + expectedtotal + "\n"
+ "Affected ids: " + ids + "\n");
}
if (this.debug) {
testString += "Final Count: " + index + "\n";
writeFile(this.debugOutFile, testString, this.encoding);
}
} catch (SQLException e) {
log.error("Problem getting documents: " + sqlStatement, e);
return;
}
}
}