2 * Copyright (C) 2020 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.service
;
11 import java
.util
.HashMap
;
12 import java
.util
.HashSet
;
13 import java
.util
.List
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.springframework
.remoting
.support
.RemoteInvocation
;
19 import org
.springframework
.remoting
.support
.RemoteInvocationResult
;
21 import eu
.etaxonomy
.cdm
.api
.cache
.CdmServiceCacher
;
22 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
23 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
26 public class RemoteInvocationTermCacher
implements IRemoteInvocationTermCacher
{
28 private static final Logger logger
= Logger
.getLogger(RemoteInvocationTermCacher
.class);
30 private static Map
<TermType
, RemoteInvocationResult
> termTypeMap
= new HashMap
<>();
32 private static CdmServiceCacher cdmServiceCacher
;
34 public static void setDefaultCacher(CdmServiceCacher csc
) {
35 cdmServiceCacher
= csc
;
39 public void cacheTerms(RemoteInvocation ri
, RemoteInvocationResult rir
) {
40 if(cdmServiceCacher
!= null) {
41 if(ri
.getMethodName().equals("listByTermType")) {
42 if(ri
.getArguments()[1] == null) {
43 Set
<DefinedTermBase
<?
>> terms
= new HashSet
<>();
44 if(rir
.getValue() != null) {
45 terms
.addAll((List
<DefinedTermBase
<?
>>)rir
.getValue());
47 for(DefinedTermBase
<?
> term
: terms
) {
48 cdmServiceCacher
.load(term
);
50 termTypeMap
.put((TermType
)ri
.getArguments()[0], rir
);
55 logger
.info("Default CdmServiceCacher is null. Cannot cache terms");
60 public RemoteInvocationResult
termsFromCache(RemoteInvocation ri
) {
61 return termTypeMap
.get(ri
.getArguments()[0]);