Project

General

Profile

« Previous | Next » 

Revision cfd4c9cb

Added by Andreas Müller over 6 years ago

ref #6792 fix latest issues in SalvadorSpecimenImport

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/salvador/SalvadorSpecimenImport.java
74 74
        initDedupHelper();
75 75
        try {
76 76
            UUID factUuid = UUID.fromString(state.getCurrentRecord().get("specimenFactUuid"));
77

  
77 78
            if (existingFieldUnits.get(factUuid)== null){
78
                FieldUnit fieldUnit = getFieldUnit(state);
79

  
80
                FieldUnit fieldUnit = makeFieldUnit(state);
79 81
                DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(
80 82
                        SpecimenOrObservationType.PreservedSpecimen, fieldUnit);
81 83
                makeFieldUnitData(state, facade);
......
117 119
     */
118 120
    private void makeSpecimenDuplicate(SalvadorSpecimenImportState state,
119 121
            DerivedUnitFacade facade) {
122

  
120 123
        Map<String, String> record = state.getCurrentRecord();
124

  
125
        TaxonDescription desc = getTaxonDescription(state, record);
126

  
121 127
        int row = state.getRow();
122 128
        String herbariaStr = record.get("Herbaria");
123 129
        String[] splits = herbariaStr.split(";");
......
133 139
                    URI uri = URI.create(uriStr);
134 140
                    facade.setPreferredStableUri(uri);
135 141
                }
142
                IndividualsAssociation assoc = IndividualsAssociation.NewInstance(facade.innerDerivedUnit());
143
                assoc.setFeature(Feature.SPECIMEN());
144
                desc.addElement(assoc);
136 145
            }
146

  
137 147
        }
138 148
    }
139 149

  
140 150

  
141 151
    private Map<UUID, FieldUnit> fieldUnitMap = new HashMap<>();
142 152
    private Map<UUID, UUID> existingFieldUnits = new HashMap<>();
143
    private FieldUnit getFieldUnit(SalvadorSpecimenImportState state) {
153
    private FieldUnit makeFieldUnit(SalvadorSpecimenImportState state) {
144 154

  
145 155
        Map<String, String> record = state.getCurrentRecord();
146
        int row = state.getRow();
147 156
        UUID factUuid = UUID.fromString(record.get("specimenFactUuid"));
148 157

  
149 158
        TextData textSpecimen = (TextData)getDescriptionService().getDescriptionElementByUuid(factUuid);
150 159
        textSpecimen.setFeature(getTexSpecimenFeature());
151 160

  
152
        TaxonDescription desc = getTaxonDescription(state, textSpecimen, record, row);
153 161
        FieldUnit fieldUnit = FieldUnit.NewInstance();
154
        IndividualsAssociation assoc = IndividualsAssociation.NewInstance(fieldUnit);
155
        assoc.setFeature(Feature.SPECIMEN());
156
        desc.addElement(assoc);
162

  
157 163
        fieldUnitMap.put(factUuid, fieldUnit);
158 164
        existingFieldUnits.put(factUuid, fieldUnit.getUuid());
159 165

  
160 166
        return fieldUnit;
161 167
    }
162 168

  
169
    //taxonUuid, TaxonDescription map
163 170
    private Map<UUID, TaxonDescription> taxonDescMap = new HashMap<>();
171
    //taxonUuid, TaxonDescription.uuid map
164 172
    private Map<UUID, UUID> existingTaxonDescs = new HashMap<>();
165 173

  
166 174
    private TaxonDescription getTaxonDescription(SalvadorSpecimenImportState state,
167
            TextData textSpecimen, Map<String, String> record, int row) {
175
            Map<String, String> record) {
176

  
177
        int row = state.getRow();
168 178
        UUID taxonUuid = UUID.fromString(record.get("taxonUuid"));
169 179
        TaxonDescription taxonDesc = taxonDescMap.get(taxonUuid);
170 180
        if (taxonDesc == null && existingTaxonDescs.get(taxonUuid) != null){
......
172 182
            taxonDescMap.put(taxonUuid, taxonDesc);
173 183
        }
174 184
        if (taxonDesc == null){
175
            Taxon taxon = CdmBase.deproxy(textSpecimen.getInDescription(),
176
                    TaxonDescription.class).getTaxon();
185

  
186
            Taxon taxon = (Taxon)getTaxonService().find(taxonUuid);
187

  
177 188
            taxonDesc = TaxonDescription.NewInstance(taxon);
178 189
            taxonDesc.setTitleCache("JACQ import for " + taxon.getName().getTitleCache(), true);
179 190
            taxonDesc.addImportSource(null, null, state.getConfig().getSourceReference(), String.valueOf(row));
......
194 205
    private void makeSpecimen(SalvadorSpecimenImportState state, DerivedUnitFacade facade) {
195 206

  
196 207
        Map<String, String> record = state.getCurrentRecord();
208

  
209
        TaxonDescription desc = getTaxonDescription(state, record);
210

  
197 211
        int row = state.getRow();
198 212
        String herbariaStr = record.get("Herbaria");
199 213
        String laguUuidStr = record.get("LAGU_UUID");
......
226 240
                    unit.setPreferredStableUri(uri);
227 241
                }
228 242
            }
243

  
244
            IndividualsAssociation assoc = IndividualsAssociation.NewInstance(unit);
245
            assoc.setFeature(Feature.SPECIMEN());
246
            desc.addElement(assoc);
229 247
        }
230 248
    }
231 249

  
......
282 300
        //CollectionDate
283 301
        String collectionDate = record.get("CollectionDate");
284 302
        if (collectionDate != null){
285
            DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-dd");
286
            collectionDate = collectionDate.replace(" 00:00:00", "");
287
            DateTime dateTime = f.parseDateTime(collectionDate);
288
            TimePeriod tp = TimePeriod.NewInstance(dateTime, null);
303
            TimePeriod tp;
304
            if (collectionDate.equals("1987")){
305
                tp = TimePeriod.NewInstance(1987);
306
                state.getResult().addWarning("Only year is not correct: " + collectionDate, state.getRow());
307
            }else{
308
                DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-dd");
309
                collectionDate = collectionDate.replace(" 00:00:00", "");
310
                DateTime dateTime = f.parseDateTime(collectionDate);
311
                tp = TimePeriod.NewInstance(dateTime, null);
312
            }
289 313
            facade.getGatheringEvent(true).setTimeperiod(tp);
290 314
        }
291 315
        //Country
......
404 428
     */
405 429
    private ExtensionType getExtensionType() {
406 430
        if (identificationHistoryType == null){
407
            identificationHistoryType = ExtensionType.NewInstance("Identification History", "IdentificationHistory", null);
431
            identificationHistoryType = ExtensionType.NewInstance("Identification History", "Identification History", null);
408 432
            UUID vocUuid = uuidUserDefinedExtensionTypeVocabulary;
409 433
            TermVocabulary<ExtensionType> voc = getVocabularyService().find(vocUuid);
410 434
            if (voc == null){
......
506 530
    private TeamOrPersonBase<?> makeCollectorTeam(SalvadorSpecimenImportState state, Map<String, String> record, int row) {
507 531

  
508 532
        Team team = Team.NewInstance();
509
        makeCollector(state, 0, team, record, row);
510
        makeCollector(state, 1, team, record, row);
511
        makeCollector(state, 2, team, record, row);
512
        makeCollector(state, 3, team, record, row);
513
        makeCollector(state, 4, team, record, row);
514
        if (team.getTeamMembers().size() == 0){
515
            return null;
516
        }else if (team.getTeamMembers().size() == 1){
517
            return team.getTeamMembers().get(0);
518
        }else{
533
        String first = record.get("COLLECTOR_0");
534
        if(first != null && first.startsWith("Grupo Ecológico")){
535
            team.setTitleCache(first, true);
519 536
            return team;
537
        }else{
538
            makeCollector(state, 0, team, record, row);
539
            makeCollector(state, 1, team, record, row);
540
            makeCollector(state, 2, team, record, row);
541
            makeCollector(state, 3, team, record, row);
542
            makeCollector(state, 4, team, record, row);
543
            if (team.getTeamMembers().size() == 0){
544
                return null;
545
            }else if (team.getTeamMembers().size() == 1){
546
                return team.getTeamMembers().get(0);
547
            }else{
548
                return team;
549
            }
520 550
        }
521 551
    }
522 552

  
......
527 557
        if (str == null){
528 558
            return;
529 559
        }else{
530
            Person person = parsePerson(state, str, row);
531
            team.addTeamMember(person);
560
            parsePerson(state, str, team, row);
532 561
        }
533 562
        return ;
534 563
    }
535 564

  
536 565
    /**
537 566
     * @param str
567
     * @param team
538 568
     * @param row
539 569
     * @param importResult
540 570
     */
541
    private Person parsePerson(SalvadorSpecimenImportState state, String str, int row) {
571
    private void parsePerson(SalvadorSpecimenImportState state, String str, Team team, int row) {
542 572
        Person result = Person.NewInstance();
543
        String regEx = "(.*),([A-Z]\\.)+";
573
        String regEx = "(.*),(([A-Z]\\.)+(\\sde)?)";
544 574
        Pattern pattern = Pattern.compile(regEx);
545 575
        Matcher matcher = pattern.matcher(str);
546 576

  
577
        String noInitials = "(Campo|Chinchilla|Campos|Claus|Desconocido|Fomtg|Huezo|Martínez|"
578
                + "Quezada|Romero|Ruíz|Sandoval|Serrano|Vásquez|Cabrera|Calderón)";
547 579

  
548 580
        if (matcher.matches()){
549 581
            String lastname = matcher.group(1);
550 582
            result.setLastname(lastname);
551 583
            String initials = matcher.group(2);
552 584
            result.setInitials(initials);
585
        }else if (str.matches(noInitials)){
586
            result.setLastname(str);
587
        }else if (str.matches("Martínez, F. de M.")){
588
            result.setLastname("Martínez");
589
            result.setInitials("F. de M.");
590
        }else if (str.equals("et al.")){
591
            team.setHasMoreMembers(true);
592
            return;
593
        }else if (str.startsWith("Grupo Ecológico")){
594
            result.setLastname(str);
553 595
        }else{
554 596
            String message = "Collector did not match pattern: " + str;
555 597
            state.getResult().addWarning(message, row);
......
557 599
        }
558 600
        result = (Person)dedupHelper.getExistingAuthor(null, result);
559 601

  
560
        return result;
602
        team.addTeamMember(result);
603
        return ;
561 604
    }
562 605

  
563 606

  

Also available in: Unified diff