add encoding property to terms and synonyms
This commit is contained in:
parent
d69bf62b5f
commit
9c7656e618
|
@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import eu.dnetlib.common.controller.AbstractDnetController;
|
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.Vocabulary;
|
||||||
import eu.dnetlib.is.vocabulary.model.VocabularyTerm;
|
import eu.dnetlib.is.vocabulary.model.VocabularyTerm;
|
||||||
import eu.dnetlib.is.vocabulary.model.VocabularyTermPK;
|
import eu.dnetlib.is.vocabulary.model.VocabularyTermPK;
|
||||||
|
@ -98,12 +99,13 @@ public class VocabularyRestController extends AbstractDnetController {
|
||||||
term.setVocabulary(vocId);
|
term.setVocabulary(vocId);
|
||||||
term.setCode(n.valueOf("@code"));
|
term.setCode(n.valueOf("@code"));
|
||||||
term.setName(n.valueOf("@english_name"));
|
term.setName(n.valueOf("@english_name"));
|
||||||
|
term.setEncoding(n.valueOf("@encoding"));
|
||||||
term.setSynonyms(n.selectNodes(".//SYNONYM")
|
term.setSynonyms(n.selectNodes(".//SYNONYM")
|
||||||
.stream()
|
.stream()
|
||||||
.map(ns -> ns.valueOf("@term"))
|
.map(ns -> new Synonym(ns.valueOf("@term"), ns.valueOf("@encoding")))
|
||||||
.sorted()
|
.sorted()
|
||||||
.distinct()
|
.distinct()
|
||||||
.toArray(String[]::new));
|
.toArray(Synonym[]::new));
|
||||||
|
|
||||||
vocabularyTermRepository.save(term);
|
vocabularyTermRepository.save(term);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ app.controller('vocabularyController', function($scope, $http, $location) {
|
||||||
$scope.tmpTerm = {
|
$scope.tmpTerm = {
|
||||||
'code' : '',
|
'code' : '',
|
||||||
'name' : '',
|
'name' : '',
|
||||||
|
'encoding' : 'OPENAIRE',
|
||||||
'synonyms' : []
|
'synonyms' : []
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">Close</button>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -49,8 +49,9 @@
|
||||||
<table class="table table-sm table-striped">
|
<table class="table table-sm table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th style="width: 25%">Code</th>
|
<th style="width: 20%">Code</th>
|
||||||
<th style="width: 25%">Name</th>
|
<th style="width: 20%">Name</th>
|
||||||
|
<th style="width: 10%">Encoding</th>
|
||||||
<th style="width: 40%">Synonyms</th>
|
<th style="width: 40%">Synonyms</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -62,9 +63,10 @@
|
||||||
<tr ng-repeat="t in terms|filter:termFilter">
|
<tr ng-repeat="t in terms|filter:termFilter">
|
||||||
<th>{{t.code}}</th>
|
<th>{{t.code}}</th>
|
||||||
<td>{{t.name}}</td>
|
<td>{{t.name}}</td>
|
||||||
|
<td><span class="badge badge-warning">{{t.encoding}}</span></td>
|
||||||
<td>
|
<td>
|
||||||
<span class="text-muted" ng-show="t.synonyms.length == 0">0 synonym(s)</span>
|
<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>
|
||||||
<td align="right">
|
<td align="right">
|
||||||
<button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#editVocabularyTermModal" ng-click="prepareEditTerm(t)" >edit</button>
|
<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>
|
<label>Name</label>
|
||||||
<input type="text" class="form-control" ng-model="tmpTerm.name" />
|
<input type="text" class="form-control" ng-model="tmpTerm.name" />
|
||||||
</div>
|
</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>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">Close</button>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -12,13 +12,15 @@ import org.hibernate.annotations.Type;
|
||||||
import org.hibernate.annotations.TypeDef;
|
import org.hibernate.annotations.TypeDef;
|
||||||
import org.hibernate.annotations.TypeDefs;
|
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
|
@Entity
|
||||||
@Table(name = "vocabulary_terms")
|
@Table(name = "vocabulary_terms")
|
||||||
@IdClass(VocabularyTermPK.class)
|
@IdClass(VocabularyTermPK.class)
|
||||||
@TypeDefs({
|
@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 {
|
public class VocabularyTerm implements Serializable {
|
||||||
|
|
||||||
|
@ -35,9 +37,12 @@ public class VocabularyTerm implements Serializable {
|
||||||
@Column(name = "name")
|
@Column(name = "name")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Type(type = "string-array")
|
@Column(name = "encoding")
|
||||||
@Column(name = "synonyms", columnDefinition = "text[]")
|
private String encoding;
|
||||||
private String[] synonyms;
|
|
||||||
|
@Type(type = "jsonb")
|
||||||
|
@Column(name = "synonyms", columnDefinition = "jsonb")
|
||||||
|
private Synonym[] synonyms;
|
||||||
|
|
||||||
public String getCode() {
|
public String getCode() {
|
||||||
return code;
|
return code;
|
||||||
|
@ -63,11 +68,19 @@ public class VocabularyTerm implements Serializable {
|
||||||
this.name = name;
|
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;
|
return synonyms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSynonyms(final String[] synonyms) {
|
public void setSynonyms(final Synonym[] synonyms) {
|
||||||
this.synonyms = synonyms;
|
this.synonyms = synonyms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
CREATE TABLE vocabularies (
|
CREATE TABLE vocabularies (
|
||||||
id text PRIMARY KEY,
|
id text PRIMARY KEY,
|
||||||
name text NOT NULL,
|
name text NOT NULL,
|
||||||
description text
|
description text
|
||||||
);
|
);
|
||||||
|
@ -8,7 +8,8 @@ CREATE TABLE vocabulary_terms (
|
||||||
vocabulary text NOT NULL REFERENCES vocabularies(id),
|
vocabulary text NOT NULL REFERENCES vocabularies(id),
|
||||||
code text NOT NULL,
|
code text NOT NULL,
|
||||||
name text NOT NULL,
|
name text NOT NULL,
|
||||||
synonyms text[],
|
encoding text DEFAULT 'OPENAIRE',
|
||||||
|
synonyms jsonb,
|
||||||
PRIMARY KEY (vocabulary, code)
|
PRIMARY KEY (vocabulary, code)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue