ref#10446 normalize to IPNI standard
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / wfo / out / WfoBackboneExportState.java
1 /**
2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.io.wfo.out;
10
11 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
14 import java.util.Map;
15 import java.util.UUID;
16
17 import eu.etaxonomy.cdm.io.common.ExportResult;
18 import eu.etaxonomy.cdm.io.common.ExportResult.ExportResultState;
19 import eu.etaxonomy.cdm.io.out.TaxonTreeExportStateBase;
20 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
21 import eu.etaxonomy.cdm.model.name.TaxonName;
22 import eu.etaxonomy.cdm.model.reference.Reference;
23 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
24 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25 import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
26
27 /**
28 * State for WFO Backbone export.
29 *
30 * @see https://dev.e-taxonomy.eu/redmine/issues/10446
31 *
32 * @author a.mueller
33 * @since 2023-12-08
34 */
35 public class WfoBackboneExportState
36 extends TaxonTreeExportStateBase<WfoBackboneExportConfigurator,WfoBackboneExportState>{
37
38 private ExportResult result;
39
40 private WfoBackboneExportResultProcessor processor = new WfoBackboneExportResultProcessor(this);
41
42 private TaxonBase<?> currentTaxonBase;
43
44 private ArrayList<UUID> homotypicalGroupStore = new ArrayList<>();
45
46 //private Map<Integer, SpecimenOrObservationBase> specimenStore = new HashMap<>();
47 private List<UUID> referenceStore = new ArrayList<>();
48 private Map<Integer, UUID> nameStore = new HashMap<>();
49 private Map<UUID,List<TaxonNodeDto>> nodeChildrenMap = new HashMap<>();
50 private UUID classificationUUID = null;
51 private String familyStr = null;
52 private Map<UUID,String> taxonNodeToWfoMap = new HashMap<>();
53 private Map<UUID,String> taxonToWfoMap = new HashMap<>();
54 private Map<UUID,String> nameToWfoMap = new HashMap<>();
55
56 private UUID rootUuid;
57
58 //CONSTRUCTOR
59 protected WfoBackboneExportState(WfoBackboneExportConfigurator config) {
60 super(config);
61 result = ExportResult.NewInstance(config.getResultType());
62 familyStr = config.getFamilyStr();
63 }
64
65 //result
66 @Override
67 public ExportResult getResult() {
68 return result;
69 }
70 @Override
71 public void setResult(ExportResult result) {
72 this.result = result;
73 }
74
75 //empty data
76 protected void setEmptyData() {
77 this.result.setState(ExportResultState.SUCCESS_BUT_NO_DATA);
78 }
79
80 //processor
81 protected WfoBackboneExportResultProcessor getProcessor() {
82 return processor;
83 }
84
85 //current taxon
86 protected void setCurrentTaxonBase(TaxonBase<?> currentTaxonBase){
87 this.currentTaxonBase = currentTaxonBase;
88 }
89 protected TaxonBase<?> getCurrentTaxonBase() {
90 return currentTaxonBase;
91 }
92
93 //homotypical group store
94 protected ArrayList<UUID> getHomotypicalGroupStore() {
95 return homotypicalGroupStore;
96 }
97 protected void addHomotypicalGroupToStore(HomotypicalGroup homotypicalGroup) {
98 this.homotypicalGroupStore.add(homotypicalGroup.getUuid());
99 }
100 protected boolean containsHomotypicalGroupFromStore(UUID id){
101 return homotypicalGroupStore.contains(id);
102 }
103 protected void setHomotypicalGroupStore(ArrayList<UUID> homotypicalGroupStore) {
104 this.homotypicalGroupStore = homotypicalGroupStore;
105 }
106
107 //reference store
108 protected void addReferenceToStore(Reference ref) {
109 this.referenceStore.add(ref.getUuid());
110 }
111 protected void setReferenceStore(List<UUID> referenceStore) {
112 this.referenceStore = referenceStore;
113 }
114 protected List<UUID> getReferenceStore() {
115 return referenceStore;
116 }
117
118 //childrenMap
119 protected Map<UUID, List<TaxonNodeDto>> getNodeChildrenMap() {
120 return nodeChildrenMap;
121 }
122 protected void setNodeChildrenMap(Map<UUID,List<TaxonNodeDto>> nodeChildrenMap) {
123 this.nodeChildrenMap = nodeChildrenMap;
124 }
125
126 //classificationUuid
127 protected UUID getClassificationUUID(TaxonNode root) {
128 if (classificationUUID == null){
129 classificationUUID = root.getClassification().getUuid();
130 }
131 return classificationUUID;
132 }
133 protected void setClassificationUUID(UUID classificationUUID) {
134 this.classificationUUID = classificationUUID;
135 }
136
137 //rootID
138 protected UUID getRootId() {
139 return rootUuid;
140 }
141 protected void setRootId(UUID rootId) {
142 this.rootUuid = rootId;
143 }
144
145 //nameStore
146 protected Map<Integer, UUID> getNameStore() {
147 return nameStore;
148 }
149 protected void setNameStore(Map<Integer, UUID> nameStore) {
150 this.nameStore = nameStore;
151 }
152
153 //familyStr
154 public String getFamilyStr() {
155 return familyStr;
156 }
157 public void setFamilyStr(String familyStr) {
158 this.familyStr = familyStr;
159 }
160
161 //taxonToWfo map
162 public void putTaxonNodeWfoId(TaxonNode node, String wfoId) {
163 taxonNodeToWfoMap.put(node.getUuid(), wfoId);
164 }
165 public String getTaxonNodeWfoId(TaxonNode node) {
166 return taxonNodeToWfoMap.get(node.getUuid());
167 }
168
169 public void putTaxonWfoId(TaxonBase<?> taxon, String wfoId) {
170 taxonToWfoMap.put(taxon.getUuid(), wfoId);
171 }
172 public String getTaxonWfoId(TaxonBase<?> taxon) {
173 return taxonToWfoMap.get(taxon.getUuid());
174 }
175
176 public void putNameWfoId(TaxonName name, String wfoId) {
177 nameToWfoMap.put(name.getUuid(), wfoId);
178 }
179 public String getNameWfoId(TaxonName name) {
180 return nameToWfoMap.get(name.getUuid());
181 }
182 }