Project

General

Profile

« Previous | Next » 

Revision 2e477cf4

Added by Andreas Müller almost 7 years ago

clean up old cyprus import activators

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/cyprus/CyprusAltitudeActivator.java
53 53

  
54 54
	//database validation status (create, update, validate ...)
55 55
	static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
56
//	static final URI source = cyprus_distribution();
57 56
	static final URI source = cyprus_altitude();
58 57

  
59 58

  
......
91 90

  
92 91
		CdmApplicationController app = CdmIoApplicationController.NewInstance(cdmDestination, hbm2dll);
93 92

  
94
		Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>();
93
		Set<TaxonBase> taxaToSave = new HashSet<>();
95 94

  
96 95
		TransactionStatus tx = app.startTransaction();
97 96

  
......
101 100
		Reference mikle77 = app.getReferenceService().find(uuidMikle77);
102 101
		Reference mikle85 = app.getReferenceService().find(uuidMikle85);
103 102

  
104

  
105 103
		Feature altitudeFeature = (Feature) app.getTermService().find(uuidAltitudeFeature);
106 104
		if (altitudeFeature == null){
107
//			altitudeFeature = Feature.NewInstance("Altitude", "Altitude", "alt.");
108
//			altitudeFeature.setUuid(uuidAltitudeFeature);
109
//			featureVoc = app.getVocabularyService().find(UUID.fromString("b187d555-f06f-4d65-9e53-da7c93f8eaa8"));
110
//			featureVoc.addTerm(altitudeFeature);
111 105
			throw new RuntimeException("Could not find altitudinal range feature");
112 106
		}
113 107

  
114 108
		MeasurementUnit meter = (MeasurementUnit)app.getTermService().find(UUID.fromString("8bef5055-789c-41e5-bea2-8dc2ea8ecdf6"));
115
//		NamedArea cyprus = (NamedArea)app.getTermService().find(UUID.fromString("da4cce9a-439b-4cc4-8073-85dc75bae169"));
116 109

  
117 110
		int count =1;
118 111
		for (HashMap<String, String> row : excel){
......
121 114
			UUID acceptedUuid = makeUuid(row, "acceptedNameUuid");
122 115
			UUID parentUuid = makeUuid(row, "parentUuid");
123 116

  
124
//			String altitude = row.get("Altitude-kumuliert");
125

  
126 117
			String altitudeMin = row.get("Min");
127 118
			String altitudeMax = row.get("Max");
128 119
			String acceptedName = row.get("AcceptedName");
129 120

  
130

  
131

  
132 121
			String source = row.get("Source");
133 122

  
134 123
			if (StringUtils.isBlank(altitudeMin)){
......
142 131
				TaxonDescription desc = getDescription(taxon, sourceRef);
143 132

  
144 133
				hasAltitude = makeAltitude(altitudeMin, altitudeMax, altitudeFeature, sourceRef, desc, meter, count);
145
//				hasAltitude = makeAltitudeOld(altitude, altitudeFeature, sourceRef, desc, meter, count);
146 134
				if (hasAltitude){
147 135
					if(desc.getTaxon() == null){
148 136
						taxon.addDescription(desc);
......
158 146

  
159 147
		app.getTaxonService().saveOrUpdate(taxaToSave);
160 148

  
161
//		tx.setRollbackOnly();
162 149
		app.commitTransaction(tx);
163 150
	}
164 151

  
165 152

  
166 153
	private Taxon getTaxon(CdmApplicationController app, UUID baseUuid, UUID acceptedUuid, UUID parentUuid, String acceptedName, int row) {
167 154
		TaxonBase<?> base = app.getTaxonService().find(baseUuid);
168
//		TaxonBase<?> parent = app.getTaxonService().find(parentUuid);
169 155

  
170
		//TODO
171 156
		Taxon result = null;
172 157
		if (base.isInstanceOf(Taxon.class)){
173 158
			Taxon t = CdmBase.deproxy(base, Taxon.class);
......
227 212
			TaxonNameBase<?,?> nameUsedInSource = null;  //TODO
228 213
			data.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, sourceRef, null, nameUsedInSource, null);
229 214
		}
230
//		//Excel   //excel source not wanted by Ralf
231
//		TaxonNameBase<?,?> nameUsedInSource = null;  //TODO probably we don't want this
232
//		data.addSource(OriginalSourceType.Import, String.valueOf(row), "row", getSourceReference(), null, nameUsedInSource, null);
233

  
234 215
		data.setUnit(meter);
235 216

  
236 217
		Integer min = Integer.valueOf(altitudeMin);
......
245 226
		return true;
246 227
	}
247 228

  
248
//	private boolean makeAltitudeOld(String altitudeOrig, Feature feature, Reference source, TaxonDescription desc, MeasurementUnit meter, int row) {
249
//		String altitude = altitudeOrig.trim().replace(" ", "");
250
//		Matcher matcher = altitudePattern.matcher(altitude);
251
//
252
//		if (matcher.matches()){
253
//			QuantitativeData data = QuantitativeData.NewInstance(feature);
254
//
255
//			//Meikle
256
//			if (source != null){
257
//				TaxonNameBase<?,?> nameUsedInSource = null;  //TODO
258
//				data.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, source, null, nameUsedInSource, null);
259
//			}
260
//			//Excel
261
//			TaxonNameBase<?,?> nameUsedInSource = null;  //TODO probably we don't want this
262
//			data.addSource(OriginalSourceType.Import, String.valueOf(row), "row", getSourceReference(), null, nameUsedInSource, null);
263
//			data.setUnit(meter);
264
//
265
//			String[] split = altitude.split("-");
266
//
267
//			Integer min = Integer.valueOf(split[0]);
268
//			StatisticalMeasurementValue minValue = StatisticalMeasurementValue.NewInstance(StatisticalMeasure.MIN(), min);
269
//			data.addStatisticalValue(minValue);
270
//
271
//			if (split.length > 1){
272
//				Integer max = Integer.valueOf(split[1]);
273
//				StatisticalMeasurementValue maxValue = StatisticalMeasurementValue.NewInstance(StatisticalMeasure.MAX(), max);
274
//				data.addStatisticalValue(maxValue);
275
//			}
276
//			desc.addElement(data);
277
//			return true;
278
//		}else{
279
//			logger.warn("Altitude does not match in row " + row + ": "  + altitudeOrig);
280
//			return false;
281
//		}
282
//	}
283

  
284 229
	private TaxonDescription getDescription(Taxon taxon, Reference sourceRef) {
285 230
		if (taxon != null){
286 231
			//TODO Mikle existiert derzeit nicht also Source
......
320 265
		}
321 266
	}
322 267

  
323
//	private void getRowValues(HashMap<String, String> row) {
324
//		// TODO Auto-generated method stub
325
//		HashMap<String, Object> = new HashM
326
//		row
327
//
328
//
329
//	}
330

  
331

  
332 268
	Reference sourceReference;
333 269
	private Reference getSourceReference() {
334 270
		if (sourceReference == null){
335 271
			sourceReference = ReferenceFactory.newGeneric();
336 272
			sourceReference.setTitleCache(sourceReferenceTitle, true);
337

  
338 273
		}
339 274
		return sourceReference;
340 275

  
341 276
	}
342 277

  
343

  
344 278
	//Cyprus
345 279
	public static URI cyprus_altitude() {
346 280
		URI sourceUrl;
......
361 295
	public static void main(String[] args) {
362 296
		CyprusAltitudeActivator me = new CyprusAltitudeActivator();
363 297
		me.doImport(cdmDestination);
364
		me.testMatcher();
365
	}
366

  
367
	private void testMatcher() {
368
//		makeAltitude("0-4400", null, null);
369

  
370 298
	}
371 299

  
372 300
}
app-import/src/main/java/eu/etaxonomy/cdm/io/cyprus/CyprusUserImport.java
1 1
/**
2 2
 * Copyright (C) 2007 EDIT
3
 * European Distributed Institute of Taxonomy 
3
 * European Distributed Institute of Taxonomy
4 4
 * http://www.e-taxonomy.eu
5
 * 
5
 *
6 6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
 * See LICENSE.TXT at the top of this package for the full license terms.
8 8
 */
......
10 10
package eu.etaxonomy.cdm.io.cyprus;
11 11

  
12 12
import org.apache.log4j.Logger;
13
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
14
import org.springframework.security.core.Authentication;
15
import org.springframework.security.core.context.SecurityContextHolder;
16 13
import org.springframework.stereotype.Component;
17 14

  
18 15
import eu.etaxonomy.cdm.io.common.CdmImportBase;
19
import eu.etaxonomy.cdm.model.common.User;
20 16

  
21 17
/**
22 18
 * @author a.babadshanjan
23 19
 * @created 08.01.2009
24
 * @version 1.0
25 20
 */
26 21

  
27 22
@Component
28 23
public class CyprusUserImport extends CdmImportBase<CyprusImportConfigurator, CyprusImportState> {
29
	private static final Logger logger = Logger.getLogger(CyprusUserImport.class);
30
	
24
    private static final long serialVersionUID = 3941622961913569851L;
25
    private static final Logger logger = Logger.getLogger(CyprusUserImport.class);
26

  
31 27
	@Override
32 28
	protected boolean isIgnore(CyprusImportState state) {
33 29
		return ! state.getConfig().isDoTaxa();
34 30
	}
35
	
36
	
37
	/* (non-Javadoc)
38
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
39
	 */
31

  
40 32
	@Override
41 33
	protected boolean doCheck(CyprusImportState state) {
42 34
		logger.warn("DoCheck not yet implemented for CyprusExcelImport");
......
47 39
	@Override
48 40
	protected void doInvoke(CyprusImportState state) {
49 41
		this.getAuthenticationManager();
50
		
51
		String username = "cmi";
52
		String password = "fasfowjo0490";
53
		String personTitle = "Cyprus initial import";
54
		User user = User.NewInstance(personTitle, username, password);
55
//		user.setAccountNonLocked(false);
56
//		user.setEnabled(false);
57
		getUserService().save(user);
58
		UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
59
		Authentication authentication = getAuthenticationManager().authenticate(token);
60
		
61
		SecurityContextHolder.getContext().setAuthentication(authentication);
62
		
63
		
64
		username = "zypern";
65
		password = "r4i6wpo";
66
		personTitle = "Cyprus editor";
67
		User userZypern = User.NewInstance(personTitle, username, password);
68
		getUserService().save(userZypern);
69
		
70
		
71 42

  
72 43
		return;
73 44
	}
74 45

  
75

  
76
	
77 46
}

Also available in: Unified diff