103 |
103 |
SpecimenSelectionDialog dialog = new SpecimenSelectionDialog(matrix.getShell(), matrix);
|
104 |
104 |
if(dialog.open()==Window.OK){
|
105 |
105 |
Collection<SpecimenNodeWrapper> wrappers = dialog.getSpecimen();
|
106 |
|
if(wrappers.stream().anyMatch(wrapper->!wrapper.isIndividualsAssociation())
|
|
106 |
if(wrappers.stream().anyMatch(wrapper->wrapper.getTaxonDescription()==null)
|
107 |
107 |
&& !MessagingUtils.confirmDialog(
|
108 |
108 |
"Create Taxon Association",
|
109 |
109 |
"Some specimens are not linked with taxon via IndividualsAssociation yet.\n"
|
... | ... | |
111 |
111 |
return;
|
112 |
112 |
}
|
113 |
113 |
for (SpecimenNodeWrapper wrapper : wrappers) {
|
114 |
|
if(!wrapper.isIndividualsAssociation()){
|
|
114 |
TaxonDescription taxonDescription = wrapper.getTaxonDescription();
|
|
115 |
if(taxonDescription==null){
|
115 |
116 |
Optional<TaxonDescription> associationDescriptionOptional = wrapper.getTaxonNode().getTaxon().getDescriptions().stream()
|
116 |
117 |
.filter(desc->desc.getTypes().contains(DescriptionType.INDIVIDUALS_ASSOCIATION))
|
117 |
118 |
.findFirst();
|
118 |
119 |
Taxon taxon = wrapper.getTaxonNode().getTaxon();
|
119 |
|
TaxonDescription associationDescription;
|
120 |
120 |
if(!associationDescriptionOptional.isPresent()){
|
121 |
|
associationDescription = TaxonDescription.NewInstance(taxon);
|
|
121 |
taxonDescription = TaxonDescription.NewInstance(taxon);
|
122 |
122 |
}
|
123 |
123 |
else{
|
124 |
|
associationDescription = associationDescriptionOptional.get();
|
|
124 |
taxonDescription = associationDescriptionOptional.get();
|
125 |
125 |
}
|
126 |
126 |
|
127 |
127 |
SpecimenOrObservationBase specimen = CdmStore.getService(IOccurrenceService.class).load(wrapper.getUuidAndTitleCache().getUuid());
|
128 |
128 |
IndividualsAssociation association = IndividualsAssociation.NewInstance(specimen);
|
129 |
|
associationDescription.addElement(association);
|
|
129 |
taxonDescription.addElement(association);
|
130 |
130 |
CdmStore.getService(ITaxonService.class).saveOrUpdate(wrapper.getTaxonNode().getTaxon());
|
131 |
131 |
}
|
132 |
132 |
SpecimenDescription specimenDescription = CdmStore.getService(IDescriptiveDataSetService.class)
|
... | ... | |
138 |
138 |
error += specimenDescription+"\n";
|
139 |
139 |
continue;
|
140 |
140 |
}
|
141 |
|
//add specimen description
|
|
141 |
//add wrapper to matrix
|
142 |
142 |
matrix.getDescriptions().add(rowWrapper);
|
|
143 |
//add specimen description to data set
|
143 |
144 |
matrix.getDescriptiveDataSet().addDescription(specimenDescription);
|
|
145 |
//add taxon description with IndividualsAssociation to the specimen to data set
|
|
146 |
matrix.getDescriptiveDataSet().addDescription(taxonDescription);
|
144 |
147 |
matrix.getCdmEntitiySession().load(specimenDescription, true);
|
|
148 |
matrix.getCdmEntitiySession().load(taxonDescription, true);
|
145 |
149 |
|
146 |
150 |
matrix.setDirty();
|
147 |
151 |
matrix.getSpecimenCache().remove(wrapper);
|
ref #8539 Add association taxon description to descriptive data set