Skip to content

Commit

Permalink
Update to latest version of Java and Spring, with some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-taman committed Mar 27, 2022
2 parents d87752e + b2f6bcb commit 3c80595
Show file tree
Hide file tree
Showing 21 changed files with 229 additions and 211 deletions.
2 changes: 1 addition & 1 deletion README.md

Large diffs are not rendered by default.

71 changes: 47 additions & 24 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.0-M2</version>
<version>2.7.0-M2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>org.siriusxi.htec</groupId>
<artifactId>flight-advisor</artifactId>
<version>2.0</version>
<version>2.5</version>
<name>Flight Advisor API</name>
<description>Flight Advisor API Spring Boot based Application.</description>
<packaging>jar</packaging>
Expand Down Expand Up @@ -58,21 +58,23 @@
</licenses>

<properties>
<java.version>17</java.version>
<java.version>18</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- Dependencies versions properties -->
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
<maven.surefire.plugin.version>3.0.0-M5</maven.surefire.plugin.version>
<maven.failsafe.plugin.version>3.0.0-M5</maven.failsafe.plugin.version>
<io.jsonwebtoken.version>0.11.2</io.jsonwebtoken.version>
<org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
<org.springdoc.version>1.5.10</org.springdoc.version>
<org.springdoc.version>1.6.6</org.springdoc.version>
<lombok.version>1.18.20</lombok.version>
<opencsv.version>5.5.2</opencsv.version>
<opencsv.version>5.6</opencsv.version>
<hipster-core.version>1.0.1</hipster-core.version>
<datasource-proxy-sbs.version>1.8.0</datasource-proxy-sbs.version>
<commons-fileupload.version>1.4</commons-fileupload.version>
<commons-io.version>2.11.0</commons-io.version>
<commons-collections4.version>4.4</commons-collections4.version>
</properties>

<dependencies>
Expand All @@ -92,6 +94,14 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<!-- print meaningful SQL statements that were generated by any data access technology -->
<dependency>
<groupId>com.github.gavlyukovskiy</groupId>
<artifactId>datasource-proxy-spring-boot-starter</artifactId>
<version>${datasource-proxy-sbs.version}</version>

</dependency>
<!-- End - Database, ORM, and validation dependencies -->

<!-- Start - Web, REST, and their OpenAPI dependencies -->
Expand Down Expand Up @@ -185,14 +195,45 @@
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>${opencsv.version}</version>
<exclusions>
<!--
To fix 78f40514-81ff-403b-9960-98145caab06f
https://advisory.checkmarx.net/advisory/vulnerability/Cx78f40514-81ff/
-->
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>${commons-collections4.version}</version>
</dependency>
<!-- The Commons FileUpload package makes it easy to add robust, high-performance,
file upload capability to your servlets and web applications. -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
<exclusions>
<!--
To fix CVE-2021-29425
https://advisory.checkmarx.net/advisory/vulnerability/CVE-2021-29425/
-->
<exclusion>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>

<!-- Add hipster-core instead of hipster-all for basic functionality. -->
Expand Down Expand Up @@ -250,7 +291,6 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<release>${java.version}</release>
<compilerArgs>--enable-preview</compilerArgs>
Expand Down Expand Up @@ -299,14 +339,6 @@
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
Expand All @@ -317,14 +349,5 @@
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>

</project>
15 changes: 5 additions & 10 deletions src/main/java/org/siriusxi/htec/fa/FlightAdvisorApplication.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.siriusxi.htec.fa;

import lombok.extern.log4j.Log4j2;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;
import org.springframework.context.annotation.Bean;

/**
* Starting point of Flight Advisor Application.
Expand All @@ -14,19 +13,15 @@
* @version 1.0
*/
@SpringBootApplication
@Log4j2
public class FlightAdvisorApplication {

public static void main(String[] args) {
SpringApplication.run(FlightAdvisorApplication.class, args);
}

@Component
@Log4j2
static class AppStartupRunner implements ApplicationRunner {

@Override
public void run(ApplicationArguments args) {
log.info("Congratulations, Flight Advisor Application is Up & Running :) ");
}
@Bean
public ApplicationRunner atStartup(){
return args -> log.info("Flight Advisor Application is Up & Running... ");
}
}
6 changes: 3 additions & 3 deletions src/main/java/org/siriusxi/htec/fa/api/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
*
* @author Mohamed Taman
* @version 1.0
* <p>
* FIXME: add refresh token method, change password.
*/

// TODO: add refresh token method, change password.
@Log4j2
@Tag(name = "Authentication",
description = "A set of public APIs, for managing user authentication, and the registration.")
Expand Down Expand Up @@ -84,7 +84,7 @@ public ResponseEntity<UserView> authenticate(@RequestBody @Valid AuthRequest req
@PostMapping(value = "register")
public UserView register(@RequestBody @Valid CreateUserRequest userRequest) {

log.debug("User information to be created: {}", userRequest);
log.debug("User to be created: {}", userRequest);
return userService.create(userRequest);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/siriusxi/htec/fa/api/CountryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
*
* @author Mohamed Taman
* @version 1.0
* <p>
* FIXME: Swagger documentation
*/

// TODO: Add Swagger documentation
@Log4j2
@Tag(name = "Country Management",
description = "A set of authorized APIs, for getting and managing system countries.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import javax.annotation.security.RolesAllowed;
import java.io.*;
import java.nio.file.Files;
import java.util.List;

import static org.springframework.http.HttpStatus.*;
Expand All @@ -42,9 +43,9 @@
*
* @author Mohamed Taman
* @version 1.0
* <p>
* TODO: Improve performance of the file processing.
*/

// TODO: Improve performance of the file processing.
@Log4j2
@Tag(name = "Files Upload Management",
description = """
Expand Down Expand Up @@ -130,7 +131,7 @@ public ResponseEntity<String> uploadAirports(@Parameter(name = "file", required
}
}

return new ResponseEntity<>("File uploaded successfully.", OK);
return new ResponseEntity<>("Airports file uploaded successfully.", OK);
}

@Operation(summary = "Upload file that contains flights routes.",
Expand Down Expand Up @@ -192,7 +193,7 @@ else if (airportRepository.count() == 0) {
}
}

return new ResponseEntity<>("File uploaded successfully.", OK);
return new ResponseEntity<>("Routes file uploaded successfully.", OK);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AirportDto {
@CsvBindByPosition(position = 3)
private String country;

@PreAssignmentProcessor(processor = ConvertUnwantedStringsToDefault.class, paramString = "")
@PreAssignmentProcessor(processor = ConvertUnwantedStringsToDefault.class)
@CsvBindByPosition(position = 4)
private String iata;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ConvertUnwantedStringsToDefault implements StringProcessor {

@Override
public String processString(String value) {
if (value == null || value.trim().isEmpty() ||
if (value == null || value.isBlank() ||
value.equalsIgnoreCase("\\N") ||
value.equalsIgnoreCase("N")) {
return defaultValue;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/siriusxi/htec/fa/domain/model/Airport.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;
import java.util.Objects;

import static javax.persistence.EnumType.STRING;
import static javax.persistence.FetchType.LAZY;

/**
Expand Down Expand Up @@ -78,6 +79,7 @@ public Airport(Integer airportId) {
private Float timezone;

@NonNull
@Enumerated(STRING)
@Basic(optional = false)
@Column(nullable = false)
private Dst dst;
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/siriusxi/htec/fa/domain/model/City.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
@RequiredArgsConstructor
public class City implements Serializable {

public City(Integer id) {
this.id = id;
}

public City(String name, String description, Country country) {
this(name, country);
this.description = description;
}

@Serial
private static final long serialVersionUID = 1322727266984495327L;

Expand Down Expand Up @@ -66,6 +57,15 @@ public City(String name, String description, Country country) {
@ToString.Exclude
private Country country;

public City(Integer id) {
this.id = id;
}

public City(String name, String description, Country country) {
this(name, country);
this.description = description;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/siriusxi/htec/fa/domain/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @version 1.0
*/
@Entity
@Table(
@Table( name ="users",
catalog = "FLIGHTDB",
schema = "PUBLIC",
uniqueConstraints = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface AirportRepository extends CrudRepository<Airport, Integer> {

@Cacheable
@Override
Optional<Airport> findById(Integer integer);
Optional<Airport> findById(Integer id);

@Query("""
SELECT a FROM Airport a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface CityRepository extends CrudRepository<City, Integer> {
Optional<City> findByCountryAndNameIgnoreCaseIsLike(Country country, String name);

/**
* Return the city if exist, else save and return it.
* Return the city if existed, else save and return it.
*
* @param name of the country.
* @param description of the city
Expand All @@ -36,7 +36,7 @@ default City findOrSaveBy(Country country, String name) {


/**
* Search cities by name, it is case insensitive search.
* Search cities by name, it is case-insensitive search.
*
* @param name to search city by.
* @return list of found cities, or empty list if not found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;
import java.util.Set;

Expand All @@ -31,7 +32,7 @@ WHERE routePK IN (:routePKs)
""")
double getTripCost(Iterable<RoutePK> routePKs);

List<Route> findAllByRoutePKIn(Iterable<RoutePK> routePKs);
List<Route> findAllByRoutePKIn(Collection<RoutePK> routePK);

@CacheEvict(key = "#p0.routePK.source + #p0.routePK.destination")
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public List<CityView> searchCities(SearchCityRequest request, int cLimit) {
.findByCity(city, PageRequest.of(0, cLimit)));
cities.add(city);
}

else
cities = cityRepository.findByNameIgnoreCaseIsLike(searchWord);

Expand Down
Loading

0 comments on commit 3c80595

Please sign in to comment.