Skip to content

Commit

Permalink
[TEAMMATES#11570] Move all external service classes to new package (T…
Browse files Browse the repository at this point in the history
…EAMMATES#11577)

* Move all external service classes to new package

* Update design diagram and documents

* Update design document and diagram

* Amend docs based on comments
  • Loading branch information
fsgmhoward authored and FergusMok committed Mar 18, 2022
1 parent 28d475e commit a4de043
Show file tree
Hide file tree
Showing 33 changed files with 100 additions and 55 deletions.
2 changes: 2 additions & 0 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ The `Logic` component handles the business logic of TEAMMATES. In particular, it
Package overview:
- **`logic.api`**: Provides the API of the component to be accessed by the UI.
- **`logic.core`**: Contains the core logic of the system.
- **`logic.external`**: Holds the logic of external services such as task queue service.

### Logic API

Expand All @@ -161,6 +162,7 @@ Represented by these classes:
- `TaskQueuer`: Adds tasks to the task queue, i.e. to be executed at a later time.
- `FileStorage`: Manages CRUD of binary files such as profile pictures.
- `LogsProcessor`: For more advanced usage of logging that cannot be captured by the standard logger class.
- `RecaptchaVerifier`: For verification of the reCAPTCHA token.

Many classes in this layer make use of proxy pattern, i.e. they only connect to production services such as Google Cloud Storage in the staging/production server.

Expand Down
50 changes: 33 additions & 17 deletions docs/diagrams/LogicComponent.puml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,55 @@
!include style.puml
skinparam componentBackgroundColor MODEL_COLOR_T1
skinparam componentFontColor #FFFFFF
skinparam packageBackgroundColor #FFFFFF
skinparam FolderBackgroundColor #FFFFFF
skinparam rectangleBackgroundColor MODEL_COLOR
skinparam rectangleFontColor #FFFFFF
skinparam arrowColor #000000

component Logic {
package "logic::core" as Core {
rectangle JavamailService
rectangle SendgridService
rectangle "*Service" as Service

rectangle TaskQueuesLogic
folder "logic::core" as Core {
rectangle AccountsLogic
rectangle InstructorsLogic
rectangle StudentsLogic
rectangle CoursesLogic
rectangle FeedbackSessionsLogic
rectangle "*Logic" as Logic1
rectangle "~*Logic" as Logic1
}

package "logic::api" as Api {
folder "logic::external" as External {
rectangle MailgunService
rectangle MailjetService
rectangle SendgridService
rectangle GoogleCloudTasksService
rectangle GoogleCloudStorageService
rectangle "~*Service" as Service
}

folder "logic::api" as Api {
rectangle EmailSender
rectangle EmailGenerator
rectangle "Logic" as Logic2
rectangle TaskQueuer
rectangle GateKeeper
rectangle FileStorage
rectangle RecaptchaVerifier
rectangle "Logic" as Logic2
rectangle UserProvision
rectangle LogsProcessor
}
}

rectangle ThirdPartyEmailAPIs
rectangle "GAE\nTaskQueueAPI" as GaeTaskQueueApi
rectangle "GoogleCloud\nTasksAPI" as GoogleCloudTasksApi
rectangle "GoogleCloud\nStorageAPI" as GoogleCloudStorageApi
rectangle "Other\nExternalAPIs" as OtherExternalApi
rectangle UI
storage Storage STORAGE_COLOR_T1

JavamailService ..> ThirdPartyEmailAPIs
MailgunService ..> ThirdPartyEmailAPIs
MailjetService ..> ThirdPartyEmailAPIs
SendgridService ..> ThirdPartyEmailAPIs
Service ..> ThirdPartyEmailAPIs
TaskQueuesLogic ..> GaeTaskQueueApi
GoogleCloudTasksService ..> GoogleCloudTasksApi
GoogleCloudStorageService ..> GoogleCloudStorageApi
Service ..> OtherExternalApi
AccountsLogic ..> Storage
InstructorsLogic ..> Storage
StudentsLogic ..> Storage
Expand All @@ -49,9 +60,14 @@ Logic1 ..> Storage

UI ..> Api
Api ..> Core
Api ..> External

' The hidden associations are for positioning purposes only
Api -[hidden]down- Core
Core -[hidden]up- Api
Api -[hidden]right- Core
Core -[hidden]left- Api
Api -[hidden]right- External
External -[hidden]left- Api
Core -[hidden]down- External
External -[hidden]up- Core

@enduml
3 changes: 3 additions & 0 deletions docs/diagrams/packageDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ component UI {

component Logic {
folder "logic::core" as LogicCore
folder "logic::external" as LogicExternal
folder "logic::api" as LogicApi
}

Expand Down Expand Up @@ -57,6 +58,7 @@ E2EPageObjects ..> UiWebsite
ClientRemoteApi ..> GCD

LogicApi ..> LogicCore
LogicApi ..> LogicExternal
StorageApi ..> StorageEntity
StorageSearch <..> StorageApi
E2ECases ..> E2EPageObjects
Expand Down Expand Up @@ -90,6 +92,7 @@ Client -[hidden]right- GCD

UiWebApi -[hidden]down- UiWebsite
LogicCore -[hidden]down- LogicApi
LogicExternal -[hidden]down- LogicApi
StorageEntity -[hidden]down- StorageApi
StorageApi -[hidden]down- StorageSearch
E2EPageObjects -[hidden]down- E2ECases
Expand Down
Binary file modified docs/images/LogicComponent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/packageDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions src/main/java/teammates/logic/api/EmailSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import teammates.common.util.EmailSendingStatus;
import teammates.common.util.EmailWrapper;
import teammates.common.util.Logger;
import teammates.logic.core.EmailSenderService;
import teammates.logic.core.EmptyEmailService;
import teammates.logic.core.MailgunService;
import teammates.logic.core.MailjetService;
import teammates.logic.core.SendgridService;
import teammates.logic.external.EmailSenderService;
import teammates.logic.external.EmptyEmailService;
import teammates.logic.external.MailgunService;
import teammates.logic.external.MailjetService;
import teammates.logic.external.SendgridService;

/**
* Handles operations related to sending emails.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/teammates/logic/api/FileStorage.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package teammates.logic.api;

import teammates.common.util.Config;
import teammates.logic.core.FileStorageService;
import teammates.logic.core.GoogleCloudStorageService;
import teammates.logic.core.LocalFileStorageService;
import teammates.logic.external.FileStorageService;
import teammates.logic.external.GoogleCloudStorageService;
import teammates.logic.external.LocalFileStorageService;

/**
* Handles operations related to binary files.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/teammates/logic/api/LogsProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import teammates.common.datatransfer.QueryLogsResults;
import teammates.common.datatransfer.logs.QueryLogsParams;
import teammates.common.util.Config;
import teammates.logic.core.GoogleCloudLoggingService;
import teammates.logic.core.LocalLoggingService;
import teammates.logic.core.LogService;
import teammates.logic.external.GoogleCloudLoggingService;
import teammates.logic.external.LocalLoggingService;
import teammates.logic.external.LogService;

/**
* Handles operations related to logs reading/writing.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/teammates/logic/api/RecaptchaVerifier.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package teammates.logic.api;

import teammates.common.util.Config;
import teammates.logic.core.EmptyRecaptchaService;
import teammates.logic.core.GoogleRecaptchaService;
import teammates.logic.core.RecaptchaService;
import teammates.logic.external.EmptyRecaptchaService;
import teammates.logic.external.GoogleRecaptchaService;
import teammates.logic.external.RecaptchaService;

/**
* Used to handle the verification of the user's reCAPTCHA response.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/teammates/logic/api/TaskQueuer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import teammates.common.util.EmailWrapper;
import teammates.common.util.Logger;
import teammates.common.util.TaskWrapper;
import teammates.logic.core.GoogleCloudTasksService;
import teammates.logic.core.LocalTaskQueueService;
import teammates.logic.core.TaskQueueService;
import teammates.logic.external.GoogleCloudTasksService;
import teammates.logic.external.LocalTaskQueueService;
import teammates.logic.external.TaskQueueService;
import teammates.ui.request.FeedbackSessionRemindRequest;
import teammates.ui.request.SendEmailRequest;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import teammates.common.exception.EmailSendingException;
import teammates.common.util.EmailSendingStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import org.apache.http.HttpStatus;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

/**
* Service that bypasses reCAPTCHA verification, i.e. always returning successful verification.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

/**
* A binary file storage interface used for managing binary files such as profile pictures.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import java.time.Instant;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import java.io.IOException;
import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import java.io.IOException;
import java.net.URISyntaxException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import java.lang.reflect.Type;
import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import java.io.IOException;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import org.apache.http.HttpStatus;
import org.json.JSONArray;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

/**
* An interface to verify the user's reCAPTCHA response.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import teammates.common.util.TaskWrapper;

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/teammates/logic/external/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Contains the logic of the external dependencies and services.
*/
package teammates.logic.external;
15 changes: 15 additions & 0 deletions src/test/java/teammates/architecture/ArchitectureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ArchitectureTest {

private static final String LOGIC_CORE_PACKAGE = LOGIC_PACKAGE + ".core";
private static final String LOGIC_API_PACKAGE = LOGIC_PACKAGE + ".api";
private static final String LOGIC_EXTERNAL_PACKAGE = LOGIC_PACKAGE + ".external";

private static final String UI_PACKAGE = "teammates.ui";
private static final String UI_WEBAPI_PACKAGE = UI_PACKAGE + ".webapi";
Expand Down Expand Up @@ -249,6 +250,20 @@ public void testArchitecture_logic_coreLogicShouldNotTouchApiLogic() {
.check(forClasses(LOGIC_PACKAGE));
}

@Test
public void testArchitecture_logic_coreLogicShouldNotTouchExternalLogic() {
noClasses().that().resideInAPackage(includeSubpackages(LOGIC_CORE_PACKAGE))
.should().accessClassesThat().resideInAPackage(includeSubpackages(LOGIC_EXTERNAL_PACKAGE))
.check(forClasses(LOGIC_PACKAGE));
}

@Test
public void testArchitecture_logic_externalLogicShouldNotTouchCoreLogic() {
noClasses().that().resideInAPackage(includeSubpackages(LOGIC_EXTERNAL_PACKAGE))
.should().accessClassesThat().resideInAPackage(includeSubpackages(LOGIC_CORE_PACKAGE))
.check(forClasses(LOGIC_PACKAGE));
}

@Test
public void testArchitecture_storage_storageSearchShouldNotTouchStorageEntity() {
noClasses().that().resideInAPackage(includeSubpackages(STORAGE_SEARCH_PACKAGE))
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/teammates/logic/api/EmailSenderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import com.sun.jersey.multipart.FormDataMultiPart;

import teammates.common.util.EmailWrapper;
import teammates.logic.core.MailgunService;
import teammates.logic.core.MailjetService;
import teammates.logic.core.SendgridService;
import teammates.logic.external.MailgunService;
import teammates.logic.external.MailjetService;
import teammates.logic.external.SendgridService;

/**
* SUT: {@link SendgridService},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package teammates.logic.core;
package teammates.logic.external;

import java.io.IOException;
import java.net.URISyntaxException;
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/teammates/logic/external/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Contains test cases for {@link teammates.logic.external} package.
*/
package teammates.logic.external;
1 change: 1 addition & 0 deletions src/test/resources/testng-component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<package name="teammates.storage.search" />
<package name="teammates.logic.api" />
<package name="teammates.logic.core" />
<package name="teammates.logic.external" />
<package name="teammates.ui.request" />
<package name="teammates.ui.servlets" />
<package name="teammates.ui.webapi" />
Expand Down

0 comments on commit a4de043

Please sign in to comment.