1
|
package eu.etaxonomy.taxeditor.service;
|
2
|
|
3
|
import java.util.HashMap;
|
4
|
import java.util.HashSet;
|
5
|
import java.util.List;
|
6
|
import java.util.Map;
|
7
|
import java.util.Set;
|
8
|
|
9
|
import org.apache.log4j.Logger;
|
10
|
import org.springframework.remoting.support.RemoteInvocation;
|
11
|
import org.springframework.remoting.support.RemoteInvocationResult;
|
12
|
|
13
|
import eu.etaxonomy.cdm.api.cache.CdmServiceCacher;
|
14
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
15
|
import eu.etaxonomy.cdm.model.common.TermType;
|
16
|
|
17
|
|
18
|
public class TermServiceRequestExecutor extends CdmServiceRequestExecutor {
|
19
|
private static final Logger logger = Logger.getLogger(TermServiceRequestExecutor.class);
|
20
|
|
21
|
private static Map<TermType, RemoteInvocationResult> termTypeMap = new
|
22
|
HashMap<TermType, RemoteInvocationResult>();
|
23
|
|
24
|
private static CdmServiceCacher cdmServiceCacher;
|
25
|
|
26
|
public static void setDefaultCacher(CdmServiceCacher css) {
|
27
|
cdmServiceCacher = css;
|
28
|
}
|
29
|
|
30
|
@Override
|
31
|
public void cache(RemoteInvocation ri, RemoteInvocationResult rir) {
|
32
|
if(cdmServiceCacher != null) {
|
33
|
if(ri.getMethodName().equals("listByTermType")) {
|
34
|
if(ri.getArguments()[1] == null) {
|
35
|
Set<DefinedTermBase> terms = new HashSet<DefinedTermBase>();
|
36
|
if(rir.getValue() != null) {
|
37
|
terms.addAll((List<DefinedTermBase>)rir.getValue());
|
38
|
|
39
|
for(DefinedTermBase<?> term : terms) {
|
40
|
cdmServiceCacher.put(term.getUuid(), term);
|
41
|
}
|
42
|
termTypeMap.put((TermType)ri.getArguments()[0], rir);
|
43
|
}
|
44
|
|
45
|
}
|
46
|
}
|
47
|
} else {
|
48
|
logger.info("Default CdmServiceCacher is null. Cannot cache terms");
|
49
|
}
|
50
|
}
|
51
|
|
52
|
|
53
|
@Override
|
54
|
public RemoteInvocationResult fromCache(RemoteInvocation ri) {
|
55
|
return termTypeMap.get(ri.getArguments()[0]);
|
56
|
}
|
57
|
|
58
|
|
59
|
|
60
|
}
|