1
|
package eu.dnetlib.clients.index.query;
|
2
|
|
3
|
import java.util.HashMap;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import eu.dnetlib.clients.index.client.IndexClientException;
|
7
|
import eu.dnetlib.clients.index.utils.MDFormatReader;
|
8
|
import eu.dnetlib.clients.index.utils.MetadataReference;
|
9
|
import eu.dnetlib.clients.index.utils.ServiceTools;
|
10
|
import org.apache.commons.logging.Log;
|
11
|
import org.apache.commons.logging.LogFactory;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
13
|
|
14
|
public class Weights extends HashMap<MetadataReference, Map<String, String>> {
|
15
|
|
16
|
private static final long serialVersionUID = -3517914310574484765L;
|
17
|
|
18
|
private static final Log log = LogFactory.getLog(Weights.class); // NOPMD by marko on 11/24/08 5:02 PM
|
19
|
|
20
|
@Autowired
|
21
|
private ServiceTools serviceTools;
|
22
|
|
23
|
@Autowired
|
24
|
private MDFormatReader mdFormatReader;
|
25
|
|
26
|
public Weights() {
|
27
|
super();
|
28
|
}
|
29
|
|
30
|
public void initialize() throws IndexClientException {
|
31
|
log.info("initializing weights");
|
32
|
|
33
|
for (MetadataReference mdRef : serviceTools.listMDRefs()) {
|
34
|
put(mdRef, mdFormatReader.getAttributeMap(mdRef, "weight"));
|
35
|
}
|
36
|
log.info("weights initialization completed");
|
37
|
|
38
|
}
|
39
|
|
40
|
@Override
|
41
|
public Map<String, String> put(final MetadataReference mdRef, final Map<String, String> w) {
|
42
|
log.info("[" + mdRef + "]" + " adding weights: " + w);
|
43
|
return super.put(mdRef, w);
|
44
|
}
|
45
|
|
46
|
@Override
|
47
|
public Map<String, String> get(final Object mdRef) {
|
48
|
Map<String, String> map = super.get(mdRef);
|
49
|
return map != null ? map : initAndGet(mdRef);
|
50
|
}
|
51
|
|
52
|
private Map<String, String> initAndGet(final Object mdRef) {
|
53
|
try {
|
54
|
initialize();
|
55
|
} catch (IndexClientException e) {
|
56
|
throw new RuntimeException(e);
|
57
|
}
|
58
|
return super.get(mdRef);
|
59
|
}
|
60
|
}
|