From 37c243618b4982bcd2ab171e7546a626c0b393d6 Mon Sep 17 00:00:00 2001 From: Stephen S Date: Mon, 20 Nov 2023 17:55:40 -0500 Subject: [PATCH] GetInfo use case implemented (#45) * GetInfo use case implemented * GetInfo use case implementation has been fixed, no longer messing up all the import statements of everything. * Documentation for GetInfoInteractor improved as requested --- .../java/entities/CompanyInformation.java | 12 ++++-- .../GetInfo/GetInfoInputBoundary.java | 5 +++ .../use_cases/GetInfo/GetInfoInputData.java | 13 ++++++ .../use_cases/GetInfo/GetInfoInteractor.java | 42 +++++++++++++++++++ .../GetInfo/GetInfoOutputBoundary.java | 7 ++++ .../use_cases/GetInfo/GetInfoOutputData.java | 27 ++++++++++++ .../use_cases/GetNews/GetNewsOutputData.java | 1 + 7 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 src/main/java/use_cases/GetInfo/GetInfoInputBoundary.java create mode 100644 src/main/java/use_cases/GetInfo/GetInfoInputData.java create mode 100644 src/main/java/use_cases/GetInfo/GetInfoInteractor.java create mode 100644 src/main/java/use_cases/GetInfo/GetInfoOutputBoundary.java create mode 100644 src/main/java/use_cases/GetInfo/GetInfoOutputData.java diff --git a/src/main/java/entities/CompanyInformation.java b/src/main/java/entities/CompanyInformation.java index e8afa90..7a37511 100644 --- a/src/main/java/entities/CompanyInformation.java +++ b/src/main/java/entities/CompanyInformation.java @@ -15,9 +15,15 @@ public CompanyInformation(String country, String name, String ticker, String web this.ipo = ipo; } - public String getName() { - return name; - } + public String getCountry() {return country;} + + public String getName() {return name;} + + public String getTicker() {return ticker;} + + public String getWeburl() {return weburl;} + + public String getIpo() {return ipo;} public String toString() { return "CompanyInformation{\n" + diff --git a/src/main/java/use_cases/GetInfo/GetInfoInputBoundary.java b/src/main/java/use_cases/GetInfo/GetInfoInputBoundary.java new file mode 100644 index 0000000..80e176f --- /dev/null +++ b/src/main/java/use_cases/GetInfo/GetInfoInputBoundary.java @@ -0,0 +1,5 @@ +package use_cases.GetInfo; + +public interface GetInfoInputBoundary { + void execute(GetInfoInputData getInfoInputData); +} diff --git a/src/main/java/use_cases/GetInfo/GetInfoInputData.java b/src/main/java/use_cases/GetInfo/GetInfoInputData.java new file mode 100644 index 0000000..205aac8 --- /dev/null +++ b/src/main/java/use_cases/GetInfo/GetInfoInputData.java @@ -0,0 +1,13 @@ +package use_cases.GetInfo; + +public class GetInfoInputData { + public String ticker; + + public GetInfoInputData(String ticker) { + this.ticker = ticker; + } + + public String getTicker() { + return ticker; + } +} diff --git a/src/main/java/use_cases/GetInfo/GetInfoInteractor.java b/src/main/java/use_cases/GetInfo/GetInfoInteractor.java new file mode 100644 index 0000000..4f4f57b --- /dev/null +++ b/src/main/java/use_cases/GetInfo/GetInfoInteractor.java @@ -0,0 +1,42 @@ +package use_cases.GetInfo; + +import entities.CompanyInformation; +import use_cases.APIAccessInterface; + +public class GetInfoInteractor implements GetInfoInputBoundary { + GetInfoOutputBoundary getInfoPresenter; + APIAccessInterface driverAPI; + + public GetInfoInteractor(GetInfoOutputBoundary getInfoPresenter, APIAccessInterface driverAPI) { + this.getInfoPresenter = getInfoPresenter; + this.driverAPI = driverAPI; + } + + @Override + public void execute(GetInfoInputData getInfoInputData) { + /** + *

+ * Info is fetched using the drivers.Finnhub.getCompanyProfile() method, which interacts with the API through + * an OKHTTP client. + * The information in the CompanyInformation object generated by the driver when data is taken from the API is + * transferred into a HashMap through the GetInfoOutputData constructor. + * + * @param getInfoInputData an InputData object containing the ticker of the company whose profile we fetch + */ + String ticker = getInfoInputData.getTicker(); + + try { + // Make API call + CompanyInformation company_info = driverAPI.getCompanyProfile(ticker); + + // Save API output using OutputData format for the GetNews use case + GetInfoOutputData result = new GetInfoOutputData(ticker, company_info); + + getInfoPresenter.prepareSuccessView(result); + + } catch (RuntimeException e) { +// e.printStackTrace(); + getInfoPresenter.prepareFailView("API call failed."); + } + } +} diff --git a/src/main/java/use_cases/GetInfo/GetInfoOutputBoundary.java b/src/main/java/use_cases/GetInfo/GetInfoOutputBoundary.java new file mode 100644 index 0000000..7dcfa83 --- /dev/null +++ b/src/main/java/use_cases/GetInfo/GetInfoOutputBoundary.java @@ -0,0 +1,7 @@ +package use_cases.GetInfo; + +public interface GetInfoOutputBoundary { + void prepareSuccessView(GetInfoOutputData result); + + void prepareFailView(String error); +} diff --git a/src/main/java/use_cases/GetInfo/GetInfoOutputData.java b/src/main/java/use_cases/GetInfo/GetInfoOutputData.java new file mode 100644 index 0000000..8f19671 --- /dev/null +++ b/src/main/java/use_cases/GetInfo/GetInfoOutputData.java @@ -0,0 +1,27 @@ +package use_cases.GetInfo; + +import entities.CompanyInformation; + +import java.util.Map; +import java.util.HashMap; + +public class GetInfoOutputData { + String ticker; + Map info_map; + + public GetInfoOutputData(String ticker, CompanyInformation company_info) { + this.ticker = ticker; + + // Initialize info_map attribute, then manually put each attribute to the Map from the CompanyInformation object + this.info_map = new HashMap(); + info_map.put("country", company_info.getCountry()); + info_map.put("name", company_info.getName()); + info_map.put("ticker", company_info.getTicker()); + info_map.put("weburl", company_info.getWeburl()); + info_map.put("ipo", company_info.getIpo()); + } + + public String getTicker() {return ticker;} + + public Map getInfo() {return info_map;} +} diff --git a/src/main/java/use_cases/GetNews/GetNewsOutputData.java b/src/main/java/use_cases/GetNews/GetNewsOutputData.java index d744777..ef22690 100644 --- a/src/main/java/use_cases/GetNews/GetNewsOutputData.java +++ b/src/main/java/use_cases/GetNews/GetNewsOutputData.java @@ -14,6 +14,7 @@ public class GetNewsOutputData { public GetNewsOutputData(String ticker, List company_news_items) { this.ticker = ticker; this.news_items = new ArrayList>(); + for (CompanyNews company_news : company_news_items) { Map news_item = new HashMap<>();