if (Logging.connectors.isDebugEnabled()) {
Logging.connectors.debug("GOOGLEDRIVE: Processing document identifier '"
+ nodeId + "'");
}
File googleFile = getObject(nodeId);
if (googleFile == null || (googleFile.containsKey("explicitlyTrashed") && googleFile.getExplicitlyTrashed())) {
//its deleted, move on
continue;
}
if (Logging.connectors.isDebugEnabled()) {
Logging.connectors.debug("GOOGLEDRIVE: have this file:\t" + googleFile.getTitle());
}
if ("application/vnd.google-apps.folder".equals(googleFile.getMimeType())) {
//if directory add its children
if (Logging.connectors.isDebugEnabled()) {
Logging.connectors.debug("GOOGLEDRIVE: its a directory");
}
// adding all the children + subdirs for a folder
getSession();
GetChildrenThread t = new GetChildrenThread(nodeId);
try {
t.start();
boolean wasInterrupted = false;
try {
XThreadStringBuffer childBuffer = t.getBuffer();
// Pick up the paths, and add them to the activities, before we join with the child thread.
while (true) {
// The only kind of exceptions this can throw are going to shut the process down.
String child = childBuffer.fetch();
if (child == null)
break;
// Add the pageID to the queue
activities.addDocumentReference(child, nodeId, RELATIONSHIP_CHILD);
}
} catch (InterruptedException e) {
wasInterrupted = true;
throw e;
} catch (ManifoldCFException e) {
if (e.getErrorCode() == ManifoldCFException.INTERRUPTED)
wasInterrupted = true;
throw e;
} finally {
if (!wasInterrupted)
t.finishUp();
}
} catch (InterruptedException e) {
t.interrupt();
throw new ManifoldCFException("Interrupted: " + e.getMessage(), e,
ManifoldCFException.INTERRUPTED);
} catch (java.net.SocketTimeoutException e) {
Logging.connectors.warn("GOOGLEDRIVE: Socket timeout adding child documents: " + e.getMessage(), e);
handleIOException(e);
} catch (InterruptedIOException e) {
t.interrupt();
throw new ManifoldCFException("Interrupted: " + e.getMessage(), e,
ManifoldCFException.INTERRUPTED);
} catch (IOException e) {
Logging.connectors.warn("GOOGLEDRIVE: Error adding child documents: " + e.getMessage(), e);
handleIOException(e);
}
} else {
// its a file
if (!scanOnly[i]) {
doLog = true;
if (Logging.connectors.isDebugEnabled()) {
Logging.connectors.debug("GOOGLEDRIVE: its a file");
}
// We always direct to the PDF
String documentURI = getUrl(googleFile, "application/pdf");
// Get the file length
Long fileLength = googleFile.getFileSize();
if (fileLength != null) {
// Unpack the version string
ArrayList acls = new ArrayList();
StringBuilder denyAclBuffer = new StringBuilder();
int index = unpackList(acls,version,0,'+');
if (index < version.length() && version.charAt(index++) == '+') {
index = unpack(denyAclBuffer,version,index,'+');
}
//otherwise process
RepositoryDocument rd = new RepositoryDocument();
// Turn into acls and add into description
String[] aclArray = new String[acls.size()];
for (int j = 0; j < aclArray.length; j++) {
aclArray[j] = (String)acls.get(j);
}
rd.setACL(aclArray);
if (denyAclBuffer.length() > 0) {
String[] denyAclArray = new String[]{denyAclBuffer.toString()};
rd.setDenyACL(denyAclArray);
}
// Now do standard stuff
String mimeType = googleFile.getMimeType();
DateTime createdDate = googleFile.getCreatedDate();
DateTime modifiedDate = googleFile.getModifiedDate();
String extension = googleFile.getFileExtension();
String title = googleFile.getTitle();
if (mimeType != null)
rd.setMimeType(mimeType);
if (createdDate != null)
rd.setCreatedDate(new Date(createdDate.getValue()));
if (modifiedDate != null)
rd.setModifiedDate(new Date(modifiedDate.getValue()));
if (extension != null)
{
if (title == null)
title = "";
rd.setFileName(title + "." + extension);
}
// Get general document metadata
for (Entry<String, Object> entry : googleFile.entrySet()) {
rd.addField(entry.getKey(), entry.getValue().toString());
}
// Fire up the document reading thread
DocumentReadingThread t = new DocumentReadingThread(documentURI);