Project

General

Profile

Revision 29ee6f42

ID29ee6f42ff5a645f5c3071068b140c90a4810501
Parent 40ad1567
Child b5a13d3d

Added by Katja Luther over 2 years ago

fix merge problems

View differences:

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

  
12
import java.util.HashMap;
13
import java.util.List;
14

  
15
/**
16
 * @author k.luther
17
 * @date 18.07.2016
18
 *
19
 */
20
public class SpecimenDataHolder {
21

  
22
    private String nomenclatureCode;
23
    private List<HashMap<String, String>> atomisedIdentificationList;
24

  
25

  
26

  
27
    /**
28
     * @return the nomenclatureCode
29
     */
30
    public String getNomenclatureCode() {
31
        return nomenclatureCode;
32
    }
33

  
34

  
35

  
36
    /**
37
     * @param nomenclatureCode the nomenclatureCode to set
38
     */
39
    public void setNomenclatureCode(String nomenclatureCode) {
40
        this.nomenclatureCode = nomenclatureCode;
41
    }
42

  
43

  
44

  
45
    /**
46
     * @return the atomisedIdentificationList
47
     */
48
    public List<HashMap<String, String>> getAtomisedIdentificationList() {
49
        return atomisedIdentificationList;
50
    }
51

  
52

  
53

  
54
    /**
55
     * @param atomisedIdentificationList the atomisedIdentificationList to set
56
     */
57
    public void setAtomisedIdentificationList(List<HashMap<String, String>> atomisedIdentificationList) {
58
        this.atomisedIdentificationList = atomisedIdentificationList;
59
    }
60
}
1
// $Id$
2
/**
3
* Copyright (C) 2016 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.io.specimen;
11

  
12
import java.util.HashMap;
13
import java.util.List;
14

  
15
/**
16
 * @author k.luther
17
 * @date 18.07.2016
18
 *
19
 */
20
public class SpecimenDataHolder {
21

  
22
    private String nomenclatureCode;
23
    private List<HashMap<String, String>> atomisedIdentificationList;
24

  
25

  
26

  
27
    /**
28
     * @return the nomenclatureCode
29
     */
30
    public String getNomenclatureCode() {
31
        return nomenclatureCode;
32
    }
33

  
34

  
35

  
36
    /**
37
     * @param nomenclatureCode the nomenclatureCode to set
38
     */
39
    public void setNomenclatureCode(String nomenclatureCode) {
40
        this.nomenclatureCode = nomenclatureCode;
41
    }
42

  
43

  
44

  
45
    /**
46
     * @return the atomisedIdentificationList
47
     */
48
    public List<HashMap<String, String>> getAtomisedIdentificationList() {
49
        return atomisedIdentificationList;
50
    }
51

  
52

  
53

  
54
    /**
55
     * @param atomisedIdentificationList the atomisedIdentificationList to set
56
     */
57
    public void setAtomisedIdentificationList(List<HashMap<String, String>> atomisedIdentificationList) {
58
        this.atomisedIdentificationList = atomisedIdentificationList;
59
    }
60
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/SpecimenImportBase.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.specimen;
11 11

  
12 12

  
13
import java.util.ArrayList;
14
import java.util.HashMap;
15
import java.util.List;
16
import java.util.Set;
17

  
13 18
import org.apache.log4j.Logger;
14 19

  
20
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
21
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
22
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
23
import eu.etaxonomy.cdm.api.service.pager.Pager;
24
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
15 25
import eu.etaxonomy.cdm.io.common.CdmImportBase;
16 26
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
17
import eu.etaxonomy.cdm.io.common.ImportStateBase;
27
import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
28
import eu.etaxonomy.cdm.model.agent.AgentBase;
29
import eu.etaxonomy.cdm.model.agent.Team;
30
import eu.etaxonomy.cdm.model.common.CdmBase;
31
import eu.etaxonomy.cdm.model.common.LanguageString;
32
import eu.etaxonomy.cdm.model.description.DescriptionBase;
33
import eu.etaxonomy.cdm.model.name.BacterialName;
34
import eu.etaxonomy.cdm.model.name.BotanicalName;
35
import eu.etaxonomy.cdm.model.name.CultivarPlantName;
36
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
37
import eu.etaxonomy.cdm.model.name.NonViralName;
38
import eu.etaxonomy.cdm.model.name.Rank;
39
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
40
import eu.etaxonomy.cdm.model.name.ZoologicalName;
41
import eu.etaxonomy.cdm.model.occurrence.Collection;
42
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
43
import eu.etaxonomy.cdm.model.reference.Reference;
44
import eu.etaxonomy.cdm.model.taxon.Classification;
45
import eu.etaxonomy.cdm.model.taxon.Synonym;
46
import eu.etaxonomy.cdm.model.taxon.Taxon;
47
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
48
import eu.etaxonomy.cdm.persistence.query.MatchMode;
49
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
50
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
18 51

  
19 52

  
20 53
/**
21 54
 * @author p.kelbert
22 55
 * @created 20.10.2008
23 56
 */
24
public abstract class SpecimenImportBase<CONFIG extends IImportConfigurator, STATE extends ImportStateBase>  extends CdmImportBase<CONFIG, STATE> {
57
public abstract class SpecimenImportBase<CONFIG extends IImportConfigurator, STATE extends SpecimenImportStateBase>  extends CdmImportBase<CONFIG, STATE> {
58

  
25 59
	@SuppressWarnings("unused")
26 60
	private static final Logger logger = Logger.getLogger(SpecimenImportBase.class);
61
	protected final boolean DEBUG = true;
62

  
63
	@Override
64
    protected abstract void doInvoke(STATE state);
65

  
66
	/**
67
	 * Handle a single unit
68
	 * @param state
69
	 * @param item
70
	 */
71
	@SuppressWarnings("rawtypes")
72
	protected abstract void handleSingleUnit(STATE state, Object item) ;
73

  
74

  
75

  
76
	protected TaxonNameBase<?, ?> getOrCreateTaxonName(String scientificName, Rank rank, boolean preferredFlag, STATE state, int unitIndexInAbcdFile){
77
        TaxonNameBase<?, ?> taxonName = null;
78
        SpecimenImportConfiguratorBase config = (SpecimenImportConfiguratorBase) state.getConfig();
79

  
80
        //check atomised name data for rank
81
        //new name will be created
82
        NonViralName<?> atomisedTaxonName = null;
83
        if (rank==null && unitIndexInAbcdFile>=0 && (state.getDataHolder().getAtomisedIdentificationList() != null || state.getDataHolder().getAtomisedIdentificationList().size() > 0)) {
84
            atomisedTaxonName = setTaxonNameByType(state.getDataHolder().getAtomisedIdentificationList().get(unitIndexInAbcdFile), scientificName, state);
85
            if(atomisedTaxonName!=null){
86
                rank = atomisedTaxonName.getRank();
87
            }
88
        }
89
        if(config.isReuseExistingTaxaWhenPossible()){
90
            NonViralName<?> parsedName = atomisedTaxonName;
91
            if(parsedName==null){
92
                parsedName = parseScientificName(scientificName, state, state.getReport());
93
            }
94
            if(config.isIgnoreAuthorship() && parsedName!=null && preferredFlag){
95
                // do not ignore authorship for non-preferred names because they need
96
                // to be created for the determination history
97
                String nameCache = parsedName.getNameCache();
98
                List<NonViralName> names = getNameService().findNamesByNameCache(nameCache, MatchMode.EXACT, null);
99
                taxonName = getBestMatchingName(scientificName, new ArrayList<TaxonNameBase>(names), state);
100
            }
101
            else {
102
                //search for existing names
103
                List<TaxonNameBase> names = getNameService().listByTitle(TaxonNameBase.class, scientificName, MatchMode.EXACT, null, null, null, null, null);
104
                taxonName = getBestMatchingName(scientificName, names, state);
105
                //still nothing found -> try with the atomised name full title cache
106
                if(taxonName==null && atomisedTaxonName!=null){
107
                    names = getNameService().listByTitle(TaxonNameBase.class, atomisedTaxonName.getFullTitleCache(), MatchMode.EXACT, null, null, null, null, null);
108
                    taxonName = getBestMatchingName(atomisedTaxonName.getTitleCache(), names, state);
109
                    //still nothing found -> try with the atomised name title cache
110
                    if(taxonName==null){
111
                        names = getNameService().listByTitle(TaxonNameBase.class, atomisedTaxonName.getTitleCache(), MatchMode.EXACT, null, null, null, null, null);
112
                        taxonName = getBestMatchingName(atomisedTaxonName.getTitleCache(), names, state);
113
                    }
114
                }
115
            }
116
        }
117

  
118
        if(taxonName==null && atomisedTaxonName!=null){
119
            taxonName = atomisedTaxonName;
120
            state.getReport().addName(taxonName);
121
            logger.info("Created new taxon name "+taxonName);
122
            if(taxonName.hasProblem()){
123
                state.getReport().addInfoMessage(String.format("Created %s with parsing problems", taxonName));
124
            }
125
            if(!atomisedTaxonName.getTitleCache().equals(scientificName)){
126
                state.getReport().addInfoMessage(String.format("Taxon %s was parsed as %s", scientificName, atomisedTaxonName.getTitleCache()));
127
            }
128
        }
129
        else if(taxonName==null){
130
            //create new taxon name
131
            taxonName = NonViralName.NewInstance(rank);
132
            taxonName.setFullTitleCache(scientificName,true);
133
            taxonName.setTitleCache(scientificName, true);
134
            state.getReport().addName(taxonName);
135
            logger.info("Created new taxon name "+taxonName);
136
        }
137
        save(taxonName, state);
138
        return taxonName;
139
    }
140

  
141
	 protected TaxonNameBase<?, ?> getBestMatchingName(String scientificName, java.util.Collection<TaxonNameBase> names, STATE state){
142
	        List<TaxonNameBase> namesWithAcceptedTaxa = new ArrayList<TaxonNameBase>();
143
	        for (TaxonNameBase name : names) {
144
	            if(!name.getTaxa().isEmpty()){
145
	                namesWithAcceptedTaxa.add(name);
146
	            }
147
	        }
148
	        String message = "More than one taxon name was found for "+scientificName+"!";
149
	        //check for names with accepted taxa
150
	        if(namesWithAcceptedTaxa.size()>0){
151
	            if(namesWithAcceptedTaxa.size()>1){
152
	                state.getReport().addInfoMessage(message);
153
	                logger.warn(message);
154
	                return null;
155
	            }
156
	            return namesWithAcceptedTaxa.iterator().next();
157
	        }
158
	        //no names with accepted taxa found -> check accepted taxa of synonyms
159
	        List<Taxon> taxaFromSynonyms = new ArrayList<Taxon>();
160
	        for (TaxonNameBase name : names) {
161
	            Set<TaxonBase> taxonBases = name.getTaxonBases();
162
	            for (TaxonBase taxonBase : taxonBases) {
163
	                if(taxonBase.isInstanceOf(Synonym.class)){
164
	                    Synonym synonym = HibernateProxyHelper.deproxy(taxonBase, Synonym.class);
165
	                    taxaFromSynonyms.addAll(synonym.getAcceptedTaxa());
166
	                }
167
	            }
168
	        }
169
	        if(taxaFromSynonyms.size()>0){
170
	            if(taxaFromSynonyms.size()>1){
171
	                state.getReport().addInfoMessage(message);
172
	                logger.warn(message);
173
	                return null;
174
	            }
175
	            return taxaFromSynonyms.iterator().next().getName();
176
	        }
177
	        return null;
178
	    }
179
	 /**
180
	     * Parse automatically the scientific name
181
	     * @param scientificName the scientific name to parse
182
	     * @param state the current import state
183
	     * @param report the import report
184
	     * @return a parsed name
185
	     */
186
	    protected NonViralName<?> parseScientificName(String scientificName, STATE state, SpecimenImportReport report) {
187
	        NonViralNameParserImpl nvnpi = NonViralNameParserImpl.NewInstance();
188
	        NonViralName<?> taxonName = null;
189
	        boolean problem = false;
190

  
191
	        if(DEBUG){
192
	            logger.info("parseScientificName " + state.getDataHolder().getNomenclatureCode().toString());
193
	        }
194

  
195
	        if (state.getDataHolder().getNomenclatureCode().toString().equals("Zoological") || state.getDataHolder().getNomenclatureCode().toString().contains("ICZN")) {
196
	            taxonName = nvnpi.parseFullName(scientificName, NomenclaturalCode.ICZN, null);
197
	            if (taxonName.hasProblem()) {
198
	                problem = true;
199
	            }
200
	        }
201
	        else if (state.getDataHolder().getNomenclatureCode().toString().equals("Botanical") || state.getDataHolder().getNomenclatureCode().toString().contains("ICBN")) {
202
	            taxonName = nvnpi.parseFullName(scientificName, NomenclaturalCode.ICNAFP, null);
203
	            if (taxonName.hasProblem()) {
204
	                problem = true;
205
	            }
206
	        }
207
	        else if (state.getDataHolder().getNomenclatureCode().toString().equals("Bacterial") || state.getDataHolder().getNomenclatureCode().toString().contains("ICBN")) {
208
	            taxonName = nvnpi.parseFullName(scientificName, NomenclaturalCode.ICNB, null);
209
	            if (taxonName.hasProblem()) {
210
	                problem = true;
211
	            }
212
	        }
213
	        else if (state.getDataHolder().getNomenclatureCode().toString().equals("Cultivar") || state.getDataHolder().getNomenclatureCode().toString().contains("ICNCP")) {
214
	            taxonName = nvnpi.parseFullName(scientificName, NomenclaturalCode.ICNCP, null);
215
	            if (taxonName.hasProblem()) {
216
	                problem = true;
217
	            }
218
	        }
219
	        if (problem) {
220
	            String message = String.format("Parsing problems for %s", scientificName);
221
	            if(taxonName!=null){
222
	                for (ParserProblem parserProblem : taxonName.getParsingProblems()) {
223
	                    message += "\n\t- "+parserProblem;
224
	                }
225
	            }
226
	            report.addInfoMessage(message);
227
	            logger.info(message);
228
	        }
229
	        return taxonName;
230

  
231
	    }
232

  
233
	    /**
234
	     * Create the name without automatic parsing, either because it failed, or because the user deactivated it.
235
	     * The name is built upon the ABCD fields
236
	     * @param atomisedMap : the ABCD atomised fields
237
	     * @param fullName : the full scientific name
238
	     * @param state
239
	     * @return the corresponding Botanical or Zoological or... name
240
	     */
241
	    protected NonViralName<?> setTaxonNameByType(
242
	            HashMap<String, String> atomisedMap, String fullName, STATE state) {
243
	        boolean problem = false;
244
	        if(DEBUG) {
245
	            logger.info("settaxonnamebytype " + state.getDataHolder().getNomenclatureCode().toString());
246
	        }
247

  
248
	        if (state.getDataHolder().getNomenclatureCode().equals("Zoological")) {
249
	            NonViralName<ZoologicalName> taxonName = ZoologicalName.NewInstance(null);
250
	            taxonName.setFullTitleCache(fullName, true);
251
	            taxonName.setGenusOrUninomial(NB(getFromMap(atomisedMap, "Genus")));
252
	            taxonName.setInfraGenericEpithet(NB(getFromMap(atomisedMap, "SubGenus")));
253
	            taxonName.setSpecificEpithet(NB(getFromMap(atomisedMap,"SpeciesEpithet")));
254
	            taxonName.setInfraSpecificEpithet(NB(getFromMap(atomisedMap,"SubspeciesEpithet")));
255

  
256
	            if (taxonName.getGenusOrUninomial() != null){
257
	                taxonName.setRank(Rank.GENUS());
258
	            }
259

  
260
	            if (taxonName.getInfraGenericEpithet() != null){
261
	                taxonName.setRank(Rank.SUBGENUS());
262
	            }
263

  
264
	            if (taxonName.getSpecificEpithet() != null){
265
	                taxonName.setRank(Rank.SPECIES());
266
	            }
267

  
268
	            if (taxonName.getInfraSpecificEpithet() != null){
269
	                taxonName.setRank(Rank.SUBSPECIES());
270
	            }
271

  
272
	            Team team = null;
273
	            if (getFromMap(atomisedMap, "AuthorTeamParenthesis") != null) {
274
	                team = Team.NewInstance();
275
	                team.setTitleCache(getFromMap(atomisedMap, "AuthorTeamParenthesis"), true);
276
	            }
277
	            else {
278
	                if (getFromMap(atomisedMap, "AuthorTeamAndYear") != null) {
279
	                    team = Team.NewInstance();
280
	                    team.setTitleCache(getFromMap(atomisedMap, "AuthorTeamAndYear"), true);
281
	                }
282
	            }
283
	            if (team != null) {
284
	                taxonName.setBasionymAuthorship(team);
285
	            }
286
	            else {
287
	                if (getFromMap(atomisedMap, "AuthorTeamParenthesis") != null) {
288
	                    taxonName.setAuthorshipCache(getFromMap(atomisedMap, "AuthorTeamParenthesis"));
289
	                }
290
	                else if (getFromMap(atomisedMap, "AuthorTeamAndYear") != null) {
291
	                    taxonName.setAuthorshipCache(getFromMap(atomisedMap, "AuthorTeamAndYear"));
292
	                }
293
	            }
294
	            if (getFromMap(atomisedMap, "CombinationAuthorTeamAndYear") != null) {
295
	                team = Team.NewInstance();
296
	                team.setTitleCache(getFromMap(atomisedMap, "CombinationAuthorTeamAndYear"), true);
297
	                taxonName.setCombinationAuthorship(team);
298
	            }
299
	            if (taxonName.hasProblem()) {
300
	                logger.info("pb ICZN");
301
	                problem = true;
302
	            }
303
	            else {
304
	                return taxonName;
305
	            }
306
	        }
307
	        else if (state.getDataHolder().getNomenclatureCode().equals("Botanical")) {
308
	            BotanicalName taxonName = (BotanicalName) parseScientificName(fullName, state, state.getReport());
309
	            if (taxonName != null){
310
	                return taxonName;
311
	            }
312
	            else{
313
	                taxonName = BotanicalName.NewInstance(null);
314
	            }
315
	            taxonName.setFullTitleCache(fullName, true);
316
	            taxonName.setGenusOrUninomial(NB(getFromMap(atomisedMap, "Genus")));
317
	            taxonName.setSpecificEpithet(NB(getFromMap(atomisedMap, "FirstEpithet")));
318
	            taxonName.setInfraSpecificEpithet(NB(getFromMap(atomisedMap, "InfraSpeEpithet")));
319
	            try {
320
	                taxonName.setRank(Rank.getRankByName(getFromMap(atomisedMap, "Rank")));
321
	            } catch (Exception e) {
322
	                if (taxonName.getInfraSpecificEpithet() != null){
323
	                    taxonName.setRank(Rank.SUBSPECIES());
324
	                }
325
	                else if (taxonName.getSpecificEpithet() != null){
326
	                    taxonName.setRank(Rank.SPECIES());
327
	                }
328
	                else if (taxonName.getInfraGenericEpithet() != null){
329
	                    taxonName.setRank(Rank.SUBGENUS());
330
	                }
331
	                else if (taxonName.getGenusOrUninomial() != null){
332
	                    taxonName.setRank(Rank.GENUS());
333
	                }
334
	            }
335
	            Team team = null;
336
	            if (getFromMap(atomisedMap, "AuthorTeamParenthesis") != null) {
337
	                team = Team.NewInstance();
338
	                team.setTitleCache(getFromMap(atomisedMap, "AuthorTeamParenthesis"), true);
339
	                taxonName.setBasionymAuthorship(team);
340
	            }
341
	            if (getFromMap(atomisedMap, "AuthorTeam") != null) {
342
	                team = Team.NewInstance();
343
	                team.setTitleCache(getFromMap(atomisedMap, "AuthorTeam"), true);
344
	                taxonName.setCombinationAuthorship(team);
345
	            }
346
	            if (team == null) {
347
	                if (getFromMap(atomisedMap, "AuthorTeamParenthesis") != null) {
348
	                    taxonName.setAuthorshipCache(getFromMap(atomisedMap, "AuthorTeamParenthesis"));
349
	                }
350
	                else if (getFromMap(atomisedMap, "AuthorTeam") != null) {
351
	                    taxonName.setAuthorshipCache(getFromMap(atomisedMap, "AuthorTeam"));
352
	                }
353
	            }
354
	            if (getFromMap(atomisedMap, "CombinationAuthorTeamAndYear") != null) {
355
	                team = Team.NewInstance();
356
	                team.setTitleCache(getFromMap(atomisedMap, "CombinationAuthorTeamAndYear"), true);
357
	                taxonName.setCombinationAuthorship(team);
358
	            }
359
	            if (taxonName.hasProblem()) {
360
	                logger.info("pb ICBN");
361
	                problem = true;
362
	            }
363
	            else {
364
	                return taxonName;
365
	            }
366
	        }
367
	        else if (state.getDataHolder().getNomenclatureCode().equals("Bacterial")) {
368
	            NonViralName<BacterialName> taxonName = BacterialName.NewInstance(null);
369
	            taxonName.setFullTitleCache(fullName, true);
370
	            taxonName.setGenusOrUninomial(getFromMap(atomisedMap, "Genus"));
371
	            taxonName.setInfraGenericEpithet(NB(getFromMap(atomisedMap, "SubGenus")));
372
	            taxonName.setSpecificEpithet(NB(getFromMap(atomisedMap, "Species")));
373
	            taxonName.setInfraSpecificEpithet(NB(getFromMap(atomisedMap, "SubspeciesEpithet")));
374

  
375
	            if (taxonName.getGenusOrUninomial() != null){
376
	                taxonName.setRank(Rank.GENUS());
377
	            }
378
	            else if (taxonName.getInfraGenericEpithet() != null){
379
	                taxonName.setRank(Rank.SUBGENUS());
380
	            }
381
	            else if (taxonName.getSpecificEpithet() != null){
382
	                taxonName.setRank(Rank.SPECIES());
383
	            }
384
	            else if (taxonName.getInfraSpecificEpithet() != null){
385
	                taxonName.setRank(Rank.SUBSPECIES());
386
	            }
387

  
388
	            if (getFromMap(atomisedMap, "AuthorTeamAndYear") != null) {
389
	                Team team = Team.NewInstance();
390
	                team.setTitleCache(getFromMap(atomisedMap, "AuthorTeamAndYear"), true);
391
	                taxonName.setCombinationAuthorship(team);
392
	            }
393
	            if (getFromMap(atomisedMap, "ParentheticalAuthorTeamAndYear") != null) {
394
	                Team team = Team.NewInstance();
395
	                team.setTitleCache(getFromMap(atomisedMap, "ParentheticalAuthorTeamAndYear"), true);
396
	                taxonName.setBasionymAuthorship(team);
397
	            }
398
	            if (taxonName.hasProblem()) {
399
	                logger.info("pb ICNB");
400
	                problem = true;
401
	            }
402
	            else {
403
	                return taxonName;
404
	            }
405
	        }
406
	        else if (state.getDataHolder().getNomenclatureCode().equals("Cultivar")) {
407
	            CultivarPlantName taxonName = CultivarPlantName.NewInstance(null);
408

  
409
	            if (taxonName.hasProblem()) {
410
	                logger.info("pb ICNCP");
411
	                problem = true;
412
	            }
413
	            else {
414
	                return taxonName;
415
	            }
416
	            return taxonName;
417
	        }
418

  
419
	        if (problem) {
420
	            logger.info("Problem im setTaxonNameByType ");
421
	            NonViralName<?> taxonName = NonViralName.NewInstance(null);
422
	            taxonName.setFullTitleCache(fullName, true);
423
	            return taxonName;
424
	        }
425
	        NonViralName<?> tn = NonViralName.NewInstance(null);
426
	        return tn;
427
	    }
428

  
429
	    /**
430
	     * Get a formated string from a hashmap
431
	     * @param atomisedMap
432
	     * @param key
433
	     * @return
434
	     */
435
	    private String getFromMap(HashMap<String, String> atomisedMap, String key) {
436
	        String value = null;
437
	        if (atomisedMap.containsKey(key)) {
438
	            value = atomisedMap.get(key);
439
	        }
440

  
441
	        try {
442
	            if (value != null && key.matches(".*Year.*")) {
443
	                value = value.trim();
444
	                if (value.matches("[a-z A-Z ]*[0-9]{4}$")) {
445
	                    String tmp = value.split("[0-9]{4}$")[0];
446
	                    int year = Integer.parseInt(value.split(tmp)[1]);
447
	                    if (year >= 1752) {
448
	                        value = tmp;
449
	                    }
450
	                    else {
451
	                        value = null;
452
	                    }
453
	                }
454
	                else {
455
	                    value = null;
456
	                }
457
	            }
458
	        }
459
	        catch (Exception e) {
460
	            value = null;
461
	        }
462
	        return value;
463
	    }
464

  
465
	    /**
466
	     * Very fast and dirty implementation to allow handling of transient objects as described in
467
	     * https://dev.e-taxonomy.eu/trac/ticket/3726
468
	     *
469
	     * Not yet complete.
470
	     *
471
	     * @param cdmBase
472
	     * @param state
473
	     */
474
	    protected void save(CdmBase cdmBase, SpecimenImportStateBase state) {
475
	        ICdmApplicationConfiguration cdmRepository = state.getConfig().getCdmAppController();
476
	        if (cdmRepository == null){
477
	            cdmRepository = this;
478
	        }
479

  
480
	        if (cdmBase.isInstanceOf(LanguageString.class)){
481
	            cdmRepository.getTermService().saveLanguageData(CdmBase.deproxy(cdmBase, LanguageString.class));
482
	        }else if (cdmBase.isInstanceOf(SpecimenOrObservationBase.class)){
483
	            cdmRepository.getOccurrenceService().saveOrUpdate(CdmBase.deproxy(cdmBase, SpecimenOrObservationBase.class));
484
	        }else if (cdmBase.isInstanceOf(Reference.class)){
485
	            cdmRepository.getReferenceService().saveOrUpdate(CdmBase.deproxy(cdmBase, Reference.class));
486
	        }else if (cdmBase.isInstanceOf(Classification.class)){
487
	            cdmRepository.getClassificationService().saveOrUpdate(CdmBase.deproxy(cdmBase, Classification.class));
488
	        }else if (cdmBase.isInstanceOf(AgentBase.class)){
489
	            cdmRepository.getAgentService().saveOrUpdate(CdmBase.deproxy(cdmBase, AgentBase.class));
490
	        }else if (cdmBase.isInstanceOf(Collection.class)){
491
	            cdmRepository.getCollectionService().saveOrUpdate(CdmBase.deproxy(cdmBase, Collection.class));
492
	        }else if (cdmBase.isInstanceOf(DescriptionBase.class)){
493
	            cdmRepository.getDescriptionService().saveOrUpdate(CdmBase.deproxy(cdmBase, DescriptionBase.class));
494
	        }else if (cdmBase.isInstanceOf(TaxonBase.class)){
495
	            cdmRepository.getTaxonService().saveOrUpdate(CdmBase.deproxy(cdmBase, TaxonBase.class));
496
	        }else if (cdmBase.isInstanceOf(TaxonNameBase.class)){
497
	            cdmRepository.getNameService().saveOrUpdate(CdmBase.deproxy(cdmBase, TaxonNameBase.class));
498
	        }else{
499
	            throw new IllegalArgumentException("Class not supported in save method: " + CdmBase.deproxy(cdmBase, CdmBase.class).getClass().getSimpleName());
500
	        }
501

  
502
	    }
503

  
504

  
505
	    protected SpecimenOrObservationBase findExistingSpecimen(String unitId, SpecimenImportStateBase state){
506
	        ICdmApplicationConfiguration cdmAppController = state.getConfig().getCdmAppController();
507
	        if(cdmAppController==null){
508
	            cdmAppController = this;
509
	        }
510
	        FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
511
	        config.setSignificantIdentifier(unitId);
512
	        Pager<SpecimenOrObservationBase> existingSpecimens = cdmAppController.getOccurrenceService().findByTitle(config);
513
	        if(!existingSpecimens.getRecords().isEmpty()){
514
	            if(existingSpecimens.getRecords().size()==1){
515
	                return existingSpecimens.getRecords().iterator().next();
516
	            }
517
	        }
518
	        return null;
519
	    }
520

  
521
	    protected abstract void importAssociatedUnits(STATE state, Object item, DerivedUnitFacade derivedUnitFacade);
522

  
27 523

  
28
	protected abstract void doInvoke(STATE state);
29 524

  
30 525
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/SpecimenImportConfiguratorBase.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.io.specimen;
11

  
12
import java.util.Map;
13

  
14
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
15
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
16
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
17
import eu.etaxonomy.cdm.model.agent.Person;
18
import eu.etaxonomy.cdm.model.agent.Team;
19

  
20
/**
21
 * @author k.luther
22
 * @date 15.07.2016
23
 *
24
 */
25
public abstract class SpecimenImportConfiguratorBase<STATE extends SpecimenImportStateBase, InputStream>  extends ImportConfiguratorBase<STATE, InputStream> {
26

  
27
    private boolean ignoreImportOfExistingSpecimen;
28
    private boolean reuseExistingTaxaWhenPossible;
29
    private Map<String, Team> teams;
30
    private Map<String, Person> persons;
31
    private boolean ignoreAuthorship;
32
    private boolean removeCountryFromLocalityText;
33
    private OccurenceQuery query ;
34

  
35
    /**
36
     * @param transformer
37
     */
38
    public SpecimenImportConfiguratorBase(IInputTransformer transformer) {
39
        super(transformer);
40
        // TODO Auto-generated constructor stub
41
    }
42

  
43
    /**
44
     * @return
45
     */
46
    public boolean isReuseExistingTaxaWhenPossible() {
47

  
48
        return reuseExistingTaxaWhenPossible;
49
    }
50

  
51
    /**
52
     * @param titleCacheTeam
53
     */
54
    public void setTeams(Map<String, Team> titleCacheTeam) {
55
       this.teams  = titleCacheTeam;
56

  
57
    }
58

  
59
    /**
60
     * @param titleCachePerson
61
     */
62
    public void setPersons(Map<String, Person> titleCachePerson) {
63
        this.persons = titleCachePerson;
64
    }
65

  
66
    /**
67
     * @return
68
     */
69
    public boolean isIgnoreAuthorship() {
70
        return ignoreAuthorship;
71
    }
72

  
73
    /**
74
     * @return
75
     */
76
    public boolean isRemoveCountryFromLocalityText() {
77
        return removeCountryFromLocalityText;
78
    }
79

  
80
    public boolean isIgnoreImportOfExistingSpecimens(){
81
        return ignoreImportOfExistingSpecimen;
82
    }
83

  
84
    public OccurenceQuery getOccurenceQuery(){
85
        return query;
86
    }
87

  
88
    public void setOccurenceQuery(OccurenceQuery query){
89
        this.query = query;
90
    }
91

  
92
}
1
// $Id$
2
/**
3
* Copyright (C) 2016 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.io.specimen;
11

  
12
import java.util.Map;
13

  
14
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
15
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
16
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
17
import eu.etaxonomy.cdm.model.agent.Person;
18
import eu.etaxonomy.cdm.model.agent.Team;
19

  
20
/**
21
 * @author k.luther
22
 * @date 15.07.2016
23
 *
24
 */
25
public abstract class SpecimenImportConfiguratorBase<STATE extends SpecimenImportStateBase, InputStream>  extends ImportConfiguratorBase<STATE, InputStream> {
26

  
27
    private boolean ignoreImportOfExistingSpecimen;
28
    private boolean reuseExistingTaxaWhenPossible;
29
    private Map<String, Team> teams;
30
    private Map<String, Person> persons;
31
    private boolean ignoreAuthorship;
32
    private boolean removeCountryFromLocalityText;
33
    private OccurenceQuery query ;
34

  
35
    /**
36
     * @param transformer
37
     */
38
    public SpecimenImportConfiguratorBase(IInputTransformer transformer) {
39
        super(transformer);
40
        // TODO Auto-generated constructor stub
41
    }
42

  
43
    /**
44
     * @return
45
     */
46
    public boolean isReuseExistingTaxaWhenPossible() {
47

  
48
        return reuseExistingTaxaWhenPossible;
49
    }
50

  
51
    /**
52
     * @param titleCacheTeam
53
     */
54
    public void setTeams(Map<String, Team> titleCacheTeam) {
55
       this.teams  = titleCacheTeam;
56

  
57
    }
58

  
59
    /**
60
     * @param titleCachePerson
61
     */
62
    public void setPersons(Map<String, Person> titleCachePerson) {
63
        this.persons = titleCachePerson;
64
    }
65

  
66
    /**
67
     * @return
68
     */
69
    public boolean isIgnoreAuthorship() {
70
        return ignoreAuthorship;
71
    }
72

  
73
    /**
74
     * @return
75
     */
76
    public boolean isRemoveCountryFromLocalityText() {
77
        return removeCountryFromLocalityText;
78
    }
79

  
80
    public boolean isIgnoreImportOfExistingSpecimens(){
81
        return ignoreImportOfExistingSpecimen;
82
    }
83

  
84
    public OccurenceQuery getOccurenceQuery(){
85
        return query;
86
    }
87

  
88
    public void setOccurenceQuery(OccurenceQuery query){
89
        this.query = query;
90
    }
91

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

  
12
import org.springframework.transaction.TransactionStatus;
13

  
14
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
15
import eu.etaxonomy.cdm.io.common.CdmImportBase;
16
import eu.etaxonomy.cdm.io.common.ImportStateBase;
17
import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
18
import eu.etaxonomy.cdm.model.description.TaxonDescription;
19
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
20
import eu.etaxonomy.cdm.model.reference.Reference;
21
import eu.etaxonomy.cdm.model.taxon.Classification;
22

  
23
/**
24
 * @author k.luther
25
 * @param <CONFIG>
26
 * @date 15.07.2016
27
 *
28
 */
29
public abstract class SpecimenImportStateBase<CONFIG extends SpecimenImportConfiguratorBase, STATE extends SpecimenImportStateBase> extends ImportStateBase<CONFIG , CdmImportBase<CONFIG , STATE >>{
30

  
31

  
32
    private TransactionStatus tx;
33

  
34
    private ICdmApplicationConfiguration cdmRepository;
35
    private Classification classification = null;
36
    private Classification defaultClassification = null;
37
    private Reference ref = null;
38

  
39
    private TaxonDescription descriptionGroup = null;
40
    private DerivedUnit derivedUnitBase;
41

  
42
    private SpecimenImportReport report;
43

  
44
    private SpecimenDataHolder dataHolder;
45

  
46

  
47
    /**
48
     * @param config
49
     */
50
    protected SpecimenImportStateBase(CONFIG config) {
51
        super(config);
52
        // TODO Auto-generated constructor stub
53
    }
54

  
55
    /* -----Getter/Setter ---*/
56

  
57
    public TransactionStatus getTx() {
58
        return tx;
59
    }
60

  
61
    public void setTx(TransactionStatus tx) {
62
        this.tx = tx;
63
    }
64

  
65
    public ICdmApplicationConfiguration getCdmRepository() {
66
        return cdmRepository;
67
    }
68

  
69
    public void setCdmRepository(ICdmApplicationConfiguration cdmRepository) {
70
        this.cdmRepository = cdmRepository;
71
    }
72

  
73
    public Classification getClassification() {
74
        return classification;
75
    }
76

  
77
    public void setClassification(Classification classification) {
78
        this.classification = classification;
79
    }
80

  
81
    public Classification getDefaultClassification() {
82
        if(defaultClassification==null){
83
            final String defaultClassificationAbcd = "Default Classification ABCD";
84
            for (Classification classif : cdmRepository.getClassificationService().list(Classification.class, null, null, null, null)){
85
                if (classif.getTitleCache()!=null && classif.getTitleCache().equalsIgnoreCase(defaultClassificationAbcd)
86
                        && classif.getCitation()!=null && classif.getCitation().equals(getRef())) {
87
                    defaultClassification = classif;
88
                    break;
89
                }
90
            }
91
            if(defaultClassification==null){
92
                defaultClassification = Classification.NewInstance(defaultClassificationAbcd);
93
                cdmRepository.getClassificationService().save(defaultClassification);
94
            }
95
        }
96
        return defaultClassification;
97
    }
98

  
99
    public void setDefaultClassification(Classification defaultClassification) {
100
        this.defaultClassification = defaultClassification;
101
    }
102

  
103
    public Reference getRef() {
104
        return ref;
105
    }
106

  
107
    public void setRef(Reference ref) {
108
        this.ref = ref;
109
    }
110

  
111
    public TaxonDescription getDescriptionGroup() {
112
        return descriptionGroup;
113
    }
114

  
115
    public void setDescriptionGroup(TaxonDescription descriptionGroup) {
116
        this.descriptionGroup = descriptionGroup;
117
    }
118

  
119
    public DerivedUnit getDerivedUnitBase() {
120
        return derivedUnitBase;
121
    }
122

  
123
    public void setDerivedUnitBase(DerivedUnit derivedUnitBase) {
124
        this.derivedUnitBase = derivedUnitBase;
125
    }
126

  
127
    /**
128
     * @return the report
129
     */
130
    public SpecimenImportReport getReport() {
131
        return report;
132
    }
133

  
134
    /**
135
     * @param report the report to set
136
     */
137
    public void setReport(SpecimenImportReport report) {
138
        this.report = report;
139
    }
140

  
141
    /**
142
     *
143
     */
144
    public abstract void reset() ;
145

  
146
    /**
147
     * @return the dataHolder
148
     */
149
    public SpecimenDataHolder getDataHolder() {
150
        return dataHolder;
151
    }
152

  
153
    /**
154
     * @param dataHolder the dataHolder to set
155
     */
156
    public void setDataHolder(SpecimenDataHolder dataHolder) {
157
        this.dataHolder = dataHolder;
158
    }
159

  
160

  
161
}
1
// $Id$
2
/**
3
* Copyright (C) 2016 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.io.specimen;
11

  
12
import org.springframework.transaction.TransactionStatus;
13

  
14
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
15
import eu.etaxonomy.cdm.io.common.CdmImportBase;
16
import eu.etaxonomy.cdm.io.common.ImportStateBase;
17
import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
18
import eu.etaxonomy.cdm.model.description.TaxonDescription;
19
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
20
import eu.etaxonomy.cdm.model.reference.Reference;
21
import eu.etaxonomy.cdm.model.taxon.Classification;
22

  
23
/**
24
 * @author k.luther
25
 * @param <CONFIG>
26
 * @date 15.07.2016
27
 *
28
 */
29
public abstract class SpecimenImportStateBase<CONFIG extends SpecimenImportConfiguratorBase, STATE extends SpecimenImportStateBase> extends ImportStateBase<CONFIG , CdmImportBase<CONFIG , STATE >>{
30

  
31

  
32
    private TransactionStatus tx;
33

  
34
    private ICdmApplicationConfiguration cdmRepository;
35
    private Classification classification = null;
36
    private Classification defaultClassification = null;
37
    private Reference ref = null;
38

  
39
    private TaxonDescription descriptionGroup = null;
40
    private DerivedUnit derivedUnitBase;
41

  
42
    private SpecimenImportReport report;
43

  
44
    private SpecimenDataHolder dataHolder;
45

  
46

  
47
    /**
48
     * @param config
49
     */
50
    protected SpecimenImportStateBase(CONFIG config) {
51
        super(config);
52
        // TODO Auto-generated constructor stub
53
    }
54

  
55
    /* -----Getter/Setter ---*/
56

  
57
    public TransactionStatus getTx() {
58
        return tx;
59
    }
60

  
61
    public void setTx(TransactionStatus tx) {
62
        this.tx = tx;
63
    }
64

  
65
    public ICdmApplicationConfiguration getCdmRepository() {
66
        return cdmRepository;
67
    }
68

  
69
    public void setCdmRepository(ICdmApplicationConfiguration cdmRepository) {
70
        this.cdmRepository = cdmRepository;
71
    }
72

  
73
    public Classification getClassification() {
74
        return classification;
75
    }
76

  
77
    public void setClassification(Classification classification) {
78
        this.classification = classification;
79
    }
80

  
81
    public Classification getDefaultClassification() {
82
        if(defaultClassification==null){
83
            final String defaultClassificationAbcd = "Default Classification ABCD";
84
            for (Classification classif : cdmRepository.getClassificationService().list(Classification.class, null, null, null, null)){
85
                if (classif.getTitleCache()!=null && classif.getTitleCache().equalsIgnoreCase(defaultClassificationAbcd)
86
                        && classif.getCitation()!=null && classif.getCitation().equals(getRef())) {
87
                    defaultClassification = classif;
88
                    break;
89
                }
90
            }
91
            if(defaultClassification==null){
92
                defaultClassification = Classification.NewInstance(defaultClassificationAbcd);
93
                cdmRepository.getClassificationService().save(defaultClassification);
94
            }
95
        }
96
        return defaultClassification;
97
    }
98

  
99
    public void setDefaultClassification(Classification defaultClassification) {
100
        this.defaultClassification = defaultClassification;
101
    }
102

  
103
    public Reference getRef() {
104
        return ref;
105
    }
106

  
107
    public void setRef(Reference ref) {
108
        this.ref = ref;
109
    }
110

  
111
    public TaxonDescription getDescriptionGroup() {
112
        return descriptionGroup;
113
    }
114

  
115
    public void setDescriptionGroup(TaxonDescription descriptionGroup) {
116
        this.descriptionGroup = descriptionGroup;
117
    }
118

  
119
    public DerivedUnit getDerivedUnitBase() {
120
        return derivedUnitBase;
121
    }
122

  
123
    public void setDerivedUnitBase(DerivedUnit derivedUnitBase) {
124
        this.derivedUnitBase = derivedUnitBase;
125
    }
126

  
127
    /**
128
     * @return the report
129
     */
130
    public SpecimenImportReport getReport() {
131
        return report;
132
    }
133

  
134
    /**
135
     * @param report the report to set
136
     */
137
    public void setReport(SpecimenImportReport report) {
138
        this.report = report;
139
    }
140

  
141
    /**
142
     *
143
     */
144
    public abstract void reset() ;
145

  
146
    /**
147
     * @return the dataHolder
148
     */
149
    public SpecimenDataHolder getDataHolder() {
150
        return dataHolder;
151
    }
152

  
153
    /**
154
     * @param dataHolder the dataHolder to set
155
     */
156
    public void setDataHolder(SpecimenDataHolder dataHolder) {
157
        this.dataHolder = dataHolder;
158
    }
159

  
160

  
161
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/UnitsGatheringEvent.java
293 293
        if (DEBUG) {
294 294
            System.out.println("getcoll:"+config.getPersons().get(collector.getTitleCache()));
295 295
        }
296
        this.gatheringEvent.setCollector(config.getPersons().get(collector.getTitleCache()));
296
       // this.gatheringEvent.setCollector(config.getPersons().get(collector.getTitleCache()));
297 297
    }
298 298

  
299 299
    /**
......
356 356
        if (DEBUG) {
357 357
            System.out.println("getteam:"+config.getTeams().get(t.getTitleCache()));
358 358
        }
359
        this.gatheringEvent.setCollector(config.getTeams().get(t.getTitleCache()));
359
        //this.gatheringEvent.setCollector(config.getTeams().get(t.getTitleCache()));
360 360
    }
361 361

  
362 362

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206DataHolder.java
16 16

  
17 17
import org.apache.log4j.Logger;
18 18

  
19
import eu.etaxonomy.cdm.io.specimen.SpecimenDataHolder;
19 20
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
20 21

  
21 22
/**
......
23 24
 * @date 16.06.2010
24 25
 *
25 26
 */
26
public class Abcd206DataHolder {
27
public class Abcd206DataHolder extends SpecimenDataHolder{
27 28
    @SuppressWarnings("unused")
28 29
    private static final Logger logger = Logger.getLogger(Abcd206DataHolder.class);
29 30

  
......
36 37

  
37 38
    //per unit
38 39
    protected List<Identification> identificationList;
39
    protected List<HashMap<String, String>> atomisedIdentificationList;
40
    private List<HashMap<String, String>> atomisedIdentificationList;
40 41
    protected Map<String, String> namedAreaList;
41 42
    protected List<String[]> referenceList;
42 43
    protected List<String> multimediaObjects;
43 44
    protected List<String> docSources;
44 45
    protected List<String> associatedUnitIds;
45 46

  
46
    protected String nomenclatureCode;
47
    private String nomenclatureCode;
47 48
    protected String institutionCode;
48 49
    protected String collectionCode;
49 50
    protected String unitID;
......
74 75

  
75 76
    public void reset() {
76 77

  
77
        nomenclatureCode = null;
78
        setNomenclatureCode(null);
78 79
        institutionCode = null;
79 80
        collectionCode = null;
80 81
        unitID = null;
......
103 104
        gatheringCoordinateErrorMethod = null;
104 105

  
105 106
        identificationList = new ArrayList<Identification>();
106
        atomisedIdentificationList = new ArrayList<HashMap<String, String>>();
107
        setAtomisedIdentificationList(new ArrayList<HashMap<String, String>>());
107 108
        namedAreaList = new HashMap<String, String>();
108 109
        referenceList = new ArrayList<String[]>();
109 110
        multimediaObjects = new ArrayList<String>();
......
111 112
        associatedUnitIds = new ArrayList<String>();
112 113
    }
113 114

  
115

  
116

  
117

  
114 118
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206Import.java
9 9

  
10 10
package eu.etaxonomy.cdm.io.specimen.abcd206.in;
11 11

  
12
import java.io.InputStream;
12 13
import java.net.MalformedURLException;
13 14
import java.util.ArrayList;
14 15
import java.util.HashMap;
......
26 27

  
27 28
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
28 29
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
29
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
30
import eu.etaxonomy.cdm.api.service.pager.Pager;
30
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
31 31
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
32 32
import eu.etaxonomy.cdm.io.specimen.SpecimenImportBase;
33 33
import eu.etaxonomy.cdm.io.specimen.SpecimenUserInteraction;
......
44 44
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
45 45
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
46 46
import eu.etaxonomy.cdm.model.common.Language;
47
import eu.etaxonomy.cdm.model.common.LanguageString;
48 47
import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
49 48
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
50
import eu.etaxonomy.cdm.model.description.DescriptionBase;
51 49
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
52 50
import eu.etaxonomy.cdm.model.description.Feature;
53 51
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
......
55 53
import eu.etaxonomy.cdm.model.location.NamedArea;
56 54
import eu.etaxonomy.cdm.model.media.Media;
57 55
import eu.etaxonomy.cdm.model.molecular.DnaSample;
58
import eu.etaxonomy.cdm.model.name.BacterialName;
59
import eu.etaxonomy.cdm.model.name.BotanicalName;
60
import eu.etaxonomy.cdm.model.name.CultivarPlantName;
61
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
62 56
import eu.etaxonomy.cdm.model.name.NonViralName;
63 57
import eu.etaxonomy.cdm.model.name.Rank;
64 58
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
65 59
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
66 60
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
67
import eu.etaxonomy.cdm.model.name.ZoologicalName;
68 61
import eu.etaxonomy.cdm.model.occurrence.Collection;
69 62
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
70 63
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
......
84 77
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
85 78
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
86 79
import eu.etaxonomy.cdm.persistence.query.MatchMode;
87
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
88
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
89 80

  
90 81
/**
91 82
 * @author p.kelbert
......
99 90

  
100 91
    private static final Logger logger = Logger.getLogger(Abcd206Import.class);
101 92

  
102
    private final boolean DEBUG = true;
93

  
103 94

  
104 95
    private static final String COLON = ":";
105 96

  
......
117 108
    @Override
118 109
    @SuppressWarnings("rawtypes")
119 110
    public void doInvoke(Abcd206ImportState state) {
111
        Abcd206ImportConfigurator config = state.getConfig();
120 112
        try{
121 113
            state.setTx(startTransaction());
122 114
            logger.info("INVOKE Specimen Import from ABCD2.06 XML ");
123

  
115
            InputStream response = null;
124 116
            //init cd repository
125 117
            if(state.getCdmRepository()==null){
126 118
                state.setCdmRepository(this);
127 119
            }
120
            if (config.getOccurenceQuery() != null){
121
                BioCaseQueryServiceWrapper queryService = new BioCaseQueryServiceWrapper();
122
                try {
128 123

  
129
            SpecimenUserInteraction sui = state.getConfig().getSpecimenUserInteraction();
124
                   response = queryService.query(config.getOccurenceQuery(), config.getSourceUri());
130 125

  
131
            //init import reference
132
            List<Reference> references = getReferenceService().list(Reference.class, null, null, null, null);
133

  
134
            if (state.getConfig().isInteractWithUser()){
135
                Map<String,Reference> refMap = new HashMap<String, Reference>();
136
                for (Reference reference : references) {
137
                    if (! StringUtils.isBlank(reference.getTitleCache())) {
138
                        refMap.put(reference.getTitleCache(),reference);
139
                    }
126
                }catch(Exception e){
127
                    logger.error("An error during ABCD import");
140 128
                }
141
                state.setRef(sui.askForReference(refMap));
129
            }
130
            SpecimenUserInteraction sui = ((Abcd206ImportConfigurator)state.getConfig()).getSpecimenUserInteraction();
142 131

  
143
                if (state.getRef() == null){
144
                    String cla = sui.createNewReference();
145
                    if (refMap.get(cla)!= null) {
146
                        state.setRef(refMap.get(cla));
147
                    } else {
148
                        state.setRef(ReferenceFactory.newGeneric());
149
                        state.getRef().setTitle(cla);
150
                    }
151
                }
152
                else{
153
                    state.setRef(getReferenceService().find(state.getRef().getUuid()));
154
                }
155
            }else{
132
            //init import reference
133
        //  List<Reference> references = getReferenceService().list(Reference.class, null, null, null, null);
134
            List<Reference> references = new ArrayList<Reference>();
135

  
136
//            if (state.getConfig().isInteractWithUser()){
137
//                Map<String,Reference> refMap = new HashMap<String, Reference>();
138
//                for (Reference reference : references) {
139
//                    if (! StringUtils.isBlank(reference.getTitleCache())) {
140
//                        refMap.put(reference.getTitleCache(),reference);
141
//                    }
142
//                }
143
//                state.setRef(sui.askForReference(refMap));
144
//
145
//                if (state.getRef() == null){
146
//                    String cla = sui.createNewReference();
147
//                    if (refMap.get(cla)!= null) {
148
//                        state.setRef(refMap.get(cla));
149
//                    } else {
150
//                        state.setRef(ReferenceFactory.newGeneric());
151
//                        state.getRef().setTitle(cla);
152
//                    }
153
//                }
154
//                else{
155
//                    state.setRef(getReferenceService().find(state.getRef().getUuid()));
156
//                }
157
//            }else{
156 158
                if (state.getRef()==null){
157
                    String name = NB(state.getConfig().getSourceReferenceTitle());
159
                    String name = NB(((Abcd206ImportConfigurator) state.getConfig()).getSourceReferenceTitle());
158 160
                    for (Reference reference : references) {
159 161
                        if (! StringUtils.isBlank(reference.getTitleCache())) {
160 162
                            if (reference.getTitleCache().equalsIgnoreCase(name)) {
......
167 169
                        state.getRef().setTitle("ABCD classic");
168 170
                    }
169 171
                }
170
            }
172
            //}
171 173
            save(state.getRef(), state);
172
            state.getConfig().setSourceReference(state.getRef());
174
            ((Abcd206ImportConfigurator) state.getConfig()).setSourceReference(state.getRef());
173 175

  
174
            if(state.getConfig().getClassificationUuid()!=null){
176
            if(((Abcd206ImportConfigurator) state.getConfig()).getClassificationUuid()!=null){
175 177
                //load classification from config if it exists
176
                state.setClassification(getClassificationService().load(state.getConfig().getClassificationUuid()));
178
                state.setClassification(getClassificationService().load(((Abcd206ImportConfigurator) state.getConfig()).getClassificationUuid()));
177 179
            }
178 180
            if(state.getClassification()==null){//no existing classification was set in config
179 181
                List<Classification> classificationList = getClassificationService().list(Classification.class, null, null, null, null);
180 182
                //get classification via user interaction
181
                if (state.getConfig().isUseClassification() && state.getConfig().isInteractWithUser()){
183
                if (((Abcd206ImportConfigurator) state.getConfig()).isUseClassification() && ((Abcd206ImportConfigurator) state.getConfig()).isInteractWithUser()){
182 184
                    Map<String,Classification> classMap = new HashMap<String, Classification>();
183 185
                    for (Classification tree : classificationList) {
184 186
                        if (! StringUtils.isBlank(tree.getTitleCache())) {
......
198 200
                }
199 201
                // use default classification as the classification to import into
200 202
                if (state.getClassification() == null) {
201
                    String name = NB(state.getConfig().getClassificationName());
203
                    String name = NB(((Abcd206ImportConfigurator) state.getConfig()).getClassificationName());
202 204
                    for (Classification classif : classificationList){
203 205
                        if (classif.getTitleCache() != null && classif.getTitleCache().equalsIgnoreCase(name)) {
204 206
                            state.setClassification(classif);
......
214 216
                }
215 217
            }
216 218

  
217
            UnitAssociationWrapper unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(state.getConfig().getSource(), state.getReport());
219
            if (response == null){
220
                response =(InputStream) ((Abcd206ImportConfigurator) state.getConfig()).getSource();
221
            }
222
            UnitAssociationWrapper unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(response, state.getReport());
218 223
            NodeList unitsList = unitAssociationWrapper.getAssociatedUnits();
219 224
            state.setPrefix(unitAssociationWrapper.getPrefix());
220 225

  
......
250 255
                    this.handleSingleUnit(state, item);
251 256

  
252 257
                }
253
                if(state.getConfig().isDeduplicateReferences()){
258
                if(((Abcd206ImportConfigurator)state.getConfig()).isDeduplicateReferences()){
254 259
                    getReferenceService().deduplicate(Reference.class, null, null);
255 260
                }
256
                if(state.getConfig().isDeduplicateClassifications()){
261
                if(((Abcd206ImportConfigurator)state.getConfig()).isDeduplicateClassifications()){
257 262
                    getClassificationService().deduplicate(Classification.class, null, null);
258 263
                }
259 264
            }
......
265 270
            state.getReport().addException(errorDuringImport, e);
266 271
        }
267 272
        finally{
268
            state.getReport().printReport(state.getConfig().getReportUri());
273
            state.getReport().printReport(((Abcd206ImportConfigurator)state.getConfig()).getReportUri());
269 274
        }
270 275
        return;
271 276
    }
......
277 282
     */
278 283
    @SuppressWarnings("rawtypes")
279 284
    private void handleSingleUnit(Abcd206ImportState state, Element item) {
285
        Abcd206ImportConfigurator config = (Abcd206ImportConfigurator)state.getConfig();
280 286
        if (DEBUG) {
281 287
            logger.info("handleSingleUnit "+state.getRef());
282 288
        }
... 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)