1 package eu
.etaxonomy
.taxeditor
.service
;
3 import java
.util
.HashMap
;
4 import java
.util
.HashSet
;
9 import org
.apache
.log4j
.Logger
;
10 import org
.springframework
.remoting
.support
.RemoteInvocation
;
11 import org
.springframework
.remoting
.support
.RemoteInvocationResult
;
13 import eu
.etaxonomy
.cdm
.api
.cache
.CdmServiceCacher
;
14 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
15 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
18 public class TermServiceRequestExecutor
extends CdmServiceRequestExecutor
{
19 private static final Logger logger
= Logger
.getLogger(TermServiceRequestExecutor
.class);
21 private static Map
<TermType
, RemoteInvocationResult
> termTypeMap
= new HashMap
<>();
23 private static CdmServiceCacher cdmServiceCacher
;
25 public static void setDefaultCacher(CdmServiceCacher csc
) {
26 cdmServiceCacher
= csc
;
30 public void cache(RemoteInvocation ri
, RemoteInvocationResult rir
) {
31 if(cdmServiceCacher
!= null) {
32 if(ri
.getMethodName().equals("listByTermType")) {
33 if(ri
.getArguments()[1] == null) {
34 Set
<DefinedTermBase
<?
>> terms
= new HashSet
<>();
35 if(rir
.getValue() != null) {
36 terms
.addAll((List
<DefinedTermBase
<?
>>)rir
.getValue());
38 for(DefinedTermBase
<?
> term
: terms
) {
39 cdmServiceCacher
.load(term
);
41 termTypeMap
.put((TermType
)ri
.getArguments()[0], rir
);
47 logger
.info("Default CdmServiceCacher is null. Cannot cache terms");
52 public RemoteInvocationResult
fromCache(RemoteInvocation ri
) {
53 return termTypeMap
.get(ri
.getArguments()[0]);