Skip to content

Commit

Permalink
Merge pull request #697 from Onlineberatung/TSYSTEMS-140-upgrade-spri…
Browse files Browse the repository at this point in the history
…ng-boot-to-2.6.X

Tsystems 140 upgrade spring boot to 2.6.x
  • Loading branch information
tkuzynow authored May 22, 2024
2 parents f3cc434 + 6294ace commit d14e1dd
Show file tree
Hide file tree
Showing 220 changed files with 3,765 additions and 3,446 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dockerImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
push_to_registry:
strategy:
matrix:
registry: [ "docker.pkg.github.com", "ghcr.io" ]
registry: [ "ghcr.io" ]
needs: [ test ]
name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest
Expand Down
85 changes: 67 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
<version>2.6.15</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

Expand All @@ -41,14 +41,14 @@
<commons-validator.version>1.7</commons-validator.version>
<liquibase-maven-plugin.version>4.8.0</liquibase-maven-plugin.version>
<javax.ws.rs-api.version>2.1.1</javax.ws.rs-api.version>
<spring-boot-starter-web.version>2.6.6</spring-boot-starter-web.version>
<spring-boot-starter-web.version>2.6.15</spring-boot-starter-web.version>
<spring-security-core.version>5.7.5</spring-security-core.version>
<spring-beans.version>5.2.20.RELEASE</spring-beans.version>
<spring-webmvc.version>5.2.20.RELEASE</spring-webmvc.version>
<spring-core.version>5.2.20.RELEASE</spring-core.version>
<spring-beans.version>5.3.35</spring-beans.version>
<spring-webmvc.version>5.3.35</spring-webmvc.version>
<spring-core.version>5.3.35</spring-core.version>
<json-smart.version>2.4.7</json-smart.version>
<springfox-swagger-ui.version>2.10.0</springfox-swagger-ui.version>
<spring-context-support.version>5.3.23</spring-context-support.version>
<spring-context-support.version>5.3.35</spring-context-support.version>
<ehcache.version>2.10.9.2</ehcache.version>
<testcontainers.version>1.17.6</testcontainers.version>
</properties>
Expand All @@ -64,6 +64,15 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.35</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down Expand Up @@ -146,6 +155,10 @@
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
Expand All @@ -159,14 +172,8 @@
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger-ui.version}</version>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>

<!-- Keycloak dependencies -->
Expand Down Expand Up @@ -349,7 +356,33 @@
<groupId>org.powermock</groupId>
<scope>test</scope>
<version>${powermock.version}</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.12.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy -->
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.14.15</version>
</dependency>


<dependency>
<artifactId>powermock-api-mockito2</artifactId>
<groupId>org.powermock</groupId>
Expand Down Expand Up @@ -414,11 +447,11 @@

<!-- MongoDB dependencies -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.11</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>


<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
Expand Down Expand Up @@ -457,7 +490,23 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.30.0</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-spring</artifactId>
<version>5.9.0</version>
</dependency>
</dependencies>
</plugin>
<!--
Add generated sources as source directory
-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestClientResponseException;
Expand Down Expand Up @@ -617,7 +617,7 @@ private boolean hasEmailAddressChanged(UserResource userResource, String email)
if (userRepresentation != null && userRepresentation.getEmail() != null) {
return !userRepresentation.getEmail().equals(email);
} else {
return !StringUtils.isEmpty(email);
return !ObjectUtils.isEmpty(email);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import lombok.Data;
import org.hibernate.validator.constraints.URL;
import org.keycloak.KeycloakSecurityContext;
import org.keycloak.adapters.KeycloakConfigResolver;
import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.KeycloakBuilder;
Expand Down Expand Up @@ -91,6 +93,15 @@ public Keycloak keycloak() {
.build();
}

/**
* Use the KeycloakSpringBootConfigResolver to be able to save the Keycloak settings in the spring
* application properties.
*/
@Bean
public KeycloakConfigResolver keyCloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
}

@URL private String authServerUrl;

@NotBlank private String realm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatUserNotInitializedException;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
Expand All @@ -16,7 +15,6 @@ public class RocketChatRollbackService {
private final RocketChatService rocketChatService;
private final RocketChatCredentialsProvider rcCredentialsHelper;

@Autowired
public RocketChatRollbackService(
RocketChatService rocketChatService, RocketChatCredentialsProvider rcCredentialsHelper) {
this.rocketChatService = rocketChatService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package de.caritas.cob.userservice.api.adapters.rocketchat;

import static com.mongodb.client.model.Filters.eq;
import static de.caritas.cob.userservice.api.helper.CustomLocalDateTime.nowInUtc;
import static java.util.Arrays.asList;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import static org.apache.commons.lang3.ArrayUtils.isNotEmpty;

import com.google.common.collect.Lists;
import com.mongodb.DBObject;
import com.mongodb.QueryBuilder;
import com.mongodb.client.MongoClient;
import com.mongodb.client.model.Filters;
import de.caritas.cob.userservice.api.adapters.rocketchat.config.RocketChatConfig;
import de.caritas.cob.userservice.api.adapters.rocketchat.dto.StandardResponseDTO;
import de.caritas.cob.userservice.api.adapters.rocketchat.dto.group.GroupAddUserBodyDTO;
Expand Down Expand Up @@ -486,15 +484,18 @@ public String getUserID(String username, String password, boolean firstLogin)
response = this.rcCredentialHelper.loginUser(username, password);
}

var rocketChatCredentialsLocal =
RocketChatCredentials.builder()
.rocketChatUserId(response.getBody().getData().getUserId())
.rocketChatToken(response.getBody().getData().getAuthToken())
.build();

logoutUser(rocketChatCredentialsLocal);

return rocketChatCredentialsLocal.getRocketChatUserId();
LoginResponseDTO body = response.getBody();
if (body != null) {
var rocketChatCredentialsLocal =
RocketChatCredentials.builder()
.rocketChatUserId(body.getData().getUserId())
.rocketChatToken(body.getData().getAuthToken())
.build();
logoutUser(rocketChatCredentialsLocal);
return rocketChatCredentialsLocal.getRocketChatUserId();
} else {
throw new RocketChatLoginException("Could not login user in Rocket.Chat");
}
}

/**
Expand Down Expand Up @@ -769,7 +770,7 @@ public List<GroupMemberDTO> getChatUsers(String chatId) {
mongoClient
.getDatabase(MONGO_DATABASE_NAME)
.getCollection(MONGO_COLLECTION_SUBSCRIPTION)
.find(Filters.eq("rid", chatId));
.find(eq("rid", chatId));

var members = new ArrayList<GroupMemberDTO>();
try (var cursor = subscriptions.iterator()) {
Expand Down Expand Up @@ -1166,35 +1167,21 @@ private void setRoomState(String rcRoomId, boolean readOnly)
public List<GroupDTO> fetchAllInactivePrivateGroupsSinceGivenDate(
LocalDateTime dateTimeSinceInactive) throws RocketChatGetGroupsListAllException {

final var GROUP_RESPONSE_LAST_MESSAGE_TIMESTAMP_FIELD = "lm";
final var GROUP_RESPONSE_GROUP_TYPE_FIELD = "t";
final var GROUP_RESPONSE_GROUP_TYPE_PRIVATE = "p";

DBObject mongoDbQuery =
QueryBuilder.start(GROUP_RESPONSE_LAST_MESSAGE_TIMESTAMP_FIELD)
.lessThan(
QueryBuilder.start("$date")
.is(
dateTimeSinceInactive.format(
DateTimeFormatter.ofPattern(RC_DATE_TIME_PATTERN)))
.get())
.and(
QueryBuilder.start(GROUP_RESPONSE_GROUP_TYPE_FIELD)
.is(GROUP_RESPONSE_GROUP_TYPE_PRIVATE)
.get())
.get();

return getGroupsListAll(mongoDbQuery);
String filter =
String.format(
"{\"lm\": {\"$lt\": {\"$date\": \"%s\"}}, \"$and\": [{\"t\": \"p\"}]}",
dateTimeSinceInactive.format(DateTimeFormatter.ofPattern(RC_DATE_TIME_PATTERN)));
return getGroupsListAll(filter);
}

/**
* Returns a list of all Rocket.Chat groups.
*
* @param mongoDbQuery mongoDB Query as {@link DBObject} created with {@link QueryBuilder}
* @param mongoDbQuery mongoDB Query as {@link String}
* @return a {@link List} of {@link GroupDTO} instances
* @throws RocketChatGetGroupsListAllException when request fails
*/
private List<GroupDTO> getGroupsListAll(DBObject mongoDbQuery)
private List<GroupDTO> getGroupsListAll(String mongoDbQuery)
throws RocketChatGetGroupsListAllException {

try {
Expand All @@ -1210,7 +1197,7 @@ private List<GroupDTO> getGroupsListAll(DBObject mongoDbQuery)
}

private List<GroupDTO> getGroupListAllCombiningPages(
DBObject mongoDbQuery, HttpEntity<GroupAddUserBodyDTO> request)
String mongoDbQuery, HttpEntity<GroupAddUserBodyDTO> request)
throws RocketChatGetGroupsListAllException {
List<GroupDTO> result = Lists.newArrayList();
int currentOffset = 0;
Expand Down Expand Up @@ -1248,12 +1235,12 @@ private boolean isResponseSuccessful(ResponseEntity<GroupsListAllResponseDTO> pa

private ResponseEntity<GroupsListAllResponseDTO>
getGroupsListAllResponseDTOResponseEntityForCurrentOffset(
DBObject mongoDbQuery, HttpEntity<GroupAddUserBodyDTO> request, int currentOffset) {
String mongoDbQuery, HttpEntity<GroupAddUserBodyDTO> request, int currentOffset) {
ResponseEntity<GroupsListAllResponseDTO> response;
var url = getGroupAllPaginatedUrl(currentOffset);
response =
restTemplate.exchange(
url, HttpMethod.GET, request, GroupsListAllResponseDTO.class, mongoDbQuery.toString());
url, HttpMethod.GET, request, GroupsListAllResponseDTO.class, mongoDbQuery);
return response;
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit d14e1dd

Please sign in to comment.