Revision b2063ede
Added by Patrick Plitzner over 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java | ||
---|---|---|
34 | 34 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm; |
35 | 35 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
36 | 36 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
37 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
|
38 | 37 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
39 | 38 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
40 | 39 |
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer; |
... | ... | |
70 | 69 |
|
71 | 70 |
|
72 | 71 |
@Override |
73 |
public int updateDistributionField(String distributionArea, Object comboValue, Taxon taxon) { |
|
72 |
public int updateDistributionField(String distributionAreaString, Object comboValue, Taxon taxon) {
|
|
74 | 73 |
Set<DefinedTermBase> chosenTerms = getChosenTerms(); |
75 |
NamedArea nArea = null; |
|
76 |
for(DefinedTermBase dt:chosenTerms){
|
|
77 |
if(dt.getTitleCache().equalsIgnoreCase(distributionArea)){
|
|
78 |
nArea = (NamedArea) dt;
|
|
74 |
NamedArea namedArea = null;
|
|
75 |
for(DefinedTermBase term:chosenTerms){
|
|
76 |
if(term.getTitleCache().equalsIgnoreCase(distributionAreaString)){
|
|
77 |
namedArea = (NamedArea) term;
|
|
79 | 78 |
break; |
80 | 79 |
} |
81 | 80 |
} |
82 |
List<Distribution> distribution = getDistribution(taxon);
|
|
83 |
Distribution db = null;
|
|
84 |
for(Distribution dist : distribution){ |
|
85 |
if(dist.getArea().equals(nArea)){ |
|
86 |
db = dist;
|
|
81 |
List<Distribution> distributions = getDistributions(taxon);
|
|
82 |
Distribution distribution = null;
|
|
83 |
for(Distribution dist : distributions){
|
|
84 |
if(dist.getArea().equals(namedArea)){
|
|
85 |
distribution = dist;
|
|
87 | 86 |
break; |
88 | 87 |
} |
89 | 88 |
} |
90 |
if(comboValue == null){//delete descriptionElementBase |
|
91 |
getDescriptionService().deleteDescriptionElement(db);//descriptionElementbase |
|
89 |
if(distribution==null){ |
|
90 |
//create new distribution |
|
91 |
distribution = Distribution.NewInstance(namedArea, (PresenceAbsenceTerm) comboValue); |
|
92 |
Set<TaxonDescription> descriptions = taxon.getDescriptions(); |
|
93 |
if (descriptions != null) { |
|
94 |
for (TaxonDescription desc : descriptions) { |
|
95 |
// add to first taxon description |
|
96 |
desc.addElement(distribution); |
|
97 |
getTaxonService().saveOrUpdate(taxon); |
|
98 |
return 0; |
|
99 |
} |
|
100 |
} else {// there are no TaxonDescription yet. |
|
101 |
TaxonDescription taxonDescription = TaxonDescription.NewInstance(taxon); |
|
102 |
taxonDescription.addElement(distribution); |
|
103 |
taxon.addDescription(taxonDescription); |
|
104 |
getTaxonService().saveOrUpdate(taxon); |
|
105 |
return 0; |
|
106 |
} |
|
107 |
} |
|
108 |
else if(comboValue == null){//delete descriptionElementBase |
|
109 |
distribution.getInDescription().removeElement(distribution); |
|
92 | 110 |
getTaxonService().saveOrUpdate(taxon); |
93 | 111 |
return 1; |
94 |
}else{ |
|
95 |
db.setStatus((PresenceAbsenceTerm)comboValue); |
|
96 |
getDescriptionService().saveDescriptionElement(db);//descriptionElementbase? |
|
112 |
} |
|
113 |
else{ |
|
114 |
distribution.setStatus((PresenceAbsenceTerm)comboValue); |
|
115 |
getTaxonService().saveOrUpdate(taxon); |
|
97 | 116 |
return 0; |
98 | 117 |
} |
118 |
return -1; |
|
99 | 119 |
} |
100 | 120 |
|
101 | 121 |
@Override |
... | ... | |
166 | 186 |
} |
167 | 187 |
|
168 | 188 |
@Override |
169 |
public List<Distribution> getDistribution(Taxon taxon) { |
|
189 |
public List<Distribution> getDistributions(Taxon taxon) {
|
|
170 | 190 |
Set<Feature> setFeature = new HashSet<Feature>(Arrays.asList(Feature.DISTRIBUTION())); |
171 | 191 |
List<Distribution> listTaxonDescription = descriptionService.listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY); |
172 | 192 |
return listTaxonDescription; |
... | ... | |
250 | 270 |
@Override |
251 | 271 |
public List<PresenceAbsenceTerm> getPresenceAbsenceTerms() { |
252 | 272 |
//TODO Better to use TermType instead of class to get the list |
253 |
return termService.list(PresenceAbsenceTerm.class, null, null, null, DESCRIPTION_INIT_STRATEGY);
|
|
273 |
return termService.list(PresenceAbsenceTerm.class, null, null, null, null);
|
|
254 | 274 |
} |
255 | 275 |
|
256 | 276 |
protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{ |
Also available in: Unified diff
ref #5458 Cleanup and stability for distribution editor