Project

General

Profile

« Previous | Next » 

Revision 0429965c

Added by Andreas Müller almost 8 years ago

#5822 / #5892 Mexico rubiaceae import

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/mexico/MexicoConabioTaxonImport.java
17 17
import java.util.Set;
18 18
import java.util.UUID;
19 19

  
20
import org.apache.commons.lang3.StringUtils;
20 21
import org.apache.log4j.Logger;
21 22
import org.springframework.stereotype.Component;
22 23

  
23 24
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
24 25
import eu.etaxonomy.cdm.model.agent.Person;
25 26
import eu.etaxonomy.cdm.model.agent.Team;
27
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
26 28
import eu.etaxonomy.cdm.model.common.Annotation;
27 29
import eu.etaxonomy.cdm.model.common.AnnotationType;
28 30
import eu.etaxonomy.cdm.model.common.CdmBase;
......
37 39
import eu.etaxonomy.cdm.model.name.NonViralName;
38 40
import eu.etaxonomy.cdm.model.name.Rank;
39 41
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
42
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
40 43
import eu.etaxonomy.cdm.model.reference.Reference;
41 44
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
45
import eu.etaxonomy.cdm.model.reference.ReferenceType;
42 46
import eu.etaxonomy.cdm.model.taxon.Classification;
43 47
import eu.etaxonomy.cdm.model.taxon.Synonym;
44 48
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
......
114 118

  
115 119
        //Name
116 120
        BotanicalName speciesName = makeName(line, record, state);
117
        String statusStr = getValue(record, "EstatusNombre");
118 121

  
122
        //sec
119 123
        String secRefStr = getValueNd(record, "ReferenciaNombre");
120 124
        Reference sec = getSecRef(state, secRefStr, line);
121 125

  
126
        //status
127
        String statusStr = getValue(record, "EstatusNombre");
122 128
        TaxonBase<?> taxonBase;
123 129
        if ("aceptado".equals(statusStr)){
124 130
            taxonBase = Taxon.NewInstance(speciesName, sec);
......
128 134
            throw new RuntimeException(line + " Status not recognized: " + statusStr);
129 135
        }
130 136

  
137
        //annotation
131 138
        String annotation = getValue(record, "Anotacion al Taxon");
132 139
        if (annotation != null && (!annotation.equals("nom. illeg.") || !annotation.equals("nom. cons."))){
133 140
            taxonBase.addAnnotation(Annotation.NewInstance(annotation, AnnotationType.EDITORIAL(), Language.SPANISH_CASTILIAN()));
134 141
        }
135 142

  
143
        //id
136 144
        String idCat = getValue(record, "IdCAT");
137 145
        this.addOriginalSource(taxonBase, idCat, TAXON_NAMESPACE, state.getConfig().getSourceReference());
138 146

  
147
        //save
139 148
        getTaxonService().save(taxonBase);
140 149
        taxonIdMap.put(idCat, taxonBase);
141 150

  
......
153 162
        if (result == null && secRefStr != null){
154 163
            result = ReferenceFactory.newBook();
155 164
            TimePeriod tp = TimePeriodParser.parseString(secRefStr.substring(secRefStr.length()-4));
156
            String authorStr = secRefStr.substring(0, secRefStr.length()-6);
157
            if (! (authorStr + ", " + tp.getYear()).equals(secRefStr)){
165
            String authorStrPart = secRefStr.substring(0, secRefStr.length()-6);
166
            if (! (authorStrPart + ", " + tp.getYear()).equals(secRefStr)){
158 167
                logger.warn(line + "Sec ref could not be parsed: " + secRefStr);
159 168
            }else{
160 169
                result.setDatePublished(tp);
161 170
            }
162

  
163
            if (authorStr.contains(",") || authorStr.contains("&")){
164
                //TODO split
165
                Team team = Team.NewTitledInstance(authorStr, null);
166
                result.setAuthorship(team);
167
            }else if (authorStr.equals("Tropicos") || authorStr.equals("The plant list")
168
                    || authorStr.equals("APG IV")){
169
                result.setTitle(authorStr);
170

  
171
            TeamOrPersonBase<?> author = state.getAgentBase(authorStrPart);
172
            if (author == null){
173
                if (authorStrPart.contains("&")){
174
                    Team team = Team.NewInstance();
175
                    String[] authorSplit = authorStrPart.split("&");
176
                    String[] firstAuthorSplit = authorSplit[0].trim().split(",");
177
                    for (String authorStr : firstAuthorSplit){
178
                        addTeamMember(team, authorStr);
179
                    }
180
                    addTeamMember(team, authorSplit[1]);
181
                    result.setAuthorship(team);
182
                    state.putAgentBase(team.getTitleCache(), team);
183
                }else if (authorStrPart.equalsIgnoreCase("Tropicos") || authorStrPart.equalsIgnoreCase("The Plant List")
184
                        || authorStrPart.equalsIgnoreCase("APG IV")){
185
                    result.setTitle(authorStrPart);
186
                }else{
187
                    Person person = Person.NewInstance();
188
                    person.setLastname(authorStrPart);
189
                    result.setAuthorship(person);
190
                    state.putAgentBase(person.getTitleCache(), person);
191
                }
171 192
            }else{
172
                Person person = Person.NewTitledInstance(authorStr);
173
                result.setAuthorship(person);
193
                result.setAuthorship(author);
174 194
            }
175

  
195
            state.putReference(secRefStr, result);
176 196
        }else if(secRefStr == null){
177
            logger.warn(line + "Empty secRefStr not yet implemented");
197
            return state.getConfig().getSecReference();
178 198
        }
179 199

  
180 200
        return result;
......
182 202

  
183 203

  
184 204

  
205
    /**
206
     * @param team
207
     * @param author
208
     */
209
    private void addTeamMember(Team team, String author) {
210
        if (StringUtils.isNotBlank(author)){
211
            Person person = Person.NewInstance();
212
            person.setLastname(author.trim());
213
            team.addTeamMember(person);
214
        }
215
    }
216

  
217

  
218

  
185 219
    /**
186 220
     * @param record
187 221
     * @param state
......
196 230
        String idCat = getValue(record, "IdCAT");
197 231
        String rankStr = getValue(record, "CategoriaTaxonomica");
198 232
        String annotation = getValue(record, "Anotacion al Taxon");
233

  
234
        //rank
199 235
        Rank rank = null;
200 236
        try {
201 237
            rank = state.getTransformer().getRankByKey(rankStr);
......
207 243
            logger.warn(line + "Rank not recognized: " + rankStr);
208 244
        }
209 245

  
246
        //name + author
210 247
        String fullNameStr = nameStr + (authorStr != null ? " " + authorStr : "");
211 248

  
212 249
        BotanicalName fullName = (BotanicalName)nameParser.parseFullName(fullNameStr, NomenclaturalCode.ICNAFP, rank);
213 250
        if (fullName.isProtectedTitleCache()){
214 251
            logger.warn(line + "Name could not be parsed: " + fullNameStr );
215 252
        }else{
216
            replaceAuthorNames(state, fullName);
253
            replaceAuthorNamesAndNomRef(state, fullName);
217 254
        }
218 255
        BotanicalName existingName = getExistingName(state, fullName);
219 256

  
257
        //reference
220 258
        String refNameStr = getRefNameStr(nomRefStr, refType, fullNameStr);
221 259

  
222 260
        BotanicalName referencedName = (BotanicalName)nameParser.parseReferencedName(refNameStr, NomenclaturalCode.ICNAFP, rank);
223 261
        if (referencedName.isProtectedFullTitleCache() || referencedName.isProtectedTitleCache()){
224 262
            logger.warn(line + "Referenced name could not be parsed: " + refNameStr );
225 263
        }else{
226
            replaceAuthorNames(state, referencedName);
264
            addSourcesToReferences(referencedName, state);
265
            replaceAuthorNamesAndNomRef(state, referencedName);
227 266
        }
267
        adaptRefTypeForGeneric(referencedName, refType);
228 268

  
269
        //compare nom. ref. with Borhidi
229 270
        BotanicalName result= referencedName;
230 271
        Boolean equal = null;
231 272
        if (existingName != null){
......
242 283
        }
243 284
        addNomRefExtension(state, result, equal);
244 285

  
245
        if (annotation != null && ! annotation.equals("nom. illeg.") && ! annotation.equals("nom. cons.")){
286
        //status
287
        if (annotation != null && (annotation.equals("nom. illeg.") || annotation.equals("nom. cons."))){
246 288
            try {
247 289
                NomenclaturalStatusType nomStatusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(annotation, result);
248 290
                result.addStatus(NomenclaturalStatus.NewInstance(nomStatusType));
......
258 300

  
259 301

  
260 302

  
303
    /**
304
     * @param name
305
     * @param state
306
     */
307
    private void addSourcesToReferences(BotanicalName name, SimpleExcelTaxonImportState<CONFIG> state) {
308
        Reference nomRef = (Reference)name.getNomenclaturalReference();
309
        if (nomRef != null){
310
            nomRef.addSource(makeOriginalSource(state));
311
            if (nomRef.getInReference() != null){
312
                nomRef.getInReference().addSource(makeOriginalSource(state));
313
            }
314
        }
315
    }
316

  
317

  
318

  
319
    /**
320
     * @param referencedName
321
     * @param refType
322
     */
323
    private void adaptRefTypeForGeneric(BotanicalName referencedName, String refTypeStr) {
324
        INomenclaturalReference ref = referencedName.getNomenclaturalReference();
325
        if (ref == null){
326
            return;
327
        }
328
        ReferenceType refType = refTypeByRefTypeStr(refTypeStr);
329
        if (ref.getType() != refType && refType == ReferenceType.Book){
330
            ref.setType(refType);
331
        }
332
    }
333

  
334

  
335
    private ReferenceType refTypeByRefTypeStr(String refType){
336
        if ("A".equals(refType)){  //Article
337
            return ReferenceType.Article;
338
        }else if ("B".equals(refType)){   //Book
339
            return ReferenceType.Book;
340
        }else if (refType == null){   //Book
341
            return null;
342
        }else{
343
            throw new IllegalArgumentException("RefType not supported " + refType);
344
        }
345
    }
346

  
261 347
    /**
262 348
     * @param nomRefStr
263 349
     * @param refType
264 350
     * @param fullNameStr
265 351
     * @return
266 352
     */
267
    private String getRefNameStr(String nomRefStr, String refType, String fullNameStr) {
353
    private String getRefNameStr(String nomRefStr, String refTypeStr, String fullNameStr) {
268 354
        String refNameStr = fullNameStr;
269
        if ("A".equals(refType)){  //Article
355
        ReferenceType refType = refTypeByRefTypeStr(refTypeStr);
356
        if (refType == ReferenceType.Article){
270 357
            refNameStr = fullNameStr + " in " + nomRefStr;
271
        }else if ("B".equals(refType)){   //Book
358
        }else if (refType == ReferenceType.Book){
272 359
            refNameStr = fullNameStr + ", " + nomRefStr;
360
        }else if (refType == null && nomRefStr != null){
361
            logger.warn("RefType is null but nomRefStr exists");
273 362
        }
274 363
        return refNameStr;
275 364
    }
......
302 391
     * @param fullName
303 392
     * @return
304 393
     */
305
    @SuppressWarnings("rawtypes")
306 394
    private BotanicalName getExistingName(SimpleExcelTaxonImportState<CONFIG> state, BotanicalName fullName) {
395
        initExistinNames(state);
396
        return (BotanicalName)state.getName(fullName.getTitleCache());
397
    }
398

  
399
    /**
400
     * @param state
401
     */
402
    @SuppressWarnings("rawtypes")
403
    private void initExistinNames(SimpleExcelTaxonImportState<CONFIG> state) {
307 404
        if (!nameMapIsInitialized){
308 405
            List<String> propertyPaths = Arrays.asList("");
309 406
            List<TaxonNameBase> existingNames = this.getNameService().list(null, null, null, null, propertyPaths);
......
312 409
            }
313 410
            nameMapIsInitialized = true;
314 411
        }
315
        return (BotanicalName)state.getName(fullName.getTitleCache());
316 412
    }
317 413

  
414

  
415

  
318 416
    /**
319 417
     * @param record
320 418
     * @param string
......
417 515
            MexicoConabioImportConfigurator config = state.getConfig();
418 516
            classification = Classification.NewInstance(config.getClassificationName());
419 517
            classification.setUuid(config.getClassificationUuid());
420
            classification.setReference(config.getSourceReference());
518
            classification.setReference(config.getSecReference());
421 519
            getClassificationService().save(classification);
422 520
        }
423 521
        return classification;

Also available in: Unified diff