Revision 4d68581f
Added by Katja Luther almost 4 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/TermNode.java | ||
---|---|---|
179 | 179 |
*/ |
180 | 180 |
@Override |
181 | 181 |
public List<TermNode<T>> getChildNodes() { |
182 |
removeNullValueFromChildren(); |
|
183 | 182 |
return children; |
184 | 183 |
} |
185 | 184 |
|
... | ... | |
575 | 574 |
return terms; |
576 | 575 |
} |
577 | 576 |
|
577 |
|
|
578 |
public String getPath(){ |
|
579 |
String result = ""; |
|
580 |
if (parent != null && parent.getTerm() != null){ |
|
581 |
result = parent.getPath() + "/" + parent.getTerm().getLabel(); |
|
582 |
} |
|
583 |
if (getTerm()!= null){ |
|
584 |
result += getTerm().getLabel(); |
|
585 |
} |
|
586 |
return result; |
|
587 |
} |
|
578 | 588 |
/** |
579 | 589 |
* Returns all terms that are contained in this node or a child node |
580 | 590 |
* as long as this node or the child nodes are not {@link #isDependent() dependent} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/term/TermTreeDaoImpl.java | ||
---|---|---|
145 | 145 |
return list; |
146 | 146 |
} |
147 | 147 |
|
148 |
@Override |
|
149 |
public TermTreeDto getTermTreeDtosByUuid(UUID uuid) { |
|
150 |
String queryString = TermTreeDto.getTermTreeDtoSelect() |
|
151 |
+ " WHERE a.uuid = :uuid" |
|
152 |
+ " ORDER BY a.titleCache"; |
|
153 |
Query query = getSession().createQuery(queryString); |
|
154 |
query.setParameter("uuid", uuid); |
|
155 |
|
|
156 |
@SuppressWarnings("unchecked") |
|
157 |
List<Object[]> result = query.list(); |
|
158 |
|
|
159 |
List<TermTreeDto> list = TermTreeDto.termTreeDtoListFrom(result); |
|
160 |
return !list.isEmpty()? list.get(0): null; |
|
161 |
} |
|
162 |
|
|
148 | 163 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/term/ITermTreeDao.java | ||
---|---|---|
41 | 41 |
|
42 | 42 |
public <S extends TermTree> List<TermTreeDto> listTermTreeDtosByTermType(TermType termType); |
43 | 43 |
|
44 |
/** |
|
45 |
* @param uuid |
|
46 |
* @return |
|
47 |
*/ |
|
48 |
TermTreeDto getTermTreeDtosByUuid(UUID uuid); |
|
49 |
|
|
44 | 50 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/AbstractTermDto.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import java.io.Serializable; |
13 | 13 |
import java.net.URI; |
14 |
import java.util.HashSet; |
|
15 |
import java.util.Iterator; |
|
14 | 16 |
import java.util.Set; |
15 | 17 |
import java.util.UUID; |
16 | 18 |
|
19 |
import eu.etaxonomy.cdm.model.common.Language; |
|
17 | 20 |
import eu.etaxonomy.cdm.model.term.Representation; |
18 | 21 |
import eu.etaxonomy.cdm.model.term.TermType; |
19 | 22 |
|
... | ... | |
29 | 32 |
private UUID uuid; |
30 | 33 |
private URI uri; |
31 | 34 |
private TermType termType; |
32 |
private final Set<Representation> representations;
|
|
35 |
private Set<Representation> representations = new HashSet<>();
|
|
33 | 36 |
private String representation_L10n = null; |
34 | 37 |
private String representation_L10n_abbreviatedLabel = null; |
35 | 38 |
private String representation_L10n_text = null; |
... | ... | |
38 | 41 |
public AbstractTermDto(UUID uuid, Set<Representation> representations, String titleCache) { |
39 | 42 |
this.uuid = uuid; |
40 | 43 |
this.titleCache = titleCache; |
41 |
this.representations = representations; |
|
44 |
|
|
45 |
for(Representation rep: representations){ |
|
46 |
this.representations.add(rep.clone()); |
|
47 |
} |
|
48 |
|
|
42 | 49 |
|
43 | 50 |
} |
44 | 51 |
|
... | ... | |
115 | 122 |
public Set<Representation> getRepresentations() { |
116 | 123 |
return representations; |
117 | 124 |
} |
125 |
public Representation getPreferredRepresentation(Language lang){ |
|
126 |
|
|
127 |
Language language = lang; |
|
128 |
if(lang != null){ |
|
129 |
language = Language.DEFAULT(); |
|
130 |
} |
|
131 |
for (Representation rep: representations){ |
|
132 |
if(rep != null && rep.getLanguage().equals(language)){ |
|
133 |
return rep; |
|
134 |
} |
|
135 |
} |
|
136 |
language = Language.DEFAULT(); |
|
137 |
for (Representation rep: representations){ |
|
138 |
if(rep != null && rep.getLanguage().equals(language)){ |
|
139 |
return rep; |
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
Iterator<Representation> it = getRepresentations().iterator(); |
|
144 |
if(it.hasNext()){ |
|
145 |
return getRepresentations().iterator().next(); |
|
146 |
} |
|
147 |
|
|
148 |
return null; |
|
149 |
} |
|
150 |
|
|
151 |
public Representation getRepresentation(Language lang) { |
|
152 |
for (Representation repr : representations){ |
|
153 |
Language reprLanguage = repr.getLanguage(); |
|
154 |
if (reprLanguage != null && reprLanguage.equals(lang)){ |
|
155 |
return repr; |
|
156 |
} |
|
157 |
} |
|
158 |
return null; |
|
159 |
} |
|
118 | 160 |
|
119 | 161 |
|
120 | 162 |
public String getTitleCache() { |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/CharacterDto.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.persistence.dto; |
10 | 10 |
|
11 |
import java.util.HashSet; |
|
11 | 12 |
import java.util.Set; |
12 | 13 |
import java.util.UUID; |
13 | 14 |
|
14 | 15 |
import eu.etaxonomy.cdm.model.description.Character; |
16 |
import eu.etaxonomy.cdm.model.description.MeasurementUnit; |
|
17 |
import eu.etaxonomy.cdm.model.description.State; |
|
18 |
import eu.etaxonomy.cdm.model.description.StatisticalMeasure; |
|
19 |
import eu.etaxonomy.cdm.model.term.DefinedTerm; |
|
15 | 20 |
import eu.etaxonomy.cdm.model.term.Representation; |
21 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
16 | 22 |
/** |
17 | 23 |
* @author k.luther |
18 | 24 |
* @since Oct 6, 2020 |
... | ... | |
48 | 54 |
UUID vocabularyUuid, Integer orderIndex, String idInVocabulary, Set<Representation> vocRepresentations, |
49 | 55 |
boolean isAvailableForTaxon, boolean isAvailableForTaxonName, boolean isAvailableForOccurrence, |
50 | 56 |
String titleCache, TermNodeDto structure, TermDto structureModifier, TermNodeDto property, |
51 |
TermDto propertyModifier) { |
|
57 |
TermDto propertyModifier, boolean isSupportCategoricalData, boolean isSupportsQuantitativeData, Set<TermVocabularyDto> supportedCategoricalEnumerations, Set<TermVocabularyDto> recommendedModifierEnumeration, Set<TermDto> recommendedMeasurementUnits, Set<TermDto> recommendedStatisticalMeasures) {
|
|
52 | 58 |
super(uuid, representations, partOfUuid, kindOfUuid, vocabularyUuid, orderIndex, idInVocabulary, |
53 |
vocRepresentations, isAvailableForTaxon, isAvailableForTaxonName, isAvailableForOccurrence, titleCache); |
|
59 |
vocRepresentations, isAvailableForTaxon, isAvailableForTaxonName, isAvailableForOccurrence, titleCache, isSupportCategoricalData, isSupportsQuantitativeData, supportedCategoricalEnumerations, recommendedModifierEnumeration, recommendedMeasurementUnits, recommendedStatisticalMeasures);
|
|
54 | 60 |
this.structure = structure; |
55 | 61 |
this.structureModifier = structureModifier; |
56 | 62 |
this.property = property; |
... | ... | |
60 | 66 |
/** |
61 | 67 |
* @param character |
62 | 68 |
*/ |
63 |
public CharacterDto(Character character) { |
|
64 |
super(character.getUuid(), character.getRepresentations(), character.getPartOf().getUuid(), character.getKindOf().getUuid(), character.getVocabulary().getUuid(), null, character.getIdInVocabulary(), character.getVocabulary().getRepresentations(), |
|
65 |
character.isAvailableForTaxon(), character.isAvailableForTaxonName(), character.isAvailableForOccurrence(), character.getTitleCache()); |
|
66 |
this.property = new TermNodeDto(character.getProperty()); |
|
67 |
this.propertyModifier = TermDto.fromTerm(character.getPropertyModifier()); |
|
68 |
this.structure = new TermNodeDto(character.getStructure()); |
|
69 |
this.structureModifier = TermDto.fromTerm(character.getStructureModifier()); |
|
69 |
public static CharacterDto fromCharacter(Character character) { |
|
70 |
TermVocabulary voc = character.getVocabulary(); |
|
71 |
|
|
72 |
Set<TermVocabularyDto> recommendedModifierDtos = new HashSet<>(); |
|
73 |
for (TermVocabulary<DefinedTerm> modVoc: character.getRecommendedModifierEnumeration()){ |
|
74 |
recommendedModifierDtos.add(TermVocabularyDto.fromVocabulary(modVoc)); |
|
75 |
} |
|
76 |
|
|
77 |
|
|
78 |
Set<TermDto> recommendedStatisticalMeasuresDtos = new HashSet<>(); |
|
79 |
for (StatisticalMeasure term: character.getRecommendedStatisticalMeasures()){ |
|
80 |
recommendedStatisticalMeasuresDtos.add(TermDto.fromTerm(term)); |
|
81 |
} |
|
82 |
|
|
83 |
|
|
84 |
Set<TermVocabularyDto> supportedCategoricalDtos = new HashSet<>(); |
|
85 |
for (TermVocabulary<State> catVoc: character.getSupportedCategoricalEnumerations()){ |
|
86 |
supportedCategoricalDtos.add(TermVocabularyDto.fromVocabulary(catVoc)); |
|
87 |
} |
|
88 |
|
|
89 |
|
|
90 |
Set<TermDto> recommendedMeasurementUnitsDtos = new HashSet<>(); |
|
91 |
for (MeasurementUnit term: character.getRecommendedMeasurementUnits()){ |
|
92 |
recommendedMeasurementUnitsDtos.add(TermDto.fromTerm(term)); |
|
93 |
} |
|
94 |
CharacterDto dto = new CharacterDto(character.getUuid(), character.getRepresentations(), character.getPartOf() != null? character.getPartOf().getUuid(): null, character.getKindOf() != null? character.getKindOf().getUuid(): null, voc != null? voc.getUuid(): null, |
|
95 |
null, character.getIdInVocabulary(), voc != null? voc.getRepresentations(): null, character.isAvailableForTaxon(), character.isAvailableForTaxonName(), character.isAvailableForOccurrence(), character.getTitleCache(), |
|
96 |
character.getStructure() !=null? TermNodeDto.fromNode(character.getStructure()): null, character.getStructureModifier() != null? TermDto.fromTerm(character.getStructureModifier()): null, character.getProperty() != null? TermNodeDto.fromNode(character.getProperty()): null, |
|
97 |
character.getPropertyModifier() != null? TermDto.fromTerm(character.getPropertyModifier()): null, character.isSupportsCategoricalData(), character.isSupportsQuantitativeData(),supportedCategoricalDtos, recommendedModifierDtos, recommendedMeasurementUnitsDtos, recommendedStatisticalMeasuresDtos); |
|
98 |
|
|
99 |
return dto; |
|
70 | 100 |
} |
71 | 101 |
|
72 | 102 |
|
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/CharacterNodeDto.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.persistence.dto; |
10 | 10 |
|
11 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.List; |
|
13 |
import java.util.UUID; |
|
14 |
|
|
15 |
import org.springframework.util.Assert; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.model.description.Character; |
|
18 |
import eu.etaxonomy.cdm.model.term.TermNode; |
|
19 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
12 | 20 |
|
13 | 21 |
/** |
14 | 22 |
* @author k.luther |
15 | 23 |
* @since Oct 9, 2020 |
16 | 24 |
*/ |
17 |
public class CharacterNodeDto extends TermNodeDto<Feature> {
|
|
25 |
public class CharacterNodeDto extends TermNodeDto { |
|
18 | 26 |
|
19 | 27 |
private static final long serialVersionUID = 7635704848569122836L; |
20 | 28 |
|
... | ... | |
23 | 31 |
* @param parent |
24 | 32 |
* @param position |
25 | 33 |
*/ |
26 |
public CharacterNodeDto(CharacterDto characterDto, TermNodeDto parent, int position, TermTreeDto treeDto) { |
|
27 |
super(characterDto, parent, position, treeDto); |
|
34 |
public CharacterNodeDto(CharacterDto characterDto, TermNodeDto parent, int position, TermTreeDto treeDto, UUID uuid, String treeIndex, String path) { |
|
35 |
super(characterDto, parent, position, treeDto, uuid, treeIndex, path); |
|
36 |
} |
|
37 |
|
|
38 |
public static CharacterNodeDto fromTermNode(TermNode<Character> child) { |
|
39 |
Assert.notNull(child, "Node should not be null"); |
|
40 |
CharacterNodeDto dto = new CharacterNodeDto(child.getTerm() != null?CharacterDto.fromCharacter(child.getTerm()): null, null, child.getParent() != null?child.getParent().getIndex(child): 0, TermTreeDto.fromTree(child.getGraph()), child.getUuid(), child.treeIndex(), child.getPath()); |
|
41 |
|
|
42 |
if (child.getParent() != null){ |
|
43 |
dto.setParentUuid(child.getParent().getUuid()); |
|
44 |
} |
|
45 |
|
|
46 |
List<TermNodeDto> children = new ArrayList(); |
|
47 |
for (Object o: child.getChildNodes()){ |
|
48 |
if (o instanceof TermNode){ |
|
49 |
TermNode childNode = (TermNode)o; |
|
50 |
|
|
51 |
if (childNode != null){ |
|
52 |
if(childNode.getTermType().equals(TermType.Character)){ |
|
53 |
children.add(CharacterNodeDto.fromTermNode(childNode)); |
|
54 |
}else{ |
|
55 |
children.add(TermNodeDto.fromNode(childNode)); |
|
56 |
} |
|
57 |
} |
|
58 |
} |
|
59 |
} |
|
60 |
dto.setChildren(children); |
|
61 |
dto.setOnlyApplicableIf(child.getOnlyApplicableIf()); |
|
62 |
dto.setInapplicableIf(child.getInapplicableIf()); |
|
63 |
|
|
64 |
dto.setTermType(child.getTermType()); |
|
65 |
|
|
66 |
return dto; |
|
67 |
|
|
68 |
|
|
28 | 69 |
} |
29 | 70 |
|
30 | 71 |
|
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/FeatureDto.java | ||
---|---|---|
20 | 20 |
|
21 | 21 |
import eu.etaxonomy.cdm.model.common.CdmClass; |
22 | 22 |
import eu.etaxonomy.cdm.model.description.Feature; |
23 |
import eu.etaxonomy.cdm.model.description.MeasurementUnit; |
|
24 |
import eu.etaxonomy.cdm.model.description.State; |
|
25 |
import eu.etaxonomy.cdm.model.description.StatisticalMeasure; |
|
23 | 26 |
import eu.etaxonomy.cdm.model.media.Media; |
27 |
import eu.etaxonomy.cdm.model.term.DefinedTerm; |
|
24 | 28 |
import eu.etaxonomy.cdm.model.term.Representation; |
25 | 29 |
import eu.etaxonomy.cdm.model.term.TermType; |
30 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
26 | 31 |
|
27 | 32 |
/** |
28 | 33 |
* @author k.luther |
... | ... | |
35 | 40 |
boolean isAvailableForTaxon = true; |
36 | 41 |
boolean isAvailableForTaxonName = true; |
37 | 42 |
boolean isAvailableForOccurrence = true; |
43 |
boolean isSupportsCategoricalData = false; |
|
44 |
boolean isSupportsQuantitativeData = false; |
|
45 |
|
|
46 |
Set<TermDto> recommendedMeasurementUnits = new HashSet<>(); |
|
47 |
Set<TermDto> recommendedStatisticalMeasures = new HashSet<>(); |
|
48 |
Set<TermVocabularyDto> supportedCategoricalEnumerations = new HashSet<>(); |
|
49 |
Set<TermVocabularyDto> recommendedModifierEnumeration = new HashSet<>(); |
|
38 | 50 |
|
39 | 51 |
public FeatureDto(UUID uuid, Set<Representation> representations, UUID partOfUuid, UUID kindOfUuid, |
40 |
UUID vocabularyUuid, Integer orderIndex, String idInVocabulary, Set<Representation> vocRepresentations, boolean isAvailableForTaxon, boolean isAvailableForTaxonName, boolean isAvailableForOccurrence, String titleCache){ |
|
52 |
UUID vocabularyUuid, Integer orderIndex, String idInVocabulary, Set<Representation> vocRepresentations, boolean isAvailableForTaxon, |
|
53 |
boolean isAvailableForTaxonName, boolean isAvailableForOccurrence, String titleCache, boolean isSupportsCategoricalData, boolean isSupportsQuantitativeData, |
|
54 |
Set<TermVocabularyDto> supportedCategoricalEnumerations, Set<TermVocabularyDto> recommendedModifierEnumeration, Set<TermDto> recommendedMeasurementUnits, Set<TermDto> recommendedStatisticalMeasures){ |
|
41 | 55 |
super(uuid, representations, TermType.Feature, partOfUuid, kindOfUuid, |
42 | 56 |
vocabularyUuid, orderIndex, idInVocabulary, vocRepresentations, titleCache); |
43 | 57 |
this.isAvailableForOccurrence = isAvailableForOccurrence; |
44 | 58 |
this.isAvailableForTaxon = isAvailableForTaxon; |
45 | 59 |
this.isAvailableForTaxonName = isAvailableForTaxonName; |
46 | 60 |
|
61 |
this.isSupportsCategoricalData = isSupportsCategoricalData; |
|
62 |
this.isSupportsQuantitativeData = isSupportsQuantitativeData; |
|
63 |
|
|
64 |
this.recommendedMeasurementUnits = recommendedMeasurementUnits; |
|
65 |
this.recommendedStatisticalMeasures = recommendedStatisticalMeasures; |
|
66 |
this.supportedCategoricalEnumerations = supportedCategoricalEnumerations; |
|
67 |
this.recommendedModifierEnumeration = recommendedModifierEnumeration; |
|
68 |
|
|
47 | 69 |
} |
48 | 70 |
|
49 | 71 |
static public FeatureDto fromTerm(Feature term) { |
... | ... | |
51 | 73 |
result.isAvailableForOccurrence = term.isAvailableForOccurrence(); |
52 | 74 |
result.isAvailableForTaxon = term.isAvailableForTaxon(); |
53 | 75 |
result.isAvailableForTaxonName = term.isAvailableForTaxonName(); |
76 |
result.isSupportsCategoricalData = term.isSupportsCategoricalData(); |
|
77 |
result.isSupportsQuantitativeData = term.isSupportsQuantitativeData(); |
|
78 |
if (term.getRecommendedMeasurementUnits() != null && !term.getRecommendedMeasurementUnits().isEmpty()){ |
|
79 |
result.recommendedMeasurementUnits = new HashSet<>(); |
|
80 |
} |
|
81 |
for (MeasurementUnit unit: term.getRecommendedMeasurementUnits()){ |
|
82 |
result.recommendedMeasurementUnits.add(TermDto.fromTerm(unit)); |
|
83 |
} |
|
84 |
|
|
85 |
if (term.getRecommendedStatisticalMeasures() != null && !term.getRecommendedStatisticalMeasures().isEmpty()){ |
|
86 |
result.recommendedStatisticalMeasures = new HashSet<>(); |
|
87 |
} |
|
88 |
for (StatisticalMeasure unit: term.getRecommendedStatisticalMeasures()){ |
|
89 |
result.recommendedStatisticalMeasures.add(TermDto.fromTerm(unit)); |
|
90 |
} |
|
91 |
|
|
92 |
if (term.getSupportedCategoricalEnumerations() != null && !term.getSupportedCategoricalEnumerations().isEmpty()){ |
|
93 |
result.supportedCategoricalEnumerations = new HashSet<>(); |
|
94 |
} |
|
95 |
for (TermVocabulary<State> voc: term.getSupportedCategoricalEnumerations()){ |
|
96 |
result.supportedCategoricalEnumerations.add(new TermVocabularyDto(voc.getUuid(), voc.getRepresentations(), voc.getTermType(), voc.getTitleCache(), voc.isAllowDuplicates(), voc.isOrderRelevant(), voc.isFlat())); |
|
97 |
} |
|
98 |
|
|
99 |
if (term.getRecommendedModifierEnumeration() != null && !term.getRecommendedModifierEnumeration().isEmpty()){ |
|
100 |
result.recommendedModifierEnumeration = new HashSet<>(); |
|
101 |
} |
|
102 |
for (TermVocabulary<DefinedTerm> voc: term.getRecommendedModifierEnumeration()){ |
|
103 |
result.recommendedModifierEnumeration.add(new TermVocabularyDto(voc.getUuid(), voc.getRepresentations(), voc.getTermType(), voc.getTitleCache(), voc.isAllowDuplicates(), voc.isOrderRelevant(), voc.isFlat())); |
|
104 |
} |
|
54 | 105 |
return result; |
55 | 106 |
} |
56 | 107 |
|
... | ... | |
96 | 147 |
this.isAvailableForOccurrence = isAvailableForOccurrence; |
97 | 148 |
} |
98 | 149 |
|
150 |
/** |
|
151 |
* @return the isSupportsCategoricalData |
|
152 |
*/ |
|
153 |
public boolean isSupportsCategoricalData() { |
|
154 |
return isSupportsCategoricalData; |
|
155 |
} |
|
156 |
|
|
157 |
/** |
|
158 |
* @param isSupportsCategoricalData the isSupportsCategoricalData to set |
|
159 |
*/ |
|
160 |
public void setSupportsCategoricalData(boolean isSupportsCategoricalData) { |
|
161 |
this.isSupportsCategoricalData = isSupportsCategoricalData; |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* @return the isSupportsQuantitativeData |
|
166 |
*/ |
|
167 |
public boolean isSupportsQuantitativeData() { |
|
168 |
return isSupportsQuantitativeData; |
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* @param isSupportsQuantitativeData the isSupportsQuantitativeData to set |
|
173 |
*/ |
|
174 |
public void setSupportsQuantitativeData(boolean isSupportsQuantitativeData) { |
|
175 |
this.isSupportsQuantitativeData = isSupportsQuantitativeData; |
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* @return the recommendedMeasurementUnits |
|
180 |
*/ |
|
181 |
public Set<TermDto> getRecommendedMeasurementUnits() { |
|
182 |
return recommendedMeasurementUnits; |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* @param recommendedMeasurementUnits the recommendedMeasurementUnits to set |
|
187 |
*/ |
|
188 |
public void setRecommendedMeasurementUnits(Set<TermDto> recommendedMeasurementUnits) { |
|
189 |
this.recommendedMeasurementUnits = recommendedMeasurementUnits; |
|
190 |
} |
|
191 |
|
|
192 |
/** |
|
193 |
* @return the recommendedStatisticalMeasures |
|
194 |
*/ |
|
195 |
public Set<TermDto> getRecommendedStatisticalMeasures() { |
|
196 |
return recommendedStatisticalMeasures; |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* @param recommendedStatisticalMeasures the recommendedStatisticalMeasures to set |
|
201 |
*/ |
|
202 |
public void setRecommendedStatisticalMeasures(Set<TermDto> recommendedStatisticalMeasures) { |
|
203 |
this.recommendedStatisticalMeasures = recommendedStatisticalMeasures; |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
207 |
* @return the supportedCategoricalEnumerations |
|
208 |
*/ |
|
209 |
public Set<TermVocabularyDto> getSupportedCategoricalEnumerations() { |
|
210 |
return supportedCategoricalEnumerations; |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* @param supportedCategoricalEnumerations the supportedCategoricalEnumerations to set |
|
215 |
*/ |
|
216 |
public void setSupportedCategoricalEnumerations(Set<TermVocabularyDto> supportedCategoricalEnumerations) { |
|
217 |
this.supportedCategoricalEnumerations = supportedCategoricalEnumerations; |
|
218 |
} |
|
219 |
|
|
220 |
/** |
|
221 |
* @return the recommendedModifierEnumeration |
|
222 |
*/ |
|
223 |
public Set<TermVocabularyDto> getRecommendedModifierEnumeration() { |
|
224 |
return recommendedModifierEnumeration; |
|
225 |
} |
|
226 |
|
|
227 |
/** |
|
228 |
* @param recommendedModifierEnumeration the recommendedModifierEnumeration to set |
|
229 |
*/ |
|
230 |
public void setRecommendedModifierEnumeration(Set<TermVocabularyDto> recommendedModifierEnumeration) { |
|
231 |
this.recommendedModifierEnumeration = recommendedModifierEnumeration; |
|
232 |
} |
|
233 |
|
|
99 | 234 |
public static String getTermDtoSelect(){ |
100 | 235 |
String[] result = createSqlParts("DefinedTermBase"); |
101 | 236 |
|
... | ... | |
116 | 251 |
+ "a.uri, " |
117 | 252 |
+ "m, " |
118 | 253 |
+ "a.availableFor, " |
119 |
+ "a.titleCache "; |
|
254 |
+ "a.titleCache, " |
|
255 |
+ "a.supportedDataTypes, " |
|
256 |
+ "recommendedModifierEnumeration, " |
|
257 |
+ "recommendedStatisticalMeasures, " |
|
258 |
+ "supportedCategoricalEnumerations, " |
|
259 |
+ "recommendedMeasurementUnits "; |
|
120 | 260 |
|
121 | 261 |
String sqlFromString = " from "+fromTable+" as a "; |
122 | 262 |
|
... | ... | |
126 | 266 |
+ "LEFT JOIN a.representations AS r " |
127 | 267 |
+ "LEFT JOIN a.vocabulary as v " |
128 | 268 |
+ "LEFT JOIN v.representations as voc_rep " |
269 |
+ "LEFT JOIN a.recommendedModifierEnumeration as recommendedModifierEnumeration " |
|
270 |
+ "LEFT JOIN a.recommendedStatisticalMeasures as recommendedStatisticalMeasures " |
|
271 |
+ "LEFT JOIN a.supportedCategoricalEnumerations as supportedCategoricalEnumerations " |
|
272 |
+ "LEFT JOIN a.recommendedMeasurementUnits as recommendedMeasurementUnits " |
|
129 | 273 |
; |
130 | 274 |
|
131 | 275 |
String[] result = new String[3]; |
... | ... | |
177 | 321 |
|
178 | 322 |
EnumSet<CdmClass> availableForString = (EnumSet<CdmClass>)elements[11]; |
179 | 323 |
|
180 |
if (availableForString.contains(CdmClass.TAXON)){ |
|
181 |
isAvailableForTaxon = true; |
|
324 |
if (availableForString.contains(CdmClass.TAXON)){ |
|
325 |
isAvailableForTaxon = true; |
|
326 |
} |
|
327 |
if (availableForString.contains(CdmClass.TAXON_NAME)){ |
|
328 |
isAvailableForTaxonName = true; |
|
329 |
} |
|
330 |
if (availableForString.contains(CdmClass.OCCURRENCE)){ |
|
331 |
isAvailableForOccurrence = true; |
|
332 |
} |
|
333 |
boolean isSupportsCategoricalData = false; |
|
334 |
boolean isSupportsQuantitativeData = false; |
|
335 |
|
|
336 |
EnumSet<CdmClass> supportsString = (EnumSet<CdmClass>)elements[13]; |
|
337 |
|
|
338 |
if (supportsString.contains(CdmClass.CATEGORICAL_DATA)){ |
|
339 |
isSupportsCategoricalData = true; |
|
340 |
} |
|
341 |
if (supportsString.contains(CdmClass.QUANTITATIVE_DATA)){ |
|
342 |
isSupportsQuantitativeData = true; |
|
343 |
} |
|
344 |
|
|
345 |
Object o = elements[14]; |
|
346 |
Set<TermVocabularyDto> recommendedModifierDtos = new HashSet<>(); |
|
347 |
if (o instanceof TermVocabulary){ |
|
348 |
recommendedModifierDtos.add(TermVocabularyDto.fromVocabulary((TermVocabulary)o)); |
|
349 |
}else if (o instanceof Set){ |
|
350 |
Set<TermVocabulary<DefinedTerm>> recommendedModifierEnumeration = (Set<TermVocabulary<DefinedTerm>>) o; |
|
351 |
if (recommendedModifierEnumeration != null){ |
|
352 |
for (TermVocabulary<DefinedTerm> voc: recommendedModifierEnumeration){ |
|
353 |
recommendedModifierDtos.add(TermVocabularyDto.fromVocabulary(voc)); |
|
354 |
} |
|
182 | 355 |
} |
183 |
if (availableForString.contains(CdmClass.TAXON_NAME)){ |
|
184 |
isAvailableForTaxonName = true; |
|
356 |
} |
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
o = elements[15]; |
|
361 |
Set<TermDto> recommendedStatisticalMeasuresDtos = new HashSet<>(); |
|
362 |
if (o instanceof StatisticalMeasure){ |
|
363 |
recommendedStatisticalMeasuresDtos.add(TermDto.fromTerm((StatisticalMeasure)o)); |
|
364 |
}else if (o instanceof Set){ |
|
365 |
Set<StatisticalMeasure> recommendedStatisticalMeasures = (Set<StatisticalMeasure>) o; |
|
366 |
if (recommendedStatisticalMeasures != null) { |
|
367 |
for (StatisticalMeasure term: recommendedStatisticalMeasures){ |
|
368 |
recommendedStatisticalMeasuresDtos.add(TermDto.fromTerm(term)); |
|
369 |
} |
|
370 |
} |
|
371 |
} |
|
372 |
o = elements[16]; |
|
373 |
Set<TermVocabularyDto> supportedCategoricalDtos = new HashSet<>(); |
|
374 |
if (o instanceof TermVocabulary){ |
|
375 |
supportedCategoricalDtos.add(TermVocabularyDto.fromVocabulary((TermVocabulary)o)); |
|
376 |
}else if (o instanceof Set){ |
|
377 |
Set<TermVocabulary> supportedCategoricalEnumerations = (Set<TermVocabulary>)o; |
|
378 |
for (TermVocabulary<State> voc: supportedCategoricalEnumerations){ |
|
379 |
supportedCategoricalDtos.add(TermVocabularyDto.fromVocabulary(voc)); |
|
185 | 380 |
} |
186 |
if (availableForString.contains(CdmClass.OCCURRENCE)){ |
|
187 |
isAvailableForOccurrence = true; |
|
381 |
} |
|
382 |
|
|
383 |
// if (supportedCategoricalEnumerations != null){ |
|
384 |
// for (TermVocabulary<State> voc: supportedCategoricalEnumerations){ |
|
385 |
// supportedCategoricalDtos.add(TermVocabularyDto.fromVocabulary(voc)); |
|
386 |
// } |
|
387 |
// } |
|
388 |
o = elements[17]; |
|
389 |
Set<TermDto> recommendedMeasurementUnitsDtos = new HashSet<>(); |
|
390 |
if (o instanceof MeasurementUnit){ |
|
391 |
recommendedMeasurementUnitsDtos.add(TermDto.fromTerm((MeasurementUnit)o)); |
|
392 |
}else if (o instanceof Set){ |
|
393 |
Set<MeasurementUnit> recommendedMeasurementUnits = (Set<MeasurementUnit>) elements[17]; |
|
394 |
for (MeasurementUnit term: recommendedMeasurementUnits){ |
|
395 |
recommendedMeasurementUnitsDtos.add(TermDto.fromTerm(term)); |
|
188 | 396 |
} |
397 |
} |
|
398 |
|
|
399 |
// if (recommendedMeasurementUnits != null){ |
|
400 |
// for (MeasurementUnit term: recommendedMeasurementUnits){ |
|
401 |
// recommendedMeasurementUnitsDtos.add(TermDto.fromTerm(term)); |
|
402 |
// } |
|
403 |
// } |
|
189 | 404 |
|
190 | 405 |
TermDto termDto = new FeatureDto( |
191 | 406 |
uuid, |
... | ... | |
199 | 414 |
isAvailableForTaxon, |
200 | 415 |
isAvailableForTaxonName, |
201 | 416 |
isAvailableForOccurrence, |
202 |
(String)elements[12]) |
|
417 |
(String)elements[12], |
|
418 |
isSupportsCategoricalData, |
|
419 |
isSupportsQuantitativeData, |
|
420 |
supportedCategoricalDtos, |
|
421 |
recommendedModifierDtos, |
|
422 |
recommendedMeasurementUnitsDtos, |
|
423 |
recommendedStatisticalMeasuresDtos) |
|
203 | 424 |
; |
204 | 425 |
termDto.setUri((URI)elements[9]); |
205 | 426 |
termDto.setMedia(mediaUuids); |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TermNodeDto.java | ||
---|---|---|
15 | 15 |
import java.util.Set; |
16 | 16 |
import java.util.UUID; |
17 | 17 |
|
18 |
import org.springframework.util.Assert; |
|
19 |
|
|
18 | 20 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
19 | 21 |
import eu.etaxonomy.cdm.model.description.FeatureState; |
20 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
|
21 | 22 |
import eu.etaxonomy.cdm.model.term.TermNode; |
22 | 23 |
import eu.etaxonomy.cdm.model.term.TermTree; |
23 | 24 |
import eu.etaxonomy.cdm.model.term.TermType; |
... | ... | |
26 | 27 |
* @author k.luther |
27 | 28 |
* @since Mar 18, 2020 |
28 | 29 |
*/ |
29 |
public class TermNodeDto<T extends DefinedTermBase> implements Serializable{
|
|
30 |
public class TermNodeDto implements Serializable{ |
|
30 | 31 |
|
31 | 32 |
private static final long serialVersionUID = 7568459208397248126L; |
32 | 33 |
|
33 | 34 |
UUID parentUuid; |
34 | 35 |
String treeIndex; |
35 |
List<TermNodeDto<T>> children;
|
|
36 |
List<TermNodeDto> children; |
|
36 | 37 |
Set<FeatureState> onlyApplicableIf = new HashSet<>(); |
37 | 38 |
Set<FeatureState> inapplicableIf = new HashSet<>(); |
38 | 39 |
UUID uuid; |
39 | 40 |
TermDto term; |
40 | 41 |
TermType type; |
41 | 42 |
TermTreeDto tree; |
42 |
|
|
43 |
public TermNodeDto(TermNode<T> node){ |
|
44 |
uuid = node.getUuid(); |
|
43 |
String path; |
|
44 |
|
|
45 |
public static TermNodeDto fromNode(TermNode node){ |
|
46 |
Assert.notNull(node, "Node should not be null"); |
|
47 |
TermDto term = node.getTerm() != null?TermDto.fromTerm(node.getTerm()): null; |
|
48 |
TermTreeDto tree = node.getGraph() != null? TermTreeDto.fromTree(HibernateProxyHelper.deproxy(node.getGraph(), TermTree.class)):null; |
|
49 |
TermNodeDto dto = new TermNodeDto(term, null, node.getParent() != null? node.getParent().getIndex(node): 0, tree, node.getUuid(), node.treeIndex(), node.getPath()); |
|
50 |
// uuid = node.getUuid(); |
|
45 | 51 |
if (node.getParent() != null){ |
46 |
parentUuid = node.getParent().getUuid();
|
|
52 |
dto.setParentUuid(node.getParent().getUuid());
|
|
47 | 53 |
} |
48 |
TermTree termTree = HibernateProxyHelper.deproxy(node.getGraph(), TermTree.class); |
|
49 |
tree = new TermTreeDto(termTree); |
|
50 |
treeIndex = node.treeIndex(); |
|
51 |
children = new ArrayList(); |
|
52 |
for (TermNode<T> child: node.getChildNodes()){ |
|
53 |
|
|
54 |
children.add(new TermNodeDto(child)); |
|
55 |
} |
|
56 |
onlyApplicableIf = node.getOnlyApplicableIf(); |
|
57 |
inapplicableIf = node.getInapplicableIf(); |
|
58 |
if (node.getTerm() != null){ |
|
59 |
term = TermDto.fromTerm(node.getTerm()); |
|
54 |
// TermTree termTree = HibernateProxyHelper.deproxy(node.getGraph(), TermTree.class); |
|
55 |
// tree = TermTreeDto.fromTree(termTree); |
|
56 |
// treeIndex = node.treeIndex(); |
|
57 |
List<TermNodeDto> children = new ArrayList(); |
|
58 |
for (Object o: node.getChildNodes()){ |
|
59 |
if (o instanceof TermNode){ |
|
60 |
TermNode child = (TermNode)o; |
|
61 |
|
|
62 |
if (child != null){ |
|
63 |
if(child.getTermType().equals(TermType.Character)){ |
|
64 |
children.add(CharacterNodeDto.fromTermNode(child)); |
|
65 |
}else{ |
|
66 |
children.add(TermNodeDto.fromNode(child)); |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
60 | 70 |
} |
61 |
type = node.getTermType(); |
|
71 |
dto.setChildren(children); |
|
72 |
dto.setOnlyApplicableIf(node.getOnlyApplicableIf()); |
|
73 |
dto.setInapplicableIf(node.getInapplicableIf()); |
|
74 |
// if (node.getTerm() != null){ |
|
75 |
// term = TermDto.fromTerm(node.getTerm()); |
|
76 |
// } |
|
77 |
dto.setTermType(node.getTermType()); |
|
78 |
// path = node.getPath(); |
|
79 |
return dto; |
|
62 | 80 |
} |
63 | 81 |
|
64 | 82 |
|
65 |
public TermNodeDto(TermDto termDto, TermNodeDto parent, int position, TermTreeDto treeDto){ |
|
66 |
uuid = null;
|
|
83 |
public TermNodeDto(TermDto termDto, TermNodeDto parent, int position, TermTreeDto treeDto, UUID uuid, String treeIndex, String path){
|
|
84 |
this.uuid = uuid;
|
|
67 | 85 |
if (parent != null){ |
68 | 86 |
parentUuid = parent.getUuid(); |
69 | 87 |
} |
70 |
treeIndex = null;
|
|
88 |
this.treeIndex = treeIndex;
|
|
71 | 89 |
term = termDto; |
72 | 90 |
type = termDto!= null? termDto.getTermType(): null; |
73 | 91 |
children = new ArrayList<>(); |
... | ... | |
75 | 93 |
parent.getChildren().add(position, this); |
76 | 94 |
} |
77 | 95 |
tree = treeDto; |
96 |
this.path = path; |
|
97 |
|
|
78 | 98 |
} |
79 | 99 |
|
80 | 100 |
/*--------Getter and Setter ---------------*/ |
... | ... | |
103 | 123 |
this.tree = tree; |
104 | 124 |
} |
105 | 125 |
|
106 |
public List<TermNodeDto<T>> getChildren() {
|
|
126 |
public List<TermNodeDto> getChildren() { |
|
107 | 127 |
return children; |
108 | 128 |
} |
109 | 129 |
|
110 |
public void setChildren(List<TermNodeDto<T>> children) {
|
|
130 |
public void setChildren(List<TermNodeDto> children) { |
|
111 | 131 |
this.children = children; |
112 | 132 |
} |
113 | 133 |
|
... | ... | |
162 | 182 |
return -1; |
163 | 183 |
} |
164 | 184 |
|
165 |
public boolean removeChild(TermNodeDto nodeDto){ |
|
185 |
/** |
|
186 |
* @return the path |
|
187 |
*/ |
|
188 |
public String getPath() { |
|
189 |
return path; |
|
190 |
} |
|
191 |
|
|
192 |
|
|
193 |
/** |
|
194 |
* @param path the path to set |
|
195 |
*/ |
|
196 |
public void setPath(String path) { |
|
197 |
this.path = path; |
|
198 |
} |
|
199 |
|
|
200 |
|
|
201 |
public boolean removeChild(TermNodeDto nodeDto){ |
|
166 | 202 |
int index = this.getIndex(nodeDto); |
167 | 203 |
if (index > -1){ |
168 | 204 |
this.getChildren().remove(index); |
... | ... | |
179 | 215 |
} |
180 | 216 |
|
181 | 217 |
|
218 |
public static String getTermNodeDtoSelect(){ |
|
219 |
String[] result = createSqlParts(); |
|
220 |
|
|
221 |
return result[0]+result[1]+result[2]; |
|
222 |
} |
|
223 |
|
|
224 |
/** |
|
225 |
* @param fromTable |
|
226 |
* @return |
|
227 |
*/ |
|
228 |
private static String[] createSqlParts() { |
|
229 |
String sqlSelectString = "" |
|
230 |
+ "select a.uuid, " |
|
231 |
+ "r, " |
|
232 |
+ "a.termType, " |
|
233 |
+ "a.uri, " |
|
234 |
+ "root, " |
|
235 |
+ "a.titleCache, " |
|
236 |
+ "a.allowDuplicates, " |
|
237 |
+ "a.orderRelevant, " |
|
238 |
+ "a.isFlat "; |
|
239 |
String sqlFromString = "from TermNode as a "; |
|
240 |
|
|
241 |
String sqlJoinString = "LEFT JOIN a.tree " |
|
242 |
+ "LEFT JOIN a.representations AS r " |
|
243 |
; |
|
244 |
|
|
245 |
String[] result = new String[3]; |
|
246 |
result[0] = sqlSelectString; |
|
247 |
result[1] = sqlFromString; |
|
248 |
result[2] = sqlJoinString; |
|
249 |
return result; |
|
250 |
} |
|
251 |
|
|
252 |
|
|
182 | 253 |
|
183 | 254 |
|
184 | 255 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TermTreeDto.java | ||
---|---|---|
17 | 17 |
import java.util.Set; |
18 | 18 |
import java.util.UUID; |
19 | 19 |
|
20 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
|
20 |
import eu.etaxonomy.cdm.model.description.Character;
|
|
21 | 21 |
import eu.etaxonomy.cdm.model.term.Representation; |
22 | 22 |
import eu.etaxonomy.cdm.model.term.TermNode; |
23 | 23 |
import eu.etaxonomy.cdm.model.term.TermTree; |
24 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
24 |
import eu.etaxonomy.cdm.model.term.TermType;;
|
|
25 | 25 |
|
26 | 26 |
/** |
27 | 27 |
* @author k.luther |
... | ... | |
32 | 32 |
|
33 | 33 |
TermNodeDto root; |
34 | 34 |
|
35 |
public TermTreeDto(TermTree<DefinedTermBase<DefinedTermBase>> tree){ |
|
36 |
this(tree.getUuid(), tree.getRepresentations(), tree.getTermType(), tree.getRoot(), tree.getTitleCache(), tree.isAllowDuplicates(), tree.isOrderRelevant(), tree.isFlat() ); |
|
37 |
} |
|
35 |
public static TermTreeDto fromTree(TermTree tree){ |
|
36 |
TermTreeDto dto = new TermTreeDto(tree.getUuid(), tree.getRepresentations(), tree.getTermType(), tree.getRoot(), tree.getTitleCache(), tree.isAllowDuplicates(), tree.isOrderRelevant(), tree.isFlat() ); |
|
37 |
return dto; |
|
38 |
} |
|
38 | 39 |
|
39 | 40 |
|
40 | 41 |
/** |
... | ... | |
49 | 50 |
|
50 | 51 |
public TermTreeDto(UUID uuid, Set<Representation> representations, TermType termType, TermNode root, String titleCache, boolean isAllowDuplicates, boolean isOrderRelevant, boolean isFlat) { |
51 | 52 |
super(uuid, representations, termType, titleCache, isAllowDuplicates, isOrderRelevant, isFlat); |
52 |
this.root = new TermNodeDto(null, null, 0, this); |
|
53 |
this.root = new TermNodeDto(null, null, 0, this, root.getUuid(), root.treeIndex(), root.getPath());
|
|
53 | 54 |
|
54 | 55 |
} |
55 | 56 |
|
... | ... | |
129 | 130 |
(boolean)elements[7], |
130 | 131 |
(boolean)elements[8]); |
131 | 132 |
termDto.setUri((URI)elements[3]); |
133 |
if (termDto.getTermType().equals(TermType.Character)){ |
|
134 |
termDto.setRoot(CharacterNodeDto.fromTermNode((TermNode<Character>) elements[4])); |
|
135 |
}else { |
|
136 |
termDto.setRoot(TermNodeDto.fromNode(((TermNode)elements[4]))); |
|
137 |
} |
|
132 | 138 |
|
133 |
termDto.setRoot(new TermNodeDto((TermNode)elements[4])); |
|
134 | 139 |
|
135 | 140 |
|
136 | 141 |
dtoMap.put(uuid, termDto); |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dto/TermVocabularyDto.java | ||
---|---|---|
18 | 18 |
|
19 | 19 |
import eu.etaxonomy.cdm.model.term.Representation; |
20 | 20 |
import eu.etaxonomy.cdm.model.term.TermType; |
21 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
21 | 22 |
|
22 | 23 |
/** |
23 | 24 |
* @author k.luther |
... | ... | |
36 | 37 |
// TODO Auto-generated constructor stub |
37 | 38 |
} |
38 | 39 |
|
40 |
public static TermVocabularyDto fromVocabulary(TermVocabulary voc) { |
|
41 |
TermVocabularyDto dto = new TermVocabularyDto(voc.getUuid(), voc.getRepresentations(), voc.getTermType(), voc.getTitleCache(), voc.isAllowDuplicates(), voc.isOrderRelevant(), voc.isFlat()); |
|
42 |
return dto; |
|
43 |
} |
|
44 |
|
|
39 | 45 |
public static List<TermVocabularyDto> termVocabularyDtoListFrom(List<Object[]> results) { |
40 | 46 |
List<TermVocabularyDto> dtos = new ArrayList<>(); // list to ensure order |
41 | 47 |
// map to handle multiple representations because of LEFT JOIN |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITermNodeService.java | ||
---|---|---|
16 | 16 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
17 | 17 |
import eu.etaxonomy.cdm.model.term.TermNode; |
18 | 18 |
import eu.etaxonomy.cdm.model.term.TermType; |
19 |
import eu.etaxonomy.cdm.persistence.dto.CharacterNodeDto; |
|
19 | 20 |
import eu.etaxonomy.cdm.persistence.dto.TermNodeDto; |
20 | 21 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
21 | 22 |
|
... | ... | |
82 | 83 |
*/ |
83 | 84 |
UpdateResult saveTermNodeDtoList(List<TermNodeDto> dtos); |
84 | 85 |
|
86 |
/** |
|
87 |
* @param dtos |
|
88 |
* @return |
|
89 |
*/ |
|
90 |
public UpdateResult saveCharacterNodeDtoList(List<CharacterNodeDto> dtos); |
|
91 |
|
|
85 | 92 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITermTreeService.java | ||
---|---|---|
50 | 50 |
public List<Restriction<?>> buildTermTypeFilterRestrictions(TermType termType); |
51 | 51 |
|
52 | 52 |
public List<TermTreeDto> listTermTreeDtosByTermType(TermType termType); |
53 |
|
|
54 |
/** |
|
55 |
* @param uuid |
|
56 |
* @return |
|
57 |
*/ |
|
58 |
public TermTreeDto getTermTreeDtoByUuid(UUID uuid); |
|
59 |
|
|
60 |
|
|
53 | 61 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TermNodeServiceImpl.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.cdm.api.service; |
11 | 11 |
|
12 | 12 |
import java.util.ArrayList; |
13 |
import java.util.HashSet; |
|
13 | 14 |
import java.util.Iterator; |
14 | 15 |
import java.util.List; |
15 | 16 |
import java.util.Set; |
... | ... | |
25 | 26 |
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException; |
26 | 27 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
27 | 28 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
29 |
import eu.etaxonomy.cdm.model.description.Character; |
|
28 | 30 |
import eu.etaxonomy.cdm.model.description.Feature; |
31 |
import eu.etaxonomy.cdm.model.description.MeasurementUnit; |
|
32 |
import eu.etaxonomy.cdm.model.description.StatisticalMeasure; |
|
33 |
import eu.etaxonomy.cdm.model.term.DefinedTerm; |
|
29 | 34 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
35 |
import eu.etaxonomy.cdm.model.term.Representation; |
|
30 | 36 |
import eu.etaxonomy.cdm.model.term.TermNode; |
31 | 37 |
import eu.etaxonomy.cdm.model.term.TermTree; |
32 | 38 |
import eu.etaxonomy.cdm.model.term.TermType; |
33 | 39 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
34 | 40 |
import eu.etaxonomy.cdm.persistence.dao.term.ITermNodeDao; |
41 |
import eu.etaxonomy.cdm.persistence.dto.CharacterDto; |
|
42 |
import eu.etaxonomy.cdm.persistence.dto.CharacterNodeDto; |
|
43 |
import eu.etaxonomy.cdm.persistence.dto.MergeResult; |
|
44 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
|
35 | 45 |
import eu.etaxonomy.cdm.persistence.dto.TermNodeDto; |
46 |
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto; |
|
36 | 47 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
37 | 48 |
|
38 | 49 |
/** |
... | ... | |
219 | 230 |
@Override |
220 | 231 |
public UpdateResult saveTermNodeDtoList(List<TermNodeDto> dtos){ |
221 | 232 |
UpdateResult result = new UpdateResult(); |
233 |
MergeResult<TermNode> mergeResult; |
|
222 | 234 |
List<UUID> uuids = new ArrayList<>(); |
223 | 235 |
dtos.stream().forEach(dto -> uuids.add(dto.getUuid())); |
224 | 236 |
List<TermNode> nodes = dao.list(uuids, null, 0, null, null); |
225 | 237 |
//check all attributes for changes and adapt |
226 |
Iterator<TermNodeDto> dtoIterator = dtos.iterator(); |
|
238 |
// Iterator<TermNodeDto> dtoIterator = dtos.iterator();
|
|
227 | 239 |
for (TermNode node: nodes){ |
228 |
TermNodeDto dto = dtoIterator.next(); |
|
229 |
if (dto.getUuid().equals(node.getUuid())){ |
|
230 |
// only node changes, everything else will be handled by the operations/service methods |
|
231 |
if (!dto.getInapplicableIf().equals(node.getInapplicableIf())){ |
|
232 |
node.getInapplicableIf().clear(); |
|
233 |
node.getInapplicableIf().addAll(dto.getInapplicableIf()); |
|
240 |
for (TermNodeDto dto: dtos){ |
|
241 |
// TermNodeDto dto = dtoIterator.next(); |
|
242 |
if (dto.getUuid().equals(node.getUuid())){ |
|
243 |
// only node changes, everything else will be handled by the operations/service methods |
|
244 |
if (!dto.getInapplicableIf().equals(node.getInapplicableIf())){ |
|
245 |
node.getInapplicableIf().clear(); |
|
246 |
node.getInapplicableIf().addAll(dto.getInapplicableIf()); |
|
247 |
} |
|
248 |
if (!dto.getOnlyApplicableIf().equals(node.getOnlyApplicableIf())){ |
|
249 |
node.getOnlyApplicableIf().clear(); |
|
250 |
node.getOnlyApplicableIf().addAll(dto.getOnlyApplicableIf()); |
|
251 |
} |
|
234 | 252 |
} |
235 |
if (!dto.getOnlyApplicableIf().equals(node.getOnlyApplicableIf())){ |
|
236 |
node.getOnlyApplicableIf().clear(); |
|
237 |
node.getOnlyApplicableIf().addAll(dto.getOnlyApplicableIf()); |
|
253 |
mergeResult = dao.merge(node, true); |
|
254 |
result.addUpdatedObject(mergeResult.getMergedEntity()); |
|
255 |
} |
|
256 |
} |
|
257 |
|
|
258 |
//saveOrUpdate all nodes |
|
259 |
return result; |
|
260 |
} |
|
261 |
|
|
262 |
@Override |
|
263 |
public UpdateResult saveCharacterNodeDtoList(List<CharacterNodeDto> dtos){ |
|
264 |
MergeResult<TermNode> mergeResult; |
|
265 |
UpdateResult result = new UpdateResult(); |
|
266 |
List<UUID> nodeUuids = new ArrayList<>(); |
|
267 |
|
|
268 |
dtos.stream().forEach(dto -> nodeUuids.add(dto.getUuid())); |
|
269 |
List<TermNode> nodes = dao.list(nodeUuids, null, 0, null, null); |
|
270 |
//check all attributes for changes and adapt |
|
271 |
Iterator<CharacterNodeDto> dtoIterator = dtos.iterator(); |
|
272 |
for (TermNode<Character> node: nodes){ |
|
273 |
for (CharacterNodeDto dto: dtos){ |
|
274 |
// TermNodeDto dto = dtoIterator.next(); |
|
275 |
if (dto.getUuid().equals(node.getUuid())){ |
|
276 |
// only node changes, everything else will be handled by the operations/service methods |
|
277 |
if (!dto.getInapplicableIf().equals(node.getInapplicableIf())){ |
|
278 |
node.getInapplicableIf().clear(); |
|
279 |
node.getInapplicableIf().addAll(dto.getInapplicableIf()); |
|
280 |
} |
|
281 |
if (!dto.getOnlyApplicableIf().equals(node.getOnlyApplicableIf())){ |
|
282 |
node.getOnlyApplicableIf().clear(); |
|
283 |
node.getOnlyApplicableIf().addAll(dto.getOnlyApplicableIf()); |
|
284 |
} |
|
285 |
|
|
286 |
Character character = null; |
|
287 |
CharacterDto characterDto = (CharacterDto) dto.getTerm(); |
|
288 |
character = HibernateProxyHelper.deproxy(node.getTerm(), Character.class); |
|
289 |
// representations |
|
290 |
for (Representation rep: dto.getTerm().getRepresentations()){ |
|
291 |
Representation oldRep = character.getRepresentation(rep.getLanguage()); |
|
292 |
if (oldRep == null){ |
|
293 |
oldRep = new Representation(); |
|
294 |
oldRep.setLanguage(rep.getLanguage()); |
|
295 |
character.addRepresentation(oldRep); |
|
296 |
} |
|
297 |
oldRep.setLabel(rep.getLabel()); |
|
298 |
oldRep.setAbbreviatedLabel(rep.getAbbreviatedLabel()); |
|
299 |
oldRep.setText(rep.getText()); |
|
300 |
} |
|
301 |
Set<Representation> deleteRepresentations = new HashSet<>(); |
|
302 |
if (character.getRepresentations().size() > dto.getTerm().getRepresentations().size()){ |
|
303 |
for (Representation rep: character.getRepresentations()){ |
|
304 |
if(dto.getTerm().getRepresentation(rep.getLanguage()) == null){ |
|
305 |
deleteRepresentations.add(rep); |
|
306 |
} |
|
307 |
} |
|
308 |
} |
|
309 |
|
|
310 |
if (!deleteRepresentations.isEmpty()){ |
|
311 |
for (Representation rep: deleteRepresentations){ |
|
312 |
character.removeRepresentation(rep); |
|
313 |
} |
|
314 |
|
|
315 |
} |
|
316 |
|
|
317 |
// structural modifier |
|
318 |
if (characterDto.getStructureModifier() != null){ |
|
319 |
DefinedTerm structureModifier = (DefinedTerm) termService.load(characterDto.getStructureModifier().getUuid()); |
|
320 |
character.setStructureModifier(structureModifier); |
|
321 |
} |
|
322 |
|
|
323 |
|
|
324 |
// supports quantitative data |
|
325 |
character.setSupportsQuantitativeData(characterDto.isSupportsQuantitativeData()); |
|
326 |
// recommended measurement units |
|
327 |
character.getRecommendedMeasurementUnits().clear(); |
|
328 |
List<UUID> uuids = new ArrayList<>(); |
|
329 |
for (TermDto termDto: characterDto.getRecommendedMeasurementUnits()){ |
|
330 |
uuids.add(termDto.getUuid()); |
|
331 |
} |
|
332 |
List<DefinedTermBase> terms; |
|
333 |
if (!uuids.isEmpty()){ |
|
334 |
terms = termService.load(uuids, null); |
|
335 |
Set<MeasurementUnit> measurementUnits = new HashSet<>(); |
|
336 |
for (DefinedTermBase term: terms){ |
|
337 |
if (term instanceof MeasurementUnit){ |
|
338 |
measurementUnits.add((MeasurementUnit)term); |
|
339 |
} |
|
340 |
} |
|
341 |
character.getRecommendedMeasurementUnits().addAll(measurementUnits); |
|
342 |
} |
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
// statistical measures |
|
347 |
character.getRecommendedStatisticalMeasures().clear(); |
|
348 |
uuids = new ArrayList<>(); |
|
349 |
for (TermDto termDto: characterDto.getRecommendedStatisticalMeasures()){ |
|
350 |
uuids.add(termDto.getUuid()); |
|
351 |
} |
|
352 |
if (!uuids.isEmpty()){ |
|
353 |
terms = termService.load(uuids, null); |
|
354 |
Set<StatisticalMeasure> statisticalMeasures = new HashSet<>(); |
|
355 |
for (DefinedTermBase term: terms){ |
|
356 |
if (term instanceof StatisticalMeasure){ |
|
357 |
statisticalMeasures.add((StatisticalMeasure)term); |
|
358 |
} |
|
359 |
} |
|
360 |
character.getRecommendedStatisticalMeasures().addAll(statisticalMeasures); |
|
361 |
} |
|
362 |
|
|
363 |
// recommended mod. vocabularies |
|
364 |
character.getRecommendedModifierEnumeration().clear(); |
|
365 |
uuids = new ArrayList<>(); |
|
366 |
for (TermVocabularyDto termDto: characterDto.getRecommendedModifierEnumeration()){ |
|
367 |
uuids.add(termDto.getUuid()); |
|
368 |
} |
|
369 |
List<TermVocabulary> termVocs; |
|
370 |
if (!uuids.isEmpty()){ |
|
371 |
termVocs = vocabularyService.load(uuids, null); |
|
372 |
for (TermVocabulary voc: termVocs){ |
|
373 |
character.addRecommendedModifierEnumeration(voc); |
|
374 |
} |
|
375 |
} |
|
376 |
|
|
377 |
|
|
378 |
// supports categorical data |
|
379 |
character.setSupportsCategoricalData(characterDto.isSupportsCategoricalData()); |
|
380 |
// supported state vocabularies |
|
381 |
character.getSupportedCategoricalEnumerations().clear(); |
|
382 |
uuids = new ArrayList<>(); |
|
383 |
for (TermVocabularyDto termDto: characterDto.getSupportedCategoricalEnumerations()){ |
|
384 |
uuids.add(termDto.getUuid()); |
|
385 |
} |
|
386 |
if (!uuids.isEmpty()){ |
|
387 |
termVocs = vocabularyService.load(uuids, null); |
|
388 |
|
|
389 |
for (TermVocabulary voc: termVocs){ |
|
390 |
character.addSupportedCategoricalEnumeration(voc); |
|
391 |
} |
|
392 |
} |
|
393 |
node.setTerm(character); |
|
394 |
UUID uuid = dao.saveOrUpdate(node); |
|
395 |
result.addUpdatedObject(load(uuid)); |
|
396 |
|
|
397 |
// result.addUpdatedObject(termService.merge(character, true).getMergedEntity()); |
|
238 | 398 |
} |
399 |
|
|
239 | 400 |
} |
240 | 401 |
|
241 | 402 |
} |
242 |
dao.saveOrUpdateAll(nodes); |
|
243 |
//saveOrUpdate all nodes |
|
244 | 403 |
return result; |
245 | 404 |
} |
246 | 405 |
|
406 |
|
|
247 | 407 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TermTreeServiceImpl.java | ||
---|---|---|
178 | 178 |
return dao.listTermTreeDtosByTermType(termType); |
179 | 179 |
} |
180 | 180 |
|
181 |
|
|
181 |
@Override |
|
182 |
public TermTreeDto getTermTreeDtoByUuid(UUID uuid) { |
|
183 |
return dao.getTermTreeDtosByUuid(uuid); |
|
184 |
} |
|
182 | 185 |
|
183 | 186 |
} |
Also available in: Unified diff
ref #8774: further implementations for using term dtos in editor