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

Import/Export command #232

Merged
merged 21 commits into from
Nov 6, 2018
Merged

Import/Export command #232

merged 21 commits into from
Nov 6, 2018

Conversation

Scrubbius
Copy link

import commands added on top of the export ones.

@Scrubbius Scrubbius changed the title Import commands Import command Nov 6, 2018
@Scrubbius Scrubbius added the status.Ongoing The issue is currently being worked on. note: remove this label before closing an issue. label Nov 6, 2018
@coveralls
Copy link

coveralls commented Nov 6, 2018

Coverage Status

Coverage decreased (-5.7%) to 65.148% when pulling 5c77c98 on Scrubbius:ImportCommands into f77c7fd on CS2103-AY1819S1-W16-2:master.

@Scrubbius Scrubbius added status.Ready The PR is ready to be reviewed. note: remove this label before merging a PR. and removed status.Ongoing The issue is currently being worked on. note: remove this label before closing an issue. labels Nov 6, 2018
@sharan8 sharan8 self-requested a review November 6, 2018 02:48
@sharan8
Copy link

sharan8 commented Nov 6, 2018

Hey Wen Jun, some thoughts & suggestions:

  1. It might it be worth exploring taking in -csv or -xml as an input parameter for abstracted exportvolunteer and importvolunteer commands instead, and applying the corresponding execution? Felt that this may help reduce duplication of code through applying the concept of abstraction.
  2. The files could perhaps be exported to the user's current working directory instead of Desktop, as this is a portable application and doing so would allow the user to access and manage the files related to the application in a more consolidated manner. This is also what is done in the exportcert command, and thus we may be able to achieve more consistency across the application by doing so. A more specific suggestion would be to export it to a folder in the user's current working directory. Feel free to draw inspiration from my implementation of the exportcert command here.
  3. In order to accommodate duplicate event/volunteer names, the naming of the exported files could be updated to include perhaps the event ID or volunteer ID as well (e.g. <EVENTNAME>_<EVENTID>.csv). With the current implementation, unique events with the same name will have their exported files overwriting each other.

Looking forward to test out how your feature works!


// Setting up file path
File output = new File(System.getProperty("user.home") + "/Desktop/"
+ event.getName().toString() + ".xml");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion to include the event ID here as well, such that the export file name takes the format <EVENTNAME>_<EVENTID>.xml

DOMSource source = new DOMSource(doc);

// Setting up file path
File output = new File(System.getProperty("user.home") + "/Desktop/"
Copy link

@sharan8 sharan8 Nov 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would personally suggest extracting System.getProperty("user.home") + "/Desktop/" out to a field named SAVE_PATH, so as to be able to plug it in multiple places without worrying about errors or having to edit each usage location separately if you wish to update the save path.


try {
createEventXml(model, selectedEvent);
} catch (Exception e) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be useful to find out what type(s) of Exception may result from running this method call, and handling them more specifically

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used it as a blanket statement for now because of possible file creation exceptions when handling the xml transformer and writing throws out to an error at creating the file. I will update the individual exceptions accordingly although they have the same handler

*/
private void createVolunteerCsv(ObservableList<Volunteer> list, ArrayList<Index> index) throws Exception {
// Setting up file path
File output = new File(System.getProperty("user.home") + "/Desktop/"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Desktop might not be a good choice. Better to use relative path


if (!model.hasVolunteer(volunteer)) {
model.addVolunteer(volunteer);
model.commitAddressBook();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the commit here? Placing it here means:

  • When user uses the undo command, it only removes the add of the last volunteer added.
    It is better to put the model.commitAddressBook() method outside. -> When ALL the volunteers have been added.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noted and will update accordingly

public ExportVolunteerXmlCommand parse(String userInput) throws ParseException {
requireNonNull(userInput);

Index index;
Copy link

@Kratious Kratious Nov 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this command only take in 1 volunteer to export in the current state?
Maybe should have a good use case for this command before updating, XML to XML doesn't seem to be a feature that makes sense from the end user perspective.

Copy link
Author

@Scrubbius Scrubbius Nov 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current state takes in only 1 volunteer, but it calls out all the events this volunteer has participated in and logs the information about these events as well into the xml output. Main focus of this feature is to list all the events a volunteer has participated as an export.


try {
createVolunteerCsv(model.getFilteredVolunteerList(), index);
} catch (Exception e) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like Sharan mentioned, should handle specific exceptions instead of using a catch all Exception

// Setting up writer & stringbuilder for appending
PrintWriter pw = new PrintWriter(output);
StringBuilder sb = new StringBuilder();
String csvSplit = ",";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to test this with fields that could contain commas, like Address

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assumption on the csv entries dont have characters which messes with the tuple splits, like comma (,)and bracer ("").

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not work under this assumption. Users should be allowed to enter commas for addresses. Try to find a way to clean the input. Maybe this link would be helpful.

https://stackoverflow.com/questions/4617935/is-there-a-way-to-include-commas-in-csv-columns-without-breaking-the-formatting

sharan8 and others added 3 commits November 6, 2018 12:30
…nd.java

Co-Authored-By: Scrubbius <36285531+Scrubbius@users.noreply.github.com>
…ommand.java

Co-Authored-By: Scrubbius <36285531+Scrubbius@users.noreply.github.com>
…ommand.java

Co-Authored-By: Scrubbius <36285531+Scrubbius@users.noreply.github.com>
@Scrubbius Scrubbius added status.Ongoing The issue is currently being worked on. note: remove this label before closing an issue. and removed status.Ready The PR is ready to be reviewed. note: remove this label before merging a PR. labels Nov 6, 2018
ExportEventXml now has event ID on part of the filename
File directory created for the specific exports as well with the desktop as a fall-back
@Scrubbius
Copy link
Author

Not going to split the export command into -csv and -xml as part of the parameters since the xml command takes in only 1 volunteer at a time while the csv command merges all into one file.

Maybe the xml variant can be updated in the future to take in more than one volunteer index and produce the files accordingly but for now it is an auxiliary command for individual information exporting.

@Scrubbius Scrubbius added status.Ready The PR is ready to be reviewed. note: remove this label before merging a PR. and removed status.Ongoing The issue is currently being worked on. note: remove this label before closing an issue. labels Nov 6, 2018
@Scrubbius Scrubbius changed the title Import command Import/Export command Nov 6, 2018
@iMarbles iMarbles merged commit ce6a42d into CS2103-AY1819S1-W16-2:master Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status.Ready The PR is ready to be reviewed. note: remove this label before merging a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants