Revision fd711754
Added by Katja Luther almost 4 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixPart.java | ||
---|---|---|
40 | 40 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
41 | 41 |
import eu.etaxonomy.cdm.api.service.IDescriptionService; |
42 | 42 |
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService; |
43 |
import eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto; |
|
44 |
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO; |
|
45 |
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO; |
|
43 | 46 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
44 | 47 |
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet; |
45 | 48 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
46 | 49 |
import eu.etaxonomy.cdm.model.term.TermType; |
50 |
import eu.etaxonomy.cdm.persistence.dto.MergeResult; |
|
47 | 51 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
48 | 52 |
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin; |
49 | 53 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
... | ... | |
186 | 190 |
@Override |
187 | 191 |
public void save(IProgressMonitor monitor) { |
188 | 192 |
// save edited descriptions |
189 |
List<DescriptionBase> descriptions = matrix.getRowsToSave().stream()
|
|
193 |
List<DescriptionBaseDto> descriptions = matrix.getRowsToSave().values().stream()
|
|
190 | 194 |
.map(row->row.getDescription()) |
191 | 195 |
.collect(Collectors.toList()); |
192 | 196 |
matrix.addSpecimensToDescriptiveDataSet(); |
193 |
CdmStore.getService(IDescriptiveDataSetService.class).removeDescriptions(matrix.getDescriptionsToDelete(), matrix.getDescriptiveDataSet().getUuid()); |
|
194 |
|
|
195 |
CdmStore.getService(IDescriptionService.class).merge(descriptions); |
|
197 |
//newly added descriptions should not be saved again. |
|
198 |
descriptions.removeAll(matrix.getRowsToSave().values()); |
|
196 | 199 |
matrix.getRowsToSave().clear(); |
200 |
if (matrix.getDescriptionsToDelete() != null && !matrix.getDescriptionsToDelete().isEmpty()){ |
|
201 |
CdmStore.getService(IDescriptiveDataSetService.class).removeDescriptions(matrix.getDescriptionsToDelete(), matrix.getDescriptiveDataSet().getUuid()); |
|
202 |
} |
|
203 |
List<MergeResult<DescriptionBase>> results = CdmStore.getService(IDescriptionService.class).mergeDescriptions(descriptions, true); |
|
197 | 204 |
conversation.commit(); |
205 |
HashMap<UUID, DescriptionBase> descriptionResults = new HashMap<>(); |
|
206 |
for (MergeResult result: results){ |
|
207 |
if (result.getMergedEntity() != null){ |
|
208 |
descriptionResults.put(result.getMergedEntity().getUuid(), (DescriptionBase)result.getMergedEntity()); |
|
209 |
} |
|
210 |
} |
|
211 |
List<Object> updateRows = matrix.getDescriptions().stream().filter(row->descriptionResults.keySet().contains(((RowWrapperDTO)row).getDescription().getDescription().getUuid())).collect(Collectors.toList()); |
|
212 |
for (Object updateRow: updateRows){ |
|
213 |
if (updateRow instanceof SpecimenRowWrapperDTO){ |
|
214 |
SpecimenRowWrapperDTO dto = (SpecimenRowWrapperDTO)updateRow; |
|
215 |
dto.getDescription().setDescription(descriptionResults.get(((SpecimenRowWrapperDTO) updateRow).getDescription().getDescription().getUuid())); |
|
216 |
} |
|
217 |
} |
|
218 |
// matrix.loadDescriptions(getDescriptiveDataSet().getUuid(), false); |
|
219 |
|
|
198 | 220 |
dirty.setDirty(false); |
199 | 221 |
} |
200 | 222 |
|
Also available in: Unified diff
ref #8785: update descriptions in description list after merge