Skip to content

Commit

Permalink
Merge branch 'master' into feature-block-content-edit-view
Browse files Browse the repository at this point in the history
  • Loading branch information
HemanshuGandhi authored Apr 10, 2020
2 parents 3f2659b + 08a9401 commit 962adaa
Show file tree
Hide file tree
Showing 44 changed files with 981 additions and 1,398 deletions.
9 changes: 9 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
coverage:
precision: 2
round: down
range: "60...100"
status:
project:
default:
threshold: 3%

4 changes: 2 additions & 2 deletions src/main/java/com/notably/commons/path/AbsolutePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import java.util.stream.Collectors;

import com.notably.commons.path.exceptions.InvalidPathException;
import com.notably.model.block.Title;

/**
* Represents the Path to a Block, starting from the Root node.
*/
public class AbsolutePath implements Path {
public static final String INVALID_ABSOLUTE_PATH = "Invalid absolute path";
public static final String VALIDATION_REGEX = "\\/|(\\/([a-zA-Z0-9]+\\s+)*[a-zA-Z0-9]+)+\\/?";
public static final AbsolutePath TO_ROOT_PATH = new AbsolutePath("/");
public static final String VALIDATION_REGEX = "\\/|(\\/" + Title.VALIDATION_REGEX + ")+\\/?";

private final List<String> components;

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/notably/commons/path/RelativePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import java.util.Objects;

import com.notably.commons.path.exceptions.InvalidPathException;
import com.notably.model.block.Title;

/**
* Represents a path to the block relative to the current directory.
*/
public class RelativePath implements Path {
public static final String INVALID_RELATIVE_PATH = "Invalid relative path";
public static final String VALIDATION_REGEX = "(\\.|\\..|([a-zA-Z0-9]+\\s+)*[a-zA-Z0-9]+)"
+ "(\\/(\\.|\\..|([a-zA-Z0-9]+\\s+)*[a-zA-Z0-9]+))*\\/?";
public static final String VALIDATION_REGEX =
"(\\.|\\..|" + Title.VALIDATION_REGEX + ")(\\/(\\.|\\..|" + Title.VALIDATION_REGEX + "))*\\/?";

private final List<String> components;

Expand Down
7 changes: 0 additions & 7 deletions src/main/java/com/notably/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@
import static java.util.Objects.requireNonNull;

import com.notably.model.Model;
import com.notably.model.block.Body;

/**
* Represent a command that edits the block's body.
*/
public class EditCommand extends Command {
public static final String COMMAND_WORD = "edit";
public static final String COMMAND_SHORTHAND = "e";
private final Body body;

public EditCommand(Body body) {
requireNonNull(body);
this.body = body;
}

/**
* Edit the Block body of the current directory.
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/com/notably/logic/commands/NewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.util.Objects.requireNonNull;

import com.notably.commons.path.AbsolutePath;
import com.notably.logic.commands.exceptions.CommandException;
import com.notably.model.Model;
import com.notably.model.block.Block;
Expand All @@ -15,12 +14,10 @@ public class NewCommand extends Command {
public static final String COMMAND_WORD = "new";
public static final String COMMAND_SHORTHAND = "n";
private final Block toAdd;
private AbsolutePath path;

public NewCommand(Block block, AbsolutePath path) {
public NewCommand(Block block) {
requireNonNull(block);
this.toAdd = block;
this.path = path;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@ public class DeleteSuggestionCommand implements SuggestionCommand {
public DeleteSuggestionCommand(AbsolutePath path, String oldTitle) {
Objects.requireNonNull(path);
Objects.requireNonNull(oldTitle);

if (oldTitle.isBlank()) {
throw new IllegalArgumentException("The old title must contain at least one element");
}

this.path = path;
this.oldTitle = oldTitle;
}

@Override
public void execute(Model model) {
// Nullity check
Objects.requireNonNull(model);

if (!oldTitle.isEmpty()) {
// Set suggestions
List<AbsolutePath> possiblePaths = getPossiblePaths(path, model);
List<SuggestionItem> suggestions = getSuggestions(possiblePaths, model);
List<AbsolutePath> possiblePaths = getPossiblePaths(path, model);
List<SuggestionItem> suggestions = getSuggestions(possiblePaths, model);

model.setSuggestions(suggestions);
}
model.setSuggestions(suggestions);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@ public class OpenSuggestionCommand implements SuggestionCommand {
public OpenSuggestionCommand(AbsolutePath path, String oldTitle) {
Objects.requireNonNull(path);
Objects.requireNonNull(oldTitle);

if (oldTitle.isBlank()) {
throw new IllegalArgumentException("The old title must contain at least one element");
}

this.path = path;
this.oldTitle = oldTitle;
}

@Override
public void execute(Model model) {
// Nullity check
Objects.requireNonNull(model);

if (!oldTitle.isEmpty()) {
// Set suggestions
List<AbsolutePath> possiblePaths = getPossiblePaths(path, model);
List<SuggestionItem> suggestions = getSuggestions(possiblePaths, model);
List<AbsolutePath> possiblePaths = getPossiblePaths(path, model);
List<SuggestionItem> suggestions = getSuggestions(possiblePaths, model);

model.setSuggestions(suggestions);
}
model.setSuggestions(suggestions);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ public SearchSuggestionCommand(String keyword) {

@Override
public void execute(Model model) {
// Nullity check
Objects.requireNonNull(model);

// Set suggestions
List<SuggestionItem> suggestions = traverseTree(model);

model.setSuggestions(suggestions);
}

Expand Down Expand Up @@ -69,7 +66,8 @@ private List<SuggestionItem> traverseTree(Model model) {
and setting action to open that particular block when the user chooses that suggestion. */
String bodyLowerCase = blockBody.toLowerCase();
if (bodyLowerCase.contains(keyword.toLowerCase())) {
String[] blockBodies = bodyLowerCase.split(keyword, -1);
String[] blockBodies = bodyLowerCase.split(keyword.toLowerCase(), -1);

int frequency = blockBodies.length - 1;
String displayText = absolutePath.getStringRepresentation();
Runnable action = () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public CorrectionResult<AbsolutePath> correct(AbsolutePath uncorrected) {
return new CorrectionResult<>(CorrectionStatus.FAILED);
}

if (correctedItems.equals(List.of(uncorrected))) {
return new CorrectionResult<>(CorrectionStatus.UNCHANGED, List.of(uncorrected));
if (correctedItems.size() == 1 && correctedItems.get(0).equals(uncorrected)) {
return new CorrectionResult<>(CorrectionStatus.UNCHANGED, correctedItems);
}

return new CorrectionResult<>(CorrectionStatus.CORRECTED, correctedItems);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public CorrectionResult<String> correct(String uncorrected) {
return new CorrectionResult<>(CorrectionStatus.FAILED);
}

if (correctedItems.equals(List.of(uncorrected))) {
return new CorrectionResult<>(CorrectionStatus.UNCHANGED, List.of(uncorrected));
if (correctedItems.size() == 1 && correctedItems.get(0).equalsIgnoreCase(uncorrected)) {
return new CorrectionResult<>(CorrectionStatus.UNCHANGED, correctedItems);
}

return new CorrectionResult<String>(CorrectionStatus.CORRECTED, correctedItems);
Expand Down
40 changes: 0 additions & 40 deletions src/main/java/com/notably/logic/parser/EditCommandParser.java

This file was deleted.

6 changes: 2 additions & 4 deletions src/main/java/com/notably/logic/parser/NewCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public List<Command> parse(String args) throws ParseException {
throw new ParseException(String.format("Invalid Command"));
}


String title = argMultimap.getValue(PREFIX_TITLE).get();
String body;
if (!ParserUtil.arePrefixesPresent(argMultimap, PREFIX_BODY)) {
Expand All @@ -51,7 +50,6 @@ public List<Command> parse(String args) throws ParseException {
body = argMultimap.getValue(PREFIX_BODY).get();
}

AbsolutePath path = ParserUtil.createAbsolutePath(title, notablyModel.getCurrentlyOpenPath());
Block block;
try {
block = new BlockImpl(new Title(title), new Body(body));
Expand All @@ -60,15 +58,15 @@ public List<Command> parse(String args) throws ParseException {
}

List<Command> commands = new ArrayList<>();
commands.add(new NewCommand(block, path));
commands.add(new NewCommand(block));

if (!ParserUtil.arePrefixesPresent(argMultimap, PREFIX_JUMP)) {
return commands;
}

AbsolutePath path = ParserUtil.createAbsolutePath(title, notablyModel.getCurrentlyOpenPath());
commands.add(new OpenCommand(path));
return commands;

}

}
2 changes: 1 addition & 1 deletion src/main/java/com/notably/logic/parser/NotablyParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public List<? extends Command> parseCommand(String userInput) throws ParseExcept

case EditCommand.COMMAND_WORD:
case EditCommand.COMMAND_SHORTHAND:
return new EditCommandParser().parse(arguments);
return List.of(new EditCommand());

case HelpCommand.COMMAND_WORD:
case HelpCommand.COMMAND_SHORTHAND:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class DeleteSuggestionCommandParser implements SuggestionCommandParser<De

private static final String RESPONSE_MESSAGE = "Delete a note";
private static final String RESPONSE_MESSAGE_WITH_TITLE = "Delete a note titled \"%s\"";
private static final String RESPONSE_MESSAGE_CANNOT_DELETE_NOTE = "Cannot delete \"%s\". Invalid path.";
private static final String ERROR_MESSAGE_CANNOT_DELETE_NOTE = "Cannot delete \"%s\" as it is an invalid path";

private Model model;
private CorrectionEngine<AbsolutePath> pathCorrectionEngine;
Expand Down Expand Up @@ -61,7 +61,7 @@ public Optional<DeleteSuggestionCommand> parse(String userInput) {
try {
uncorrectedPath = ParserUtil.createAbsolutePath(title, model.getCurrentlyOpenPath());
} catch (ParseException pe) {
model.setResponseText(String.format(RESPONSE_MESSAGE_CANNOT_DELETE_NOTE, title));
model.setResponseText(String.format(ERROR_MESSAGE_CANNOT_DELETE_NOTE, title));
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Represents a parser for the command word "edit".
*/
public class ErrorSuggestionCommandParser implements SuggestionCommandParser<SuggestionCommand> {
private static final String ERROR_MESSAGE = "\"%s\" is an invalid command format. "
private static final String ERROR_MESSAGE_INVALID_COMMAND = "\"%s\" is an invalid command format. "
+ "To see the list of available commands, type: help";

private Model model;
Expand All @@ -20,7 +20,7 @@ public ErrorSuggestionCommandParser(Model model) {

@Override
public Optional<SuggestionCommand> parse(String userInput) {
model.setResponseText(String.format(ERROR_MESSAGE, userInput));
model.setResponseText(String.format(ERROR_MESSAGE_INVALID_COMMAND, userInput));
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.notably.logic.parser.suggestion;

import static com.notably.logic.parser.CliSyntax.PREFIX_BODY;
import static com.notably.logic.parser.CliSyntax.PREFIX_JUMP;
import static com.notably.logic.parser.CliSyntax.PREFIX_TITLE;

Expand All @@ -10,8 +9,8 @@
import com.notably.logic.parser.ArgumentMultimap;
import com.notably.logic.parser.ArgumentTokenizer;
import com.notably.logic.parser.ParserUtil;
import com.notably.logic.parser.exceptions.ParseException;
import com.notably.model.Model;
import com.notably.model.block.Title;

/**
* Represents a Parser for New Command.
Expand All @@ -22,31 +21,43 @@ public class NewSuggestionCommandParser implements SuggestionCommandParser<Sugge
private static final String RESPONSE_MESSAGE = "Create a new note";
private static final String RESPONSE_MESSAGE_WITH_TITLE = "Create a new note titled \"%s\".";
private static final String RESPONSE_MESSAGE_WITH_TITLE_AND_OPEN = "Create a new note titled \"%s\" and open it.";
private static final String ERROR_MESSAGE_INVALID_COMMAND = "\"%s\" is an invalid creation format. "
+ "The correct format is \"new -t TITLE [-o]\"";
private static final String ERROR_MESSAGE_INVALID_TITLE = "Title \"%s\" is invalid. "
+ "Titles should only contain alphanumeric characters and symbols except - and /";

private Model model;

public NewSuggestionCommandParser(Model model) {
this.model = model;
}

/**
* Parses input and displays the appropriate response text.
*
* @param userInput .
* @return List of command to execute.
* @throws ParseException when input is invalid.
* @return Optional.empty()
*/
public Optional<SuggestionCommand> parse(String userInput) {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(userInput, PREFIX_TITLE, PREFIX_BODY, PREFIX_JUMP);
ArgumentTokenizer.tokenize(userInput, PREFIX_TITLE, PREFIX_JUMP);

if (userInput.isBlank()) {
model.setResponseText(RESPONSE_MESSAGE);
return Optional.empty();
}

String title;
if (!ParserUtil.arePrefixesPresent(argMultimap, PREFIX_TITLE)
|| !argMultimap.getPreamble().isEmpty()) {
title = userInput.trim();
} else {
title = argMultimap.getValue(PREFIX_TITLE).get();
model.setResponseText(String.format(ERROR_MESSAGE_INVALID_COMMAND, model.getInput()));
return Optional.empty();
}

if (title.isBlank()) {
String title = argMultimap.getValue(PREFIX_TITLE).get();

if (!Title.isValidTitle(title) && !title.isBlank()) {
model.setResponseText(String.format(ERROR_MESSAGE_INVALID_TITLE, title));
} else if (title.isBlank()) {
model.setResponseText(RESPONSE_MESSAGE);
} else if (!ParserUtil.arePrefixesPresent(argMultimap, PREFIX_JUMP)) { // If user does NOT type "-o"
model.setResponseText(String.format(RESPONSE_MESSAGE_WITH_TITLE, title));
Expand Down
Loading

0 comments on commit 962adaa

Please sign in to comment.