@Test public void testGenerateUpdateActivity() { Activity ret; ret = todolistActivityGenerator.generateUpdateActivity(todolist, todolistDeleted); assertEquals(ret.getAction(), ActivityActionType.DISCARD); ret = todolistActivityGenerator.generateUpdateActivity(todolistDeleted, todolist); assertEquals(ret.getAction(), ActivityActionType.RECOVER); ret = todolistActivityGenerator.generateUpdateActivity(todolist, todolistArchived); assertEquals(ret.getAction(), ActivityActionType.ARCHIVE); ret = todolistActivityGenerator.generateUpdateActivity(todolistArchived, todolist); assertEquals(ret.getAction(), ActivityActionType.ACTIVATE); ret = todolistActivityGenerator.generateUpdateActivity(todolist, todolistMoved); assertEquals(ret.getAction(), ActivityActionType.RELOCATE); ret = todolistActivityGenerator.generateUpdateActivity(todolist, todolistName); assertEquals(ret.getAction(), ActivityActionType.UPDATE); assertEquals(ret.getContent(), String.format(TodolistActivityGenerator.NAME_UPDATE, todolist.getName(), todolistName.getName())); ret = todolistActivityGenerator.generateUpdateActivity(todolist, todolistDescription); assertEquals(ret.getAction(), ActivityActionType.UPDATE); assertEquals(ret.getContent(), String.format(TodolistActivityGenerator.DESCRIPTION_UPDATE, todolist.getDescription(), todolistDescription.getDescription())); ret = todolistActivityGenerator.generateUpdateActivity(todolist, todolistNameAndDescription); assertEquals(ret.getAction(), ActivityActionType.UPDATE); assertEquals(ret.getContent(), String.format(TodolistActivityGenerator.NAME_AND_DESCRIPTION_UPDATE, todolist.getName(), todolistNameAndDescription.getName(), todolist.getDescription(), todolistNameAndDescription.getDescription())); }
private Activity generateUpdateActivity(Todolist originalList, Todolist modifiedList) { if (modifiedList.getProjectId() != null && !originalList.getProjectId().equals(modifiedList.getProjectId())) { Activity activity = this.generateActivityByActionType(ActivityActionType.RELOCATE, RELOCATE_SUBJECT, originalList); ActivityRecorderHelper.setupMoveInformation(originalList.getProjectId(), modifiedList.getProjectId(), activity); return activity; } else { Activity activity = this.generateActivityByActionType(ActivityActionType.UPDATE, UPDATE_SUBJECT, originalList); boolean changeName = modifiedList.getName() != null && !modifiedList.getName().equals(originalList.getName()); boolean changeDescription = modifiedList.getDescription() != null && !modifiedList.getDescription().equals(originalList.getDescription()); if (changeName & changeDescription) { activity.setContent(String.format(NAME_AND_DESCRIPTION_UPDATE, originalList.getName(), modifiedList.getName(), originalList.getDescription(), modifiedList.getDescription())); } else if (changeName) { activity.setContent(String.format(NAME_UPDATE, originalList.getName(), modifiedList.getName())); } else if (changeDescription) { activity.setContent(String.format(DESCRIPTION_UPDATE, originalList.getDescription(), modifiedList.getDescription())); } else { return null; } return activity; } }
TodolistActivityGenerator implements ActivityGenerator { private Activity generateUpdateActivity(Todolist originalList, Todolist modifiedList) { if (modifiedList.getProjectId() != null && !originalList.getProjectId().equals(modifiedList.getProjectId())) { Activity activity = this.generateActivityByActionType(ActivityActionType.RELOCATE, RELOCATE_SUBJECT, originalList); ActivityRecorderHelper.setupMoveInformation(originalList.getProjectId(), modifiedList.getProjectId(), activity); return activity; } else { Activity activity = this.generateActivityByActionType(ActivityActionType.UPDATE, UPDATE_SUBJECT, originalList); boolean changeName = modifiedList.getName() != null && !modifiedList.getName().equals(originalList.getName()); boolean changeDescription = modifiedList.getDescription() != null && !modifiedList.getDescription().equals(originalList.getDescription()); if (changeName & changeDescription) { activity.setContent(String.format(NAME_AND_DESCRIPTION_UPDATE, originalList.getName(), modifiedList.getName(), originalList.getDescription(), modifiedList.getDescription())); } else if (changeName) { activity.setContent(String.format(NAME_UPDATE, originalList.getName(), modifiedList.getName())); } else if (changeDescription) { activity.setContent(String.format(DESCRIPTION_UPDATE, originalList.getDescription(), modifiedList.getDescription())); } else { return null; } return activity; } } }
TodolistActivityGenerator implements ActivityGenerator { private Activity generateUpdateActivity(Todolist originalList, Todolist modifiedList) { if (modifiedList.getProjectId() != null && !originalList.getProjectId().equals(modifiedList.getProjectId())) { Activity activity = this.generateActivityByActionType(ActivityActionType.RELOCATE, RELOCATE_SUBJECT, originalList); ActivityRecorderHelper.setupMoveInformation(originalList.getProjectId(), modifiedList.getProjectId(), activity); return activity; } else { Activity activity = this.generateActivityByActionType(ActivityActionType.UPDATE, UPDATE_SUBJECT, originalList); boolean changeName = modifiedList.getName() != null && !modifiedList.getName().equals(originalList.getName()); boolean changeDescription = modifiedList.getDescription() != null && !modifiedList.getDescription().equals(originalList.getDescription()); if (changeName & changeDescription) { activity.setContent(String.format(NAME_AND_DESCRIPTION_UPDATE, originalList.getName(), modifiedList.getName(), originalList.getDescription(), modifiedList.getDescription())); } else if (changeName) { activity.setContent(String.format(NAME_UPDATE, originalList.getName(), modifiedList.getName())); } else if (changeDescription) { activity.setContent(String.format(DESCRIPTION_UPDATE, originalList.getDescription(), modifiedList.getDescription())); } else { return null; } return activity; } }  }
TodolistActivityGenerator implements ActivityGenerator { private Activity generateUpdateActivity(Todolist originalList, Todolist modifiedList) { if (modifiedList.getProjectId() != null && !originalList.getProjectId().equals(modifiedList.getProjectId())) { Activity activity = this.generateActivityByActionType(ActivityActionType.RELOCATE, RELOCATE_SUBJECT, originalList); ActivityRecorderHelper.setupMoveInformation(originalList.getProjectId(), modifiedList.getProjectId(), activity); return activity; } else { Activity activity = this.generateActivityByActionType(ActivityActionType.UPDATE, UPDATE_SUBJECT, originalList); boolean changeName = modifiedList.getName() != null && !modifiedList.getName().equals(originalList.getName()); boolean changeDescription = modifiedList.getDescription() != null && !modifiedList.getDescription().equals(originalList.getDescription()); if (changeName & changeDescription) { activity.setContent(String.format(NAME_AND_DESCRIPTION_UPDATE, originalList.getName(), modifiedList.getName(), originalList.getDescription(), modifiedList.getDescription())); } else if (changeName) { activity.setContent(String.format(NAME_UPDATE, originalList.getName(), modifiedList.getName())); } else if (changeDescription) { activity.setContent(String.format(DESCRIPTION_UPDATE, originalList.getDescription(), modifiedList.getDescription())); } else { return null; } return activity; } }  @Override String modelType(); @Override Activity generateCreateActivity(BaseProjectItem item); @Override Activity generateUpdateActivity(BaseProjectItem item, BaseProjectItem modifiedItem); @Override BaseProjectItem enrichModel(BaseProjectItem identifiable); @Override String modelService(); }
TodolistActivityGenerator implements ActivityGenerator { private Activity generateUpdateActivity(Todolist originalList, Todolist modifiedList) { if (modifiedList.getProjectId() != null && !originalList.getProjectId().equals(modifiedList.getProjectId())) { Activity activity = this.generateActivityByActionType(ActivityActionType.RELOCATE, RELOCATE_SUBJECT, originalList); ActivityRecorderHelper.setupMoveInformation(originalList.getProjectId(), modifiedList.getProjectId(), activity); return activity; } else { Activity activity = this.generateActivityByActionType(ActivityActionType.UPDATE, UPDATE_SUBJECT, originalList); boolean changeName = modifiedList.getName() != null && !modifiedList.getName().equals(originalList.getName()); boolean changeDescription = modifiedList.getDescription() != null && !modifiedList.getDescription().equals(originalList.getDescription()); if (changeName & changeDescription) { activity.setContent(String.format(NAME_AND_DESCRIPTION_UPDATE, originalList.getName(), modifiedList.getName(), originalList.getDescription(), modifiedList.getDescription())); } else if (changeName) { activity.setContent(String.format(NAME_UPDATE, originalList.getName(), modifiedList.getName())); } else if (changeDescription) { activity.setContent(String.format(DESCRIPTION_UPDATE, originalList.getDescription(), modifiedList.getDescription())); } else { return null; } return activity; } }  @Override String modelType(); @Override Activity generateCreateActivity(BaseProjectItem item); @Override Activity generateUpdateActivity(BaseProjectItem item, BaseProjectItem modifiedItem); @Override BaseProjectItem enrichModel(BaseProjectItem identifiable); @Override String modelService(); static final String CREATE_SUBJECT; static final String COPY_SUBJECT; static final String UPDATE_SUBJECT; static final String DISCARD_SUBJECT; static final String RECOVER_SUBJECT; static final String MOVE_SUBJECT; static final String RELOCATE_SUBJECT; static final String ARCHIVE_SUBJECT; static final String ACTIVATE_SUBJECT; static final String NAME_UPDATE; static final String DESCRIPTION_UPDATE; static final String NAME_AND_DESCRIPTION_UPDATE; }