Skip to content

Commit

Permalink
Several general improvement including migration
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomanguinhas committed Jun 26, 2024
1 parent 4887506 commit 7f391cb
Show file tree
Hide file tree
Showing 74 changed files with 2,922 additions and 854 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public interface CC

public static final String License = "License";
public static final String deprecatedOn = "deprecatedOn";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface FormatWriter<T> {

/**
* Method for serialising list of values
* @param value list of value to be formatted
* @param value list of objects to be serialised
* @param out output stream
* @throws IOException
*/
Expand Down
5 changes: 5 additions & 0 deletions record-api-common/src/main/resources/mediacategories.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<format mediaType="application/dash+xml" label="MPEG-DASH" type="Video" support="Browser"/>
<format mediaType="video/x-flv" label="FLV" type="Video" support="Rendered"/>
<format mediaType="audio/x-ms-wma" label="WMA" type="Sound" support="Rendered"/>
<format mediaType="audio/amr" label="AMR" type="Sound" support="Rendered"/> <!-- new -->
<format mediaType="audio/x-aiff" label="AIFF" type="Sound" support="Browser"/> <!-- new (the browser should be able to play) -->
<format mediaType="video/x-matroska" label="MKV" type="Video" support="Rendered"/> <!-- new (browser cannot natively played it but it is possible with plugin) -->
<format mediaType="video/x-ms-wmv" label="WMV" type="Video" support="Rendered"/>
<format mediaType="video/x-msvideo" label="AVI" type="Video" support="Rendered"/>
<format mediaType="image/jp2" label="JP2000" type="Image" support="Rendered"/>
Expand All @@ -42,4 +45,6 @@
<format mediaType="application/epub+zip" label="EPUB" type="Text" support="Rendered"/>
<format type="Video" support="EUScreen"/>
<format type="Sound" support="EUScreen"/>
<format mediaType="application/json+oembed" label="oEmbed" support="Rendered"/>
<format mediaType="application/xml+oembed" label="oEmbed" support="Rendered"/>
</config>
53 changes: 53 additions & 0 deletions record-api-migration/dependency-reduced-pom.xml
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>
81 changes: 79 additions & 2 deletions record-api-migration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,89 @@
<spring.boot.mainclass>eu.europeana.api.record.migration.RunMigration</spring.boot.mainclass>
</properties>

<build>
<plugins>

<!--
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>eu.europeana.api.record.migration.MigrationCommand</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
-->

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>eu.europeana.api.record.migration.MigrationCommand</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
<addHeader>false</addHeader>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>**/Log4j2Plugins.dat</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>

</build>

<!--
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>**/Log4j2Plugins.dat</exclude>
</excludes>
</filter>
</filters>
-->

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<!-- use log4j2 instead -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
Expand Down
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;
}

}
Loading

0 comments on commit 7f391cb

Please sign in to comment.