This commit is contained in:
Michele Artini 2022-06-23 12:04:38 +02:00
parent 9c7656e618
commit bbcd58a353
4 changed files with 32 additions and 21 deletions

View File

@ -23,7 +23,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
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;
@ -119,13 +118,13 @@ public class VocabularyRestController extends AbstractDnetController {
} }
@PostMapping("/{vocabulary}/terms") @PostMapping("/{vocabulary}/terms")
public Iterable<VocabularyTerm> saveTerm(@PathVariable final String vocabulary, @RequestParam final VocabularyTerm term) { public Iterable<VocabularyTerm> saveTerm(@PathVariable final String vocabulary, @RequestBody final VocabularyTerm term) {
term.setVocabulary(vocabulary); term.setVocabulary(vocabulary);
vocabularyTermRepository.save(term); vocabularyTermRepository.save(term);
return vocabularyTermRepository.findByVocabularyOrderByCode(vocabulary); return vocabularyTermRepository.findByVocabularyOrderByCode(vocabulary);
} }
@DeleteMapping("/{vocabulary}/terms/{termId}") @DeleteMapping("/{vocabulary}/terms/{term}")
public Iterable<VocabularyTerm> listTerms(@PathVariable final String vocabulary, @PathVariable final String term) { public Iterable<VocabularyTerm> listTerms(@PathVariable final String vocabulary, @PathVariable final String term) {
final VocabularyTermPK pk = new VocabularyTermPK(); final VocabularyTermPK pk = new VocabularyTermPK();
pk.setCode(term); pk.setCode(term);

View File

@ -52,7 +52,7 @@ app.controller('vocabulariesController', function($scope, $http) {
$scope.deleteVocabulary = function(id) { $scope.deleteVocabulary = function(id) {
if (confirm("Are you sure ?")) { if (confirm("Are you sure ?")) {
$http.delete('./api/vocs/' + id).then(function successCallback(res) { $http.delete('./api/vocs/' + encodeURIComponent(id)).then(function successCallback(res) {
$scope.vocabularies = res.data; $scope.vocabularies = res.data;
alert("Vocabulary deleted"); alert("Vocabulary deleted");
}, function errorCallback(res) { }, function errorCallback(res) {

View File

@ -39,29 +39,41 @@ app.controller('vocabularyController', function($scope, $http, $location) {
$scope.saveTerm = function(term) { $scope.saveTerm = function(term) {
var url = './api/vocs/' + encodeURIComponent($scope.vocId) + '/terms';
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8"; $http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
alert("TO SAVE HERE - " + term.code); $http.post(url, term).then(function successCallback(res) {
if ($scope.editTermCode != '' && $scope.editTermCode != $scope.tmpTerm.code) {
//TODO var deleteUrl = './api/vocs/' + encodeURIComponent($scope.vocId) + '/terms/' + encodeURIComponent($scope.editTermCode);
$http.delete(deleteUrl).then(function successCallback(res) {
if ($scope.editTermCode != '' && $scope.editTermCode != $scope.tmpTerm.code) { $scope.terms = res.data;
$scope.callDeleteTerm($scope.editTermCode); alert("Term replaced");
} }, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
});
} else {
$scope.terms = res.data;
alert("Term saved");
}
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
});
}; };
$scope.deleteTerm = function(code) { $scope.deleteTerm = function(code) {
if (confirm("Are you sure ?")) { if (confirm("Are you sure ?")) {
$scope.callDeleteTerm(code); var url = './api/vocs/' + encodeURIComponent($scope.vocId) + '/terms/' + encodeURIComponent(code);
$http.delete(url).then(function successCallback(res) {
$scope.terms = res.data;
alert("Term deleted");
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
});
} }
}; };
$scope.callDeleteTerm = function(code) {
alert("TO DELETE HERE - " + code);
// TODO
};
$scope.reload(); $scope.reload();
}); });

View File

@ -5,7 +5,7 @@ CREATE TABLE vocabularies (
); );
CREATE TABLE vocabulary_terms ( CREATE TABLE vocabulary_terms (
vocabulary text NOT NULL REFERENCES vocabularies(id), vocabulary text NOT NULL REFERENCES vocabularies(id) ON UPDATE CASCADE ON DELETE CASCADE,
code text NOT NULL, code text NOT NULL,
name text NOT NULL, name text NOT NULL,
encoding text DEFAULT 'OPENAIRE', encoding text DEFAULT 'OPENAIRE',