Project

General

Profile

« Previous | Next » 

Revision 9d7f0160

Added by Katja Luther about 8 years ago

minot

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/csv/caryophyllales/out/CsvNameExport.java
17 17

  
18 18
import org.apache.log4j.Logger;
19 19
import org.springframework.stereotype.Component;
20
import org.unitils.spring.annotation.SpringBeanByType;
20 21

  
22
import eu.etaxonomy.cdm.api.service.dto.CondensedDistribution;
21 23
import eu.etaxonomy.cdm.api.service.pager.Pager;
22 24
import eu.etaxonomy.cdm.ext.geo.CondensedDistributionRecipe;
23 25
import eu.etaxonomy.cdm.ext.geo.EditGeoService;
24 26
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
25 27
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
26 28
import eu.etaxonomy.cdm.model.common.Language;
27
import eu.etaxonomy.cdm.model.common.MarkerType;
28 29
import eu.etaxonomy.cdm.model.description.DescriptionBase;
29 30
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
30 31
import eu.etaxonomy.cdm.model.description.Distribution;
31 32
import eu.etaxonomy.cdm.model.description.Feature;
33
import eu.etaxonomy.cdm.model.description.TaxonDescription;
32 34
import eu.etaxonomy.cdm.model.description.TextData;
33 35
import eu.etaxonomy.cdm.model.name.BotanicalName;
34 36
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
......
55 57
@Component
56 58
public class CsvNameExport extends CsvNameExportBase {
57 59
    private static final Logger logger = Logger.getLogger(CsvNameExport.class);
60

  
61
    @SpringBeanByType
62
    EditGeoService geoService;
58 63

  
59 64
    public CsvNameExport() {
60 65
        super();
61
        this.ioName = this.getClass().getSimpleName();
66
        this.ioName = this.getClass().getSimpleName();
67

  
62 68
    }
63 69

  
64 70
    @Override
......
273 279
        }
274 280
    }
275 281

  
276
    private void extractDescriptions(HashMap<String, String> nameRecord, Taxon taxon, Feature feature, String columnName){
282
    private void extractDescriptions(HashMap<String, String> nameRecord, Taxon taxon, Feature feature, String columnName, CsvNameExportState state){
277 283
        StringBuffer descriptionsString = new StringBuffer();
278 284
        TextData textElement;
279 285
        List<Distribution> distributions = new ArrayList<Distribution>();
280
        for (DescriptionBase<?> descriptionBase: taxon.getDescriptions()){
286
        for (DescriptionBase<?> descriptionBase: taxon.getDescriptions()){
287

  
281 288
            Set<DescriptionElementBase> elements = descriptionBase.getElements();
282 289
            for (DescriptionElementBase element: elements){
283 290
                if (element.getFeature().equals(feature)){
......
285 292
                        textElement = HibernateProxyHelper.deproxy(element, TextData.class);
286 293
                        descriptionsString.append(textElement.getText(Language.ENGLISH()));
287 294

  
288
                    }else if (element instanceof Distribution){
295
                    }else if (element instanceof Distribution && ! state.getConfig().isCondensedDistribution()){
289 296

  
290 297
                        Distribution distribution = HibernateProxyHelper.deproxy(element, Distribution.class);
291 298
                        distributions.add(distribution);
......
300 307

  
301 308
        }
302 309
     //   Collections.sort(distributions, new DistributionNodeByAreaLabelComparator());
303
        EditGeoService.getCondensedDistribution(distributions, true,
304
                Set<MarkerType> hideMarkedAreas,
305
                MarkerType fallbackAreaMarkerType,
306
                CondensedDistributionRecipe recipe,
307
                List<Language> langs);
308
        for (Distribution distribution:distributions){
309 310

  
310
            if (descriptionsString.length()> 0 ){
311
                descriptionsString.append(", ");
312
            }
313
            descriptionsString.append(distribution.getArea().getIdInVocabulary());
311
        if (state.getConfig().isCondensedDistribution()){
312
            List<Language> langs = new ArrayList<Language>();
313
            langs.add(Language.ENGLISH());
314
            List<TaxonDescription> descriptions = new ArrayList(taxon.getDescriptions());
315

  
316
            CondensedDistribution conDis = geoService.getCondensedDistribution(descriptions, true, null,null,CondensedDistributionRecipe.FloraCuba, langs );
314 317

  
318
            nameRecord.put(columnName, conDis.toString());
319

  
320
        } else{
321
            for (Distribution distribution:distributions){
322

  
323
                if (descriptionsString.length()> 0 ){
324
                    descriptionsString.append(", ");
325
                }
326
                descriptionsString.append(distribution.getArea().getIdInVocabulary());
327

  
328
            }
329
            nameRecord.put(columnName, descriptionsString.toString());
315 330
        }
316
        nameRecord.put(columnName, descriptionsString.toString());
331

  
317 332
    }
318 333

  
319 334
    private Feature getNotesFeature(CsvNameExportState state){
......
354 369
        //  if (taxon.isPublish()){
355 370
        BotanicalName name = HibernateProxyHelper.deproxy(taxon.getName(), BotanicalName.class);
356 371
        nameRecord.put("familyName", name.getNameCache());
357
        extractDescriptions(nameRecord, taxon, Feature.INTRODUCTION(), "descriptionsFam");
372
        extractDescriptions(nameRecord, taxon, Feature.INTRODUCTION(), "descriptionsFam", state);
358 373

  
359 374
        TaxonNode genusNode = getHigherNode(childNode, Rank.GENUS());
360 375
        if (genusNode!= null){
......
373 388
            }else{
374 389
                nameRecord.put("genusName", name.getGenusOrUninomial());
375 390
            }
376
            extractDescriptions(nameRecord, taxon, Feature.INTRODUCTION(), "descriptionsGen");
391
            extractDescriptions(nameRecord, taxon, Feature.INTRODUCTION(), "descriptionsGen", state);
377 392
        }
378 393
        taxon = (Taxon) getTaxonService().load(childNode.getTaxon().getUuid());
379 394
        taxon = HibernateProxyHelper.deproxy(taxon, Taxon.class);
......
509 524
        nameRecord.put("relatedName", relatedName);
510 525
        nameRecord.put("nameRelType", nameRelType);
511 526

  
512
        extractDescriptions(nameRecord, taxon, Feature.DISTRIBUTION(), "description");
527
        extractDescriptions(nameRecord, taxon, Feature.DISTRIBUTION(), "description", state);
513 528
        return nameRecord;
514 529
    }
515 530

  

Also available in: Unified diff