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 RemoteInvocationTermCacher
implements IRemoteInvocationTermCacher
{
20 private static final Logger logger
= Logger
.getLogger(RemoteInvocationTermCacher
.class);
22 private static Map
<TermType
, RemoteInvocationResult
> termTypeMap
= new HashMap
<>();
24 private static CdmServiceCacher cdmServiceCacher
;
26 public static void setDefaultCacher(CdmServiceCacher csc
) {
27 cdmServiceCacher
= csc
;
31 public void cacheTerms(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
<>();
36 if(rir
.getValue() != null) {
37 terms
.addAll((List
<DefinedTermBase
<?
>>)rir
.getValue());
39 for(DefinedTermBase
<?
> term
: terms
) {
40 cdmServiceCacher
.load(term
);
42 termTypeMap
.put((TermType
)ri
.getArguments()[0], rir
);
47 logger
.info("Default CdmServiceCacher is null. Cannot cache terms");
52 public RemoteInvocationResult
termsFromCache(RemoteInvocation ri
) {
53 return termTypeMap
.get(ri
.getArguments()[0]);