/* @@author A0135769N */
package seedu.tasklist.logic.commands;
import java.io.IOException;
import org.json.JSONException;
import org.json.simple.parser.ParseException;

import seedu.tasklist.storage.Storage;

public class SetStorageCommand extends Command {
	public static final String COMMAND_WORD = "setstorage";

	public static final String MESSAGE_USAGE = COMMAND_WORD
			+ ": Sets the storage file path\n"
			+ "Parameters: [store][valid file path]\n"
			+ "Example: " + COMMAND_WORD + " src/main/java/seedu/tasklist/logic/commands/tasklist.xml";

	public static final String MESSAGE_SUCCESS = "Changed file path to: ";
	public static final String MESSAGE_STORAGE_FAILURE = "File path not found. Please enter a valid file path.";
    
	protected Storage storage;
	private static String filePath;
	
	public SetStorageCommand(String path){
		filePath = path;

	}

	public CommandResult execute() throws IOException, JSONException, ParseException {
		assert model != null;
		model.changeFileStorage(filePath);
		return new CommandResult(String.format(MESSAGE_SUCCESS + filePath));
	}
}

@@ -18,16 +18,17 @@
 769N */%0A
+%0A
 package 
@@ -58,16 +58,37 @@
 mmands;%0A
+import java.io.File;%0A
 import j
@@ -184,17 +184,16 @@
 eption;%0A
-%0A
 import s
@@ -330,17 +330,16 @@
 orage%22;%0A
-%0A
 %09public 
@@ -566,17 +566,16 @@
 t.xml%22;%0A
-%0A
 %09public 
@@ -752,13 +752,8 @@
 .%22;%0A
-    %0A
 %09pro
@@ -809,17 +809,16 @@
 lePath;%0A
-%09
 %0A%09public
@@ -869,17 +869,16 @@
 = path;%0A
-%0A
 %09%7D%0A%0A%09pub
@@ -1024,78 +1024,454 @@
 ;%0A%09%09
-return new CommandResult(String.format(MESSAGE_SUCCESS + filePath));%0A%09%7D%0A%7D%0A
+if(!isValidFilePath(filePath))%0A%09%09%09return new CommandResult(String.format(MESSAGE_STORAGE_FAILURE+%22%22));%0A%09%09else%0A%09%09%09return new CommandResult(String.format(MESSAGE_SUCCESS + filePath));%0A%09%7D%0A%0A%09public boolean isValidFilePath(String filepath)%7B%0A%09%09if(filepath.equals(%22default%22))%7B%0A%09%09%09filepath = %22data/tasklist.xml%22;%0A%09%09%7D%0A%09%09File targetListFile = new File(filePath);%0A%09%09return filePath.equals(%22default%22)%7C%7CtargetListFile.exists()%7C%7CtargetListFile.isDirectory();%0A%09%7D%0A%0A%7D

fix setstorage