if (userName == null)
throw new NotLockedException();
ProfTimer pt = new ProfTimer(logger, "ResourceBridgeClient.syncUp["
+ remoteUrl + "]");
ResourceCollectionDiff diff = getDiff();
applySyncFilter(diff, filter);
pt.click("Computed local-vs-remote diff");
if (diff == null || diff.noDifferencesFound()) {
logger.finer("no changes to sync up");
return false;
}
boolean madeChange = false;
List<String> filesToDownload = new ArrayList<String>();
// decide what to do for each file that is present only in the remote
// collection (but not in our local collection)
if (!diff.getOnlyInB().isEmpty()) {
List<String> params = new ArrayList<String>();
for (String resourceName : diff.getOnlyInB()) {
if (isSyncDownOnly(resourceName)) {
filesToDownload.add(resourceName);
} else {
logger.fine("deleting remote resource " + resourceName);
params.add(DELETE_FILE_PARAM);
params.add(resourceName);
}
}
if (!params.isEmpty()) {
doPostRequest(DELETE_ACTION, (Object[]) params.toArray());
pt.click("Deleted remote resources");
madeChange = true;
}
}
// upload files that need to be created or updated in the remote
// collection
if (!diff.getOnlyInA().isEmpty() || !diff.getDiffering().isEmpty()) {
List params = new ArrayList();
for (String resourceName : diff.getOnlyInA()) {
if (isSyncDownOnly(resourceName)) {
logger.fine("deleting local resource " + resourceName);
localCollection.deleteResource(resourceName);
madeChange = true;
} else {
logger.fine("uploading new resource " + resourceName);
addFileUploadParamsWithBatching(params, resourceName);
madeChange = true;
}
}
for (String resourceName : diff.getDiffering()) {
if (isSyncDownOnly(resourceName)) {
filesToDownload.add(resourceName);
} else {
logger.fine("uploading modified resource " + resourceName);
addFileUploadParamsWithBatching(params, resourceName);