Skip to content

Commit 4e47d3b

Browse files
committed
Initial import.
0 parents  commit 4e47d3b

20 files changed

+605
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea/
2+
/target/
3+
application.yml
4+
nb-configuration.xml
5+
/nbproject/
6+
*.iml

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: java
2+
3+
jdk:
4+
- oraclejdk8

Readme.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# EMiL - Rosetta integration service
2+
3+
A microservice framework providing object storage metadata from an arbitrary archive to EMiL. The REST-Interface provides data as JSON or XML based on HTTP content negotiation (default: JSON).
4+
5+
## Introduction
6+
7+
### Implementation
8+
9+
To provide data from your archive to EMiL, your implementation has to implement the interface `ArchiveService`:
10+
11+
@Service
12+
public class YourArchiveService implements ArchiveService<YourPid> {
13+
14+
@Override
15+
public ArchiveObject getArchiveObject(YourPid pid) throws Exception {
16+
...
17+
}
18+
19+
@Override
20+
public IEPid getPid(String token) {
21+
...
22+
}
23+
24+
}
25+
26+
27+
### Implementation
28+
29+
java -jar <your implementation>.jar
30+
31+
Make sure that `application.yml` is the same directory as `<your implementation>.jar`.
32+
33+
### Usage:
34+
35+
GET http://hostname/<IDENTIFIER>
36+
37+
{
38+
"objectId": "IE12345",
39+
"files": [
40+
{ "fileId": "FL12312.iso", "type": "ISO", "url": "http://rosetta-hostname/delivery/DeliveryManagerServlet?dps_pid=FL12312&dps_func=stream" },
41+
{ "fileId": "FL12313.iso", "type": "ISO", "url": "http://rosetta-hostname/delivery/DeliveryManagerServlet?dps_pid=FL12313&dps_func=stream" },
42+
{ "fileId": "FL12314.iso", "type": "ISO", "url": "http://rosetta-hostname/delivery/DeliveryManagerServlet?dps_pid=FL12314&dps_func=stream" }
43+
]
44+
}
45+
46+
This service also offers a freely configurable demo object (see application.yml.template). The application.yml file has to be in the same directory as the jar file.
47+
48+
## Demo Mode
49+
50+
In application.yml one can define one PID with the desired response for testing. In case of this PID, the underlying archive won't be queried.
51+
52+
## Content Negotiation
53+
54+
If not ordered otherwise the service produces JSON. To get an XML representation, use `Accept: application/xml` header or add ".xml" at the end of the URL *(experimental)*.

application.yml.template

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
demoObject:
2+
objectId: IE00000
3+
files:
4+
- fileId: FL00001
5+
type: ISO
6+
fileOriginalName: demo.ISO
7+
url: http://example.com/demo.ISO
8+
- fileId: FL00002
9+
type: ISO
10+
fileOriginalName: demo2.ISO
11+
url: http://example.com/demo2.ISO
12+
13+
server:
14+
port: 1337

pom.xml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>de.multimedia.emulation.emil.integration</groupId>
5+
<artifactId>framework</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<name>EMiL - Integration Microservice Framework</name>
8+
<packaging>jar</packaging>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
<!-- Dependencies -->
15+
<version.mockito>1.10.8</version.mockito>
16+
<!-- Plugins -->
17+
<version.jacoco-maven-plugin>0.7.4.201502262128</version.jacoco-maven-plugin>
18+
</properties>
19+
20+
<parent>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-parent</artifactId>
23+
<version>1.3.3.RELEASE</version>
24+
</parent>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-actuator</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-web</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.hamcrest</groupId>
37+
<artifactId>java-hamcrest</artifactId>
38+
<version>2.0.0.0</version>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>junit</groupId>
43+
<artifactId>junit</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.mockito</groupId>
48+
<artifactId>mockito-all</artifactId>
49+
<version>${version.mockito}</version>
50+
<scope>test</scope>
51+
</dependency>
52+
</dependencies>
53+
54+
<build>
55+
<plugins>
56+
<plugin>
57+
<artifactId>maven-compiler-plugin</artifactId>
58+
<version>3.5.1</version>
59+
<configuration>
60+
<source>${maven.compiler.source}</source>
61+
<target>${maven.compiler.target}</target>
62+
</configuration>
63+
</plugin>
64+
<plugin>
65+
<groupId>org.jacoco</groupId>
66+
<artifactId>jacoco-maven-plugin</artifactId>
67+
<version>${version.jacoco-maven-plugin}</version>
68+
<executions>
69+
<execution>
70+
<id>pre-unit-test</id>
71+
<goals>
72+
<goal>prepare-agent</goal>
73+
</goals>
74+
</execution>
75+
<execution>
76+
<phase>test</phase>
77+
<goals>
78+
<goal>report</goal>
79+
</goals>
80+
</execution>
81+
</executions>
82+
</plugin>
83+
</plugins>
84+
</build>
85+
86+
<reporting>
87+
<plugins>
88+
<plugin>
89+
<groupId>org.jacoco</groupId>
90+
<artifactId>jacoco-maven-plugin</artifactId>
91+
<version>${version.jacoco-maven-plugin}</version>
92+
</plugin>
93+
</plugins>
94+
</reporting>
95+
96+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package de.multimedia.emulation.emil.integration.config;
2+
3+
import org.springframework.context.annotation.ComponentScan;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
@ComponentScan("de.multimedia.emulation.emil.integration")
8+
public class EmilIntegrationFramworkConfig {
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package de.multimedia.emulation.emil.integration.controller;
2+
3+
import de.multimedia.emulation.emil.integration.demo.service.DemoService;
4+
import de.multimedia.emulation.emil.integration.model.object.ArchiveObject;
5+
import de.multimedia.emulation.emil.integration.model.pid.Pid;
6+
import de.multimedia.emulation.emil.integration.service.ArchiveService;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.web.bind.annotation.PathVariable;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RequestMethod;
11+
import org.springframework.web.bind.annotation.ResponseBody;
12+
import org.springframework.web.bind.annotation.RestController;
13+
14+
/**
15+
*
16+
* @author Marcus Bitzl <[email protected]>
17+
*/
18+
@RestController
19+
public class EmilController {
20+
21+
private final ArchiveService<Pid> archiveService;
22+
23+
private final DemoService demoService;
24+
25+
@Autowired
26+
public EmilController(ArchiveService archiveService, DemoService demoService) {
27+
this.archiveService = archiveService;
28+
this.demoService = demoService;
29+
}
30+
31+
/**
32+
*
33+
* @param id The Pid for the desired object.
34+
* @return A representation of the object and all suitable files.
35+
* @throws Exception if the request fails.
36+
*/
37+
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = {"application/json", "application/xml"})
38+
@ResponseBody
39+
public ArchiveObject get(@PathVariable("id") String id) throws Exception {
40+
if (demoService.isDemoObjectId(id)) {
41+
return demoService.getDemoObject();
42+
}
43+
return archiveService.getArchiveObject(archiveService.getPid(id));
44+
}
45+
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package de.multimedia.emulation.emil.integration.demo.config;
2+
3+
import de.multimedia.emulation.emil.integration.demo.model.DemoFile;
4+
import de.multimedia.emulation.emil.integration.demo.model.DemoObject;
5+
import de.multimedia.emulation.emil.integration.model.object.ArchiveObject;
6+
import java.util.List;
7+
import org.springframework.boot.context.properties.ConfigurationProperties;
8+
import org.springframework.context.annotation.Configuration;
9+
10+
/**
11+
*
12+
* @author Marcus Bitzl <[email protected]>
13+
*/
14+
@ConfigurationProperties(prefix = "demoObject")
15+
@Configuration
16+
public class DemoConfig {
17+
18+
private String objectId;
19+
20+
private List<DemoFile> files;
21+
22+
public List<DemoFile> getFiles() {
23+
return files;
24+
}
25+
26+
public void setFiles(List<DemoFile> files) {
27+
this.files = files;
28+
}
29+
30+
public void setObjectId(String objectId) {
31+
this.objectId = objectId;
32+
}
33+
34+
public String getObjectId() {
35+
return objectId;
36+
}
37+
38+
public ArchiveObject getDemoObject() {
39+
return new DemoObject(objectId, files);
40+
}
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package de.multimedia.emulation.emil.integration.demo.model;
2+
3+
import de.multimedia.emulation.emil.integration.model.object.ArchiveFile;
4+
import de.multimedia.emulation.emil.integration.model.object.FileType;
5+
import java.net.MalformedURLException;
6+
import java.net.URL;
7+
8+
/**
9+
*
10+
* @author Marcus Bitzl <[email protected]>
11+
*/
12+
public class DemoFile implements ArchiveFile {
13+
14+
private String fileId;
15+
private String fileOriginalName;
16+
private String url;
17+
private String type;
18+
19+
@Override
20+
public String getFileId() {
21+
return fileId;
22+
}
23+
24+
public void setFileId(String fileId) {
25+
this.fileId = fileId;
26+
}
27+
28+
@Override
29+
public String getFileOriginalName() {
30+
return fileOriginalName;
31+
}
32+
33+
public void setFileOriginalName(String fileOriginalName) {
34+
this.fileOriginalName = fileOriginalName;
35+
}
36+
37+
@Override
38+
public URL getUrl() {
39+
try {
40+
return new URL(url);
41+
} catch (MalformedURLException exception) {
42+
throw new RuntimeException(exception);
43+
}
44+
}
45+
46+
public void setUrl(String url) {
47+
this.url = url;
48+
}
49+
50+
@Override
51+
public FileType getType() {
52+
return FileType.valueOf(type.toUpperCase());
53+
}
54+
55+
public void setType(String type) {
56+
this.type = type;
57+
}
58+
59+
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package de.multimedia.emulation.emil.integration.demo.model;
2+
3+
import de.multimedia.emulation.emil.integration.model.object.ArchiveFile;
4+
import de.multimedia.emulation.emil.integration.model.object.ArchiveObject;
5+
import java.util.List;
6+
import javax.xml.bind.annotation.XmlRootElement;
7+
8+
/**
9+
*
10+
* @author Marcus Bitzl <[email protected]>
11+
*/
12+
@XmlRootElement(name = "ArchiveObject")
13+
public class DemoObject implements ArchiveObject {
14+
15+
private final String id;
16+
17+
private final List<? extends ArchiveFile> files;
18+
19+
public DemoObject(String id, List<? extends ArchiveFile> files) {
20+
this.id = id;
21+
this.files = files;
22+
}
23+
24+
@Override
25+
public String getId() {
26+
return id;
27+
}
28+
29+
@Override
30+
public List<? extends ArchiveFile> getFiles() {
31+
return files;
32+
}
33+
34+
}

0 commit comments

Comments
 (0)