Skip to content

Commit 7f391cb

Browse files
Several general improvement including migration
1 parent 4887506 commit 7f391cb

File tree

74 files changed

+2922
-854
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2922
-854
lines changed

record-api-common/src/main/java/eu/europeana/api/edm/CC.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ public interface CC
1212

1313
public static final String License = "License";
1414
public static final String deprecatedOn = "deprecatedOn";
15-
}
15+
}

record-api-common/src/main/java/eu/europeana/api/format/FormatWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public interface FormatWriter<T> {
2020

2121
/**
2222
* Method for serialising list of values
23-
* @param value list of value to be formatted
23+
* @param value list of objects to be serialised
2424
* @param out output stream
2525
* @throws IOException
2626
*/

record-api-common/src/main/resources/mediacategories.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<format mediaType="application/dash+xml" label="MPEG-DASH" type="Video" support="Browser"/>
2424
<format mediaType="video/x-flv" label="FLV" type="Video" support="Rendered"/>
2525
<format mediaType="audio/x-ms-wma" label="WMA" type="Sound" support="Rendered"/>
26+
<format mediaType="audio/amr" label="AMR" type="Sound" support="Rendered"/> <!-- new -->
27+
<format mediaType="audio/x-aiff" label="AIFF" type="Sound" support="Browser"/> <!-- new (the browser should be able to play) -->
28+
<format mediaType="video/x-matroska" label="MKV" type="Video" support="Rendered"/> <!-- new (browser cannot natively played it but it is possible with plugin) -->
2629
<format mediaType="video/x-ms-wmv" label="WMV" type="Video" support="Rendered"/>
2730
<format mediaType="video/x-msvideo" label="AVI" type="Video" support="Rendered"/>
2831
<format mediaType="image/jp2" label="JP2000" type="Image" support="Rendered"/>
@@ -42,4 +45,6 @@
4245
<format mediaType="application/epub+zip" label="EPUB" type="Text" support="Rendered"/>
4346
<format type="Video" support="EUScreen"/>
4447
<format type="Sound" support="EUScreen"/>
48+
<format mediaType="application/json+oembed" label="oEmbed" support="Rendered"/>
49+
<format mediaType="application/xml+oembed" label="oEmbed" support="Rendered"/>
4550
</config>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<parent>
4+
<artifactId>record-api</artifactId>
5+
<groupId>eu.europeana.api</groupId>
6+
<version>1.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
<artifactId>record-api-migration</artifactId>
10+
<description>This is a temporary module to migrate all the data from the DB</description>
11+
<build>
12+
<plugins>
13+
<plugin>
14+
<artifactId>maven-shade-plugin</artifactId>
15+
<version>3.6.0</version>
16+
<executions>
17+
<execution>
18+
<phase>package</phase>
19+
<goals>
20+
<goal>shade</goal>
21+
</goals>
22+
</execution>
23+
</executions>
24+
<configuration>
25+
<shadedArtifactAttached>false</shadedArtifactAttached>
26+
<transformers>
27+
<transformer>
28+
<mainClass>eu.europeana.api.record.migration.MigrationCommand</mainClass>
29+
</transformer>
30+
<transformer />
31+
<transformer />
32+
<transformer>
33+
<addHeader>false</addHeader>
34+
</transformer>
35+
</transformers>
36+
<filters>
37+
<filter>
38+
<artifact>*:*</artifact>
39+
<excludes>
40+
<exclude>**/Log4j2Plugins.dat</exclude>
41+
</excludes>
42+
</filter>
43+
</filters>
44+
</configuration>
45+
</plugin>
46+
</plugins>
47+
</build>
48+
<properties>
49+
<maven.compiler.target>17</maven.compiler.target>
50+
<maven.compiler.source>17</maven.compiler.source>
51+
<spring.boot.mainclass>eu.europeana.api.record.migration.RunMigration</spring.boot.mainclass>
52+
</properties>
53+
</project>

record-api-migration/pom.xml

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,89 @@
1717
<spring.boot.mainclass>eu.europeana.api.record.migration.RunMigration</spring.boot.mainclass>
1818
</properties>
1919

20+
<build>
21+
<plugins>
22+
23+
<!--
24+
<plugin>
25+
<artifactId>maven-assembly-plugin</artifactId>
26+
<configuration>
27+
<archive>
28+
<manifest>
29+
<mainClass>eu.europeana.api.record.migration.MigrationCommand</mainClass>
30+
</manifest>
31+
</archive>
32+
<descriptorRefs>
33+
<descriptorRef>jar-with-dependencies</descriptorRef>
34+
</descriptorRefs>
35+
</configuration>
36+
<executions>
37+
<execution>
38+
<id>make-assembly</id>
39+
<phase>package</phase>
40+
<goals>
41+
<goal>single</goal>
42+
</goals>
43+
</execution>
44+
</executions>
45+
</plugin>
46+
-->
47+
48+
<plugin>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-shade-plugin</artifactId>
51+
<version>3.6.0</version>
52+
<configuration>
53+
<shadedArtifactAttached>false</shadedArtifactAttached>
54+
<transformers>
55+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
56+
<mainClass>eu.europeana.api.record.migration.MigrationCommand</mainClass>
57+
</transformer>
58+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
59+
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
60+
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
61+
<addHeader>false</addHeader>
62+
</transformer>
63+
</transformers>
64+
<filters>
65+
<filter>
66+
<artifact>*:*</artifact>
67+
<excludes>
68+
<exclude>**/Log4j2Plugins.dat</exclude>
69+
</excludes>
70+
</filter>
71+
</filters>
72+
</configuration>
73+
<executions>
74+
<execution>
75+
<phase>package</phase>
76+
<goals>
77+
<goal>shade</goal>
78+
</goals>
79+
</execution>
80+
</executions>
81+
</plugin>
82+
83+
</plugins>
84+
85+
</build>
86+
87+
<!--
88+
<filters>
89+
<filter>
90+
<artifact>*:*</artifact>
91+
<excludes>
92+
<exclude>**/Log4j2Plugins.dat</exclude>
93+
</excludes>
94+
</filter>
95+
</filters>
96+
-->
97+
2098
<dependencies>
2199
<dependency>
22100
<groupId>org.springframework.boot</groupId>
23-
<artifactId>spring-boot-starter-web</artifactId>
101+
<artifactId>spring-boot-starter</artifactId>
24102
<exclusions>
25-
<!-- use log4j2 instead -->
26103
<exclusion>
27104
<groupId>org.springframework.boot</groupId>
28105
<artifactId>spring-boot-starter-logging</artifactId>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package eu.europeana.api.record.migration;
2+
3+
import com.mongodb.Block;
4+
import com.mongodb.ConnectionString;
5+
import com.mongodb.MongoClientSettings;
6+
import com.mongodb.client.MongoClient;
7+
import com.mongodb.client.MongoClients;
8+
import com.mongodb.connection.ConnectionPoolSettings;
9+
import java.util.concurrent.TimeUnit;
10+
import dev.morphia.Datastore;
11+
import dev.morphia.DatastoreImpl;
12+
import dev.morphia.Morphia;
13+
import dev.morphia.internal.DatastoreHolder;
14+
import dev.morphia.mapping.Mapper;
15+
import dev.morphia.mapping.codec.CodecUtils;
16+
import dev.morphia.mapping.codec.MorphiaCodecProvider;
17+
import eu.europeana.api.config.AppConfigConstants;
18+
import eu.europeana.api.record.db.codec.*;
19+
import org.apache.logging.log4j.LogManager;
20+
import org.apache.logging.log4j.Logger;
21+
22+
import org.bson.codecs.configuration.CodecProvider;
23+
import org.bson.codecs.configuration.CodecRegistry;
24+
import org.springframework.beans.factory.annotation.Value;
25+
import org.springframework.context.annotation.Bean;
26+
import org.springframework.context.annotation.Configuration;
27+
import org.springframework.context.annotation.Import;
28+
import org.springframework.context.annotation.Primary;
29+
import org.springframework.context.annotation.PropertySource;
30+
31+
import static org.bson.codecs.configuration.CodecRegistries.*;
32+
33+
@Configuration
34+
@PropertySource(
35+
value = {"classpath:record-api.properties", "classpath:record-api.user.properties"},
36+
ignoreResourceNotFound = true)
37+
@Import({eu.europeana.api.record.db.config.DataSourceConfig.class})
38+
public class DataSourceConfig {
39+
40+
private static final Logger LOGGER = LogManager.getLogger(DataSourceConfig.class);
41+
42+
@Value("${mongo.connectionUrl}")
43+
private String hostUri;
44+
45+
@Value("${mongo.record.database}")
46+
private String recordDatabase;
47+
48+
@Primary
49+
@Bean
50+
public MongoClient mongoClient(MigrationConfig config) {
51+
ConnectionString connectionString = new ConnectionString(hostUri);
52+
53+
// add codecs
54+
CodecRegistry myRegistry = fromRegistries(
55+
fromProviders(getDataValueCodecProvider())
56+
, MongoClientSettings.getDefaultCodecRegistry()
57+
);
58+
59+
60+
return MongoClients.create(
61+
MongoClientSettings.builder()
62+
.applyConnectionString(connectionString)
63+
.codecRegistry(myRegistry)
64+
.build());
65+
}
66+
67+
@Primary
68+
@Bean(name = AppConfigConstants.BEAN_RECORD_DATA_STORE)
69+
public Datastore emDataStore(MongoClient mongoClient) {
70+
LOGGER.info("Configuring Record API database: {}", recordDatabase);
71+
Datastore datastore= createDatastore(mongoClient, recordDatabase, getDataValueCodecProvider());
72+
//datastore.ensureIndexes();
73+
return datastore;
74+
}
75+
76+
@Bean
77+
public RecordApiCodecProvider getDataValueCodecProvider() {
78+
return new RecordApiCodecProvider();
79+
}
80+
81+
private Datastore createDatastore(MongoClient mongoClient, String recordDatabase, RecordApiCodecProvider provider) {
82+
Datastore datastore = Morphia.createDatastore(mongoClient, recordDatabase);
83+
// provider.setDatastore(datastore);
84+
DatastoreHolder.holder.set(datastore);
85+
86+
// hack in order to inject our own PropertyCodecProvider
87+
for ( CodecProvider p : ((DatastoreImpl)datastore).morphiaCodecProviders ) {
88+
if ( p instanceof MorphiaCodecProvider) {
89+
CodecUtils.register((MorphiaCodecProvider)p, provider);
90+
}
91+
}
92+
Mapper mapper = datastore.getMapper();
93+
mapper.mapPackage("eu.europeana.api.record.model");
94+
mapper.mapPackage("eu.europeana.api.record.model.media");
95+
mapper.mapPackage("eu.europeana.api.record.model.data");
96+
mapper.mapPackage("eu.europeana.api.record.model.internal");
97+
mapper.mapPackage("eu.europeana.api.record.model.entity");
98+
99+
LOGGER.info("Datastore initialized");
100+
return datastore;
101+
}
102+
103+
}

0 commit comments

Comments
 (0)