1
|
package eu.etaxonomy.cdm.io.common;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import org.apache.log4j.Logger;
|
6
|
import org.springframework.stereotype.Component;
|
7
|
|
8
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
9
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
10
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
11
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
12
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
13
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
14
|
import eu.etaxonomy.cdm.model.media.Media;
|
15
|
import eu.etaxonomy.cdm.model.molecular.Sequence;
|
16
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
17
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
18
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
19
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
20
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
21
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
22
|
import eu.etaxonomy.cdm.strategy.cache.taxon.TaxonBaseShortSecCacheStrategy;
|
23
|
|
24
|
@Component
|
25
|
public class CacheUpdaterWithNewCacheStrategy extends CacheUpdater {
|
26
|
private static final Logger logger = Logger.getLogger(CacheUpdaterWithNewCacheStrategy.class);
|
27
|
|
28
|
@Override
|
29
|
protected void doInvoke(DefaultImportState<CacheUpdaterConfigurator> state) {
|
30
|
CacheUpdaterConfigurator config = state.getConfig();
|
31
|
|
32
|
//handle class list
|
33
|
handleClassList(config.getClassList());
|
34
|
|
35
|
return;
|
36
|
}
|
37
|
|
38
|
private boolean handleClassList(List<Class<? extends IdentifiableEntity>> classList) {
|
39
|
boolean result = true;
|
40
|
for (Class<? extends IdentifiableEntity> clazz : classList){
|
41
|
//WE need to separate classes , because hibernate
|
42
|
//returns multiple values for service.count() for e.g. IdentifableEntity.class
|
43
|
//which leads to an exception
|
44
|
result &= this.handleSingleTableClass(clazz);
|
45
|
}
|
46
|
return result;
|
47
|
}
|
48
|
|
49
|
|
50
|
private boolean handleSingleTableClass(Class<? extends IdentifiableEntity> clazz) {
|
51
|
logger.warn("Updating class " + clazz.getSimpleName() + " ...");
|
52
|
try {
|
53
|
//TermBase
|
54
|
if (DefinedTermBase.class.isAssignableFrom(clazz)){
|
55
|
getTermService().updateTitleCache((Class) clazz, null, null, null);
|
56
|
}else if (FeatureTree.class.isAssignableFrom(clazz)){
|
57
|
getFeatureTreeService().updateTitleCache((Class) clazz, null, null, null);
|
58
|
}else if (TermVocabulary.class.isAssignableFrom(clazz)){
|
59
|
getVocabularyService().updateTitleCache((Class) clazz, null, null, null);
|
60
|
}
|
61
|
//DescriptionBase
|
62
|
else if (DescriptionBase.class.isAssignableFrom(clazz)){
|
63
|
getDescriptionService().updateTitleCache((Class) clazz, null, null, null);
|
64
|
}
|
65
|
//Media
|
66
|
else if (Media.class.isAssignableFrom(clazz)){
|
67
|
getMediaService().updateTitleCache((Class) clazz, null, null, null);
|
68
|
}//TaxonBase
|
69
|
else if (TaxonBase.class.isAssignableFrom(clazz)){
|
70
|
TaxonBaseShortSecCacheStrategy<TaxonBase> cacheStrategy = new TaxonBaseShortSecCacheStrategy<TaxonBase>();
|
71
|
getTaxonService().updateTitleCache((Class) clazz, null,cacheStrategy , null);
|
72
|
}
|
73
|
//IdentifiableMediaEntity
|
74
|
else if (AgentBase.class.isAssignableFrom(clazz)){
|
75
|
getAgentService().updateTitleCache((Class) clazz, null, null, null);
|
76
|
}else if (Collection.class.isAssignableFrom(clazz)){
|
77
|
getCollectionService().updateTitleCache((Class) clazz, null, null, null);
|
78
|
}else if (Reference.class.isAssignableFrom(clazz)){
|
79
|
getReferenceService().updateTitleCache((Class) clazz, null, null, null);
|
80
|
}else if (SpecimenOrObservationBase.class.isAssignableFrom(clazz)){
|
81
|
getOccurrenceService().updateTitleCache((Class) clazz, null, null, null);
|
82
|
}
|
83
|
//Sequence
|
84
|
else if (Sequence.class.isAssignableFrom(clazz)){
|
85
|
//TODO misuse TaxonServic for sequence update, use sequence service when it exists
|
86
|
getTaxonService().updateTitleCache((Class) clazz, null, null, null);
|
87
|
}
|
88
|
//TaxonNameBase
|
89
|
else if (TaxonNameBase.class.isAssignableFrom(clazz)){
|
90
|
getNameService().updateTitleCache((Class) clazz, null, null, null);
|
91
|
}
|
92
|
//Classification
|
93
|
else if (Classification.class.isAssignableFrom(clazz)){
|
94
|
getClassificationService().updateTitleCache((Class) clazz, null, null, null);
|
95
|
}
|
96
|
//unknown class
|
97
|
else {
|
98
|
String warning = "Unknown identifable entity subclass + " + clazz == null ? "null" : clazz.getName();
|
99
|
logger.error(warning);
|
100
|
return false;
|
101
|
//getTaxonService().updateTitleCache((Class) clazz);
|
102
|
}
|
103
|
return true;
|
104
|
} catch (Exception e) {
|
105
|
String warning = "Exception occurred when trying to update class + " + clazz == null ? "null" : clazz.getName();
|
106
|
warning += " Exception was: " + e.getMessage();
|
107
|
logger.error(warning);
|
108
|
e.printStackTrace();
|
109
|
return false;
|
110
|
}
|
111
|
}
|
112
|
|
113
|
}
|