Revision e1fe2afa
Added by Andreas Müller almost 2 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonNode.java | ||
---|---|---|
51 | 51 |
import org.hibernate.search.annotations.Store; |
52 | 52 |
|
53 | 53 |
import eu.etaxonomy.cdm.common.CdmUtils; |
54 |
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util; |
|
55 | 54 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
56 | 55 |
import eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter; |
57 | 56 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
... | ... | |
81 | 80 |
"taxon", |
82 | 81 |
"parent", |
83 | 82 |
"treeIndex", |
84 |
"sortIndex", |
|
85 | 83 |
"childNodes", |
86 | 84 |
"countChildren", |
87 | 85 |
"agentRelations", |
... | ... | |
139 | 137 |
@XmlIDREF |
140 | 138 |
@XmlSchemaType(name = "IDREF") |
141 | 139 |
//see https://dev.e-taxonomy.eu/redmine/issues/3722 |
140 |
//see https://dev.e-taxonomy.eu/redmine/issues/4200 |
|
141 |
//see https://dev.e-taxonomy.eu/redmine/issues/8127 |
|
142 |
//see https://dev.e-taxonomy.eu/redmine/issues/10067 |
|
142 | 143 |
@OrderColumn(name="sortIndex", nullable=true) |
143 |
// @OrderBy("sortIndex") |
|
144 | 144 |
@OneToMany(mappedBy="parent", fetch=FetchType.LAZY) |
145 | 145 |
//do not cascade |
146 | 146 |
private List<TaxonNode> childNodes = new ArrayList<>(); |
147 | 147 |
|
148 |
//see https://dev.e-taxonomy.eu/redmine/issues/3722 |
|
149 |
//see https://dev.e-taxonomy.eu/redmine/issues/4200 |
|
150 |
@Transient |
|
151 |
private Integer sortIndex = -1; |
|
152 |
|
|
153 | 148 |
@XmlElement(name = "countChildren") |
154 | 149 |
private int countChildren; |
155 | 150 |
|
... | ... | |
221 | 216 |
|
222 | 217 |
// ************************* GETTER / SETTER *******************************/ |
223 | 218 |
|
224 |
@Transient |
|
225 |
public Integer getSortIndex() { |
|
226 |
//return sortIndex; |
|
227 |
return getParent() == null ? null : getParent().getChildNodes().indexOf(CdmBase.deproxy(this)); |
|
228 |
} |
|
229 |
/** |
|
230 |
* SortIndex shall be handled only internally, therefore not public. |
|
231 |
* However, as javaassist only supports protected methods it needs to be protected, not private. |
|
232 |
* Alternatively we could use deproxy on every call of this method (see commented code) |
|
233 |
* @param i |
|
234 |
* @return |
|
235 |
* @deprecated for internal use only |
|
236 |
*/ |
|
237 |
@Deprecated |
|
238 |
protected void setSortIndex(Integer i) { |
|
239 |
// CdmBase.deproxy(this, TaxonNode.class).sortIndex = i; //alternative solution for private, DON'T remove |
|
240 |
// sortIndex = i; old #3722 |
|
241 |
//do nothing |
|
242 |
} |
|
243 |
|
|
244 | 219 |
public Taxon getTaxon() { |
245 | 220 |
return taxon; |
246 | 221 |
} |
... | ... | |
315 | 290 |
|
316 | 291 |
//************************************************************/ |
317 | 292 |
|
293 |
/** |
|
294 |
* The computed order index of this node being a child in the parents |
|
295 |
* childnode list. |
|
296 |
*/ |
|
297 |
@Transient |
|
298 |
public Integer getSortIndex() { |
|
299 |
return getParent() == null ? null : getParent().getChildNodes().indexOf(CdmBase.deproxy(this)); |
|
300 |
} |
|
301 |
|
|
318 | 302 |
//countChildren |
319 | 303 |
public int getCountChildren() { |
320 | 304 |
return countChildren; |
... | ... | |
692 | 676 |
this.countChildren = childNodes.size(); |
693 | 677 |
child.setParent(null); |
694 | 678 |
child.setTreeIndex(null); |
695 |
child.setSortIndex(null); |
|
696 | 679 |
} |
697 | 680 |
} |
698 | 681 |
|
... | ... | |
795 | 778 |
parent.setCountChildren(parent.getChildNodes().size()); |
796 | 779 |
} |
797 | 780 |
|
798 |
/** |
|
799 |
* As long as the sort index is not correctly handled through hibernate this is a workaround method |
|
800 |
* to update the sort index manually |
|
801 |
* @param parentChildren |
|
802 |
* @param index |
|
803 |
*/ |
|
804 |
private void updateSortIndex_old(int index) { |
|
805 |
if (this.hasChildNodes()){ |
|
806 |
List<TaxonNode> children = this.getChildNodes(); |
|
807 |
HHH_9751_Util.removeAllNull(children); |
|
808 |
for(int i = index; i < children.size(); i++){ |
|
809 |
TaxonNode child = children.get(i); |
|
810 |
if (child != null){ |
|
811 |
// child = CdmBase.deproxy(child, TaxonNode.class); //deproxy not needed as long as setSortIndex is protected or public #4200 |
|
812 |
child.setSortIndex(i); |
|
813 |
}else{ |
|
814 |
String message = "A node in a taxon tree must never be null but is (ParentId: %d; sort index: %d; index: %d; i: %d)"; |
|
815 |
throw new IllegalStateException(String.format(message, getId(), sortIndex, index, i)); |
|
816 |
} |
|
817 |
} |
|
818 |
} |
|
819 |
} |
|
820 |
|
|
821 | 781 |
/** |
822 | 782 |
* Returns a set containing this node and all nodes that are descendants of this node. |
823 | 783 |
*/ |
... | ... | |
1034 | 994 |
return getTaxon() == null? null: getTaxon().getName(); |
1035 | 995 |
} |
1036 | 996 |
|
1037 |
// public void removeNullValueFromChildren(){ |
|
1038 |
// try { |
|
1039 |
// //HHH_9751_Util.removeAllNull(childNodes); |
|
1040 |
// this.updateSortIndex(0); |
|
1041 |
// } catch (LazyInitializationException e) { |
|
1042 |
// logger.info("Cannot clean up uninitialized children without a session, skipping."); |
|
1043 |
// } |
|
1044 |
// } |
|
1045 |
|
|
1046 | 997 |
private boolean hasStatus(TaxonNodeStatus status) { |
1047 | 998 |
return CdmUtils.nullSafeEqual(this.status, status); |
1048 | 999 |
} |
Also available in: Unified diff
ref #10067, ref #3722, ref #8127 fully remove TaxonNode sortindex code from TaxonNode and CdmLight