@Test public void testInSync() throws Exception { Task task = decider.getTask(existingTestNode, existingTestNode, stateDecider, bufferedStateDecider); checkAction(task.getCurrentAction(), ActionType.NOTHING, Location.NONE, BufferUpdate.NONE); }
@Override public Task getTask(final File src, final File dst, final StateDecider sd, final BufferStateDecider bsd) throws DataParseException, IOException { List<Action> actions = new ArrayList<>(3); State state = sd.getState(src, dst); switch (state) { case ORPHAN_SOURCE: if (!bsd.getState(dst).equals(State.ORPHAN_SOURCE)) { actions.add(addDestination); } else { actions.add(ignoreDestinationExists); actions.add(overwriteDestination); } break; case DIR_SOURCE_FILE_DESTINATION: State buff = bsd.getState(dst); if (buff.equals(State.ORPHAN_SOURCE)) { actions.add(new Action(ActionType.ADD, DESTINATION, BufferUpdate.DESTINATION, "There was a node in buff, but its orphan, so add")); } else if (buff.equals(State.DIR_SOURCE_FILE_DESTINATION)) { actions.add(new Action(ActionType.NOTHING, NONE, BufferUpdate.NONE, "dirherefilethere, but there is a dir instead of file, so its in sync")); } else { actions.add(new Action(ActionType.DIR_HERE_FILE_THERE_ERROR, SOURCE, BufferUpdate.NONE, "cant update, dir here file there error occured")); } break; case FILE_SOURCE_DIR_DESTINATION: State buff1 = bsd.getState(dst); if (buff1.equals(State.ORPHAN_SOURCE)) { actions.add( new Action(ActionType.ADD, SOURCE, BufferUpdate.DESTINATION, "There was a node in buff, but its orphan, so add")); } else if (buff1.equals(State.FILE_SOURCE_DIR_DESTINATION)) { actions.add(new Action(ActionType.UNEXPECTED_CHANGE_ERROR, DESTINATION, BufferUpdate.NONE, "dirherefilethere, but there is a file instead of dir, so unexpected change")); } else { actions.add(new Action(ActionType.DIR_HERE_FILE_THERE_ERROR, DESTINATION, BufferUpdate.NONE, "cant update, dir here file there error occured")); } break; case FILE_CHANGE_SOURCE: if (bsd.getState(dst).equals(State.IN_SYNC)) { actions.add(updateDestination); } else { actions.add(unexpectedBothChanged); actions.add(overwriteDestination); } break; case FILE_CHANGE_DESTINATION: if (bsd.getState(dst).equals(State.IN_SYNC)) { actions.add(unexpectedDestinationChanged); actions.add(overwriteDestination); } else { actions.add(unexpectedBothChanged); actions.add(overwriteDestination); } break; case IN_SYNC: actions.add(inSync); actions.add(overwriteDestination); actions.add(overwriteSource); break; case ORPHAN_DESTINATION: break; } actions.add(ignore); Action[] as = new Action[actions.size()]; actions.toArray(as); return new Task(src, dst, state, as); }
PublishActionDecider implements ActionDecider { @Override public Task getTask(final File src, final File dst, final StateDecider sd, final BufferStateDecider bsd) throws DataParseException, IOException { List<Action> actions = new ArrayList<>(3); State state = sd.getState(src, dst); switch (state) { case ORPHAN_SOURCE: if (!bsd.getState(dst).equals(State.ORPHAN_SOURCE)) { actions.add(addDestination); } else { actions.add(ignoreDestinationExists); actions.add(overwriteDestination); } break; case DIR_SOURCE_FILE_DESTINATION: State buff = bsd.getState(dst); if (buff.equals(State.ORPHAN_SOURCE)) { actions.add(new Action(ActionType.ADD, DESTINATION, BufferUpdate.DESTINATION, "There was a node in buff, but its orphan, so add")); } else if (buff.equals(State.DIR_SOURCE_FILE_DESTINATION)) { actions.add(new Action(ActionType.NOTHING, NONE, BufferUpdate.NONE, "dirherefilethere, but there is a dir instead of file, so its in sync")); } else { actions.add(new Action(ActionType.DIR_HERE_FILE_THERE_ERROR, SOURCE, BufferUpdate.NONE, "cant update, dir here file there error occured")); } break; case FILE_SOURCE_DIR_DESTINATION: State buff1 = bsd.getState(dst); if (buff1.equals(State.ORPHAN_SOURCE)) { actions.add( new Action(ActionType.ADD, SOURCE, BufferUpdate.DESTINATION, "There was a node in buff, but its orphan, so add")); } else if (buff1.equals(State.FILE_SOURCE_DIR_DESTINATION)) { actions.add(new Action(ActionType.UNEXPECTED_CHANGE_ERROR, DESTINATION, BufferUpdate.NONE, "dirherefilethere, but there is a file instead of dir, so unexpected change")); } else { actions.add(new Action(ActionType.DIR_HERE_FILE_THERE_ERROR, DESTINATION, BufferUpdate.NONE, "cant update, dir here file there error occured")); } break; case FILE_CHANGE_SOURCE: if (bsd.getState(dst).equals(State.IN_SYNC)) { actions.add(updateDestination); } else { actions.add(unexpectedBothChanged); actions.add(overwriteDestination); } break; case FILE_CHANGE_DESTINATION: if (bsd.getState(dst).equals(State.IN_SYNC)) { actions.add(unexpectedDestinationChanged); actions.add(overwriteDestination); } else { actions.add(unexpectedBothChanged); actions.add(overwriteDestination); } break; case IN_SYNC: actions.add(inSync); actions.add(overwriteDestination); actions.add(overwriteSource); break; case ORPHAN_DESTINATION: break; } actions.add(ignore); Action[] as = new Action[actions.size()]; actions.toArray(as); return new Task(src, dst, state, as); } }
PublishActionDecider implements ActionDecider { @Override public Task getTask(final File src, final File dst, final StateDecider sd, final BufferStateDecider bsd) throws DataParseException, IOException { List<Action> actions = new ArrayList<>(3); State state = sd.getState(src, dst); switch (state) { case ORPHAN_SOURCE: if (!bsd.getState(dst).equals(State.ORPHAN_SOURCE)) { actions.add(addDestination); } else { actions.add(ignoreDestinationExists); actions.add(overwriteDestination); } break; case DIR_SOURCE_FILE_DESTINATION: State buff = bsd.getState(dst); if (buff.equals(State.ORPHAN_SOURCE)) { actions.add(new Action(ActionType.ADD, DESTINATION, BufferUpdate.DESTINATION, "There was a node in buff, but its orphan, so add")); } else if (buff.equals(State.DIR_SOURCE_FILE_DESTINATION)) { actions.add(new Action(ActionType.NOTHING, NONE, BufferUpdate.NONE, "dirherefilethere, but there is a dir instead of file, so its in sync")); } else { actions.add(new Action(ActionType.DIR_HERE_FILE_THERE_ERROR, SOURCE, BufferUpdate.NONE, "cant update, dir here file there error occured")); } break; case FILE_SOURCE_DIR_DESTINATION: State buff1 = bsd.getState(dst); if (buff1.equals(State.ORPHAN_SOURCE)) { actions.add( new Action(ActionType.ADD, SOURCE, BufferUpdate.DESTINATION, "There was a node in buff, but its orphan, so add")); } else if (buff1.equals(State.FILE_SOURCE_DIR_DESTINATION)) { actions.add(new Action(ActionType.UNEXPECTED_CHANGE_ERROR, DESTINATION, BufferUpdate.NONE, "dirherefilethere, but there is a file instead of dir, so unexpected change")); } else { actions.add(new Action(ActionType.DIR_HERE_FILE_THERE_ERROR, DESTINATION, BufferUpdate.NONE, "cant update, dir here file there error occured")); } break; case FILE_CHANGE_SOURCE: if (bsd.getState(dst).equals(State.IN_SYNC)) { actions.add(updateDestination); } else { actions.add(unexpectedBothChanged); actions.add(overwriteDestination); } break; case FILE_CHANGE_DESTINATION: if (bsd.getState(dst).equals(State.IN_SYNC)) { actions.add(unexpectedDestinationChanged); actions.add(overwriteDestination); } else { actions.add(unexpectedBothChanged); actions.add(overwriteDestination); } break; case IN_SYNC: actions.add(inSync); actions.add(overwriteDestination); actions.add(overwriteSource); break; case ORPHAN_DESTINATION: break; } actions.add(ignore); Action[] as = new Action[actions.size()]; actions.toArray(as); return new Task(src, dst, state, as); }  }
PublishActionDecider implements ActionDecider { @Override public Task getTask(final File src, final File dst, final StateDecider sd, final BufferStateDecider bsd) throws DataParseException, IOException { List<Action> actions = new ArrayList<>(3); State state = sd.getState(src, dst); switch (state) { case ORPHAN_SOURCE: if (!bsd.getState(dst).equals(State.ORPHAN_SOURCE)) { actions.add(addDestination); } else { actions.add(ignoreDestinationExists); actions.add(overwriteDestination); } break; case DIR_SOURCE_FILE_DESTINATION: State buff = bsd.getState(dst); if (buff.equals(State.ORPHAN_SOURCE)) { actions.add(new Action(ActionType.ADD, DESTINATION, BufferUpdate.DESTINATION, "There was a node in buff, but its orphan, so add")); } else if (buff.equals(State.DIR_SOURCE_FILE_DESTINATION)) { actions.add(new Action(ActionType.NOTHING, NONE, BufferUpdate.NONE, "dirherefilethere, but there is a dir instead of file, so its in sync")); } else { actions.add(new Action(ActionType.DIR_HERE_FILE_THERE_ERROR, SOURCE, BufferUpdate.NONE, "cant update, dir here file there error occured")); } break; case FILE_SOURCE_DIR_DESTINATION: State buff1 = bsd.getState(dst); if (buff1.equals(State.ORPHAN_SOURCE)) { actions.add( new Action(ActionType.ADD, SOURCE, BufferUpdate.DESTINATION, "There was a node in buff, but its orphan, so add")); } else if (buff1.equals(State.FILE_SOURCE_DIR_DESTINATION)) { actions.add(new Action(ActionType.UNEXPECTED_CHANGE_ERROR, DESTINATION, BufferUpdate.NONE, "dirherefilethere, but there is a file instead of dir, so unexpected change")); } else { actions.add(new Action(ActionType.DIR_HERE_FILE_THERE_ERROR, DESTINATION, BufferUpdate.NONE, "cant update, dir here file there error occured")); } break; case FILE_CHANGE_SOURCE: if (bsd.getState(dst).equals(State.IN_SYNC)) { actions.add(updateDestination); } else { actions.add(unexpectedBothChanged); actions.add(overwriteDestination); } break; case FILE_CHANGE_DESTINATION: if (bsd.getState(dst).equals(State.IN_SYNC)) { actions.add(unexpectedDestinationChanged); actions.add(overwriteDestination); } else { actions.add(unexpectedBothChanged); actions.add(overwriteDestination); } break; case IN_SYNC: actions.add(inSync); actions.add(overwriteDestination); actions.add(overwriteSource); break; case ORPHAN_DESTINATION: break; } actions.add(ignore); Action[] as = new Action[actions.size()]; actions.toArray(as); return new Task(src, dst, state, as); }  @Override Task getTask(final File src, final File dst, final StateDecider sd, final BufferStateDecider bsd); }
PublishActionDecider implements ActionDecider { @Override public Task getTask(final File src, final File dst, final StateDecider sd, final BufferStateDecider bsd) throws DataParseException, IOException { List<Action> actions = new ArrayList<>(3); State state = sd.getState(src, dst); switch (state) { case ORPHAN_SOURCE: if (!bsd.getState(dst).equals(State.ORPHAN_SOURCE)) { actions.add(addDestination); } else { actions.add(ignoreDestinationExists); actions.add(overwriteDestination); } break; case DIR_SOURCE_FILE_DESTINATION: State buff = bsd.getState(dst); if (buff.equals(State.ORPHAN_SOURCE)) { actions.add(new Action(ActionType.ADD, DESTINATION, BufferUpdate.DESTINATION, "There was a node in buff, but its orphan, so add")); } else if (buff.equals(State.DIR_SOURCE_FILE_DESTINATION)) { actions.add(new Action(ActionType.NOTHING, NONE, BufferUpdate.NONE, "dirherefilethere, but there is a dir instead of file, so its in sync")); } else { actions.add(new Action(ActionType.DIR_HERE_FILE_THERE_ERROR, SOURCE, BufferUpdate.NONE, "cant update, dir here file there error occured")); } break; case FILE_SOURCE_DIR_DESTINATION: State buff1 = bsd.getState(dst); if (buff1.equals(State.ORPHAN_SOURCE)) { actions.add( new Action(ActionType.ADD, SOURCE, BufferUpdate.DESTINATION, "There was a node in buff, but its orphan, so add")); } else if (buff1.equals(State.FILE_SOURCE_DIR_DESTINATION)) { actions.add(new Action(ActionType.UNEXPECTED_CHANGE_ERROR, DESTINATION, BufferUpdate.NONE, "dirherefilethere, but there is a file instead of dir, so unexpected change")); } else { actions.add(new Action(ActionType.DIR_HERE_FILE_THERE_ERROR, DESTINATION, BufferUpdate.NONE, "cant update, dir here file there error occured")); } break; case FILE_CHANGE_SOURCE: if (bsd.getState(dst).equals(State.IN_SYNC)) { actions.add(updateDestination); } else { actions.add(unexpectedBothChanged); actions.add(overwriteDestination); } break; case FILE_CHANGE_DESTINATION: if (bsd.getState(dst).equals(State.IN_SYNC)) { actions.add(unexpectedDestinationChanged); actions.add(overwriteDestination); } else { actions.add(unexpectedBothChanged); actions.add(overwriteDestination); } break; case IN_SYNC: actions.add(inSync); actions.add(overwriteDestination); actions.add(overwriteSource); break; case ORPHAN_DESTINATION: break; } actions.add(ignore); Action[] as = new Action[actions.size()]; actions.toArray(as); return new Task(src, dst, state, as); }  @Override Task getTask(final File src, final File dst, final StateDecider sd, final BufferStateDecider bsd);  }