Project

General

Profile

Revision 2c12c2ca

ID2c12c2ca31d4ba79e5a4c940a66bed4b25ad9ea9
Parent 6a9f4423
Child 2c774ade

Added by Katja Luther almost 3 years ago

fix merge problems

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/SpecimenImportUtility.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.io.specimen.SpecimenImportConfiguratorBase;
13
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
14

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

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

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

  
48
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/UnitAssociationParser.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.IOException;
13
import java.io.InputStream;
14
import java.net.URI;
15

  
16
import org.apache.http.client.ClientProtocolException;
17
import org.apache.log4j.Logger;
18
import org.w3c.dom.Element;
19

  
20
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
21
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
22
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
23

  
24
/**
25
 * @author pplitzner
26
 * @date 16.06.2015
27
 *
28
 */
29
public class UnitAssociationParser {
30

  
31
    private static final Logger logger = Logger.getLogger(UnitAssociationParser.class);
32

  
33
    private final String prefix;
34

  
35
    private final Abcd206ImportReport report;
36

  
37
    private final ICdmApplicationConfiguration cdmAppController;
38

  
39
    public UnitAssociationParser(String prefix, Abcd206ImportReport report, ICdmApplicationConfiguration cdmAppController) {
40
        this.prefix = prefix;
41
        this.report = report;
42
        this.cdmAppController = cdmAppController;
43
    }
44

  
45
    public UnitAssociationWrapper parse(Element unitAssociation){
46
        if(prefix.equals("abcd:")){
47

  
48
        }
49
        else if(prefix.equals("abcd21:")){
50

  
51
        }
52
        //unit id
53
        String unitId = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"UnitID"));
54
        if(unitId==null){
55
            unitId = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociatedUnitID"));//abcd 2.0.6
56
        }
57
        //institution code
58
        String institutionCode = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"SourceInstitutionCode"));
59
        if(institutionCode==null){
60
            institutionCode = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociatedUnitSourceInstitutionCode"));//abcd 2.0.6
61
        }
62
        //institution name
63
        String institutionName = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"SourceName"));
64
        if(institutionName==null){
65
            institutionName = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociatedUnitSourceName"));//abcd 2.0.6
66
        }
67
        //data access point
68
        URI datasetAccessPoint = AbcdParseUtility.parseFirstUri(unitAssociation.getElementsByTagName(prefix+"DatasetAccessPoint"), report);
69
        if(datasetAccessPoint==null){
70
            datasetAccessPoint = AbcdParseUtility.parseFirstUri(unitAssociation.getElementsByTagName(prefix+"Comment"), report);//abcd 2.0.6
71
        }
72
        //association type
73
        String associationType = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociationType"));
74

  
75
        String unableToLoadMessage = String.format("Unable to load unit %s from %s", unitId, datasetAccessPoint);
76
        if(unitId!=null && datasetAccessPoint!=null){
77
            BioCaseQueryServiceWrapper serviceWrapper = new BioCaseQueryServiceWrapper();
78
            OccurenceQuery query = new OccurenceQuery(unitId);
79
            try {
80
                InputStream inputStream = serviceWrapper.query(query, datasetAccessPoint);
81
                if(inputStream!=null){
82
                    UnitAssociationWrapper unitAssociationWrapper = null;
83
                    try {
84
                        unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(inputStream, report);
85
                    } catch (Exception e) {
86
                        String exceptionMessage = "An exception occurred during parsing of associated units!";
87
                        logger.error(exceptionMessage, e);
88
                        report.addException(exceptionMessage, e);
89
                    }
90

  
91
                    if(unitAssociationWrapper!=null){
92
                        unitAssociationWrapper.setAssociationType(associationType);
93
                        if(unitAssociationWrapper.getAssociatedUnits()!=null && unitAssociationWrapper.getAssociatedUnits().getLength()>1){
94
                            String moreThanOneUnitFoundMessage = String.format("More than one unit was found for unit association to %s", unitId);
95
                            logger.warn(moreThanOneUnitFoundMessage);
96
                            report.addInfoMessage(moreThanOneUnitFoundMessage);
97
                        }
98
                    }
99
                    return unitAssociationWrapper;
100
                }
101
                else{
102
                    logger.error(unableToLoadMessage);
103
                    report.addInfoMessage(unableToLoadMessage);
104
                }
105
            } catch (ClientProtocolException e) {
106
                logger.error(unableToLoadMessage, e);
107
                report.addInfoMessage(unableToLoadMessage);
108
            } catch (IOException e) {
109
                logger.error(unableToLoadMessage, e);
110
                report.addInfoMessage(unableToLoadMessage);
111
            }
112
        }
113
        else{
114
            report.addInfoMessage(unableToLoadMessage);
115
        }
116
        return null;
117
    }
118

  
119
}
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.IOException;
13
import java.io.InputStream;
14
import java.net.URI;
15
import java.util.HashSet;
16
import java.util.Set;
17

  
18
import org.apache.http.client.ClientProtocolException;
19
import org.apache.log4j.Logger;
20
import org.w3c.dom.Element;
21

  
22
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
23
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
24
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
25

  
26
/**
27
 * @author pplitzner
28
 * @date 16.06.2015
29
 *
30
 */
31
public class UnitAssociationParser {
32

  
33
    private static final Logger logger = Logger.getLogger(UnitAssociationParser.class);
34

  
35
    private final String prefix;
36

  
37
    private final SpecimenImportReport report;
38

  
39
    private final ICdmApplicationConfiguration cdmAppController;
40

  
41
    public UnitAssociationParser(String prefix, SpecimenImportReport report, ICdmApplicationConfiguration cdmAppController) {
42
        this.prefix = prefix;
43
        this.report = report;
44
        this.cdmAppController = cdmAppController;
45
    }
46

  
47
    public UnitAssociationWrapper parse(Element unitAssociation){
48
        if(prefix.equals("abcd:")){
49

  
50
        }
51
        else if(prefix.equals("abcd21:")){
52

  
53
        }
54
        //unit id
55
        String unitId = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"UnitID"));
56
        if(unitId==null){
57
            unitId = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociatedUnitID"));//abcd 2.0.6
58
        }
59
        //institution code
60
        String institutionCode = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"SourceInstitutionCode"));
61
        if(institutionCode==null){
62
            institutionCode = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociatedUnitSourceInstitutionCode"));//abcd 2.0.6
63
        }
64
        //institution name
65
        String institutionName = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"SourceName"));
66
        if(institutionName==null){
67
            institutionName = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociatedUnitSourceName"));//abcd 2.0.6
68
        }
69
        //data access point
70
        URI datasetAccessPoint = AbcdParseUtility.parseFirstUri(unitAssociation.getElementsByTagName(prefix+"DatasetAccessPoint"), report);
71
        if(datasetAccessPoint==null){
72
            datasetAccessPoint = AbcdParseUtility.parseFirstUri(unitAssociation.getElementsByTagName(prefix+"Comment"), report);//abcd 2.0.6
73
        }
74
        //association type
75
        String associationType = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociationType"));
76

  
77
        String unableToLoadMessage = String.format("Unable to load unit %s from %s", unitId, datasetAccessPoint);
78
        if(unitId!=null && datasetAccessPoint!=null){
79
            BioCaseQueryServiceWrapper serviceWrapper = new BioCaseQueryServiceWrapper();
80
            Set<String[]> unitIds = new HashSet<String[]>();
81
            String[] unitIdArray = {unitId};
82
            unitIds.add(unitIdArray);
83
            OccurenceQuery query = new OccurenceQuery(unitIds);
84
            try {
85
                InputStream inputStream = serviceWrapper.query(query, datasetAccessPoint);
86
                if(inputStream!=null){
87
                    UnitAssociationWrapper unitAssociationWrapper = null;
88
                    try {
89
                        unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(inputStream, report);
90
                    } catch (Exception e) {
91
                        String exceptionMessage = "An exception occurred during parsing of associated units!";
92
                        logger.error(exceptionMessage, e);
93
                        report.addException(exceptionMessage, e);
94
                    }
95

  
96
                    if(unitAssociationWrapper!=null){
97
                        unitAssociationWrapper.setAssociationType(associationType);
98
                        if(unitAssociationWrapper.getAssociatedUnits()!=null && unitAssociationWrapper.getAssociatedUnits().getLength()>1){
99
                            String moreThanOneUnitFoundMessage = String.format("More than one unit was found for unit association to %s", unitId);
100
                            logger.warn(moreThanOneUnitFoundMessage);
101
                            report.addInfoMessage(moreThanOneUnitFoundMessage);
102
                        }
103
                    }
104
                    return unitAssociationWrapper;
105
                }
106
                else{
107
                    logger.error(unableToLoadMessage);
108
                    report.addInfoMessage(unableToLoadMessage);
109
                }
110
            } catch (ClientProtocolException e) {
111
                logger.error(unableToLoadMessage, e);
112
                report.addInfoMessage(unableToLoadMessage);
113
            } catch (IOException e) {
114
                logger.error(unableToLoadMessage, e);
115
                report.addInfoMessage(unableToLoadMessage);
116
            }
117
        }
118
        else{
119
            report.addInfoMessage(unableToLoadMessage);
120
        }
121
        return null;
122
    }
123

  
124
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)