1
|
package eu.dnetlib.index;
|
2
|
|
3
|
import java.lang.reflect.Type;
|
4
|
import java.net.URI;
|
5
|
import java.util.Map;
|
6
|
|
7
|
import com.google.common.collect.Maps;
|
8
|
import com.google.gson.Gson;
|
9
|
import com.google.gson.reflect.TypeToken;
|
10
|
import eu.dnetlib.rmi.provision.IndexServiceException;
|
11
|
import org.springframework.beans.factory.annotation.Required;
|
12
|
|
13
|
public abstract class AbstractBackendDescriptor implements IndexServerDAO {
|
14
|
|
15
|
protected Type typeToken = new TypeToken<Map<String, String>>() {
|
16
|
}.getType();
|
17
|
|
18
|
private Map<String, String> serviceProperties;
|
19
|
|
20
|
private String jsonConfiguration;
|
21
|
|
22
|
public void init() throws IndexServiceException {
|
23
|
try {
|
24
|
serviceProperties = new Gson().fromJson(getJsonConfiguration(), typeToken);
|
25
|
} catch (Throwable e) {
|
26
|
throw new IndexServiceException("unable to parse configuration: " + jsonConfiguration, e);
|
27
|
}
|
28
|
}
|
29
|
|
30
|
public String getJsonConfiguration() {
|
31
|
return jsonConfiguration;
|
32
|
}
|
33
|
|
34
|
@Required
|
35
|
public void setJsonConfiguration(final String jsonConfiguration) {
|
36
|
this.jsonConfiguration = jsonConfiguration;
|
37
|
}
|
38
|
|
39
|
protected URI getEndpointURL() {
|
40
|
return URI.create(getEndpoint().get(ADDRESS));
|
41
|
}
|
42
|
|
43
|
@Override
|
44
|
public Map<String, String> getServiceProperties() {
|
45
|
return serviceProperties;
|
46
|
}
|
47
|
|
48
|
@Override
|
49
|
public String getBackendId() {
|
50
|
return getServiceProperties().get(ID);
|
51
|
}
|
52
|
|
53
|
@Override
|
54
|
public Map<String, String> getEndpoint() {
|
55
|
return Maps.filterKeys(getServiceProperties(), key -> key.equals(ID) || key.equals(ADDRESS));
|
56
|
}
|
57
|
|
58
|
}
|