Project

General

Profile

Revision 0da5fc18

ID0da5fc18d2a3fc17eecb48237e18dba2f9bed475
Parent 95371079
Child 66172879

Added by Katja Luther over 1 year ago

ref #8096: delete old cache updater and adapt cache updater to moved terms

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/operation/CacheUpdater.java
1
package eu.etaxonomy.cdm.io.operation;
2

  
3
import java.util.Arrays;
4
import java.util.List;
5

  
6
import org.apache.log4j.Logger;
7
import org.springframework.stereotype.Component;
8

  
9
import eu.etaxonomy.cdm.io.common.CdmImportBase;
10
import eu.etaxonomy.cdm.io.common.DefaultImportState;
11
import eu.etaxonomy.cdm.io.operation.config.CacheUpdaterConfigurator;
12
import eu.etaxonomy.cdm.model.agent.AgentBase;
13
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
14
import eu.etaxonomy.cdm.model.description.DescriptionBase;
15
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
16
import eu.etaxonomy.cdm.model.description.FeatureTree;
17
import eu.etaxonomy.cdm.model.description.PolytomousKey;
18
import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
19
import eu.etaxonomy.cdm.model.media.Media;
20
import eu.etaxonomy.cdm.model.molecular.Sequence;
21
import eu.etaxonomy.cdm.model.name.TaxonName;
22
import eu.etaxonomy.cdm.model.occurrence.Collection;
23
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
24
import eu.etaxonomy.cdm.model.reference.Reference;
25
import eu.etaxonomy.cdm.model.taxon.Classification;
26
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
27
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
28
import eu.etaxonomy.cdm.model.term.TermBase;
29
import eu.etaxonomy.cdm.model.term.TermVocabulary;
30

  
31

  
32
@Component
33
public class CacheUpdater extends CdmImportBase<CacheUpdaterConfigurator, DefaultImportState<CacheUpdaterConfigurator>> {
34

  
35
    private static final long serialVersionUID = -1410600568024821771L;
36

  
37
    private static final Logger logger = Logger.getLogger(CacheUpdater.class);
38

  
39
	@Override
40
	protected void doInvoke(DefaultImportState<CacheUpdaterConfigurator> state) {
41
		CacheUpdaterConfigurator config = state.getConfig();
42
		if (config.getClassList() == null || config.getClassList().isEmpty()){
43
			//!! not yet implemented
44
			logger.warn("Create class list from boolean values is not yet implemented for cache updater");
45
			createClassListFromBoolean();
46
		}
47

  
48
		//handle class list
49
		handleClassList(config.getClassList());
50

  
51
		return;
52
	}
53

  
54

  
55
	private boolean handleClassList(List<Class<? extends IdentifiableEntity>> classList) {
56
		boolean result = true;
57
		for (Class<? extends IdentifiableEntity> clazz : classList){
58
			//WE need to separate classes , because hibernate
59
			//returns multiple values for service.count() for e.g. IdentifableEntity.class
60
			//which leads to an exception
61
			if (! handleMultiTableClasses(clazz)){
62
				result &= this.handleSingleTableClass(clazz);
63
			}
64
		}
65
		return result;
66
	}
67

  
68
	private boolean handleMultiTableClasses(Class<? extends IdentifiableEntity> clazz) {
69
		if (clazz.isAssignableFrom(IdentifiableEntity.class)){
70
            @SuppressWarnings("rawtypes")
71
            List list = Arrays.asList(new Class[]{
72
					DescriptionBase.class, IdentifiableMediaEntity.class,
73
					Media.class, Sequence.class,
74
					TaxonBase.class, TaxonName.class,
75
					Classification.class, TermBase.class
76
					});
77
			handleClassList(list);
78
		}else if (clazz.isAssignableFrom(IdentifiableMediaEntity.class)){
79
			@SuppressWarnings("rawtypes")
80
            List list = Arrays.asList(new Class[]{AgentBase.class, Collection.class, Reference.class, SpecimenOrObservationBase.class});
81
			handleClassList(list);
82
		}else if (clazz.isAssignableFrom(TermBase.class)){
83
			@SuppressWarnings("rawtypes")
84
            List list = Arrays.asList(new Class[]{DefinedTermBase.class, FeatureTree.class, TermVocabulary.class });
85
			handleClassList(list);
86
		}else{
87
			return false;
88
		}
89
		return true;
90
	}
91

  
92
	private boolean handleSingleTableClass(Class<? extends IdentifiableEntity> clazz) {
93
		if (clazz == null){
94
		    return true;
95
		}
96
	    logger.info("Updating class " + clazz.getSimpleName() + " ...");
97
		try {
98
			//TermBase
99
			if (DefinedTermBase.class.isAssignableFrom(clazz)){
100
				getTermService().updateCaches((Class) clazz, null, null, null);
101
			}else if (TermVocabulary.class.isAssignableFrom(clazz)){
102
				getVocabularyService().updateCaches((Class) clazz, null, null, null);
103
			}
104
			//DescriptionBase
105
			else if (DescriptionBase.class.isAssignableFrom(clazz)){
106
				getDescriptionService().updateCaches((Class) clazz, null, null, null);
107
			}
108
			//Media
109
			else if (Media.class.isAssignableFrom(clazz)){
110
				getMediaService().updateCaches((Class) clazz, null, null, null);
111
			}//TaxonBase
112
			else if (TaxonBase.class.isAssignableFrom(clazz)){
113
				getTaxonService().updateCaches((Class) clazz, null, null, null);
114
			}
115
			//IdentifiableMediaEntity
116
			else if (AgentBase.class.isAssignableFrom(clazz)){
117
				getAgentService().updateCaches((Class) clazz, null, null, null);
118
			}else if (Collection.class.isAssignableFrom(clazz)){
119
				getCollectionService().updateCaches((Class) clazz, null, null, null);
120
			}else if (Reference.class.isAssignableFrom(clazz)){
121
				getReferenceService().updateCaches((Class) clazz, null, null, null);
122
			//Occurrence
123
			}else if (SpecimenOrObservationBase.class.isAssignableFrom(clazz)){
124
				getOccurrenceService().updateCaches((Class) clazz, null, null, null);
125
			}
126
//			//Sequence  //currently not identifiable and therefore has not caches
127
//			else if (Sequence.class.isAssignableFrom(clazz)){
128
//				//TODO misuse TaxonService for sequence update, use sequence service when it exists
129
//				getTaxonService().updateTitleCache((Class) clazz, null, null, null);
130
//			}
131
			//TaxonName
132
			else if (TaxonName.class.isAssignableFrom(clazz)){
133
				getNameService().updateCaches((Class) clazz, null, null, null);
134
			}
135
			//Classification
136
			else if (Classification.class.isAssignableFrom(clazz)){
137
				getClassificationService().updateCaches((Class) clazz, null, null, null);
138
			}
139
			//Polytomous Key
140
            else if (PolytomousKey.class.isAssignableFrom(clazz)){
141
                getPolytomousKeyService().updateCaches((Class) clazz, null, null, null);
142
            }
143
            //DescriptiveDataSet
144
            else if (DescriptiveDataSet.class.isAssignableFrom(clazz)){
145
                getDescriptiveDataSetService().updateCaches((Class) clazz, null, null, null);
146
            }
147
            //FeatureTree
148
            else if (FeatureTree.class.isAssignableFrom(clazz)){
149
                getFeatureTreeService().updateCaches((Class) clazz, null, null, null);
150
            }
151
			//unknown class
152
			else {
153
				String warning = "Unknown identifable entity subclass + " + clazz.getName();
154
				logger.error(warning);
155
				return false;
156
			}
157
			return true;
158
		} catch (Exception e) {
159
			String warning = "Exception occurred when trying to update class + " + clazz.getName();
160
			warning += " Exception was: " + e.getMessage();
161
			logger.error(warning);
162
			e.printStackTrace();
163
			return false;
164
		}
165
	}
166

  
167
	private void createClassListFromBoolean() {
168
		logger.warn("Create class list from boolean not yet implemented. Can't run cache updater");
169
	}
170

  
171

  
172
// ************* inherited form CdmIoBase but not needed here ********************/
173

  
174
	@Override
175
	protected boolean doCheck(DefaultImportState<CacheUpdaterConfigurator> state) {
176
		//not needed here
177
		return false;
178
	}
179

  
180
	@Override
181
	protected boolean isIgnore(DefaultImportState<CacheUpdaterConfigurator> state) {
182
		//not needed here
183
		return false;
184
	}
185

  
186
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/util/CacheUpdater.java
26 26
import eu.etaxonomy.cdm.api.service.config.CacheUpdaterConfigurator;
27 27
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
28 28
import eu.etaxonomy.cdm.model.agent.AgentBase;
29
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
30 29
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
31
import eu.etaxonomy.cdm.model.common.TermBase;
32
import eu.etaxonomy.cdm.model.common.TermVocabulary;
33 30
import eu.etaxonomy.cdm.model.description.DescriptionBase;
34 31
import eu.etaxonomy.cdm.model.description.FeatureTree;
35 32
import eu.etaxonomy.cdm.model.description.PolytomousKey;
......
42 39
import eu.etaxonomy.cdm.model.reference.Reference;
43 40
import eu.etaxonomy.cdm.model.taxon.Classification;
44 41
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
42
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
43
import eu.etaxonomy.cdm.model.term.TermBase;
44
import eu.etaxonomy.cdm.model.term.TermVocabulary;
45 45

  
46 46

  
47 47
@Component

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)