Skip to content

Commit

Permalink
Merged upstream into local. Fixed some style errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ParasK26 committed Oct 31, 2018
2 parents d1c5678 + 57e7348 commit f73e5ce
Show file tree
Hide file tree
Showing 136 changed files with 1,899 additions and 3,142 deletions.
Binary file added SourceCode.tar.gz
Binary file not shown.
30 changes: 28 additions & 2 deletions docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,21 @@ _{More to be added}_
*MSS*

1. User requests to list products
2. AddressBook shows a list of products
2. Inventarie PRO shows a list of products
3. User requests to delete a specific product in the list
4. AddressBook deletes the product
4. Inventarie PRO deletes the product
+
Use case ends.

[discrete]
=== Use case: Delete distributor

*MSS*

1. User requests to list distributors
2. Inventarie PRO shows a list of distributors
3. User requests to delete a specific distributor in the list
4. Inventarie PRO deletes the product
+
Use case ends.

Expand Down Expand Up @@ -986,6 +998,20 @@ _{ more test cases ... }_

_{ more test cases ... }_

=== Deleting a distributor

. Deleting a distributor while all distributors are listed

.. Prerequisites: List all distributors using the `listDistributor` command. Multiple products in the list.
.. Test case: `deleteDistributor 1` +
Expected: First contact is deleted from the list. Details of the deleted distributor shown in the status message. Timestamp in the status bar is updated.
.. Test case: `deleteDistributor 0` +
Expected: No distributor is deleted. Error details shown in the status message. Status bar remains the same.
.. Other incorrect delete commands to try: `delete`, `delete x` (where x is larger than the list size) _{give more}_ +
Expected: Similar to previous.

_{ more test cases ... }_

=== Saving data

. Dealing with missing/corrupted data files
Expand Down
20 changes: 11 additions & 9 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Inventarie Pro is for self employed business owners who *prefer to use a desktop

== Quick Start

. Ensure you have Java version 10 or later installed in your Computer.
. Ensure you have Java version 9 installed in your Computer.
. Download the latest inventarie.jar here (link will be added later).
. Copy the file to the folder you want to use as the home folder for your Inventarie Pro.
. Double-click the file to start the app. The GUI should appear in a few seconds.
Expand Down Expand Up @@ -82,7 +82,7 @@ e.g. `deregister u/John p/pass`

Format: `add n/<product name> s/<serial no.> d/<distributor> i/<info.> t/<tags>`

Adds a product to the list of products offered by the store
Adds a product to the list of products offered by the store, and adds the distributor to the list of distributors too if the distributor is not yet added. Distributors:s name is the Primary key.

==== List all products: `inventory`

Expand Down Expand Up @@ -111,15 +111,22 @@ Lists the best selling products in order of the sales revenues from those produc

==== Add a distributor: `addDistributor`

Format: `addDistributor dn/<distributor name> dp/<distributor serialNumber>`
Format: `addDistributor dn/<distributor name> dp/<distributor phone>`

Adds a distributor to the list of distributors engaged with the store.
Adds a distributor to the list of distributors engaged with the store. Distributors should have different names. There should not exist 2 distributors with the same name but different phone numbers.

==== List all distributors: `listDistributors`

Format: `listDistributors`

Provides the list of distributors engaged with the store.

==== Edit a distributor: `editDistributor index`

Format: `editDistributor index dn/<distributor name> dp/<distributor serialNumber>`

Edits details of the indexed distributor from the list of distributors engaged with the store.
Index should be a positive number.

==== Find a distributor: `findDistributor`

Expand All @@ -133,11 +140,6 @@ Format: `deleteDistributor index`

Deletes the indexed distributor from the list of distributors engaged with the store.

==== Find all stored contact information (distributors and customers): `contacts`

Format: `contacts`

This command lists all the contacts in alphabetical order of the first name, and whether they are distributors or customers.
// end::distributormanagement[]

// tag::journal[]
Expand Down
38 changes: 33 additions & 5 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.Logic;
import seedu.address.logic.LogicManager;
import seedu.address.model.DistributorBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.ProductDatabase;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyDistributorBook;
import seedu.address.model.ReadOnlyUserDatabase;
import seedu.address.model.UserDatabase;
import seedu.address.model.UserPrefs;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.model.util.SampleDistributorsUtil;
import seedu.address.model.util.SampleUsersUtil;
import seedu.address.storage.DistributorBookStorage;
import seedu.address.storage.JsonUserPrefsStorage;
import seedu.address.storage.ProductDatabaseStorage;
import seedu.address.storage.SalesHistoryStorage;
import seedu.address.storage.Storage;
import seedu.address.storage.StorageManager;
import seedu.address.storage.UserDatabaseStorage;
import seedu.address.storage.UserPrefsStorage;
import seedu.address.storage.XmlDistributorBookStorage;
import seedu.address.storage.XmlProductDatabaseStorage;
import seedu.address.storage.XmlSalesHistoryStorage;
import seedu.address.storage.XmlUserDatabaseStorage;
Expand Down Expand Up @@ -67,13 +72,19 @@ public void init() throws Exception {
AppParameters appParameters = AppParameters.parse(getParameters());
config = initConfig(appParameters.getConfigPath());

UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath());
UserPrefsStorage userPrefsStorage =
new JsonUserPrefsStorage(config.getUserPrefsFilePath());
userPrefs = initPrefs(userPrefsStorage);
UserDatabaseStorage usersStorage = new XmlUserDatabaseStorage(userPrefs.getUsersFilePath());
UserDatabaseStorage usersStorage =
new XmlUserDatabaseStorage(userPrefs.getUsersFilePath());
ProductDatabaseStorage productDatabaseStorage =
new XmlProductDatabaseStorage(userPrefs.getAddressBookFilePath());
SalesHistoryStorage salesHistoryStorage = new XmlSalesHistoryStorage(userPrefs.getSalesHistoryFilePath());
storage = new StorageManager(productDatabaseStorage, userPrefsStorage, usersStorage, salesHistoryStorage);
SalesHistoryStorage salesHistoryStorage =
new XmlSalesHistoryStorage(userPrefs.getSalesHistoryFilePath());
DistributorBookStorage distributorBookStorage =
new XmlDistributorBookStorage(userPrefs.getDistributorBookFilePath());
storage = new StorageManager(productDatabaseStorage, distributorBookStorage,
userPrefsStorage, usersStorage, salesHistoryStorage);

initLogging(config);

Expand All @@ -96,6 +107,8 @@ private Model initModelManager(Storage storage, UserPrefs userPrefs) {
ReadOnlyAddressBook initialData;
Optional<ReadOnlyUserDatabase> userDatabaseOptional;
ReadOnlyUserDatabase initialUsers;
Optional<ReadOnlyDistributorBook> distributorBookOptional;
ReadOnlyDistributorBook initialDist;
try {
userDatabaseOptional = storage.readUserDatabase();
if (!userDatabaseOptional.isPresent()) {
Expand Down Expand Up @@ -123,7 +136,21 @@ private Model initModelManager(Storage storage, UserPrefs userPrefs) {
initialData = new ProductDatabase();
}

return new ModelManager(initialData, userPrefs, initialUsers, this.storage);
try {
distributorBookOptional = storage.readDistributorBook();
if (!distributorBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample DistributorBook");
}
initialDist = distributorBookOptional.orElseGet(SampleDistributorsUtil::getSampleDistributorBook);
} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty DistributorBook");
initialDist = new DistributorBook();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty DistributorBook");
initialDist = new DistributorBook();
}

return new ModelManager(initialData, initialDist, userPrefs, initialUsers, this.storage);
}

private void initLogging(Config config) {
Expand Down Expand Up @@ -184,6 +211,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {
+ "Using default user prefs");
initializedPrefs = new UserPrefs();
} catch (IOException e) {

logger.warning("Problem while reading from the file. Will be starting with an empty ProductDatabase");
initializedPrefs = new UserPrefs();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class GuiSettings implements Serializable {

private static final double DEFAULT_HEIGHT = 600;
private static final double DEFAULT_WIDTH = 740;
private static final double DEFAULT_WIDTH = 750;

private Double windowWidth;
private Double windowHeight;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/LogsCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class LogsCenter {
private static final int MAX_FILE_COUNT = 5;
private static final int MAX_FILE_SIZE_IN_BYTES = (int) (Math.pow(2, 20) * 5); // 5MB
private static final String LOG_FILE = "addressbook.log";
private static final String LOG_FILE = "inventarie.log";
private static Level currentLogLevel = Level.INFO;
private static final Logger logger = LogsCenter.getLogger(LogsCenter.class);
private static FileHandler fileHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public AddressBookChangedEvent(ReadOnlyAddressBook data) {

@Override
public String toString() {
return "number of products " + data.getPersonList().size()
+ "number of distributors " + data.getDistributorList().size();
return "number of products " + data.getProductList().size();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package seedu.address.commons.events.model;

import seedu.address.commons.events.BaseEvent;
import seedu.address.model.ReadOnlyDistributorBook;

/** Indicates the AddressBook in the model has changed*/
public class DistributorBookChangedEvent extends BaseEvent {

public final ReadOnlyDistributorBook data;

public DistributorBookChangedEvent(ReadOnlyDistributorBook data) {
this.data = data;
}

@Override
public String toString() {
return "number of distributors " + data.getDistributorList().size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import seedu.address.model.distributor.Distributor;

/**
* Represents a selection change in the Product List Panel
* Represents a selection change in the Distributor List Panel
*/
public class DistributorPanelSelectionChangedEvent extends BaseEvent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
/**
* Represents a selection change in the Product List Panel
*/
public class PersonPanelSelectionChangedEvent extends BaseEvent {
public class ProductPanelSelectionChangedEvent extends BaseEvent {


private final Product newSelection;

public PersonPanelSelectionChangedEvent(Product newSelection) {
public ProductPanelSelectionChangedEvent(Product newSelection) {
this.newSelection = newSelection;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface Logic {
CommandResult execute(String commandText) throws CommandException, ParseException;

/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Product> getFilteredPersonList();
ObservableList<Product> getFilteredProductList();

/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Distributor> getFilteredDistributorList();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public ObservableList<Distributor> getFilteredDistributorList() {
}

@Override
public ObservableList<Product> getFilteredPersonList() {
return model.getFilteredPersonList();
public ObservableList<Product> getFilteredProductList() {
return model.getFilteredProductList();
}

@Override
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AddCommand extends Command {
+ PREFIX_TAG + "fruit ";

public static final String MESSAGE_SUCCESS = "New product added: %1$s";
public static final String MESSAGE_DUPLICATE_PRODUCT = "This product already exists in the Product list";
public static final String MESSAGE_DUPLICATE_PRODUCT = "A product with the same serialnumber already exists";


private final Product toAdd;
Expand All @@ -61,8 +61,13 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
}

model.addPerson(toAdd);
model.addDistributor(distToAdd);

if (!(model.hasDistributor(distToAdd))) {
model.addDistributor(distToAdd);
}

model.commitAddressBook();
model.commitDistributorBook();
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
//import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
//import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DIST_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DIST_PHONE;
//import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
// import seedu.address.model.product.Person;
import seedu.address.model.distributor.Distributor;

/**
Expand Down Expand Up @@ -50,7 +46,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
}

model.addDistributor(toAdd);
model.commitAddressBook();
model.commitDistributorBook();
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public DeleteCommand(Index targetIndex) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
List<Product> lastShownList = model.getFilteredPersonList();
List<Product> lastShownList = model.getFilteredProductList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

Distributor distributorToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteDistributor(distributorToDelete);
model.commitAddressBook();
model.commitDistributorBook();
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, distributorToDelete));
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class EditCommand extends Command {

public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Product: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_DUPLICATE_PERSON = "This product already exists in the product list.";
public static final String MESSAGE_DUPLICATE_PRODUCT = "A product with the same serialnumber already exists.";

private final Index index;
private final EditPersonDescriptor editPersonDescriptor;
Expand All @@ -71,7 +71,7 @@ public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
List<Product> lastShownList = model.getFilteredPersonList();
List<Product> lastShownList = model.getFilteredProductList();

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
Expand All @@ -80,12 +80,12 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
Product productToEdit = lastShownList.get(index.getZeroBased());
Product editedProduct = createEditedPerson(productToEdit, editPersonDescriptor);

if (!productToEdit.isSamePerson(editedProduct) && model.hasPerson(editedProduct)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
if (!productToEdit.isSameProduct(editedProduct) && model.hasPerson(editedProduct)) {
throw new CommandException(MESSAGE_DUPLICATE_PRODUCT);
}

model.updatePerson(productToEdit, editedProduct);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.updateFilteredProductList(PREDICATE_SHOW_ALL_PERSONS);
model.commitAddressBook();
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedProduct));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

model.updateDistributor(distributorToEdit, editedDistributor);
model.updateFilteredDistributorList(PREDICATE_SHOW_ALL_DISTRIBUTORS);
model.commitAddressBook();
model.commitDistributorBook();
return new CommandResult(String.format(MESSAGE_EDIT_DISTRIBUTOR_SUCCESS, editedDistributor));
}

Expand Down
Loading

0 comments on commit f73e5ce

Please sign in to comment.