Project

General

Profile

« Previous | Next » 

Revision 99e92829

Added by Andreas Müller about 7 years ago

ref #6286 FloraHellenica import transactional

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/greece/FloraHellenicaCommentsImport.java
15 15

  
16 16
import org.apache.log4j.Logger;
17 17
import org.springframework.stereotype.Component;
18
import org.springframework.transaction.TransactionStatus;
18 19

  
19 20
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
20 21
import eu.etaxonomy.cdm.model.common.Language;
......
53 54
        return "comments";
54 55
    }
55 56

  
57
    private boolean isFirst = true;
58
    private TransactionStatus tx = null;
56 59
    /**
57 60
     * {@inheritDoc}
58 61
     */
59 62
    @Override
60 63
    protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) {
64
        if (isFirst){
65
            tx = this.startTransaction();
66
            isFirst = false;
67
        }
61 68

  
62 69
        String line = state.getCurrentLine() + ": ";
63 70
        HashMap<String, String> record = state.getOriginalRecord();
......
73 80
        makeComment(state, line, record, noStr);
74 81
    }
75 82

  
83
    @Override
84
    protected void secondPass(SimpleExcelTaxonImportState<CONFIG> state) {
85
        if (tx != null){
86
            this.commitTransaction(tx);
87
            tx = null;
88
        }
89
    }
90

  
76 91

  
77 92
    /**
78 93
     * @param state
app-import/src/main/java/eu/etaxonomy/cdm/io/greece/FloraHellenicaExcludedTaxonImport.java
15 15

  
16 16
import org.apache.log4j.Logger;
17 17
import org.springframework.stereotype.Component;
18
import org.springframework.transaction.TransactionStatus;
18 19

  
19 20
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
20 21
import eu.etaxonomy.cdm.model.name.BotanicalName;
......
60 61
        return "excluded taxa";
61 62
    }
62 63

  
64
    private boolean isFirst = true;
65
    private TransactionStatus tx = null;
63 66
    /**
64 67
     * {@inheritDoc}
65 68
     */
66 69
    @Override
67 70
    protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) {
71
        if (isFirst){
72
            tx = this.startTransaction();
73
            isFirst = false;
74
        }
68 75

  
69 76
        String line = state.getCurrentLine() + ": ";
70 77
        HashMap<String, String> record = state.getOriginalRecord();
......
83 90
        }
84 91
    }
85 92

  
93
    @Override
94
    protected void secondPass(SimpleExcelTaxonImportState<CONFIG> state) {
95
        if (tx != null){
96
            this.commitTransaction(tx);
97
            tx = null;
98
        }
99
    }
100

  
86 101

  
87 102
    /**
88 103
     * @param state
app-import/src/main/java/eu/etaxonomy/cdm/io/greece/FloraHellenicaImportBase.java
81 81
            String message = state.getCurrentLine()+  ": Accepted taxon could not be found: " + accStr;
82 82
            logger.warn(message);
83 83
            return null;
84
        }else{
85
            accTaxon = (Taxon)getTaxonService().find(accTaxon.getUuid());
84 86
        }
85 87
        return accTaxon;
86 88
    }
app-import/src/main/java/eu/etaxonomy/cdm/io/greece/FloraHellenicaSynonymImport.java
17 17

  
18 18
import org.apache.log4j.Logger;
19 19
import org.springframework.stereotype.Component;
20
import org.springframework.transaction.TransactionStatus;
20 21

  
21 22
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
22 23
import eu.etaxonomy.cdm.model.name.INonViralName;
......
59 60
        return "synonyms";
60 61
    }
61 62

  
63
    private boolean isFirst = true;
64
    private TransactionStatus tx = null;
62 65
    /**
63 66
     * {@inheritDoc}
64 67
     */
65 68
    @Override
66 69
    protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) {
70
        if (isFirst){
71
            tx = this.startTransaction();
72
            isFirst = false;
73
        }
67 74

  
68 75
        String line = state.getCurrentLine() + ": ";
69 76
        HashMap<String, String> record = state.getOriginalRecord();
......
80 87
        getTaxonService().saveOrUpdate(relatedTaxon);
81 88
    }
82 89

  
90
    @Override
91
    protected void secondPass(SimpleExcelTaxonImportState<CONFIG> state) {
92
        if (tx != null){
93
            this.commitTransaction(tx);
94
            tx = null;
95
        }
96
    }
97

  
83 98

  
84 99
    /**
85 100
     * @param state
app-import/src/main/java/eu/etaxonomy/cdm/io/greece/FloraHellenicaTaxonImport.java
18 18

  
19 19
import org.apache.log4j.Logger;
20 20
import org.springframework.stereotype.Component;
21
import org.springframework.transaction.TransactionStatus;
21 22

  
22 23
import eu.etaxonomy.cdm.api.service.ITermService;
23 24
import eu.etaxonomy.cdm.common.CdmUtils;
......
84 85

  
85 86

  
86 87
   private  static List<String> expectedKeys= Arrays.asList(new String[]{
87
            "Unique ID","Group","Family","Genus","Species","Species Author","Subspecies","Subspecies Author",
88
            "Unique ID","uuid","Group","Family","Genus","Species","Species Author","Subspecies","Subspecies Author",
88 89
            "IoI","NPi","SPi","Pe","StE","EC","NC","NE","NAe","WAe","Kik","KK","EAe",
89 90
            STATUS,CHOROLOGICAL_CATEGOGY,LIFE_FORM,"A","C","G","H","M","P","R","W", "Taxon"
90 91
    });
......
98 99
        return "valid taxa names";
99 100
    }
100 101

  
102

  
103
    private boolean isFirst = true;
104
    private TransactionStatus tx = null;
101 105
    /**
102 106
     * {@inheritDoc}
103 107
     */
104 108
    @Override
105 109
    protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) {
110
        if (isFirst){
111
            tx = this.startTransaction();
112
            isFirst = false;
113
        }
106 114
        initAreaVocabulary(state);
107 115
        initLifeformVocabulary(state);
108 116
        initHabitatVocabulary(state);
......
138 146
        state.putTaxon(noStr, taxon);
139 147
    }
140 148

  
149

  
150
    @Override
151
    protected void secondPass(SimpleExcelTaxonImportState<CONFIG> state) {
152
        if (tx != null){
153
            this.commitTransaction(tx);
154
            tx = null;
155
        }
156
    }
157

  
158

  
141 159
    boolean hasFeatureTree = false;
142 160
    /**
143 161
     * @param state
......
373 391
        String speciesAuthorStr = getValue(record, "Species Author");
374 392
        String subSpeciesStr = getValue(record, "Subspecies");
375 393
        String subSpeciesAuthorStr = getValue(record, "Subspecies Author");
394
        String uuidStr = getValue(record, "uuid");
395
        UUID uuid = UUID.fromString(uuidStr);
376 396
        boolean isSubSpecies = isNotBlank(subSpeciesStr);
377 397
        boolean isAutonym = isSubSpecies && speciesStr.equals(subSpeciesStr);
378 398
        if (isSubSpecies && ! isAutonym && isBlank(subSpeciesAuthorStr)){
......
399 419
        Taxon taxon = Taxon.NewInstance(name, getSecReference(state));
400 420
        taxon.addImportSource(noStr, getWorksheetName(), getSourceCitation(state), null);
401 421
//        String parentStr = isSubSpecies ? makeSpeciesKey(genusStr, speciesStr, speciesAuthorStr) : genusStr;
422
        taxon.setUuid(uuid);
402 423
        String parentStr = genusStr;
403 424
        boolean genusAsBefore = genusStr.equals(lastGenus);
404 425
        boolean speciesAsBefore = speciesStr.equals(lastSpecies);
......
906 927
        //FIXME
907 928
//        addMapping(greece, xx "mex_adm0", "iso", "MEX");
908 929

  
909
        addArea(state, "IoI", "Ionian Islands", FloraHellenicaTransformer.uuidAreaIoI);
910
        addArea(state, "NPi", "North Pindos", FloraHellenicaTransformer.uuidAreaNPi);
911
        addArea(state, "SPi", "South Pindos", FloraHellenicaTransformer.uuidAreaSPi);
912
        addArea(state, "Pe", "Peloponnisos", FloraHellenicaTransformer.uuidAreaPe);
913
        addArea(state, "StE", "Sterea Ellas", FloraHellenicaTransformer.uuidAreaStE);
914
        addArea(state, "EC", "East Central Greece", FloraHellenicaTransformer.uuidAreaEC);
915
        addArea(state, "NC", "North Central Greece", FloraHellenicaTransformer.uuidAreaNC);
916
        addArea(state, "NE", "North-East Greece", FloraHellenicaTransformer.uuidAreaNE);
917
        addArea(state, "NAe", "North Aegean islands", FloraHellenicaTransformer.uuidAreaNAe);
918
        addArea(state, "WAe", "West Aegean islands", FloraHellenicaTransformer.uuidAreaWAe);
919
        addArea(state, "Kik", "Kiklades", FloraHellenicaTransformer.uuidAreaKik);
920
        addArea(state, "KK", "Kriti and Karpathos", FloraHellenicaTransformer.uuidAreaKK);
921
        addArea(state, "EAe", "East Aegean islands", FloraHellenicaTransformer.uuidAreaEAe);
930
        addArea(state, "IoI", "Ionian Islands", 4, FloraHellenicaTransformer.uuidAreaIoI);
931
        addArea(state, "NPi", "North Pindos", 13, FloraHellenicaTransformer.uuidAreaNPi);
932
        addArea(state, "SPi", "South Pindos", 11, FloraHellenicaTransformer.uuidAreaSPi);
933
        addArea(state, "Pe", "Peloponnisos", 1, FloraHellenicaTransformer.uuidAreaPe);
934
        addArea(state, "StE", "Sterea Ellas", 12, FloraHellenicaTransformer.uuidAreaStE);
935
        addArea(state, "EC", "East Central Greece", 5, FloraHellenicaTransformer.uuidAreaEC);
936
        addArea(state, "NC", "North Central Greece", 2, FloraHellenicaTransformer.uuidAreaNC);
937
        addArea(state, "NE", "North-East Greece", 10, FloraHellenicaTransformer.uuidAreaNE);
938
        addArea(state, "NAe", "North Aegean islands", 7, FloraHellenicaTransformer.uuidAreaNAe);
939
        addArea(state, "WAe", "West Aegean islands", 9, FloraHellenicaTransformer.uuidAreaWAe);
940
        addArea(state, "Kik", "Kiklades", 8, FloraHellenicaTransformer.uuidAreaKik);
941
        addArea(state, "KK", "Kriti and Karpathos", 6, FloraHellenicaTransformer.uuidAreaKK);
942
        addArea(state, "EAe", "East Aegean islands", 3, FloraHellenicaTransformer.uuidAreaEAe);
922 943

  
923 944
        this.getVocabularyService().save(areasVoc);
924 945
        return;
925 946
    }
926 947

  
927
    private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel, UUID uuid) {
928
        addArea(state, abbrevLabel, areaLabel, uuid, areaLabel);  //short cut if label and mapping label are equal
948
    private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel,
949
            Integer id, UUID uuid) {
950
        addArea(state, abbrevLabel, areaLabel, uuid, String.valueOf(id));  //short cut if label and mapping label are equal
929 951
    }
930 952

  
931 953
    private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel,
......
939 961
     * @param string
940 962
     * @param uuidaguascalientes
941 963
     */
942
    private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel, UUID uuid, String mappingLabel, Integer id1) {
964
    private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel,
965
            UUID uuid, String mappingLabel, Integer id1) {
943 966
        NamedArea newArea = NamedArea.NewInstance(
944 967
                areaLabel, areaLabel, abbrevLabel);
945 968
        newArea.setIdInVocabulary(abbrevLabel);
......
948 971
        newArea.setLevel(null);
949 972
        newArea.setType(NamedAreaType.NATURAL_AREA());
950 973
        areasVoc.addTerm(newArea);
951
        //FIXME
952
        if (id1 != null){
953
            addMapping(newArea, "mex_adm1", "id_1", String.valueOf(id1));
954
        }else if (mappingLabel != null){
955
            addMapping(newArea, "mex_adm1", "name_1", mappingLabel);
974
        if (mappingLabel != null){
975
            addMapping(newArea, "phytogeographical_regions_of_greece", "id", mappingLabel);
956 976
        }
957 977
    }
958 978

  

Also available in: Unified diff