Skip to content

Commit

Permalink
Merge branch 'release/v7'
Browse files Browse the repository at this point in the history
  • Loading branch information
jeortizquan committed Jul 8, 2022
2 parents fe93bcc + c789501 commit 6107430
Show file tree
Hide file tree
Showing 320 changed files with 10,643 additions and 18,407 deletions.
36 changes: 31 additions & 5 deletions CONTRIBUTING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,40 @@ If there is any doubt on fixing the merge conflicts while merging, the implement
worked on the relevant changes that were introduced on the destination branch.

The merge can be performed on the github pull request page or manually(especially for conflicts).
To do this manually, checkout the destination branch(usually `develop`) and execute the merge command with the `--no-ff`
parameter:
To do this manually, checkout the destination branch(usually `develop`).
We prefer squash merging or alternatively non fast forward merging.

- A squash merge can be performed with the `--squash` parameter:

`git merge --squash <branch_to_be_merge>`

To complete the squash merge, a commit has to also be performed if done locally.
The commit should be formatted as the following template(replicating github squashed commits):
```
<branch_type>/<ticket_number> <clear_description_of_the_issue_being_implemented> (#<pull_request_number>)
(optionally as description)
* List of all commit messages from the pull requst
```
Example message:
```
Debt/met 4250 refactor code to remove mock maker inline (#508)
* MET-4250 Update NetworkUtil
* MET-4250 Update RdfConversionUtils
* MET-4250 Javadocs and cleanup
* MET-4250 Remove mockito inline from root pom
```


- A non fast forward merge can be performed with the `--no-ff` parameter:

`git merge --no-ff <branch_to_be_merge>`

The merger should check that the local branch is building before and after merging. If there were merge conflicts that were
resolved during the merge, then a local deployment should be triggered and verified. If the build succeeds the destination branch
can be pushed to the remote repository and the pull request will be resolved.
The merger should check that the local branch is building before and after merging.
If there were merge conflicts that were resolved during the merge, then a local deployment should be triggered and verified.
If the build succeeds the destination branch can be pushed to the remote repository and the pull request will be resolved.

The reviewer can now move the ticket ahead in the board and re-assign it to the implementor.

Expand Down
2 changes: 1 addition & 1 deletion metis-authentication/metis-authentication-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>metis-authentication</artifactId>
<groupId>eu.europeana.metis</groupId>
<version>6</version>
<version>7</version>
</parent>
<artifactId>metis-authentication-common</artifactId>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>metis-authentication</artifactId>
<groupId>eu.europeana.metis</groupId>
<version>6</version>
<version>7</version>
</parent>
<artifactId>metis-authentication-rest-client</artifactId>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TestAuthenticationClient {

static {
try {
portForWireMock = NetworkUtil.getAvailableLocalPort();
portForWireMock = new NetworkUtil().getAvailableLocalPort();
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
2 changes: 1 addition & 1 deletion metis-authentication/metis-authentication-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>metis-authentication</artifactId>
<groupId>eu.europeana.metis</groupId>
<version>6</version>
<version>7</version>
</parent>
<artifactId>metis-authentication-rest</artifactId>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion metis-authentication/metis-authentication-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>metis-authentication</artifactId>
<groupId>eu.europeana.metis</groupId>
<version>6</version>
<version>7</version>
</parent>
<artifactId>metis-authentication-service</artifactId>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import eu.europeana.metis.authentication.dao.PsqlMetisUserDao;
import eu.europeana.metis.authentication.user.AccountRole;
import eu.europeana.metis.authentication.user.Credentials;
import eu.europeana.metis.authentication.user.MetisUserView;
import eu.europeana.metis.authentication.user.MetisUserAccessToken;
import eu.europeana.metis.authentication.user.MetisUser;
import eu.europeana.metis.authentication.user.MetisUserAccessToken;
import eu.europeana.metis.authentication.user.MetisUserView;
import eu.europeana.metis.authentication.utils.ZohoMetisUserUtils;
import eu.europeana.metis.exception.BadContentException;
import eu.europeana.metis.exception.GenericMetisException;
Expand Down Expand Up @@ -36,8 +36,7 @@
import org.springframework.stereotype.Service;

/**
* Service that handles all related operations to authentication including communication between a
* psql database and Zoho.
* Service that handles all related operations to authentication including communication between a psql database and Zoho.
*
* @author Simon Tzanakis (Simon.Tzanakis@europeana.eu)
* @since 2018-12-05
Expand All @@ -47,10 +46,10 @@ public class AuthenticationService {

private static final int LOG_ROUNDS = 13;
private static final int CREDENTIAL_FIELDS_NUMBER = 2;
@SuppressWarnings("java:S6418") // It is not an actual token
private static final String ACCESS_TOKEN_CHARACTER_BASKET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
private static final int ACCESS_TOKEN_LENGTH = 32;
private static final Pattern TOKEN_MATCHING_PATTERN = Pattern
.compile("^[" + ACCESS_TOKEN_CHARACTER_BASKET + "]*$");
private static final Pattern TOKEN_MATCHING_PATTERN = Pattern.compile("^[" + ACCESS_TOKEN_CHARACTER_BASKET + "]*$");
public static final Supplier<BadContentException> COULD_NOT_CONVERT_EXCEPTION_SUPPLIER = () -> new BadContentException(
"Could not convert internal user");
private final PsqlMetisUserDao psqlMetisUserDao;
Expand Down Expand Up @@ -243,7 +242,7 @@ public String validateAuthorizationHeaderWithAccessToken(String authorization)
}
//Check that the token is of valid structure
if (accessToken.length() != ACCESS_TOKEN_LENGTH || !TOKEN_MATCHING_PATTERN.matcher(accessToken)
.matches()) {
.matches()) {
throw new UserUnauthorizedException("Access token invalid");
}
return accessToken;
Expand Down Expand Up @@ -368,7 +367,8 @@ public boolean hasPermissionToRequestUserUpdate(String accessToken, String userE
}
MetisUser storedMetisUser = authenticateUserInternal(accessToken);
return storedMetisUser.getAccountRole() == AccountRole.METIS_ADMIN || storedMetisUser.getEmail()
.equals(storedMetisUserToUpdate.getEmail());
.equals(
storedMetisUserToUpdate.getEmail());
}

String generateAccessToken() {
Expand Down Expand Up @@ -480,14 +480,14 @@ public List<MetisUserView> getAllUsers() {
return convert(psqlMetisUserDao.getAllMetisUsers());
}

private static MetisUserView convert(MetisUser record) throws BadContentException {
return Optional.ofNullable(record).map(MetisUserView::new)
.orElseThrow(COULD_NOT_CONVERT_EXCEPTION_SUPPLIER);
private static MetisUserView convert(MetisUser metisUser) throws BadContentException {
return Optional.ofNullable(metisUser).map(MetisUserView::new)
.orElseThrow(COULD_NOT_CONVERT_EXCEPTION_SUPPLIER);
}

private static List<MetisUserView> convert(List<MetisUser> records) {
return Optional.ofNullable(records).stream().flatMap(Collection::stream).map(MetisUserView::new)
.collect(Collectors.toList());
.collect(Collectors.toList());
}
}

2 changes: 1 addition & 1 deletion metis-authentication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>metis-framework</artifactId>
<groupId>eu.europeana.metis</groupId>
<version>6</version>
<version>7</version>
</parent>
<artifactId>metis-authentication</artifactId>
<packaging>pom</packaging>
Expand Down
3 changes: 1 addition & 2 deletions metis-common/metis-common-mongo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>metis-common</artifactId>
<groupId>eu.europeana.metis</groupId>
<version>6</version>
<version>7</version>
</parent>
<artifactId>metis-common-mongo</artifactId>

Expand All @@ -28,7 +28,6 @@
<dependency>
<groupId>eu.europeana.metis</groupId>
<artifactId>metis-schema</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.morphia.morphia</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.connection.ConnectionPoolSettings;
import eu.europeana.metis.mongo.connection.MongoProperties.ReadPreferenceValue;
import java.util.List;
import java.util.Optional;
Expand All @@ -17,8 +18,7 @@
import java.util.function.Supplier;

/**
* This class can set up and provide a Mongo client given the Mongo properties. It applies the
* following default values:
* This class can set up and provide a Mongo client given the Mongo properties. It applies the following default values:
* <ul>
* <li>
* The read preference for the connection is defaulted to {@link ReadPreference#secondaryPreferred()}.
Expand Down Expand Up @@ -46,15 +46,16 @@ public class MongoClientProvider<E extends Exception> {

private static final ReadPreference DEFAULT_READ_PREFERENCE = ReadPreference.secondaryPreferred();
private static final int DEFAULT_MAX_CONNECTION_IDLE_MILLIS = 30_000;
private static final int DEFAULT_MAX_CONNECTIONS = 20;
private static final boolean DEFAULT_RETRY_WRITES = false;
private static final String DEFAULT_APPLICATION_NAME = "Europeana Application Suite";

private final MongoClientCreator<E> creator;
private final String authenticationDatabase;

/**
* Constructor from a connection URI string (see the documentation of {@link MongoClientURI} for
* the details). The connection URL can provide settings that will override the default settings.
* Constructor from a connection URI string (see the documentation of {@link MongoClientURI} for the details). The connection
* URL can provide settings that will override the default settings.
*
* @param connectionUri The connection URI as a string
* @param exceptionCreator How to report exceptions.
Expand All @@ -79,28 +80,27 @@ public MongoClientProvider(String connectionUri, Function<String, E> exceptionCr
}

/**
* Constructor from a {@link MongoProperties} object. The caller needs to provide settings that
* will be used instead of the default settings.
* Constructor from a {@link MongoProperties} object. The caller needs to provide settings that will be used instead of the
* default settings.
*
* @param properties The properties of the Mongo connection. Note that if the passed properties
* object is changed after calling this method, those changes will not be reflected when creating
* mongo clients.
* @param clientSettingsBuilder The settings to be applied. The default settings will not be used.
* The caller can however choose to incorporate the default settings as needed by using a client
* settings builder obtained from {@link #getDefaultClientSettingsBuilder()} as input.
* @param properties The properties of the Mongo connection. Note that if the passed properties object is changed after calling
* this method, those changes will not be reflected when creating mongo clients.
* @param clientSettingsBuilder The settings to be applied. The default settings will not be used. The caller can however choose
* to incorporate the default settings as needed by using a client settings builder obtained from {@link
* #getDefaultClientSettingsBuilder()} as input.
* @throws E In case the properties are wrong
*/
public MongoClientProvider(MongoProperties<E> properties, Builder clientSettingsBuilder)
throws E {
final ReadPreference readPreference = Optional.ofNullable(properties.getReadPreferenceValue())
.map(ReadPreferenceValue::getReadPreferenceSupplier).map(Supplier::get)
.orElse(DEFAULT_READ_PREFERENCE);
.map(ReadPreferenceValue::getReadPreferenceSupplier).map(Supplier::get)
.orElse(DEFAULT_READ_PREFERENCE);
clientSettingsBuilder.readPreference(readPreference);

final List<ServerAddress> mongoHosts = properties.getMongoHosts();
final MongoCredential mongoCredential = properties.getMongoCredentials();
this.authenticationDatabase = Optional.ofNullable(mongoCredential)
.map(MongoCredential::getSource).orElse(null);
.map(MongoCredential::getSource).orElse(null);
clientSettingsBuilder
.applyToSslSettings(builder -> builder.enabled(properties.mongoEnableSsl()));
clientSettingsBuilder.applyToClusterSettings(builder -> builder.hosts(mongoHosts));
Expand All @@ -109,6 +109,9 @@ public MongoClientProvider(MongoProperties<E> properties, Builder clientSettings
}
Optional.ofNullable(properties.getApplicationName()).filter(name -> !name.isBlank())
.ifPresent(clientSettingsBuilder::applicationName);

clientSettingsBuilder.applyToConnectionPoolSettings(
builder -> builder.applySettings(createConnectionPoolSettings(properties.getMaxConnectionPoolSize())));
final MongoClientSettings mongoClientSettings = clientSettingsBuilder.build();

this.creator = () -> MongoClients.create(mongoClientSettings);
Expand All @@ -117,9 +120,8 @@ public MongoClientProvider(MongoProperties<E> properties, Builder clientSettings
/**
* Constructor from a {@link MongoProperties} object, using the default settings.
*
* @param properties The properties of the Mongo connection. Note that if the passed properties
* object is changed after calling this method, those changes will not be reflected when calling
* {@link #createMongoClient()}.
* @param properties The properties of the Mongo connection. Note that if the passed properties object is changed after calling
* this method, those changes will not be reflected when calling {@link #createMongoClient()}.
* @throws E In case the properties are wrong
*/
public MongoClientProvider(MongoProperties<E> properties) throws E {
Expand All @@ -131,19 +133,17 @@ public MongoClientProvider(MongoProperties<E> properties) throws E {
*
* @return A new instance of {@link Builder} with the default settings.
*/
public static Builder getDefaultClientSettingsBuilder() {
public static MongoClientSettings.Builder getDefaultClientSettingsBuilder() {
return MongoClientSettings.builder()
// TODO: 7/16/20 Remove default retry writes after upgrade to mongo server version 4.2
.retryWrites(DEFAULT_RETRY_WRITES)
.applyToConnectionPoolSettings(builder -> builder
.maxConnectionIdleTime(DEFAULT_MAX_CONNECTION_IDLE_MILLIS, TimeUnit.MILLISECONDS))
.readPreference(DEFAULT_READ_PREFERENCE)
.applicationName(DEFAULT_APPLICATION_NAME);
// TODO: 7/16/20 Remove default retry writes after upgrade to mongo server version 4.2
.retryWrites(DEFAULT_RETRY_WRITES)
.applyToConnectionPoolSettings(builder -> builder.applySettings(getDefaultConnectionPoolSettings()))
.readPreference(DEFAULT_READ_PREFERENCE)
.applicationName(DEFAULT_APPLICATION_NAME);
}

/**
* Convenience method for {@link #MongoClientProvider(String, Function)}. See that
* constructor for the details.
* Convenience method for {@link #MongoClientProvider(String, Function)}. See that constructor for the details.
*
* @param connectionUri The connection URI.
* @return An instance.
Expand All @@ -153,8 +153,7 @@ public static MongoClientProvider<IllegalArgumentException> create(String connec
}

/**
* Convenience method for {@link #MongoClientProvider(String, Function)}. See that
* constructor for the details.
* Convenience method for {@link #MongoClientProvider(String, Function)}. See that constructor for the details.
*
* @param connectionUri The connection URI.
* @return A supplier for {@link MongoClient} instances based on this class.
Expand All @@ -164,8 +163,17 @@ public static Supplier<MongoClient> createAsSupplier(String connectionUri) {
}

/**
* Returns the authentication database for mongo connections that are provided. Can be null
* (signifying that the default is to be used or that no authentication is specified).
* Get the default connection pool settings
*
* @return the default connection pool settings
*/
private static ConnectionPoolSettings getDefaultConnectionPoolSettings() {
return createConnectionPoolSettings(null);
}

/**
* Returns the authentication database for mongo connections that are provided. Can be null (signifying that the default is to
* be used or that no authentication is specified).
*
* @return The authentication database.
*/
Expand All @@ -174,9 +182,8 @@ public final String getAuthenticationDatabase() {
}

/**
* Creates a Mongo client. This method can be called multiple times and will create and return a
* different client each time. The calling code is responsible for properly closing the created
* client.
* Creates a Mongo client. This method can be called multiple times and will create and return a different client each time. The
* calling code is responsible for properly closing the created client.
*
* @return A mongo client.
* @throws E In case there is a problem with creating the client.
Expand All @@ -185,6 +192,23 @@ public final MongoClient createMongoClient() throws E {
return creator.createMongoClient();
}

/**
* Create a connection pool settings object. Settings that are null will be set to default settings.
*
* @param maxPoolSize the maximum connection pool size
* @return the connection pool settings
*/
static ConnectionPoolSettings createConnectionPoolSettings(Integer maxPoolSize) {
final ConnectionPoolSettings.Builder builder = ConnectionPoolSettings.builder();
builder.maxConnectionIdleTime(DEFAULT_MAX_CONNECTION_IDLE_MILLIS, TimeUnit.MILLISECONDS);
if (maxPoolSize != null && maxPoolSize > 0) {
builder.maxSize(maxPoolSize);
} else {
builder.maxSize(DEFAULT_MAX_CONNECTIONS);
}
return builder.build();
}

private interface MongoClientCreator<E extends Exception> {

MongoClient createMongoClient() throws E;
Expand Down
Loading

0 comments on commit 6107430

Please sign in to comment.