Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
giselabcruz committed Jan 9, 2024
2 parents 9913596 + 48a80e4 commit 4946f4e
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 83 deletions.
173 changes: 90 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Weather Data Capture and Persistence From REST API [OpenWeather](https://openweathermap.org/api)
# Canary Islands Travel Advisor Final Project


### University
Expand All @@ -24,32 +24,97 @@ Data Science Application Development
- [SQLite Documentation](https://www.sqlite.org/docs.html)
- Documentation Tools: Markdown for README.md
- [Documentation ActiveMQ Broker](https://activemq.apache.org/using-activemq)
- [Postman](https://www.postman.com/) for API testing

# Funcionality

This Java application serves as a weather forecast system for the 8 Canary Islands, querying the service's API every 6 hours. It retrieves weather data for the next 5 days at 12:00:00 pm.
The project is centered on developing a travel advisor for the Canary Islands, focusing primarily on weather conditions and hotel accommodations.

Modularity is present in this final project. It ensures flexibility, scalability, and ease of maintenance, allowing each component to function independently while contributing to the system's overall functionality.

## Architecture

![Organized project modules](/images/Archetype-removebg-preview.png)

**DataLake**: Stores all relevant data, creating separate files for weather predictions and hotel data.

**DataMart**: Processes and refines data for user queries.

**BusinessUnit**: Accesses historical data from the DataLake. In this project, when no specific parameters or locations are provided, it displays stored DataLake information. So the businessUnit is connected to datalake.


## API Implementation:
A REST API is implemented for user interaction, utilizing Postman for testing API responses.

### OpenAPI Schema

```openapi: 3.0.0
info:
title: Vacation Recommendation API
version: 1.0.0
description: An API for vacation recommendations based on hotels and weather predictions
paths:
# Define your API paths here
components:
schemas:
Hotel:
type: object
properties:
name:
type: string
location:
type: string
platformName:
type: string
price:
type: number
checkIn:
type: string
checkOut:
type: string
Weather:
type: object
properties:
location:
type: string
date:
type: string
precipitation:
type: number
clouds:
type: number
temperature:
type: number
windSpeed:
type: number
```

**Publisher/Subscriber Implementation:**
![Publisher/Subscriber](/images/publish-subscribe.png)
This application incorporates the Publisher/Subscriber pattern. The project is structured into modules, with the **Prediction Provider** and **Event Store Builder** as separate components.
In this case, the broker is ActiveMQ, and it is installed as an application on the operating system.
### Filter by Location
_________________________________________
Get all generalized information about hotels in the input location.

### Provider Module
The Provider module retrieves meteorological data at the specified frequency, generating a JSON-formatted event with information from the weather service.
GET ```/api/vacation-recommendations?location=Gran_Canaria```

![Location](/images/Location.png)

The event structure includes timestamp, source (prediction-provider), prediction timestamp, and location (latitude and longitude).
Additionally, it incorporates the weather metrics as temperature, wind speed, humidity, precipitation and clouds in the OpenWeatherMap API request.

The event is sent to the "prediction.Weather" topic.
### Filter by Temperature
_________________________________________
Get all hotels where the temperature of the Weather predictions of any location fulfill the criteria

### Broker - ActiveMQ
ActiveMQ serves as the broker, facilitating communication between the Prediction Provider and Event Store Builder modules.
GET ``` /api//vacation-recommendations?temperature=23```

### Event Store Builder Module
![byTemperature](/images/byTemperature.jpg)

The Event Store Builder module subscribes to the "prediction.Weather" topic, storing events in a temporally ordered directory structure.

Events are serialized and organized into files based on the timestamp, with the following directory structure: *eventstore/prediction.Weather/{ss}/{YYYYMMDD}.events*
**Publisher/Subscriber Implementation:**
![Publisher/Subscriber](/images/publish-subscribe.png)
This application incorporates the Publisher/Subscriber pattern for working with events.
In this case, the broker is ActiveMQ, and it is installed as an application on the operating system.

This image shows all the Topics in activeMQ created in this project:
![Topics](/images/activeMQ.png)


## Important Libraries
Expand Down Expand Up @@ -96,64 +161,21 @@ The Maven Copy-Dependencies Plugin is a valuable tool for managing project depen
```
This is particularly useful for packaging and distributing the applications along with its dependencies.

## Important Dependencies

The following Maven dependencies are included in this project's `pom.xml` file:

### - org.apache.httpcomponents.client5
This project relies on the Apache HttpClient library (Version 5.2.1) to facilitate robust and efficient HTTP communication.
Apache HttpClient is a mature and widely-used Java library that provides powerful features for making HTTP requests and handling responses.

#### Key Features:
- HTTP Protocol Support: Apache HttpClient supports various versions of the HTTP protocol, allowing seamless communication with web services and APIs.

- Connection Management: The library offers sophisticated connection management, ensuring optimal usage of network resources and minimizing latency.

- Request and Response Handling: Apache HttpClient simplifies the process of crafting HTTP requests and processing responses, making it an integral part of this project's functionality.

#### Integration in this Project:

```xml
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version>
</dependency>
```

The inclusion of __org.apache.httpcomponents.client5__ is essential for the proper functioning of HTTP-related tasks, such as querying external API for weather data.


### - org.slf4j
SLF4J (Simple Logging Facade for Java) provides a flexible logging interface for better logging within the application. It allows you to choose and configure the underlying logging implementation.

#### Key Benefits:
- Logging Abstraction: SLF4J serves as a logging facade, allowing for a consistent logging API while providing the flexibility to choose and configure the underlying logging implementation.

- Ease of Integration: By using SLF4J, this project ensures smooth integration with various logging frameworks, enabling developers to use their preferred logging implementation.

- Efficient Logging: SLF4J optimizes logging statements, avoiding unnecessary computation if the logging level is not enabled. This ensures efficient logging in both development and production environments.

#### Integration in this Project:

```xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
</dependency>
```


# Design

## Class Diagram eventStoreBuilder:
![class_diagram_EventStoreBuilder](/images/eventStoreBuilder.png)
![class_diagram_DatalakeBuilder](/images/datalakeBuilder.png)

## Class Diagram predictionProvider:
![class_diagram_PredictionProvider](/images/predictionProvider.png)

## Desing Pattern
## Class Diagram hotelProvider:
![class_diagram_HotelProvider](/images/HOTELPROVIDER.png)

## Class Diagram businessUnit:
![class_diagram_businessUnit](/images/businessUnit.png)

## Desing Patterns
In this project, **Clean Architecture** has been implemented.

![Clean_Architecture](/images/CleanArchitecture.png)
Expand All @@ -179,31 +201,16 @@ In essence, Clean Architecture promotes a flexible and scalable code structure.

[buckpal by thombergs](https://github.com/thombergs/buckpal): This repository is an example application for implementing Clean Architecture in Java. It demonstrates how to structure a Java application following Clean Architecture principles.

Also, in this project, **Repository Pattern** has been implemented in the Business Unit for efficient data handling and CRUD operations. Used as reference this [blog](https://www.linkedin.com/pulse/what-repository-pattern-alper-sara%C3%A7).

## Implemented Design Principles
The SOLID principles have been diligently implemented to in this project.

### Single Responsibility:
Classes are designed with only one responsibility, and each class has only one reason to change.

### Open for Extension, Closed for Modification:
Existing code should not be modified if it is necessary to add new implementations in the future. Therefore, it is open for extension but not for modification.

### Interface Segregation:
Large interfaces have been divided into smaller ones.

### Dependency Inversion:
Instead of high-level modules depending on low-level modules, both depend on abstractions. This principle facilitates potential future modifications or project reusability as it relies on abstractions rather than concrete implementations. Consequently, the need to change the entire codebase is avoided and only the relevant abstractions need to be modified with the new business logic.

______________________________________________________________________________________________
In addition, the __principles of modularity, cohesion and abstraction__ have been implemented.

### __Modularization__:
Is a key principle that emphasizes the organization of code into independent, self-contained modules or components.


### __Cohesion__:
Refers to the degree to which elements within a module or component work together to achieve a common goal.

### __Abstraction__:
Involves simplifying complex systems by modeling classes or components at the appropriate level of detail.
Binary file added images/Archetype-removebg-preview.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 added images/HOTELPROVIDER.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 added images/Location.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 added images/POSTMAN.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 added images/RepositoryPattern.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 added images/activeMQ.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 added images/businessUnit.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 added images/byTemperature.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/datalakeBuilder.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 removed images/eventStoreBuilder.png
Binary file not shown.
Binary file modified images/predictionProvider.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4946f4e

Please sign in to comment.