org.jumpmind.symmetric.fs.client.SyncStatus Maven / Gradle / Ivy
/*
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU Lesser General Public License (the
* "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* .
*
* 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.jumpmind.symmetric.fs.client;
import java.util.ArrayList;
import java.util.List;
import org.jumpmind.symmetric.fs.config.ConflictStrategy;
import org.jumpmind.symmetric.fs.config.Node;
import org.jumpmind.symmetric.fs.config.SyncConfig;
import org.jumpmind.symmetric.fs.track.DirectorySpecSnapshot;
import org.jumpmind.symmetric.fs.track.FileChange;
import org.jumpmind.symmetric.fs.track.FileChangeType;
public class SyncStatus {
public enum Stage {
START, RAN_PRESCRIPT, RECORDED_FILES_TO_SEND, SEND_FILES, RECEIVE_FILES, RUN_POSTSCRIPT, DONE
};
protected Node node;
protected Stage stage = Stage.START;
protected SyncConfig syncConfig;
protected DirectorySpecSnapshot clientSnapshot;
protected DirectorySpecSnapshot serverSnapshot;
protected List deletesToSend;
protected List deletesSent;
protected List filesToSend;
protected List fileSent;
protected List filesToReceive;
protected List deletesToReceive;
protected List deletesReceived;
protected List filesReceived;
protected List filesInConflict;
public SyncStatus() {
deletesToSend = new ArrayList();
deletesSent = new ArrayList();
filesToSend = new ArrayList();
fileSent = new ArrayList();
deletesToReceive = new ArrayList();
deletesReceived = new ArrayList();
filesToReceive = new ArrayList();
filesReceived = new ArrayList();
filesInConflict = new ArrayList();
}
public SyncStatus(Node node, SyncConfig syncConfig) {
this();
this.node = node;
this.syncConfig = syncConfig;
}
public Node getNode() {
return node;
}
public void setNode(Node node) {
this.node = node;
}
public Stage getStage() {
return stage;
}
public void setStage(Stage stage) {
this.stage = stage;
}
public DirectorySpecSnapshot getClientSnapshot() {
return clientSnapshot;
}
public void setClientSnapshot(DirectorySpecSnapshot clientSnapshot) {
this.clientSnapshot = clientSnapshot;
List changes = clientSnapshot.getFiles();
for (FileChange fileChange : changes) {
String fileName = fileChange.getFileName();
if (fileChange.getFileChangeType() == FileChangeType.DELETE) {
filesToSend.remove(fileName);
deletesToSend.add(fileName);
} else {
deletesToSend.remove(fileName);
filesToSend.add(fileName);
}
}
}
public void setServerSnapshot(DirectorySpecSnapshot serverSnapshot) {
this.serverSnapshot = serverSnapshot;
List changes = serverSnapshot.getFiles();
for (FileChange fileChange : changes) {
String fileName = fileChange.getFileName();
if (fileChange.getFileChangeType() == FileChangeType.DELETE) {
filesToReceive.remove(fileName);
deletesToReceive.add(fileName);
} else {
deletesToReceive.remove(fileName);
if (!filesToSend.contains(fileName)) {
filesToReceive.add(fileName);
} else {
ConflictStrategy conflictStrategy = syncConfig.getConflictStrategy();
switch (conflictStrategy) {
case CLIENT_WINS:
// do nothing
break;
case REPORT_ERROR:
filesInConflict.add(fileName);
filesToSend.remove(fileName);
break;
case SERVER_WINS:
filesToReceive.add(fileName);
filesToSend.remove(fileName);
break;
default:
break;
}
}
}
}
}
public List getFilesInConflict() {
return filesInConflict;
}
public List getFilesToSend() {
return filesToSend;
}
public List getFileSent() {
return fileSent;
}
public List getFilesToReceive() {
return filesToReceive;
}
public List getFilesReceived() {
return filesReceived;
}
public List getDeletesReceived() {
return deletesReceived;
}
public List getDeletesSent() {
return deletesSent;
}
public List getDeletesToReceive() {
return deletesToReceive;
}
public List getDeletesToSend() {
return deletesToSend;
}
public SyncConfig getSyncConfig() {
return syncConfig;
}
public void setSyncConfig(SyncConfig syncConfig) {
this.syncConfig = syncConfig;
}
public DirectorySpecSnapshot getServerSnapshot() {
return serverSnapshot;
}
}