Project

General

Profile

Revision f318c828

IDf318c828821be9d6f4a5359c1f8e494140e3863e
Parent 5711e069
Child b3babf1b

Added by Katja Luther almost 4 years ago

ref #6314: handle homotypical group and further implementation for filling the name table

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/outputmodel/OutputModelClassificationExport.java
8 8
*/
9 9
package eu.etaxonomy.cdm.io.outputmodel;
10 10

  
11
import java.util.ArrayList;
12
import java.util.Collections;
11 13
import java.util.Iterator;
12 14
import java.util.List;
13 15
import java.util.Set;
14 16
import java.util.UUID;
15 17

  
18
import org.apache.commons.lang3.StringUtils;
19

  
16 20
import eu.etaxonomy.cdm.common.CdmUtils;
17 21
import eu.etaxonomy.cdm.io.common.CdmExportBase;
18 22
import eu.etaxonomy.cdm.io.common.ICdmExport;
......
28 32
import eu.etaxonomy.cdm.model.media.Media;
29 33
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
30 34
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
35
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
36
import eu.etaxonomy.cdm.model.name.HomotypicalGroupNameComparator;
37
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
38
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
31 39
import eu.etaxonomy.cdm.model.name.Rank;
32 40
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
33 41
import eu.etaxonomy.cdm.model.reference.Reference;
......
160 168
        String[] csvLine = new String[table.getSize()];
161 169

  
162 170
        csvLine[table.getIndex(OutputModelTable.NAME_ID)] = getId(state, name);
171
        csvLine[table.getIndex(OutputModelTable.LSID)] = name.getLsid().getLsid();
172

  
163 173
        csvLine[table.getIndex(OutputModelTable.RANK)] = getTitleCache(rank);
164 174
        csvLine[table.getIndex(OutputModelTable.RANK_SEQUENCE)] = String.valueOf(rank.getOrderIndex());
165 175
        csvLine[table.getIndex(OutputModelTable.FULL_NAME_WITH_AUTHORS)] = getTropicosTitleCache(name);
......
227 237
        }else{
228 238
            csvLine[table.getIndex(OutputModelTable.PROTOLOGUE_URI)] = "";
229 239
        }
240
        if (name.getStatus() != null || name.getStatus().isEmpty()){
241
            csvLine[table.getIndex(OutputModelTable.NOM_STATUS)] = "";
242
            csvLine[table.getIndex(OutputModelTable.NOM_STATUS_ABBREV)] = "";
243
        }else{
244

  
245
            String statusStringAbbrev = extractStatusString(name, true);
246
            String statusString = extractStatusString(name, false);
247

  
248
            csvLine[table.getIndex(OutputModelTable.NOM_STATUS)] = statusString.trim();
249
            csvLine[table.getIndex(OutputModelTable.NOM_STATUS_ABBREV)] = statusStringAbbrev.trim();
250
        }
251

  
252
        HomotypicalGroup group =name.getHomotypicalGroup();
253

  
254
        if (state.getHomotypicalGroupFromStore(group.getId()) == null){
255
            handleHomotypicalGroup(state, group);
256
        }
257
        csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_FK)] = String.valueOf(group.getId());
258
        //csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_FK)] = String.valueOf(group.getTypifiedNames());
259
        state.getProcessor().put(table, name, csvLine);
260

  
230 261

  
231 262
        state.getProcessor().put(table, name, csvLine);
232 263
/*
......
245 276
DatePublished
246 277
YearPublished
247 278
TitlePageYear
248
ProtologueURI
249
NomenclaturalStatus
250
NomenclaturalStatusAbbreviation
251
HomotypicGroup_Fk
279

  
280

  
281

  
252 282
HomotypicGroupSequenceNumber
253
TypeString
283

  
254 284

  
255 285
 *
256 286
 */
......
258 288

  
259 289
    /**
260 290
     * @param name
291
     * @param statusString
292
     * @return
293
     */
294
    private String extractStatusString(TaxonNameBase name, boolean abbrev) {
295
        Set<NomenclaturalStatus> status = name.getStatus();
296
        String statusString = "";
297
        for (NomenclaturalStatus nameStatus: status){
298
            if (abbrev){
299
                statusString += nameStatus.getType().getIdInVocabulary();
300
            }else{
301
                statusString += nameStatus.getType().getTitleCache();
302
            }
303
            if (!abbrev){
304
                if (!StringUtils.isBlank(nameStatus.getRuleConsidered())){
305
                    statusString += " " + nameStatus.getRuleConsidered();
306
                }
307
                if (nameStatus.getCitation() != null){
308
                    statusString += " " + nameStatus.getCitation().getTitleCache();
309
                }
310
                if (!StringUtils.isBlank(nameStatus.getCitationMicroReference())){
311
                    statusString += " " + nameStatus.getCitationMicroReference();
312
                }
313
            }
314
            statusString += " ";
315
        }
316
        return statusString;
317
    }
318

  
319
    /**
320
     * @param group
321
     */
322
    private void handleHomotypicalGroup(OutputModelExportState state, HomotypicalGroup group) {
323
        state.addHomotypicalGroupToStore(group);
324
        OutputModelTable table = OutputModelTable.HOMOTYPIC_GROUP;
325
        String[] csvLine = new String[table.getSize()];
326

  
327
        csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_ID)] = String.valueOf(group.getId());
328
        List<TaxonNameBase> typifiedNames = new ArrayList<>();
329
        typifiedNames.addAll(group.getTypifiedNames());
330
        Collections.sort(typifiedNames, new HomotypicalGroupNameComparator(null, true));
331
        String typifiedNamesString = "";
332
        for (TaxonNameBase name: typifiedNames){
333
            //Concatenated output string for homotypic group (names and citations) + status + some name relations (e.g. “non”)
334
//TODO: nameRelations, which and how to display
335
            typifiedNamesString = name.getTitleCache() + " " + extractStatusString(name, true) + " ";
336
        }
337
        csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_SEQ)] = typifiedNamesString.trim();
338

  
339
        Set<NameTypeDesignation> typeDesigantions = group.getNameTypeDesignations();
340
        for (NameTypeDesignation typeDesignation: typeDesigantions){
341
            //TODO...
342
        }
343

  
344
    }
345

  
346
    /**
347
     * @param name
261 348
     * @return
262 349
     */
263 350
    private String getTropicosTitleCache(TaxonNameBase name) {
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/outputmodel/OutputModelExportState.java
8 8
*/
9 9
package eu.etaxonomy.cdm.io.outputmodel;
10 10

  
11
import java.util.HashMap;
12
import java.util.Map;
13

  
11 14
import eu.etaxonomy.cdm.io.common.ExportResult;
12 15
import eu.etaxonomy.cdm.io.common.ExportResult.ExportResultState;
13 16
import eu.etaxonomy.cdm.io.common.ExportStateBase;
14 17
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
18
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
15 19
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
16 20

  
17 21
/**
......
27 31

  
28 32
    private TaxonBase actualTaxonBase;
29 33

  
34
    private Map<Integer, HomotypicalGroup> homotypicalGroupStore = new HashMap<Integer, HomotypicalGroup>();
35

  
36

  
30 37
    /**
31 38
     * @param config
32 39
     */
33 40
    protected OutputModelExportState(OutputModelConfigurator config) {
34 41
        super(config);
35 42
        result = ExportResult.NewInstance(config.getResultType());
36

  
37 43
    }
38 44

  
39 45
    /**
......
66 72

  
67 73
    public TaxonBase getActualTaxonBase() {return actualTaxonBase;}
68 74

  
75
    /**
76
     * @return the homotypicalGroupStore
77
     */
78
    public Map<Integer, HomotypicalGroup> getHomotypicalGroupStore() {
79
        return homotypicalGroupStore;
80
    }
81

  
82
    /**
83
     * @param homotypicalGroupStore the homotypicalGroupStore to set
84
     */
85
    public void addHomotypicalGroupToStore(HomotypicalGroup homotypicalGroup) {
86
        this.homotypicalGroupStore.put(homotypicalGroup.getId(), homotypicalGroup);
87
    }
88

  
89
    public HomotypicalGroup getHomotypicalGroupFromStore(Integer id){
90
        return homotypicalGroupStore.get(id);
91
    }
92

  
69 93

  
70 94

  
71 95
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/outputmodel/OutputModelTable.java
52 52
    protected static final String NAME_ID = "Name_ID";
53 53
    protected static final String TROPICOS_ID = "Tropicos_ID";
54 54
    protected static final String IPNI_ID = "IPNI_ID";
55
    protected static final String LSID = "LSID";
55 56
    protected static final String RANK = "Rank";
56 57
    protected static final String RANK_SEQUENCE = "Name_ID";
57 58
    protected static final String FULL_NAME_WITH_AUTHORS = "FullNameWithAuthors";

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)