Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix storage bug #132

Merged
merged 70 commits into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
84edbcd
v1.1
seanieyap Mar 3, 2019
7715c8d
fix some errors and typos
seanieyap Mar 3, 2019
2b79726
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 3, 2019
a59a7db
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 10, 2019
e94d3a2
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 17, 2019
984e459
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 17, 2019
3dc81e8
Refactor entire project, remove all traces of Addressbook
seanieyap Mar 17, 2019
474d1d4
Update developer guide for ExportCommandP (#80)
macchazuki Mar 17, 2019
219cd79
Update documentation for view command (#81)
dingheng4448 Mar 17, 2019
669099d
Remove remaining Addressbook classes
seanieyap Mar 17, 2019
262e12c
Refactor some classes
seanieyap Mar 17, 2019
02322e1
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 17, 2019
db66222
fix missing files issue
seanieyap Mar 17, 2019
a73e964
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 17, 2019
3eb2fe4
Add test cases for add function, Utils and other code enhancements
seanieyap Mar 18, 2019
7913f99
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 18, 2019
348b702
fix codacy issues
seanieyap Mar 18, 2019
461da9e
fix codacy issues
seanieyap Mar 18, 2019
16f2c7e
Add tests for Utils
seanieyap Mar 18, 2019
5add3ce
Update Ui.png
seanieyap Mar 18, 2019
586fd41
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 18, 2019
edf9da0
Add diagrams
seanieyap Mar 18, 2019
fca2e67
Update Ui.png
seanieyap Mar 18, 2019
4fb7462
fix issue with Ui.png
seanieyap Mar 18, 2019
30b9285
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 18, 2019
1b69c0e
Update Codacy Badge link due to reinitialization.
seanieyap Mar 18, 2019
c6d307d
Enhance ordering of slots printed
seanieyap Mar 19, 2019
9f58e44
Update UserGuide.adoc
seanieyap Mar 19, 2019
cc03c36
Update UserGuide.adoc
seanieyap Mar 19, 2019
0c808b0
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 19, 2019
320e5ae
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 19, 2019
4c5b129
Merge (#18)
marcus-pzj Mar 19, 2019
266f244
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 20, 2019
387aa71
Update UserGuide.adoc with feedback from peers
seanieyap Mar 20, 2019
8784d69
Update UserGuide.adoc with nicer tables
seanieyap Mar 20, 2019
1cbf2c6
Update UserGuide.adoc: fix formatting issues
seanieyap Mar 20, 2019
078b3c0
UserGuide.adoc Remove potential Netlify breaking code
seanieyap Mar 21, 2019
58d11e4
Resolve conflicts
marcus-pzj Mar 22, 2019
3ed1b50
Merge (#19)
marcus-pzj Mar 22, 2019
76c32b2
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 23, 2019
800ea8a
Merge (#21)
marcus-pzj Mar 23, 2019
b718d23
Resolve merge conflicts
marcus-pzj Mar 23, 2019
39d58cb
Merge (#24)
marcus-pzj Mar 23, 2019
4dca755
Merge codacy
marcus-pzj Mar 24, 2019
a2e7955
Resolve conflicts
marcus-pzj Mar 24, 2019
0fb1aa7
resolve whitesapce
marcus-pzj Mar 24, 2019
f4e41a8
Merge (#27)
marcus-pzj Mar 24, 2019
50c1f97
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 24, 2019
7d1c30e
Testing (#29)
marcus-pzj Mar 25, 2019
9ebefc6
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 25, 2019
300b5c9
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 26, 2019
2b7d999
Update
marcus-pzj Mar 29, 2019
5834aeb
Merge (#30)
marcus-pzj Mar 29, 2019
024762e
Resolve merge conflict
marcus-pzj Mar 30, 2019
3466536
Merge (#32)
marcus-pzj Mar 30, 2019
5c7b86a
Enhance FindCommand to use Levenshtein Distance (#31)
marcus-pzj Mar 30, 2019
8b97443
Fix codacy issues
marcus-pzj Mar 30, 2019
fa52f01
Merge branch 'master' into master
marcus-pzj Mar 30, 2019
74cdb3e
resolve merge conflict
marcus-pzj Mar 30, 2019
63ceb82
Merge (#33)
marcus-pzj Mar 30, 2019
d7a1cb4
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 30, 2019
f1ee71a
Merge (#36)
marcus-pzj Mar 31, 2019
cd47865
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
marcus-pzj Mar 31, 2019
2fa7a70
Add UndoRedo Command
marcus-pzj Mar 31, 2019
870d23c
ERROR:parsing file format
marcus-pzj Mar 31, 2019
3935d7e
Merge branch 'hist' of https://github.com/marcus-pzj/main
seanieyap Mar 31, 2019
544f5b9
Fix storage bug
seanieyap Mar 31, 2019
64f1d70
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 31, 2019
900bc31
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/main
seanieyap Mar 31, 2019
7e0b2b3
Fix checkstyle errors unused imports
seanieyap Mar 31, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -509,28 +509,20 @@ Additionally, doing these actions when parsing, though bloats code, allows for m
The find function supports searching using a single keyword. +
If some part of the name of `Slot` / tags attributed to `Slot` contains the specified keyword,
a positive match is registered and the designated `Slot` will be added to the output list. +
Examples: +
`find n/CS` +
`CS2101`, `CS2113T`, `SOCSMeet` are considered positive matches. +
`ST2334`, `Hockey`, `Lunch` are NOT considered positive matches. +

==== Design Considerations

===== Aspect: What constitutes a positive search result in `find` command
* **Alternative 1:** Positive search result by strictly matching the entered keyword
** Pros: Easy to implement.
** Cons: Search must be exact, typos or an incomplete keyword will yield incorrect results. Nothing different from `List` feature.
* **Alternative 2 (current choice):** Positive search result as long as name/tag contains the keyword.
** Pros: Searches can now consider names/tags similar to the keyword.
* **Alternative 2:** Positive search result as long as name/tag contains the keyword.
** Pros: Searches will detect names/tags similar to the keyword.
** Cons: Output list will be longer. May become excessively long if short keyword is provided.
* **Alternative 3 (future implementation):** Store the search results in a `treeMap` ordered by their Levenshtein distances from the search keyword
** Pros: Will also consider searches that are similar to what we want and will account for typos or incomplete keywords
* **Alternative 3 (current implementation):** Store the search results in a `PriorityQueue` ordered by their <<levenshtein-distance,Levenshtein distances>> from the search keyword.
** Pros: Will also consider searches that are similar to the desired name/tag and will account for a typo or an incomplete keyword
** Cons: Added complexities in finding and searching.

==== Future Implementation
The find function will be revamped to support search guessing. +
FindCommand will be enhanced by using Levenshtein Distance to generate an ordered set of `Slot` attributes ordered by similarity.

=== View Month/Week/Day feature

==== Design Considerations
Expand Down Expand Up @@ -1379,6 +1371,11 @@ _{More to be added}_
[[mainstream-os]] Mainstream OS::
Windows, Linux, Unix, OS-X

[[levenshtein-distance]] Levenshtein Distance::
The Levenshtein distance is a string metric for measuring difference between two sequences. +
Informally, the Levenshtein distance between two words is the minimum number of single-character edits (i.e. insertions, deletions or substitutions)
required to change one word into the other.

////
Should only include this if we actually make any mention to private planner detail.
[[private-planner-detail]] Private planner detail::
Expand Down
5 changes: 1 addition & 4 deletions src/planmysem/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import javafx.application.Platform;
import javafx.stage.Stage;
import planmysem.logic.LogicManager;
import planmysem.model.Model;
import planmysem.model.ModelManager;
import planmysem.storage.Storage;
import planmysem.storage.StorageFile;
import planmysem.ui.Gui;
Expand All @@ -28,8 +26,7 @@ public static void main(String[] args) {
@Override
public void start(Stage primaryStage) throws Exception {
Storage storageFile = new StorageFile();
Model modelManager = new ModelManager();
Gui gui = new Gui(new LogicManager(storageFile, modelManager), VERSION);
Gui gui = new Gui(new LogicManager(storageFile), VERSION);
gui.start(primaryStage, this);
}

Expand Down
7 changes: 4 additions & 3 deletions src/planmysem/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import planmysem.logic.parser.ParserManager;
import planmysem.logic.parser.exceptions.ParseException;
import planmysem.model.Model;
import planmysem.model.ModelManager;
import planmysem.model.semester.ReadOnlyDay;
import planmysem.model.slot.ReadOnlySlot;
import planmysem.storage.Storage;
Expand All @@ -27,9 +28,9 @@ public class LogicManager implements Logic {
private final CommandHistory history;
private final ParserManager parserManager;

public LogicManager(Storage storageFile, Model model) {
public LogicManager(Storage storageFile) throws Exception {
this.storageFile = storageFile;
this.model = model;
this.model = new ModelManager(storageFile.load());
this.history = new CommandHistory();
this.parserManager = new ParserManager();
}
Expand All @@ -54,7 +55,7 @@ public CommandResult execute(String userCommandText) throws CommandException, Pa
history.add(userCommandText);
}
try {
storageFile.save(model);
storageFile.save(model.getPlanner());
} catch (StorageFile.StorageOperationException soe) {
throw new CommandException(STORAGE_ERROR + soe, soe);
}
Expand Down
3 changes: 1 addition & 2 deletions src/planmysem/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,14 @@ public AddCommand(Slot slot, Recurrence recurrence) {
public CommandResult execute(Model model, CommandHistory commandHistory) throws CommandException {
Set<LocalDate> dates = recurrence.generateDates(model.getPlanner().getSemester());
Map<LocalDate, Day> days = new TreeMap<>();

for (LocalDate date : dates) {
try {
days.put(date, model.addSlot(date, slot));
} catch (Semester.DateNotFoundException dnfe) {
throw new CommandException(MESSAGE_FAIL_OUT_OF_BOUNDS);
}
}

model.commit();
return new CommandResult(String.format(MESSAGE_SUCCESS, dates.size(),
craftSuccessMessage(days, slot)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/planmysem/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public CommandResult execute(Model model, CommandHistory commandHistory) throws
throw new CommandException(Messages.MESSAGE_INVALID_SLOT_DISPLAYED_INDEX);
}
}

model.commit();
return new CommandResult(String.format(MESSAGE_SUCCESS,
selectedSlots.size(), messageSelected, messageSlots));
}
Expand Down
2 changes: 1 addition & 1 deletion src/planmysem/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public CommandResult execute(Model model, CommandHistory commandHistory) throws
throw new CommandException(Messages.MESSAGE_INVALID_SLOT_DISPLAYED_INDEX);
}
}

model.commit();
return new CommandResult(String.format(MESSAGE_SUCCESS, selectedSlots.size(),
messageSelected, messageSlots));
}
Expand Down
3 changes: 2 additions & 1 deletion src/planmysem/logic/commands/RedoCommand.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@@author marcus-pzj
package planmysem.logic.commands;

import static java.util.Objects.requireNonNull;
Expand All @@ -7,7 +8,7 @@
import planmysem.model.Model;

/**
* Reverts the {@code model}'s address book to its previously undone state.
* Reverts the {@code model}'s planner to its previously undone state.
*/
public class RedoCommand extends Command {

Expand Down
3 changes: 2 additions & 1 deletion src/planmysem/logic/commands/UndoCommand.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@@author marcus-pzj
package planmysem.logic.commands;

import static java.util.Objects.requireNonNull;
Expand All @@ -7,7 +8,7 @@
import planmysem.model.Model;

/**
* Reverts the {@code model}'s address book to its previous state.
* Reverts the {@code model}'s planner to its previous state.
*/
public class UndoCommand extends Command {

Expand Down
16 changes: 8 additions & 8 deletions src/planmysem/model/VersionedPlanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;

/**
* {@code AddressBook} that keeps track of its own history.
* {@code Planner} that keeps track of its own history.
*/
public class VersionedPlanner extends Planner {

Expand All @@ -20,7 +20,7 @@ public VersionedPlanner(ReadOnlyPlanner initialState) {
}

/**
* Saves a copy of the current {@code AddressBook} state at the end of the state list.
* Saves a copy of the current {@code Planner} state at the end of the state list.
* Undone states are removed from the state list.
*/
public void commit() {
Expand All @@ -34,7 +34,7 @@ private void removeStatesAfterCurrentPointer() {
}

/**
* Restores the address book to its previous state.
* Restores the planner to its previous state.
*/
public void undo() {
if (!canUndo()) {
Expand All @@ -45,7 +45,7 @@ public void undo() {
}

/**
* Restores the address book to its previously undone state.
* Restores the planner to its previously undone state.
*/
public void redo() {
if (!canRedo()) {
Expand All @@ -56,14 +56,14 @@ public void redo() {
}

/**
* Returns true if {@code undo()} has address book states to undo.
* Returns true if {@code undo()} has planner states to undo.
*/
public boolean canUndo() {
return currentStatePointer > 0;
}

/**
* Returns true if {@code redo()} has address book states to redo.
* Returns true if {@code redo()} has planner states to redo.
*/
public boolean canRedo() {
return currentStatePointer < plannerListState.size() - 1;
Expand Down Expand Up @@ -94,7 +94,7 @@ public boolean equals(Object other) {
*/
public static class NoUndoableStateException extends RuntimeException {
private NoUndoableStateException() {
super("Current state pointer at start of addressBookState list, unable to undo.");
super("Current state pointer at start of plannerState list, unable to undo.");
}
}

Expand All @@ -103,7 +103,7 @@ private NoUndoableStateException() {
*/
public static class NoRedoableStateException extends RuntimeException {
private NoRedoableStateException() {
super("Current state pointer at end of addressBookState list, unable to redo.");
super("Current state pointer at end of plannerState list, unable to redo.");
}
}
}
6 changes: 3 additions & 3 deletions src/planmysem/model/semester/Day.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Day(ReadOnlyDay day) {
this.dayOfWeek = day.getDayOfWeek();
this.type = day.getType();
for (Slot slot : day.getSlots()) {
this.slots.add(slot);
this.slots.add(new Slot(slot));
}
}

Expand All @@ -38,15 +38,15 @@ public Day(DayOfWeek dayOfWeek, String weekType, ArrayList<Slot> slots) {
this.type = weekType;

for (Slot slot : slots) {
this.slots.add(slot);
this.slots.add(new Slot(slot));
}
}

/**
* Add a slot to the day.
*/
public void addSlot(Slot slot) {
slots.add(slot);
slots.add(new Slot(slot));
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/planmysem/model/semester/Semester.java
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,10 @@ public String getAcademicYear() {
@Override
public void setDays(HashMap<LocalDate, Day> days) {
this.days.clear();
this.days.putAll(days);

for (Map.Entry<LocalDate, Day> entry : days.entrySet()) {
this.days.put(entry.getKey(), new Day(entry.getValue()));
}
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/planmysem/storage/Storage.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package planmysem.storage;

import planmysem.common.exceptions.IllegalValueException;
import planmysem.model.Model;
import planmysem.model.Planner;

/**
* API of the Logic component
Expand All @@ -13,14 +13,14 @@ public interface Storage {
*
* @throws StorageFile.StorageOperationException if there were errors converting and/or storing model to file.
*/
void save(Model model) throws StorageFile.StorageOperationException;
void save(Planner planner) throws StorageFile.StorageOperationException;

/**
* Loads model from this storage file.
*
* @throws StorageFile.StorageOperationException if there were errors reading and/or converting model from file.
*/
Model load() throws StorageFile.StorageOperationException;
Planner load() throws StorageFile.StorageOperationException;

/**
* Gets path of file.
Expand Down
13 changes: 6 additions & 7 deletions src/planmysem/storage/StorageFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import javax.xml.bind.Unmarshaller;

import planmysem.common.exceptions.IllegalValueException;
import planmysem.model.Model;
import planmysem.model.ModelManager;
import planmysem.model.Planner;
import planmysem.storage.jaxb.AdaptedPlanner;

/**
Expand Down Expand Up @@ -70,14 +69,14 @@ private static boolean isValidPath(Path filePath) {
}

@Override
public void save(Model model) throws StorageOperationException {
public void save(Planner planner) throws StorageOperationException {
/* Note: Note the 'try with resource' statement below.
* More info: https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
*/
try (final Writer fileWriter =
new BufferedWriter(new FileWriter(path.toFile()))) {

final AdaptedPlanner toSave = new AdaptedPlanner(model.getPlanner());
final AdaptedPlanner toSave = new AdaptedPlanner(planner);
final Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
if (isEncrypted) {
Expand All @@ -96,7 +95,7 @@ public void save(Model model) throws StorageOperationException {
}

@Override
public Model load() throws StorageOperationException {
public Planner load() throws StorageOperationException {
try (final BufferedReader fileReader =
new BufferedReader(new FileReader(path.toFile()))) {

Expand All @@ -114,7 +113,7 @@ public Model load() throws StorageOperationException {
if (loaded.isAnyRequiredFieldMissing()) {
throw new StorageOperationException("File model missing some elements");
}
return new ModelManager(loaded.toModelType());
return loaded.toModelType();

/* Note: Here, we are using an exception to create the file if it is missing or empty. However, we should
* minimize using exceptions to facilitate normal paths of execution. If we consider the missing file as a
Expand All @@ -123,7 +122,7 @@ public Model load() throws StorageOperationException {

// create empty file if not found or is empty
} catch (FileNotFoundException | NullPointerException ex) {
final Model empty = new ModelManager();
final Planner empty = new Planner();
save(empty);
return empty;

Expand Down
3 changes: 2 additions & 1 deletion src/planmysem/storage/jaxb/AdaptedSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public boolean isAnyRequiredFieldMissing() {
* @throws IllegalValueException if there were any model constraints violated in the IcsSemester
*/
public Slot toModelType() throws IllegalValueException {
if (hasIllegalValues(name) || hasIllegalValues(location) || hasIllegalValues(description) || duration < 0) {
if ((name != null && hasIllegalValues(name)) || (location != null && hasIllegalValues(location))
|| (description != null && hasIllegalValues(description)) || duration < 0) {
throw new IllegalValueException(MESSAGE_ILLEGAL_VALUE);
}

Expand Down
1 change: 0 additions & 1 deletion test/java/planmysem/logic/Commands/AddCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public void clearLastShownList() {

@Override
public void commit() {
throw new AssertionError("This method should not be called.");
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions test/java/planmysem/logic/Commands/DeleteCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public void execute_validTag_success() {

expectedModel.removeSlot(pair3);
expectedModel.removeSlot(pair4);
expectedModel.commit();

assertCommandSuccess(deleteCommand, model, commandHistory, expectedMessage, expectedModel);
}
Expand All @@ -147,6 +148,7 @@ public void execute_validIndex_success() {
Messages.craftSelectedMessage("Deleted Slot:", selectedSlots));

expectedModel.removeSlot(slot);
expectedModel.commit();

assertCommandSuccess(deleteCommand, model, commandHistory, expectedMessage, expectedModel);
}
Expand Down
3 changes: 2 additions & 1 deletion test/java/planmysem/logic/Commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void execute_validTag_success() {
description,
tags
);

expectedModel.commit();
assertCommandSuccess(editCommand, model, commandHistory, expectedMessage, expectedModel);
}

Expand Down Expand Up @@ -269,6 +269,7 @@ public void execute_validIndex_success() {
description,
tags
);
expectedModel.commit();

assertCommandSuccess(editCommand, model, commandHistory, expectedMessage, expectedModel);
}
Expand Down
Loading