Project

General

Profile

Revision 8fb964f0

ID8fb964f0a493d038d5674385dc8dd4245b2b1e70
Parent deed567d
Child a9047fed

Added by Andreas Müller 9 months ago

ref #2826 cleanup

View differences:

cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumGeneraImport.java
78 78

  
79 79
				//Don't use (created bei Marc): DisplayName, NomRefCache
80 80

  
81
				Integer id =( (Number)rs.getObject("RECORD NUMBER")).intValue();
81
				Integer id = rs.getInt("RECORD NUMBER");
82 82

  
83 83
				String preferredName = rs.getString("NAME OF FUNGUS");
84 84
				if (StringUtils.isBlank(preferredName)){
......
96 96
				//author + publication
97 97
				makeAuthorAndPublication(state, rs, name);
98 98
				//source
99
				//makeSource(state, taxon, id, NAMESPACE_GENERA );
100
//				if (id != null){
101
					makeSource(state, taxon, id.intValue(), NAMESPACE_GENERA );
102
//				} else{
103
//					makeSource(state, taxon, null,NAMESPACE_GENERA);
104
//				}
99
				makeSource(state, taxon, id.intValue(), NAMESPACE_GENERA );
100

  
105 101
				getTaxonService().saveOrUpdate(taxon);
106 102
			}
107 103
		} catch (Exception e) {
......
153 149
	}
154 150

  
155 151
	@Override
156
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, IndexFungorumImportState state) {
157
		String nameSpace;
158
//		Class<?> cdmClass;
159
//		Set<String> idSet;
160
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
152
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(
153
	        ResultSet rs, IndexFungorumImportState state) {
154

  
155
	    Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
161 156

  
162 157
		try{
163
//			Set<String> taxonNameSet = new HashSet<>();
164
			while (rs.next()){
165
//				handleForeignKey(rs, taxonIdSet,"tu_accfinal" );
166
			}
167 158

  
168 159
			//taxon map
169
			nameSpace = NAMESPACE_SUPRAGENERIC_NAMES ;
170
//			cdmClass = Taxon.class;
171
//			idSet = taxonNameSet;
160
		    String nameSpace = NAMESPACE_SUPRAGENERIC_NAMES ;
172 161
			Map<String, TaxonBase<?>> taxonMap = new HashMap<>();
173 162
			@SuppressWarnings("rawtypes")
174 163
            List<TaxonBase> list = getTaxonService().listTaxaByName(Taxon.class, "*", null, null, null, "*", null, 1000000, null, null);
......
183 172
			referenceMap.put(SOURCE_REFERENCE, sourceReference);
184 173
			result.put(NAMESPACE_REFERENCE, referenceMap);
185 174

  
186
		} catch (SQLException e) {
175
		} catch (Exception e) {
187 176
			throw new RuntimeException(e);
188 177
		}
189 178
		return result;
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumHigherClassificationImport.java
14 14
import java.util.HashMap;
15 15
import java.util.List;
16 16
import java.util.Map;
17
import java.util.Set;
18 17

  
19 18
import org.apache.log4j.Logger;
20 19
import org.springframework.stereotype.Component;
......
167 166
					}
168 167
					taxonFamily = makeTaxon(state, family, Rank.FAMILY());
169 168
					if (taxonFamily != null){
170
						try{
169
					    try{
171 170
							//if this shows a warning see single issue in #2826 about Glomerellaceae (which has 2 different parents)
172 171
						    getClassification(state).addParentChild(higherTaxon, taxonFamily, null, null);
173 172
						}catch(IllegalStateException e){
174 173
							if (e.getMessage().startsWith("The child taxon is already part of the tree")){
175
								//TaxonNode node = getClassification(state).getNode(taxonFamily);
176 174
								logger.warn(e.getMessage() + taxonFamily.getTitleCache() + " " + higherTaxon.getTitleCache());
177 175
							}
178 176
						}
......
229 227
	@Override
230 228
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, IndexFungorumImportState state) {
231 229
		String nameSpace;
232
		Class<?> cdmClass;
233
		Set<String> idSet;
234 230
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
235 231

  
236 232
		try{
237
//			Set<String> taxonNameSet = new HashSet<>();
238
//			while (rs.next()){
239
//				handleForeignKey(rs, taxonIdSet,"tu_accfinal" );
240
//			}
241

  
242 233
			//taxon map
243 234
			nameSpace = IndexFungorumImportBase.NAMESPACE_SUPRAGENERIC_NAMES ;
244
			cdmClass = TaxonBase.class;
245
//			idSet = taxonNameSet;
246 235
			Map<String, TaxonBase<?>> taxonMap = new HashMap<>();
247 236
			List<Taxon> list = getTaxonService().list(Taxon.class, null, null, null, null);
248 237
			for (Taxon taxon : list){
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumImportBase.java
13 13
import java.sql.ResultSetMetaData;
14 14
import java.sql.SQLException;
15 15
import java.util.HashMap;
16
import java.util.HashSet;
17 16
import java.util.Map;
18 17
import java.util.Set;
19 18
import java.util.UUID;
......
52 51
 * @author a.mueller
53 52
 * @since 27.02.2012
54 53
 */
55
public abstract class IndexFungorumImportBase extends CdmImportBase<IndexFungorumImportConfigurator, IndexFungorumImportState> implements ICdmIO<IndexFungorumImportState>, IPartitionedIO<IndexFungorumImportState> {
54
public abstract class IndexFungorumImportBase
55
        extends CdmImportBase<IndexFungorumImportConfigurator, IndexFungorumImportState>
56
        implements ICdmIO<IndexFungorumImportState>, IPartitionedIO<IndexFungorumImportState> {
56 57

  
57 58
    private static final long serialVersionUID = -729872543287390949L;
58 59
    private static final Logger logger = Logger.getLogger(IndexFungorumImportBase.class);
......
105 106

  
106 107
    @Override
107 108
    public boolean doPartition(@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner, IndexFungorumImportState state) {
108

  
109
        boolean success = true ;
110
		Set<CdmBase> objectsToSave = new HashSet<>();
111

  
112
// 		DbImportMapping<?, ?> mapping = getMapping();
113
//		mapping.initialize(state, cdmTargetClass);
114

  
115
		ResultSet rs = partitioner.getResultSet();
116
		try{
117
			while (rs.next()){
118
//				success &= mapping.invoke(rs,objectsToSave);
119
			}
120
		} catch (SQLException e) {
121
			logger.error("SQLException:" +  e);
122
			return false;
123
		}
124

  
125
		partitioner.startDoSave();
126
		getCommonService().save(objectsToSave);
127
		return success;
109
        //should be overridden by subclasses if used
110
		return true;
128 111
	}
129 112

  
130 113
	protected abstract String getRecordQuery(IndexFungorumImportConfigurator config);
......
218 201

  
219 202
	/**
220 203
	 * Returns true if i is a multiple of recordsPerTransaction
221
	 * @param i
222
	 * @param recordsPerTransaction
223
	 * @return
224 204
	 */
225 205
	protected boolean loopNeedsHandling(int i, int recordsPerLoop) {
226 206
		startTransaction();
......
316 296
		}
317 297
		ref.setVolume(volume);
318 298

  
319
		//year   //TODO why yearOfPubl 2x exact same value
299
		//year
320 300
		String yearOfPubl = rs.getString("YEAR OF PUBLICATION");
321 301
		String yearOnPubl = rs.getString("YEAR ON PUBLICATION");
322 302
		String year = null;
......
330 310
			ref.setDatePublished(TimePeriodParser.parseStringVerbatim(year));
331 311
		}
332 312

  
333
		//preliminary, set protected titlecache as Generic Cache Generation with in references currently doesn't fully work yet
313
		//TODO preliminary, set protected titlecache as generic cache generation with in-references currently doesn't fully work yet
334 314
		String titleCache = CdmUtils.concat(", ", pubAuthorStr, title);
335
		if  ( StringUtils.isNotBlank(pubAuthorStr)){
315
		if  (isNotBlank(pubAuthorStr)){
336 316
			titleCache = "in " + titleCache;
337 317
		}
338 318
		titleCache = CdmUtils.concat(" ", titleCache, volume);
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumSpeciesImport.java
85 85

  
86 86
				//DisplayName, NomRefCache -> don't use, created by Marc
87 87

  
88
				Integer id = (Integer)rs.getObject("PreferredNameIFnumber");
88
				Integer id = rs.getInt("PreferredNameIFnumber");
89 89
				String phylumName = rs.getString("Phylum name");
90 90

  
91 91
				String preferredName = rs.getString("PreferredName");
......
125 125

  
126 126
				//save
127 127
				getTaxonService().saveOrUpdate(taxon);
128

  
129 128
			}
130 129
		} catch (Exception e) {
131 130
			e.printStackTrace();
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumSubSpeciesImport.java
26 26
public class IndexFungorumSubSpeciesImport extends IndexFungorumImportBase {
27 27

  
28 28
    private static final long serialVersionUID = -2877755674188760685L;
29
    private static final Logger logger = Logger.getLogger(IndexFungorumSpeciesImport.class);
29
    private static final Logger logger = Logger.getLogger(IndexFungorumSubSpeciesImport.class);
30 30

  
31 31
	private static final String pluralString = "subSpecies";
32 32

  
......
64 64

  
65 65
            TaxonName name = infraspecificTaxon.getName();
66 66

  
67
//            getNameService().saveOrUpdate(name);
68 67
            String parentNameString = getParentNameInfraSpecific(name);
69
//            System.out.println("Parent name string: " + parentNameString);
70 68
            MatchingTaxonConfigurator matchingConfig = new MatchingTaxonConfigurator();
71 69
            matchingConfig.setTaxonNameTitle(parentNameString);
72 70

  
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumSupraGeneraImport.java
50 50
		String strRecordQuery =
51 51
			" SELECT * " +
52 52
			" FROM [tblSupragenericNames] " +
53
//			" WHERE ( dr.id IN (" + ID_LIST_TOKEN + ") )";
54 53
			"";
55 54
		return strRecordQuery;
56 55
	}
......
59 58
	protected void doInvoke(IndexFungorumImportState state) {
60 59

  
61 60
	    logger.info("Start supra genera ...");
62
		//handle source reference first
61

  
62
	    //handle source reference first
63 63
		Reference sourceReference = state.getConfig().getSourceReference();
64 64
		getReferenceService().save(sourceReference);
65 65

  
......
77 77

  
78 78
				//Don't use (created by Marc): DisplayName, NomRefCache
79 79

  
80
				Integer id = ((Number)rs.getObject(COL_RECORD_NUMBER)).intValue();
80
				Integer id = rs.getInt(COL_RECORD_NUMBER);
81 81

  
82 82
				String supragenericNames = rs.getString(SUPRAGENERIC_NAMES);
83
				//String preferredName = rs.getString("PreferredName");
84 83
				Integer rankFk = rs.getInt("PESI_RankFk");
85 84

  
86 85
				//name
87 86
				Rank rank = state.getTransformer().getRankByKey(String.valueOf(rankFk));
88 87
				TaxonName name = TaxonNameFactory.NewBotanicalInstance(rank);
89 88
				name.setGenusOrUninomial(supragenericNames);
90
				/*if (preferredName != null && !preferredName.equals(supragenericNames)){
91
					logger.warn("Suprageneric names and preferredName is not equal. This case is not yet handled by IF import. I take SupragenericNames for import. RECORD NUMBER" +id);
92
				}*/
93 89

  
94 90
				//taxon
95 91
				Taxon taxon = Taxon.NewInstance(name, sourceReference);
96 92
				//author + nom.ref.
97 93
				makeAuthorAndPublication(state, rs, name);
98 94
				//source
99
//				if (id != null){
100
					makeSource(state, taxon, id.intValue(), NAMESPACE_SUPRAGENERIC_NAMES );
101
//				} else{
102
//					makeSource(state, taxon, null, NAMESPACE_SUPRAGENERIC_NAMES);
103
//				}
95
				makeSource(state, taxon, id, NAMESPACE_SUPRAGENERIC_NAMES );
96

  
104 97
				getTaxonService().saveOrUpdate(taxon);
105 98
			}
106 99
		} catch (Exception e) {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)