Skip to content

Commit

Permalink
Merge branch 'release/v4'
Browse files Browse the repository at this point in the history
  • Loading branch information
stzanakis committed Apr 19, 2021
2 parents ac87a3b + fcf5d44 commit 27caa7a
Show file tree
Hide file tree
Showing 205 changed files with 9,476 additions and 3,714 deletions.
9 changes: 1 addition & 8 deletions 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>3</version>
<version>4</version>
</parent>
<artifactId>metis-authentication-common</artifactId>

Expand All @@ -19,11 +19,6 @@
<artifactId>metis-common-zoho</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>eu.europeana.metis</groupId>
<artifactId>metis-common-network</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
Expand All @@ -41,12 +36,10 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eu.europeana.metis.authentication.utils;

import static eu.europeana.metis.network.SonarqubeNullcheckAvoidanceUtils.performAction;
import static eu.europeana.metis.network.SonarqubeNullcheckAvoidanceUtils.performThrowingFunction;
import static eu.europeana.metis.utils.SonarqubeNullcheckAvoidanceUtils.performAction;
import static eu.europeana.metis.utils.SonarqubeNullcheckAvoidanceUtils.performThrowingFunction;

import com.zoho.oauth.client.ZohoPersistenceHandler;
import com.zoho.oauth.common.ZohoOAuthException;
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>3</version>
<version>4</version>
</parent>
<artifactId>metis-authentication-rest-client</artifactId>

Expand Down Expand Up @@ -42,13 +42,10 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${version.mockito.core}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
6 changes: 1 addition & 5 deletions 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>3</version>
<version>4</version>
</parent>
<artifactId>metis-authentication-rest</artifactId>
<packaging>war</packaging>
Expand Down Expand Up @@ -67,13 +67,10 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${version.mockito.core}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
Expand All @@ -89,7 +86,6 @@
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>${version.json.path}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package eu.europeana.metis.authentication.rest.config;

import static eu.europeana.metis.network.SonarqubeNullcheckAvoidanceUtils.performAction;
import static eu.europeana.metis.utils.SonarqubeNullcheckAvoidanceUtils.performAction;

import com.zoho.oauth.common.ZohoOAuthException;
import eu.europeana.metis.authentication.dao.PsqlMetisUserDao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://exampl.location.of.psql.server:port/database</property>
<!-- ssl=true enables ssl, sslfactory=org.postgresql.ssl.DefaultJavaSSLFactory uses the truststore to check for certificates, that should be used in this application, sslmode=verify-ca performs verification of the certificate as well.
Use ssl from localhost too with the corresponding custom truststore-->
<property name="hibernate.connection.url">jdbc:postgresql://exampl.location.of.psql.server:port/database?ssl=true&amp;sslfactory=org.postgresql.ssl.DefaultJavaSSLFactory&amp;sslmode=verify-ca</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL82Dialect</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">password</property>
Expand Down
6 changes: 1 addition & 5 deletions 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>3</version>
<version>4</version>
</parent>
<artifactId>metis-authentication-service</artifactId>

Expand All @@ -27,18 +27,14 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${version.mockito.core}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eu.europeana.metis.authentication.dao;

import static eu.europeana.metis.network.SonarqubeNullcheckAvoidanceUtils.performAction;
import static eu.europeana.metis.network.SonarqubeNullcheckAvoidanceUtils.performFunction;
import static eu.europeana.metis.utils.SonarqubeNullcheckAvoidanceUtils.performAction;
import static eu.europeana.metis.utils.SonarqubeNullcheckAvoidanceUtils.performFunction;

import eu.europeana.metis.authentication.user.AccountRole;
import eu.europeana.metis.authentication.user.MetisUserAccessToken;
Expand Down
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>3</version>
<version>4</version>
</parent>
<artifactId>metis-authentication</artifactId>
<packaging>pom</packaging>
Expand Down
12 changes: 6 additions & 6 deletions metis-common/metis-common-mongo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
<parent>
<artifactId>metis-common</artifactId>
<groupId>eu.europeana.metis</groupId>
<version>3</version>
<version>4</version>
</parent>
<artifactId>metis-common-mongo</artifactId>

<dependencies>
<dependency>
<groupId>eu.europeana.metis</groupId>
<artifactId>metis-common-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>eu.europeana.metis</groupId>
<artifactId>metis-common-network</artifactId>
Expand All @@ -19,11 +24,6 @@
<groupId>eu.europeana.corelib</groupId>
<artifactId>corelib-storage</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>${version.mongodb.driver.core}</version>
</dependency>
<dependency>
<groupId>dev.morphia.morphia</groupId>
<artifactId>morphia-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
* Whether writes should be retried if they fail due to a network error is defaulted to
* {@value #DEFAULT_RETRY_WRITES}.
* </li>
* <li>
* The application name (used among other things for server logging) is defaulted to
* {@value #DEFAULT_APPLICATION_NAME}.
* </li>
* </ul>
* These defaults can be overridden or additional (default) settings can be set upon
* construction. To facilitate this, this class offers access to the default settings by means of
Expand All @@ -43,6 +47,7 @@ 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 boolean DEFAULT_RETRY_WRITES = false;
private static final String DEFAULT_APPLICATION_NAME = "Europeana Application Suite";

private final MongoClientCreator<E> creator;
private final String authenticationDatabase;
Expand Down Expand Up @@ -74,14 +79,15 @@ public MongoClientProvider(String connectionUri, Function<String, E> exceptionCr
}

/**
* Constructor from a {@link MongoProperties} object. The caller can provide settings that will
* override the default settings (i.e. the default settings will not be used).
* 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 calling
* 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 incorporate the default settings by using an client settings builder obtained
* from {@link #getDefaultClientSettingsBuilder()}. {@link #createMongoClient()}.
* 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)
Expand All @@ -101,6 +107,8 @@ public MongoClientProvider(MongoProperties<E> properties, Builder clientSettings
if (mongoCredential != null) {
clientSettingsBuilder.credential(mongoCredential);
}
Optional.ofNullable(properties.getApplicationName()).filter(name -> !name.isBlank())
.ifPresent(clientSettingsBuilder::applicationName);
final MongoClientSettings mongoClientSettings = clientSettingsBuilder.build();

this.creator = () -> MongoClients.create(mongoClientSettings);
Expand All @@ -126,9 +134,11 @@ public MongoClientProvider(MongoProperties<E> properties) throws E {
public static 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);
.retryWrites(DEFAULT_RETRY_WRITES)
.applyToConnectionPoolSettings(builder -> builder
.maxConnectionIdleTime(DEFAULT_MAX_CONNECTION_IDLE_MILLIS, TimeUnit.MILLISECONDS))
.readPreference(DEFAULT_READ_PREFERENCE)
.applicationName(DEFAULT_APPLICATION_NAME);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class MongoProperties<E extends Exception> {
private MongoCredential mongoCredentials;
private boolean mongoEnableSsl;
private ReadPreferenceValue readPreferenceValue;
private String applicationName;

/**
* Constructor.
Expand All @@ -39,7 +40,7 @@ public MongoProperties(Function<String, E> exceptionCreator) {
}

/**
* Setter for all properties.
* Setter for multiple properties.
*
* @param hosts The hosts. This cannot be null or empty.
* @param ports The ports. This cannot be null or empty. Must contain either the same number of
Expand All @@ -66,7 +67,7 @@ public void setAllProperties(String[] hosts, int[] ports, String authenticationD
}

/**
* Setter for all properties.
* Setter for multiple properties.
*
* @param hosts The hosts. This cannot be null or empty.
* @param ports The ports. This cannot be null or empty. Must contain either the same number of
Expand All @@ -79,12 +80,37 @@ public void setAllProperties(String[] hosts, int[] ports, String authenticationD
* @param readPreferenceValue The read preference. Can be null, where then the default applies
* @throws E In case either of the arrays is null, or their lengths don't match.
*/
@Deprecated
public void setAllProperties(String[] hosts, int[] ports, String authenticationDatabase,
String username, String password, boolean enableSsl, ReadPreferenceValue readPreferenceValue)
throws E {
setAllProperties(hosts, ports, authenticationDatabase, username, password, enableSsl,
readPreferenceValue, null);
}

/**
* Setter for multiple properties.
*
* @param hosts The hosts. This cannot be null or empty.
* @param ports The ports. This cannot be null or empty. Must contain either the same number of
* elements as the hosts array, or exactly 1 element (which will then apply to all hosts).
* @param authenticationDatabase The name of the authentication database. Can be null, in which
* case no authentication takes place.
* @param username The username. Can be null, in which case no authentication takes place.
* @param password The password. Can be null, in which case no authentication takes place.
* @param enableSsl Whether to enable SSL connections.
* @param readPreferenceValue The read preference. Can be null, where then the default applies
* @param applicationName The name of the application. Can be null, where then the default applies
* @throws E In case either of the arrays is null, or their lengths don't match.
*/
public void setAllProperties(String[] hosts, int[] ports, String authenticationDatabase,
String username, String password, boolean enableSsl, ReadPreferenceValue readPreferenceValue,
String applicationName)
throws E {
setAllProperties(hosts, ports, authenticationDatabase, username, password);
this.mongoEnableSsl = enableSsl;
setReadPreferenceValue(readPreferenceValue);
setApplicationName(applicationName);
}

/**
Expand Down Expand Up @@ -137,14 +163,24 @@ public void setMongoEnableSsl() {
}

/**
* Set the read preference value. Can be null, where then the default applies
* Set the read preference value. Can be null, in which case the default applies.
*
* @param readPreferenceValue the read preference value (null for the default).
*/
public void setReadPreferenceValue(ReadPreferenceValue readPreferenceValue) {
this.readPreferenceValue = readPreferenceValue;
}

/**
* Set the application name. Can be null, in which case a default generic application name is
* to be used.
*
* @param applicationName The application name, or null for the default.
*/
public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}

private <T> T nonNull(T value, String fieldName) throws E {
if (value == null) {
throw exceptionCreator.apply(String.format("Value '%s' cannot be null.", fieldName));
Expand Down Expand Up @@ -199,14 +235,23 @@ public boolean mongoEnableSsl() {
}

/**
* This method returns the value of the read preference (or null for the default behavior)
* This method returns the value of the read preference (or null for the default behavior).
*
* @return the read preference set
* @return The read preference.
*/
public ReadPreferenceValue getReadPreferenceValue() {
return readPreferenceValue;
}

/**
* This method returns the value of the application name (or null for the default).
*
* @return The application name.
*/
public String getApplicationName() {
return applicationName;
}

/**
* Enum for read preference values
*/
Expand Down
Loading

0 comments on commit 27caa7a

Please sign in to comment.