-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDataManagerContextProvider.java
More file actions
69 lines (61 loc) · 2.29 KB
/
Copy pathDataManagerContextProvider.java
File metadata and controls
69 lines (61 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package life.qbic.datamanager;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Paths;
import life.qbic.application.commons.ApplicationException;
import life.qbic.projectmanagement.application.AppContextProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* <b>Data Manager context provider</b>
* <p>
* Simple implementation of the {@link AppContextProvider} interface.
*
* @since 1.0.0
*/
@Component
public class DataManagerContextProvider implements AppContextProvider {
private final String projectInfoEndpoint;
private final URL baseUrlApplication;
private final String samplesEndpoint;
public DataManagerContextProvider(
@Value("${service.host.protocol}") String protocol,
@Value("${service.host.name}") String host,
@Value("${service.host.port}") int port,
@Value("${server.servlet.context-path}") String contextPath,
@Value("${routing.projects.info.endpoint}") String projectEndpoint,
@Value("${routing.projects.samples.enpoint}") String samplesEndpoint) {
this.projectInfoEndpoint = projectEndpoint;
this.samplesEndpoint = samplesEndpoint;
try {
baseUrlApplication = new URL(protocol, host, port, contextPath);
} catch (MalformedURLException e) {
throw new ApplicationException("Initialization of context provider failed.", e);
}
}
@Override
public String urlToProject(String projectId) {
try {
return new URL(baseUrlApplication,
Paths.get(baseUrlApplication.getPath(), projectInfoEndpoint.formatted(projectId))
.toString()).toExternalForm();
} catch (MalformedURLException e) {
throw new ApplicationException("Data Manager context creation failed.", e);
}
}
@Override
public String urlToSamplePage(String projectId, String experimentId) {
try {
return new URL(baseUrlApplication,
Paths.get(baseUrlApplication.getPath(),
samplesEndpoint.formatted(projectId, experimentId))
.toString()).toExternalForm();
} catch (MalformedURLException e) {
throw new ApplicationException("Data Manager context creation failed.", e);
}
}
@Override
public String baseUrl() {
return baseUrlApplication.toExternalForm();
}
}