Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #84 from Cloud7050/rename
Browse files Browse the repository at this point in the history
Big refactor
  • Loading branch information
bwangpj authored Oct 20, 2023
2 parents 7dd1ee4 + 233040d commit 0157a33
Show file tree
Hide file tree
Showing 136 changed files with 1,790 additions and 2,593 deletions.
28 changes: 13 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
# Gradle build files
/.gradle/
/build/
src/main/resources/docs/
# macOS Finder files
.DS_Store

# IDEA files
/.idea/
/out/
/*.iml

# VSCode extension build files
bin/
/bin/

# JVM crash logs
/hs_err_pid[0-9]*.log

# Gradle build files
/.gradle/
/build/
/src/main/resources/docs/

# Storage/log files
# App data/log files
/data/
/config.json
/preferences.json
/settings.json
/*.log.*
hs_err_pid[0-9]*.log

# Test sandbox files
src/test/data/sandbox/

# MacOS custom attributes files created by Finder
.DS_Store
docs/_site/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ For information as well as detailed user/developer documentation, check out the

![UI](./docs/images/Ui.png)

This project is based on the AddressBook-Level3 project created by the [SE-EDU initiative](https://se-education.org).
This project is based on the AddressBook-Level3 project created by the [SE-EDU initiative](https://se-education.org).
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ checkstyle {
}

shadowJar {
archiveFileName = 'ConText.jar'
archiveFileName = 'context.jar'
}
8 changes: 1 addition & 7 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
<property name="lineSeparator" value="lf_cr_crlf"/>
</module>

<module name="RegexpSingleline">
<!-- Checks that FIXME is not used in comments. TODO is preferred. -->
<property name="format" value="((//.*)|(\*.*))FIXME" />
<property name="message" value='TODO is preferred to FIXME."' />
</module>

<module name="SuppressionFilter">
<property name="file" value="${config_loc}/suppressions.xml"/>
</module>
Expand Down Expand Up @@ -94,7 +88,7 @@
</module>

<module name="TypeName">
<!-- Validates static, final fields against the expression "^[A-Z][a-zA-Z0-9]*$". -->
<!-- Validates type names against the expression "^[A-Z][a-zA-Z0-9]*$". -->
<metadata name="altname" value="TypeName"/>
<property name="severity" value="warning"/>
</module>
Expand Down
9 changes: 0 additions & 9 deletions copyright.txt

This file was deleted.

4 changes: 3 additions & 1 deletion docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ title: Developer Guide

## **Acknowledgements**

* {list here sources of all reused/adapted ideas, code, documentation, and third-party libraries -- include links to the original source as well}
- Libraries: [JavaFX](https://openjfx.io/), [Jackson](https://github.com/FasterXML/jackson), [JUnit5](https://github.com/junit-team/junit5)
- App icon from http://www.mcdodesign.com/ by Susumu Yoshida
- Some code adapted from http://code.makery.ch/library/javafx-8-tutorial/ by Marco Jakob

---

Expand Down
1 change: 0 additions & 1 deletion docs/_sass/minima/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,3 @@ table {
font-size: 32px;
}
}

1 change: 0 additions & 1 deletion docs/_sass/minima/custom-styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ h2, h3, h4, h5, h6 {
@include alert-variant(color-level($value, $alert-bg-level), color-level($value, $alert-border-level), color-level($value, $alert-color-level));
}
}

6 changes: 4 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ title: ConText

![UI](images/Ui.png)

**ConText is a desktop app designed for NUS SoC students to manage their contacts quickly via text commands.** While it has a GUI, most of its user interactions happen via a CLI (Command Line Interface).

**ConText is a desktop app designed for NUS SoC students to manage their contacts quickly via text commands.**
While it has a GUI, most of its user interactions happen via a CLI (Command Line Interface).

- If you are interested in using ConText, head over to the [_Quick Start_ section of the **User Guide**](./UserGuide.html#quick-start).
- If you are interested about developing ConText, the [**Developer Guide**](./DeveloperGuide.html) is a good place to start.

**Acknowledgements**

- Libraries used: [JavaFX](https://openjfx.io/), [Jackson](https://github.com/FasterXML/jackson), [JUnit5](https://github.com/junit-team/junit5)
- Libraries used: [JavaFX](https://openjfx.io/), [Jackson](https://github.com/FasterXML/jackson), [JUnit5](https://github.com/junit-team/junit5)
188 changes: 106 additions & 82 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import javafx.application.Application;
import javafx.stage.Stage;
import seedu.address.annotation.Nullable;
import seedu.address.commons.core.Config;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.core.Version;
Expand All @@ -15,98 +16,89 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.Logic;
import seedu.address.logic.LogicManager;
import seedu.address.model.ContactList;
import seedu.address.model.ContactsManager;
import seedu.address.model.Contacts;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.UserPrefs;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.model.ReadOnlyContacts;
import seedu.address.model.ReadOnlySettings;
import seedu.address.model.Settings;
import seedu.address.model.util.SampleContactsUtil;
import seedu.address.storage.ContactsStorage;
import seedu.address.storage.JsonContactsStorage;
import seedu.address.storage.JsonUserPrefsStorage;
import seedu.address.storage.JsonSettingsStorage;
import seedu.address.storage.SettingsStorage;
import seedu.address.storage.Storage;
import seedu.address.storage.StorageManager;
import seedu.address.storage.UserPrefsStorage;
import seedu.address.ui.Ui;
import seedu.address.ui.UiManager;



/**
* Runs the application.
* Runs as a JavaFX application.
*/
public class MainApp extends Application {

public static final Version VERSION = new Version(0, 2, 2, true);
public static final String NAME = "ConText";
public static final Version VERSION = new Version(1, 2, 0, false);

private static final Logger logger = LogsCenter.getLogger(MainApp.class);

protected Ui ui;
protected Logic logic;
protected Storage storage;
protected Model model;
protected Config config;
private Config config;

private Ui ui;
private Logic logic;
private Model model;
private Storage storage;

@Override
public void init() throws Exception {
logger.info("=============================[ Initializing ContactsManager ]===========================");
super.init();

AppParameters appParameters = AppParameters.parse(getParameters());
config = initConfig(appParameters.getConfigPath());
initLogging(config);
AppParameters appParameters = AppParameters.parse(this.getParameters());
config = this.initConfig(appParameters.getConfigPath());

this.initLogging(config);

UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath());
UserPrefs userPrefs = initPrefs(userPrefsStorage);
ContactsStorage contactsStorage = new JsonContactsStorage(userPrefs.getConTextFilePath());
storage = new StorageManager(contactsStorage, userPrefsStorage);
SettingsStorage settingsStorage = new JsonSettingsStorage(config.getSettingsPath());
ReadOnlySettings settings = this.initSettings(settingsStorage);

model = initModelManager(storage, userPrefs);
ContactsStorage contactsStorage = new JsonContactsStorage(settings.getContactsPath());
storage = new StorageManager(contactsStorage, settingsStorage);

model = this.initModel(storage, settings);

logic = new LogicManager(model, storage);

ui = new UiManager(logic);
}

/**
* Returns a {@code ModelManager} with the data from {@code storage}'s address book and {@code userPrefs}. <br>
* The data from the sample address book will be used instead if {@code storage}'s address book is not found,
* or an empty address book will be used instead if errors occur when reading {@code storage}'s address book.
*/
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
logger.info("Using data file : " + storage.getConTextFilePath());
@Override
public void start(Stage primaryStage) {
ui.start(primaryStage);
}

Optional<ContactList> contactListOptional;
ContactList initialData;
@Override
public void stop() {
try {
contactListOptional = storage.readContactsManager();
if (!contactListOptional.isPresent()) {
logger.info("Creating a new data file " + storage.getConTextFilePath()
+ " populated with a sample ContactsManager.");
}
initialData = contactListOptional.orElseGet(SampleDataUtil::getSampleContactsManager);
} catch (DataLoadingException e) {
logger.warning("Data file at " + storage.getConTextFilePath() + " could not be loaded."
+ " Will be starting with an empty contactList.");
initialData = new ContactsManager();
storage.saveSettings(model.getSettings());
} catch (IOException e) {
logger.severe(String.format(
"Failed to save settings: %s",
StringUtil.getDetails(e)
));
}

return new ModelManager(initialData, userPrefs);
}

private void initLogging(Config config) {
LogsCenter.init(config);
}

/**
* Returns a {@code Config} using the file at {@code configFilePath}. <br>
* The default file path {@code Config#DEFAULT_CONFIG_FILE} will be used instead
* if {@code configFilePath} is null.
*/
protected Config initConfig(Path configFilePath) {
private Config initConfig(@Nullable Path configFilePath) {
Config initializedConfig;
Path configFilePathUsed;

configFilePathUsed = Config.DEFAULT_CONFIG_FILE;
configFilePathUsed = Config.DEFAULT_PATH;

if (configFilePath != null) {
logger.info("Custom Config file specified " + configFilePath);
Expand All @@ -127,7 +119,7 @@ protected Config initConfig(Path configFilePath) {
initializedConfig = new Config();
}

//Update config file in case it was missing to begin with or there are new/unused fields
// Update config file in case it was missing to begin with or there are new/unused fields
try {
ConfigUtil.saveConfig(initializedConfig, configFilePathUsed);
} catch (IOException e) {
Expand All @@ -136,51 +128,83 @@ protected Config initConfig(Path configFilePath) {
return initializedConfig;
}

private void initLogging(Config config) {
LogsCenter.init(config);
}

/**
* Returns a {@code UserPrefs} using the file at {@code storage}'s user prefs file path,
* or a new {@code UserPrefs} with default configuration if errors occur when
* reading from the file.
* Returns {@link Settings} from reading via the specified
* {@link SettingsStorage}.
*
* If no file is found for the {@link SettingsStorage} or an error occurs
* while trying to read the file, default settings will be populated.
*
* This always resaves the updated file.
*/
protected UserPrefs initPrefs(UserPrefsStorage storage) {
Path prefsFilePath = storage.getUserPrefsFilePath();
logger.info("Using preference file : " + prefsFilePath);

UserPrefs initializedPrefs;
private Settings initSettings(SettingsStorage settingsStorage) {
Path settingsPath = settingsStorage.getSettingsPath();
logger.info(String.format(
"Settings storage path: %s",
settingsPath
));

@Nullable Settings settings = null;
try {
Optional<UserPrefs> prefsOptional = storage.readUserPrefs();
if (!prefsOptional.isPresent()) {
logger.info("Creating new preference file " + prefsFilePath);
Optional<Settings> settingsOptional = settingsStorage.readSettings();
if (settingsOptional.isPresent()) {
settings = settingsOptional.get();
} else {
logger.info("No settings file found, populating with default settings.");
settings = new Settings();
}
initializedPrefs = prefsOptional.orElse(new UserPrefs());
} catch (DataLoadingException e) {
logger.warning("Preference file at " + prefsFilePath + " could not be loaded."
+ " Using default preferences.");
initializedPrefs = new UserPrefs();
logger.warning("Failed to read settings file, populating with default settings.");
settings = new Settings();
}

//Update prefs file in case it was missing to begin with or there are new/unused fields
try {
storage.saveUserPrefs(initializedPrefs);
settingsStorage.saveSettings(settings);
} catch (IOException e) {
logger.warning("Failed to save config file : " + StringUtil.getDetails(e));
logger.severe(String.format(
"Failed to save settings: %s",
StringUtil.getDetails(e)
));
}

return initializedPrefs;
return settings;
}

@Override
public void start(Stage primaryStage) {
logger.info("Starting ContactsManager " + MainApp.VERSION);
ui.start(primaryStage);
}
/**
* Returns a {@link Model} with the {@link ReadOnlyContacts} from reading via the
* specified {@link Storage}, and with the specified
* {@link ReadOnlySettings}.
*
* If no contacts file is found for the {@link Storage}, sample contacts
* will be populated.
*
* If an error occurs while trying to read the file, no contacts will be
* populated.
*/
private Model initModel(Storage storage, ReadOnlySettings settings) {
logger.info(String.format(
"Storage contacts path: %s",
storage.getContactsPath()
));

@Override
public void stop() {
logger.info("============================ [ Stopping Address Book ] =============================");
@Nullable ReadOnlyContacts contacts = null;
try {
storage.saveUserPrefs(model.getUserPrefs());
} catch (IOException e) {
logger.severe("Failed to save preferences " + StringUtil.getDetails(e));
Optional<? extends ReadOnlyContacts> contactsOptional = storage.readContacts();
if (contactsOptional.isPresent()) {
contacts = contactsOptional.get();
} else {
logger.info("No contacts file found, populating with sample contacts.");
contacts = SampleContactsUtil.getSampleContacts();
}
} catch (DataLoadingException e) {
logger.warning("Failed to read contacts file.");
contacts = new Contacts();
}

return new ModelManager(contacts, settings);
}
}
Loading

0 comments on commit 0157a33

Please sign in to comment.