Project

General

Profile

Revision c7415eab

IDc7415eab2a750f343284b5804cfb5c02c71af1c1
Parent 7f271868
Child cef0a41d

Added by Patrick Plitzner about 3 years ago

Saving files before refreshing line endings

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/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/abcd206/in/AbcdImportUtility.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 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.abcd206.in;
11

  
12
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
13

  
14
/**
15
 * @author pplitzner
16
 * @date 16.06.2015
17
 *
18
 */
19
public class AbcdImportUtility {
20

  
21
    public static String getUnitID(DerivedUnit derivedUnit, Abcd206ImportConfigurator config){
22
        if(config.isMapUnitIdToAccessionNumber()){
23
            return derivedUnit.getAccessionNumber();
24
        }
25
        if(config.isMapUnitIdToBarcode()){
26
            return derivedUnit.getBarcode();
27
        }
28
        return derivedUnit.getCatalogNumber();
29
    }
30

  
31
    public static void setUnitID(DerivedUnit derivedUnit, String unitId, Abcd206ImportConfigurator config){
32
        if(config.isMapUnitIdToCatalogNumber()
33
                || !(config.isMapUnitIdToAccessionNumber() || config.isMapUnitIdToBarcode() || config.isMapUnitIdToCatalogNumber())){
34
            // set catalog number (default if nothing is set)
35
            derivedUnit.setCatalogNumber(unitId);
36
        }
37
        if(config.isMapUnitIdToAccessionNumber()){
38
            derivedUnit.setAccessionNumber(unitId);
39
        }
40
        if(config.isMapUnitIdToBarcode()){
41
            derivedUnit.setBarcode(unitId);
42
        }
43
    }
44

  
45
}
1
// $Id$
2
/**
3
* Copyright (C) 2015 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.abcd206.in;
11

  
12
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
13

  
14
/**
15
 * @author pplitzner
16
 * @date 16.06.2015
17
 *
18
 */
19
public class AbcdImportUtility {
20

  
21
    public static String getUnitID(DerivedUnit derivedUnit, Abcd206ImportConfigurator config){
22
        if(config.isMapUnitIdToAccessionNumber()){
23
            return derivedUnit.getAccessionNumber();
24
        }
25
        if(config.isMapUnitIdToBarcode()){
26
            return derivedUnit.getBarcode();
27
        }
28
        return derivedUnit.getCatalogNumber();
29
    }
30

  
31
    public static void setUnitID(DerivedUnit derivedUnit, String unitId, Abcd206ImportConfigurator config){
32
        if(config.isMapUnitIdToCatalogNumber()
33
                || !(config.isMapUnitIdToAccessionNumber() || config.isMapUnitIdToBarcode() || config.isMapUnitIdToCatalogNumber())){
34
            // set catalog number (default if nothing is set)
35
            derivedUnit.setCatalogNumber(unitId);
36
        }
37
        if(config.isMapUnitIdToAccessionNumber()){
38
            derivedUnit.setAccessionNumber(unitId);
39
        }
40
        if(config.isMapUnitIdToBarcode()){
41
            derivedUnit.setBarcode(unitId);
42
        }
43
    }
44

  
45
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/AbcdParseUtility.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 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.abcd206.in;
11

  
12
import java.io.InputStream;
13
import java.net.URI;
14
import java.util.Date;
15
import java.util.List;
16

  
17
import javax.xml.parsers.DocumentBuilder;
18
import javax.xml.parsers.DocumentBuilderFactory;
19

  
20
import org.apache.log4j.Logger;
21
import org.joda.time.DateTime;
22
import org.w3c.dom.Document;
23
import org.w3c.dom.Element;
24
import org.w3c.dom.Node;
25
import org.w3c.dom.NodeList;
26

  
27
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
28
import eu.etaxonomy.cdm.model.reference.Reference;
29
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
30
import eu.etaxonomy.cdm.persistence.query.MatchMode;
31

  
32
/**
33
 * @author pplitzner
34
 * @date 16.06.2015
35
 *
36
 */
37
public class AbcdParseUtility {
38

  
39
    private static final Logger logger = Logger.getLogger(AbcdParseUtility.class);
40

  
41

  
42
    public static URI parseFirstUri(NodeList nodeList, SpecimenImportReport report){
43
        URI uri = null;
44
        String textContent = parseFirstTextContent(nodeList);
45
        if(textContent!=null){
46
            try {
47
                uri = URI.create(textContent);
48
            } catch (IllegalArgumentException e) {
49
                if(report!=null){
50
                    report.addException("Exception during URI parsing!", e);
51
                }
52
            }
53
        }
54
        return uri;
55
    }
56

  
57
    public static String parseFirstTextContent(NodeList nodeList){
58
        return parseFirstTextContent(nodeList, true);
59
    }
60

  
61
    public static String parseFirstTextContent(NodeList nodeList, boolean cleanUpWhiteSpaces){
62
        String string = null;
63
        if(nodeList.getLength()>0){
64
            string = nodeList.item(0).getTextContent();
65
            if(cleanUpWhiteSpaces){
66
                string = string.replace("\n", "").replaceAll("( )+", " ").trim();
67
            }
68
        }
69
        return string;
70
    }
71

  
72
    public static Double parseFirstDouble(NodeList nodeList, SpecimenImportReport report){
73
        if(nodeList.getLength()>0){
74
            return parseDouble(nodeList.item(0), report);
75
        }
76
        return null;
77
    }
78

  
79
    public static Double parseDouble(Node node, SpecimenImportReport report){
80
        String message = "Could not parse double value for node " + node.getNodeName();
81
        Double doubleValue = null;
82
        try{
83
            String textContent = node.getTextContent();
84
            //remove 1000 dots
85
            textContent = textContent.replace(".","");
86
            //convert commmas
87
            textContent = textContent.replace(",",".");
88
            doubleValue = Double.parseDouble(textContent);
89
        } catch (NullPointerException npe){
90
            logger.error(message, npe);
91
            if(report!=null){
92
                report.addException(message, npe);
93
            }
94
        } catch (NumberFormatException nfe){
95
            logger.error(message, nfe);
96
            if(report!=null){
97
                report.addException(message, nfe);
98
            }
99
        }
100
        return doubleValue;
101
    }
102

  
103
    public static DateTime parseFirstDateTime(NodeList nodeList) {
104
        DateTime dateTime = null;
105
        String textContent = parseFirstTextContent(nodeList);
106
        if(textContent!=null){
107
            dateTime = DateTime.parse(textContent);
108
        }
109
        return dateTime;
110
    }
111

  
112
    public static Date parseFirstDate(NodeList nodeList) {
113
        Date date = null;
114
        DateTime dateTime = parseFirstDateTime(nodeList);
115
        if(dateTime!=null){
116
            date = dateTime.toDate();
117
        }
118
        return date;
119
    }
120

  
121
    public static Reference parseFirstReference(NodeList referenceNodeList, ICdmApplicationConfiguration cdmAppController){
122
        String referenceCitation = AbcdParseUtility.parseFirstTextContent(referenceNodeList);
123
        //check if reference already exists
124
        List<Reference> matchingReferences = cdmAppController.getReferenceService().findByTitle(Reference.class, referenceCitation, MatchMode.EXACT, null, null, null, null, null).getRecords();
125
        Reference reference;
126
        if(matchingReferences.size()==1){
127
            reference = matchingReferences.iterator().next();
128
        }
129
        else{
130
            reference = ReferenceFactory.newGeneric();
131
            reference.setTitle(referenceCitation);
132
            cdmAppController.getReferenceService().saveOrUpdate(reference);
133
        }
134
        return reference;
135
    }
136

  
137
    /**
138
     * Return the wrapper with the list of root nodes for an ABCD XML file
139
     * @param fileName: the file's location
140
     * @return a wrapper with a list of root nodes ("Unit")
141
     */
142
    public static UnitAssociationWrapper parseUnitsNodeList(InputStream inputStream, SpecimenImportReport report) {
143
        UnitAssociationWrapper unitAssociationWrapper = new UnitAssociationWrapper();
144
        NodeList unitList = null;
145
        try {
146
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
147
            DocumentBuilder builder = factory.newDocumentBuilder();
148

  
149
            Document document = builder.parse(inputStream);
150
            Element root = document.getDocumentElement();
151
            unitList = root.getElementsByTagName("Unit");
152
            if (unitList.getLength()>0) {
153
                unitAssociationWrapper.setPrefix("");
154
                unitAssociationWrapper.setAssociatedUnits(unitList);
155
                return unitAssociationWrapper;
156
            }
157
            unitList = root.getElementsByTagName("abcd:Unit");
158
            if (unitList.getLength()>0) {
159
                unitAssociationWrapper.setPrefix("abcd:");
160
                unitAssociationWrapper.setAssociatedUnits(unitList);
161
                return unitAssociationWrapper;
162
            }
163
            unitList = root.getElementsByTagName("abcd21:Unit");
164
            if (unitList.getLength()>0) {
165
                unitAssociationWrapper.setPrefix("abcd21:");
166
                unitAssociationWrapper.setAssociatedUnits(unitList);
167
            }
168
        } catch (Exception e) {
169
            logger.warn(e);
170
            if(report!=null){
171
                report.addException("Exception during parsing of nodeList!", e);
172
            }
173
        }
174
        return unitAssociationWrapper;
175
    }
176

  
177
}
1
// $Id$
2
/**
3
* Copyright (C) 2015 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.abcd206.in;
11

  
12
import java.io.InputStream;
13
import java.net.URI;
14
import java.util.Date;
15
import java.util.List;
16

  
17
import javax.xml.parsers.DocumentBuilder;
18
import javax.xml.parsers.DocumentBuilderFactory;
19

  
20
import org.apache.log4j.Logger;
21
import org.joda.time.DateTime;
22
import org.w3c.dom.Document;
23
import org.w3c.dom.Element;
24
import org.w3c.dom.Node;
25
import org.w3c.dom.NodeList;
26

  
27
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
28
import eu.etaxonomy.cdm.model.reference.Reference;
29
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
30
import eu.etaxonomy.cdm.persistence.query.MatchMode;
31

  
32
/**
33
 * @author pplitzner
34
 * @date 16.06.2015
35
 *
36
 */
37
public class AbcdParseUtility {
38

  
39
    private static final Logger logger = Logger.getLogger(AbcdParseUtility.class);
40

  
41

  
42
    public static URI parseFirstUri(NodeList nodeList, SpecimenImportReport report){
43
        URI uri = null;
44
        String textContent = parseFirstTextContent(nodeList);
45
        if(textContent!=null){
46
            try {
47
                uri = URI.create(textContent);
48
            } catch (IllegalArgumentException e) {
49
                if(report!=null){
50
                    report.addException("Exception during URI parsing!", e);
51
                }
52
            }
53
        }
54
        return uri;
55
    }
56

  
57
    public static String parseFirstTextContent(NodeList nodeList){
58
        return parseFirstTextContent(nodeList, true);
59
    }
60

  
61
    public static String parseFirstTextContent(NodeList nodeList, boolean cleanUpWhiteSpaces){
62
        String string = null;
63
        if(nodeList.getLength()>0){
64
            string = nodeList.item(0).getTextContent();
65
            if(cleanUpWhiteSpaces){
66
                string = string.replace("\n", "").replaceAll("( )+", " ").trim();
67
            }
68
        }
69
        return string;
70
    }
71

  
72
    public static Double parseFirstDouble(NodeList nodeList, SpecimenImportReport report){
73
        if(nodeList.getLength()>0){
74
            return parseDouble(nodeList.item(0), report);
75
        }
76
        return null;
77
    }
78

  
79
    public static Double parseDouble(Node node, SpecimenImportReport report){
80
        String message = "Could not parse double value for node " + node.getNodeName();
81
        Double doubleValue = null;
82
        try{
83
            String textContent = node.getTextContent();
84
            //remove 1000 dots
85
            textContent = textContent.replace(".","");
86
            //convert commmas
87
            textContent = textContent.replace(",",".");
88
            doubleValue = Double.parseDouble(textContent);
89
        } catch (NullPointerException npe){
90
            logger.error(message, npe);
91
            if(report!=null){
92
                report.addException(message, npe);
93
            }
94
        } catch (NumberFormatException nfe){
95
            logger.error(message, nfe);
96
            if(report!=null){
97
                report.addException(message, nfe);
98
            }
99
        }
100
        return doubleValue;
101
    }
102

  
103
    public static DateTime parseFirstDateTime(NodeList nodeList) {
104
        DateTime dateTime = null;
105
        String textContent = parseFirstTextContent(nodeList);
106
        if(textContent!=null){
107
            dateTime = DateTime.parse(textContent);
108
        }
109
        return dateTime;
110
    }
111

  
112
    public static Date parseFirstDate(NodeList nodeList) {
113
        Date date = null;
114
        DateTime dateTime = parseFirstDateTime(nodeList);
115
        if(dateTime!=null){
116
            date = dateTime.toDate();
117
        }
118
        return date;
119
    }
120

  
121
    public static Reference parseFirstReference(NodeList referenceNodeList, ICdmApplicationConfiguration cdmAppController){
122
        String referenceCitation = AbcdParseUtility.parseFirstTextContent(referenceNodeList);
123
        //check if reference already exists
124
        List<Reference> matchingReferences = cdmAppController.getReferenceService().findByTitle(Reference.class, referenceCitation, MatchMode.EXACT, null, null, null, null, null).getRecords();
125
        Reference reference;
126
        if(matchingReferences.size()==1){
127
            reference = matchingReferences.iterator().next();
128
        }
129
        else{
130
            reference = ReferenceFactory.newGeneric();
131
            reference.setTitle(referenceCitation);
132
            cdmAppController.getReferenceService().saveOrUpdate(reference);
133
        }
134
        return reference;
135
    }
136

  
137
    /**
138
     * Return the wrapper with the list of root nodes for an ABCD XML file
139
     * @param fileName: the file's location
140
     * @return a wrapper with a list of root nodes ("Unit")
141
     */
142
    public static UnitAssociationWrapper parseUnitsNodeList(InputStream inputStream, SpecimenImportReport report) {
143
        UnitAssociationWrapper unitAssociationWrapper = new UnitAssociationWrapper();
144
        NodeList unitList = null;
145
        try {
146
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
147
            DocumentBuilder builder = factory.newDocumentBuilder();
148

  
149
            Document document = builder.parse(inputStream);
150
            Element root = document.getDocumentElement();
151
            unitList = root.getElementsByTagName("Unit");
152
            if (unitList.getLength()>0) {
153
                unitAssociationWrapper.setPrefix("");
154
                unitAssociationWrapper.setAssociatedUnits(unitList);
155
                return unitAssociationWrapper;
156
            }
157
            unitList = root.getElementsByTagName("abcd:Unit");
158
            if (unitList.getLength()>0) {
159
                unitAssociationWrapper.setPrefix("abcd:");
160
                unitAssociationWrapper.setAssociatedUnits(unitList);
161
                return unitAssociationWrapper;
162
            }
163
            unitList = root.getElementsByTagName("abcd21:Unit");
164
            if (unitList.getLength()>0) {
165
                unitAssociationWrapper.setPrefix("abcd21:");
166
                unitAssociationWrapper.setAssociatedUnits(unitList);
167
            }
168
        } catch (Exception e) {
169
            logger.warn(e);
170
            if(report!=null){
171
                report.addException("Exception during parsing of nodeList!", e);
172
            }
173
        }
174
        return unitAssociationWrapper;
175
    }
176

  
177
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/AbcdPersonParser.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 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.abcd206.in;
11

  
12
import java.util.List;
13

  
14
import org.w3c.dom.Element;
15
import org.w3c.dom.NodeList;
16

  
17
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
18
import eu.etaxonomy.cdm.model.agent.AgentBase;
19
import eu.etaxonomy.cdm.model.agent.Person;
20
import eu.etaxonomy.cdm.persistence.query.MatchMode;
21

  
22
/**
23
 * @author pplitzner
24
 * @date 16.06.2015
25
 *
26
 */
27
public class AbcdPersonParser {
28

  
29
    private final String prefix;
30

  
31
    private final SpecimenImportReport report;
32

  
33
    private final ICdmApplicationConfiguration cdmAppController;
34

  
35

  
36
    public AbcdPersonParser(String prefix, SpecimenImportReport report, ICdmApplicationConfiguration cdmAppController) {
37
        this.prefix = prefix;
38
        this.report = report;
39
        this.cdmAppController = cdmAppController;
40
    }
41

  
42

  
43
    public AgentBase<?> parse(Element item) {
44
        AgentBase<?> agentBase = null;
45
        NodeList fullNameList = item.getElementsByTagName(prefix+"FullName");
46
        String fullName = AbcdParseUtility.parseFirstTextContent(fullNameList);
47
        if(fullName!=null){
48
            List<AgentBase> matchingAgents = cdmAppController.getAgentService().findByTitle(AgentBase.class, fullName, MatchMode.EXACT, null, null, null, null, null).getRecords();
49
            if(matchingAgents.size()==1){
50
                agentBase = matchingAgents.iterator().next();
51
            }
52
            else{
53
                agentBase = Person.NewTitledInstance(fullName);
54
            }
55
        }
56
        return agentBase;
57
    }
58

  
59

  
60
}
1
// $Id$
2
/**
3
* Copyright (C) 2015 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.abcd206.in;
11

  
12
import java.util.List;
13

  
14
import org.w3c.dom.Element;
15
import org.w3c.dom.NodeList;
16

  
17
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
18
import eu.etaxonomy.cdm.model.agent.AgentBase;
19
import eu.etaxonomy.cdm.model.agent.Person;
20
import eu.etaxonomy.cdm.persistence.query.MatchMode;
21

  
22
/**
23
 * @author pplitzner
24
 * @date 16.06.2015
25
 *
26
 */
27
public class AbcdPersonParser {
28

  
29
    private final String prefix;
30

  
31
    private final SpecimenImportReport report;
32

  
33
    private final ICdmApplicationConfiguration cdmAppController;
34

  
35

  
36
    public AbcdPersonParser(String prefix, SpecimenImportReport report, ICdmApplicationConfiguration cdmAppController) {
37
        this.prefix = prefix;
38
        this.report = report;
39
        this.cdmAppController = cdmAppController;
40
    }
41

  
42

  
43
    public AgentBase<?> parse(Element item) {
44
        AgentBase<?> agentBase = null;
45
        NodeList fullNameList = item.getElementsByTagName(prefix+"FullName");
46
        String fullName = AbcdParseUtility.parseFirstTextContent(fullNameList);
47
        if(fullName!=null){
48
            List<AgentBase> matchingAgents = cdmAppController.getAgentService().findByTitle(AgentBase.class, fullName, MatchMode.EXACT, null, null, null, null, null).getRecords();
49
            if(matchingAgents.size()==1){
50
                agentBase = matchingAgents.iterator().next();
51
            }
52
            else{
53
                agentBase = Person.NewTitledInstance(fullName);
54
            }
55
        }
56
        return agentBase;
57
    }
58

  
59

  
60
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/SpecimenImportReport.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 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.abcd206.in;
11

  
12
import java.io.File;
13
import java.io.FileNotFoundException;
14
import java.io.PrintStream;
15
import java.io.PrintWriter;
16
import java.io.StringWriter;
17
import java.net.URI;
18
import java.util.ArrayList;
19
import java.util.HashMap;
20
import java.util.HashSet;
21
import java.util.List;
22
import java.util.Map;
23
import java.util.Map.Entry;
24
import java.util.Set;
25

  
26
import org.apache.log4j.Logger;
27

  
28
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
29
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
30
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
31
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
32
import eu.etaxonomy.cdm.model.taxon.Taxon;
33
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
34

  
35
/**
36
 * Gathers information about the ABCD import and presents them in a suitable way.
37
 * @author pplitzner
38
 * @date Jan 23, 2015
39
 *
40
 */
41
public class SpecimenImportReport {
42

  
43
    static private final Logger logger = Logger.getLogger(SpecimenImportReport.class);
44

  
45

  
46
    private final List<Taxon> createdTaxa = new ArrayList<Taxon>();
47
    private final Map<Taxon, List<UnitIdSpecimen>> taxonToAssociatedSpecimens =  new HashMap<Taxon, List<UnitIdSpecimen>>();
48
    private final Map<UnitIdSpecimen, List<UnitIdSpecimen>> derivateMap = new HashMap<UnitIdSpecimen, List<UnitIdSpecimen>>();
49
    private final List<UnitIdSpecimen> alreadyExistingSpecimens = new ArrayList<UnitIdSpecimen>();
50
    private final List<TaxonNameBase<?, ?>> createdNames = new ArrayList<TaxonNameBase<?,?>>();
51
    private final List<TaxonNode> createdTaxonNodes = new ArrayList<TaxonNode>();
52
    private final List<String> infoMessages = new ArrayList<String>();
53

  
54
    public void addTaxon(Taxon taxon){
55
        createdTaxa.add(taxon);
56
    }
57

  
58
    public void addName(TaxonNameBase<?, ?> taxonName){
59
        createdNames.add(taxonName);
60
    }
61

  
62
    public void addTaxonNode(TaxonNode taxonNode){
63
        createdTaxonNodes.add(taxonNode);
64
    }
65

  
66
    public void addDerivate(DerivedUnit parent, Abcd206ImportConfigurator config){
67
        addDerivate(parent, null, config);
68
    }
69

  
70
    public void addDerivate(DerivedUnit parent, DerivedUnit child, Abcd206ImportConfigurator config){
71
        UnitIdSpecimen parentUnitIdSpecimen = new UnitIdSpecimen(SpecimenImportUtility.getUnitID(parent, config), parent);
72
        List<UnitIdSpecimen> children = derivateMap.get(parentUnitIdSpecimen);
73
        if(children==null){
74
            children = new ArrayList<UnitIdSpecimen>();
75
        }
76
        if(child!=null){
77
            children.add(new UnitIdSpecimen(SpecimenImportUtility.getUnitID(child, config), child));
78
        }
79
        derivateMap.put(parentUnitIdSpecimen, children);
80
    }
81

  
82
    public void addIndividualAssociation(Taxon taxon, String derivedUnitId, DerivedUnit derivedUnitBase) {
83
        UnitIdSpecimen derivedUnitIdSpecimen = new UnitIdSpecimen(derivedUnitId, derivedUnitBase);
84
        List<UnitIdSpecimen> associatedSpecimens = taxonToAssociatedSpecimens.get(taxon);
85
        if(associatedSpecimens==null){
86
            associatedSpecimens = new ArrayList<UnitIdSpecimen>();
87
        }
88
        associatedSpecimens.add(derivedUnitIdSpecimen);
89
        taxonToAssociatedSpecimens.put(taxon, associatedSpecimens);
90
    }
91

  
92
    public void addAlreadyExistingSpecimen(String unitId, DerivedUnit derivedUnit){
93
        alreadyExistingSpecimens.add(new UnitIdSpecimen(unitId, derivedUnit));
94
    }
95

  
96
    public void addException(String message, Exception e) {
97
        StringWriter errors = new StringWriter();
98
        e.printStackTrace(new PrintWriter(errors));
99
        infoMessages.add(message+"\n"+e.getMessage()+"\n"+errors.toString());
100
    }
101

  
102
    public void addInfoMessage(String message) {
103
        infoMessages.add(message);
104
    }
105

  
106
    public void printReport(URI reportUri) {
107
        PrintStream out;
108
        if(reportUri != null){
109
            try {
110
                out = new PrintStream(new File(reportUri));
111
            } catch (FileNotFoundException e) {
112
                logger.warn("Report file could not be found.");
113
                out = System.out;
114
            }
115
        }
116
        else{
117
            out = System.out;
118
        }
119
        printReport(out);
120
    }
121

  
122

  
123
    public void printReport(PrintStream out) {
124

  
125
        out.println("++++++++Import Report+++++++++");
126
      //all specimens
127
        Set<UnitIdSpecimen> allSpecimens = new HashSet<UnitIdSpecimen>();
128
        for (Entry<UnitIdSpecimen, List<UnitIdSpecimen>> entry : derivateMap.entrySet()) {
129
            UnitIdSpecimen parentSpecimen = entry.getKey();
130
            allSpecimens.add(parentSpecimen);
131
            for (UnitIdSpecimen childSpecimen : entry.getValue()) {
132
                allSpecimens.add(childSpecimen);
133
            }
134
        }
135
        out.println("Specimens created: "+allSpecimens.size());
136
        Map<SpecimenOrObservationType, Integer> specimenTypeToCount = new HashMap<SpecimenOrObservationType, Integer>();
137
        for (UnitIdSpecimen unitIdSpecimen : allSpecimens) {
138
            incrementSpecimenTypeCount(specimenTypeToCount, unitIdSpecimen);
139
        }
140
        for(Entry<SpecimenOrObservationType, Integer> entry:specimenTypeToCount.entrySet()){
141
            SpecimenOrObservationType type = entry.getKey();
142
            out.println(type+": "+entry.getValue());
143
        }
144
        out.println("\n");
145

  
146
        //taxon name
147
        out.println("---Created Taxon Names ("+createdNames.size()+")---");
148
        for (TaxonNameBase<?, ?> taxonName : createdNames) {
149
            out.println(taxonName.getTitleCache());
150
        }
151
        out.println("\n");
152

  
153
        //taxa
154
        out.println("---Created Taxa ("+createdTaxa.size()+")---");
155
        for (Taxon taxon : createdTaxa) {
156
            out.println(taxon.getTitleCache());
157
        }
158
        out.println("\n");
159

  
160
        //taxon nodes
161
        out.println("---Created Taxon Nodes ("+createdTaxonNodes.size()+")---");
162
        for (TaxonNode taxonNode : createdTaxonNodes) {
163
            String nodeString = taxonNode.toString();
164
            if(taxonNode.getTaxon()!=null){
165
                nodeString += " ("+taxonNode.getTaxon().getTitleCache()+")";
166
            }
167
            if(taxonNode.getParent()!=null){
168
                nodeString += " with parent "+taxonNode.getParent();
169
                if(taxonNode.getParent().getTaxon()!=null){
170
                    nodeString += " ("+taxonNode.getParent().getTaxon().getTitleCache()+")";
171
                }
172
            }
173
            out.println(nodeString);
174
        }
175
        out.println("\n");
176

  
177
        //not imported
178
        out.println("---Already existing specimen (not imported)---");
179
        for(UnitIdSpecimen specimen:alreadyExistingSpecimens){
180
            out.println(formatSpecimen(specimen));
181
        }
182
        out.println("\n");
183

  
184
        //taxa with associated specimens
185
        out.println("---Taxa with associated specimens---");
186
        for(Entry<Taxon, List<UnitIdSpecimen>> entry:taxonToAssociatedSpecimens.entrySet()){
187
            Taxon taxon = entry.getKey();
188
            List<UnitIdSpecimen> specimens = entry.getValue();
189
            out.println(taxon.getTitleCache() + " ("+specimens.size()+")");
190
            for (UnitIdSpecimen derivedUnit : specimens) {
191
                out.println("\t- "+formatSpecimen(derivedUnit));
192
                //check for derivatives
193
                List<UnitIdSpecimen> list = derivateMap.get(derivedUnit);
194
                for (UnitIdSpecimen derivate : list) {
195
                    out.println("\t\t- "+formatSpecimen(derivate));
196
                }
197
            }
198
        }
199
        out.println("\n");
200
        out.println("\n");
201
        //info messages
202
        out.println("---Info messages---");
203
        for(String message:infoMessages){
204
            out.println(message);
205
            out.println("---");
206
        }
207
        if(out!=System.out){
208
            out.close();
209
        }
210
    }
211

  
212
    private void incrementSpecimenTypeCount(Map<SpecimenOrObservationType, Integer> specimenTypeToCount,
213
            UnitIdSpecimen specimen) {
214
        SpecimenOrObservationType specimenType = specimen.getSpecimen().getRecordBasis();
215
        Integer count = specimenTypeToCount.get(specimenType);
216
        if(count==null){
217
            count = 1;
218
        }
219
        else{
220
            count++;
221
        }
222
        specimenTypeToCount.put(specimenType, count);
223
    }
224

  
225
    private String formatSpecimen(UnitIdSpecimen specimen){
226
        return "("+specimen.getUnitId()+") ["+specimen.getSpecimen().getRecordBasis()+"] "+specimen.getSpecimen().getTitleCache();
227
    }
228

  
229
    private class UnitIdSpecimen{
230
        private final String unitId;
231
        private final SpecimenOrObservationBase<?> specimen;
232

  
233

  
234
        public UnitIdSpecimen(String unitId, SpecimenOrObservationBase<?> specimen) {
235
            super();
236
            this.unitId = unitId;
237
            this.specimen = specimen;
238
        }
239
        public String getUnitId() {
240
            return unitId;
241
        }
242
        public SpecimenOrObservationBase<?> getSpecimen() {
243
            return specimen;
244
        }
245
        @Override
246
        public int hashCode() {
247
            final int prime = 31;
248
            int result = 1;
249
            result = prime * result + ((specimen == null) ? 0 : specimen.hashCode());
250
            result = prime * result + ((unitId == null) ? 0 : unitId.hashCode());
251
            return result;
252
        }
253
        @Override
254
        public boolean equals(Object obj) {
255
            if (this == obj) {
256
                return true;
257
            }
258
            if (obj == null) {
259
                return false;
260
            }
261
            if (getClass() != obj.getClass()) {
262
                return false;
263
            }
264
            UnitIdSpecimen other = (UnitIdSpecimen) obj;
265
            if (specimen == null) {
266
                if (other.specimen != null) {
267
                    return false;
268
                }
269
            } else if (!specimen.equals(other.specimen)) {
270
                return false;
... 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)