From df6bb71de35bf8d4ab89d8c11f8e49355d59c4bc Mon Sep 17 00:00:00 2001 From: stickycorner Date: Sat, 2 Nov 2024 09:12:52 -0400 Subject: [PATCH 01/56] added new entities --- src/main/java/entity/Event.java | 4 ++++ src/main/java/entity/Note.java | 4 ++++ src/main/java/entity/Task.java | 4 ++++ 3 files changed, 12 insertions(+) create mode 100644 src/main/java/entity/Event.java create mode 100644 src/main/java/entity/Note.java create mode 100644 src/main/java/entity/Task.java diff --git a/src/main/java/entity/Event.java b/src/main/java/entity/Event.java new file mode 100644 index 000000000..14787019d --- /dev/null +++ b/src/main/java/entity/Event.java @@ -0,0 +1,4 @@ +package entity; + +public class Event { +} diff --git a/src/main/java/entity/Note.java b/src/main/java/entity/Note.java new file mode 100644 index 000000000..0729889af --- /dev/null +++ b/src/main/java/entity/Note.java @@ -0,0 +1,4 @@ +package entity; + +public class Note { +} diff --git a/src/main/java/entity/Task.java b/src/main/java/entity/Task.java new file mode 100644 index 000000000..d5553ee03 --- /dev/null +++ b/src/main/java/entity/Task.java @@ -0,0 +1,4 @@ +package entity; + +public class Task { +} From cd8991cd45962b240e9ad7320392b3c1137d8c3e Mon Sep 17 00:00:00 2001 From: stickycorner Date: Sat, 2 Nov 2024 09:13:42 -0400 Subject: [PATCH 02/56] updated entities --- src/main/java/entity/Event.java | 32 ++++++++++++++++++++++++++++++++ src/main/java/entity/Note.java | 19 +++++++++++++++++++ src/main/java/entity/Task.java | 27 +++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/src/main/java/entity/Event.java b/src/main/java/entity/Event.java index 14787019d..8de0dac3f 100644 --- a/src/main/java/entity/Event.java +++ b/src/main/java/entity/Event.java @@ -1,4 +1,36 @@ package entity; +/** + * The representation of a calendar event for our program. + */ public class Event { + + private final String name; + private final String datetime; + private final String location; + private final String notes; + + public Event(String name, String datetime, String location, String notes) { + this.name = name; + this.datetime = datetime; + this.location = location; + this.notes = notes; + } + + public String getEventName() { + return name; + } + + public String getEventDatetime() { + return datetime; + } + + public String getEventLocation() { + return location; + } + + public String getEventNotes() { + return notes; + } + } diff --git a/src/main/java/entity/Note.java b/src/main/java/entity/Note.java index 0729889af..9cd116cfb 100644 --- a/src/main/java/entity/Note.java +++ b/src/main/java/entity/Note.java @@ -1,4 +1,23 @@ package entity; +/** + * The representation of a note file for this program. + */ public class Note { + + private final String content; + private final String creationDate; + + public Note(String content, String creationDate) { + this.content = content; + this.creationDate = creationDate; + } + + public String getContent() { + return content; + } + + public String getCreationDate() { + return creationDate; + } } diff --git a/src/main/java/entity/Task.java b/src/main/java/entity/Task.java index d5553ee03..b8c23b6e7 100644 --- a/src/main/java/entity/Task.java +++ b/src/main/java/entity/Task.java @@ -1,4 +1,31 @@ package entity; +/** + * The representation of a task for this program. + */ public class Task { + + private final String description; + private boolean done; + + public Task(String description) { + this.description = description; + this.done = false; + } + + public String getDescription() { + return description; + } + + public boolean isDone() { + return done; + } + + /** + * Marks the task as completed. + */ + public void markDone() { + done = true; + } + } From 207bd65f77b1e3320eef73b32ff3eb4727755e5b Mon Sep 17 00:00:00 2001 From: stickycorner Date: Mon, 4 Nov 2024 13:18:50 -0500 Subject: [PATCH 03/56] added jenna to readme --- README.md | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/README.md b/README.md index 5e1d8b77c..28b350c7f 100644 --- a/README.md +++ b/README.md @@ -1,36 +1 @@ -# Note Application - -This is a minimal example demonstrating usage of the -password-protected user part of the API used in lab 5. - -You can find more information about the API endpoints in -[the documentation](https://www.postman.com/cloudy-astronaut-813156/csc207-grade-apis-demo/documentation/fg3zkjm/5-password-protected-user). - -If your team is considering an application for which it would be convenient to -store data in something like a database, you may find that the API calls demonstrated -here will be useful in your project, as this will allow you to store -an arbitrary JSON object associated with a username and password. - -In this application, a single note has a name (the "username" in terms of the API) and the note -can be read by anyone who knows the name — but only edited by someone who -knows the password for it. - -You can see the documentation in the various files for more information. - -## Testing - -The repo also includes an example of a use case interactor test, as well as -an example of an end-to-end test which automates button clicks and inspects -the contents of the actual views. This is something we discussed in the lectures -about testing in CA but had not provided a code example of before. Note, one -could also inspect the contents of the ViewModel objects instead when testing -CA to make a similar test which would be less dependent on the details of the -specific UI implementation. - -## Project Starter Code - -Your team may choose to use this repo as starter code for your project. You could -also use the lab 5 code — or start from an empty repo if your team prefers. - -If you choose to use one of the repositories we have provided, you can either make -a fork of it or copy the subset of code you want into a completely new repository. +Jenna Zhang - stickycorner \ No newline at end of file From f82ef118eae0f042aecb495f5cf9641b1543954b Mon Sep 17 00:00:00 2001 From: stickycorner Date: Mon, 4 Nov 2024 13:41:54 -0500 Subject: [PATCH 04/56] use case -> use cases rename file --- .../java/{use_case => use_cases}/note/DataAccessException.java | 0 .../{use_case => use_cases}/note/NoteDataAccessInterface.java | 0 src/main/java/{use_case => use_cases}/note/NoteInputBoundary.java | 0 src/main/java/{use_case => use_cases}/note/NoteInteractor.java | 0 .../java/{use_case => use_cases}/note/NoteOutputBoundary.java | 0 .../java/{use_case => use_cases}/note/NoteInteractorTest.java | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename src/main/java/{use_case => use_cases}/note/DataAccessException.java (100%) rename src/main/java/{use_case => use_cases}/note/NoteDataAccessInterface.java (100%) rename src/main/java/{use_case => use_cases}/note/NoteInputBoundary.java (100%) rename src/main/java/{use_case => use_cases}/note/NoteInteractor.java (100%) rename src/main/java/{use_case => use_cases}/note/NoteOutputBoundary.java (100%) rename src/test/java/{use_case => use_cases}/note/NoteInteractorTest.java (100%) diff --git a/src/main/java/use_case/note/DataAccessException.java b/src/main/java/use_cases/note/DataAccessException.java similarity index 100% rename from src/main/java/use_case/note/DataAccessException.java rename to src/main/java/use_cases/note/DataAccessException.java diff --git a/src/main/java/use_case/note/NoteDataAccessInterface.java b/src/main/java/use_cases/note/NoteDataAccessInterface.java similarity index 100% rename from src/main/java/use_case/note/NoteDataAccessInterface.java rename to src/main/java/use_cases/note/NoteDataAccessInterface.java diff --git a/src/main/java/use_case/note/NoteInputBoundary.java b/src/main/java/use_cases/note/NoteInputBoundary.java similarity index 100% rename from src/main/java/use_case/note/NoteInputBoundary.java rename to src/main/java/use_cases/note/NoteInputBoundary.java diff --git a/src/main/java/use_case/note/NoteInteractor.java b/src/main/java/use_cases/note/NoteInteractor.java similarity index 100% rename from src/main/java/use_case/note/NoteInteractor.java rename to src/main/java/use_cases/note/NoteInteractor.java diff --git a/src/main/java/use_case/note/NoteOutputBoundary.java b/src/main/java/use_cases/note/NoteOutputBoundary.java similarity index 100% rename from src/main/java/use_case/note/NoteOutputBoundary.java rename to src/main/java/use_cases/note/NoteOutputBoundary.java diff --git a/src/test/java/use_case/note/NoteInteractorTest.java b/src/test/java/use_cases/note/NoteInteractorTest.java similarity index 100% rename from src/test/java/use_case/note/NoteInteractorTest.java rename to src/test/java/use_cases/note/NoteInteractorTest.java From cfa25a94637063fca370e59db294ca3404cb3611 Mon Sep 17 00:00:00 2001 From: stickycorner Date: Mon, 4 Nov 2024 13:50:02 -0500 Subject: [PATCH 05/56] package name change --- src/main/java/app/MainNoteApplication.java | 2 +- src/main/java/app/NoteAppBuilder.java | 6 +++--- src/main/java/data_access/DBNoteDataAccessObject.java | 4 ++-- src/main/java/interface_adapter/note/NoteController.java | 2 +- src/main/java/interface_adapter/note/NotePresenter.java | 2 +- src/main/java/use_cases/note/DataAccessException.java | 2 +- src/main/java/use_cases/note/NoteDataAccessInterface.java | 2 +- src/main/java/use_cases/note/NoteInputBoundary.java | 2 +- src/main/java/use_cases/note/NoteInteractor.java | 2 +- src/main/java/use_cases/note/NoteOutputBoundary.java | 2 +- src/test/java/app/MainNoteApplicationTest.java | 2 +- src/test/java/use_cases/note/NoteInteractorTest.java | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/app/MainNoteApplication.java b/src/main/java/app/MainNoteApplication.java index c37860156..41e197d48 100644 --- a/src/main/java/app/MainNoteApplication.java +++ b/src/main/java/app/MainNoteApplication.java @@ -1,7 +1,7 @@ package app; import data_access.DBNoteDataAccessObject; -import use_case.note.NoteDataAccessInterface; +import use_cases.note.NoteDataAccessInterface; /** * An application where we can view and add to a note stored by a user. diff --git a/src/main/java/app/NoteAppBuilder.java b/src/main/java/app/NoteAppBuilder.java index a68cb9ad6..f42c1c964 100644 --- a/src/main/java/app/NoteAppBuilder.java +++ b/src/main/java/app/NoteAppBuilder.java @@ -6,9 +6,9 @@ import interface_adapter.note.NoteController; import interface_adapter.note.NotePresenter; import interface_adapter.note.NoteViewModel; -import use_case.note.NoteDataAccessInterface; -import use_case.note.NoteInteractor; -import use_case.note.NoteOutputBoundary; +import use_cases.note.NoteDataAccessInterface; +import use_cases.note.NoteInteractor; +import use_cases.note.NoteOutputBoundary; import view.NoteView; /** diff --git a/src/main/java/data_access/DBNoteDataAccessObject.java b/src/main/java/data_access/DBNoteDataAccessObject.java index dadb0cab0..0ea8779f8 100644 --- a/src/main/java/data_access/DBNoteDataAccessObject.java +++ b/src/main/java/data_access/DBNoteDataAccessObject.java @@ -11,8 +11,8 @@ import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; -import use_case.note.DataAccessException; -import use_case.note.NoteDataAccessInterface; +import use_cases.note.DataAccessException; +import use_cases.note.NoteDataAccessInterface; /** * The DAO for accessing notes stored in the database. diff --git a/src/main/java/interface_adapter/note/NoteController.java b/src/main/java/interface_adapter/note/NoteController.java index e3e5dfb32..04ff417c8 100644 --- a/src/main/java/interface_adapter/note/NoteController.java +++ b/src/main/java/interface_adapter/note/NoteController.java @@ -1,6 +1,6 @@ package interface_adapter.note; -import use_case.note.NoteInputBoundary; +import use_cases.note.NoteInputBoundary; /** * Controller for our Note related Use Cases. diff --git a/src/main/java/interface_adapter/note/NotePresenter.java b/src/main/java/interface_adapter/note/NotePresenter.java index d4e416165..8dac7c53e 100644 --- a/src/main/java/interface_adapter/note/NotePresenter.java +++ b/src/main/java/interface_adapter/note/NotePresenter.java @@ -1,6 +1,6 @@ package interface_adapter.note; -import use_case.note.NoteOutputBoundary; +import use_cases.note.NoteOutputBoundary; /** * The presenter for our Note viewing and editing program. diff --git a/src/main/java/use_cases/note/DataAccessException.java b/src/main/java/use_cases/note/DataAccessException.java index b8c17920d..5b971a03f 100644 --- a/src/main/java/use_cases/note/DataAccessException.java +++ b/src/main/java/use_cases/note/DataAccessException.java @@ -1,4 +1,4 @@ -package use_case.note; +package use_cases.note; /** * Exception thrown when there is an error with accessing data. diff --git a/src/main/java/use_cases/note/NoteDataAccessInterface.java b/src/main/java/use_cases/note/NoteDataAccessInterface.java index b71597828..7198cc3ea 100644 --- a/src/main/java/use_cases/note/NoteDataAccessInterface.java +++ b/src/main/java/use_cases/note/NoteDataAccessInterface.java @@ -1,4 +1,4 @@ -package use_case.note; +package use_cases.note; import entity.User; diff --git a/src/main/java/use_cases/note/NoteInputBoundary.java b/src/main/java/use_cases/note/NoteInputBoundary.java index b41da9bf5..5a804e3ec 100644 --- a/src/main/java/use_cases/note/NoteInputBoundary.java +++ b/src/main/java/use_cases/note/NoteInputBoundary.java @@ -1,4 +1,4 @@ -package use_case.note; +package use_cases.note; /** * The Input Boundary for our note-related use cases. Since they are closely related, diff --git a/src/main/java/use_cases/note/NoteInteractor.java b/src/main/java/use_cases/note/NoteInteractor.java index 369e9309a..9d3af6e5a 100644 --- a/src/main/java/use_cases/note/NoteInteractor.java +++ b/src/main/java/use_cases/note/NoteInteractor.java @@ -1,4 +1,4 @@ -package use_case.note; +package use_cases.note; import entity.User; diff --git a/src/main/java/use_cases/note/NoteOutputBoundary.java b/src/main/java/use_cases/note/NoteOutputBoundary.java index c0c2bb1d0..2e00e5442 100644 --- a/src/main/java/use_cases/note/NoteOutputBoundary.java +++ b/src/main/java/use_cases/note/NoteOutputBoundary.java @@ -1,4 +1,4 @@ -package use_case.note; +package use_cases.note; /** * The output boundary for the Login Use Case. diff --git a/src/test/java/app/MainNoteApplicationTest.java b/src/test/java/app/MainNoteApplicationTest.java index 025d970e2..de97460b7 100644 --- a/src/test/java/app/MainNoteApplicationTest.java +++ b/src/test/java/app/MainNoteApplicationTest.java @@ -3,7 +3,7 @@ import entity.User; import org.junit.Before; import org.junit.Test; -import use_case.note.NoteDataAccessInterface; +import use_cases.note.NoteDataAccessInterface; import javax.swing.*; import java.awt.*; diff --git a/src/test/java/use_cases/note/NoteInteractorTest.java b/src/test/java/use_cases/note/NoteInteractorTest.java index a3ed466b6..857c2bb4f 100644 --- a/src/test/java/use_cases/note/NoteInteractorTest.java +++ b/src/test/java/use_cases/note/NoteInteractorTest.java @@ -1,4 +1,4 @@ -package use_case.note; +package use_cases.note; import entity.User; import org.junit.Test; From 9dad98822301b69cee34cd4c54ab84ab2c227d49 Mon Sep 17 00:00:00 2001 From: akhimie1 Date: Mon, 4 Nov 2024 13:51:30 -0500 Subject: [PATCH 06/56] added my name and github username to the README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 5e1d8b77c..bbf421c82 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Note Application +Team member ---- GitHub username +1. Iguehi Akhimien ---- iguehi-akhimien + This is a minimal example demonstrating usage of the password-protected user part of the API used in lab 5. From 4efcfc0a4632f5abeedec5b0d0fb0458f9d03010 Mon Sep 17 00:00:00 2001 From: akhimie1 Date: Mon, 4 Nov 2024 13:57:56 -0500 Subject: [PATCH 07/56] edited the README.md --- README.md | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/README.md b/README.md index bbf421c82..d93d650e2 100644 --- a/README.md +++ b/README.md @@ -3,37 +3,3 @@ Team member ---- GitHub username 1. Iguehi Akhimien ---- iguehi-akhimien -This is a minimal example demonstrating usage of the -password-protected user part of the API used in lab 5. - -You can find more information about the API endpoints in -[the documentation](https://www.postman.com/cloudy-astronaut-813156/csc207-grade-apis-demo/documentation/fg3zkjm/5-password-protected-user). - -If your team is considering an application for which it would be convenient to -store data in something like a database, you may find that the API calls demonstrated -here will be useful in your project, as this will allow you to store -an arbitrary JSON object associated with a username and password. - -In this application, a single note has a name (the "username" in terms of the API) and the note -can be read by anyone who knows the name — but only edited by someone who -knows the password for it. - -You can see the documentation in the various files for more information. - -## Testing - -The repo also includes an example of a use case interactor test, as well as -an example of an end-to-end test which automates button clicks and inspects -the contents of the actual views. This is something we discussed in the lectures -about testing in CA but had not provided a code example of before. Note, one -could also inspect the contents of the ViewModel objects instead when testing -CA to make a similar test which would be less dependent on the details of the -specific UI implementation. - -## Project Starter Code - -Your team may choose to use this repo as starter code for your project. You could -also use the lab 5 code — or start from an empty repo if your team prefers. - -If you choose to use one of the repositories we have provided, you can either make -a fork of it or copy the subset of code you want into a completely new repository. From 190502246235e373b2f1a82d82e7e1ab22ef591d Mon Sep 17 00:00:00 2001 From: PrishaPatel24 Date: Mon, 4 Nov 2024 14:12:55 -0500 Subject: [PATCH 08/56] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 28b350c7f..16f19920b 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -Jenna Zhang - stickycorner \ No newline at end of file +Jenna Zhang - stickycorner +Prisha Patel - PrishaPatel24 From a43be406623dd2d0ac0606e3f746cc73952adb3a Mon Sep 17 00:00:00 2001 From: akhimie1 Date: Mon, 4 Nov 2024 14:54:40 -0500 Subject: [PATCH 09/56] added my user stories to the README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d93d650e2..196a8fadf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # Note Application Team member ---- GitHub username -1. Iguehi Akhimien ---- iguehi-akhimien +1. Iguehi Akhimien ---- iguehi-akhimien + +**User stories**: +1. As a user, I want to create a new sticky note. +2. As a user, I want to ask the system to suggest ideas to complete my note. +3. As a user, I want to retrieve an already existing note. +4. As a user, I want to delete a note. From 5fa5b2fd0e6eea36280f4fe43e4cd7e6ec5ed134 Mon Sep 17 00:00:00 2001 From: akhimie1 Date: Mon, 4 Nov 2024 15:04:59 -0500 Subject: [PATCH 10/56] added my user stories to the README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 196a8fadf..4b34e8bd9 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ Team member ---- GitHub username 1. Iguehi Akhimien ---- iguehi-akhimien - -**User stories**: -1. As a user, I want to create a new sticky note. +# User Stories +**Notes**: +1. As a user, I want to create a new note. 2. As a user, I want to ask the system to suggest ideas to complete my note. 3. As a user, I want to retrieve an already existing note. 4. As a user, I want to delete a note. From 6e2695aa97970de7ed9f81284a5e649ad5c4dc74 Mon Sep 17 00:00:00 2001 From: PrishaPatel24 Date: Mon, 4 Nov 2024 18:02:48 -0500 Subject: [PATCH 11/56] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 16f19920b..d729d2d65 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ Jenna Zhang - stickycorner + Prisha Patel - PrishaPatel24 From bce7bfbc09689690ead4671baa44157613f4e0ae Mon Sep 17 00:00:00 2001 From: PrishaPatel24 Date: Mon, 4 Nov 2024 18:05:16 -0500 Subject: [PATCH 12/56] Update README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index d729d2d65..1396b5e3b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,15 @@ Jenna Zhang - stickycorner Prisha Patel - PrishaPatel24 + +USER STORIES + +- Calendar: User wants to update their schedule for the day. They navigate to the calendar and delete an existing event in their calendar. Then, the user adds a new event in place of the old one. The user checks when the event will take place and adds a note to the event. + +- Note-taking: User wants to view an already existing note. User is already logged into an account. User opens the note-taking tab and writes the name of already existing note in search bar. If found, note is opened and displayed. If not found, user is told to type the name again. + +- Checklist: User opens the checklist tab. User wants to either add new tasks or check off pre-existing ones. User can type in and save new tasks or click a button to show that a task has been completed. + +- AI-assisted writing: User is currently typing out notes and is unsure how to finish writing their thoughts. They click on the AI writing button and the program completes the current section and updates the note view section with the AI-generated results. + +- Language translation: User opens a notes file. User clicks on translate button and chooses a language to translate to. If the language is one of the options, notes are translated. If the language is not found, user is prompted to try again. From 9b9f4ede8c88fc3989da90574074ae28590572a4 Mon Sep 17 00:00:00 2001 From: PrishaPatel24 Date: Mon, 4 Nov 2024 18:05:50 -0500 Subject: [PATCH 13/56] Update README.md --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1396b5e3b..8568eeb18 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,12 @@ -Jenna Zhang - stickycorner +USERNAMES +Jenna Zhang - stickycorner Prisha Patel - PrishaPatel24 USER STORIES - Calendar: User wants to update their schedule for the day. They navigate to the calendar and delete an existing event in their calendar. Then, the user adds a new event in place of the old one. The user checks when the event will take place and adds a note to the event. - - Note-taking: User wants to view an already existing note. User is already logged into an account. User opens the note-taking tab and writes the name of already existing note in search bar. If found, note is opened and displayed. If not found, user is told to type the name again. - - Checklist: User opens the checklist tab. User wants to either add new tasks or check off pre-existing ones. User can type in and save new tasks or click a button to show that a task has been completed. - - AI-assisted writing: User is currently typing out notes and is unsure how to finish writing their thoughts. They click on the AI writing button and the program completes the current section and updates the note view section with the AI-generated results. - - Language translation: User opens a notes file. User clicks on translate button and chooses a language to translate to. If the language is one of the options, notes are translated. If the language is not found, user is prompted to try again. From 2e7dc9a30d04a9a6aa4e5177b99d2d260a83e07d Mon Sep 17 00:00:00 2001 From: stickycorner Date: Sat, 9 Nov 2024 10:30:28 -0500 Subject: [PATCH 14/56] created view, added CA classes/interfaces for AI use cases --- src/main/java/app/MainNoteApplication.java | 137 ++++++++++++------ .../interface_adapter/ai/AiController.java | 4 + .../interface_adapter/note/NoteState.java | 2 +- .../java/use_cases/ai/AiInputBoundary.java | 4 + src/main/java/use_cases/ai/AiInteractor.java | 41 ++++++ .../java/use_cases/ai/AiOutputBoundary.java | 12 ++ 6 files changed, 152 insertions(+), 48 deletions(-) create mode 100644 src/main/java/interface_adapter/ai/AiController.java create mode 100644 src/main/java/use_cases/ai/AiInputBoundary.java create mode 100644 src/main/java/use_cases/ai/AiInteractor.java create mode 100644 src/main/java/use_cases/ai/AiOutputBoundary.java diff --git a/src/main/java/app/MainNoteApplication.java b/src/main/java/app/MainNoteApplication.java index 41e197d48..a93ee11a4 100644 --- a/src/main/java/app/MainNoteApplication.java +++ b/src/main/java/app/MainNoteApplication.java @@ -1,56 +1,99 @@ package app; -import data_access.DBNoteDataAccessObject; -import use_cases.note.NoteDataAccessInterface; - -/** - * An application where we can view and add to a note stored by a user. - *

- * This is a minimal example of using the password-protected user API from lab 5, - * but demonstrating the endpoint allowing you to store an arbitrary JSON object. - * This functionality could be used in any project where your team wants to persist - * data which is then accessible across devices.

- *

The code is intentionally somewhat incomplete to leave work to be done if your - * team were to choose to work on a project which would require similar functionality. - * For example, we have intentionally not created a full "Note" entity here, but - * rather just represented a note as a string. - *

- * The ViewManager code has also been removed, since this minimal program only requires a single - * view. Your team may wish to bring back the ViewManager or make your own implementation of supporting - * switching between views depending on your project. - */ +import javax.swing.*; +import java.awt.*; + public class MainNoteApplication { + static final int WIDTH = 850; + static final int HEIGHT = 300; - /** - * The main entry point of the application. - *

- * The program will show you the note currently saved in the system. - * You are able to edit it and then save it to the system. You can refresh - * to update the note to reflect what was saved most recently. This - * uses the API from lab, so there is one database storing the note, - * which means that if anyone updates the note, that is what you will - * see when you refresh. - *

- * You can generalize the code to allow you to - * specify which "user" to save the note for, which will allow your team - * to store information specific to your team which is password-protected. - * The username and password used in this application are currently for - * user jonathan_calver2, but you can change that. As you did in lab 3, - * you will likely want to store password information locally rather than - * in your repo. Or you can require the user to enter their credentials - * in your application; it just depends on what your program's main - * functionality. - *

- * @param args commandline arguments are ignored - */ public static void main(String[] args) { + SwingUtilities.invokeLater(() -> { + final CardLayout cardLayout = new CardLayout(); + final JPanel cardPanel = new JPanel(cardLayout); + + final JPanel dashboardPanel = createDashboard(); + final JPanel notesPanel = createNotes(); + final JPanel calendarPanel = createCalendar(); + final JPanel checklistPanel = createChecklist(); + + cardPanel.add(dashboardPanel, "Dashboard"); + cardPanel.add(notesPanel, "Notes"); + cardPanel.add(calendarPanel, "Calendar"); + cardPanel.add(checklistPanel, "Checklist"); + + final JButton showCalendarButton = new JButton("Calendar"); + showCalendarButton.addActionListener(event -> cardLayout.show(cardPanel, "Calendar")); + + final JButton showNotesButton = new JButton("Notes"); + showNotesButton.addActionListener(event -> cardLayout.show(cardPanel, "Notes")); + + final JButton showChecklistButton = new JButton("Checklist"); + showChecklistButton.addActionListener(event -> cardLayout.show(cardPanel, "Checklist")); + + final JButton homeButton = new JButton("Dashboard"); + homeButton.addActionListener(event -> cardLayout.show(cardPanel, "Dashboard")); + + final JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS)); + buttonPanel.add(homeButton); + buttonPanel.add(showCalendarButton); + buttonPanel.add(showNotesButton); + buttonPanel.add(showChecklistButton); + + final JPanel mainPanel = new JPanel(new BorderLayout()); + mainPanel.add(buttonPanel, BorderLayout.WEST); + mainPanel.add(cardPanel, BorderLayout.CENTER); + + final JFrame frame = new JFrame("ZenTask"); + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + frame.setSize(WIDTH, HEIGHT); + frame.setContentPane(mainPanel); + frame.setVisible(true); + }); + } - // create the data access and inject it into our builder! - final NoteDataAccessInterface noteDataAccess = new DBNoteDataAccessObject(); + private static JPanel createDashboard() { + final JPanel dashboardPanel = new JPanel(); + dashboardPanel.add(new JLabel("Welcome to your Dashboard")); + return dashboardPanel; + } + + private static JPanel createCalendar() { + final JPanel calendarPanel = new JPanel(); + calendarPanel.add(new JLabel("Your calendar would be displayed here")); + return calendarPanel; + } + + private static JPanel createNotes() { + final JPanel notesPanel = new JPanel(); + notesPanel.setLayout(new BoxLayout(notesPanel, BoxLayout.X_AXIS)); + + final TextArea textArea = new TextArea(); + notesPanel.add(textArea); + + final JPanel toolBarPanel = new JPanel(); + toolBarPanel.setLayout(new BoxLayout(toolBarPanel, BoxLayout.Y_AXIS)); + final JButton aiButton = new JButton("Complete Notes With AI"); + toolBarPanel.add(aiButton); + + final JButton languageButton = new JButton("Translate to Other Language"); + toolBarPanel.add(languageButton); + + final JTextArea notesTextArea = new JTextArea(); + notesTextArea.setEditable(false); + notesTextArea.setSize(75, 50); + toolBarPanel.add(notesTextArea); + + notesPanel.add(toolBarPanel); + return notesPanel; + } - final NoteAppBuilder builder = new NoteAppBuilder(); - builder.addNoteDAO(noteDataAccess) - .addNoteView() - .addNoteUseCase().build().setVisible(true); + private static JPanel createChecklist() { + final JPanel checklistPanel = new JPanel(); + checklistPanel.add(new JLabel("Tasks go here!")); + final JButton addTaskButton = new JButton("Add Task +"); + checklistPanel.add(addTaskButton); + return checklistPanel; } } diff --git a/src/main/java/interface_adapter/ai/AiController.java b/src/main/java/interface_adapter/ai/AiController.java new file mode 100644 index 000000000..2abf67784 --- /dev/null +++ b/src/main/java/interface_adapter/ai/AiController.java @@ -0,0 +1,4 @@ +package interface_adapter.ai; + +public class AiController { +} diff --git a/src/main/java/interface_adapter/note/NoteState.java b/src/main/java/interface_adapter/note/NoteState.java index c5b2234d6..900b924e6 100644 --- a/src/main/java/interface_adapter/note/NoteState.java +++ b/src/main/java/interface_adapter/note/NoteState.java @@ -2,7 +2,7 @@ /** * The State for a note. - *

For this example, a note is simplay a string.

+ *

For this example, a note is simply a string.

*/ public class NoteState { private String note = ""; diff --git a/src/main/java/use_cases/ai/AiInputBoundary.java b/src/main/java/use_cases/ai/AiInputBoundary.java new file mode 100644 index 000000000..8eb688e6e --- /dev/null +++ b/src/main/java/use_cases/ai/AiInputBoundary.java @@ -0,0 +1,4 @@ +package use_cases.ai; + +public interface AiInputBoundary { +} diff --git a/src/main/java/use_cases/ai/AiInteractor.java b/src/main/java/use_cases/ai/AiInteractor.java new file mode 100644 index 000000000..7fb746725 --- /dev/null +++ b/src/main/java/use_cases/ai/AiInteractor.java @@ -0,0 +1,41 @@ +package use_cases.ai; + +import javax.swing.*; + +/** + * The class that will implement the different functions of AI in the program. + * It will generate a completed written version of the current note. + */ +public class AiInteractor { + private final String key; + private final AiInputBoundary aiInputBoundary; + private final AiOutputBoundary aiOutputBoundary; + + // take in note panel in attribute or in parameter to the method, defining interfaces, etc + // decide on functions for the calendar, load events, oauth 2 login, edit/modify events? + + AiInteractor(AiInputBoundary aiInputBoundary, AiOutputBoundary aiOutputBoundary) { + this.key = "AIzaSyA5NGM5lAXTTPbdzgtBssW2Xg27kg0gDa4"; + this.aiInputBoundary = aiInputBoundary; + this.aiOutputBoundary = aiOutputBoundary; + } + + /** + * Find the text content of a given note in the program. + * @param textArea The field notes have been added to. + * @return A string of the inputted text in notes. + */ + public String getNote(JTextArea textArea) { + return textArea.getText(); + } + + /** + * Auto-complete the current notes written by the user with AI. + * @param currNote The call to the AI to complete the current note. + * @return The generated AI response. + */ + public String generateResponse(String currNote) { + // call to API here + return ""; + } +} diff --git a/src/main/java/use_cases/ai/AiOutputBoundary.java b/src/main/java/use_cases/ai/AiOutputBoundary.java new file mode 100644 index 000000000..78947470c --- /dev/null +++ b/src/main/java/use_cases/ai/AiOutputBoundary.java @@ -0,0 +1,12 @@ +package use_cases.ai; + +/** + * The output boundary for the AI use case. + */ +public interface AiOutputBoundary { + /** + * Add the AI generated completed note into the current note. + * @param note The final output from the AI. + */ + void updateNote(String note); +} From 52d3f6e27d8ee4d74b6e83d2a252457639e7ad05 Mon Sep 17 00:00:00 2001 From: Prisha Patel Date: Sat, 9 Nov 2024 10:31:22 -0500 Subject: [PATCH 15/56] add_task use case initial work --- src/main/java/entity/Checklist.java | 27 +++++++ .../add_task/AddTaskController.java | 24 ++++++ .../add_task/AddTaskPresenter.java | 33 ++++++++ .../interface_adapter/add_task/TaskState.java | 27 +++++++ .../add_task/TaskViewModel.java | 14 ++++ .../add_task/AddTaskInputBoundary.java | 12 +++ .../use_cases/add_task/AddTaskInputData.java | 13 +++ .../use_cases/add_task/AddTaskInteractor.java | 19 +++++ .../add_task/AddTaskOutputBoundary.java | 18 +++++ .../use_cases/add_task/AddTaskOutputData.java | 20 +++++ src/main/java/view/ChecklistView.java | 80 +++++++++++++++++++ 11 files changed, 287 insertions(+) create mode 100644 src/main/java/entity/Checklist.java create mode 100644 src/main/java/interface_adapter/add_task/AddTaskController.java create mode 100644 src/main/java/interface_adapter/add_task/AddTaskPresenter.java create mode 100644 src/main/java/interface_adapter/add_task/TaskState.java create mode 100644 src/main/java/interface_adapter/add_task/TaskViewModel.java create mode 100644 src/main/java/use_cases/add_task/AddTaskInputBoundary.java create mode 100644 src/main/java/use_cases/add_task/AddTaskInputData.java create mode 100644 src/main/java/use_cases/add_task/AddTaskInteractor.java create mode 100644 src/main/java/use_cases/add_task/AddTaskOutputBoundary.java create mode 100644 src/main/java/use_cases/add_task/AddTaskOutputData.java create mode 100644 src/main/java/view/ChecklistView.java diff --git a/src/main/java/entity/Checklist.java b/src/main/java/entity/Checklist.java new file mode 100644 index 000000000..e846a67ed --- /dev/null +++ b/src/main/java/entity/Checklist.java @@ -0,0 +1,27 @@ +package entity; + +import java.util.ArrayList; +import java.util.List; + +/** + * Class representing a checklist. + */ +public class Checklist { + private List tasks; + + public Checklist() { + this.tasks = new ArrayList<>(); + } + + public List getTasks() { + return tasks; + } + + /** + * Adds new task to the checklist. + * @param description the task description + */ + public void addTask(String description) { + this.tasks.add(new Task(description)); + } +} diff --git a/src/main/java/interface_adapter/add_task/AddTaskController.java b/src/main/java/interface_adapter/add_task/AddTaskController.java new file mode 100644 index 000000000..f9c41b674 --- /dev/null +++ b/src/main/java/interface_adapter/add_task/AddTaskController.java @@ -0,0 +1,24 @@ +package interface_adapter.add_task; + +import use_cases.add_task.AddTaskInputBoundary; +import use_cases.add_task.AddTaskInputData; + +/** + * The controller for the add_task Use Case. + */ +public class AddTaskController { + private final AddTaskInputBoundary addTaskUseCaseInteractor; + + public AddTaskController(AddTaskInputBoundary addTaskUseCaseInteractor) { + this.addTaskUseCaseInteractor = addTaskUseCaseInteractor; + } + + /** + * Executes the add_task Use Case. + * @param description the task description + */ + public void execute(String description) { + final AddTaskInputData addTaskInputData = new AddTaskInputData(description); + addTaskUseCaseInteractor.execute(addTaskInputData); + } +} diff --git a/src/main/java/interface_adapter/add_task/AddTaskPresenter.java b/src/main/java/interface_adapter/add_task/AddTaskPresenter.java new file mode 100644 index 000000000..f681f737c --- /dev/null +++ b/src/main/java/interface_adapter/add_task/AddTaskPresenter.java @@ -0,0 +1,33 @@ +package interface_adapter.add_task; + +import interface_adapter.ViewModel; +import use_cases.add_task.AddTaskOutputBoundary; +import use_cases.add_task.AddTaskOutputData; + +/** + * The presenter for the add_task use case. + */ +public class AddTaskPresenter implements AddTaskOutputBoundary { + private final TaskViewModel taskViewModel; + + public AddTaskPresenter(TaskViewModel taskViewModel) { + this.taskViewModel = taskViewModel; + } + + @Override + public void prepareSuccessView(AddTaskOutputData response) { + // On success, add task to the view. + + final TaskState taskState = taskViewModel.getState(); + taskState.setTask(response.getDescription()); + taskState.setError(null); + this.taskViewModel.firePropertyChanged(); + } + + @Override + public void prepareFailView(String error) { + final TaskState taskState = taskViewModel.getState(); + taskState.setError(error); + taskViewModel.firePropertyChanged(); + } +} diff --git a/src/main/java/interface_adapter/add_task/TaskState.java b/src/main/java/interface_adapter/add_task/TaskState.java new file mode 100644 index 000000000..de1bfc85c --- /dev/null +++ b/src/main/java/interface_adapter/add_task/TaskState.java @@ -0,0 +1,27 @@ +package interface_adapter.add_task; + +import entity.Task; + +/** + * The State for a task. + */ +public class TaskState { + private Task task; + private String error; + + public Task getTask() { + return task; + } + + public void setTask(String description) { + this.task = new Task(description); + } + + public void setError(String errorMessage) { + this.error = errorMessage; + } + + public String getError() { + return error; + } +} diff --git a/src/main/java/interface_adapter/add_task/TaskViewModel.java b/src/main/java/interface_adapter/add_task/TaskViewModel.java new file mode 100644 index 000000000..c7a2bd425 --- /dev/null +++ b/src/main/java/interface_adapter/add_task/TaskViewModel.java @@ -0,0 +1,14 @@ +package interface_adapter.add_task; + +import interface_adapter.ViewModel; +import interface_adapter.add_task.TaskState; + +/** + * The ViewModel for the TaskView. + */ +public class TaskViewModel extends ViewModel { + public TaskViewModel() { + super("task"); + setState(new TaskState()); + } +} \ No newline at end of file diff --git a/src/main/java/use_cases/add_task/AddTaskInputBoundary.java b/src/main/java/use_cases/add_task/AddTaskInputBoundary.java new file mode 100644 index 000000000..6ce1c7d97 --- /dev/null +++ b/src/main/java/use_cases/add_task/AddTaskInputBoundary.java @@ -0,0 +1,12 @@ +package use_cases.add_task; + +/** + * Input Boundary for actions which are related to adding tasks. + */ +public interface AddTaskInputBoundary { + /** + * Executes the add_task use case. + * @param addTaskInputData the input data + */ + void execute(AddTaskInputData addTaskInputData); +} diff --git a/src/main/java/use_cases/add_task/AddTaskInputData.java b/src/main/java/use_cases/add_task/AddTaskInputData.java new file mode 100644 index 000000000..9bd23a36f --- /dev/null +++ b/src/main/java/use_cases/add_task/AddTaskInputData.java @@ -0,0 +1,13 @@ +package use_cases.add_task; + +public class AddTaskInputData { + private final String description; + + public AddTaskInputData(String description) { + this.description = description; + } + + String getDescription() { + return description; + } +} diff --git a/src/main/java/use_cases/add_task/AddTaskInteractor.java b/src/main/java/use_cases/add_task/AddTaskInteractor.java new file mode 100644 index 000000000..b35c20ef7 --- /dev/null +++ b/src/main/java/use_cases/add_task/AddTaskInteractor.java @@ -0,0 +1,19 @@ +package use_cases.add_task; + +/** + * The add_task Interactor. + */ +public class AddTaskInteractor implements AddTaskInputBoundary { + private final AddTaskOutputBoundary addTaskPresenter; + + public AddTaskInteractor(AddTaskOutputBoundary addTaskOutputBoundary) { + this.addTaskPresenter = addTaskOutputBoundary; + } + + @Override + public void execute(AddTaskInputData addTaskInputData) { + final String description = addTaskInputData.getDescription(); + final AddTaskOutputData addTaskOutputData = new AddTaskOutputData(description, false); + addTaskPresenter.prepareSuccessView(addTaskOutputData); + } +} diff --git a/src/main/java/use_cases/add_task/AddTaskOutputBoundary.java b/src/main/java/use_cases/add_task/AddTaskOutputBoundary.java new file mode 100644 index 000000000..f17bf92e0 --- /dev/null +++ b/src/main/java/use_cases/add_task/AddTaskOutputBoundary.java @@ -0,0 +1,18 @@ +package use_cases.add_task; + +/** + * The output boundary for the add_task Use Case. + */ +public interface AddTaskOutputBoundary { + /** + * Prepares the success view for the add_task Use Case. + * @param outputData the output data + */ + void prepareSuccessView(AddTaskOutputData outputData); + + /** + * Prepares the failure view for the add_task Use Case. + * @param errorMessage the explanation of the failure + */ + void prepareFailView(String errorMessage); +} diff --git a/src/main/java/use_cases/add_task/AddTaskOutputData.java b/src/main/java/use_cases/add_task/AddTaskOutputData.java new file mode 100644 index 000000000..7f49014c2 --- /dev/null +++ b/src/main/java/use_cases/add_task/AddTaskOutputData.java @@ -0,0 +1,20 @@ +package use_cases.add_task; + +/** + * Output Data for the add_task Use Case. + */ +public class AddTaskOutputData { + + private final String description; + private final boolean useCaseFailed; + + public AddTaskOutputData(String description, boolean useCaseFailed) { + this.description = description; + this.useCaseFailed = useCaseFailed; + } + + public String getDescription() { + return description; + } + +} \ No newline at end of file diff --git a/src/main/java/view/ChecklistView.java b/src/main/java/view/ChecklistView.java new file mode 100644 index 000000000..5f9f61022 --- /dev/null +++ b/src/main/java/view/ChecklistView.java @@ -0,0 +1,80 @@ +package view; + +import interface_adapter.add_task.AddTaskController; +import interface_adapter.add_task.TaskState; +import interface_adapter.add_task.TaskViewModel; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +/** + * The View for when the user is viewing a checklist in the program. + */ +public class ChecklistView extends JPanel implements ActionListener, PropertyChangeListener { + + private final TaskViewModel taskViewModel; + + private final JLabel title = new JLabel("Title:"); + private final JTextArea titleInputField = new JTextArea(); + + private final JTextArea taskInputField = new JTextArea(); + private final JButton checkbox = new JButton(); + + private AddTaskController addTaskController; + + public ChecklistView(TaskViewModel taskViewModel) { + + title.setAlignmentX(Component.CENTER_ALIGNMENT); + this.taskViewModel = taskViewModel; + this.taskViewModel.addPropertyChangeListener(this); + + final JPanel checkboxes = new JPanel(); + checkboxes.add(checkbox); + + checkbox.addActionListener( + evt -> { + if (evt.getSource().equals(checkbox)) { + addTaskController.execute(null); + + } + } + ); + + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + + this.add(title); + this.add(titleInputField); + this.add(checkboxes); + } + + /** + * React to a button click that results in evt. + * @param evt the ActionEvent to react to + */ + public void actionPerformed(ActionEvent evt) { + System.out.println("Click " + evt.getActionCommand()); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + final TaskState state = (TaskState) evt.getNewValue(); + setFields(state); + if (state.getError() != null) { + JOptionPane.showMessageDialog(this, state.getError(), + "Error", JOptionPane.ERROR_MESSAGE); + } + } + + private void setFields(TaskState state) { + taskInputField.setText(state.getTask().toString()); + } + + public void setTaskController(AddTaskController controller) { + this.addTaskController = controller; + } + +} From 792a2d6015b282c604ac7c80270bce051b495978 Mon Sep 17 00:00:00 2001 From: stickycorner Date: Sat, 9 Nov 2024 11:11:05 -0500 Subject: [PATCH 16/56] updated view package --- src/main/java/app/AppBuilder.java | 13 +++++++++ .../interface_adapter/ai/AiController.java | 16 ++++++++++ .../interface_adapter/ai/AiPresenter.java | 4 +++ .../java/use_cases/ai/AiInputBoundary.java | 9 ++++++ src/main/java/view/CalendarView.java | 4 +++ src/main/java/view/ChecklistView.java | 29 +++++++++++++++++++ src/main/java/view/DashboardView.java | 4 +++ src/main/java/view/NotesView.java | 8 +++++ 8 files changed, 87 insertions(+) create mode 100644 src/main/java/app/AppBuilder.java create mode 100644 src/main/java/interface_adapter/ai/AiPresenter.java create mode 100644 src/main/java/view/CalendarView.java create mode 100644 src/main/java/view/ChecklistView.java create mode 100644 src/main/java/view/DashboardView.java create mode 100644 src/main/java/view/NotesView.java diff --git a/src/main/java/app/AppBuilder.java b/src/main/java/app/AppBuilder.java new file mode 100644 index 000000000..0885e9b3e --- /dev/null +++ b/src/main/java/app/AppBuilder.java @@ -0,0 +1,13 @@ +package app; + +import interface_adapter.note.NoteViewModel; +import use_cases.note.NoteDataAccessInterface; +import use_cases.note.NoteInteractor; +import view.NoteView; + +public class AppBuilder { + public static final int HEIGHT = 300; + public static final int WIDTH = 400; + private NoteView noteView; + private NoteInteractor noteInteractor; +} diff --git a/src/main/java/interface_adapter/ai/AiController.java b/src/main/java/interface_adapter/ai/AiController.java index 2abf67784..3d6946328 100644 --- a/src/main/java/interface_adapter/ai/AiController.java +++ b/src/main/java/interface_adapter/ai/AiController.java @@ -1,4 +1,20 @@ package interface_adapter.ai; +import use_cases.ai.AiInputBoundary; + public class AiController { + private final AiInputBoundary aiInteractor; + + public AiController(AiInputBoundary aiInputBoundary) { + this.aiInteractor = aiInputBoundary; + } + + /** + * Generates the AI response from a given note. + * @param note The note in the JTextArea written by the user. + */ + public void generateResponse(String note) { + aiInteractor.generateResponse(note + "Please complete the note based on the" + + "given notes."); + } } diff --git a/src/main/java/interface_adapter/ai/AiPresenter.java b/src/main/java/interface_adapter/ai/AiPresenter.java new file mode 100644 index 000000000..5df0670b9 --- /dev/null +++ b/src/main/java/interface_adapter/ai/AiPresenter.java @@ -0,0 +1,4 @@ +package interface_adapter.ai; + +public class AiPresenter { +} diff --git a/src/main/java/use_cases/ai/AiInputBoundary.java b/src/main/java/use_cases/ai/AiInputBoundary.java index 8eb688e6e..8d37ce9e1 100644 --- a/src/main/java/use_cases/ai/AiInputBoundary.java +++ b/src/main/java/use_cases/ai/AiInputBoundary.java @@ -1,4 +1,13 @@ package use_cases.ai; +/** + * AiInputBoundary involved in the AI prompt use case. + */ public interface AiInputBoundary { + + /** + * Generates AI response. + * @param note The modified prompt going into the AI." + */ + void generateResponse(String note); } diff --git a/src/main/java/view/CalendarView.java b/src/main/java/view/CalendarView.java new file mode 100644 index 000000000..122c2f997 --- /dev/null +++ b/src/main/java/view/CalendarView.java @@ -0,0 +1,4 @@ +package view; + +public class CalendarView { +} diff --git a/src/main/java/view/ChecklistView.java b/src/main/java/view/ChecklistView.java new file mode 100644 index 000000000..ff4c4fb40 --- /dev/null +++ b/src/main/java/view/ChecklistView.java @@ -0,0 +1,29 @@ +package view; + +import javax.swing.*; +import java.lang.reflect.Array; + +/** + * The view and taking in the inputs for the checklist section of the program. + */ +public class ChecklistView { + private final JButton taskButton; + private final JLabel label; + + public ChecklistView() { + final JPanel checklistPanel = new JPanel(); + this.label = new JLabel("Tasks go here!"); + checklistPanel.add(label); + this.taskButton = new JButton("Add Task +"); + checklistPanel.add(taskButton); + + taskButton.addActionListener( + evt -> { + if (evt.getSource().equals(taskButton)) { + // add ChecklistController.dosomething() based + // on button + } + } + ); + } +} diff --git a/src/main/java/view/DashboardView.java b/src/main/java/view/DashboardView.java new file mode 100644 index 000000000..bd7afac9a --- /dev/null +++ b/src/main/java/view/DashboardView.java @@ -0,0 +1,4 @@ +package view; + +public class DashboardView { +} diff --git a/src/main/java/view/NotesView.java b/src/main/java/view/NotesView.java new file mode 100644 index 000000000..07763600e --- /dev/null +++ b/src/main/java/view/NotesView.java @@ -0,0 +1,8 @@ +package view; + +import javax.swing.*; +import java.awt.event.ActionListener; + +public class NotesView { + +} From 535a8d6245b677d443b25c40cba8ee90e4b80ecf Mon Sep 17 00:00:00 2001 From: stickycorner Date: Sat, 9 Nov 2024 12:23:00 -0500 Subject: [PATCH 17/56] fix api key --- src/main/java/use_cases/ai/AiInteractor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/use_cases/ai/AiInteractor.java b/src/main/java/use_cases/ai/AiInteractor.java index 7fb746725..431a34f69 100644 --- a/src/main/java/use_cases/ai/AiInteractor.java +++ b/src/main/java/use_cases/ai/AiInteractor.java @@ -15,7 +15,7 @@ public class AiInteractor { // decide on functions for the calendar, load events, oauth 2 login, edit/modify events? AiInteractor(AiInputBoundary aiInputBoundary, AiOutputBoundary aiOutputBoundary) { - this.key = "AIzaSyA5NGM5lAXTTPbdzgtBssW2Xg27kg0gDa4"; + this.key = ""; this.aiInputBoundary = aiInputBoundary; this.aiOutputBoundary = aiOutputBoundary; } From a242fa49d5db9db9e57f2c7acd5823cc5907ff1c Mon Sep 17 00:00:00 2001 From: Prisha Patel Date: Sat, 9 Nov 2024 12:39:53 -0500 Subject: [PATCH 18/56] add_task view progress --- src/main/java/app/MainNoteApplication.java | 141 ++++++++++++++------- src/main/java/entity/Task.java | 12 +- src/main/java/view/ChecklistView.java | 73 ++++++++--- 3 files changed, 156 insertions(+), 70 deletions(-) diff --git a/src/main/java/app/MainNoteApplication.java b/src/main/java/app/MainNoteApplication.java index 41e197d48..84cfb77b9 100644 --- a/src/main/java/app/MainNoteApplication.java +++ b/src/main/java/app/MainNoteApplication.java @@ -1,56 +1,107 @@ package app; -import data_access.DBNoteDataAccessObject; -import use_cases.note.NoteDataAccessInterface; +import interface_adapter.ViewModel; +import interface_adapter.add_task.TaskViewModel; +import view.ChecklistView; + +import javax.swing.*; +import java.awt.*; +import view.ChecklistView; /** - * An application where we can view and add to a note stored by a user. - *

- * This is a minimal example of using the password-protected user API from lab 5, - * but demonstrating the endpoint allowing you to store an arbitrary JSON object. - * This functionality could be used in any project where your team wants to persist - * data which is then accessible across devices.

- *

The code is intentionally somewhat incomplete to leave work to be done if your - * team were to choose to work on a project which would require similar functionality. - * For example, we have intentionally not created a full "Note" entity here, but - * rather just represented a note as a string. - *

- * The ViewManager code has also been removed, since this minimal program only requires a single - * view. Your team may wish to bring back the ViewManager or make your own implementation of supporting - * switching between views depending on your project. + * An */ + public class MainNoteApplication { - /** - * The main entry point of the application. - *

- * The program will show you the note currently saved in the system. - * You are able to edit it and then save it to the system. You can refresh - * to update the note to reflect what was saved most recently. This - * uses the API from lab, so there is one database storing the note, - * which means that if anyone updates the note, that is what you will - * see when you refresh. - *

- * You can generalize the code to allow you to - * specify which "user" to save the note for, which will allow your team - * to store information specific to your team which is password-protected. - * The username and password used in this application are currently for - * user jonathan_calver2, but you can change that. As you did in lab 3, - * you will likely want to store password information locally rather than - * in your repo. Or you can require the user to enter their credentials - * in your application; it just depends on what your program's main - * functionality. - *

- * @param args commandline arguments are ignored - */ + static final int WIDTH = 850; + static final int HEIGHT = 300; + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> { + final CardLayout cardLayout = new CardLayout(); + final JPanel cardPanel = new JPanel(cardLayout); + + final JPanel dashboardPanel = createDashboard(); + final JPanel notesPanel = createNotes(); + final JPanel calendarPanel = createCalendar(); + final JPanel checklistPanel = createChecklist(); + + cardPanel.add(dashboardPanel, "Dashboard"); + cardPanel.add(notesPanel, "Notes"); + cardPanel.add(calendarPanel, "Calendar"); + cardPanel.add(checklistPanel, "Checklist"); + + final JButton showCalendarButton = new JButton("Calendar"); + showCalendarButton.addActionListener(event -> cardLayout.show(cardPanel, "Calendar")); - // create the data access and inject it into our builder! - final NoteDataAccessInterface noteDataAccess = new DBNoteDataAccessObject(); + final JButton showNotesButton = new JButton("Notes"); + showNotesButton.addActionListener(event -> cardLayout.show(cardPanel, "Notes")); + + final JButton showChecklistButton = new JButton("Checklist"); + showChecklistButton.addActionListener(event -> cardLayout.show(cardPanel, "Checklist")); + + final JButton homeButton = new JButton("Dashboard"); + homeButton.addActionListener(event -> cardLayout.show(cardPanel, "Dashboard")); + + final JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS)); + buttonPanel.add(homeButton); + buttonPanel.add(showCalendarButton); + buttonPanel.add(showNotesButton); + buttonPanel.add(showChecklistButton); + + final JPanel mainPanel = new JPanel(new BorderLayout()); + mainPanel.add(buttonPanel, BorderLayout.WEST); + mainPanel.add(cardPanel, BorderLayout.CENTER); + + final JFrame frame = new JFrame("ZenTask"); + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + frame.setSize(WIDTH, HEIGHT); + frame.setContentPane(mainPanel); + frame.setVisible(true); + }); + } + + private static JPanel createDashboard() { + final JPanel dashboardPanel = new JPanel(); + dashboardPanel.add(new JLabel("Welcome to your Dashboard")); + return dashboardPanel; + } + + private static JPanel createCalendar() { + final JPanel calendarPanel = new JPanel(); + calendarPanel.add(new JLabel("Your calendar would be displayed here")); + return calendarPanel; + } + + private static JPanel createNotes() { + final JPanel notesPanel = new JPanel(); + notesPanel.setLayout(new BoxLayout(notesPanel, BoxLayout.X_AXIS)); + + final TextArea textArea = new TextArea(); + notesPanel.add(textArea); + + final JPanel toolBarPanel = new JPanel(); + toolBarPanel.setLayout(new BoxLayout(toolBarPanel, BoxLayout.Y_AXIS)); + final JButton aiButton = new JButton("Complete Notes With AI"); + toolBarPanel.add(aiButton); + + final JButton languageButton = new JButton("Translate to Other Language"); + toolBarPanel.add(languageButton); + + final JTextArea notesTextArea = new JTextArea(); + notesTextArea.setEditable(false); + notesTextArea.setSize(75, 50); + toolBarPanel.add(notesTextArea); + + notesPanel.add(toolBarPanel); + return notesPanel; + } - final NoteAppBuilder builder = new NoteAppBuilder(); - builder.addNoteDAO(noteDataAccess) - .addNoteView() - .addNoteUseCase().build().setVisible(true); + private static JPanel createChecklist() { + final TaskViewModel taskViewModel = new TaskViewModel(); + final ChecklistView checklistView = new ChecklistView(taskViewModel); + return checklistView; } -} +} \ No newline at end of file diff --git a/src/main/java/entity/Task.java b/src/main/java/entity/Task.java index b8c23b6e7..ee55450a6 100644 --- a/src/main/java/entity/Task.java +++ b/src/main/java/entity/Task.java @@ -6,26 +6,26 @@ public class Task { private final String description; - private boolean done; + private boolean checked; public Task(String description) { this.description = description; - this.done = false; + this.checked = false; } public String getDescription() { return description; } - public boolean isDone() { - return done; + public boolean isChecked() { + return checked; } /** * Marks the task as completed. */ - public void markDone() { - done = true; + public void markChecked() { + checked = true; } } diff --git a/src/main/java/view/ChecklistView.java b/src/main/java/view/ChecklistView.java index 5f9f61022..c83bc2e94 100644 --- a/src/main/java/view/ChecklistView.java +++ b/src/main/java/view/ChecklistView.java @@ -17,38 +17,73 @@ public class ChecklistView extends JPanel implements ActionListener, PropertyChangeListener { private final TaskViewModel taskViewModel; - - private final JLabel title = new JLabel("Title:"); - private final JTextArea titleInputField = new JTextArea(); - - private final JTextArea taskInputField = new JTextArea(); - private final JButton checkbox = new JButton(); - private AddTaskController addTaskController; - public ChecklistView(TaskViewModel taskViewModel) { + private final JPanel checklistPanel; + private final JButton addTaskButton; + private final JTextArea taskInputField; - title.setAlignmentX(Component.CENTER_ALIGNMENT); - this.taskViewModel = taskViewModel; - this.taskViewModel.addPropertyChangeListener(this); - final JPanel checkboxes = new JPanel(); - checkboxes.add(checkbox); + public ChecklistView(TaskViewModel taskViewModel) { + this.checklistPanel = new JPanel(); + this.addTaskButton = new JButton("Add Task +"); + this.taskInputField = new JTextArea(); + taskInputField.setSize(10, 10); + taskInputField.setVisible(false); + + this.checklistPanel.add(new JLabel("Tasks go here!")); + checklistPanel.add(addTaskButton); + + final JButton emptyBox = new JButton(); + final JButton checkedBox = new JButton("X"); + emptyBox.setPreferredSize(checkedBox.getPreferredSize()); + emptyBox.setVisible(false); + checkedBox.setVisible(false); + + addTaskButton.addActionListener( + evt -> { + if (evt.getSource().equals(addTaskButton)) { + // add ChecklistController.dosomething() based + // on button + taskInputField.setVisible(true); + emptyBox.setVisible(true); + addTaskController.execute(taskInputField.getText()); + } + } + ); - checkbox.addActionListener( + emptyBox.addActionListener( evt -> { - if (evt.getSource().equals(checkbox)) { - addTaskController.execute(null); + if (evt.getSource().equals(emptyBox)) { + emptyBox.setVisible(false); + checkedBox.setVisible(true); + } + } + ); + checkedBox.addActionListener( + evt -> { + if (evt.getSource().equals(checkedBox)) { + checkedBox.setVisible(false); + emptyBox.setVisible(true); } } ); + this.taskViewModel = taskViewModel; + this.taskViewModel.addPropertyChangeListener(this); + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - this.add(title); - this.add(titleInputField); - this.add(checkboxes); + final JPanel taskPanel = new JPanel(); + taskPanel.add(emptyBox); + taskPanel.add(checkedBox); + taskPanel.add(taskInputField); + taskPanel.setLayout(new BoxLayout(taskPanel, BoxLayout.X_AXIS)); + + checklistPanel.setLayout(new BoxLayout(checklistPanel, BoxLayout.Y_AXIS)); + checklistPanel.add(taskPanel); + this.add(checklistPanel); } /** From 6ee4f1b8646ee5ad6dfa6ca2ccf62451a75b4a0d Mon Sep 17 00:00:00 2001 From: akhimie1 Date: Sat, 9 Nov 2024 14:40:00 -0500 Subject: [PATCH 19/56] I am setting up the Notes view actions: save, view, delete... --- README.md | 20 +++++---- src/main/java/view/NoteView.java | 77 +++++++++++++++++++++++++------- 2 files changed, 73 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 4b34e8bd9..8ab5c26ed 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,15 @@ # Note Application Team member ---- GitHub username -1. Iguehi Akhimien ---- iguehi-akhimien - -# User Stories -**Notes**: -1. As a user, I want to create a new note. -2. As a user, I want to ask the system to suggest ideas to complete my note. -3. As a user, I want to retrieve an already existing note. -4. As a user, I want to delete a note. +1. Iguehi Akhimien - iguehi-akhimien +2. Jenna Zhang - stickycorner +3. Prisha Patel - PrishaPatel24 + + +USER STORIES + +- Calendar: User wants to update their schedule for the day. They navigate to the calendar and delete an existing event in their calendar. Then, the user adds a new event in place of the old one. The user checks when the event will take place and adds a note to the event. +- Note-taking: User wants to view an already existing note. User is already logged into an account. User opens the note-taking tab and writes the name of already existing note in search bar. If found, note is opened and displayed. If not found, user is told to type the name again. +- Checklist: User opens the checklist tab. User wants to either add new tasks or check off pre-existing ones. User can type in and save new tasks or click a button to show that a task has been completed. +- AI-assisted writing: User is currently typing out notes and is unsure how to finish writing their thoughts. They click on the AI writing button and the program completes the current section and updates the note view section with the AI-generated results. +- Language translation: User opens a notes file. User clicks on translate button and chooses a language to translate to. If the language is one of the options, notes are translated. If the language is not found, user is prompted to try again. diff --git a/src/main/java/view/NoteView.java b/src/main/java/view/NoteView.java index 331d76493..df64115e2 100644 --- a/src/main/java/view/NoteView.java +++ b/src/main/java/view/NoteView.java @@ -5,13 +5,13 @@ import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextArea; +import javax.swing.*; import interface_adapter.note.NoteController; import interface_adapter.note.NoteState; @@ -24,11 +24,14 @@ public class NoteView extends JPanel implements ActionListener, PropertyChangeLi private final NoteViewModel noteViewModel; - private final JLabel noteName = new JLabel("note for jonathan_calver2"); - private final JTextArea noteInputField = new JTextArea(); + private final JLabel noteName = new JLabel("Actions"); + private final JTextArea noteInput = new JTextArea(); private final JButton saveButton = new JButton("Save"); - private final JButton refreshButton = new JButton("Refresh"); + private final JButton viewButtton = new JButton("View"); + private final JButton deleteButton = new JButton("Delete"); + private final JButton uploadButton = new JButton("Upload"); + private NoteController noteController; public NoteView(NoteViewModel noteViewModel) { @@ -36,25 +39,67 @@ public NoteView(NoteViewModel noteViewModel) { noteName.setAlignmentX(Component.CENTER_ALIGNMENT); this.noteViewModel = noteViewModel; this.noteViewModel.addPropertyChangeListener(this); + noteInput.setText(" "); + add(noteInput); final JPanel buttons = new JPanel(); buttons.add(saveButton); - buttons.add(refreshButton); + buttons.add(viewButtton); + buttons.add(deleteButton); + buttons.add(uploadButton); saveButton.addActionListener( evt -> { if (evt.getSource().equals(saveButton)) { - noteController.execute(noteInputField.getText()); + final JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle("Save Note"); + fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); + final int returnVal = fileChooser.showOpenDialog(this); + if (returnVal == JFileChooser.APPROVE_OPTION) { + final File file = fileChooser.getSelectedFile(); + try { + if (file.exists()) { + final BufferedWriter writer = new BufferedWriter(new FileWriter(file)); + writer.write(noteInput.getText()); + } + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + noteController.execute(noteInput.getText()); } } ); - refreshButton.addActionListener( + deleteButton.addActionListener( evt -> { - if (evt.getSource().equals(refreshButton)) { - noteController.execute(null); + if (evt.getSource().equals(deleteButton)) { + noteInput.setText(""); + } + } + ); + viewButtton.addActionListener( + evt -> { + if (evt.getSource().equals(viewButtton)) { + final JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle("View"); + fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); + final int returnVal = fileChooser.showOpenDialog(this); + if (returnVal == JFileChooser.APPROVE_OPTION) { + try { + String text = " "; + for (String line : Files.readAllLines(fileChooser.getSelectedFile().toPath())) { + text += line + "\n"; + noteInput.setText(text); + } + } + catch (IOException e) { + throw new RuntimeException(e); + } + } } } ); @@ -62,7 +107,7 @@ public NoteView(NoteViewModel noteViewModel) { this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.add(noteName); - this.add(noteInputField); + this.add(noteInput); this.add(buttons); } @@ -85,7 +130,7 @@ public void propertyChange(PropertyChangeEvent evt) { } private void setFields(NoteState state) { - noteInputField.setText(state.getNote()); + noteInput.setText(state.getNote()); } public void setNoteController(NoteController controller) { From dfe8799dc4f265923c0d47ed2531e9df407e113c Mon Sep 17 00:00:00 2001 From: akhimie1 Date: Sat, 9 Nov 2024 15:31:28 -0500 Subject: [PATCH 20/56] I am setting up the Notes view actions: save, view, delete... --- src/main/java/view/NoteView.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/view/NoteView.java b/src/main/java/view/NoteView.java index df64115e2..ba3ed549a 100644 --- a/src/main/java/view/NoteView.java +++ b/src/main/java/view/NoteView.java @@ -28,9 +28,9 @@ public class NoteView extends JPanel implements ActionListener, PropertyChangeLi private final JTextArea noteInput = new JTextArea(); private final JButton saveButton = new JButton("Save"); + private final JButton saveAsButton = new JButton("Save As"); private final JButton viewButtton = new JButton("View"); private final JButton deleteButton = new JButton("Delete"); - private final JButton uploadButton = new JButton("Upload"); private NoteController noteController; @@ -44,9 +44,9 @@ public NoteView(NoteViewModel noteViewModel) { final JPanel buttons = new JPanel(); buttons.add(saveButton); + buttons.add(saveAsButton); buttons.add(viewButtton); buttons.add(deleteButton); - buttons.add(uploadButton); saveButton.addActionListener( evt -> { @@ -54,13 +54,13 @@ public NoteView(NoteViewModel noteViewModel) { final JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Save Note"); fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); - final int returnVal = fileChooser.showOpenDialog(this); + final int returnVal = fileChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { - final File file = fileChooser.getSelectedFile(); try { - if (file.exists()) { - final BufferedWriter writer = new BufferedWriter(new FileWriter(file)); - writer.write(noteInput.getText()); + final File selectedFile = fileChooser.getSelectedFile(); + if (selectedFile.exists()) { + final FileWriter writer = new FileWriter(selectedFile); + writer.write("Hello"); } } catch (IOException e) { From eb85edfd34a294cbf798fa2aabe74ed32f18e617 Mon Sep 17 00:00:00 2001 From: akhimie1 Date: Sun, 10 Nov 2024 20:28:14 -0500 Subject: [PATCH 21/56] I added the functionalities for add title, clear, upload and delete. I tried to add some style functionalities. It is not working yet. --- src/main/java/app/NoteAppBuilder.java | 5 +- src/main/java/entity/Note.java | 10 +- .../note/NoteController.java | 35 +++-- .../use_cases/note/NoteInputBoundary.java | 19 ++- .../java/use_cases/note/NoteInteractor.java | 48 ++----- src/main/java/view/NoteView.java | 121 +++++++++++------- .../use_cases/note/NoteInteractorTest.java | 59 +++++---- 7 files changed, 157 insertions(+), 140 deletions(-) diff --git a/src/main/java/app/NoteAppBuilder.java b/src/main/java/app/NoteAppBuilder.java index f42c1c964..ea143d817 100644 --- a/src/main/java/app/NoteAppBuilder.java +++ b/src/main/java/app/NoteAppBuilder.java @@ -41,8 +41,7 @@ public NoteAppBuilder addNoteDAO(NoteDataAccessInterface noteDataAccess) { */ public NoteAppBuilder addNoteUseCase() { final NoteOutputBoundary noteOutputBoundary = new NotePresenter(noteViewModel); - noteInteractor = new NoteInteractor( - noteDAO, noteOutputBoundary); + noteInteractor = new NoteInteractor(noteOutputBoundary); final NoteController controller = new NoteController(noteInteractor); if (noteView == null) { @@ -75,7 +74,7 @@ public JFrame build() { frame.add(noteView); // refresh so that the note will be visible when we start the program - noteInteractor.executeRefresh(); +// noteInteractor.executeRefresh(); return frame; diff --git a/src/main/java/entity/Note.java b/src/main/java/entity/Note.java index 9cd116cfb..889ff0110 100644 --- a/src/main/java/entity/Note.java +++ b/src/main/java/entity/Note.java @@ -6,18 +6,18 @@ public class Note { private final String content; - private final String creationDate; + private final String title; - public Note(String content, String creationDate) { + public Note(String content, String title) { this.content = content; - this.creationDate = creationDate; + this.title = title; } public String getContent() { return content; } - public String getCreationDate() { - return creationDate; + public String getTitle() { + return title; } } diff --git a/src/main/java/interface_adapter/note/NoteController.java b/src/main/java/interface_adapter/note/NoteController.java index 04ff417c8..4bad38391 100644 --- a/src/main/java/interface_adapter/note/NoteController.java +++ b/src/main/java/interface_adapter/note/NoteController.java @@ -1,28 +1,41 @@ package interface_adapter.note; -import use_cases.note.NoteInputBoundary; +import use_cases.note.NoteInteractor; /** * Controller for our Note related Use Cases. */ public class NoteController { - private final NoteInputBoundary noteInteractor; + private final NoteInteractor noteInteractor; - public NoteController(NoteInputBoundary noteInteractor) { + public NoteController(NoteInteractor noteInteractor) { this.noteInteractor = noteInteractor; } /** * Executes the Note related Use Cases. - * @param note the note to be recorded + * @param content the content of the note being worked on + * @param title the title of the note */ - public void execute(String note) { - if (note != null) { - noteInteractor.executeSave(note); - } - else { - noteInteractor.executeRefresh(); - } + public void save(String content, String title) { + noteInteractor.executeSave(content, title); } + + /** + * Executes the Note related Use Cases. + * @param content the content of the note being worked on + */ + public void clear(String content) { + noteInteractor.executeClear(content); + } + + /** + * Executes the Note related Use Cases. + * @param content the content of the note being worked on + */ + public void updateContent(String content) { + noteInteractor.executeUpload(content); + } + } diff --git a/src/main/java/use_cases/note/NoteInputBoundary.java b/src/main/java/use_cases/note/NoteInputBoundary.java index 5a804e3ec..55dc6629a 100644 --- a/src/main/java/use_cases/note/NoteInputBoundary.java +++ b/src/main/java/use_cases/note/NoteInputBoundary.java @@ -7,13 +7,22 @@ public interface NoteInputBoundary { /** - * Executes the refresh note use case. + * Executes the save note use case. + * @param content the note being worked on + * @param title the title of note */ - void executeRefresh(); + void executeSave(String content, String title); /** - * Executes the save note use case. - * @param message the input data + * Executes the upload note use case. + * @param content the note being worked on + */ + void executeUpload(String content); + + /** + * Executes the clear note use case. + * @param content the note being worked on */ - void executeSave(String message); + void executeClear(String content); + } diff --git a/src/main/java/use_cases/note/NoteInteractor.java b/src/main/java/use_cases/note/NoteInteractor.java index 9d3af6e5a..10e09b80b 100644 --- a/src/main/java/use_cases/note/NoteInteractor.java +++ b/src/main/java/use_cases/note/NoteInteractor.java @@ -1,7 +1,5 @@ package use_cases.note; -import entity.User; - /** * The "Use Case Interactor" for our two note-related use cases of refreshing * the contents of the note and saving the contents of the note. Since they @@ -9,51 +7,27 @@ */ public class NoteInteractor implements NoteInputBoundary { - private final NoteDataAccessInterface noteDataAccessInterface; private final NoteOutputBoundary noteOutputBoundary; - // Note: this program has it hardcoded which user object it is getting data for; - // you could change this if you wanted to generalize the code. For example, - // you might allow a user of the program to create a new note, which you - // could store as a "user" through the API OR you might maintain all notes - // in a JSON object stored in one common "user" stored through the API. - private final User user = new User("jonathan_calver2", "abc123"); - public NoteInteractor(NoteDataAccessInterface noteDataAccessInterface, - NoteOutputBoundary noteOutputBoundary) { - this.noteDataAccessInterface = noteDataAccessInterface; + public NoteInteractor(NoteOutputBoundary noteOutputBoundary) { this.noteOutputBoundary = noteOutputBoundary; } - /** - * Executes the refresh note use case. - * - */ @Override - public void executeRefresh() { - try { + public void executeSave(String content, String title) { + this.noteOutputBoundary.prepareSuccessView(content); + } - final String note = noteDataAccessInterface.loadNote(user); - noteOutputBoundary.prepareSuccessView(note); - } - catch (DataAccessException ex) { - noteOutputBoundary.prepareFailView(ex.getMessage()); + @Override + public void executeUpload(String content) { + if (content == null || content.isEmpty()) { + this.noteOutputBoundary.prepareFailView("Upload failed"); } + this.noteOutputBoundary.prepareSuccessView(content); } - /** - * Executes the save note use case. - * - * @param note the input data - */ @Override - public void executeSave(String note) { - try { - - final String updatedNote = noteDataAccessInterface.saveNote(user, note); - noteOutputBoundary.prepareSuccessView(updatedNote); - } - catch (DataAccessException ex) { - noteOutputBoundary.prepareFailView(ex.getMessage()); - } + public void executeClear(String content) { + this.noteOutputBoundary.prepareSuccessView(" "); } } diff --git a/src/main/java/view/NoteView.java b/src/main/java/view/NoteView.java index ba3ed549a..d3fda4c85 100644 --- a/src/main/java/view/NoteView.java +++ b/src/main/java/view/NoteView.java @@ -5,13 +5,12 @@ import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; +import java.io.*; import javax.swing.*; +import javax.swing.text.MutableAttributeSet; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyledEditorKit; import interface_adapter.note.NoteController; import interface_adapter.note.NoteState; @@ -24,14 +23,21 @@ public class NoteView extends JPanel implements ActionListener, PropertyChangeLi private final NoteViewModel noteViewModel; - private final JLabel noteName = new JLabel("Actions"); - private final JTextArea noteInput = new JTextArea(); + private final JLabel noteName = new JLabel("New Note"); + private final JTextArea noteInputField = new JTextArea(); + private final JMenuBar menuBar = new JMenuBar(); - private final JButton saveButton = new JButton("Save"); - private final JButton saveAsButton = new JButton("Save As"); - private final JButton viewButtton = new JButton("View"); + private final JButton addButton = new JButton("Add Title"); + private final JButton uploadButton = new JButton("Upload"); + private final JButton clearButton = new JButton("Clear"); private final JButton deleteButton = new JButton("Delete"); + private final JMenuItem boldMenu = new JMenuItem("Bold"); + private final JMenuItem italicMenu = new JMenuItem("Italic"); + private final JMenuItem underlineMenu = new JMenuItem("Underline"); + private final JMenu redoMenu = new JMenu("Redo"); + private final JMenu undoMenu = new JMenu("Undo"); + private NoteController noteController; public NoteView(NoteViewModel noteViewModel) { @@ -39,76 +45,93 @@ public NoteView(NoteViewModel noteViewModel) { noteName.setAlignmentX(Component.CENTER_ALIGNMENT); this.noteViewModel = noteViewModel; this.noteViewModel.addPropertyChangeListener(this); - noteInput.setText(" "); - add(noteInput); final JPanel buttons = new JPanel(); - buttons.add(saveButton); - buttons.add(saveAsButton); - buttons.add(viewButtton); + buttons.add(addButton); + buttons.add(uploadButton); + buttons.add(clearButton); buttons.add(deleteButton); - saveButton.addActionListener( + addButton.addActionListener( + evt -> { + if (evt.getSource().equals(addButton)) { + final String newNoteName = JOptionPane.showInputDialog("Enter new note name"); + noteName.setText(newNoteName); + noteController.save(noteInputField.getText(), noteName.getText()); + + } + } + ); + + uploadButton.addActionListener( evt -> { - if (evt.getSource().equals(saveButton)) { + if (evt.getSource().equals(uploadButton)) { final JFileChooser fileChooser = new JFileChooser(); - fileChooser.setDialogTitle("Save Note"); - fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); - final int returnVal = fileChooser.showSaveDialog(this); + fileChooser.setDialogTitle("Upload"); + final int returnVal = fileChooser.showOpenDialog(this); + final File selectedFile = fileChooser.getSelectedFile(); if (returnVal == JFileChooser.APPROVE_OPTION) { try { - final File selectedFile = fileChooser.getSelectedFile(); - if (selectedFile.exists()) { - final FileWriter writer = new FileWriter(selectedFile); - writer.write("Hello"); + final BufferedReader reader = new BufferedReader(new FileReader(selectedFile)); + noteInputField.setText(""); + String line; + while ((line = reader.readLine()) != null) { + noteInputField.append(line); + noteInputField.append("\n"); } + noteController.updateContent(noteInputField.getText()); } - catch (IOException e) { - throw new RuntimeException(e); + catch (IOException exception) { + JOptionPane.showMessageDialog(this, exception.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } - noteController.execute(noteInput.getText()); } } ); + clearButton.addActionListener( + evt -> { + if (evt.getSource().equals(clearButton)) { + noteController.clear(noteInputField.getText()); + } + } + ); + deleteButton.addActionListener( evt -> { if (evt.getSource().equals(deleteButton)) { - noteInput.setText(""); + noteController.clear(noteInputField.getText()); + noteName.setText("New Note"); } } ); - viewButtton.addActionListener( + final JMenu editMenu = new JMenu("Edit"); + editMenu.add(boldMenu); + editMenu.add(italicMenu); + editMenu.add(underlineMenu); + menuBar.add(editMenu); + menuBar.add(redoMenu); + menuBar.add(undoMenu); + + boldMenu.addActionListener( evt -> { - if (evt.getSource().equals(viewButtton)) { - final JFileChooser fileChooser = new JFileChooser(); - fileChooser.setDialogTitle("View"); - fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); - final int returnVal = fileChooser.showOpenDialog(this); - if (returnVal == JFileChooser.APPROVE_OPTION) { - try { - String text = " "; - for (String line : Files.readAllLines(fileChooser.getSelectedFile().toPath())) { - text += line + "\n"; - noteInput.setText(text); - } - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - } + final JTextPane textPane = new JTextPane(); + noteInputField.add(textPane); + textPane.setEditorKit(new StyledEditorKit()); + final StyledEditorKit.BoldAction boldAction = new StyledEditorKit.BoldAction(); + boldAction.actionPerformed(evt); } ); this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.add(noteName); - this.add(noteInput); + this.add(menuBar); + this.add(noteInputField); this.add(buttons); + } /** @@ -130,7 +153,7 @@ public void propertyChange(PropertyChangeEvent evt) { } private void setFields(NoteState state) { - noteInput.setText(state.getNote()); + noteInputField.setText(state.getNote()); } public void setNoteController(NoteController controller) { diff --git a/src/test/java/use_cases/note/NoteInteractorTest.java b/src/test/java/use_cases/note/NoteInteractorTest.java index 857c2bb4f..a4723e2b1 100644 --- a/src/test/java/use_cases/note/NoteInteractorTest.java +++ b/src/test/java/use_cases/note/NoteInteractorTest.java @@ -10,36 +10,35 @@ public class NoteInteractorTest { @Test public void testExecuteRefreshSuccess() { - NoteDataAccessInterface noteDAO = new NoteDataAccessInterface() { - - - @Override - public String saveNote(User user, String note) { - return ""; - } - - - @Override - public String loadNote(User user) { - return "test"; - } - }; - - NoteOutputBoundary noteOB = new NoteOutputBoundary() { - @Override - public void prepareSuccessView(String message) { - assertEquals("test", message); - } - - @Override - public void prepareFailView(String errorMessage) { - fail(errorMessage); - } - }; - - NoteInteractor noteInteractor = new NoteInteractor(noteDAO, noteOB); - - noteInteractor.executeRefresh(); +// NoteDataAccessInterface noteDAO = new NoteDataAccessInterface() { +// +// +// @Override +// public String saveNote(User user, String note) { +// return ""; +// } +// +// +// @Override +// public String loadNote(User user) { +// return "test"; +// } +// }; +// +// NoteOutputBoundary noteOB = new NoteOutputBoundary() { +// @Override +// public void prepareSuccessView(String message) { +// assertEquals("test", message); +// } +// +// @Override +// public void prepareFailView(String errorMessage) { +// fail(errorMessage); +// } +// }; +// +// NoteInteractor noteInteractor = new NoteInteractor(noteOB); +// noteInteractor.executeSave(); } From 30e4489a47a040854032d90f878d0384cbfdbecb Mon Sep 17 00:00:00 2001 From: stickycorner Date: Mon, 11 Nov 2024 13:58:09 -0500 Subject: [PATCH 22/56] added the views and updated the main note application to use them. started writing out the AiInteractor. --- README.md | 8 +-- pom.xml | 6 ++ src/main/java/app/AppBuilder.java | 13 ---- src/main/java/app/MainNoteApplication.java | 62 ++++++++++++------- .../interface_adapter/ai/AiController.java | 7 ++- .../calendar/CalendarController.java | 5 ++ src/main/java/use_cases/ai/AiInteractor.java | 14 ++--- src/main/java/view/CalendarView.java | 30 ++++++++- src/main/java/view/ChecklistView.java | 5 +- src/main/java/view/DashboardView.java | 13 +++- src/main/java/view/NotesView.java | 57 ++++++++++++++++- 11 files changed, 164 insertions(+), 56 deletions(-) delete mode 100644 src/main/java/app/AppBuilder.java create mode 100644 src/main/java/interface_adapter/calendar/CalendarController.java diff --git a/README.md b/README.md index 8568eeb18..96648e4db 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -USERNAMES +### Usernames -Jenna Zhang - stickycorner -Prisha Patel - PrishaPatel24 +- Jenna Zhang - stickycorner +- Prisha Patel - PrishaPatel24 -USER STORIES +### User Stories - Calendar: User wants to update their schedule for the day. They navigate to the calendar and delete an existing event in their calendar. Then, the user adds a new event in place of the old one. The user checks when the event will take place and adds a note to the event. - Note-taking: User wants to view an already existing note. User is already logged into an account. User opens the note-taking tab and writes the name of already existing note in search bar. If found, note is opened and displayed. If not found, user is told to type the name again. diff --git a/pom.xml b/pom.xml index 527f61e36..aaea666d8 100644 --- a/pom.xml +++ b/pom.xml @@ -10,6 +10,12 @@ + + com.google.cloud + google-cloud-aiplatform + 3.35.0 + + org.json json diff --git a/src/main/java/app/AppBuilder.java b/src/main/java/app/AppBuilder.java deleted file mode 100644 index 0885e9b3e..000000000 --- a/src/main/java/app/AppBuilder.java +++ /dev/null @@ -1,13 +0,0 @@ -package app; - -import interface_adapter.note.NoteViewModel; -import use_cases.note.NoteDataAccessInterface; -import use_cases.note.NoteInteractor; -import view.NoteView; - -public class AppBuilder { - public static final int HEIGHT = 300; - public static final int WIDTH = 400; - private NoteView noteView; - private NoteInteractor noteInteractor; -} diff --git a/src/main/java/app/MainNoteApplication.java b/src/main/java/app/MainNoteApplication.java index a93ee11a4..7ebff3461 100644 --- a/src/main/java/app/MainNoteApplication.java +++ b/src/main/java/app/MainNoteApplication.java @@ -1,45 +1,38 @@ package app; +import org.jetbrains.annotations.NotNull; + import javax.swing.*; import java.awt.*; +import view.CalendarView; +import view.ChecklistView; +import view.DashboardView; +import view.NotesView; + +/** + * The main application to boot the program. + */ public class MainNoteApplication { static final int WIDTH = 850; - static final int HEIGHT = 300; + static final int HEIGHT = 500; public static void main(String[] args) { SwingUtilities.invokeLater(() -> { final CardLayout cardLayout = new CardLayout(); final JPanel cardPanel = new JPanel(cardLayout); - final JPanel dashboardPanel = createDashboard(); - final JPanel notesPanel = createNotes(); - final JPanel calendarPanel = createCalendar(); - final JPanel checklistPanel = createChecklist(); + final JPanel dashboardPanel = new DashboardView(); + final JPanel notesPanel = new NotesView(); + final JPanel calendarPanel = new CalendarView(); + final JPanel checklistPanel = new ChecklistView(); cardPanel.add(dashboardPanel, "Dashboard"); cardPanel.add(notesPanel, "Notes"); cardPanel.add(calendarPanel, "Calendar"); cardPanel.add(checklistPanel, "Checklist"); - final JButton showCalendarButton = new JButton("Calendar"); - showCalendarButton.addActionListener(event -> cardLayout.show(cardPanel, "Calendar")); - - final JButton showNotesButton = new JButton("Notes"); - showNotesButton.addActionListener(event -> cardLayout.show(cardPanel, "Notes")); - - final JButton showChecklistButton = new JButton("Checklist"); - showChecklistButton.addActionListener(event -> cardLayout.show(cardPanel, "Checklist")); - - final JButton homeButton = new JButton("Dashboard"); - homeButton.addActionListener(event -> cardLayout.show(cardPanel, "Dashboard")); - - final JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS)); - buttonPanel.add(homeButton); - buttonPanel.add(showCalendarButton); - buttonPanel.add(showNotesButton); - buttonPanel.add(showChecklistButton); + final JPanel buttonPanel = getButtonPanel(cardLayout, cardPanel); final JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(buttonPanel, BorderLayout.WEST); @@ -53,6 +46,29 @@ public static void main(String[] args) { }); } + @NotNull + private static JPanel getButtonPanel(CardLayout cardLayout, JPanel cardPanel) { + final JButton showCalendarButton = new JButton("Calendar"); + showCalendarButton.addActionListener(event -> cardLayout.show(cardPanel, "Calendar")); + + final JButton showNotesButton = new JButton("Notes"); + showNotesButton.addActionListener(event -> cardLayout.show(cardPanel, "Notes")); + + final JButton showChecklistButton = new JButton("Checklist"); + showChecklistButton.addActionListener(event -> cardLayout.show(cardPanel, "Checklist")); + + final JButton homeButton = new JButton("Dashboard"); + homeButton.addActionListener(event -> cardLayout.show(cardPanel, "Dashboard")); + + final JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS)); + buttonPanel.add(homeButton); + buttonPanel.add(showCalendarButton); + buttonPanel.add(showNotesButton); + buttonPanel.add(showChecklistButton); + return buttonPanel; + } + private static JPanel createDashboard() { final JPanel dashboardPanel = new JPanel(); dashboardPanel.add(new JLabel("Welcome to your Dashboard")); diff --git a/src/main/java/interface_adapter/ai/AiController.java b/src/main/java/interface_adapter/ai/AiController.java index 3d6946328..a5be23e8f 100644 --- a/src/main/java/interface_adapter/ai/AiController.java +++ b/src/main/java/interface_adapter/ai/AiController.java @@ -2,6 +2,9 @@ import use_cases.ai.AiInputBoundary; +/** + * The controller for the AI use case. + */ public class AiController { private final AiInputBoundary aiInteractor; @@ -14,7 +17,7 @@ public AiController(AiInputBoundary aiInputBoundary) { * @param note The note in the JTextArea written by the user. */ public void generateResponse(String note) { - aiInteractor.generateResponse(note + "Please complete the note based on the" - + "given notes."); + aiInteractor.generateResponse(note + "Please briefly complete the note with a few sentences" + + "based on the given notes."); } } diff --git a/src/main/java/interface_adapter/calendar/CalendarController.java b/src/main/java/interface_adapter/calendar/CalendarController.java new file mode 100644 index 000000000..90d28dacc --- /dev/null +++ b/src/main/java/interface_adapter/calendar/CalendarController.java @@ -0,0 +1,5 @@ +package interface_adapter.calendar; + +public class CalendarController { + +} diff --git a/src/main/java/use_cases/ai/AiInteractor.java b/src/main/java/use_cases/ai/AiInteractor.java index 431a34f69..dd8d3a7ae 100644 --- a/src/main/java/use_cases/ai/AiInteractor.java +++ b/src/main/java/use_cases/ai/AiInteractor.java @@ -6,17 +6,13 @@ * The class that will implement the different functions of AI in the program. * It will generate a completed written version of the current note. */ -public class AiInteractor { - private final String key; - private final AiInputBoundary aiInputBoundary; +public class AiInteractor implements AiInputBoundary { private final AiOutputBoundary aiOutputBoundary; // take in note panel in attribute or in parameter to the method, defining interfaces, etc // decide on functions for the calendar, load events, oauth 2 login, edit/modify events? - AiInteractor(AiInputBoundary aiInputBoundary, AiOutputBoundary aiOutputBoundary) { - this.key = ""; - this.aiInputBoundary = aiInputBoundary; + public AiInteractor(AiInputBoundary aiInputBoundary, AiOutputBoundary aiOutputBoundary) { this.aiOutputBoundary = aiOutputBoundary; } @@ -31,11 +27,11 @@ public String getNote(JTextArea textArea) { /** * Auto-complete the current notes written by the user with AI. + * * @param currNote The call to the AI to complete the current note. - * @return The generated AI response. */ - public String generateResponse(String currNote) { + public void generateResponse(String currNote) { // call to API here - return ""; + aiOutputBoundary.updateNote(currNote); } } diff --git a/src/main/java/view/CalendarView.java b/src/main/java/view/CalendarView.java index 122c2f997..47c940935 100644 --- a/src/main/java/view/CalendarView.java +++ b/src/main/java/view/CalendarView.java @@ -1,4 +1,32 @@ package view; -public class CalendarView { +import javax.swing.*; + +import interface_adapter.calendar.CalendarController; + +/** + * The view for the calendar use case. + */ +public class CalendarView extends JPanel { + private final JLabel promptLabel; + private final JButton loginButton; + private CalendarController calendarController; + + public CalendarView() { + this.promptLabel = new JLabel("Login to Google Calendar here."); + this.loginButton = new JButton("Login"); + loginButton.addActionListener( + evt -> { + if (evt.getSource().equals(loginButton)) { + // some action to do here + } + } + ); + this.add(this.promptLabel); + this.add(this.loginButton); + } + + public void setCalendarController(CalendarController calendarController) { + this.calendarController = calendarController; + } } diff --git a/src/main/java/view/ChecklistView.java b/src/main/java/view/ChecklistView.java index ff4c4fb40..d3cbdb6a4 100644 --- a/src/main/java/view/ChecklistView.java +++ b/src/main/java/view/ChecklistView.java @@ -6,9 +6,10 @@ /** * The view and taking in the inputs for the checklist section of the program. */ -public class ChecklistView { +public class ChecklistView extends JPanel { private final JButton taskButton; private final JLabel label; + // @prisha fix everything here pls public ChecklistView() { final JPanel checklistPanel = new JPanel(); @@ -26,4 +27,6 @@ public ChecklistView() { } ); } + + // add checklist controller here } diff --git a/src/main/java/view/DashboardView.java b/src/main/java/view/DashboardView.java index bd7afac9a..2a2c36fc7 100644 --- a/src/main/java/view/DashboardView.java +++ b/src/main/java/view/DashboardView.java @@ -1,4 +1,15 @@ package view; -public class DashboardView { +import javax.swing.*; + +/** + * Default open screen for the program. + */ +public class DashboardView extends JPanel { + private final JLabel welcomeText; + + public DashboardView() { + welcomeText = new JLabel("Welcome to your Dashboard."); + this.add(welcomeText); + } } diff --git a/src/main/java/view/NotesView.java b/src/main/java/view/NotesView.java index 07763600e..9d1b418fb 100644 --- a/src/main/java/view/NotesView.java +++ b/src/main/java/view/NotesView.java @@ -1,8 +1,61 @@ package view; +import interface_adapter.ai.AiController; +import use_cases.ai.AiInteractor; + import javax.swing.*; -import java.awt.event.ActionListener; +import java.awt.*; + +public class NotesView extends JPanel { + private final JTextArea notesTextArea; + private final JPanel toolBarPanel; + private final JButton aiButton; + private final JButton languageButton; + private final JTextArea outputArea; + private AiController aiController; + // add controllers and other view methods as necessary for language and note use cases + + public NotesView() { + this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); + final JPanel igeePanel = new JPanel(); + this.notesTextArea = new JTextArea(); + igeePanel.add(notesTextArea); + this.add(notesTextArea); + // @Igee the Notes text area is basically just a field to where youd add your stuff. + + this.toolBarPanel = new JPanel(); + toolBarPanel.setLayout(new BoxLayout(toolBarPanel, BoxLayout.Y_AXIS)); + this.aiButton = new JButton("Complete Notes With AI"); + aiButton.addActionListener( + evt -> { + if (evt.getSource().equals(aiButton)) { + aiController.generateResponse(notesTextArea.getText()); + } + } + ); + toolBarPanel.add(aiButton); + + this.languageButton = new JButton("Translate to Other Language"); + languageButton.addActionListener( + evt -> { + if (evt.getSource().equals(languageButton)) { + // call controlller here + } + } + ); + toolBarPanel.add(languageButton); + + this.outputArea = new JTextArea(); + outputArea.setEditable(false); + outputArea.setSize(75, 50); + toolBarPanel.add(outputArea); + + this.add(toolBarPanel); + } -public class NotesView { + public void setAiController(AiController aiController) { + this.aiController = aiController; + } + // add methods for other controllers here } From 26bea7d5e7169b063af6e1ba6ec63bb2c5ea1ba8 Mon Sep 17 00:00:00 2001 From: Prisha Patel Date: Mon, 11 Nov 2024 14:21:02 -0500 Subject: [PATCH 23/56] interactor test for add_task use case --- .../add_task/AddTaskInteractorTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/test/java/use_cases/add_task/AddTaskInteractorTest.java diff --git a/src/test/java/use_cases/add_task/AddTaskInteractorTest.java b/src/test/java/use_cases/add_task/AddTaskInteractorTest.java new file mode 100644 index 000000000..3d607f51e --- /dev/null +++ b/src/test/java/use_cases/add_task/AddTaskInteractorTest.java @@ -0,0 +1,30 @@ +package use_cases.add_task; + +import entity.Task; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class AddTaskInteractorTest { + + @Test + public void successTest() { + + final AddTaskInputData inputData = new AddTaskInputData("test description"); + + AddTaskOutputBoundary addTaskOB = new AddTaskOutputBoundary() { + @Override + public void prepareSuccessView(AddTaskOutputData outputData) { + assertEquals("test description", outputData.getDescription()); + } + + @Override + public void prepareFailView(String errorMessage) { + fail("Use case failure is unexpected."); + } + }; + AddTaskInteractor addTaskInteractor = new AddTaskInteractor(addTaskOB); + addTaskInteractor.execute(inputData); + } +} From ab11a50a7160ef92655014649d2b664f09ed5a36 Mon Sep 17 00:00:00 2001 From: Prisha Patel Date: Mon, 11 Nov 2024 14:27:32 -0500 Subject: [PATCH 24/56] committing my changes before git pull --- src/main/java/app/MainNoteApplication.java | 2 +- src/main/java/view/ChecklistView.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/app/MainNoteApplication.java b/src/main/java/app/MainNoteApplication.java index 84cfb77b9..fe355877f 100644 --- a/src/main/java/app/MainNoteApplication.java +++ b/src/main/java/app/MainNoteApplication.java @@ -15,7 +15,7 @@ public class MainNoteApplication { static final int WIDTH = 850; - static final int HEIGHT = 300; + static final int HEIGHT = 500; public static void main(String[] args) { SwingUtilities.invokeLater(() -> { diff --git a/src/main/java/view/ChecklistView.java b/src/main/java/view/ChecklistView.java index c83bc2e94..373917eca 100644 --- a/src/main/java/view/ChecklistView.java +++ b/src/main/java/view/ChecklistView.java @@ -34,7 +34,7 @@ public ChecklistView(TaskViewModel taskViewModel) { this.checklistPanel.add(new JLabel("Tasks go here!")); checklistPanel.add(addTaskButton); - final JButton emptyBox = new JButton(); + final JButton emptyBox = new JButton(" "); final JButton checkedBox = new JButton("X"); emptyBox.setPreferredSize(checkedBox.getPreferredSize()); emptyBox.setVisible(false); From 6492b119c83f92dfb0d9bc0f2e5e9d42e8bae4ae Mon Sep 17 00:00:00 2001 From: Prisha Patel Date: Mon, 11 Nov 2024 14:41:21 -0500 Subject: [PATCH 25/56] connected my ChecklistView to Main --- src/main/java/app/MainNoteApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/app/MainNoteApplication.java b/src/main/java/app/MainNoteApplication.java index 8931aa2cd..3e56b360e 100644 --- a/src/main/java/app/MainNoteApplication.java +++ b/src/main/java/app/MainNoteApplication.java @@ -26,7 +26,7 @@ public static void main(String[] args) { final JPanel dashboardPanel = new DashboardView(); final JPanel notesPanel = new NotesView(); final JPanel calendarPanel = new CalendarView(); - final JPanel checklistPanel = new ChecklistView(); + final JPanel checklistPanel = createChecklist(); cardPanel.add(dashboardPanel, "Dashboard"); cardPanel.add(notesPanel, "Notes"); From 359809bcf17d251014da004c24514afacf74815b Mon Sep 17 00:00:00 2001 From: Prisha Patel Date: Wed, 13 Nov 2024 21:27:40 -0500 Subject: [PATCH 26/56] finalized checklist view and updated main to sync changes --- src/main/java/app/MainNoteApplication.java | 9 ++ .../add_task/AddTaskPresenter.java | 3 +- .../add_task/TaskViewModel.java | 1 - src/main/java/view/ChecklistView.java | 90 +++++++------------ 4 files changed, 44 insertions(+), 59 deletions(-) diff --git a/src/main/java/app/MainNoteApplication.java b/src/main/java/app/MainNoteApplication.java index 3e56b360e..3c7428d84 100644 --- a/src/main/java/app/MainNoteApplication.java +++ b/src/main/java/app/MainNoteApplication.java @@ -1,11 +1,16 @@ package app; +import interface_adapter.add_task.AddTaskController; +import interface_adapter.add_task.AddTaskPresenter; import interface_adapter.add_task.TaskViewModel; import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; +import use_cases.add_task.AddTaskInputBoundary; +import use_cases.add_task.AddTaskInteractor; +import use_cases.add_task.AddTaskOutputBoundary; import view.CalendarView; import view.ChecklistView; import view.DashboardView; @@ -108,7 +113,11 @@ private static JPanel createNotes() { private static JPanel createChecklist() { final TaskViewModel taskViewModel = new TaskViewModel(); + final AddTaskOutputBoundary addTaskPresenter = new AddTaskPresenter(taskViewModel); + final AddTaskInputBoundary addTaskUseCaseInteractor = new AddTaskInteractor(addTaskPresenter); + final AddTaskController controller = new AddTaskController(addTaskUseCaseInteractor); final ChecklistView checklistView = new ChecklistView(taskViewModel); + checklistView.setTaskController(controller); return checklistView; } } diff --git a/src/main/java/interface_adapter/add_task/AddTaskPresenter.java b/src/main/java/interface_adapter/add_task/AddTaskPresenter.java index f681f737c..5d4a89e43 100644 --- a/src/main/java/interface_adapter/add_task/AddTaskPresenter.java +++ b/src/main/java/interface_adapter/add_task/AddTaskPresenter.java @@ -21,7 +21,8 @@ public void prepareSuccessView(AddTaskOutputData response) { final TaskState taskState = taskViewModel.getState(); taskState.setTask(response.getDescription()); taskState.setError(null); - this.taskViewModel.firePropertyChanged(); + this.taskViewModel.setState(taskState); + taskViewModel.firePropertyChanged(); } @Override diff --git a/src/main/java/interface_adapter/add_task/TaskViewModel.java b/src/main/java/interface_adapter/add_task/TaskViewModel.java index c7a2bd425..378a969bc 100644 --- a/src/main/java/interface_adapter/add_task/TaskViewModel.java +++ b/src/main/java/interface_adapter/add_task/TaskViewModel.java @@ -1,7 +1,6 @@ package interface_adapter.add_task; import interface_adapter.ViewModel; -import interface_adapter.add_task.TaskState; /** * The ViewModel for the TaskView. diff --git a/src/main/java/view/ChecklistView.java b/src/main/java/view/ChecklistView.java index 373917eca..564cb681b 100644 --- a/src/main/java/view/ChecklistView.java +++ b/src/main/java/view/ChecklistView.java @@ -11,6 +11,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; + /** * The View for when the user is viewing a checklist in the program. */ @@ -21,69 +22,45 @@ public class ChecklistView extends JPanel implements ActionListener, PropertyCha private final JPanel checklistPanel; private final JButton addTaskButton; - private final JTextArea taskInputField; - public ChecklistView(TaskViewModel taskViewModel) { + this.taskViewModel = taskViewModel; + this.taskViewModel.addPropertyChangeListener(this); + this.checklistPanel = new JPanel(); this.addTaskButton = new JButton("Add Task +"); - this.taskInputField = new JTextArea(); - taskInputField.setSize(10, 10); - taskInputField.setVisible(false); - this.checklistPanel.add(new JLabel("Tasks go here!")); + checklistPanel.setLayout(new BoxLayout(checklistPanel, BoxLayout.Y_AXIS)); + checklistPanel.add(new JLabel("Tasks:")); checklistPanel.add(addTaskButton); - final JButton emptyBox = new JButton(" "); - final JButton checkedBox = new JButton("X"); - emptyBox.setPreferredSize(checkedBox.getPreferredSize()); - emptyBox.setVisible(false); - checkedBox.setVisible(false); - - addTaskButton.addActionListener( - evt -> { - if (evt.getSource().equals(addTaskButton)) { - // add ChecklistController.dosomething() based - // on button - taskInputField.setVisible(true); - emptyBox.setVisible(true); - addTaskController.execute(taskInputField.getText()); - } - } - ); - - emptyBox.addActionListener( - evt -> { - if (evt.getSource().equals(emptyBox)) { - emptyBox.setVisible(false); - checkedBox.setVisible(true); - } - } - ); - - checkedBox.addActionListener( - evt -> { - if (evt.getSource().equals(checkedBox)) { - checkedBox.setVisible(false); - emptyBox.setVisible(true); - } - } - ); - - this.taskViewModel = taskViewModel; - this.taskViewModel.addPropertyChangeListener(this); - this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + this.add(checklistPanel); - final JPanel taskPanel = new JPanel(); - taskPanel.add(emptyBox); - taskPanel.add(checkedBox); - taskPanel.add(taskInputField); - taskPanel.setLayout(new BoxLayout(taskPanel, BoxLayout.X_AXIS)); + addTaskButton.addActionListener(evt -> { + if (evt.getSource().equals(addTaskButton)) { + final String taskDescription = JOptionPane.showInputDialog(this, + "Enter Task Description:", "New Task", JOptionPane.PLAIN_MESSAGE); + if (taskDescription != null && !taskDescription.trim().isEmpty()) { + addTask(taskDescription.trim()); + } + } + }); + } - checklistPanel.setLayout(new BoxLayout(checklistPanel, BoxLayout.Y_AXIS)); + /** + * Adds a new task to the checklist as a JCheckBox. + * @param taskDescription the description of the new task + */ + private void addTask(String taskDescription) { + final JPanel taskPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JCheckBox taskCheckBox = new JCheckBox(taskDescription); + taskPanel.add(taskCheckBox); checklistPanel.add(taskPanel); - this.add(checklistPanel); + + addTaskController.execute(taskDescription); + checklistPanel.revalidate(); + checklistPanel.repaint(); } /** @@ -97,19 +74,18 @@ public void actionPerformed(ActionEvent evt) { @Override public void propertyChange(PropertyChangeEvent evt) { final TaskState state = (TaskState) evt.getNewValue(); - setFields(state); + // setFields(state); if (state.getError() != null) { JOptionPane.showMessageDialog(this, state.getError(), "Error", JOptionPane.ERROR_MESSAGE); } } - private void setFields(TaskState state) { - taskInputField.setText(state.getTask().toString()); - } +// private void setFields(TaskState state) { +// state.setTask("test description"); +// } public void setTaskController(AddTaskController controller) { this.addTaskController = controller; } - } From eb34e1d70f9a2d0db629a71ee8e215f135a9f8aa Mon Sep 17 00:00:00 2001 From: stickycorner Date: Mon, 18 Nov 2024 13:59:48 -0500 Subject: [PATCH 27/56] added and completed entity tests --- src/main/java/entity/Note.java | 6 +++++- src/test/java/entity/EventTest.java | 33 +++++++++++++++++++++++++++++ src/test/java/entity/NoteTest.java | 24 +++++++++++++++++++++ src/test/java/entity/TaskTest.java | 24 +++++++++++++++++++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/test/java/entity/EventTest.java create mode 100644 src/test/java/entity/NoteTest.java create mode 100644 src/test/java/entity/TaskTest.java diff --git a/src/main/java/entity/Note.java b/src/main/java/entity/Note.java index 9cd116cfb..4c5d6ab51 100644 --- a/src/main/java/entity/Note.java +++ b/src/main/java/entity/Note.java @@ -5,7 +5,7 @@ */ public class Note { - private final String content; + private String content; private final String creationDate; public Note(String content, String creationDate) { @@ -17,6 +17,10 @@ public String getContent() { return content; } + public void setContent(String content) { + this.content = content; + } + public String getCreationDate() { return creationDate; } diff --git a/src/test/java/entity/EventTest.java b/src/test/java/entity/EventTest.java new file mode 100644 index 000000000..4fea8f092 --- /dev/null +++ b/src/test/java/entity/EventTest.java @@ -0,0 +1,33 @@ +package entity; + +import org.junit.Test; + +public class EventTest { + @Test + public void getEventNameTest() { + final Event testEvent = new Event("test name", "2024-11-18", + "test location", "extra notes go here"); + assert testEvent.getEventName().equals("test name"); + } + + @Test + public void getEventLocationTest() { + final Event testEvent = new Event("test name", "2024-11-18", + "test location", "extra notes go here"); + assert testEvent.getEventLocation().equals("test location"); + } + + @Test + public void getDateTimeTest() { + final Event testEvent = new Event("test name", "2024-11-18", + "test location", "extra notes go here"); + assert testEvent.getEventDatetime().equals("2024-11-18"); + } + + @Test + public void getNoteTest() { + final Event testEvent = new Event("test name", "2024-11-18", + "test location", "extra notes go here"); + assert testEvent.getEventNotes().equals("extra notes go here"); + } +} diff --git a/src/test/java/entity/NoteTest.java b/src/test/java/entity/NoteTest.java new file mode 100644 index 000000000..3aba5aed1 --- /dev/null +++ b/src/test/java/entity/NoteTest.java @@ -0,0 +1,24 @@ +package entity; + +import org.junit.Test; + +public class NoteTest { + @Test + public void getContentTest() { + final Note testNote = new Note("content of note is here", "2024-11-18"); + assert testNote.getContent().equals("content of note is here"); + } + + @Test + public void setContentTest() { + final Note testNote = new Note("content of note is here", "2024-11-18"); + testNote.setContent("new note content"); + assert testNote.getContent().equals("new note content"); + } + + @Test + public void getDateTest() { + final Note testNote = new Note("content of note is here", "2024-11-18"); + assert testNote.getCreationDate().equals("2024-11-18"); + } +} diff --git a/src/test/java/entity/TaskTest.java b/src/test/java/entity/TaskTest.java new file mode 100644 index 000000000..c265b0d01 --- /dev/null +++ b/src/test/java/entity/TaskTest.java @@ -0,0 +1,24 @@ +package entity; + +import org.junit.Test; + +public class TaskTest { + @Test + public void getTaskDescriptionTest() { + final Task testTask = new Task("title of task"); + assert testTask.getDescription().equals("title of task"); + } + + @Test + public void markDoneTest() { + final Task testTask = new Task("title of task"); + testTask.markDone(); + assert testTask.isDone(); + } + + @Test + public void notDoneTest() { + final Task testTask = new Task("title of task"); + assert !testTask.isDone(); + } +} From 903d0463579d6cb24f6c898d9cee34a0bde09385 Mon Sep 17 00:00:00 2001 From: akhimie1 Date: Thu, 21 Nov 2024 12:44:20 -0500 Subject: [PATCH 28/56] This is many commits in one commit. So, I made a couple of changes: 1. I resolved the conflict between the implementation of the notes view from the remote repo and mine. Then, I deleted NoteView.java. 2. I deleted some classes: DBNoteDataAccessObject.java and DataAccessException.java. I did not need them since I am saving the notes permanently to a database. 3. I added an Input Data class and an Output Data class. I also added an InMemoryNoteDataAccessObject.java. 4. P.S. I am still implementing Clean Architecture. --- src/main/java/app/MainNoteApplication.java | 11 +- src/main/java/app/NoteAppBuilder.java | 164 +++++++-------- .../data_access/DBNoteDataAccessObject.java | 107 ---------- .../InMemoryNoteDataAccessObject.java | 33 +++ .../use_cases/note/DataAccessException.java | 10 - .../note/NoteDataAccessInterface.java | 18 +- .../java/use_cases/note/NoteInputData.java | 22 ++ .../java/use_cases/note/NoteInteractor.java | 22 +- .../java/use_cases/note/NoteOutputData.java | 23 +++ src/main/java/view/NoteView.java | 163 --------------- src/main/java/view/NotesView.java | 190 +++++++++++++++--- .../java/app/MainNoteApplicationTest.java | 4 +- 12 files changed, 351 insertions(+), 416 deletions(-) delete mode 100644 src/main/java/data_access/DBNoteDataAccessObject.java create mode 100644 src/main/java/data_access/InMemoryNoteDataAccessObject.java delete mode 100644 src/main/java/use_cases/note/DataAccessException.java create mode 100644 src/main/java/use_cases/note/NoteInputData.java create mode 100644 src/main/java/use_cases/note/NoteOutputData.java delete mode 100644 src/main/java/view/NoteView.java diff --git a/src/main/java/app/MainNoteApplication.java b/src/main/java/app/MainNoteApplication.java index 7ebff3461..fe57e0806 100644 --- a/src/main/java/app/MainNoteApplication.java +++ b/src/main/java/app/MainNoteApplication.java @@ -1,14 +1,12 @@ package app; +import interface_adapter.note.NoteViewModel; import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; -import view.CalendarView; -import view.ChecklistView; -import view.DashboardView; -import view.NotesView; +import view.*; /** * The main application to boot the program. @@ -23,7 +21,10 @@ public static void main(String[] args) { final JPanel cardPanel = new JPanel(cardLayout); final JPanel dashboardPanel = new DashboardView(); - final JPanel notesPanel = new NotesView(); + + final NoteViewModel noteViewModel = new NoteViewModel(); + final JPanel notesPanel = new NotesView(noteViewModel); + final JPanel calendarPanel = new CalendarView(); final JPanel checklistPanel = new ChecklistView(); diff --git a/src/main/java/app/NoteAppBuilder.java b/src/main/java/app/NoteAppBuilder.java index ea143d817..a1d900f85 100644 --- a/src/main/java/app/NoteAppBuilder.java +++ b/src/main/java/app/NoteAppBuilder.java @@ -1,82 +1,82 @@ -package app; - -import javax.swing.JFrame; -import javax.swing.WindowConstants; - -import interface_adapter.note.NoteController; -import interface_adapter.note.NotePresenter; -import interface_adapter.note.NoteViewModel; -import use_cases.note.NoteDataAccessInterface; -import use_cases.note.NoteInteractor; -import use_cases.note.NoteOutputBoundary; -import view.NoteView; - -/** - * Builder for the Note Application. - */ -public class NoteAppBuilder { - public static final int HEIGHT = 300; - public static final int WIDTH = 400; - private NoteDataAccessInterface noteDAO; - private NoteViewModel noteViewModel = new NoteViewModel(); - private NoteView noteView; - private NoteInteractor noteInteractor; - - /** - * Sets the NoteDAO to be used in this application. - * @param noteDataAccess the DAO to use - * @return this builder - */ - public NoteAppBuilder addNoteDAO(NoteDataAccessInterface noteDataAccess) { - noteDAO = noteDataAccess; - return this; - } - - /** - * Creates the objects for the Note Use Case and connects the NoteView to its - * controller. - *

This method must be called after addNoteView!

- * @return this builder - * @throws RuntimeException if this method is called before addNoteView - */ - public NoteAppBuilder addNoteUseCase() { - final NoteOutputBoundary noteOutputBoundary = new NotePresenter(noteViewModel); - noteInteractor = new NoteInteractor(noteOutputBoundary); - - final NoteController controller = new NoteController(noteInteractor); - if (noteView == null) { - throw new RuntimeException("addNoteView must be called before addNoteUseCase"); - } - noteView.setNoteController(controller); - return this; - } - - /** - * Creates the NoteView and underlying NoteViewModel. - * @return this builder - */ - public NoteAppBuilder addNoteView() { - noteViewModel = new NoteViewModel(); - noteView = new NoteView(noteViewModel); - return this; - } - - /** - * Builds the application. - * @return the JFrame for the application - */ - public JFrame build() { - final JFrame frame = new JFrame(); - frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - frame.setTitle("Note Application"); - frame.setSize(WIDTH, HEIGHT); - - frame.add(noteView); - - // refresh so that the note will be visible when we start the program -// noteInteractor.executeRefresh(); - - return frame; - - } -} +//package app; +// +//import javax.swing.JFrame; +//import javax.swing.WindowConstants; +// +//import interface_adapter.note.NoteController; +//import interface_adapter.note.NotePresenter; +//import interface_adapter.note.NoteViewModel; +//import use_cases.note.NoteDataAccessInterface; +//import use_cases.note.NoteInteractor; +//import use_cases.note.NoteOutputBoundary; +//import view.NoteView; +// +///** +// * Builder for the Note Application. +// */ +//public class NoteAppBuilder { +// public static final int HEIGHT = 300; +// public static final int WIDTH = 400; +// private NoteDataAccessInterface noteDAO; +// private NoteViewModel noteViewModel = new NoteViewModel(); +// private NoteView noteView = new NoteView(); +// private NoteInteractor noteInteractor; +// +// /** +// * Sets the NoteDAO to be used in this application. +// * @param noteDataAccess the DAO to use +// * @return this builder +// */ +// public NoteAppBuilder addNoteDAO(NoteDataAccessInterface noteDataAccess) { +// noteDAO = noteDataAccess; +// return this; +// } +// +// /** +// * Creates the objects for the Note Use Case and connects the NoteView to its +// * controller. +// *

This method must be called after addNoteView!

+// * @return this builder +// * @throws RuntimeException if this method is called before addNoteView +// */ +// public NoteAppBuilder addNoteUseCase() { +// final NoteOutputBoundary noteOutputBoundary = new NotePresenter(noteViewModel); +// noteInteractor = new NoteInteractor(noteOutputBoundary); +// +// final NoteController controller = new NoteController(noteInteractor); +// if (noteView == null) { +// throw new RuntimeException("addNoteView must be called before addNoteUseCase"); +// } +// noteView.setNoteController(controller); +// return this; +// } +// +// /** +// * Creates the NoteView and underlying NoteViewModel. +// * @return this builder +// */ +// public NoteAppBuilder addNoteView() { +// noteViewModel = new NoteViewModel(); +// noteView = new NoteView(noteViewModel); +// return this; +// } +// +// /** +// * Builds the application. +// * @return the JFrame for the application +// */ +// public JFrame build() { +// final JFrame frame = new JFrame(); +// frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); +// frame.setTitle("Note Application"); +// frame.setSize(WIDTH, HEIGHT); +// +// frame.add(NoteView); +// +// // refresh so that the note will be visible when we start the program +//// noteInteractor.executeRefresh(); +// +// return frame; +// +// } +//} diff --git a/src/main/java/data_access/DBNoteDataAccessObject.java b/src/main/java/data_access/DBNoteDataAccessObject.java deleted file mode 100644 index 0ea8779f8..000000000 --- a/src/main/java/data_access/DBNoteDataAccessObject.java +++ /dev/null @@ -1,107 +0,0 @@ -package data_access; - -import java.io.IOException; - -import org.json.JSONException; -import org.json.JSONObject; - -import entity.User; -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; -import use_cases.note.DataAccessException; -import use_cases.note.NoteDataAccessInterface; - -/** - * The DAO for accessing notes stored in the database. - *

This class demonstrates how your group can use the password-protected user - * endpoints of the API used in lab 5 to store persistent data in your program. - *

- *

You can also refer to the lab 5 code for signing up a new user and other use cases. - *

- * See - * - * the documentation - * of the API for more details. - */ -public class DBNoteDataAccessObject implements NoteDataAccessInterface { - private static final int SUCCESS_CODE = 200; - private static final int CREDENTIAL_ERROR = 401; - private static final String CONTENT_TYPE_LABEL = "Content-Type"; - private static final String CONTENT_TYPE_JSON = "application/json"; - private static final String STATUS_CODE_LABEL = "status_code"; - private static final String USERNAME = "username"; - private static final String PASSWORD = "password"; - private static final String MESSAGE = "message"; - - @Override - public String saveNote(User user, String note) throws DataAccessException { - final OkHttpClient client = new OkHttpClient().newBuilder() - .build(); - - // POST METHOD - final MediaType mediaType = MediaType.parse(CONTENT_TYPE_JSON); - final JSONObject requestBody = new JSONObject(); - requestBody.put(USERNAME, user.getName()); - requestBody.put(PASSWORD, user.getPassword()); - final JSONObject extra = new JSONObject(); - extra.put("note", note); - requestBody.put("info", extra); - final RequestBody body = RequestBody.create(requestBody.toString(), mediaType); - final Request request = new Request.Builder() - .url("http://vm003.teach.cs.toronto.edu:20112/modifyUserInfo") - .method("PUT", body) - .addHeader(CONTENT_TYPE_LABEL, CONTENT_TYPE_JSON) - .build(); - try { - final Response response = client.newCall(request).execute(); - - final JSONObject responseBody = new JSONObject(response.body().string()); - - if (responseBody.getInt(STATUS_CODE_LABEL) == SUCCESS_CODE) { - return loadNote(user); - } - else if (responseBody.getInt(STATUS_CODE_LABEL) == CREDENTIAL_ERROR) { - throw new DataAccessException("message could not be found or password was incorrect"); - } - else { - throw new DataAccessException("database error: " + responseBody.getString(MESSAGE)); - } - } - catch (IOException | JSONException ex) { - throw new DataAccessException(ex.getMessage()); - } - } - - @Override - public String loadNote(User user) throws DataAccessException { - // Make an API call to get the user object. - final String username = user.getName(); - final OkHttpClient client = new OkHttpClient().newBuilder().build(); - final Request request = new Request.Builder() - .url(String.format("http://vm003.teach.cs.toronto.edu:20112/user?username=%s", username)) - .addHeader("Content-Type", CONTENT_TYPE_JSON) - .build(); - try { - final Response response = client.newCall(request).execute(); - - final JSONObject responseBody = new JSONObject(response.body().string()); - - if (responseBody.getInt(STATUS_CODE_LABEL) == SUCCESS_CODE) { - final JSONObject userJSONObject = responseBody.getJSONObject("user"); - final JSONObject data = userJSONObject.getJSONObject("info"); - return data.getString("note"); - } - else { - throw new DataAccessException(responseBody.getString(MESSAGE)); - } - } - catch (IOException | JSONException ex) { - throw new RuntimeException(ex); - } - } -} diff --git a/src/main/java/data_access/InMemoryNoteDataAccessObject.java b/src/main/java/data_access/InMemoryNoteDataAccessObject.java new file mode 100644 index 000000000..07b642530 --- /dev/null +++ b/src/main/java/data_access/InMemoryNoteDataAccessObject.java @@ -0,0 +1,33 @@ +package data_access; + +import java.util.Map; + +import entity.Note; +import use_cases.note.NoteDataAccessInterface; + +/** + * This class implements storage of notes within a single run of the program. + * This does not persist data between runs of the program. + */ +public class InMemoryNoteDataAccessObject implements NoteDataAccessInterface { + private final Map notes; + + public InMemoryNoteDataAccessObject(Map notes) { + this.notes = notes; + } + + @Override + public void saveNote(String title, Note note) { + this.notes.put(title, note); + } + + @Override + public String loadNote(String title) { + final Note note = this.notes.get(title); + return note.getContent(); + } + + public String[] getNotes() { + return this.notes.keySet().toArray(new String[0]); + } +} diff --git a/src/main/java/use_cases/note/DataAccessException.java b/src/main/java/use_cases/note/DataAccessException.java deleted file mode 100644 index 5b971a03f..000000000 --- a/src/main/java/use_cases/note/DataAccessException.java +++ /dev/null @@ -1,10 +0,0 @@ -package use_cases.note; - -/** - * Exception thrown when there is an error with accessing data. - */ -public class DataAccessException extends Exception { - public DataAccessException(String string) { - super(string); - } -} diff --git a/src/main/java/use_cases/note/NoteDataAccessInterface.java b/src/main/java/use_cases/note/NoteDataAccessInterface.java index 7198cc3ea..aeae21439 100644 --- a/src/main/java/use_cases/note/NoteDataAccessInterface.java +++ b/src/main/java/use_cases/note/NoteDataAccessInterface.java @@ -1,6 +1,6 @@ package use_cases.note; -import entity.User; +import entity.Note; /** * Interface for the NoteDAO. It consists of methods for @@ -9,22 +9,18 @@ public interface NoteDataAccessInterface { /** - * Saves a note for a given user. This will replace any existing note. + * Saves a note. *

The password of the user must match that of the user saved in the system.

- * @param user the user information associated with the note + * @param title the title associated with the note * @param note the note to be saved - * @return the contents of the note - * @throws DataAccessException if the user's note can not be saved for any reason */ - String saveNote(User user, String note) throws DataAccessException; + void saveNote(String title, Note note); /** - * Returns the note associated with the user. The password - * is not checked, so anyone can read the information. - * @param user the user information associated with the note + * Returns the note associated with the title. + * @param title the title associated with the note * @return the contents of the note - * @throws DataAccessException if the user's note can not be loaded for any reason */ - String loadNote(User user) throws DataAccessException; + String loadNote(String title); } diff --git a/src/main/java/use_cases/note/NoteInputData.java b/src/main/java/use_cases/note/NoteInputData.java new file mode 100644 index 000000000..9cb02005c --- /dev/null +++ b/src/main/java/use_cases/note/NoteInputData.java @@ -0,0 +1,22 @@ +package use_cases.note; + +/** + * The input data for the Notes Use Case. + */ +public class NoteInputData { + private final String title; + private final String content; + + public NoteInputData(String title, String content) { + this.title = title; + this.content = content; + } + + public String getTitle() { + return title; + } + + public String getNo() { + return content; + } +} diff --git a/src/main/java/use_cases/note/NoteInteractor.java b/src/main/java/use_cases/note/NoteInteractor.java index 10e09b80b..c28328dc5 100644 --- a/src/main/java/use_cases/note/NoteInteractor.java +++ b/src/main/java/use_cases/note/NoteInteractor.java @@ -1,5 +1,9 @@ package use_cases.note; +import data_access.InMemoryNoteDataAccessObject; +import entity.Note; +import org.checkerframework.checker.units.qual.N; + /** * The "Use Case Interactor" for our two note-related use cases of refreshing * the contents of the note and saving the contents of the note. Since they @@ -7,27 +11,31 @@ */ public class NoteInteractor implements NoteInputBoundary { - private final NoteOutputBoundary noteOutputBoundary; + private final NoteOutputBoundary notePresenter; + private final InMemoryNoteDataAccessObject inMemoryNoteDataAccessObject; - public NoteInteractor(NoteOutputBoundary noteOutputBoundary) { - this.noteOutputBoundary = noteOutputBoundary; + public NoteInteractor(NoteOutputBoundary noteOutputBoundary, InMemoryNoteDataAccessObject inMemoryNoteDataAccessObject) { + this.notePresenter = noteOutputBoundary; + this.inMemoryNoteDataAccessObject = inMemoryNoteDataAccessObject; } @Override public void executeSave(String content, String title) { - this.noteOutputBoundary.prepareSuccessView(content); + final Note noteInputData = new Note(content, title); + inMemoryNoteDataAccessObject.saveNote(content, (Note) noteInputData); + this.notePresenter.prepareSuccessView(content); } @Override public void executeUpload(String content) { if (content == null || content.isEmpty()) { - this.noteOutputBoundary.prepareFailView("Upload failed"); + this.notePresenter.prepareFailView("Upload failed"); } - this.noteOutputBoundary.prepareSuccessView(content); + this.notePresenter.prepareSuccessView(content); } @Override public void executeClear(String content) { - this.noteOutputBoundary.prepareSuccessView(" "); + this.notePresenter.prepareSuccessView(" "); } } diff --git a/src/main/java/use_cases/note/NoteOutputData.java b/src/main/java/use_cases/note/NoteOutputData.java new file mode 100644 index 000000000..404c15dbf --- /dev/null +++ b/src/main/java/use_cases/note/NoteOutputData.java @@ -0,0 +1,23 @@ +package use_cases.note; + +/** + * The Output data for the Notes Use Case. + */ +public class NoteOutputData { + + private final String title; + private final boolean useCaseFailed; + + public NoteOutputData(String title, boolean useCaseFailed) { + this.title = title; + this.useCaseFailed = useCaseFailed; + } + + public String getTitle() { + return title; + } + + public boolean isUseCaseFailed() { + return useCaseFailed; + } +} diff --git a/src/main/java/view/NoteView.java b/src/main/java/view/NoteView.java deleted file mode 100644 index d3fda4c85..000000000 --- a/src/main/java/view/NoteView.java +++ /dev/null @@ -1,163 +0,0 @@ -package view; - -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.*; - -import javax.swing.*; -import javax.swing.text.MutableAttributeSet; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyledEditorKit; - -import interface_adapter.note.NoteController; -import interface_adapter.note.NoteState; -import interface_adapter.note.NoteViewModel; - -/** - * The View for when the user is viewing a note in the program. - */ -public class NoteView extends JPanel implements ActionListener, PropertyChangeListener { - - private final NoteViewModel noteViewModel; - - private final JLabel noteName = new JLabel("New Note"); - private final JTextArea noteInputField = new JTextArea(); - private final JMenuBar menuBar = new JMenuBar(); - - private final JButton addButton = new JButton("Add Title"); - private final JButton uploadButton = new JButton("Upload"); - private final JButton clearButton = new JButton("Clear"); - private final JButton deleteButton = new JButton("Delete"); - - private final JMenuItem boldMenu = new JMenuItem("Bold"); - private final JMenuItem italicMenu = new JMenuItem("Italic"); - private final JMenuItem underlineMenu = new JMenuItem("Underline"); - private final JMenu redoMenu = new JMenu("Redo"); - private final JMenu undoMenu = new JMenu("Undo"); - - private NoteController noteController; - - public NoteView(NoteViewModel noteViewModel) { - - noteName.setAlignmentX(Component.CENTER_ALIGNMENT); - this.noteViewModel = noteViewModel; - this.noteViewModel.addPropertyChangeListener(this); - - final JPanel buttons = new JPanel(); - buttons.add(addButton); - buttons.add(uploadButton); - buttons.add(clearButton); - buttons.add(deleteButton); - - addButton.addActionListener( - evt -> { - if (evt.getSource().equals(addButton)) { - final String newNoteName = JOptionPane.showInputDialog("Enter new note name"); - noteName.setText(newNoteName); - noteController.save(noteInputField.getText(), noteName.getText()); - - } - } - ); - - uploadButton.addActionListener( - evt -> { - if (evt.getSource().equals(uploadButton)) { - final JFileChooser fileChooser = new JFileChooser(); - fileChooser.setDialogTitle("Upload"); - final int returnVal = fileChooser.showOpenDialog(this); - final File selectedFile = fileChooser.getSelectedFile(); - if (returnVal == JFileChooser.APPROVE_OPTION) { - try { - final BufferedReader reader = new BufferedReader(new FileReader(selectedFile)); - noteInputField.setText(""); - String line; - while ((line = reader.readLine()) != null) { - noteInputField.append(line); - noteInputField.append("\n"); - } - noteController.updateContent(noteInputField.getText()); - } - catch (IOException exception) { - JOptionPane.showMessageDialog(this, exception.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); - } - } - - } - } - ); - - clearButton.addActionListener( - evt -> { - if (evt.getSource().equals(clearButton)) { - noteController.clear(noteInputField.getText()); - } - } - ); - - deleteButton.addActionListener( - evt -> { - if (evt.getSource().equals(deleteButton)) { - noteController.clear(noteInputField.getText()); - noteName.setText("New Note"); - } - } - ); - - final JMenu editMenu = new JMenu("Edit"); - editMenu.add(boldMenu); - editMenu.add(italicMenu); - editMenu.add(underlineMenu); - menuBar.add(editMenu); - menuBar.add(redoMenu); - menuBar.add(undoMenu); - - boldMenu.addActionListener( - evt -> { - final JTextPane textPane = new JTextPane(); - noteInputField.add(textPane); - textPane.setEditorKit(new StyledEditorKit()); - final StyledEditorKit.BoldAction boldAction = new StyledEditorKit.BoldAction(); - boldAction.actionPerformed(evt); - } - ); - - this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - - this.add(noteName); - this.add(menuBar); - this.add(noteInputField); - this.add(buttons); - - } - - /** - * React to a button click that results in evt. - * @param evt the ActionEvent to react to - */ - public void actionPerformed(ActionEvent evt) { - System.out.println("Click " + evt.getActionCommand()); - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - final NoteState state = (NoteState) evt.getNewValue(); - setFields(state); - if (state.getError() != null) { - JOptionPane.showMessageDialog(this, state.getError(), - "Error", JOptionPane.ERROR_MESSAGE); - } - } - - private void setFields(NoteState state) { - noteInputField.setText(state.getNote()); - } - - public void setNoteController(NoteController controller) { - this.noteController = controller; - } -} - diff --git a/src/main/java/view/NotesView.java b/src/main/java/view/NotesView.java index 9d1b418fb..946d43ce4 100644 --- a/src/main/java/view/NotesView.java +++ b/src/main/java/view/NotesView.java @@ -1,58 +1,190 @@ package view; import interface_adapter.ai.AiController; -import use_cases.ai.AiInteractor; +import interface_adapter.note.NoteController; +import interface_adapter.note.NoteState; +import interface_adapter.note.NoteViewModel; +import org.jetbrains.annotations.NotNull; import javax.swing.*; +import javax.swing.text.StyledEditorKit; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +public class NotesView extends JPanel implements ActionListener, PropertyChangeListener { -public class NotesView extends JPanel { - private final JTextArea notesTextArea; - private final JPanel toolBarPanel; - private final JButton aiButton; - private final JButton languageButton; - private final JTextArea outputArea; private AiController aiController; - // add controllers and other view methods as necessary for language and note use cases - - public NotesView() { - this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); - final JPanel igeePanel = new JPanel(); - this.notesTextArea = new JTextArea(); - igeePanel.add(notesTextArea); - this.add(notesTextArea); - // @Igee the Notes text area is basically just a field to where youd add your stuff. - - this.toolBarPanel = new JPanel(); - toolBarPanel.setLayout(new BoxLayout(toolBarPanel, BoxLayout.Y_AXIS)); - this.aiButton = new JButton("Complete Notes With AI"); + private NoteController noteController; + private final NoteViewModel noteViewModel; + + private final JLabel noteName = new JLabel("New Note"); + private final JTextArea noteInputField = new JTextArea(); + private final JMenuBar menuBar = new JMenuBar(); + + private final JButton addButton = new JButton("Add Title"); + private final JButton uploadButton = new JButton("Upload"); + private final JButton clearButton = new JButton("Clear"); + private final JButton deleteButton = new JButton("Delete"); + + private final JMenuItem boldMenu = new JMenuItem("Bold"); + private final JMenuItem italicMenu = new JMenuItem("Italic"); + private final JMenuItem underlineMenu = new JMenuItem("Underline"); + private final JMenu redoMenu = new JMenu("Redo"); + private final JMenu undoMenu = new JMenu("Undo"); + + public NotesView(NoteViewModel noteViewModel) { + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + + this.noteViewModel = noteViewModel; + this.noteViewModel.addPropertyChangeListener(this); + + final JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); + + mainPanel.add(noteName); + noteName.setAlignmentX(Component.CENTER_ALIGNMENT); + + final JPanel buttons = new JPanel(); + buttons.add(addButton); + buttons.add(uploadButton); + buttons.add(clearButton); + buttons.add(deleteButton); + + addButton.addActionListener( + evt -> { + if (evt.getSource().equals(addButton)) { + final String newNoteName = JOptionPane.showInputDialog("Enter new note name"); + noteName.setText(newNoteName); + noteController.save(noteInputField.getText(), noteName.getText()); + + } + } + ); + + uploadButton.addActionListener( + evt -> { + if (evt.getSource().equals(uploadButton)) { + final JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle("Upload"); + final int returnVal = fileChooser.showOpenDialog(this); + final File selectedFile = fileChooser.getSelectedFile(); + if (returnVal == JFileChooser.APPROVE_OPTION) { + try { + final BufferedReader reader = new BufferedReader(new FileReader(selectedFile)); + noteInputField.setText(""); + String line; + while ((line = reader.readLine()) != null) { + noteInputField.append(line); + noteInputField.append("\n"); + } + noteController.updateContent(noteInputField.getText()); + } + catch (IOException exception) { + JOptionPane.showMessageDialog(this, exception.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); + } + } + + } + } + ); + + clearButton.addActionListener( + evt -> { + if (evt.getSource().equals(clearButton)) { + noteController.clear(noteInputField.getText()); + } + } + ); + + deleteButton.addActionListener( + evt -> { + if (evt.getSource().equals(deleteButton)) { + noteController.clear(noteInputField.getText()); + noteName.setText("New Note"); + } + } + ); + + mainPanel.add(menuBar); + mainPanel.add(noteInputField); + mainPanel.add(buttons); + this.add(mainPanel); + + final JPanel functionalityPanel = getjPanel(); + this.add(functionalityPanel); + + final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mainPanel, functionalityPanel); + this.add(splitPane); + + } + + @NotNull + private JPanel getjPanel() { + final JPanel functionalityPanel = new JPanel(); + functionalityPanel.setLayout(new BoxLayout(functionalityPanel, BoxLayout.Y_AXIS)); + + final JPanel tools = new JPanel(); + + final JButton aiButton = new JButton("Complete Notes With AI"); aiButton.addActionListener( evt -> { if (evt.getSource().equals(aiButton)) { - aiController.generateResponse(notesTextArea.getText()); + aiController.generateResponse(noteInputField.getText()); } } ); - toolBarPanel.add(aiButton); + tools.add(aiButton); - this.languageButton = new JButton("Translate to Other Language"); + final JButton languageButton = new JButton("Translate to Other Language"); languageButton.addActionListener( evt -> { if (evt.getSource().equals(languageButton)) { - // call controlller here + // call controller here } } ); - toolBarPanel.add(languageButton); + tools.add(languageButton); - this.outputArea = new JTextArea(); + final JTextArea outputArea = new JTextArea(); outputArea.setEditable(false); - outputArea.setSize(75, 50); - toolBarPanel.add(outputArea); - this.add(toolBarPanel); + functionalityPanel.add(outputArea); + functionalityPanel.add(tools); + return functionalityPanel; + } + + /** + * React to a button click that results in evt. + * @param evt the ActionEvent to react to + */ + public void actionPerformed(ActionEvent evt) { + System.out.println("Click " + evt.getActionCommand()); } + @Override + public void propertyChange(PropertyChangeEvent evt) { + final NoteState state = (NoteState) evt.getNewValue(); + setFields(state); + if (state.getError() != null) { + JOptionPane.showMessageDialog(this, state.getError(), + "Error", JOptionPane.ERROR_MESSAGE); + } + } + + private void setFields(NoteState state) { + noteInputField.setText(state.getNote()); + } + + public void setNoteController(NoteController controller) { + this.noteController = controller; + } public void setAiController(AiController aiController) { this.aiController = aiController; } diff --git a/src/test/java/app/MainNoteApplicationTest.java b/src/test/java/app/MainNoteApplicationTest.java index de97460b7..b87e059ec 100644 --- a/src/test/java/app/MainNoteApplicationTest.java +++ b/src/test/java/app/MainNoteApplicationTest.java @@ -24,13 +24,13 @@ public void setUp() { private String note = "test"; @Override - public String saveNote(User user, String note) { + public String saveNote(String title, String note) { this.note = note; return note; } @Override - public String loadNote(User user) { + public String loadNote(String title) { return note; } }; From 80bf70a70a322c3f0a67ff822716899881253a93 Mon Sep 17 00:00:00 2001 From: akhimie1 Date: Thu, 21 Nov 2024 13:44:44 -0500 Subject: [PATCH 29/56] I am working on the Interactor now. I am fixing the current implementation so that it takes Input Data from the controller at the beginning of the use case and gives Output Data to the presenter after executing the use case. --- src/main/java/use_cases/note/NoteInputData.java | 2 +- src/main/java/use_cases/note/NoteInteractor.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/use_cases/note/NoteInputData.java b/src/main/java/use_cases/note/NoteInputData.java index 9cb02005c..b4ca76c1d 100644 --- a/src/main/java/use_cases/note/NoteInputData.java +++ b/src/main/java/use_cases/note/NoteInputData.java @@ -16,7 +16,7 @@ public String getTitle() { return title; } - public String getNo() { + public String getContent() { return content; } } diff --git a/src/main/java/use_cases/note/NoteInteractor.java b/src/main/java/use_cases/note/NoteInteractor.java index c28328dc5..75d666a0f 100644 --- a/src/main/java/use_cases/note/NoteInteractor.java +++ b/src/main/java/use_cases/note/NoteInteractor.java @@ -2,7 +2,6 @@ import data_access.InMemoryNoteDataAccessObject; import entity.Note; -import org.checkerframework.checker.units.qual.N; /** * The "Use Case Interactor" for our two note-related use cases of refreshing @@ -20,10 +19,11 @@ public NoteInteractor(NoteOutputBoundary noteOutputBoundary, InMemoryNoteDataAcc } @Override - public void executeSave(String content, String title) { - final Note noteInputData = new Note(content, title); - inMemoryNoteDataAccessObject.saveNote(content, (Note) noteInputData); - this.notePresenter.prepareSuccessView(content); + public void executeSave(NoteInputData noteInputData) { + final Note note = new Note(noteInputData.getContent(), noteInputData.getTitle()); + inMemoryNoteDataAccessObject.saveNote(noteInputData.getContent(), note); + final NoteOutputData noteOutputData = new NoteOutputData(note.getTitle(), false); + this.notePresenter.prepareSuccessView(noteOutputData); } @Override From 62db340a666535126b87792ffed9141ee9e763eb Mon Sep 17 00:00:00 2001 From: stickycorner Date: Fri, 22 Nov 2024 16:37:23 -0500 Subject: [PATCH 30/56] completed ai use case updated the main application builder to take in createNotes method instead and added dependencies to pom file --- .idea/jarRepositories.xml | 10 ++ pom.xml | 89 ++++++++++++++ src/main/java/app/MainNoteApplication.java | 36 +++--- .../interface_adapter/ai/AiController.java | 6 +- .../interface_adapter/ai/AiPresenter.java | 22 +++- .../java/use_cases/ai/AiInputBoundary.java | 4 +- src/main/java/use_cases/ai/AiInteractor.java | 12 +- .../java/use_cases/ai/AiOutputBoundary.java | 4 +- src/main/java/use_cases/ai/AiRequest.java | 32 +++++ .../use_cases/calendar/CalendarRequest.java | 109 ++++++++++++++++++ src/main/java/view/NotesView.java | 10 +- 11 files changed, 301 insertions(+), 33 deletions(-) create mode 100644 src/main/java/use_cases/ai/AiRequest.java create mode 100644 src/main/java/use_cases/calendar/CalendarRequest.java diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml index 712ab9d98..57a597202 100644 --- a/.idea/jarRepositories.xml +++ b/.idea/jarRepositories.xml @@ -1,11 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index cc1ea8d07..9ebeab509 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,10 @@ google-maven-repository https://maven-central.storage-download.googleapis.com/maven2/ + + dynomakeRepository + https://maven.dynomake.space/releases + @@ -129,6 +133,11 @@ 4.13.1 test
+ + space.dynomake + libretranslate-java + 1.0.9 +
diff --git a/src/main/java/use_cases/note/NoteTranslation.java b/src/main/java/use_cases/note/NoteTranslation.java new file mode 100644 index 000000000..93c502c34 --- /dev/null +++ b/src/main/java/use_cases/note/NoteTranslation.java @@ -0,0 +1,20 @@ +package use_case.note; + +import space.dynomake.libretranslate.Language; +import space.dynomake.libretranslate.Translator; + +/** + * Class for note translation. + */ +public class NoteTranslation { + + /** + * Translates text from english to other language. + * @param textToTranslate text that is to be translated + */ + public static String translate(String textToTranslate) { + final String res = Translator.translate(Language.ENGLISH, Language.RUSSIAN, textToTranslate); + //System.out.println(res); + return res; + } +} diff --git a/src/test/java/use_cases/note/NoteTranslationTest.java b/src/test/java/use_cases/note/NoteTranslationTest.java new file mode 100644 index 000000000..532772a78 --- /dev/null +++ b/src/test/java/use_cases/note/NoteTranslationTest.java @@ -0,0 +1,15 @@ +package use_case.note; + +import junit.framework.TestCase; + +public class NoteTranslationTest extends TestCase { + + public void testTranslate() { + String text = "Hello world!"; + System.out.println(text); + //--- translate it using Liza's class: + String translated = NoteTranslation.translate(text); + System.out.println(translated); + assertEquals("Привет!", translated); + } +} \ No newline at end of file From 0ec20bafb15df3e0e7ed83147db9a01d886b0bed Mon Sep 17 00:00:00 2001 From: Elizabeth Kochel Date: Mon, 11 Nov 2024 20:06:57 -0500 Subject: [PATCH 41/56] fixed package name --- src/main/java/use_cases/note/NoteTranslation.java | 3 +-- src/test/java/use_cases/note/NoteTranslationTest.java | 5 +---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/use_cases/note/NoteTranslation.java b/src/main/java/use_cases/note/NoteTranslation.java index 93c502c34..aaa8e26be 100644 --- a/src/main/java/use_cases/note/NoteTranslation.java +++ b/src/main/java/use_cases/note/NoteTranslation.java @@ -1,4 +1,4 @@ -package use_case.note; +package use_cases.note; import space.dynomake.libretranslate.Language; import space.dynomake.libretranslate.Translator; @@ -14,7 +14,6 @@ public class NoteTranslation { */ public static String translate(String textToTranslate) { final String res = Translator.translate(Language.ENGLISH, Language.RUSSIAN, textToTranslate); - //System.out.println(res); return res; } } diff --git a/src/test/java/use_cases/note/NoteTranslationTest.java b/src/test/java/use_cases/note/NoteTranslationTest.java index 532772a78..b0974dbc0 100644 --- a/src/test/java/use_cases/note/NoteTranslationTest.java +++ b/src/test/java/use_cases/note/NoteTranslationTest.java @@ -1,4 +1,4 @@ -package use_case.note; +package use_cases.note; import junit.framework.TestCase; @@ -6,10 +6,7 @@ public class NoteTranslationTest extends TestCase { public void testTranslate() { String text = "Hello world!"; - System.out.println(text); - //--- translate it using Liza's class: String translated = NoteTranslation.translate(text); - System.out.println(translated); assertEquals("Привет!", translated); } } \ No newline at end of file From 59ee66aa2268b4c2786399fb301052df1775fff6 Mon Sep 17 00:00:00 2001 From: Elizabeth Kochel Date: Mon, 11 Nov 2024 21:17:17 -0500 Subject: [PATCH 42/56] added controller for translate button --- .../java/use_cases/note/NoteTranslation.java | 3 +++ src/main/java/view/NotesView.java | 16 +++++++++++----- .../java/use_cases/note/NoteTranslationTest.java | 5 +++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/use_cases/note/NoteTranslation.java b/src/main/java/use_cases/note/NoteTranslation.java index aaa8e26be..ca56a2932 100644 --- a/src/main/java/use_cases/note/NoteTranslation.java +++ b/src/main/java/use_cases/note/NoteTranslation.java @@ -13,6 +13,9 @@ public class NoteTranslation { * @param textToTranslate text that is to be translated */ public static String translate(String textToTranslate) { + System.out.println("debug: " + textToTranslate); + // TODO: add libretranslate error handling; + // TODO: use Google Translate API; final String res = Translator.translate(Language.ENGLISH, Language.RUSSIAN, textToTranslate); return res; } diff --git a/src/main/java/view/NotesView.java b/src/main/java/view/NotesView.java index 47c7f7466..a380f16e3 100644 --- a/src/main/java/view/NotesView.java +++ b/src/main/java/view/NotesView.java @@ -3,6 +3,7 @@ import entity.Note; import interface_adapter.ai.AiController; import use_cases.ai.AiInteractor; +import use_cases.note.NoteTranslation; import javax.swing.*; import java.awt.*; @@ -36,19 +37,24 @@ public NotesView() { ); toolBarPanel.add(aiButton); + this.outputArea = new JTextArea(); + outputArea.setEditable(false); + outputArea.setSize(75, 50); + this.languageButton = new JButton("Translate to Other Language"); languageButton.addActionListener( evt -> { if (evt.getSource().equals(languageButton)) { - // call controlller here + // call controller here + final String textInput = notesTextArea.getText(); + final String translation = NoteTranslation.translate(textInput); + outputArea.setText(translation); + System.out.println(translation); } } ); - toolBarPanel.add(languageButton); - this.outputArea = new JTextArea(); - outputArea.setEditable(false); - outputArea.setSize(75, 50); + toolBarPanel.add(languageButton); toolBarPanel.add(outputArea); this.add(toolBarPanel); diff --git a/src/test/java/use_cases/note/NoteTranslationTest.java b/src/test/java/use_cases/note/NoteTranslationTest.java index b0974dbc0..fd3c87278 100644 --- a/src/test/java/use_cases/note/NoteTranslationTest.java +++ b/src/test/java/use_cases/note/NoteTranslationTest.java @@ -5,8 +5,9 @@ public class NoteTranslationTest extends TestCase { public void testTranslate() { - String text = "Hello world!"; + // TODO: fix bug when "Bye guys" (w/o exclamation) fails to translate; + String text = "Bye guys!"; String translated = NoteTranslation.translate(text); - assertEquals("Привет!", translated); + assertEquals("Пока, ребята!", translated); } } \ No newline at end of file From ee00b435a4aff032f4df6647d8337e88b7938ca9 Mon Sep 17 00:00:00 2001 From: Elizabeth Kochel Date: Tue, 12 Nov 2024 16:22:56 -0500 Subject: [PATCH 43/56] deleted some lines that were just for debugging --- src/main/java/use_cases/note/NoteTranslation.java | 1 - src/main/java/view/NotesView.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/use_cases/note/NoteTranslation.java b/src/main/java/use_cases/note/NoteTranslation.java index ca56a2932..ab2be92f8 100644 --- a/src/main/java/use_cases/note/NoteTranslation.java +++ b/src/main/java/use_cases/note/NoteTranslation.java @@ -13,7 +13,6 @@ public class NoteTranslation { * @param textToTranslate text that is to be translated */ public static String translate(String textToTranslate) { - System.out.println("debug: " + textToTranslate); // TODO: add libretranslate error handling; // TODO: use Google Translate API; final String res = Translator.translate(Language.ENGLISH, Language.RUSSIAN, textToTranslate); diff --git a/src/main/java/view/NotesView.java b/src/main/java/view/NotesView.java index a380f16e3..4563e4aee 100644 --- a/src/main/java/view/NotesView.java +++ b/src/main/java/view/NotesView.java @@ -49,7 +49,6 @@ public NotesView() { final String textInput = notesTextArea.getText(); final String translation = NoteTranslation.translate(textInput); outputArea.setText(translation); - System.out.println(translation); } } ); From 9b47f52cae5566f5ef918404999120117ef4860f Mon Sep 17 00:00:00 2001 From: Elizabeth Kochel Date: Sun, 24 Nov 2024 20:40:46 -0500 Subject: [PATCH 44/56] note translation implemented --- .../java/use_cases/note/NoteInputData.java | 22 +++++ .../java/use_cases/note/NoteOutputData.java | 16 ++++ .../java/use_cases/note/NoteTranslation.java | 38 +++++++-- src/main/java/view/NotesView.java | 28 +++++-- .../use_cases/note/NoteTranslationTest.java | 82 +++++++++++++++++-- 5 files changed, 169 insertions(+), 17 deletions(-) create mode 100644 src/main/java/use_cases/note/NoteInputData.java create mode 100644 src/main/java/use_cases/note/NoteOutputData.java diff --git a/src/main/java/use_cases/note/NoteInputData.java b/src/main/java/use_cases/note/NoteInputData.java new file mode 100644 index 000000000..c8e00bbe3 --- /dev/null +++ b/src/main/java/use_cases/note/NoteInputData.java @@ -0,0 +1,22 @@ +package use_cases.note; + +/** + * The Note Input Data contains the text to translate and the selected language to translate to. + */ +public class NoteInputData { + private final String textToTranslate; + private final String selectedLanguage; + + public NoteInputData(String textToTranslate, String selectedLanguage) { + this.textToTranslate = textToTranslate; + this.selectedLanguage = selectedLanguage; + } + + public String getTextToTranslate() { + return textToTranslate; + } + + public String getSelectedLanguage() { + return selectedLanguage; + } +} diff --git a/src/main/java/use_cases/note/NoteOutputData.java b/src/main/java/use_cases/note/NoteOutputData.java new file mode 100644 index 000000000..62e04afc4 --- /dev/null +++ b/src/main/java/use_cases/note/NoteOutputData.java @@ -0,0 +1,16 @@ +package use_cases.note; + +/** + * The Note Output Data contains the translated text. + */ +public class NoteOutputData { + private final String translatedText; + + public NoteOutputData(String translatedText) { + this.translatedText = translatedText; + } + + public String getTranslatedText() { + return translatedText; + } +} diff --git a/src/main/java/use_cases/note/NoteTranslation.java b/src/main/java/use_cases/note/NoteTranslation.java index ab2be92f8..8b1e08a91 100644 --- a/src/main/java/use_cases/note/NoteTranslation.java +++ b/src/main/java/use_cases/note/NoteTranslation.java @@ -10,12 +10,38 @@ public class NoteTranslation { /** * Translates text from english to other language. - * @param textToTranslate text that is to be translated + * + * @param inputData the input data containing the text to translate and the selected language + * @return NoteOutputData containing the translation */ - public static String translate(String textToTranslate) { - // TODO: add libretranslate error handling; - // TODO: use Google Translate API; - final String res = Translator.translate(Language.ENGLISH, Language.RUSSIAN, textToTranslate); - return res; + public static NoteOutputData translate(NoteInputData inputData) { + final int characterLimit = 2000; + final String textToTranslate = inputData.getTextToTranslate(); + final String selectedLanguage = inputData.getSelectedLanguage(); + + // checking if length of text exceeds char limit + if (textToTranslate.length() > characterLimit) { + return new NoteOutputData("Exceeded character limit"); + } + + final String translation; + switch (selectedLanguage) { + case "Russian": + translation = Translator.translate(Language.ENGLISH, Language.RUSSIAN, textToTranslate); + break; + case "French": + translation = Translator.translate(Language.ENGLISH, Language.FRENCH, textToTranslate); + break; + case "Spanish": + translation = Translator.translate(Language.ENGLISH, Language.SPANISH, textToTranslate); + break; + case "Arabic": + translation = Translator.translate(Language.ENGLISH, Language.ARABIC, textToTranslate); + break; + default: + translation = textToTranslate; + } + + return new NoteOutputData(translation); } } diff --git a/src/main/java/view/NotesView.java b/src/main/java/view/NotesView.java index 4563e4aee..18e2d6afa 100644 --- a/src/main/java/view/NotesView.java +++ b/src/main/java/view/NotesView.java @@ -3,6 +3,8 @@ import entity.Note; import interface_adapter.ai.AiController; import use_cases.ai.AiInteractor; +import use_cases.note.NoteInputData; +import use_cases.note.NoteOutputData; import use_cases.note.NoteTranslation; import javax.swing.*; @@ -23,7 +25,7 @@ public NotesView() { this.notesTextArea = new JTextArea(); igeePanel.add(notesTextArea); this.add(notesTextArea); - // @Igee the Notes text area is basically just a field to where youd add your stuff. + // @Igee the Notes text area is basically just a field to where you'd add your stuff. this.toolBarPanel = new JPanel(); toolBarPanel.setLayout(new BoxLayout(toolBarPanel, BoxLayout.Y_AXIS)); @@ -41,14 +43,28 @@ public NotesView() { outputArea.setEditable(false); outputArea.setSize(75, 50); - this.languageButton = new JButton("Translate to Other Language"); + // Dropdown menu + final String[] languages = {"Russian", "French", "Spanish", "Arabic"}; + final JComboBox languageDropdown = new JComboBox<>(languages); + languageDropdown.setVisible(false); + toolBarPanel.add(languageDropdown); + + // Language Translation Button + this.languageButton = new JButton("Translate"); languageButton.addActionListener( evt -> { if (evt.getSource().equals(languageButton)) { - // call controller here - final String textInput = notesTextArea.getText(); - final String translation = NoteTranslation.translate(textInput); - outputArea.setText(translation); + if (!languageDropdown.isVisible()) { + languageDropdown.setVisible(true); + } + else { + final String selectedLanguage = (String) languageDropdown.getSelectedItem(); + final String textInput = notesTextArea.getText(); + final NoteInputData inputData = new NoteInputData(textInput, selectedLanguage); + final NoteOutputData outputData = NoteTranslation.translate(inputData); + outputArea.setText(outputData.getTranslatedText()); + languageDropdown.setVisible(false); + } } } ); diff --git a/src/test/java/use_cases/note/NoteTranslationTest.java b/src/test/java/use_cases/note/NoteTranslationTest.java index fd3c87278..ad65a8e0a 100644 --- a/src/test/java/use_cases/note/NoteTranslationTest.java +++ b/src/test/java/use_cases/note/NoteTranslationTest.java @@ -4,10 +4,82 @@ public class NoteTranslationTest extends TestCase { - public void testTranslate() { - // TODO: fix bug when "Bye guys" (w/o exclamation) fails to translate; - String text = "Bye guys!"; - String translated = NoteTranslation.translate(text); - assertEquals("Пока, ребята!", translated); + public void testTranslate2Russian() { + String text = "Hello world"; + String selectedLanguage = "Russian"; + NoteInputData inputData = new NoteInputData(text, selectedLanguage); + + NoteOutputData output = NoteTranslation.translate(inputData); + String expectedOutput = "Привет мир"; + + assertEquals(expectedOutput, output.getTranslatedText()); + } + + public void testTranslate2Spanish() { + String text = "Welcome everyone"; + String selectedLanguage = "Spanish"; + NoteInputData inputData = new NoteInputData(text, selectedLanguage); + + NoteOutputData output = NoteTranslation.translate(inputData); + String expectedOutput = "Bienvenido a todos"; + + assertEquals(expectedOutput, output.getTranslatedText()); + } + + public void testTranslate2French() { + String text = "Hello everyone"; + String selectedLanguage = "French"; + NoteInputData inputData = new NoteInputData(text, selectedLanguage); + + NoteOutputData output = NoteTranslation.translate(inputData); + String expectedOutput = "Bonjour à tous"; + + assertEquals(expectedOutput, output.getTranslatedText()); + } + + public void testTranslate2Arabic() { + String text = "Please and thank you"; + String selectedLanguage = "Arabic"; + NoteInputData inputData = new NoteInputData(text, selectedLanguage); + + NoteOutputData output = NoteTranslation.translate(inputData); + String expectedOutput = "من فضلك وشكرا لكم"; + + assertEquals(expectedOutput, output.getTranslatedText()); + } + + public void testLanguageNotInDropdown() { + // If selected language is not part of the dropdown list, should output original text + String text = "Hello everyone"; + String selectedLanguage = "Italian"; + NoteInputData inputData = new NoteInputData(text, selectedLanguage); + + NoteOutputData output = NoteTranslation.translate(inputData); + String expectedOutput = "Hello everyone"; + + assertEquals(expectedOutput, output.getTranslatedText()); + } + + public void testTranslateEmptyString() { + // Empty string should return empty string + String text = " "; + String selectedLanguage = "Russian"; + NoteInputData inputData = new NoteInputData(text, selectedLanguage); + + NoteOutputData output = NoteTranslation.translate(inputData); + String expectedOutput = ""; + + assertEquals(expectedOutput, output.getTranslatedText()); + } + + public void testExceededCharLimit() { + String text = "hello ".repeat(400); + String selectedLanguage = "Spanish"; + NoteInputData inputData = new NoteInputData(text, selectedLanguage); + + NoteOutputData output = NoteTranslation.translate(inputData); + String expectedOutput = "Exceeded character limit"; + + assertEquals(expectedOutput, output.getTranslatedText()); } } \ No newline at end of file From 45f5d19bc0af51cbf6b543c41b6674b1a2bba8f7 Mon Sep 17 00:00:00 2001 From: Elizabeth Kochel Date: Wed, 27 Nov 2024 21:28:53 -0500 Subject: [PATCH 45/56] added input boundary, output boundary, controller, presenter, interactor for translation use case --- pom.xml | 2 +- src/main/java/app/MainNoteApplication.java | 10 +++++++ .../translation/TranslationController.java | 25 +++++++++++++++++ .../translation/TranslationPresenter.java | 25 +++++++++++++++++ .../use_cases/calendar/CalendarRequest.java | 10 ++++--- .../java/use_cases/note/NoteTranslation.java | 6 ++-- .../note/TranslationInputBoundary.java | 13 +++++++++ ...putData.java => TranslationInputData.java} | 4 +-- .../use_cases/note/TranslationInteractor.java | 23 +++++++++++++++ .../note/TranslationOutputBoundary.java | 12 ++++++++ ...utData.java => TranslationOutputData.java} | 4 +-- src/main/java/view/NotesView.java | 26 +++++++++++------ .../use_cases/note/NoteTranslationTest.java | 28 +++++++++---------- 13 files changed, 154 insertions(+), 34 deletions(-) create mode 100644 src/main/java/interface_adapter/translation/TranslationController.java create mode 100644 src/main/java/interface_adapter/translation/TranslationPresenter.java create mode 100644 src/main/java/use_cases/note/TranslationInputBoundary.java rename src/main/java/use_cases/note/{NoteInputData.java => TranslationInputData.java} (80%) create mode 100644 src/main/java/use_cases/note/TranslationInteractor.java create mode 100644 src/main/java/use_cases/note/TranslationOutputBoundary.java rename src/main/java/use_cases/note/{NoteOutputData.java => TranslationOutputData.java} (73%) diff --git a/pom.xml b/pom.xml index 9ebeab509..5a4acf3f8 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ - com.cohere + com.cohere cohere-java 1.4.1 diff --git a/src/main/java/app/MainNoteApplication.java b/src/main/java/app/MainNoteApplication.java index 0c405c607..fa3049c2c 100644 --- a/src/main/java/app/MainNoteApplication.java +++ b/src/main/java/app/MainNoteApplication.java @@ -7,6 +7,8 @@ import interface_adapter.ai.AiPresenter; import interface_adapter.calendar.CalendarController; import interface_adapter.calendar.CalendarPresenter; +import interface_adapter.translation.TranslationController; +import interface_adapter.translation.TranslationPresenter; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -23,6 +25,8 @@ import use_cases.calendar.CalendarInteractor; import use_cases.calendar.CalendarOutputBoundary; import use_cases.calendar.CalendarRequest; +import use_cases.note.TranslationInputBoundary; +import use_cases.note.TranslationInteractor; import view.CalendarView; import view.ChecklistView; import view.DashboardView; @@ -109,6 +113,12 @@ private static JPanel createNotes() { final AiInputBoundary aiInteractor = new AiInteractor(aiPresenter, aiRequest); final AiController aiController = new AiController(aiInteractor); notesView.setAiController(aiController); + + final TranslationPresenter translationPresenter = new TranslationPresenter(notesView); + final TranslationInputBoundary translationInteractor = new TranslationInteractor(translationPresenter); + final TranslationController translationController = new TranslationController(translationInteractor); + notesView.setTranslationController(translationController); + return notesView; } diff --git a/src/main/java/interface_adapter/translation/TranslationController.java b/src/main/java/interface_adapter/translation/TranslationController.java new file mode 100644 index 000000000..63b3e4b61 --- /dev/null +++ b/src/main/java/interface_adapter/translation/TranslationController.java @@ -0,0 +1,25 @@ +package interface_adapter.translation; + +import use_cases.note.TranslationInputData; +import use_cases.note.TranslationInputBoundary; + +/** + * Controller for translation use case. + */ +public class TranslationController { + private final TranslationInputBoundary translationInteractor; + + public TranslationController(TranslationInputBoundary translationInteractor) { + this.translationInteractor = translationInteractor; + } + + /** + * Handles the user clicking the translate button. + * @param textToTranslate text to be translated + * @param selectedLanguage language to translate to + */ + public void translateNote(String textToTranslate, String selectedLanguage) { + final TranslationInputData inputData = new TranslationInputData(textToTranslate, selectedLanguage); + translationInteractor.translateNote(inputData); + } +} diff --git a/src/main/java/interface_adapter/translation/TranslationPresenter.java b/src/main/java/interface_adapter/translation/TranslationPresenter.java new file mode 100644 index 000000000..b18171e24 --- /dev/null +++ b/src/main/java/interface_adapter/translation/TranslationPresenter.java @@ -0,0 +1,25 @@ +package interface_adapter.translation; + +import use_cases.note.TranslationOutputData; +import use_cases.note.TranslationOutputBoundary; +import view.NotesView; + +/** + * Presenter for translation use case. + */ +public class TranslationPresenter implements TranslationOutputBoundary { + private final NotesView notesView; + + public TranslationPresenter(NotesView notesView) { + this.notesView = notesView; + } + + /** + * updates translation. + * @param outputData translated content + */ + public void updateTranslation(TranslationOutputData outputData) { + final String translatedText = outputData.getTranslatedText(); + notesView.updateTranslation(translatedText); + } +} diff --git a/src/main/java/use_cases/calendar/CalendarRequest.java b/src/main/java/use_cases/calendar/CalendarRequest.java index 57fbd201e..3b72aec44 100644 --- a/src/main/java/use_cases/calendar/CalendarRequest.java +++ b/src/main/java/use_cases/calendar/CalendarRequest.java @@ -45,9 +45,10 @@ public class CalendarRequest { /** * Creates credentials. + * * @return Calendar. * @throws GeneralSecurityException exception. - * @throws IOException exception. + * @throws IOException exception. */ public static Calendar getCalendarService() throws GeneralSecurityException, IOException { // Load the service account key JSON file @@ -69,9 +70,10 @@ public static Calendar getCalendarService() throws GeneralSecurityException, IOE /** * Retrieves calendar events, first 10 of them. + * * @return List of events. * @throws GeneralSecurityException exception. - * @throws IOException exception. + * @throws IOException exception. */ public List getCalendarEvents() throws GeneralSecurityException, IOException { final Calendar service = getCalendarService(); @@ -83,8 +85,7 @@ public List getCalendarEvents() throws GeneralSecurityException, IOExcept final List items = events.getItems(); if (items.isEmpty()) { System.out.println("No upcoming events found."); - } - else { + } else { System.out.println("Upcoming events:"); for (Event event : items) { DateTime start = event.getStart().getDateTime(); @@ -96,3 +97,4 @@ public List getCalendarEvents() throws GeneralSecurityException, IOExcept } return items; } +} diff --git a/src/main/java/use_cases/note/NoteTranslation.java b/src/main/java/use_cases/note/NoteTranslation.java index 8b1e08a91..bebe1bda2 100644 --- a/src/main/java/use_cases/note/NoteTranslation.java +++ b/src/main/java/use_cases/note/NoteTranslation.java @@ -14,14 +14,14 @@ public class NoteTranslation { * @param inputData the input data containing the text to translate and the selected language * @return NoteOutputData containing the translation */ - public static NoteOutputData translate(NoteInputData inputData) { + public static TranslationOutputData translate(TranslationInputData inputData) { final int characterLimit = 2000; final String textToTranslate = inputData.getTextToTranslate(); final String selectedLanguage = inputData.getSelectedLanguage(); // checking if length of text exceeds char limit if (textToTranslate.length() > characterLimit) { - return new NoteOutputData("Exceeded character limit"); + return new TranslationOutputData("Exceeded character limit"); } final String translation; @@ -42,6 +42,6 @@ public static NoteOutputData translate(NoteInputData inputData) { translation = textToTranslate; } - return new NoteOutputData(translation); + return new TranslationOutputData(translation); } } diff --git a/src/main/java/use_cases/note/TranslationInputBoundary.java b/src/main/java/use_cases/note/TranslationInputBoundary.java new file mode 100644 index 000000000..a4b23e010 --- /dev/null +++ b/src/main/java/use_cases/note/TranslationInputBoundary.java @@ -0,0 +1,13 @@ +package use_cases.note; + +/** + * InputBoundary for translation use case. + */ +public interface TranslationInputBoundary { + /** + * Translates note. + * + * @param inputData contains text to be translated and selected language + */ + void translateNote(TranslationInputData inputData); +} diff --git a/src/main/java/use_cases/note/NoteInputData.java b/src/main/java/use_cases/note/TranslationInputData.java similarity index 80% rename from src/main/java/use_cases/note/NoteInputData.java rename to src/main/java/use_cases/note/TranslationInputData.java index c8e00bbe3..f1a8f1da3 100644 --- a/src/main/java/use_cases/note/NoteInputData.java +++ b/src/main/java/use_cases/note/TranslationInputData.java @@ -3,11 +3,11 @@ /** * The Note Input Data contains the text to translate and the selected language to translate to. */ -public class NoteInputData { +public class TranslationInputData { private final String textToTranslate; private final String selectedLanguage; - public NoteInputData(String textToTranslate, String selectedLanguage) { + public TranslationInputData(String textToTranslate, String selectedLanguage) { this.textToTranslate = textToTranslate; this.selectedLanguage = selectedLanguage; } diff --git a/src/main/java/use_cases/note/TranslationInteractor.java b/src/main/java/use_cases/note/TranslationInteractor.java new file mode 100644 index 000000000..ca7e18471 --- /dev/null +++ b/src/main/java/use_cases/note/TranslationInteractor.java @@ -0,0 +1,23 @@ +package use_cases.note; + +/** + * Interactor for translation use case. + */ +public class TranslationInteractor implements TranslationInputBoundary { + private final TranslationOutputBoundary outputBoundary; + + public TranslationInteractor(TranslationOutputBoundary outputBoundary) { + + this.outputBoundary = outputBoundary; + } + + /** + * Translates input data. + * + * @param inputData contains text to be translated and selected language + */ + public void translateNote(TranslationInputData inputData) { + final TranslationOutputData outputData = NoteTranslation.translate(inputData); + outputBoundary.updateTranslation(outputData); + } +} diff --git a/src/main/java/use_cases/note/TranslationOutputBoundary.java b/src/main/java/use_cases/note/TranslationOutputBoundary.java new file mode 100644 index 000000000..f67f66146 --- /dev/null +++ b/src/main/java/use_cases/note/TranslationOutputBoundary.java @@ -0,0 +1,12 @@ +package use_cases.note; + +/** + * OutputBoundary for translation use case. + */ +public interface TranslationOutputBoundary { + /** + * presents the translated text. + * @param outputData translated content + */ + void updateTranslation(TranslationOutputData outputData); +} diff --git a/src/main/java/use_cases/note/NoteOutputData.java b/src/main/java/use_cases/note/TranslationOutputData.java similarity index 73% rename from src/main/java/use_cases/note/NoteOutputData.java rename to src/main/java/use_cases/note/TranslationOutputData.java index 62e04afc4..a8efa5735 100644 --- a/src/main/java/use_cases/note/NoteOutputData.java +++ b/src/main/java/use_cases/note/TranslationOutputData.java @@ -3,10 +3,10 @@ /** * The Note Output Data contains the translated text. */ -public class NoteOutputData { +public class TranslationOutputData { private final String translatedText; - public NoteOutputData(String translatedText) { + public TranslationOutputData(String translatedText) { this.translatedText = translatedText; } diff --git a/src/main/java/view/NotesView.java b/src/main/java/view/NotesView.java index 18e2d6afa..5ec65d2ac 100644 --- a/src/main/java/view/NotesView.java +++ b/src/main/java/view/NotesView.java @@ -2,14 +2,13 @@ import entity.Note; import interface_adapter.ai.AiController; -import use_cases.ai.AiInteractor; -import use_cases.note.NoteInputData; -import use_cases.note.NoteOutputData; -import use_cases.note.NoteTranslation; +import interface_adapter.translation.TranslationController; import javax.swing.*; -import java.awt.*; +/** + * View for the Notes. + */ public class NotesView extends JPanel { private final JTextArea notesTextArea; private final JPanel toolBarPanel; @@ -17,6 +16,7 @@ public class NotesView extends JPanel { private final JButton languageButton; private final JTextArea outputArea; private AiController aiController; + private TranslationController translationController; // add controllers and other view methods as necessary for language and note use cases public NotesView() { @@ -60,9 +60,7 @@ public NotesView() { else { final String selectedLanguage = (String) languageDropdown.getSelectedItem(); final String textInput = notesTextArea.getText(); - final NoteInputData inputData = new NoteInputData(textInput, selectedLanguage); - final NoteOutputData outputData = NoteTranslation.translate(inputData); - outputArea.setText(outputData.getTranslatedText()); + translationController.translateNote(textInput, selectedLanguage); languageDropdown.setVisible(false); } } @@ -75,6 +73,18 @@ public NotesView() { this.add(toolBarPanel); } + /** + * updates the translation. + * @param translatedText text that has been translated + */ + public void updateTranslation(String translatedText) { + outputArea.setText(translatedText); + } + + public void setTranslationController(TranslationController translationController) { + this.translationController = translationController; + } + public void setAiController(AiController aiController) { this.aiController = aiController; } diff --git a/src/test/java/use_cases/note/NoteTranslationTest.java b/src/test/java/use_cases/note/NoteTranslationTest.java index ad65a8e0a..b6e66bcad 100644 --- a/src/test/java/use_cases/note/NoteTranslationTest.java +++ b/src/test/java/use_cases/note/NoteTranslationTest.java @@ -7,9 +7,9 @@ public class NoteTranslationTest extends TestCase { public void testTranslate2Russian() { String text = "Hello world"; String selectedLanguage = "Russian"; - NoteInputData inputData = new NoteInputData(text, selectedLanguage); + TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - NoteOutputData output = NoteTranslation.translate(inputData); + TranslationOutputData output = NoteTranslation.translate(inputData); String expectedOutput = "Привет мир"; assertEquals(expectedOutput, output.getTranslatedText()); @@ -18,9 +18,9 @@ public void testTranslate2Russian() { public void testTranslate2Spanish() { String text = "Welcome everyone"; String selectedLanguage = "Spanish"; - NoteInputData inputData = new NoteInputData(text, selectedLanguage); + TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - NoteOutputData output = NoteTranslation.translate(inputData); + TranslationOutputData output = NoteTranslation.translate(inputData); String expectedOutput = "Bienvenido a todos"; assertEquals(expectedOutput, output.getTranslatedText()); @@ -29,9 +29,9 @@ public void testTranslate2Spanish() { public void testTranslate2French() { String text = "Hello everyone"; String selectedLanguage = "French"; - NoteInputData inputData = new NoteInputData(text, selectedLanguage); + TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - NoteOutputData output = NoteTranslation.translate(inputData); + TranslationOutputData output = NoteTranslation.translate(inputData); String expectedOutput = "Bonjour à tous"; assertEquals(expectedOutput, output.getTranslatedText()); @@ -40,9 +40,9 @@ public void testTranslate2French() { public void testTranslate2Arabic() { String text = "Please and thank you"; String selectedLanguage = "Arabic"; - NoteInputData inputData = new NoteInputData(text, selectedLanguage); + TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - NoteOutputData output = NoteTranslation.translate(inputData); + TranslationOutputData output = NoteTranslation.translate(inputData); String expectedOutput = "من فضلك وشكرا لكم"; assertEquals(expectedOutput, output.getTranslatedText()); @@ -52,9 +52,9 @@ public void testLanguageNotInDropdown() { // If selected language is not part of the dropdown list, should output original text String text = "Hello everyone"; String selectedLanguage = "Italian"; - NoteInputData inputData = new NoteInputData(text, selectedLanguage); + TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - NoteOutputData output = NoteTranslation.translate(inputData); + TranslationOutputData output = NoteTranslation.translate(inputData); String expectedOutput = "Hello everyone"; assertEquals(expectedOutput, output.getTranslatedText()); @@ -64,9 +64,9 @@ public void testTranslateEmptyString() { // Empty string should return empty string String text = " "; String selectedLanguage = "Russian"; - NoteInputData inputData = new NoteInputData(text, selectedLanguage); + TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - NoteOutputData output = NoteTranslation.translate(inputData); + TranslationOutputData output = NoteTranslation.translate(inputData); String expectedOutput = ""; assertEquals(expectedOutput, output.getTranslatedText()); @@ -75,9 +75,9 @@ public void testTranslateEmptyString() { public void testExceededCharLimit() { String text = "hello ".repeat(400); String selectedLanguage = "Spanish"; - NoteInputData inputData = new NoteInputData(text, selectedLanguage); + TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - NoteOutputData output = NoteTranslation.translate(inputData); + TranslationOutputData output = NoteTranslation.translate(inputData); String expectedOutput = "Exceeded character limit"; assertEquals(expectedOutput, output.getTranslatedText()); From bb86c1a6858589855f71b25727c79ead8c5ddc1e Mon Sep 17 00:00:00 2001 From: Elizabeth Kochel Date: Thu, 28 Nov 2024 22:22:02 -0500 Subject: [PATCH 46/56] changed TranslationNoteTest to TranslationInteractorTest and fixed some changes --- src/main/java/app/MainNoteApplication.java | 3 +- ...anslation.java => TranslationFactory.java} | 2 +- .../use_cases/note/TranslationInteractor.java | 2 +- .../use_cases/note/NoteTranslationTest.java | 85 -------------- .../note/TranslationInteractorTest.java | 109 ++++++++++++++++++ 5 files changed, 113 insertions(+), 88 deletions(-) rename src/main/java/use_cases/note/{NoteTranslation.java => TranslationFactory.java} (98%) delete mode 100644 src/test/java/use_cases/note/NoteTranslationTest.java create mode 100644 src/test/java/use_cases/note/TranslationInteractorTest.java diff --git a/src/main/java/app/MainNoteApplication.java b/src/main/java/app/MainNoteApplication.java index fa3049c2c..dd41bb21b 100644 --- a/src/main/java/app/MainNoteApplication.java +++ b/src/main/java/app/MainNoteApplication.java @@ -27,6 +27,7 @@ import use_cases.calendar.CalendarRequest; import use_cases.note.TranslationInputBoundary; import use_cases.note.TranslationInteractor; +import use_cases.note.TranslationOutputBoundary; import view.CalendarView; import view.ChecklistView; import view.DashboardView; @@ -114,7 +115,7 @@ private static JPanel createNotes() { final AiController aiController = new AiController(aiInteractor); notesView.setAiController(aiController); - final TranslationPresenter translationPresenter = new TranslationPresenter(notesView); + final TranslationOutputBoundary translationPresenter = new TranslationPresenter(notesView); final TranslationInputBoundary translationInteractor = new TranslationInteractor(translationPresenter); final TranslationController translationController = new TranslationController(translationInteractor); notesView.setTranslationController(translationController); diff --git a/src/main/java/use_cases/note/NoteTranslation.java b/src/main/java/use_cases/note/TranslationFactory.java similarity index 98% rename from src/main/java/use_cases/note/NoteTranslation.java rename to src/main/java/use_cases/note/TranslationFactory.java index bebe1bda2..0953c8461 100644 --- a/src/main/java/use_cases/note/NoteTranslation.java +++ b/src/main/java/use_cases/note/TranslationFactory.java @@ -6,7 +6,7 @@ /** * Class for note translation. */ -public class NoteTranslation { +public class TranslationFactory { /** * Translates text from english to other language. diff --git a/src/main/java/use_cases/note/TranslationInteractor.java b/src/main/java/use_cases/note/TranslationInteractor.java index ca7e18471..ad6533794 100644 --- a/src/main/java/use_cases/note/TranslationInteractor.java +++ b/src/main/java/use_cases/note/TranslationInteractor.java @@ -17,7 +17,7 @@ public TranslationInteractor(TranslationOutputBoundary outputBoundary) { * @param inputData contains text to be translated and selected language */ public void translateNote(TranslationInputData inputData) { - final TranslationOutputData outputData = NoteTranslation.translate(inputData); + final TranslationOutputData outputData = TranslationFactory.translate(inputData); outputBoundary.updateTranslation(outputData); } } diff --git a/src/test/java/use_cases/note/NoteTranslationTest.java b/src/test/java/use_cases/note/NoteTranslationTest.java deleted file mode 100644 index b6e66bcad..000000000 --- a/src/test/java/use_cases/note/NoteTranslationTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package use_cases.note; - -import junit.framework.TestCase; - -public class NoteTranslationTest extends TestCase { - - public void testTranslate2Russian() { - String text = "Hello world"; - String selectedLanguage = "Russian"; - TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - - TranslationOutputData output = NoteTranslation.translate(inputData); - String expectedOutput = "Привет мир"; - - assertEquals(expectedOutput, output.getTranslatedText()); - } - - public void testTranslate2Spanish() { - String text = "Welcome everyone"; - String selectedLanguage = "Spanish"; - TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - - TranslationOutputData output = NoteTranslation.translate(inputData); - String expectedOutput = "Bienvenido a todos"; - - assertEquals(expectedOutput, output.getTranslatedText()); - } - - public void testTranslate2French() { - String text = "Hello everyone"; - String selectedLanguage = "French"; - TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - - TranslationOutputData output = NoteTranslation.translate(inputData); - String expectedOutput = "Bonjour à tous"; - - assertEquals(expectedOutput, output.getTranslatedText()); - } - - public void testTranslate2Arabic() { - String text = "Please and thank you"; - String selectedLanguage = "Arabic"; - TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - - TranslationOutputData output = NoteTranslation.translate(inputData); - String expectedOutput = "من فضلك وشكرا لكم"; - - assertEquals(expectedOutput, output.getTranslatedText()); - } - - public void testLanguageNotInDropdown() { - // If selected language is not part of the dropdown list, should output original text - String text = "Hello everyone"; - String selectedLanguage = "Italian"; - TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - - TranslationOutputData output = NoteTranslation.translate(inputData); - String expectedOutput = "Hello everyone"; - - assertEquals(expectedOutput, output.getTranslatedText()); - } - - public void testTranslateEmptyString() { - // Empty string should return empty string - String text = " "; - String selectedLanguage = "Russian"; - TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - - TranslationOutputData output = NoteTranslation.translate(inputData); - String expectedOutput = ""; - - assertEquals(expectedOutput, output.getTranslatedText()); - } - - public void testExceededCharLimit() { - String text = "hello ".repeat(400); - String selectedLanguage = "Spanish"; - TranslationInputData inputData = new TranslationInputData(text, selectedLanguage); - - TranslationOutputData output = NoteTranslation.translate(inputData); - String expectedOutput = "Exceeded character limit"; - - assertEquals(expectedOutput, output.getTranslatedText()); - } -} \ No newline at end of file diff --git a/src/test/java/use_cases/note/TranslationInteractorTest.java b/src/test/java/use_cases/note/TranslationInteractorTest.java new file mode 100644 index 000000000..b198cd34b --- /dev/null +++ b/src/test/java/use_cases/note/TranslationInteractorTest.java @@ -0,0 +1,109 @@ +package use_cases.note; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class TranslationInteractorTest { + + @Test + public void testTranslate2Russian() { + final TranslationInputData inputData = new TranslationInputData("Hello world", "Russian"); + + TranslationOutputBoundary outputBoundary = new TranslationOutputBoundary() { + @Override + public void updateTranslation(TranslationOutputData outputData) { + assertEquals("Привет мир", outputData.getTranslatedText()); + } + }; + TranslationInteractor translationInteractor = new TranslationInteractor(outputBoundary); + translationInteractor.translateNote(inputData); + } + + @Test + public void testTranslate2Spanish() { + final TranslationInputData inputData = new TranslationInputData("Welcome everyone", "Spanish"); + + TranslationOutputBoundary outputBoundary = new TranslationOutputBoundary() { + @Override + public void updateTranslation(TranslationOutputData outputData) { + assertEquals("Bienvenido a todos", outputData.getTranslatedText()); + } + }; + TranslationInteractor translationInteractor = new TranslationInteractor(outputBoundary); + translationInteractor.translateNote(inputData); + } + + @Test + public void testTranslate2French() { + final TranslationInputData inputData = new TranslationInputData("Hello everyone", "French"); + + TranslationOutputBoundary outputBoundary = new TranslationOutputBoundary() { + @Override + public void updateTranslation(TranslationOutputData outputData) { + assertEquals("Bonjour à tous", outputData.getTranslatedText()); + } + }; + TranslationInteractor translationInteractor = new TranslationInteractor(outputBoundary); + translationInteractor.translateNote(inputData); + } + + @Test + public void testTranslate2Arabic() { + final TranslationInputData inputData = new TranslationInputData("Please and thank you", "Arabic"); + + TranslationOutputBoundary outputBoundary = new TranslationOutputBoundary() { + @Override + public void updateTranslation(TranslationOutputData outputData) { + assertEquals("من فضلك وشكرا لكم", outputData.getTranslatedText()); + } + }; + TranslationInteractor translationInteractor = new TranslationInteractor(outputBoundary); + translationInteractor.translateNote(inputData); + } + + @Test + public void testLanguageNotInDropdown() { + // If selected language is not part of the dropdown list, should output original text + final TranslationInputData inputData = new TranslationInputData("Hello everyone", "Italian"); + + TranslationOutputBoundary outputBoundary = new TranslationOutputBoundary() { + @Override + public void updateTranslation(TranslationOutputData outputData) { + assertEquals("Hello everyone", outputData.getTranslatedText()); + } + }; + TranslationInteractor translationInteractor = new TranslationInteractor(outputBoundary); + translationInteractor.translateNote(inputData); + } + + @Test + public void testTranslateEmptyString() { + // Empty string should return empty string + final TranslationInputData inputData = new TranslationInputData(" ", "French"); + + TranslationOutputBoundary outputBoundary = new TranslationOutputBoundary() { + @Override + public void updateTranslation(TranslationOutputData outputData) { + assertEquals("", outputData.getTranslatedText()); + } + }; + TranslationInteractor translationInteractor = new TranslationInteractor(outputBoundary); + translationInteractor.translateNote(inputData); + } + + @Test + public void testExceededCharLimit() { + String text = "hello ".repeat(400); + final TranslationInputData inputData = new TranslationInputData(text, "Spanish"); + + TranslationOutputBoundary outputBoundary = new TranslationOutputBoundary() { + @Override + public void updateTranslation(TranslationOutputData outputData) { + assertEquals("Exceeded character limit", outputData.getTranslatedText()); + } + }; + TranslationInteractor translationInteractor = new TranslationInteractor(outputBoundary); + translationInteractor.translateNote(inputData); + } +} \ No newline at end of file From 36330b72a4f3ed29a94127577bc18264e0f5682d Mon Sep 17 00:00:00 2001 From: Elizabeth Kochel Date: Fri, 29 Nov 2024 01:17:43 -0500 Subject: [PATCH 47/56] fixed pom.xml --- pom.xml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/pom.xml b/pom.xml index 5a4acf3f8..322ba7eb1 100644 --- a/pom.xml +++ b/pom.xml @@ -53,14 +53,6 @@ 2.13.0 - - com.fasterxml.jackson.core - jackson-bom - 2.13.0 - pom - import - - com.google.oauth-client google-oauth-client @@ -91,13 +83,6 @@ v3-rev20240705-2.0.0 - - com.google.apis - google-api-services-calendar - v3-rev20220715-2.0.0 - beta - - com.google.http-client google-http-client-jackson2 From 97104c7cc4247b63ef65e3527c39c3bb10303903 Mon Sep 17 00:00:00 2001 From: akhimie1 Date: Fri, 29 Nov 2024 11:16:32 -0500 Subject: [PATCH 48/56] I am still working on the README. --- README.md | 9 +++++++++ src/main/java/entity/Note.java | 6 +++--- src/main/java/use_cases/calendar/CalendarRequest.java | 10 ++++++---- src/main/java/view/NotesView.java | 3 ++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3f78f85c1..e90ce8fc4 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,15 @@ To keep track of things, you can tick off tasks as you go about completing them. ## Features of the Software +There are three major components of this software: Calendar, Checklist and Notes. +So, upon running the program, the user first sees "Welcome to your Dashboard" +// TODO: add a screenshot +On the left of the Dashboard, the user sees three tabs: Calendar, Notes and Checklist. + +#### Calendar +The user can easily migrate to the Calendar tab by clicking on it. +// TODO: add a screenshot +Now, the user is on the calendar. They are prompter to log in... ## Installation Instructions diff --git a/src/main/java/entity/Note.java b/src/main/java/entity/Note.java index 419d23053..a47db3de9 100644 --- a/src/main/java/entity/Note.java +++ b/src/main/java/entity/Note.java @@ -5,8 +5,8 @@ */ public class Note { - private final String content; - private final String title; + private String content; + private String title; public Note(String content, String title) { this.content = content; @@ -25,7 +25,7 @@ public void setContent(String newContent) { this.content = newContent; } - public String setTitle(newTitle){ + public void setTitle(String newTitle) { this.title = newTitle; } } diff --git a/src/main/java/use_cases/calendar/CalendarRequest.java b/src/main/java/use_cases/calendar/CalendarRequest.java index 57fbd201e..3b72aec44 100644 --- a/src/main/java/use_cases/calendar/CalendarRequest.java +++ b/src/main/java/use_cases/calendar/CalendarRequest.java @@ -45,9 +45,10 @@ public class CalendarRequest { /** * Creates credentials. + * * @return Calendar. * @throws GeneralSecurityException exception. - * @throws IOException exception. + * @throws IOException exception. */ public static Calendar getCalendarService() throws GeneralSecurityException, IOException { // Load the service account key JSON file @@ -69,9 +70,10 @@ public static Calendar getCalendarService() throws GeneralSecurityException, IOE /** * Retrieves calendar events, first 10 of them. + * * @return List of events. * @throws GeneralSecurityException exception. - * @throws IOException exception. + * @throws IOException exception. */ public List getCalendarEvents() throws GeneralSecurityException, IOException { final Calendar service = getCalendarService(); @@ -83,8 +85,7 @@ public List getCalendarEvents() throws GeneralSecurityException, IOExcept final List items = events.getItems(); if (items.isEmpty()) { System.out.println("No upcoming events found."); - } - else { + } else { System.out.println("Upcoming events:"); for (Event event : items) { DateTime start = event.getStart().getDateTime(); @@ -96,3 +97,4 @@ public List getCalendarEvents() throws GeneralSecurityException, IOExcept } return items; } +} diff --git a/src/main/java/view/NotesView.java b/src/main/java/view/NotesView.java index e8069455c..27fe96fe9 100644 --- a/src/main/java/view/NotesView.java +++ b/src/main/java/view/NotesView.java @@ -38,6 +38,7 @@ public class NotesView extends JPanel implements ActionListener, PropertyChangeL private JLabel noteName; private JTextArea noteInputField; + private JTextArea outputArea; private JButton saveNoteButton; private JButton uploadButton; @@ -197,7 +198,7 @@ private JPanel getjPanel() { ); tools.add(languageButton); - final JTextArea outputArea = new JTextArea(); + outputArea = new JTextArea(); outputArea.setEditable(false); panel.add(outputArea); From 4502c3cedb3fc3c211699cf0c6de888fc66e1217 Mon Sep 17 00:00:00 2001 From: akhimie1 Date: Sat, 30 Nov 2024 17:51:30 -0500 Subject: [PATCH 49/56] I am done with the content of the README.md. I need to include screenshots now. I also added a check for my use case to ensure titles of notes are unique to the note. --- README.md | 70 ++++++++++++++++++- .../java/use_cases/note/NoteInteractor.java | 11 ++- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3f78f85c1..79be02b5c 100644 --- a/README.md +++ b/README.md @@ -32,15 +32,81 @@ To keep track of things, you can tick off tasks as you go about completing them. ## Features of the Software +There are three major components of this software: Calendar, Checklist and Notes. +So, upon running the program, the user first sees "Welcome to your Dashboard" +__// TODO: add a screenshot__ +On the left of the Dashboard, the user sees three tabs: Calendar, Notes and Checklist. + +### Calendar +The user can easily migrate to the Calendar tab by clicking on it. +__// TODO: add a screenshot__ +Now, the user is on the Calendar tab. They are prompter to log in their __Google Account__. +__// TODO: add a screenshot__ +This displays the events the user has logged in on their Google calendar. +The user then has the option to add event to their already existing calendar that was retrieved by logging into their Google account. +(The user has the option of creating a new calendar, without having to log into their Google account?) + +### Notes +The user can also go to the Notes tab by clicking the menu on the left of their view. +__// TODO: add a screenshot__ +Now, the user is on the Notes tab. +On the left side of the user's view, they can create a new note by simply typing into the provided area that says "*_Create Note_*" +The user also has the option of uploading text from an already existing file. +__// I am thinking of any style functions and undo, and redo...//__ +As additional functionalities, the user can translate existing text on their notes to either French, Spanish, Russian. +Also, the user can prompt AI to complete the note based on what the user has written. + +### Checklist +The user can move to the Checklist tab by clicking the menu on the left of their view. +__// TODO: add a screenshot__ +Now, the user is on the Checklist tab. +On the user's view, the user will sea add task. +__// TODO: add a screenshot__ +This will allow the user to make a new checklist or add new tasks to an already existing checklist. + ## Installation Instructions +As the user, you should ensure that their IDE is working and already setup. If you need any help setting up, +[visit here](https://www.jetbrains.com/help/idea/getting-started.html). +To run the program, there are two options: +1. __Through the IDE:__ + 1. First, you have to clone the repo, by using [this URL](https://github.com/PrishaPatel24/ZenTask.git). + 2. Then, run the MainNoteApplication found in the src/main/java/app of the project through the IDE. +2. __Through the terminal:__ + 1. First, you have to clone the repo, by using [this URL](https://github.com/PrishaPatel24/ZenTask.git). + 2. Navigate to the directory where the MainNoteApplication is on, in your File Manager + (ensure the directory is like .../ZenTask/src/main/java/app). + 3. Then, open the terminal there. + 4. In you terminal, compile the program by using `javac MainNoteApplication.java` + 5. Then, run the application, using `java MainNoteApplication` + 6. You should see your Dashboard. __// TODO: add a screenshot__ ## Usage Guide +To use the software, the user should navigate the tabs using the menu found on the left of the view. +__// TODO: add a screenshot__ ## License +To view the License consistent with the details and use of this program, please refer to the file name **LICENSE** in the project directory. ## Feedback +As a user, you can give feedback on the software, using [this link](https://forms.gle/mA2Q9dh3G84v8RdW7). +Please, take your time to carefully fill out the form and should expect a follow-up with 2-3 business days. ## Contributions - - +All contributions to the project are welcome. +To contribute to the project, you have to follow these steps: +1. Make a fork of the [project](https://github.com/PrishaPatel24/ZenTask) on GitHub by right-clicking _Fork_ found on the top right of the GitHub page. +Then, create a new fork. __// TODO: add a screenshot__ +2. Then, clone the repo and work from your IDE. +3. Do not forget to add a branch protection rule, especially if you are working with other people. Ensure everyone has their branch. +Then, they will need to make a pull request on your own fork of the repository ([do this through the IDE](https://www.jetbrains.com/help/idea/work-with-github-pull-requests.html#create-pull-request)), +explaining in detail what changes they have made, and perform a [code review](https://swimm.io/learn/code-reviews/ultimate-10-step-code-review-checklist). +4. To add your contributions to this project, you have to make a merge request. +5. To make a merge request, first navigate to the back to [this project's repository](https://github.com/PrishaPatel24/ZenTask). +6. Then, on top of the GitHub page, click on _Pull Requests_. __// TODO: add a screenshot__ +7. Click on the green button on the left of the GitHub page to create a _New pull request_. +8. Then, set the base repository to [this project's repository](https://github.com/PrishaPatel24/ZenTask) and set base to _main_. +9. Similarly, set the head repository to be your fork of the repository and set base to main. +10. Then, click on the green button, _Create pull request_. __// TODO: add a screenshot__ +11. In the pull request, add a title that properly summarizes the content of the "contribution". +Also, add a proper description that contain what changes you made or things you added, what files your worked on and why this contribution is meaningful and beneficial. diff --git a/src/main/java/use_cases/note/NoteInteractor.java b/src/main/java/use_cases/note/NoteInteractor.java index a991ca2f5..0450f2643 100644 --- a/src/main/java/use_cases/note/NoteInteractor.java +++ b/src/main/java/use_cases/note/NoteInteractor.java @@ -21,10 +21,17 @@ public NoteInteractor(NoteOutputBoundary noteOutputBoundary, InMemoryNoteDataAcc @Override public void execute(NoteInputData noteInputData) { final Note note = new Note(noteInputData.getContent(), noteInputData.getTitle()); - inMemoryNoteDataAccessObject.saveNote(noteInputData.getContent(), note); + if (this.inMemoryNoteDataAccessObject.getNotes() != null) { + for (String title : this.inMemoryNoteDataAccessObject.getNotes()) { + if (noteInputData.getTitle().equals(title)) { + this.notePresenter.prepareFailView( + "Title already exists. Multiple notes cannot have the same title."); + } + } + } // TODO: Check if this works + this.inMemoryNoteDataAccessObject.saveNote(noteInputData.getContent(), note); final NoteOutputData noteOutputData = new NoteOutputData(note.getTitle(), false); this.notePresenter.prepareSuccessView(noteOutputData.getContent()); } - } From 1983d85f1b04e009e550615479c44e48fde76801 Mon Sep 17 00:00:00 2001 From: Elizabeth Kochel Date: Sat, 30 Nov 2024 18:30:28 -0500 Subject: [PATCH 50/56] wrote accessibility report --- accessibility-report.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 accessibility-report.md diff --git a/accessibility-report.md b/accessibility-report.md new file mode 100644 index 000000000..05f09c34d --- /dev/null +++ b/accessibility-report.md @@ -0,0 +1,39 @@ +## 1. Principles of Universal Design +- Equitable Use: The translation feature allows users who speak other languages to interact with our program. Since the + interface is easy to use and straightforward, users with varying levels of technical knowledge can use the program. +- Flexibility in Use: The program has multiple functionalities, including note-taking, checklists for tasks, a calendar + for event management, language translation, and AI-assisted completion. Users can choose how they interact with the + program, whether they organize tasks, translate content, or write notes. This accommodates different workflows and + user needs. +- Simple and Intuitive Use: The program has clearly-labeled buttons like "Translate", "Complete Notes With AI", and "Add + Task" so that users can intuitively navigate the app. The checklist and calendar are straightforward and allow users to + add tasks or events without much effort. +- Perceptible Information: Information is presented visually through text areas, dropdown menus, and buttons, which makes + the program easy to understand. For example, the dropdown menu for language selection is simple and easy to locate, + and the translation output is displayed in a separate area so that users can distinguish between the original text and + the translated text. +- Tolerance for Error: If users attempt to translate notes that are too long, the program provides feedback ("Exceeded + character limit") instead of crashing. The checklist and calendar features allow users to update or remove entries so + that mistakes can be easily fixed. +- Low Physical Effort: Tasks such as adding events to the calendar, updating the checklist, or translating text are + simplified and made more efficient for the user. The AI-assisted note completion feature helps users save time and effort + by automatically filling in ideas or suggestions, so that users don’t have to type it all out themselves. +- Size and Space for Approach and Use: The program can be used on standard desktop or laptop screens and has well-spaced + buttons and input fields that are easy to access. The dropdown menu and text areas are appropriately sized so that it's + user-friendly. + +## 2. Marketing +If we were to sell or license ZenTask to customers, we would primarily market our program to students and professionals. +Since it has note-taking and translation features, our program would be particularly useful for multilingual users, +exchange students or students studying foreign languages, and professionals who are working in multicultural environments +or abroad. The "Complete Notes with AI" feature is helpful for students and writers needing additional assistance, and +the checklist and calendar features can be used by anyone with a busy schedule that could benefit from organizing their +tasks, deadlines, and scheduled events. + +## 3. Demographic Challenges +This program may be less likely to be used by those who are visually impaired since this program does not have +screen readers or voice navigation to make it more suitable for those users. Implementing a text-to-speech feature +would help reach a wider audience of users and make it more accessible. This program is also less likely to be +used by those with dyslexia or reading impairments since it does not include spell-checking and the size of the text cannot +be increased. To accommodate for these users, in the future we could implement a feature that allows people to create +text by speaking instead of typing. From 59792c5fdf38fb5bbe26f62338cec208f2069b27 Mon Sep 17 00:00:00 2001 From: stickycorner Date: Sat, 30 Nov 2024 18:32:41 -0500 Subject: [PATCH 51/56] bug fixes --- src/main/java/entity/Note.java | 10 +++++----- src/main/java/use_cases/calendar/CalendarRequest.java | 10 ++++++---- src/main/java/view/NotesView.java | 4 ++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/entity/Note.java b/src/main/java/entity/Note.java index 419d23053..ec540c883 100644 --- a/src/main/java/entity/Note.java +++ b/src/main/java/entity/Note.java @@ -5,8 +5,8 @@ */ public class Note { - private final String content; - private final String title; + private String content; + private String title; public Note(String content, String title) { this.content = content; @@ -20,12 +20,12 @@ public String getContent() { public String getTitle() { return title; } - + public void setContent(String newContent) { this.content = newContent; } - public String setTitle(newTitle){ - this.title = newTitle; + public void setTitle(String newTitle) { + this.title = newTitle; } } diff --git a/src/main/java/use_cases/calendar/CalendarRequest.java b/src/main/java/use_cases/calendar/CalendarRequest.java index 57fbd201e..3b72aec44 100644 --- a/src/main/java/use_cases/calendar/CalendarRequest.java +++ b/src/main/java/use_cases/calendar/CalendarRequest.java @@ -45,9 +45,10 @@ public class CalendarRequest { /** * Creates credentials. + * * @return Calendar. * @throws GeneralSecurityException exception. - * @throws IOException exception. + * @throws IOException exception. */ public static Calendar getCalendarService() throws GeneralSecurityException, IOException { // Load the service account key JSON file @@ -69,9 +70,10 @@ public static Calendar getCalendarService() throws GeneralSecurityException, IOE /** * Retrieves calendar events, first 10 of them. + * * @return List of events. * @throws GeneralSecurityException exception. - * @throws IOException exception. + * @throws IOException exception. */ public List getCalendarEvents() throws GeneralSecurityException, IOException { final Calendar service = getCalendarService(); @@ -83,8 +85,7 @@ public List getCalendarEvents() throws GeneralSecurityException, IOExcept final List items = events.getItems(); if (items.isEmpty()) { System.out.println("No upcoming events found."); - } - else { + } else { System.out.println("Upcoming events:"); for (Event event : items) { DateTime start = event.getStart().getDateTime(); @@ -96,3 +97,4 @@ public List getCalendarEvents() throws GeneralSecurityException, IOExcept } return items; } +} diff --git a/src/main/java/view/NotesView.java b/src/main/java/view/NotesView.java index e8069455c..d04905499 100644 --- a/src/main/java/view/NotesView.java +++ b/src/main/java/view/NotesView.java @@ -19,6 +19,7 @@ import javax.swing.JSplitPane; import javax.swing.JTextArea; +import entity.Note; import org.jetbrains.annotations.NotNull; import interface_adapter.ai.AiController; @@ -44,6 +45,8 @@ public class NotesView extends JPanel implements ActionListener, PropertyChangeL private JButton clearButton; private JButton deleteButton; + private JTextArea notesTextArea; + private JPanel notePanel; private JPanel editPanel; private JPanel savePanel; @@ -163,6 +166,7 @@ private void buildUi() { splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, notePanel, functionalityPanel); splitPane.setDividerLocation(DIVIDER); + this.add(splitPane); } From 11af58eabc84938b63c830ad93a80a1f04d28f08 Mon Sep 17 00:00:00 2001 From: akhimie1 Date: Sat, 30 Nov 2024 19:22:23 -0500 Subject: [PATCH 52/56] I started writing my tests for the interactor. I need to fix some things. --- .../InMemoryNoteDataAccessObject.java | 11 +- src/main/java/entity/Note.java | 3 +- .../note/NoteDataAccessInterface.java | 15 ++- .../java/use_cases/note/NoteInteractor.java | 10 +- src/main/java/view/NotesView.java | 5 +- .../java/app/MainNoteApplicationTest.java | 104 ------------------ src/test/java/entity/NoteTest.java | 2 +- .../use_cases/note/NoteInteractorTest.java | 50 ++++----- 8 files changed, 48 insertions(+), 152 deletions(-) delete mode 100644 src/test/java/app/MainNoteApplicationTest.java diff --git a/src/main/java/data_access/InMemoryNoteDataAccessObject.java b/src/main/java/data_access/InMemoryNoteDataAccessObject.java index c508f4f20..15958b748 100644 --- a/src/main/java/data_access/InMemoryNoteDataAccessObject.java +++ b/src/main/java/data_access/InMemoryNoteDataAccessObject.java @@ -1,6 +1,8 @@ package data_access; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import entity.Note; @@ -11,18 +13,19 @@ * This does not persist data between runs of the program. */ public class InMemoryNoteDataAccessObject implements NoteDataAccessInterface { - private final Map notes; + private final Map notes; public InMemoryNoteDataAccessObject() { this.notes = new HashMap<>(); } @Override - public void saveNote(String title, Note note) { + public void saveNote(String title, String note) { this.notes.put(title, note); } - public String[] getNotes() { - return this.notes.keySet().toArray(new String[0]); + @Override + public List getNotes() { + return new ArrayList<>(this.notes.keySet()); } } diff --git a/src/main/java/entity/Note.java b/src/main/java/entity/Note.java index a47db3de9..59a3596fc 100644 --- a/src/main/java/entity/Note.java +++ b/src/main/java/entity/Note.java @@ -26,6 +26,7 @@ public void setContent(String newContent) { } public void setTitle(String newTitle) { - this.title = newTitle; + title = newTitle; } + } diff --git a/src/main/java/use_cases/note/NoteDataAccessInterface.java b/src/main/java/use_cases/note/NoteDataAccessInterface.java index 0859738c5..bd89b6b78 100644 --- a/src/main/java/use_cases/note/NoteDataAccessInterface.java +++ b/src/main/java/use_cases/note/NoteDataAccessInterface.java @@ -1,5 +1,7 @@ package use_cases.note; +import java.util.List; + import entity.Note; /** @@ -10,9 +12,14 @@ public interface NoteDataAccessInterface { /** * Saves a note. - *

The password of the user must match that of the user saved in the system.

- * @param title the title associated with the note - * @param note the note to be saved + * @param title the title associated with the note. + * @param note the note to be saved. + */ + void saveNote(String title, String note); + + /** + * Creates an "in-memory" database of all notes saved in the program. + * @return a list of the titles of all notes that have been saved. */ - void saveNote(String title, Note note); + List getNotes(); } diff --git a/src/main/java/use_cases/note/NoteInteractor.java b/src/main/java/use_cases/note/NoteInteractor.java index 0450f2643..3f2c1fd6e 100644 --- a/src/main/java/use_cases/note/NoteInteractor.java +++ b/src/main/java/use_cases/note/NoteInteractor.java @@ -1,6 +1,5 @@ package use_cases.note; -import data_access.InMemoryNoteDataAccessObject; import entity.Note; /** @@ -11,16 +10,15 @@ public class NoteInteractor implements NoteInputBoundary { private final NoteOutputBoundary notePresenter; - private final InMemoryNoteDataAccessObject inMemoryNoteDataAccessObject; + private final NoteDataAccessInterface inMemoryNoteDataAccessObject; - public NoteInteractor(NoteOutputBoundary noteOutputBoundary, InMemoryNoteDataAccessObject inMemoryNoteDAO) { + public NoteInteractor(NoteOutputBoundary noteOutputBoundary, NoteDataAccessInterface inMemoryNoteDAO) { this.notePresenter = noteOutputBoundary; this.inMemoryNoteDataAccessObject = inMemoryNoteDAO; } @Override public void execute(NoteInputData noteInputData) { - final Note note = new Note(noteInputData.getContent(), noteInputData.getTitle()); if (this.inMemoryNoteDataAccessObject.getNotes() != null) { for (String title : this.inMemoryNoteDataAccessObject.getNotes()) { if (noteInputData.getTitle().equals(title)) { @@ -29,8 +27,8 @@ public void execute(NoteInputData noteInputData) { } } } // TODO: Check if this works - this.inMemoryNoteDataAccessObject.saveNote(noteInputData.getContent(), note); - final NoteOutputData noteOutputData = new NoteOutputData(note.getTitle(), false); + this.inMemoryNoteDataAccessObject.saveNote(noteInputData.getTitle(), noteInputData.getContent()); + final NoteOutputData noteOutputData = new NoteOutputData(noteInputData.getTitle(), false); this.notePresenter.prepareSuccessView(noteOutputData.getContent()); } } diff --git a/src/main/java/view/NotesView.java b/src/main/java/view/NotesView.java index 27fe96fe9..ed32ae80b 100644 --- a/src/main/java/view/NotesView.java +++ b/src/main/java/view/NotesView.java @@ -19,6 +19,7 @@ import javax.swing.JSplitPane; import javax.swing.JTextArea; +import entity.Note; import org.jetbrains.annotations.NotNull; import interface_adapter.ai.AiController; @@ -75,6 +76,7 @@ private void initializeComponents() { noteName = new JLabel("New Note"); noteInputField = new JTextArea(); + noteInputField.setText("Create New Note..."); saveNoteButton = new JButton("Save Note"); uploadButton = new JButton("Upload"); @@ -179,7 +181,6 @@ private JPanel getjPanel() { aiButton.addActionListener( evt -> { if (evt.getSource().equals(aiButton)) { - aiController.generateResponse(noteInputField.getText()); aiController.generateResponse(new Note(noteInputField.getText(), "NA")); // Jenna, you may need to call some method since you cannot create an instance of Note here. @@ -241,7 +242,7 @@ public void setAiController(AiController aiController) { * @param newNote The new note to display. */ public void displayNewNote(Note newNote) { - notesTextArea.setText(newNote.getContent()); + outputArea.setText(newNote.getContent()); } // add methods for other controllers here } diff --git a/src/test/java/app/MainNoteApplicationTest.java b/src/test/java/app/MainNoteApplicationTest.java deleted file mode 100644 index 9125d223d..000000000 --- a/src/test/java/app/MainNoteApplicationTest.java +++ /dev/null @@ -1,104 +0,0 @@ -package app; - -import entity.User; -import org.junit.Before; -import org.junit.Test; -import use_cases.note.NoteDataAccessInterface; - -import javax.swing.*; -import java.awt.*; - -import static java.lang.Thread.sleep; -import static org.junit.Assert.*; - -public class MainNoteApplicationTest { - - private JFrame app; - - @Before - public void setUp() { - - // create the data access and inject it into our builder! - final NoteDataAccessInterface noteDataAccess = new NoteDataAccessInterface() { - - private String note = "test"; - - @Override - public String saveNote(String title, String note) { - this.note = note; - return note; - } - - @Override - public String loadNote(String title) { - return note; - } - }; - } - - /** - * This is an example of an end-to-end test with a mocked database. - *

The code creates the application and directly tests to see that the GUI - * is updated as expected when the buttons and UI elements are interacted with. - *

- * You can run the test to visually see what happens. - */ - @Test - public void testEndToEnd() { - - Component[] components = ((JPanel)app.getRootPane().getContentPane().getComponents()[0]).getComponents(); - JTextArea textArea = null; - for (Component component : components) { - if (component instanceof JTextArea) { - textArea = (JTextArea) component; - assertEquals("test", textArea.getText()); - - } - } - - textArea.setText("test test"); - - - JButton save = null; - JButton load = null; - for (Component component : components) { - if (component instanceof JPanel) { - for (Component c : ((JPanel) component).getComponents()) { - if (c instanceof JButton) { - if (save != null) { - load = (JButton) c; - } - else { - save = (JButton) c; - } - } - } - } - } - - save.doClick(); - assertEquals("test test", textArea.getText()); - textArea.setText(""); - - System.out.println("cleared text; about to refresh..."); - // pause execution for a bit so we can visually see the changes on the screen - try { - sleep(1500); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - - load.doClick(); - assertEquals("test test", textArea.getText()); - - System.out.println("after refresh!"); - - // pause execution for a bit so we can visually see the changes on the screen - try { - sleep(1500); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - - } -} \ No newline at end of file diff --git a/src/test/java/entity/NoteTest.java b/src/test/java/entity/NoteTest.java index 3aba5aed1..42405b940 100644 --- a/src/test/java/entity/NoteTest.java +++ b/src/test/java/entity/NoteTest.java @@ -19,6 +19,6 @@ public void setContentTest() { @Test public void getDateTest() { final Note testNote = new Note("content of note is here", "2024-11-18"); - assert testNote.getCreationDate().equals("2024-11-18"); + assert testNote.getTitle().equals("2024-11-18"); } } diff --git a/src/test/java/use_cases/note/NoteInteractorTest.java b/src/test/java/use_cases/note/NoteInteractorTest.java index a4723e2b1..7d14aa6d4 100644 --- a/src/test/java/use_cases/note/NoteInteractorTest.java +++ b/src/test/java/use_cases/note/NoteInteractorTest.java @@ -1,5 +1,7 @@ package use_cases.note; +import data_access.InMemoryNoteDataAccessObject; +import entity.Note; import entity.User; import org.junit.Test; @@ -8,38 +10,26 @@ public class NoteInteractorTest { @Test - public void testExecuteRefreshSuccess() { + public void testExecuteSaveSuccess() { + NoteInputData inputData = new NoteInputData("Test note", "This is a sample note! " + + "This tests to see if the note is properly saved. "); + NoteDataAccessInterface noteDataAccess = new InMemoryNoteDataAccessObject(); + noteDataAccess.saveNote(inputData.getTitle(), inputData.getContent()); -// NoteDataAccessInterface noteDAO = new NoteDataAccessInterface() { -// -// -// @Override -// public String saveNote(User user, String note) { -// return ""; -// } -// -// -// @Override -// public String loadNote(User user) { -// return "test"; -// } -// }; -// -// NoteOutputBoundary noteOB = new NoteOutputBoundary() { -// @Override -// public void prepareSuccessView(String message) { -// assertEquals("test", message); -// } -// -// @Override -// public void prepareFailView(String errorMessage) { -// fail(errorMessage); -// } -// }; -// -// NoteInteractor noteInteractor = new NoteInteractor(noteOB); -// noteInteractor.executeSave(); + NoteOutputBoundary successPresenter = new NoteOutputBoundary() { + @Override + public void prepareSuccessView(String message) { + assertEquals("This is a sample note! This tests to see if the note is properly saved. ", + inputData.getContent()); + } + @Override + public void prepareFailView(String errorMessage) { + fail("Use case failure is unexpected."); + } + }; + NoteInputBoundary noteInteractor = new NoteInteractor(successPresenter, noteDataAccess); + noteInteractor.execute(inputData); } } \ No newline at end of file From d93901cd8de3666d3a6f98f59142f771d9a4e49a Mon Sep 17 00:00:00 2001 From: akhimie1 Date: Sat, 30 Nov 2024 19:57:39 -0500 Subject: [PATCH 53/56] One test works. I will add a test for failure. --- src/main/java/use_cases/note/NoteInteractor.java | 11 +---------- src/test/java/use_cases/note/NoteInteractorTest.java | 5 +---- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/main/java/use_cases/note/NoteInteractor.java b/src/main/java/use_cases/note/NoteInteractor.java index 3f2c1fd6e..3552e149e 100644 --- a/src/main/java/use_cases/note/NoteInteractor.java +++ b/src/main/java/use_cases/note/NoteInteractor.java @@ -1,7 +1,5 @@ package use_cases.note; -import entity.Note; - /** * The "Use Case Interactor" for our two note-related use cases of refreshing * the contents of the note and saving the contents of the note. Since they @@ -19,15 +17,8 @@ public NoteInteractor(NoteOutputBoundary noteOutputBoundary, NoteDataAccessInter @Override public void execute(NoteInputData noteInputData) { - if (this.inMemoryNoteDataAccessObject.getNotes() != null) { - for (String title : this.inMemoryNoteDataAccessObject.getNotes()) { - if (noteInputData.getTitle().equals(title)) { - this.notePresenter.prepareFailView( - "Title already exists. Multiple notes cannot have the same title."); - } - } - } // TODO: Check if this works this.inMemoryNoteDataAccessObject.saveNote(noteInputData.getTitle(), noteInputData.getContent()); + final NoteOutputData noteOutputData = new NoteOutputData(noteInputData.getTitle(), false); this.notePresenter.prepareSuccessView(noteOutputData.getContent()); } diff --git a/src/test/java/use_cases/note/NoteInteractorTest.java b/src/test/java/use_cases/note/NoteInteractorTest.java index 7d14aa6d4..9c9ed6960 100644 --- a/src/test/java/use_cases/note/NoteInteractorTest.java +++ b/src/test/java/use_cases/note/NoteInteractorTest.java @@ -1,8 +1,6 @@ package use_cases.note; import data_access.InMemoryNoteDataAccessObject; -import entity.Note; -import entity.User; import org.junit.Test; import static org.junit.Assert.*; @@ -19,8 +17,7 @@ public void testExecuteSaveSuccess() { NoteOutputBoundary successPresenter = new NoteOutputBoundary() { @Override public void prepareSuccessView(String message) { - assertEquals("This is a sample note! This tests to see if the note is properly saved. ", - inputData.getContent()); + assertEquals("Use case success is expected","This is a sample note! This tests to see if the note is properly saved. ", inputData.getContent()); } @Override From fa2edd6d30bf7807fb35dcc148b9effed185882e Mon Sep 17 00:00:00 2001 From: PrishaPatel24 Date: Sun, 1 Dec 2024 15:05:45 -0500 Subject: [PATCH 54/56] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 79be02b5c..c21ac0aad 100644 --- a/README.md +++ b/README.md @@ -60,14 +60,14 @@ Also, the user can prompt AI to complete the note based on what the user has wri The user can move to the Checklist tab by clicking the menu on the left of their view. __// TODO: add a screenshot__ Now, the user is on the Checklist tab. -On the user's view, the user will sea add task. +On the user's view, the user will see add task. __// TODO: add a screenshot__ This will allow the user to make a new checklist or add new tasks to an already existing checklist. ## Installation Instructions As the user, you should ensure that their IDE is working and already setup. If you need any help setting up, -[visit here](https://www.jetbrains.com/help/idea/getting-started.html). +[visit here](https://www.jetbrains.com/help/idea/getting-started.html). The program can be run on any OS. To run the program, there are two options: 1. __Through the IDE:__ 1. First, you have to clone the repo, by using [this URL](https://github.com/PrishaPatel24/ZenTask.git). From 575df7aab72829b71c39e46368366347e1f1e920 Mon Sep 17 00:00:00 2001 From: stickycorner Date: Sun, 1 Dec 2024 20:57:08 -0500 Subject: [PATCH 55/56] completed calendar use case, updated event entity -> Events to reduce confusion with Google's implemented Event entity, renamed entity. --- README.md | 12 ++- src/main/java/app/MainNoteApplication.java | 17 ++-- .../java/entity/{Event.java => Events.java} | 12 +-- .../calendar/CalendarController.java | 12 ++- .../calendar/CalendarPresenter.java | 4 +- .../calendar/CalendarInputBoundary.java | 7 +- .../calendar/CalendarInteractor.java | 26 ++++--- .../calendar/CalendarOutputBoundary.java | 4 +- .../use_cases/calendar/CalendarRequest.java | 14 ++-- src/main/java/view/CalendarView.java | 77 +++++++------------ src/test/java/entity/EventTest.java | 33 -------- src/test/java/entity/EventsTest.java | 35 +++++++++ 12 files changed, 124 insertions(+), 129 deletions(-) rename src/main/java/entity/{Event.java => Events.java} (72%) delete mode 100644 src/test/java/entity/EventTest.java create mode 100644 src/test/java/entity/EventsTest.java diff --git a/README.md b/README.md index c21ac0aad..853dea7e5 100644 --- a/README.md +++ b/README.md @@ -40,11 +40,15 @@ On the left of the Dashboard, the user sees three tabs: Calendar, Notes and Chec ### Calendar The user can easily migrate to the Calendar tab by clicking on it. __// TODO: add a screenshot__ -Now, the user is on the Calendar tab. They are prompter to log in their __Google Account__. +Now, the user is on the Calendar tab. They are prompted to enter their __Google Email__. __// TODO: add a screenshot__ -This displays the events the user has logged in on their Google calendar. -The user then has the option to add event to their already existing calendar that was retrieved by logging into their Google account. -(The user has the option of creating a new calendar, without having to log into their Google account?) +This displays the upcoming events the user has added in on their Google calendar. +The details displayed are the event summary, location, start time, and description. + +__Note regarding Calendar Usage:__ Since we are unable to release our private project credentials, you should add your +own service account credentials in a json file somewhere in the project and add the path to the file in the CalendarRequest section. +Change the SERVICE_ACCOUNT_KEY_FILE attribute to the path and the calender should be properly +integrated to use your new own Google project credentials. ### Notes The user can also go to the Notes tab by clicking the menu on the left of their view. diff --git a/src/main/java/app/MainNoteApplication.java b/src/main/java/app/MainNoteApplication.java index 97da16e5a..cc58e2f02 100644 --- a/src/main/java/app/MainNoteApplication.java +++ b/src/main/java/app/MainNoteApplication.java @@ -18,6 +18,8 @@ import javax.swing.*; import java.awt.*; +import java.io.IOException; +import java.security.GeneralSecurityException; import use_cases.add_task.AddTaskInputBoundary; import use_cases.add_task.AddTaskInteractor; @@ -56,7 +58,13 @@ public static void main(String[] args) { final JPanel dashboardPanel = new DashboardView(); final JPanel notesPanel = createNotes(); - final JPanel calendarPanel = createCalendar(); + final JPanel calendarPanel; + try { + calendarPanel = createCalendar(); + } + catch (GeneralSecurityException | IOException exception) { + throw new RuntimeException(exception); + } final JPanel checklistPanel = createChecklist(); cardPanel.add(dashboardPanel, "Dashboard"); @@ -89,12 +97,9 @@ private static JPanel getButtonPanel(CardLayout cardLayout, JPanel cardPanel) { final JButton showChecklistButton = new JButton("Checklist"); showChecklistButton.addActionListener(event -> cardLayout.show(cardPanel, "Checklist")); - final JButton homeButton = new JButton("Dashboard"); - homeButton.addActionListener(event -> cardLayout.show(cardPanel, "Dashboard")); - final JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS)); - buttonPanel.add(homeButton); + buttonPanel.add(showCalendarButton); buttonPanel.add(showNotesButton); buttonPanel.add(showChecklistButton); @@ -107,7 +112,7 @@ private static JPanel createDashboard() { return dashboardPanel; } - private static JPanel createCalendar() { + private static JPanel createCalendar() throws GeneralSecurityException, IOException { final CalendarView calendarView = new CalendarView(); final CalendarOutputBoundary calendarPresenter = new CalendarPresenter(calendarView); final CalendarInputBoundary calendarInteractor = new CalendarInteractor(calendarPresenter, new CalendarRequest()); diff --git a/src/main/java/entity/Event.java b/src/main/java/entity/Events.java similarity index 72% rename from src/main/java/entity/Event.java rename to src/main/java/entity/Events.java index f7143275f..f39d72a85 100644 --- a/src/main/java/entity/Event.java +++ b/src/main/java/entity/Events.java @@ -1,16 +1,18 @@ package entity; +import com.google.api.services.calendar.model.EventDateTime; + /** * The representation of a calendar event for our program. */ -public class Event { +public class Events { private String name; - private String datetime; + private EventDateTime datetime; private String location; private String notes; - public Event(String name, String datetime, String location, String notes) { + public Events(String name, EventDateTime datetime, String location, String notes) { this.name = name; this.datetime = datetime; this.location = location; @@ -22,7 +24,7 @@ public String getEventName() { } public String getEventDatetime() { - return datetime; + return datetime.getDateTime().toString(); } public String getEventLocation() { @@ -37,7 +39,7 @@ public void setEventName(String eventName) { this.name = eventName; } - public void setEventDatetime(String eventDatetime) { + public void setEventDatetime(EventDateTime eventDatetime) { this.datetime = eventDatetime; } diff --git a/src/main/java/interface_adapter/calendar/CalendarController.java b/src/main/java/interface_adapter/calendar/CalendarController.java index 607409f77..0513939df 100644 --- a/src/main/java/interface_adapter/calendar/CalendarController.java +++ b/src/main/java/interface_adapter/calendar/CalendarController.java @@ -1,8 +1,10 @@ package interface_adapter.calendar; -import entity.Event; import use_cases.calendar.CalendarInputBoundary; +import java.io.IOException; +import java.security.GeneralSecurityException; + /** * The controller for the calendar use case. */ @@ -15,9 +17,11 @@ public CalendarController(CalendarInputBoundary calendarUseCaseInteractor) { /** * Executes the calendar Use Case. - * @param event the calendar event + * @param email the email of user. + * @throws GeneralSecurityException for Google account. + * @throws IOException for Google login. */ - public void execute(Event event) { - calendarUseCaseInteractor.execute(event); + public void execute(String email) throws GeneralSecurityException, IOException { + calendarUseCaseInteractor.execute(email); } } diff --git a/src/main/java/interface_adapter/calendar/CalendarPresenter.java b/src/main/java/interface_adapter/calendar/CalendarPresenter.java index 134ab5d49..f8bd4ced4 100644 --- a/src/main/java/interface_adapter/calendar/CalendarPresenter.java +++ b/src/main/java/interface_adapter/calendar/CalendarPresenter.java @@ -1,6 +1,6 @@ package interface_adapter.calendar; -import entity.Event; +import entity.Events; import use_cases.calendar.CalendarOutputBoundary; import view.CalendarView; @@ -16,7 +16,7 @@ public CalendarPresenter(CalendarView calendarView) { this.calendarView = calendarView; } - public void prepareSuccessView(List events) { + public void prepareSuccessView(List events) { calendarView.displayEvents(events); } } diff --git a/src/main/java/use_cases/calendar/CalendarInputBoundary.java b/src/main/java/use_cases/calendar/CalendarInputBoundary.java index 3f67db18e..cf88b1917 100644 --- a/src/main/java/use_cases/calendar/CalendarInputBoundary.java +++ b/src/main/java/use_cases/calendar/CalendarInputBoundary.java @@ -1,6 +1,7 @@ package use_cases.calendar; -import entity.Event; +import java.io.IOException; +import java.security.GeneralSecurityException; /** * The input boundary taking in an event. @@ -8,7 +9,7 @@ public interface CalendarInputBoundary { /** * Executes the calendar use case. - * @param event to be executed + * @param email to be executed */ - void execute(Event event); + void execute(String email) throws GeneralSecurityException, IOException; } diff --git a/src/main/java/use_cases/calendar/CalendarInteractor.java b/src/main/java/use_cases/calendar/CalendarInteractor.java index 95804dcaa..d2c5d60f8 100644 --- a/src/main/java/use_cases/calendar/CalendarInteractor.java +++ b/src/main/java/use_cases/calendar/CalendarInteractor.java @@ -1,29 +1,33 @@ package use_cases.calendar; -import entity.Event; +import entity.Events; +import com.google.api.services.calendar.model.Event; +import java.io.IOException; +import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.List; public class CalendarInteractor implements CalendarInputBoundary { private final CalendarOutputBoundary calendarPresenter; private final CalendarRequest calendarRequest; - private final List events; + private final List events; public CalendarInteractor(CalendarOutputBoundary calendarOutputBoundary, CalendarRequest calendarRequest) { this.calendarPresenter = calendarOutputBoundary; this.calendarRequest = calendarRequest; - this.events = new ArrayList<>(); + this.events = new ArrayList(); } - public void execute(Event event) { - // TODO jenna set these events based on what the api request returns -// for (event : events) { -// event.setEventName(); -// event.setEventDatetime(); -// event.setEventLocation(); -// event.setEventNotes(); -// } + public void execute(String email) throws GeneralSecurityException, IOException { + final List retResult = calendarRequest.getCalendarEvents(email); + for (Event value : retResult) { + final Events event = new Events(value.getSummary(), + value.getStart(), value.getLocation(), value.getDescription() + ); + events.add(event); + } + System.out.println("finished processing API"); calendarPresenter.prepareSuccessView(events); } } diff --git a/src/main/java/use_cases/calendar/CalendarOutputBoundary.java b/src/main/java/use_cases/calendar/CalendarOutputBoundary.java index 572156bac..3ad6f88cc 100644 --- a/src/main/java/use_cases/calendar/CalendarOutputBoundary.java +++ b/src/main/java/use_cases/calendar/CalendarOutputBoundary.java @@ -2,7 +2,7 @@ import java.util.List; -import entity.Event; +import entity.Events; /** * The output boundary for the calendar use case. @@ -12,5 +12,5 @@ public interface CalendarOutputBoundary { * Prepares the success view for the calendar Use Case. * @param events the output data as a list of events */ - void prepareSuccessView(List events); + void prepareSuccessView(List events); } diff --git a/src/main/java/use_cases/calendar/CalendarRequest.java b/src/main/java/use_cases/calendar/CalendarRequest.java index 3b72aec44..d26614809 100644 --- a/src/main/java/use_cases/calendar/CalendarRequest.java +++ b/src/main/java/use_cases/calendar/CalendarRequest.java @@ -41,7 +41,7 @@ public class CalendarRequest { /** * Directory to store authorization tokens for this application. */ - private static final String SERVICE_ACCOUNT_KEY_FILE = "fair-ceiling-402704-460d2d4af835.json"; + private static final String SERVICE_ACCOUNT_KEY_FILE = "YOUR_KEY_HERE"; /** * Creates credentials. @@ -56,12 +56,7 @@ public static Calendar getCalendarService() throws GeneralSecurityException, IOE // Build the service account credentials final GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccountStream) - .createScoped(List.of("https://www.googleapis.com/auth/calendar")) - .createDelegated("jennazhang.jz@gmail.com"); - - // REPLACE USER WITH AN EMAIL INPUT FROM LIKE A TEXT FIELD OR STH FROMM A POP UOP @ PRISHA - // YOU DID THIS BEFORE W UR ADD TASK STUFF - // MINE IS THERE AS A PLACEHOLDER FOR TESTING + .createScoped(List.of("https://www.googleapis.com/auth/calendar")); // Construct the Calendar service object return new Calendar.Builder(GoogleNetHttpTransport.newTrustedTransport(), JSON_FACTORY, @@ -71,16 +66,17 @@ public static Calendar getCalendarService() throws GeneralSecurityException, IOE /** * Retrieves calendar events, first 10 of them. * + * @param email The email address of Google account. * @return List of events. * @throws GeneralSecurityException exception. * @throws IOException exception. */ - public List getCalendarEvents() throws GeneralSecurityException, IOException { + public List getCalendarEvents(String email) throws GeneralSecurityException, IOException { final Calendar service = getCalendarService(); // List the next 10 events from the primary calendar. final DateTime now = new DateTime(System.currentTimeMillis()); - final Events events = service.events().list("calendar-id").setMaxResults(10).setTimeMin(now) + final Events events = service.events().list(email).setMaxResults(10).setTimeMin(now) .setOrderBy("startTime").setSingleEvents(true).execute(); final List items = events.getItems(); if (items.isEmpty()) { diff --git a/src/main/java/view/CalendarView.java b/src/main/java/view/CalendarView.java index b66b54a5c..08870276c 100644 --- a/src/main/java/view/CalendarView.java +++ b/src/main/java/view/CalendarView.java @@ -2,10 +2,12 @@ import javax.swing.*; -import entity.Event; +import entity.Events; import interface_adapter.calendar.CalendarController; import java.awt.*; +import java.io.IOException; +import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -20,74 +22,49 @@ public class CalendarView extends JPanel { private final JPanel weekPanel; private CalendarController calendarController; - public CalendarView() { - this.promptLabel = new JLabel("Login to Google Calendar here."); - this.loginButton = new JButton("Login"); - this.weekPanel = new JPanel(new GridLayout(1, 7)); + public CalendarView() throws GeneralSecurityException, IOException { + this.promptLabel = new JLabel("Please access your Google account:"); + this.loginButton = new JButton("Enter Email"); + this.weekPanel = new JPanel(); loginButton.addActionListener( evt -> { if (evt.getSource().equals(loginButton)) { loginButton.setVisible(false); - List> data = new ArrayList<>(); - HashMap event1 = new HashMap<>(); - HashMap event2 = new HashMap<>(); - event1.put("name", "event1"); - event2.put("name", "event2"); - event1.put("datetime", "datetime1"); - event2.put("datetime", "datetime2"); - event1.put("location", "location1"); - event2.put("location", "location2"); - event1.put("notes", "notes1"); - event2.put("notes", "notes2"); - data.add(event1); - data.add(event2); - - for (Map event : data) { - final JPanel eventPanel = new JPanel(); - eventPanel.setLayout(new BoxLayout(eventPanel, BoxLayout.Y_AXIS)); - eventPanel.add(new JButton((String) event.get("name"))); - eventPanel.add(new JButton((String) event.get("datetime"))); - eventPanel.add(new JButton((String) event.get("location"))); - eventPanel.add(new JButton((String) event.get("notes"))); - weekPanel.add(eventPanel); - // jenna api stuff for current calendar + final String email = JOptionPane.showInputDialog(this, + "Enter Email:", "Google Account", JOptionPane.PLAIN_MESSAGE); + if (email != null && !email.trim().isEmpty()) { + try { + calendarController.execute(email); + } + catch (GeneralSecurityException | IOException exception) { + throw new RuntimeException(exception); + } } } } ); this.add(this.promptLabel); this.add(this.loginButton); - this.add(this.weekPanel, BorderLayout.CENTER); } /** * Displays events in the view based on the data from the API. * @param events list of events from the API */ - public void displayEvents(List events) { - List> data = new ArrayList<>(); - HashMap event1 = new HashMap<>(); - HashMap event2 = new HashMap<>(); - event1.put("name", "event1"); - event2.put("name", "event2"); - event1.put("datetime", "datetime1"); - event2.put("datetime", "datetime2"); - event1.put("location", "location1"); - event2.put("location", "location2"); - event1.put("notes", "notes1"); - event2.put("notes", "notes2"); - data.add(event1); - data.add(event2); - - for (Map event : data) { + public void displayEvents(List events) { + weekPanel.setLayout(new BoxLayout(weekPanel, BoxLayout.Y_AXIS)); + for (Events event : events) { final JPanel eventPanel = new JPanel(); - eventPanel.setLayout(new BoxLayout(eventPanel, BoxLayout.Y_AXIS)); - eventPanel.add(new JLabel((String) event.get("name"))); - eventPanel.add(new JLabel((String) event.get("location"))); - eventPanel.add(new JLabel((String) event.get("datetime"))); - eventPanel.add(new JLabel((String) event.get("notes"))); + eventPanel.add(new JLabel(event.getEventName())); + eventPanel.add(new JLabel(event.getEventLocation())); + eventPanel.add(new JLabel(event.getEventDatetime())); + eventPanel.add(new JLabel(event.getEventNotes())); + weekPanel.add(eventPanel); } + this.promptLabel.setText("Please access your Google account:"); + this.add(this.weekPanel); + promptLabel.setVisible(false); } public void setCalendarController(CalendarController calendarController) { diff --git a/src/test/java/entity/EventTest.java b/src/test/java/entity/EventTest.java deleted file mode 100644 index 4fea8f092..000000000 --- a/src/test/java/entity/EventTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package entity; - -import org.junit.Test; - -public class EventTest { - @Test - public void getEventNameTest() { - final Event testEvent = new Event("test name", "2024-11-18", - "test location", "extra notes go here"); - assert testEvent.getEventName().equals("test name"); - } - - @Test - public void getEventLocationTest() { - final Event testEvent = new Event("test name", "2024-11-18", - "test location", "extra notes go here"); - assert testEvent.getEventLocation().equals("test location"); - } - - @Test - public void getDateTimeTest() { - final Event testEvent = new Event("test name", "2024-11-18", - "test location", "extra notes go here"); - assert testEvent.getEventDatetime().equals("2024-11-18"); - } - - @Test - public void getNoteTest() { - final Event testEvent = new Event("test name", "2024-11-18", - "test location", "extra notes go here"); - assert testEvent.getEventNotes().equals("extra notes go here"); - } -} diff --git a/src/test/java/entity/EventsTest.java b/src/test/java/entity/EventsTest.java new file mode 100644 index 000000000..2219a71c3 --- /dev/null +++ b/src/test/java/entity/EventsTest.java @@ -0,0 +1,35 @@ +package entity; + +import com.google.api.client.util.DateTime; +import com.google.api.services.calendar.model.EventDateTime; +import org.junit.Test; + +public class EventsTest { + @Test + public void getEventNameTest() { + final Events testEvents = new Events("test name", new EventDateTime().setDateTime(new DateTime("2024-12-02T09:00:00.000-05:00")), + "test location", "extra notes go here"); + assert testEvents.getEventName().equals("test name"); + } + + @Test + public void getEventLocationTest() { + final Events testEvents = new Events("test name", new EventDateTime().setDateTime(new DateTime("2024-12-02T09:00:00.000-05:00")), + "test location", "extra notes go here"); + assert testEvents.getEventLocation().equals("test location"); + } + + @Test + public void getDateTimeTest() { + final Events testEvents = new Events("test name", new EventDateTime().setDateTime(new DateTime("2024-12-02T09:00:00.000-05:00")), + "test location", "extra notes go here"); + assert testEvents.getEventDatetime().equals("2024-12-02T09:00:00.000-05:00"); + } + + @Test + public void getNoteTest() { + final Events testEvents = new Events("test name", new EventDateTime().setDateTime(new DateTime("2024-12-02T09:00:00.000-05:00")), + "test location", "extra notes go here"); + assert testEvents.getEventNotes().equals("extra notes go here"); + } +} From b85b7cc0094dfb411cf168803592a26fdfac0e70 Mon Sep 17 00:00:00 2001 From: stickycorner Date: Mon, 2 Dec 2024 01:50:59 -0500 Subject: [PATCH 56/56] complete interactor test for AI use case and started an implementation of calendar interactor test. --- src/main/java/entity/Events.java | 24 +++----------- src/main/java/entity/User.java | 24 -------------- src/main/java/use_cases/ai/AiInteractor.java | 1 - src/main/java/view/NotesView.java | 1 + .../java/use_cases/ai/AiInteractorTest.java | 25 +++++++++++++++ .../calendar/CalendarInteractorTest.java | 31 +++++++++++++++++++ 6 files changed, 61 insertions(+), 45 deletions(-) delete mode 100644 src/main/java/entity/User.java create mode 100644 src/test/java/use_cases/ai/AiInteractorTest.java create mode 100644 src/test/java/use_cases/calendar/CalendarInteractorTest.java diff --git a/src/main/java/entity/Events.java b/src/main/java/entity/Events.java index f39d72a85..8104bd544 100644 --- a/src/main/java/entity/Events.java +++ b/src/main/java/entity/Events.java @@ -7,10 +7,10 @@ */ public class Events { - private String name; - private EventDateTime datetime; - private String location; - private String notes; + private final String name; + private final EventDateTime datetime; + private final String location; + private final String notes; public Events(String name, EventDateTime datetime, String location, String notes) { this.name = name; @@ -34,20 +34,4 @@ public String getEventLocation() { public String getEventNotes() { return notes; } - - public void setEventName(String eventName) { - this.name = eventName; - } - - public void setEventDatetime(EventDateTime eventDatetime) { - this.datetime = eventDatetime; - } - - public void setEventLocation(String eventLocation) { - this.location = eventLocation; - } - - public void setEventNotes(String eventNotes) { - this.notes = eventNotes; - } } diff --git a/src/main/java/entity/User.java b/src/main/java/entity/User.java deleted file mode 100644 index e0c57e9a6..000000000 --- a/src/main/java/entity/User.java +++ /dev/null @@ -1,24 +0,0 @@ -package entity; - -/** - * The representation of a password-protected user for our program. - */ -public class User { - - private final String name; - private final String password; - - public User(String name, String password) { - this.name = name; - this.password = password; - } - - public String getName() { - return name; - } - - public String getPassword() { - return password; - } - -} diff --git a/src/main/java/use_cases/ai/AiInteractor.java b/src/main/java/use_cases/ai/AiInteractor.java index 47f66f864..1ccae8ae0 100644 --- a/src/main/java/use_cases/ai/AiInteractor.java +++ b/src/main/java/use_cases/ai/AiInteractor.java @@ -20,7 +20,6 @@ public AiInteractor(AiOutputBoundary aiOutputBoundary, AiRequest aiRequest) { /** * Auto-complete the current notes written by the user with AI. - * * @param currNote The call to the AI to complete the current note. */ public void generateResponse(Note currNote) { diff --git a/src/main/java/view/NotesView.java b/src/main/java/view/NotesView.java index c2761a108..39a8aeb0a 100644 --- a/src/main/java/view/NotesView.java +++ b/src/main/java/view/NotesView.java @@ -39,6 +39,7 @@ public class NotesView extends JPanel implements ActionListener, PropertyChangeL private final NoteViewModel noteViewModel; private AiController aiController; private NoteController noteController; + private TranslationController translationController; private JLabel noteName; private JTextArea noteInputField; diff --git a/src/test/java/use_cases/ai/AiInteractorTest.java b/src/test/java/use_cases/ai/AiInteractorTest.java new file mode 100644 index 000000000..e34941543 --- /dev/null +++ b/src/test/java/use_cases/ai/AiInteractorTest.java @@ -0,0 +1,25 @@ +package use_cases.ai; + +import entity.Note; +import org.junit.Test; +import use_cases.add_task.AddTaskInputData; +import use_cases.add_task.AddTaskInteractor; +import use_cases.add_task.AddTaskOutputBoundary; +import use_cases.add_task.AddTaskOutputData; + +import static org.junit.Assert.*; + +public class AiInteractorTest { + + @Test + public void successTest() { + AiOutputBoundary aiOutputBoundary = new AiOutputBoundary() { + @Override + public void updateNote(Note note) { + assertNotNull(note); + } + }; + AiInteractor aiInteractor = new AiInteractor(aiOutputBoundary, new AiRequest()); + aiInteractor.generateResponse(new Note("testing Note!", "Note title")); + } +} diff --git a/src/test/java/use_cases/calendar/CalendarInteractorTest.java b/src/test/java/use_cases/calendar/CalendarInteractorTest.java new file mode 100644 index 000000000..4b6f1e37f --- /dev/null +++ b/src/test/java/use_cases/calendar/CalendarInteractorTest.java @@ -0,0 +1,31 @@ +package use_cases.calendar; + +import entity.Note; +import org.junit.Test; +import entity.Events; +import use_cases.ai.AiInteractor; +import use_cases.ai.AiOutputBoundary; +import use_cases.ai.AiRequest; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.List; + +import static org.junit.Assert.*; + + +public class CalendarInteractorTest { + + @Test + public void successTest() throws GeneralSecurityException, IOException { + CalendarOutputBoundary calendarOutputBoundary = new CalendarOutputBoundary() { + @Override + public void prepareSuccessView(List events) { + assertNotNull(events); + } + }; + CalendarInteractor calendarInteractor = new CalendarInteractor(calendarOutputBoundary, new CalendarRequest()); + calendarInteractor.execute("jennazhang.jz@gmail.com"); + } + +}