Revision b1fe8acf
Added by Fabian Reimeier over 6 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTablePresenter.java | ||
---|---|---|
19 | 19 |
import java.util.Set; |
20 | 20 |
import java.util.UUID; |
21 | 21 |
|
22 |
import org.springframework.beans.factory.annotation.Autowired; |
|
23 |
import org.springframework.beans.factory.annotation.Qualifier; |
|
24 |
import org.springframework.transaction.TransactionStatus; |
|
25 |
|
|
22 | 26 |
import com.vaadin.server.VaadinSession; |
23 | 27 |
import com.vaadin.spring.annotation.SpringComponent; |
24 | 28 |
import com.vaadin.spring.annotation.ViewScope; |
25 | 29 |
import com.vaadin.ui.Notification; |
26 | 30 |
|
31 |
import eu.etaxonomy.cdm.api.application.CdmRepository; |
|
27 | 32 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
28 | 33 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
29 | 34 |
import eu.etaxonomy.cdm.model.common.Language; |
30 | 35 |
import eu.etaxonomy.cdm.model.common.Representation; |
31 | 36 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
37 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
32 | 38 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
33 | 39 |
import eu.etaxonomy.cdm.model.description.Distribution; |
34 | 40 |
import eu.etaxonomy.cdm.model.description.Feature; |
... | ... | |
38 | 44 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
39 | 45 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
40 | 46 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
47 |
import eu.etaxonomy.cdm.service.CdmUserHelper; |
|
41 | 48 |
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer; |
42 | 49 |
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory; |
43 | 50 |
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper; |
... | ... | |
55 | 62 |
|
56 | 63 |
private static final long serialVersionUID = 3313043335587777217L; |
57 | 64 |
|
65 |
@Autowired |
|
66 |
private CdmUserHelper userHelper; |
|
67 |
|
|
68 |
@Autowired |
|
69 |
@Qualifier("cdmRepository") |
|
70 |
private CdmRepository repo; |
|
71 |
|
|
58 | 72 |
public int updateDistributionField(String distributionAreaString, Object comboValue, Taxon taxon) { |
73 |
TransactionStatus tx = repo.startTransaction(); |
|
74 |
taxon = (Taxon)getRepo().getTaxonService().find(taxon.getUuid()); |
|
59 | 75 |
Set<DefinedTermBase> chosenTerms = getChosenTerms(); |
60 |
Set<NamedArea> termSet = getTermSet(); |
|
61 | 76 |
NamedArea namedArea = null; |
62 | 77 |
for(DefinedTermBase term:chosenTerms){ |
63 | 78 |
Representation representation = term.getRepresentation(Language.DEFAULT()); |
... | ... | |
82 | 97 |
} |
83 | 98 |
if(namedArea==null){ |
84 | 99 |
Notification.show("Error during update of distribution term!"); |
100 |
repo.commitTransaction(tx); |
|
85 | 101 |
return -1; |
86 | 102 |
} |
87 | 103 |
List<Distribution> distributions = getDistributions(taxon); |
... | ... | |
100 | 116 |
for (TaxonDescription desc : descriptions) { |
101 | 117 |
// add to first taxon description |
102 | 118 |
desc.addElement(distribution); |
103 |
CdmSpringContextHelper.getTaxonService().saveOrUpdate(taxon);
|
|
119 |
repo.commitTransaction(tx);
|
|
104 | 120 |
return 0; |
105 | 121 |
} |
106 | 122 |
} else {// there are no TaxonDescription yet. |
107 | 123 |
TaxonDescription taxonDescription = TaxonDescription.NewInstance(taxon); |
108 | 124 |
taxonDescription.addElement(distribution); |
109 |
taxon.addDescription(taxonDescription); |
|
110 |
CdmSpringContextHelper.getTaxonService().saveOrUpdate(taxon); |
|
125 |
repo.commitTransaction(tx); |
|
111 | 126 |
return 0; |
112 | 127 |
} |
113 | 128 |
} |
114 | 129 |
else if(comboValue == null){//delete descriptionElementBase |
115 |
distribution.getInDescription().removeElement(distribution); |
|
116 |
CdmSpringContextHelper.getTaxonService().saveOrUpdate(taxon); |
|
130 |
DescriptionBase<?> desc = distribution.getInDescription(); |
|
131 |
desc.removeElement(distribution); |
|
132 |
repo.commitTransaction(tx); |
|
117 | 133 |
return 1; |
118 | 134 |
} |
119 |
else{ |
|
135 |
else{//update distribution
|
|
120 | 136 |
distribution.setStatus((PresenceAbsenceTerm)comboValue); |
121 |
CdmSpringContextHelper.getTaxonService().saveOrUpdate(taxon);
|
|
137 |
repo.commitTransaction(tx);
|
|
122 | 138 |
return 0; |
123 | 139 |
} |
140 |
repo.commitTransaction(tx); |
|
124 | 141 |
return -1; |
125 | 142 |
} |
126 | 143 |
|
127 | 144 |
public Set<DefinedTermBase> getChosenTerms() { |
128 | 145 |
VaadinSession session = VaadinSession.getCurrent(); |
129 |
UUID termUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID);
|
|
146 |
UUID vocUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID);
|
|
130 | 147 |
getConversationHolder().getSession(); |
131 |
TermVocabulary<DefinedTermBase> term = CdmSpringContextHelper.getVocabularyService().load(termUUID, Arrays.asList("terms.representations"));
|
|
132 |
term = CdmBase.deproxy(term);
|
|
133 |
return term.getTerms();
|
|
148 |
TermVocabulary<DefinedTermBase> voc = CdmSpringContextHelper.getVocabularyService().load(vocUUID, Arrays.asList("terms.representations"));
|
|
149 |
voc = CdmBase.deproxy(voc);
|
|
150 |
return voc.getTerms();
|
|
134 | 151 |
} |
135 | 152 |
|
136 | 153 |
public List<String> getAbbreviatedTermList() { |
137 | 154 |
Set<NamedArea> terms = getTermSet(); |
138 |
List<String> list = new ArrayList<String>();
|
|
139 |
for(DefinedTermBase dtb: terms){ |
|
155 |
List<String> list = new ArrayList<>(); |
|
156 |
for(DefinedTermBase<?> dtb: terms){
|
|
140 | 157 |
for(Representation r : dtb.getRepresentations()){ |
141 | 158 |
list.add(r.getAbbreviatedLabel()); |
142 | 159 |
} |
... | ... | |
154 | 171 |
|
155 | 172 |
private Set<NamedArea> getTermSet(){ |
156 | 173 |
VaadinSession session = VaadinSession.getCurrent(); |
157 |
UUID termUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID);
|
|
158 |
TermVocabulary<NamedArea> vocabulary = CdmSpringContextHelper.getVocabularyService().load(termUUID, Arrays.asList("terms.representations"));
|
|
174 |
UUID vocUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID);
|
|
175 |
TermVocabulary<NamedArea> vocabulary = CdmSpringContextHelper.getVocabularyService().load(vocUUID, Arrays.asList("terms.representations"));
|
|
159 | 176 |
vocabulary = CdmBase.deproxy(vocabulary, TermVocabulary.class); |
160 | 177 |
return vocabulary.getTermsOrderedByLabels(Language.DEFAULT()); |
161 | 178 |
} |
... | ... | |
185 | 202 |
|
186 | 203 |
public List<Distribution> getDistributions(Taxon taxon) { |
187 | 204 |
Set<Feature> setFeature = new HashSet<>(Arrays.asList(Feature.DISTRIBUTION())); |
188 |
List<Distribution> listTaxonDescription = CdmSpringContextHelper.getDescriptionService().listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY); |
|
205 |
List<Distribution> listTaxonDescription = CdmSpringContextHelper.getDescriptionService() |
|
206 |
.listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY); |
|
189 | 207 |
return listTaxonDescription; |
190 | 208 |
|
191 | 209 |
} |
... | ... | |
254 | 272 |
"name.$", |
255 | 273 |
"name.rank.representations", |
256 | 274 |
"name.status.type.representations", |
257 |
"taxon2.name" |
|
275 |
"taxon2.name",
|
|
258 | 276 |
}); |
259 | 277 |
|
260 | 278 |
/**Helper Methods*/ |
... | ... | |
274 | 292 |
} |
275 | 293 |
}); |
276 | 294 |
} |
295 |
|
|
296 |
/** |
|
297 |
* |
|
298 |
* {@inheritDoc} |
|
299 |
*/ |
|
300 |
@Override |
|
301 |
protected void onPresenterReady() { |
|
302 |
// VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_TAXON_NODES_UUID, taxonNodes); |
|
303 |
// VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID, voc.getUuid()); |
|
304 |
// VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_SELECTED_AREAS, selectedAreas); |
|
305 |
// VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_CLASSIFICATION, classificationUuid); |
|
306 |
if(userHelper.userIsAutheticated() && !userHelper.userIsAnnonymous()) { |
|
307 |
getView().openDistributionSettings(); |
|
308 |
} |
|
309 |
} |
|
277 | 310 |
} |
Also available in: Unified diff
ref #6903