Commit d38ff283 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '173-updating-controlled-vocabularies-fails' into 'master'

Resolve "Updating controlled vocabularies fails"

Closes #173

See merge request !167
parents 57d72bee 96ba2a06
Pipeline #5637 passed with stages
in 4 minutes and 39 seconds
......@@ -199,6 +199,15 @@ public class VocabularyTerm extends BasicModel implements SelfCleaning {
return vocabulary;
}
/**
* Sets the Controlled vocabulary.
*
* @param vocabulary the Controlled vocabulary to set
*/
public void setVocabulary(final ControlledVocabulary vocabulary) {
this.vocabulary = vocabulary;
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
......
......@@ -228,15 +228,17 @@ public class VocabularyServiceImpl implements VocabularyService {
// only when there's a code
if (inputTerm.getCode() != null) {
inputTerm.setId(existing.stream()
final VocabularyTerm persistedTerm = existing.stream()
// the ones with codes only
.filter(existingTerm -> existingTerm != null && existingTerm.getCode() != null)
// find matching term by code
.filter(existingTerm -> existingTerm.getCode().equals(inputTerm.getCode()))
// get it's ID
.map(existingTerm -> existingTerm.getId())
// get the ID of the existing term by code or null
.findFirst().orElse(null));
.filter(existingTerm -> existingTerm.getCode().equals(inputTerm.getCode())).findFirst().orElse(null);
// set the ID of the existing term or null
inputTerm.setId(persistedTerm != null ? persistedTerm.getId() : null);
// set the reference of the existing vocabulary or null
inputTerm.setVocabulary(persistedTerm != null ? persistedTerm.getVocabulary() : null);
if (inputTerm.getId() == null) {
LOG.debug("New vocabulary term {}", inputTerm);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment