Project

General

Profile

Revision 4df9f28c

ID4df9f28c23998e62035910674f29e9ee11610fc3
Parent 05f33e9b
Child 28fe8728

Added by Andreas Müller over 2 years ago

ref #3740 refactor operations in io layer

  • move operations and operation configurators to a separate package (remove from common package) as they are not realy related to import or export
  • operations are long running tasks using the io framework but not importing or exporting data

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/CacheUpdater.java
1
package eu.etaxonomy.cdm.io.common;
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.model.agent.AgentBase;
10
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
11
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
12
import eu.etaxonomy.cdm.model.common.TermBase;
13
import eu.etaxonomy.cdm.model.common.TermVocabulary;
14
import eu.etaxonomy.cdm.model.description.DescriptionBase;
15
import eu.etaxonomy.cdm.model.description.FeatureTree;
16
import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
17
import eu.etaxonomy.cdm.model.media.Media;
18
import eu.etaxonomy.cdm.model.molecular.Sequence;
19
import eu.etaxonomy.cdm.model.name.TaxonName;
20
import eu.etaxonomy.cdm.model.occurrence.Collection;
21
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
22
import eu.etaxonomy.cdm.model.reference.Reference;
23
import eu.etaxonomy.cdm.model.taxon.Classification;
24
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
25

  
26

  
27
@Component
28
public class CacheUpdater extends CdmImportBase<CacheUpdaterConfigurator, DefaultImportState<CacheUpdaterConfigurator>> {
29

  
30
    private static final long serialVersionUID = -1410600568024821771L;
31

  
32
    private static final Logger logger = Logger.getLogger(CacheUpdater.class);
33

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

  
43
		//handle class list
44
		handleClassList(config.getClassList());
45

  
46
		return;
47
	}
48

  
49

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

  
63
	private boolean handleMultiTableClasses(Class<? extends IdentifiableEntity> clazz) {
64
		if (clazz.isAssignableFrom(IdentifiableEntity.class)){
65
			List list = Arrays.asList(new Class[]{
66
					DescriptionBase.class, IdentifiableMediaEntity.class,
67
					Media.class, Sequence.class,
68
					TaxonBase.class, TaxonName.class,
69
					Classification.class, TermBase.class
70
					});
71
			handleClassList(list);
72
		}else if (clazz.isAssignableFrom(IdentifiableMediaEntity.class)){
73
			List list = Arrays.asList(new Class[]{AgentBase.class, Collection.class, Reference.class, SpecimenOrObservationBase.class});
74
			handleClassList(list);
75
		}else if (clazz.isAssignableFrom(TermBase.class)){
76
			List list = Arrays.asList(new Class[]{DefinedTermBase.class, FeatureTree.class, TermVocabulary.class });
77
			handleClassList(list);
78
		}else{
79
			return false;
80
		}
81
		return true;
82
	}
83

  
84
	private boolean handleSingleTableClass(Class<? extends IdentifiableEntity> clazz) {
85
		logger.warn("Updating class " + clazz.getSimpleName() + " ...");
86
		try {
87
			//TermBase
88
			if (DefinedTermBase.class.isAssignableFrom(clazz)){
89
				getTermService().updateTitleCache((Class) clazz, null, null, null);
90
			}else if (FeatureTree.class.isAssignableFrom(clazz)){
91
				getFeatureTreeService().updateTitleCache((Class) clazz, null, null, null);
92
			}else if (TermVocabulary.class.isAssignableFrom(clazz)){
93
				getVocabularyService().updateTitleCache((Class) clazz, null, null, null);
94
			}
95
			//DescriptionBase
96
			else if (DescriptionBase.class.isAssignableFrom(clazz)){
97
				getDescriptionService().updateTitleCache((Class) clazz, null, null, null);
98
			}
99
			//Media
100
			else if (Media.class.isAssignableFrom(clazz)){
101
				getMediaService().updateTitleCache((Class) clazz, null, null, null);
102
			}//TaxonBase
103
			else if (TaxonBase.class.isAssignableFrom(clazz)){
104
				getTaxonService().updateTitleCache((Class) clazz, null, null, null);
105
			}
106
			//IdentifiableMediaEntity
107
			else if (AgentBase.class.isAssignableFrom(clazz)){
108
				getAgentService().updateTitleCache((Class) clazz, null, null, null);
109
			}else if (Collection.class.isAssignableFrom(clazz)){
110
				getCollectionService().updateTitleCache((Class) clazz, null, null, null);
111
			}else if (Reference.class.isAssignableFrom(clazz)){
112
				getReferenceService().updateTitleCache((Class) clazz, null, null, null);
113
			}else if (SpecimenOrObservationBase.class.isAssignableFrom(clazz)){
114
				getOccurrenceService().updateTitleCache((Class) clazz, null, null, null);
115
			}
116
			//Sequence
117
			else if (Sequence.class.isAssignableFrom(clazz)){
118
				//TODO misuse TaxonServic for sequence update, use sequence service when it exists
119
				getTaxonService().updateTitleCache((Class) clazz, null, null, null);
120
			}
121
			//TaxonName
122
			else if (TaxonName.class.isAssignableFrom(clazz)){
123
				getNameService().updateTitleCache((Class) clazz, null, null, null);
124
			}
125
			//Classification
126
			else if (Classification.class.isAssignableFrom(clazz)){
127
				getClassificationService().updateTitleCache((Class) clazz, null, null, null);
128
			}
129
			//unknown class
130
			else {
131
				String warning = "Unknown identifable entity subclass + " + clazz == null ? "null" : clazz.getName();
132
				logger.error(warning);
133
				return false;
134
				//getTaxonService().updateTitleCache((Class) clazz);
135
			}
136
			return true;
137
		} catch (Exception e) {
138
			String warning = "Exception occurred when trying to update class + " + clazz == null ? "null" : clazz.getName();
139
			warning += " Exception was: " + e.getMessage();
140
			logger.error(warning);
141
			e.printStackTrace();
142
			return false;
143
		}
144
	}
145

  
146
	private void createClassListFromBoolean() {
147
		logger.warn("Create class list from boolean not yet implemented. Can't run cache updater");
148
	}
149

  
150

  
151
// ************* inherited form CdmIoBase but not needed here ********************/
152

  
153
	@Override
154
	protected boolean doCheck(DefaultImportState<CacheUpdaterConfigurator> state) {
155
		//not needed here
156
		return false;
157
	}
158

  
159
	@Override
160
	protected boolean isIgnore(DefaultImportState<CacheUpdaterConfigurator> state) {
161
		//not needed here
162
		return false;
163
	}
164

  
165
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/CacheUpdaterConfigurator.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.cdm.io.common;
10

  
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.List;
14

  
15
import org.apache.log4j.Logger;
16

  
17
import eu.etaxonomy.cdm.database.ICdmDataSource;
18
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
19
import eu.etaxonomy.cdm.model.reference.Reference;
20

  
21
/**
22
 * @author a.mueller
23
 * @created 02-Jul-2010 13:06:43
24
 *
25
 */
26
public class CacheUpdaterConfigurator extends ImportConfiguratorBase<DefaultImportState<CacheUpdaterConfigurator>, Object> implements IImportConfigurator{
27
	@SuppressWarnings("unused")
28
	private static final Logger logger = Logger.getLogger(CacheUpdaterConfigurator.class);
29

  
30

  
31
	private boolean updateCacheStrategies = false;
32

  
33
	public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination){
34
		return new CacheUpdaterConfigurator(destination, false);
35
	}
36

  
37
	/**
38
	 * Returns a new Configurator with all boolean values set to false
39
	 * @param allFalse
40
	 * @return
41
	 */
42
	public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination, boolean allTrue){
43
		return new CacheUpdaterConfigurator(destination, allTrue);
44
	}
45

  
46
	public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination, List<Class<? extends IdentifiableEntity>> classList){
47
		CacheUpdaterConfigurator result = new CacheUpdaterConfigurator(destination, true);
48
		result.setClassList(classList);
49
		return result;
50
	}
51

  
52
	public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination, Collection<String> classListNames) throws ClassNotFoundException{
53
		CacheUpdaterConfigurator result = new CacheUpdaterConfigurator(destination, true);
54
		List<Class<? extends IdentifiableEntity>> classList = new ArrayList<Class<? extends IdentifiableEntity>>();
55
		for (String className : classListNames){
56
			Class clazz = Class.forName(className);
57
			classList.add(clazz);
58
		}
59
		result.setClassList(classList);
60
		return result;
61
	}
62

  
63
	public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination, Collection<String> classListNames, boolean doUpdateCacheStrategies) throws ClassNotFoundException{
64
		CacheUpdaterConfigurator result = new CacheUpdaterConfigurator(destination, false);
65
		List<Class<? extends IdentifiableEntity>> classList = new ArrayList<Class<? extends IdentifiableEntity>>();
66
		for (String className : classListNames){
67
			Class clazz = Class.forName(className);
68
			classList.add(clazz);
69
		}
70
		result.setClassList(classList);
71
		result.setUpdateCacheStrategy(doUpdateCacheStrategies);
72
		return result;
73
	}
74

  
75

  
76

  
77
//	//DescriptionBase
78
//	private boolean doTaxonDescription = true;
79
//	private boolean doSpecimenDescription = true;
80
//	private boolean doNameDescription = true;
81
//
82
//	//AgentBase
83
//	private boolean doPerson = true;
84
//	private boolean doTeam = true;
85
//	private boolean doInstitution = true;
86
//
87
//	//MediaEntities
88
//	private boolean doCollection = true;
89
//	private boolean doReferenceBase = true;
90
//
91
//	//SpecimenOrObservationBase
92
//	private boolean doFieldUnit = true;
93
//	private boolean doDeriveUnit = true;
94
//	private boolean doDnaSample = true;
95
//
96
//	//Media
97
//	private boolean doMedia = true;
98
//	private boolean doMediaKey = true;
99
//	private boolean doPhylogenticTree = true;
100
//
101
//
102
//	//TaxonBase
103
//	private boolean doTaxon = true;
104
//	private boolean doSynonym = true;
105
//
106
//	private boolean doSequence = true;
107
//
108
//	//Names
109
//	private boolean doTaxonName = true;
110
//
111
//	private boolean doClassification = true;
112
//
113
//	//TermBase
114
//	private boolean doFeatureTree = true;
115
//	private boolean doPolytomousKey = true;
116
//
117
//	private boolean doTermVocabulary = true;
118
//	private boolean doDefinedTermBase = true;
119
	private List<Class<? extends IdentifiableEntity>> classList;
120

  
121
	private CacheUpdaterConfigurator(ICdmDataSource destination, boolean allFalse){
122
		super(null);
123
		this.setDestination(destination);
124
		this.classList = new ArrayList<Class<? extends IdentifiableEntity>>();
125
		if (allFalse){
126
			//DescriptionBase
127
//			doTaxonDescription = false;
128
//			doSpecimenDescription = false;
129
//			doNameDescription = false;
130
//
131
//			//AgentBase
132
//			doPerson = false;
133
//			doTeam = false;
134
//			doInstitution = false;
135
//
136
//			//MediaEntities
137
//			doCollection = false;
138
//			doReferenceBase = false;
139
//
140
//			//SpecimenOrObservationBase
141
//			doFieldUnit = false;
142
//			doDeriveUnit = false;
143
//			doDnaSample = false;
144
//
145
//			//Media
146
//			doMedia = false;
147
//			doMediaKey = false;
148
//			doPhylogenticTree = false;
149
//
150
//
151
//			//TaxonBase
152
//			doTaxon = false;
153
//			doSynonym = false;
154
//
155
//			doSequence = false;
156
//
157
//			//Names
158
//			doTaxonName = false;
159
//
160
//			doClassification = false;
161
//
162
//			//TermBase
163
//			doFeatureTree = false;
164
//			doPolytomousKey = false;
165
//
166
//			doTermVocabulary = false;
167
//			doDefinedTermBase = false;
168
		}
169
	}
170

  
171

  
172

  
173
// **************** GETTER / SETTER ************************************
174

  
175

  
176
	public List<Class<? extends IdentifiableEntity>> getClassList(){
177
		return this.classList;
178
	}
179
	private void setClassList(List<Class<? extends IdentifiableEntity>> classList) {
180
		this.classList = classList;
181
	}
182

  
183

  
184
//	public void setDoTaxonDescription(boolean doTaxonDescription) {
185
//		this.doTaxonDescription = doTaxonDescription;
186
//	}
187
//	public boolean isDoTaxonDescription() {
188
//		return doTaxonDescription;
189
//	}
190
//	public void setDoSpecimenDescription(boolean doSpecimenDescription) {
191
//		this.doSpecimenDescription = doSpecimenDescription;
192
//	}
193
//	public boolean isDoSpecimenDescription() {
194
//		return doSpecimenDescription;
195
//	}
196
//	public void setDoNameDescription(boolean doNameDescription) {
197
//		this.doNameDescription = doNameDescription;
198
//	}
199
//	public boolean isDoNameDescription() {
200
//		return doNameDescription;
201
//	}
202
//	public void setDoPerson(boolean doPerson) {
203
//		this.doPerson = doPerson;
204
//	}
205
//	public boolean isDoPerson() {
206
//		return doPerson;
207
//	}
208
//	public void setDoTeam(boolean doTeam) {
209
//		this.doTeam = doTeam;
210
//	}
211
//	public boolean isDoTeam() {
212
//		return doTeam;
213
//	}
214
//	public void setDoInstitution(boolean doInstitution) {
215
//		this.doInstitution = doInstitution;
216
//	}
217
//	public boolean isDoInstitution() {
218
//		return doInstitution;
219
//	}
220
//	public void setDoCollection(boolean doCollection) {
221
//		this.doCollection = doCollection;
222
//	}
223
//	public boolean isDoCollection() {
224
//		return doCollection;
225
//	}
226
//	public void setDoReferenceBase(boolean doReferenceBase) {
227
//		this.doReferenceBase = doReferenceBase;
228
//	}
229
//	public boolean isDoReferenceBase() {
230
//		return doReferenceBase;
231
//	}
232
//	public void setDoFieldUnit(boolean doFieldUnit) {
233
//		this.doFieldUnit = doFieldUnit;
234
//	}
235
//	public boolean isDoFieldUnit() {
236
//		return doFieldUnit;
237
//	}
238
//	public void setDoDeriveUnit(boolean doDeriveUnit) {
239
//		this.doDeriveUnit = doDeriveUnit;
240
//	}
241
//	public boolean isDoDeriveUnit() {
242
//		return doDeriveUnit;
243
//	}
244
//	public void setDoDnaSample(boolean doDnaSample) {
245
//		this.doDnaSample = doDnaSample;
246
//	}
247
//	public boolean isDoDnaSample() {
248
//		return doDnaSample;
249
//	}
250
//	public void setDoMedia(boolean doMedia) {
251
//		this.doMedia = doMedia;
252
//	}
253
//	public boolean isDoMedia() {
254
//		return doMedia;
255
//	}
256
//	public void setDoMediaKey(boolean doMediaKey) {
257
//		this.doMediaKey = doMediaKey;
258
//	}
259
//	public boolean isDoMediaKey() {
260
//		return doMediaKey;
261
//	}
262
//	public void setDoPhylogenticTree(boolean doPhylogenticTree) {
263
//		this.doPhylogenticTree = doPhylogenticTree;
264
//	}
265
//	public boolean isDoPhylogenticTree() {
266
//		return doPhylogenticTree;
267
//	}
268
//	public void setDoTaxon(boolean doTaxon) {
269
//		this.doTaxon = doTaxon;
270
//	}
271
//	public boolean isDoTaxon() {
272
//		return doTaxon;
273
//	}
274
//	public void setDoSynonym(boolean doSynonym) {
275
//		this.doSynonym = doSynonym;
276
//	}
277
//	public boolean isDoSynonym() {
278
//		return doSynonym;
279
//	}
280
//	public void setDoSequence(boolean doSequence) {
281
//		this.doSequence = doSequence;
282
//	}
283
//	public boolean isDoSequence() {
284
//		return doSequence;
285
//	}
286
//	public void setDoClassification(boolean doClassification) {
287
//		this.doClassification = doClassification;
288
//	}
289
//	public boolean isDoClassification() {
290
//		return doClassification;
291
//	}
292
//	public void setDoFeatureTree(boolean doFeatureTree) {
293
//		this.doFeatureTree = doFeatureTree;
294
//	}
295
//	public boolean isDoFeatureTree() {
296
//		return doFeatureTree;
297
//	}
298
//	public void setDoPolytomousKey(boolean doPolytomousKey) {
299
//		this.doPolytomousKey = doPolytomousKey;
300
//	}
301
//	public boolean isDoPolytomousKey() {
302
//		return doPolytomousKey;
303
//	}
304
//	public void setDoTermVocabulary(boolean doTermVocabulary) {
305
//		this.doTermVocabulary = doTermVocabulary;
306
//	}
307
//	public boolean isDoTermVocabulary() {
308
//		return doTermVocabulary;
309
//	}
310
//	public void setDoDefinedTermBase(boolean doDefinedTermBase) {
311
//		this.doDefinedTermBase = doDefinedTermBase;
312
//	}
313
//	public boolean isDoDefinedTermBase() {
314
//		return doDefinedTermBase;
315
//	}
316

  
317
	@Override
318
	public Reference getSourceReference() {
319
		//not needed here
320
		return null;
321
	}
322

  
323
	@Override
324
	protected void makeIoClassList() {
325
		if (this.doUpdateCacheStrategy()){
326
			ioClassList = new Class[]{
327
					 CacheUpdaterWithNewCacheStrategy.class
328
			};
329
		}else{
330
			ioClassList = new Class[]{
331
					 CacheUpdater.class
332
			};
333
			}
334
	}
335

  
336
	@Override
337
	public <STATE extends ImportStateBase> STATE getNewState() {
338
		return (STATE) new DefaultImportState(this);
339
	}
340

  
341
	@Override
342
	public boolean isValid() {
343
		//as no source needs to exist
344
		return true;
345
	}
346

  
347
	@Override
348
	public String getSourceNameString() {
349
		//not needed here
350
		return null;
351
	}
352

  
353
	public boolean doUpdateCacheStrategy() {
354
		return updateCacheStrategies;
355
	}
356

  
357
	public void setUpdateCacheStrategy(boolean doUpdateCacheStrategies){
358
		this.updateCacheStrategies = doUpdateCacheStrategies;
359
	}
360

  
361
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/CacheUpdaterWithNewCacheStrategy.java
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.TaxonName;
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
			//TaxonName
89
			else if (TaxonName.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
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/CacheUpdaterWrapper.java
1
/**
2
* Copyright (C) 2016 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.cdm.io.common;
10

  
11
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
12
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
13

  
14
/**
15
 * @author k.luther
16
 * @date 08.12.2016
17
 *
18
 */
19
public class CacheUpdaterWrapper extends CdmImportBase<CacheUpdaterConfigurator, DefaultImportState<CacheUpdaterConfigurator>> {
20

  
21
    /**
22
     * {@inheritDoc}
23
     */
24
    @Override
25
    protected void doInvoke(DefaultImportState<CacheUpdaterConfigurator> state) {
26
        CacheUpdaterConfigurator config = state.getConfig();
27
        CacheUpdater updater;
28

  
29
       // CaseType caseType = CaseType.caseTypeOfDatasource(config.getDestination());
30
        IProgressMonitor  monitor = DefaultProgressMonitor.NewInstance();
31
        updater = new CacheUpdater();
32
        updater.invoke(state);
33

  
34
        return;
35

  
36
    }
37

  
38
    /**
39
     * {@inheritDoc}
40
     */
41
    @Override
42
    protected boolean doCheck(DefaultImportState<CacheUpdaterConfigurator> state) {
43
        // TODO Auto-generated method stub
44
        return false;
45
    }
46

  
47
    /**
48
     * {@inheritDoc}
49
     */
50
    @Override
51
    protected boolean isIgnore(DefaultImportState<CacheUpdaterConfigurator> state) {
52
        // TODO Auto-generated method stub
53
        return false;
54
    }
55

  
56
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/DeleteNonReferencedReferencesConfigurator.java
1
package eu.etaxonomy.cdm.io.common;
2

  
3
import org.apache.log4j.Logger;
4

  
5
import eu.etaxonomy.cdm.database.DbSchemaValidation;
6
import eu.etaxonomy.cdm.database.ICdmDataSource;
7
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
8
import eu.etaxonomy.cdm.model.reference.Reference;
9

  
10
public class DeleteNonReferencedReferencesConfigurator extends ImportConfiguratorBase<DefaultImportState<DeleteNonReferencedReferencesConfigurator>, Object> implements IImportConfigurator{
11

  
12
	private boolean doReferences = true;
13
	private boolean doAuthors = true;	
14
	
15
	public boolean isDoReferences() {
16
		return doReferences;
17
	}
18

  
19
	public void setDoReferences(boolean doReferences) {
20
		this.doReferences = doReferences;
21
	}
22

  
23
	public boolean isDoAuthors() {
24
		return doAuthors;
25
	}
26

  
27
	public void setDoAuthors(boolean doAuthors) {
28
		this.doAuthors = doAuthors;
29
	}
30

  
31
	public DeleteNonReferencedReferencesConfigurator(
32
			IInputTransformer transformer) {
33
		super(transformer);
34
		// TODO Auto-generated constructor stub
35
	}
36

  
37
	public DeleteNonReferencedReferencesConfigurator() {
38
		super(null);
39
	}
40

  
41
	public DeleteNonReferencedReferencesConfigurator(ICdmDataSource destination) {
42
		super(null);
43
		this.setSource(destination);
44
		this.setDestination(destination);
45
		this.setDbSchemaValidation(DbSchemaValidation.UPDATE);
46
		
47
	}
48

  
49
	@SuppressWarnings("unused")
50
	private static final Logger logger = Logger.getLogger(CacheUpdaterConfigurator.class);
51

  
52
	public static DeleteNonReferencedReferencesConfigurator NewInstance(ICdmDataSource destination){
53
		DeleteNonReferencedReferencesConfigurator result = new DeleteNonReferencedReferencesConfigurator(destination);
54
		return result;
55
	}
56
	
57
	
58
	
59
	@Override
60
	public <STATE extends ImportStateBase> STATE getNewState() {
61
		return (STATE) new DefaultImportState(this);
62
	}
63

  
64
	@Override
65
	protected void makeIoClassList() {
66
		ioClassList = new Class[]{
67
				 DeleteNonReferencedreferencesUpdater.class
68
		};	
69
	}
70

  
71
	@Override
72
	public Reference getSourceReference() {
73
		// TODO Auto-generated method stub
74
		return null;
75
	}
76

  
77
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/DeleteNonReferencedreferencesUpdater.java
1
package eu.etaxonomy.cdm.io.common;
2

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

  
6
import org.springframework.stereotype.Component;
7

  
8
import eu.etaxonomy.cdm.api.service.DeleteResult;
9
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
10
import eu.etaxonomy.cdm.model.common.CdmBase;
11
import eu.etaxonomy.cdm.model.reference.Reference;
12
@Component
13

  
14
public class DeleteNonReferencedreferencesUpdater extends CdmImportBase<DeleteNonReferencedReferencesConfigurator, DefaultImportState<DeleteNonReferencedReferencesConfigurator>> {
15

  
16

  
17
	@Override
18
	protected void doInvoke(
19
			DefaultImportState<DeleteNonReferencedReferencesConfigurator> state) {
20

  
21
		if (state.getConfig().isDoAuthors()){
22
			List<TeamOrPersonBase> authors =getAgentService().list(TeamOrPersonBase.class, null, null, null, null);
23
			DeleteResult result;
24
			int deleted = 0;
25
			System.out.println("There are " + authors.size() + " authors");
26
			for (TeamOrPersonBase author: authors){
27
				Set<CdmBase> refObjects = getCommonService().getReferencingObjects(author);
28
				if (refObjects.isEmpty()) {
29
					result = getAgentService().delete(author);
30
					deleted++;
31
					if (!result.isOk()){
32
						System.out.println("Author " + author.getTitleCache() + " with id " + author.getId() + " could not be deleted.");
33
						result = null;
34
					}
35
				}
36
			}
37
			System.out.println(deleted + " authors are deleted.");
38
		}
39
		if (state.getConfig().isDoReferences()){
40
			List<Reference> references =getReferenceService().list(Reference.class, null, null, null, null);
41
			DeleteResult result;
42
			int deleted = 0;
43
			System.out.println("There are " + references.size() + " references");
44
			for (Reference ref: references){
45
				Set<CdmBase> refObjects = getCommonService().getReferencingObjects(ref);
46
				if (refObjects.isEmpty()) {
47
					result = getReferenceService().delete(ref);
48
					deleted++;
49
					if (!result.isOk()){
50
						System.out.println("Reference " + ref.getTitle() + " with id " + ref.getId() + " could not be deleted.");
51
						result = null;
52
					}
53
				}
54
			}
55
			System.out.println(deleted + " references are deleted.");
56
		}
57
	}
58

  
59
	@Override
60
	protected boolean doCheck(
61
			DefaultImportState<DeleteNonReferencedReferencesConfigurator> state) {
62
		// TODO Auto-generated method stub
63
		return false;
64
	}
65

  
66
	@Override
67
	protected boolean isIgnore(
68
			DefaultImportState<DeleteNonReferencedReferencesConfigurator> state) {
69
		// TODO Auto-generated method stub
70
		return false;
71
	}
72

  
73

  
74
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/SecundumUpdater.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.cdm.io.common;
10

  
11
import org.apache.log4j.Logger;
12
import org.springframework.beans.BeansException;
13
import org.springframework.context.ApplicationContext;
14
import org.springframework.stereotype.Component;
15

  
16
import eu.etaxonomy.cdm.api.service.UpdateResult;
17

  
18
/**
19
 * @author k.luther
20
 * @date 14.03.2017
21
 *
22
 */
23
@Component
24
public class SecundumUpdater extends CdmImportBase<SetSecundumForSubtreeConfigurator, DefaultImportState<SetSecundumForSubtreeConfigurator>>  {
25
    /**
26
     *
27
     */
28
    private static final long serialVersionUID = 6788425152444747546L;
29

  
30
    private static final Logger logger = Logger.getLogger(SecundumUpdater.class);
31

  
32

  
33
    /**
34
     * {@inheritDoc}
35
     */
36
    @Override
37
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
38
        this.applicationContext = applicationContext;
39

  
40
    }
41
    /**
42
     * {@inheritDoc}
43
     */
44
    @Override
45
    protected void doInvoke(DefaultImportState<SetSecundumForSubtreeConfigurator> state) {
46
        SetSecundumForSubtreeConfigurator config = state.getConfig();
47
        state.getConfig().getProgressMonitor().beginTask("Update Secundum References ", 100);
48

  
49
        UpdateResult result = getTaxonNodeService().setSecundumForSubtree(config.getSubtreeUuid(),  config.getNewSecundum(), config.isIncludeAcceptedTaxa(), config.isIncludeSynonyms(), config.isOverwriteExistingAccepted(), config.isOverwriteExistingSynonyms(), config.isIncludeSharedTaxa(), config.isEmptySecundumDetail(), config.getProgressMonitor());
50

  
51
        return;
52

  
53
    }
54
    /**
55
     * {@inheritDoc}
56
     */
57
    @Override
58
    protected boolean doCheck(DefaultImportState<SetSecundumForSubtreeConfigurator> state) {
59
        // TODO Auto-generated method stub
60
        return true;
61
    }
62
    /**
63
     * {@inheritDoc}
64
     */
65
    @Override
66
    protected boolean isIgnore(DefaultImportState<SetSecundumForSubtreeConfigurator> state) {
67
        // TODO Auto-generated method stub
68
        return false;
69
    }
70

  
71

  
72

  
73
}
74

  
75

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/SetSecundumForSubtreeConfigurator.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.cdm.io.common;
10

  
11
import java.util.UUID;
12

  
13
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
14
import eu.etaxonomy.cdm.model.reference.Reference;
15

  
16
/**
17
 * Configurator for the setSecundumForSubtree operation.
18
 *
19
 * @author a.mueller
20
 * @date 06.01.2017
21
 *
22
 */
23
public class SetSecundumForSubtreeConfigurator extends ImportConfiguratorBase<DefaultImportState<SetSecundumForSubtreeConfigurator>, Object> implements IImportConfigurator{
24
    private UUID subtreeUuid;
25
    private Reference newSecundum;
26
    private boolean includeAcceptedTaxa = true;
27
    private boolean includeSynonyms = true;
28
    private boolean overwriteExistingAccepted = true;
29
    private boolean overwriteExistingSynonyms = true;
30
    private boolean emptySecundumDetail = true;
31
    private boolean includeSharedTaxa = true;
32
    private IProgressMonitor monitor;
33

  
34
    /**
35
     * @param monitor the monitor to set
36
     */
37
    public void setMonitor(IProgressMonitor monitor) {
38
        this.monitor = monitor;
39
    }
40

  
41
    /**
42
     * @param subtreeUuid
43
     * @param newSecundum
44
     */
45
    public SetSecundumForSubtreeConfigurator(UUID subtreeUuid, Reference newSecundum, IProgressMonitor monitor) {
46
        super(null);
47
        this.subtreeUuid = subtreeUuid;
48
        this.newSecundum = newSecundum;
49
        this.monitor = monitor;
50
    }
51

  
52
    /**
53
     * @param subtreeUuid
54
     * @param newSecundum
55
     */
56
    public SetSecundumForSubtreeConfigurator(UUID subtreeUuid) {
57
        super(null);
58
        this.subtreeUuid = subtreeUuid;
59
        // this.newSecundum = newSecundum;
60
    }
61

  
62
    /**
63
     * @return the subtreeUuid
64
     */
65
    public UUID getSubtreeUuid() {
66
        return subtreeUuid;
67
    }
68

  
69
    /**
70
     * @param subtreeUuid
71
     *            the subtreeUuid to set
72
     */
73
    public void setSubtreeUuid(UUID subtreeUuid) {
74
        this.subtreeUuid = subtreeUuid;
75
    }
76

  
77
    /**
78
     * @return the newSecundum
79
     */
80
    public Reference getNewSecundum() {
81
        return newSecundum;
82
    }
83

  
84
    /**
85
     * @param newSecundum
86
     *            the newSecundum to set
87
     */
88
    public void setNewSecundum(Reference newSecundum) {
89
        this.newSecundum = newSecundum;
90
    }
91

  
92
    /**
93
     * @return the overrideExisting
94
     */
95
    public boolean isOverwriteExistingAccepted() {
96
        return overwriteExistingAccepted;
97
    }
98

  
99
    /**
100
     * @param overrideExisting
101
     *            the overrideExisting to set
102
     */
103
    public void setOverwriteExistingAccepted(boolean overwriteExistingAccepted) {
104
        this.overwriteExistingAccepted = overwriteExistingAccepted;
105
    }
106

  
107
    /**
108
     * @return the overrideExisting
109
     */
110
    public boolean isOverwriteExistingSynonyms() {
111
        return overwriteExistingSynonyms;
112
    }
113

  
114
    /**
115
     * @param overrideExisting
116
     *            the overrideExisting to set
117
     */
118
    public void setOverwriteExistingSynonyms(boolean overwriteExistingSynonyms) {
119
        this.overwriteExistingSynonyms = overwriteExistingSynonyms;
120
    }
121

  
122
    /**
123
     * @return the emptySecundumDetail
124
     */
125
    public boolean isEmptySecundumDetail() {
126
        return emptySecundumDetail;
127
    }
128

  
129
    /**
130
     * @param emptySecundumDetail
131
     *            the emptySecundumDetail to set
132
     */
133
    public void setEmptySecundumDetail(boolean emptySecundumDetail) {
134
        this.emptySecundumDetail = emptySecundumDetail;
135
    }
136

  
137
    /**
138
     * @return the includeSynonyms
139
     */
140
    public boolean isIncludeSynonyms() {
141
        return includeSynonyms;
142
    }
143

  
144
    /**
145
     * @param includeSynonyms
146
     *            the includeSynonyms to set
147
     */
148
    public void setIncludeSynonyms(boolean includeSynonyms) {
149
        this.includeSynonyms = includeSynonyms;
150
    }
151

  
152
    /**
153
     * @return the includeAcceptedTaxa
154
     */
155
    public boolean isIncludeAcceptedTaxa() {
156
        return includeAcceptedTaxa;
157
    }
158

  
159
    /**
160
     * @param includeAcceptedTaxa
161
     *            the includeAcceptedTaxa to set
162
     */
163
    public void setIncludeAcceptedTaxa(boolean includeAcceptedTaxa) {
164
        this.includeAcceptedTaxa = includeAcceptedTaxa;
165
    }
166

  
167
    /**
168
     * @return the includeSharedTaxa
169
     */
170
    public boolean isIncludeSharedTaxa() {
171
        return includeSharedTaxa;
172
    }
173

  
174
    /**
175
     * @param includeSharedTaxa
176
     *            the includeSharedTaxa to set
177
     */
178
    public void setIncludeSharedTaxa(boolean includeSharedTaxa) {
179
        this.includeSharedTaxa = includeSharedTaxa;
180
    }
181

  
182
    /**
183
     * @return
184
     */
185
    public IProgressMonitor getMonitor() {
186

  
187
        return monitor;
188
    }
189

  
190
    /**
191
     * {@inheritDoc}
192
     */
193
    @SuppressWarnings("rawtypes")
194
    @Override
195
    public DefaultImportState getNewState() {
196
      return new DefaultImportState(this);
197
    }
198

  
199
    /**
200
     * {@inheritDoc}
201
     */
202
    @Override
203
    protected void makeIoClassList() {
204
        ioClassList = new Class[]{
205
                SecundumUpdater.class
206
                };
207

  
208
    }
209

  
210
    /**
211
     * {@inheritDoc}
212
     */
213
    @Override
214
    public Reference getSourceReference() {
215
        // TODO Auto-generated method stub
216
        return null;
217
    }
218

  
219
    @Override
220
    public boolean isValid(){
221
        return true;
222
    }
223

  
224
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/SortIndexUpdaterConfigurator.java
1
/**
2
* Copyright (C) 2016 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.cdm.io.common;
10

  
11
import eu.etaxonomy.cdm.database.ICdmDataSource;
12
import eu.etaxonomy.cdm.model.reference.Reference;
13

  
14
/**
15
 * @author k.luther
16
 * @date 08.07.2016
17
 *
18
 */
19
public class SortIndexUpdaterConfigurator  extends ImportConfiguratorBase<DefaultImportState<SetSecundumForSubtreeConfigurator>, Object> implements IImportConfigurator{
20

  
21

  
22
    private boolean doTaxonNode = true;
23
    private boolean doFeatureNode = true;
24
    private boolean doPolytomousKeyNode = true;
25

  
26
    private String subTreeIndex = null;
27

  
28
    private SortIndexUpdaterConfigurator(ICdmDataSource destination){
29
        super(null);
30
        this.setDestination(destination);
31
    }
32

  
33
    /**
34
     * @param destination
35
     * @return
36
     */
37
    public static SortIndexUpdaterConfigurator NewInstance(ICdmDataSource destination) {
38
        SortIndexUpdaterConfigurator result = new SortIndexUpdaterConfigurator(destination);
39
        return result;
40
    }
41

  
42
    /**
43
     * @param destination
44
     * @return
45
     */
46
    public static SortIndexUpdaterConfigurator NewInstance(ICdmDataSource destination, boolean doTaxonNode, boolean doFeatureNode, boolean doPolytomousKeyNode) {
47
        SortIndexUpdaterConfigurator result = new SortIndexUpdaterConfigurator(destination);
48
        result.doFeatureNode = doFeatureNode;
49
        result.doTaxonNode = doTaxonNode;
50
        result.doPolytomousKeyNode = doPolytomousKeyNode;
51
        return result;
52
    }
53

  
54

  
55
 // **************** GETTER / SETTER ************************************
56

  
57

  
58
    /**
59
     * @return the doTaxonNode
60
     */
61
    public boolean isDoTaxonNode() {
62
        return doTaxonNode;
63
    }
64
    /**
65
     * @param doTaxonNode the doTaxonNode to set
66
     */
67
    public void setDoTaxonNode(boolean doTaxonNode) {
68
        this.doTaxonNode = doTaxonNode;
69
    }
70
    /**
71
     * @return the doPolytomousKeyNode
72
     */
73
    public boolean isDoPolytomousKeyNode() {
74
        return doPolytomousKeyNode;
75
    }
76
    /**
77
     * @param doPolytomousKeyNode the doPolytomousKeyNode to set
78
     */
79
    public void setDoPolytomousKeyNode(boolean doPolytomousKeyNode) {
80
        this.doPolytomousKeyNode = doPolytomousKeyNode;
81
    }
82
    /**
83
     * @return the doFeatureNode
84
     */
85
    public boolean isDoFeatureNode() {
86
        return doFeatureNode;
87
    }
88
    /**
89
     * @param doFeatureNode the doFeatureNode to set
90
     */
91
    public void setDoFeatureNode(boolean doFeatureNode) {
92
        this.doFeatureNode = doFeatureNode;
93
    }
94

  
95
    @Override
96
    public <STATE extends ImportStateBase> STATE getNewState() {
97
        return (STATE) new DefaultImportState(this);
98
    }
99

  
100

  
101
    @Override
102
    protected void makeIoClassList() {
103
        ioClassList = new Class[]{
104
                     SortIndexUpdaterWrapper.class
105
        };
106
    }
107

  
108

  
109
    @Override
110
    public Reference getSourceReference() {
111
        return null;
112
    }
113

  
114

  
115
    @Override
116
    public boolean isValid() {
117
        //as no source needs to exist
118
        return true;
119
    }
120

  
121

  
122
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/SortIndexUpdaterWrapper.java
1
/**
2
* Copyright (C) 2016 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.cdm.io.common;
10

  
11
import java.sql.SQLException;
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.Map;
15
import java.util.Set;
16

  
17
import org.apache.log4j.Logger;
18
import org.hibernate.SQLQuery;
19
import org.springframework.stereotype.Component;
20
import org.springframework.transaction.TransactionStatus;
21

  
22
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
23
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
24
import eu.etaxonomy.cdm.database.update.SortIndexUpdater;
25

  
26
/**
27
 * @author k.luther
28
 * @date 08.07.2016
29
 *
30
 */
31
@Component
32
public class SortIndexUpdaterWrapper extends CdmImportBase<SortIndexUpdaterConfigurator, DefaultImportState<SortIndexUpdaterConfigurator>> {
33

  
34
    private static final long serialVersionUID = 1152526455024556637L;
35
    private static final Logger logger = Logger.getLogger(SortIndexUpdaterWrapper.class);
36

  
37

  
38
    @Override
39
    protected void doInvoke(DefaultImportState<SortIndexUpdaterConfigurator> state) {
40
        SortIndexUpdaterConfigurator config =  state.getConfig();
41
        SortIndexUpdater updater;
42

  
43
       // CaseType caseType = CaseType.caseTypeOfDatasource(config.getDestination());
44
        IProgressMonitor  monitor = DefaultProgressMonitor.NewInstance();
45

  
46
        if (config.isDoTaxonNode()){
47
            updater = SortIndexUpdater.NewInstance("Update taxonnode sortindex", "TaxonNode", "parent_id", "sortIndex", true);
48

  
49
            update(updater, monitor);
50

  
51

  
52
        }
53
        if (config.isDoFeatureNode()){
54
            updater = SortIndexUpdater.NewInstance("Update Feature node sortindex", "FeatureNode", "parent_id", "sortIndex", true);
55
            update(updater, monitor);
56
        }
57
        if (config.isDoPolytomousKeyNode()){
58
            updater = SortIndexUpdater.NewInstance("Update Polytomouskey node sortindex", "PolytomousKeyNode", "parent_id", "sortindex", true);
59
           update(updater, monitor);
60
        }
61
        return;
62

  
63
    }
64

  
65
    private void update(SortIndexUpdater updater,  IProgressMonitor  monitor){
66
        try {
67
            TransactionStatus tx;
68
            tx = startTransaction();
69
            String query = updater.createIndexMapQuery();
70
            SQLQuery sqlQuery = getAgentService().getSession().createSQLQuery(query);
71

  
72
            List data = sqlQuery.list();
73

  
74
           List<Integer[]> result = new ArrayList<Integer[]>();
75
           int id;
76
           int parentId;
77
           Object oId;
78
           Object oParentId;
79
           Integer[] rowArray = new Integer[2];
80
            for(Object object : data)
81
            {
82
               Object[] row = (Object[])object;
83
               oId = row[0];
84

  
85
                if (oId != null){
86
                    id = Integer.valueOf(oId.toString());
87
                    rowArray = new Integer[2];
88
                    oParentId = row[1];
89
                    if (oParentId != null){
90
                        parentId = Integer.valueOf(oParentId.toString());
91
                        rowArray[1]= parentId;
92

  
93
                    }else{
94
                        rowArray[1]= null;
95
                    }
96
                    rowArray[0]= id;
97
                    result.add(rowArray);
98
                }
99
            }
100
            Map<Integer, Set<Integer>> indexMap =  updater.makeIndexMap(result);
101
            for (Map.Entry<Integer, Set<Integer>> entry: indexMap.entrySet()){
102
                String idSet = updater.makeIdSetString(entry.getValue());
103
                query = updater.createUpdateIndicesQuery(null,entry.getKey(), idSet);
104
                sqlQuery = getAgentService().getSession().createSQLQuery(query);
105
                int resultInt = sqlQuery.executeUpdate();
106
                logger.debug("update all indice with index "+entry.getKey()+ " - " + resultInt);
107
            }
108
            //Update childrenCount
109
            if (updater.getTableName().equals("TaxonNode")){
110
                query = updater.getChildrenCountQuery();
111
                sqlQuery = getTaxonNodeService().getSession().createSQLQuery(query);
112
                data = sqlQuery.list();
113
                int realCount;
114
                int countChildren;
115
                for(Object object : data)
116
                {
117
                   Object[] row = (Object[])object;
118
                   realCount =  ((Number) row[0]).intValue();
119
                   countChildren = ((Number) row[1]).intValue();
120
                   id = ((Number) row[2]).intValue();
121

  
122
                   if (realCount != countChildren){
123
                       query = updater.getUpdateChildrenCount(realCount, id);
124
                       sqlQuery = getTaxonNodeService().getSession().createSQLQuery(query);
125
                       int resultInt = sqlQuery.executeUpdate();
126
                       logger.debug("update all childrenCount "+ resultInt);
127
                   }
128
                 }
129
            }
130
              commitTransaction(tx);
131
        } catch (SQLException e) {
132

  
133
            monitor.warning("Stopped sortIndex updater");
134
        }
135
    }
136

  
137

  
138

  
139

  
140
    @Override
141
    protected boolean isIgnore(DefaultImportState<SortIndexUpdaterConfigurator> state) {
142
        // TODO Auto-generated method stub
143
        return false;
144
    }
145

  
146
    /**
147
     * {@inheritDoc}
148
     */
149
    @Override
150
    protected boolean doCheck(DefaultImportState<SortIndexUpdaterConfigurator> state) {
151
        // TODO Auto-generated method stub
152
        return true;
153
    }
154

  
155
}
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;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)