WaveletId.deserialise(waveletTask.getWaveletId()));
LinkedList<RemoteAttachmentInfo> toImport = Lists.newLinkedList(task.getToImport());
log.info("Need attachments for " + waveletName + ": " + toImport);
int infosFetchedThisTask = 0;
while (!toImport.isEmpty() && infosFetchedThisTask < MAX_FETCHES_PER_TASK) {
RemoteAttachmentInfo info = toImport.removeFirst();
AttachmentId localId = fetchAttachment(instance, info);
log.info("Local id: " + localId);
ImportedAttachmentInfo imported = new ImportedAttachmentInfoGsonImpl();
imported.setRemoteInfo(info);
if (localId != null) {
imported.setLocalId(localId.getId());
}
infosFetchedThisTask++;
task.addImported(imported);
}
if (toImport.isEmpty()) {
log.info("All attachments imported, will import wavelet");
for (ImportedAttachmentInfo info : task.getImported()) {
ImportedAttachment attachment = new ImportedAttachmentGsonImpl();
attachment.setRemoteId(info.getRemoteInfo().getRemoteId());
if (info.hasLocalId()) {
attachment.setLocalId(info.getLocalId());
}
waveletTask.addAttachment(attachment);
}
ImportTaskPayload payload = new ImportTaskPayloadGsonImpl();
payload.setImportWaveletTask(waveletTask);