add encoding property to terms and synonyms

This commit is contained in:
Michele Artini 2022-06-23 11:18:47 +02:00
parent d69bf62b5f
commit 9c7656e618
7 changed files with 137 additions and 16 deletions

View File

@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.common.controller.AbstractDnetController;
import eu.dnetlib.is.vocabulary.model.Synonym;
import eu.dnetlib.is.vocabulary.model.Vocabulary;
import eu.dnetlib.is.vocabulary.model.VocabularyTerm;
import eu.dnetlib.is.vocabulary.model.VocabularyTermPK;
@ -98,12 +99,13 @@ public class VocabularyRestController extends AbstractDnetController {
term.setVocabulary(vocId);
term.setCode(n.valueOf("@code"));
term.setName(n.valueOf("@english_name"));
term.setEncoding(n.valueOf("@encoding"));
term.setSynonyms(n.selectNodes(".//SYNONYM")
.stream()
.map(ns -> ns.valueOf("@term"))
.map(ns -> new Synonym(ns.valueOf("@term"), ns.valueOf("@encoding")))
.sorted()
.distinct()
.toArray(String[]::new));
.toArray(Synonym[]::new));
vocabularyTermRepository.save(term);
}

View File

@ -26,6 +26,7 @@ app.controller('vocabularyController', function($scope, $http, $location) {
$scope.tmpTerm = {
'code' : '',
'name' : '',
'encoding' : 'OPENAIRE',
'synonyms' : []
};
}

View File

@ -89,7 +89,7 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-sm btn-primary" data-dismiss="modal" ng-click="saveVocabulary(tmpVoc)">Submit</button>
<button type="submit" class="btn btn-sm btn-primary" data-dismiss="modal" ng-click="saveVocabulary(tmpVoc)" ng-disabled="!tmpVoc.id || !tmpVoc.name">Submit</button>
</div>
</div>
</div>

View File

@ -49,8 +49,9 @@
<table class="table table-sm table-striped">
<thead>
<tr>
<th style="width: 25%">Code</th>
<th style="width: 25%">Name</th>
<th style="width: 20%">Code</th>
<th style="width: 20%">Name</th>
<th style="width: 10%">Encoding</th>
<th style="width: 40%">Synonyms</th>
<th></th>
</tr>
@ -62,9 +63,10 @@
<tr ng-repeat="t in terms|filter:termFilter">
<th>{{t.code}}</th>
<td>{{t.name}}</td>
<td><span class="badge badge-warning">{{t.encoding}}</span></td>
<td>
<span class="text-muted" ng-show="t.synonyms.length == 0">0 synonym(s)</span>
<span class="badge badge-primary mr-1" ng-repeat="s in t.synonyms">{{s}}</span>
<span class="badge badge-primary mr-1" ng-repeat="s in t.synonyms">{{s.term}}</span>
</td>
<td align="right">
<button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#editVocabularyTermModal" ng-click="prepareEditTerm(t)" >edit</button>
@ -97,11 +99,51 @@
<label>Name</label>
<input type="text" class="form-control" ng-model="tmpTerm.name" />
</div>
<div class="form-group">
<label>Encoding</label>
<input type="text" class="form-control" ng-model="tmpTerm.encoding" />
</div>
<div class="form-group">
<table class="table table-sm table-striped">
<thead>
<tr>
<th>Synonym</th>
<th>Encoding</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-show="tmpTerm.synonyms.length == 0">
<td colspan="3">0 synonym(s)</td>
</tr>
<tr ng-repeat="s in tmpTerm.synonyms">
<td>{{s.term}}</td>
<td>{{s.encoding}}</td>
<td align="right"><button class="btn btn-sm btn-danger" type="button" ng-click="tmpTerm.synonyms.splice($index, 1)"><i class="fa fa-trash"></i></button></td>
</tr>
</tbody>
<tfoot>
<tr ng-init="newSynomym=newEncoding=''">
<td><input type="text" class="form-control form-control-sm" placeholder="new synomym..." ng-model="newSynomym" /></td>
<td><input type="text" class="form-control form-control-sm" placeholder="encoding..." ng-model="newEncoding" /></td>
<td align="right">
<button type="button" class="btn btn-sm btn-outline-success"
ng-click="tmpTerm.synonyms.push({'term': newSynomym, 'encoding': newEncoding}); newSynomym=newEncoding=''"
ng-disabled="!newSynomym">
<i class="fa fa-plus"></i>
</button>
</td>
</tr>
</tfoot>
</table>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-sm btn-primary" data-dismiss="modal" ng-click="saveTerm(tmpTerm)">Submit</button>
<button type="submit" class="btn btn-sm btn-primary" data-dismiss="modal" ng-click="saveTerm(tmpTerm)" ng-disabled="newSynomym || !tmpTerm.code || !tmpTerm.name">Submit</button>
</div>
</div>
</div>

View File

@ -0,0 +1,62 @@
package eu.dnetlib.is.vocabulary.model;
import java.io.Serializable;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
public class Synonym implements Serializable, Comparable<Synonym> {
private static final long serialVersionUID = 194743347016156197L;
public Synonym() {}
public Synonym(final String term, final String encoding) {
this.term = term;
this.encoding = encoding;
}
private String term;
private String encoding;
public String getTerm() {
return term;
}
public void setTerm(final String term) {
this.term = term;
}
public String getEncoding() {
return encoding;
}
public void setEncoding(final String encoding) {
this.encoding = encoding;
}
@Override
public int hashCode() {
return Objects.hash(encoding, term);
}
@Override
public boolean equals(final Object obj) {
if (this == obj) { return true; }
if (!(obj instanceof Synonym)) { return false; }
final Synonym other = (Synonym) obj;
return Objects.equals(encoding, other.encoding) && Objects.equals(term, other.term);
}
@Override
public String toString() {
return String.format("Synonym [term=%s, encoding=%s]", term, encoding);
}
@Override
public int compareTo(final Synonym o) {
return StringUtils.compare(term, o.getTerm());
}
}

View File

@ -12,13 +12,15 @@ import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import com.vladmihalcea.hibernate.type.array.StringArrayType;
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
@Entity
@Table(name = "vocabulary_terms")
@IdClass(VocabularyTermPK.class)
@TypeDefs({
@TypeDef(name = "string-array", typeClass = StringArrayType.class)
@TypeDef(name = "json", typeClass = JsonStringType.class),
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
public class VocabularyTerm implements Serializable {
@ -35,9 +37,12 @@ public class VocabularyTerm implements Serializable {
@Column(name = "name")
private String name;
@Type(type = "string-array")
@Column(name = "synonyms", columnDefinition = "text[]")
private String[] synonyms;
@Column(name = "encoding")
private String encoding;
@Type(type = "jsonb")
@Column(name = "synonyms", columnDefinition = "jsonb")
private Synonym[] synonyms;
public String getCode() {
return code;
@ -63,11 +68,19 @@ public class VocabularyTerm implements Serializable {
this.name = name;
}
public String[] getSynonyms() {
public String getEncoding() {
return encoding;
}
public void setEncoding(final String encoding) {
this.encoding = encoding;
}
public Synonym[] getSynonyms() {
return synonyms;
}
public void setSynonyms(final String[] synonyms) {
public void setSynonyms(final Synonym[] synonyms) {
this.synonyms = synonyms;
}

View File

@ -1,5 +1,5 @@
CREATE TABLE vocabularies (
id text PRIMARY KEY,
id text PRIMARY KEY,
name text NOT NULL,
description text
);
@ -8,7 +8,8 @@ CREATE TABLE vocabulary_terms (
vocabulary text NOT NULL REFERENCES vocabularies(id),
code text NOT NULL,
name text NOT NULL,
synonyms text[],
encoding text DEFAULT 'OPENAIRE',
synonyms jsonb,
PRIMARY KEY (vocabulary, code)
);