-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Several general improvement including migration
- Loading branch information
1 parent
4887506
commit 7f391cb
Showing
74 changed files
with
2,922 additions
and
854 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<parent> | ||
<artifactId>record-api</artifactId> | ||
<groupId>eu.europeana.api</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>record-api-migration</artifactId> | ||
<description>This is a temporary module to migrate all the data from the DB</description> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.6.0</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<shadedArtifactAttached>false</shadedArtifactAttached> | ||
<transformers> | ||
<transformer> | ||
<mainClass>eu.europeana.api.record.migration.MigrationCommand</mainClass> | ||
</transformer> | ||
<transformer /> | ||
<transformer /> | ||
<transformer> | ||
<addHeader>false</addHeader> | ||
</transformer> | ||
</transformers> | ||
<filters> | ||
<filter> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>**/Log4j2Plugins.dat</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<properties> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<spring.boot.mainclass>eu.europeana.api.record.migration.RunMigration</spring.boot.mainclass> | ||
</properties> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
record-api-migration/src/main/java/eu/europeana/api/record/migration/DataSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package eu.europeana.api.record.migration; | ||
|
||
import com.mongodb.Block; | ||
import com.mongodb.ConnectionString; | ||
import com.mongodb.MongoClientSettings; | ||
import com.mongodb.client.MongoClient; | ||
import com.mongodb.client.MongoClients; | ||
import com.mongodb.connection.ConnectionPoolSettings; | ||
import java.util.concurrent.TimeUnit; | ||
import dev.morphia.Datastore; | ||
import dev.morphia.DatastoreImpl; | ||
import dev.morphia.Morphia; | ||
import dev.morphia.internal.DatastoreHolder; | ||
import dev.morphia.mapping.Mapper; | ||
import dev.morphia.mapping.codec.CodecUtils; | ||
import dev.morphia.mapping.codec.MorphiaCodecProvider; | ||
import eu.europeana.api.config.AppConfigConstants; | ||
import eu.europeana.api.record.db.codec.*; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import org.bson.codecs.configuration.CodecProvider; | ||
import org.bson.codecs.configuration.CodecRegistry; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.context.annotation.PropertySource; | ||
|
||
import static org.bson.codecs.configuration.CodecRegistries.*; | ||
|
||
@Configuration | ||
@PropertySource( | ||
value = {"classpath:record-api.properties", "classpath:record-api.user.properties"}, | ||
ignoreResourceNotFound = true) | ||
@Import({eu.europeana.api.record.db.config.DataSourceConfig.class}) | ||
public class DataSourceConfig { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(DataSourceConfig.class); | ||
|
||
@Value("${mongo.connectionUrl}") | ||
private String hostUri; | ||
|
||
@Value("${mongo.record.database}") | ||
private String recordDatabase; | ||
|
||
@Primary | ||
@Bean | ||
public MongoClient mongoClient(MigrationConfig config) { | ||
ConnectionString connectionString = new ConnectionString(hostUri); | ||
|
||
// add codecs | ||
CodecRegistry myRegistry = fromRegistries( | ||
fromProviders(getDataValueCodecProvider()) | ||
, MongoClientSettings.getDefaultCodecRegistry() | ||
); | ||
|
||
|
||
return MongoClients.create( | ||
MongoClientSettings.builder() | ||
.applyConnectionString(connectionString) | ||
.codecRegistry(myRegistry) | ||
.build()); | ||
} | ||
|
||
@Primary | ||
@Bean(name = AppConfigConstants.BEAN_RECORD_DATA_STORE) | ||
public Datastore emDataStore(MongoClient mongoClient) { | ||
LOGGER.info("Configuring Record API database: {}", recordDatabase); | ||
Datastore datastore= createDatastore(mongoClient, recordDatabase, getDataValueCodecProvider()); | ||
//datastore.ensureIndexes(); | ||
return datastore; | ||
} | ||
|
||
@Bean | ||
public RecordApiCodecProvider getDataValueCodecProvider() { | ||
return new RecordApiCodecProvider(); | ||
} | ||
|
||
private Datastore createDatastore(MongoClient mongoClient, String recordDatabase, RecordApiCodecProvider provider) { | ||
Datastore datastore = Morphia.createDatastore(mongoClient, recordDatabase); | ||
// provider.setDatastore(datastore); | ||
DatastoreHolder.holder.set(datastore); | ||
|
||
// hack in order to inject our own PropertyCodecProvider | ||
for ( CodecProvider p : ((DatastoreImpl)datastore).morphiaCodecProviders ) { | ||
if ( p instanceof MorphiaCodecProvider) { | ||
CodecUtils.register((MorphiaCodecProvider)p, provider); | ||
} | ||
} | ||
Mapper mapper = datastore.getMapper(); | ||
mapper.mapPackage("eu.europeana.api.record.model"); | ||
mapper.mapPackage("eu.europeana.api.record.model.media"); | ||
mapper.mapPackage("eu.europeana.api.record.model.data"); | ||
mapper.mapPackage("eu.europeana.api.record.model.internal"); | ||
mapper.mapPackage("eu.europeana.api.record.model.entity"); | ||
|
||
LOGGER.info("Datastore initialized"); | ||
return datastore; | ||
} | ||
|
||
} |
Oops, something went wrong.