contexts
This commit is contained in:
parent
d7779b364a
commit
154b27b0bb
|
@ -0,0 +1,125 @@
|
|||
package eu.dnetlib.is.context;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.Node;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import eu.dnetlib.is.context.model.Category;
|
||||
import eu.dnetlib.is.context.model.ConceptLevel0;
|
||||
import eu.dnetlib.is.context.model.ConceptLevel1;
|
||||
import eu.dnetlib.is.context.model.ConceptLevel2;
|
||||
import eu.dnetlib.is.context.model.Context;
|
||||
import eu.dnetlib.is.context.model.CtxInfo;
|
||||
import eu.dnetlib.is.context.model.CtxInfoWithClaim;
|
||||
import eu.dnetlib.is.context.model.Parameter;
|
||||
import eu.dnetlib.is.context.model.repository.CategoryRepository;
|
||||
import eu.dnetlib.is.context.model.repository.ConceptLevel0Repository;
|
||||
import eu.dnetlib.is.context.model.repository.ConceptLevel1Repository;
|
||||
import eu.dnetlib.is.context.model.repository.ConceptLevel2Repository;
|
||||
import eu.dnetlib.is.context.model.repository.ContextRepository;
|
||||
|
||||
@Component
|
||||
public class ContextImporter {
|
||||
|
||||
@Autowired
|
||||
private ContextRepository contextRepository;
|
||||
@Autowired
|
||||
private CategoryRepository categoryRepository;
|
||||
@Autowired
|
||||
private ConceptLevel0Repository conceptLevel0Repository;
|
||||
@Autowired
|
||||
private ConceptLevel1Repository conceptLevel1Repository;
|
||||
@Autowired
|
||||
private ConceptLevel2Repository conceptLevel2Repository;
|
||||
|
||||
private static final Log log = LogFactory.getLog(ContextImporter.class);
|
||||
|
||||
public void loadFromOldProfile(final String xml) throws DocumentException, IOException {
|
||||
final SAXReader reader = new SAXReader();
|
||||
final Document doc = reader.read(new StringReader(xml));
|
||||
doc.selectNodes("//context").forEach(this::saveContext);
|
||||
}
|
||||
|
||||
private void saveContext(final Node node) {
|
||||
final Context ctx = new Context();
|
||||
setCommonInfo(ctx, node);
|
||||
ctx.setType(node.valueOf("@type"));
|
||||
contextRepository.save(ctx);
|
||||
|
||||
log.info("Saved context: " + ctx.getId());
|
||||
|
||||
node.selectNodes("./category").forEach(n -> saveCategory(n, ctx.getId()));
|
||||
}
|
||||
|
||||
private void saveCategory(final Node node, final String ctxId) {
|
||||
final Category cat = new Category();
|
||||
setCommonInfo(cat, node);
|
||||
cat.setContextId(ctxId);
|
||||
|
||||
categoryRepository.save(cat);
|
||||
|
||||
log.info("- Saved category: " + cat.getId());
|
||||
|
||||
node.selectNodes("./concept").forEach(n -> saveConceptLvl0(n, ctxId, cat.getId()));
|
||||
}
|
||||
|
||||
private void saveConceptLvl0(final Node node, final String ctxId, final String catId) {
|
||||
final ConceptLevel0 c0 = new ConceptLevel0();
|
||||
setCommonInfo(c0, node);
|
||||
c0.setContextId(ctxId);
|
||||
c0.setCategoryId(catId);
|
||||
conceptLevel0Repository.save(c0);
|
||||
|
||||
log.info("-- Saved concept 0: " + c0.getId());
|
||||
|
||||
node.selectNodes("./concept").forEach(n -> saveConceptLvl1(n, ctxId, catId, c0.getId()));
|
||||
}
|
||||
|
||||
private void saveConceptLvl1(final Node node, final String ctxId, final String catId, final String c0) {
|
||||
final ConceptLevel1 c1 = new ConceptLevel1();
|
||||
setCommonInfo(c1, node);
|
||||
c1.setContextId(ctxId);
|
||||
c1.setCategoryId(catId);
|
||||
c1.setConceptLevel0Id(c0);
|
||||
conceptLevel1Repository.save(c1);
|
||||
|
||||
log.info("--- Saved concept 1: " + c1.getId());
|
||||
|
||||
node.selectNodes("./concept").forEach(n -> saveConceptLvl2(n, ctxId, catId, c0, c1.getId()));
|
||||
}
|
||||
|
||||
private void saveConceptLvl2(final Node node, final String ctxId, final String catId, final String c0, final String c1) {
|
||||
final ConceptLevel2 c2 = new ConceptLevel2();
|
||||
setCommonInfo(c2, node);
|
||||
c2.setContextId(ctxId);
|
||||
c2.setCategoryId(catId);
|
||||
c2.setConceptLevel0Id(c0);
|
||||
c2.setConceptLevel1Id(c1);
|
||||
conceptLevel2Repository.save(c2);
|
||||
|
||||
log.info("---- Saved concept 2: " + c2.getId());
|
||||
}
|
||||
|
||||
private void setCommonInfo(final CtxInfo o, final Node n) {
|
||||
o.setId(n.valueOf("@id"));
|
||||
o.setLabel(n.valueOf("@label"));
|
||||
if (o instanceof CtxInfoWithClaim) {
|
||||
((CtxInfoWithClaim) o).setClaim(BooleanUtils.toBoolean(n.valueOf("@claim")));
|
||||
}
|
||||
o.setParameters(n.selectNodes("./param")
|
||||
.stream()
|
||||
.map(np -> new Parameter(np.valueOf("@name"), np.getText()))
|
||||
.sorted()
|
||||
.toArray(Parameter[]::new));
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package eu.dnetlib.is.context;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import eu.dnetlib.is.context.model.Category;
|
||||
import eu.dnetlib.is.context.model.Context;
|
||||
import eu.dnetlib.is.context.model.repository.CategoryRepository;
|
||||
import eu.dnetlib.is.context.model.repository.ConceptLevel0Repository;
|
||||
import eu.dnetlib.is.context.model.repository.ConceptLevel1Repository;
|
||||
import eu.dnetlib.is.context.model.repository.ConceptLevel2Repository;
|
||||
import eu.dnetlib.is.context.model.repository.ContextRepository;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/contexts")
|
||||
public class ContextRestController {
|
||||
|
||||
@Autowired
|
||||
private ContextRepository contextRepository;
|
||||
@Autowired
|
||||
private CategoryRepository categoryRepository;
|
||||
@Autowired
|
||||
private ConceptLevel0Repository conceptLevel0Repository;
|
||||
@Autowired
|
||||
private ConceptLevel1Repository conceptLevel1Repository;
|
||||
@Autowired
|
||||
private ConceptLevel2Repository conceptLevel2Repository;
|
||||
|
||||
@Autowired
|
||||
private ContextImporter contextImporter;
|
||||
|
||||
private static final Log log = LogFactory.getLog(ContextRestController.class);
|
||||
|
||||
@GetMapping("/")
|
||||
public List<Context> listContexts() {
|
||||
return contextRepository.findAll()
|
||||
.stream()
|
||||
.sorted((v1, v2) -> StringUtils.compareIgnoreCase(v1.getId(), v2.getId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@GetMapping("/{ctxId}")
|
||||
public Context getContext(@PathVariable final String ctxId) {
|
||||
return contextRepository.getById(ctxId);
|
||||
}
|
||||
|
||||
@GetMapping("/{ctxId}/categories")
|
||||
public Iterable<Category> listCategories(@PathVariable final String ctxId) {
|
||||
return categoryRepository.findByContextIdOrderById(ctxId);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/load", consumes = "text/plain")
|
||||
public List<String> loadFromOldProfile(final HttpServletRequest request) throws DocumentException, IOException {
|
||||
|
||||
final String xml = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
|
||||
|
||||
contextImporter.loadFromOldProfile(xml);
|
||||
|
||||
return Arrays.asList("Done.");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package eu.dnetlib.is.context;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import eu.dnetlib.is.context.model.Context;
|
||||
import eu.dnetlib.is.context.model.repository.ContextRepository;
|
||||
|
||||
@Controller
|
||||
public class ContextUIController {
|
||||
|
||||
@Autowired
|
||||
private ContextRepository contextRepository;
|
||||
|
||||
@GetMapping("/contextEditor")
|
||||
public void vocabularyEditor(@RequestParam final String id, final ModelMap map) {
|
||||
final Context ctx = contextRepository.getById(id);
|
||||
|
||||
map.put("ctxId", ctx.getId());
|
||||
map.put("ctxLabel", ctx.getLabel());
|
||||
map.put("ctxType", ctx.getType());
|
||||
map.put("ctxParams", ctx.getParameters());
|
||||
}
|
||||
|
||||
@GetMapping("/contexts")
|
||||
public void contexts(final ModelMap map) {
|
||||
|
||||
}
|
||||
}
|
|
@ -77,8 +77,6 @@ public class VocabularyRestController extends AbstractDnetController {
|
|||
|
||||
final String xml = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
|
||||
|
||||
System.out.println(xml);
|
||||
|
||||
final SAXReader reader = new SAXReader();
|
||||
final Document doc = reader.read(new StringReader(xml));
|
||||
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
var app = angular.module('contextsApp', []);
|
||||
|
||||
app.controller('contextsController', function($scope, $http) {
|
||||
$scope.contexts = [];
|
||||
$scope.tmpCtx = {};
|
||||
$scope.mode = '';
|
||||
|
||||
$scope.reload = function() {
|
||||
$http.get('./api/contexts/?' + $.now()).then(function successCallback(res) {
|
||||
$scope.contexts = res.data;
|
||||
}, function errorCallback(res) {
|
||||
alert('ERROR: ' + res.data.message);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.prepareNewCtx = function() {
|
||||
$scope.mode = 'new';
|
||||
$scope.tmpCtx = {
|
||||
'id' : '',
|
||||
'label' : '',
|
||||
'type' : '',
|
||||
'parameters' : []
|
||||
};
|
||||
}
|
||||
|
||||
$scope.prepareEditCtx = function(ctx) {
|
||||
$scope.mode = 'edit';
|
||||
$scope.tmpCtx = angular.copy(ctx);
|
||||
}
|
||||
|
||||
$scope.saveContext = function(ctx) {
|
||||
if ($scope.mode == 'new') {
|
||||
var found = false;
|
||||
|
||||
angular.forEach($scope.contexts, function(v) {
|
||||
if (ctx.id == ctx.id) { found = true; };
|
||||
});
|
||||
|
||||
if (found) {
|
||||
alert("Insertion failed: context already exists !");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
||||
$http.post('./api/contexts/?' + $.now(), ctx).then(function successCallback(res) {
|
||||
$scope.contexts = res.data;
|
||||
alert("Context saved");
|
||||
}, function errorCallback(res) {
|
||||
alert('ERROR: ' + res.data.message);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteContext = function(id) {
|
||||
if (confirm("Are you sure ?")) {
|
||||
$http.delete('./api/contexts/' + encodeURIComponent(id) + '?' + $.now()).then(function successCallback(res) {
|
||||
$scope.contexts = res.data;
|
||||
alert("Context deleted");
|
||||
}, function errorCallback(res) {
|
||||
alert('ERROR: ' + res.data.message);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.reload();
|
||||
});
|
|
@ -0,0 +1,126 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head th:replace="fragments/mainParts.html :: htmlHeader('Contexts')"></head>
|
||||
|
||||
<body ng-app="contextsApp" ng-controller="contextsController">
|
||||
|
||||
<nav th:replace="fragments/mainParts.html :: mainMenu('Contexts')"></nav>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
|
||||
<p>
|
||||
<button class="btn btn-sm btn-primary" data-toggle="modal" data-target="#editContextModal" ng-click="prepareNewCtx()">create a new context</button>
|
||||
</p>
|
||||
<p ng-show="contexts.length > 0">
|
||||
<input type="text" class="form-control form-control-sm" ng-model="ctxFilter" placeholder="Filter..."/>
|
||||
</p>
|
||||
<p>
|
||||
<span class="text-muted"><b>Number of contexts:</b> {{(contexts | filter:ctxFilter).length}}</span>
|
||||
</p>
|
||||
<table class="table table-sm table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 20%">ID</th>
|
||||
<th style="width: 30%">Label</th>
|
||||
<th style="width: 10%">Type</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-show="(contexts|filter:ctxFilter).length == 0">
|
||||
<td colspan="4" class="text-muted">no contexts</td>
|
||||
</tr>
|
||||
<tr ng-repeat="ctx in contexts|filter:ctxFilter">
|
||||
<th><a href="contextEditor?id={{ctx.id}}">{{ctx.id}}</a></th>
|
||||
<td>{{ctx.label}}</td>
|
||||
<td>{{ctx.type}}</td>
|
||||
<td align="right">
|
||||
<button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#editContextModal" ng-click="prepareEditCtx(ctx)" >edit</button>
|
||||
<button type="button" class="btn btn-sm btn-danger" ng-click="deleteContext(ctx.id)">delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modals -->
|
||||
|
||||
<div class="modal fade" tabindex="-1" id="editContextModal">
|
||||
<div class="modal-dialog modal-xl">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" ng-if="mode == 'new'">New context</h4>
|
||||
<h4 class="modal-title" ng-if="mode == 'edit'">Edit context</h4>
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label>ID</label>
|
||||
<input ng-show="mode == 'new'" type="text" class="form-control" ng-model="tmpCtx.id" />
|
||||
<input ng-show="mode == 'edit'" type="text" readonly class="form-control-plaintext" ng-model="tmpCtx.id" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Label</label>
|
||||
<input type="text" class="form-control" ng-model="tmpCtx.label" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Type</label>
|
||||
<input type="text" class="form-control" ng-model="tmpCtx.type" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<table class="table table-sm table-striped" style="table-layout: fixed;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 20%">Parameter Name</th>
|
||||
<th style="width: 75%">Parameter Value</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-show="tmpCtx.parameters.length == 0">
|
||||
<td colspan="3">0 parameter(s)</td>
|
||||
</tr>
|
||||
<tr ng-repeat="p in tmpCtx.parameters">
|
||||
<th>{{p.name}}</th>
|
||||
<td><textarea class="form-control" ng-model="p.value"></textarea></td>
|
||||
<td align="right"><button class="btn btn-sm btn-danger" type="button" ng-click="tmpCtx.parameters.splice($index, 1)"><i class="fa fa-trash"></i></button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr ng-init="newParamName=newParamValue=''">
|
||||
<td><input type="text" class="form-control form-control-sm" placeholder="new param name..." ng-model="newParamName" /></td>
|
||||
<td><textarea class="form-control form-control-sm" placeholder="new param value..." ng-model="newParamValue"></textarea></td>
|
||||
<td align="right">
|
||||
<button type="button" class="btn btn-sm btn-outline-success"
|
||||
ng-click="tmpCtx.parameters.push({'name': newParamName, 'value': newParamValue}); newParamName=newParamValue=''"
|
||||
ng-disabled="!newParamValue || !newParamValue">
|
||||
<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="saveContext(tmpCtx)" ng-disabled="!tmpCtx.id || !tmpCtx.label || !tmpCtx.type">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
<th:block th:replace="fragments/mainParts.html :: scripts"></th:block>
|
||||
|
||||
<script src="js/contexts.js"></script>
|
||||
</html>
|
|
@ -7,7 +7,7 @@
|
|||
<link rel="stylesheet" href="common/css/fontawesome-all.min.css" />
|
||||
|
||||
<style>
|
||||
td {
|
||||
td,th {
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
label {
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package eu.dnetlib.is.context.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "context_categories")
|
||||
@IdClass(CategoryPK.class)
|
||||
public class Category extends CtxInfoWithClaim {
|
||||
|
||||
private static final long serialVersionUID = -1847175903793410585L;
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private String id;
|
||||
|
||||
@Id
|
||||
@Column(name = "ctx_id")
|
||||
private String contextId;
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContextId() {
|
||||
return contextId;
|
||||
}
|
||||
|
||||
public void setContextId(final String contextId) {
|
||||
this.contextId = contextId;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package eu.dnetlib.is.context.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CategoryPK implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2764222393730200265L;
|
||||
|
||||
private String id;
|
||||
|
||||
private String contextId;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContextId() {
|
||||
return contextId;
|
||||
}
|
||||
|
||||
public void setContextId(final String contextId) {
|
||||
this.contextId = contextId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(contextId, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) { return true; }
|
||||
if (!(obj instanceof CategoryPK)) { return false; }
|
||||
final CategoryPK other = (CategoryPK) obj;
|
||||
return Objects.equals(contextId, other.contextId) && Objects.equals(id, other.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("CategoryPK [id=%s, contextId=%s]", id, contextId);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package eu.dnetlib.is.context.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "context_cat_concepts_lvl_0")
|
||||
@IdClass(ConceptLevel0PK.class)
|
||||
public class ConceptLevel0 extends CtxInfoWithClaim {
|
||||
|
||||
private static final long serialVersionUID = -4775331902088912839L;
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private String id;
|
||||
|
||||
@Id
|
||||
@Column(name = "ctx_id")
|
||||
private String contextId;
|
||||
|
||||
@Id
|
||||
@Column(name = "cat_id")
|
||||
private String categoryId;
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContextId() {
|
||||
return contextId;
|
||||
}
|
||||
|
||||
public void setContextId(final String contextId) {
|
||||
this.contextId = contextId;
|
||||
}
|
||||
|
||||
public String getCategoryId() {
|
||||
return categoryId;
|
||||
}
|
||||
|
||||
public void setCategoryId(final String categoryId) {
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package eu.dnetlib.is.context.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ConceptLevel0PK implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -924956037443869537L;
|
||||
|
||||
private String id;
|
||||
|
||||
private String contextId;
|
||||
|
||||
private String categoryId;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContextId() {
|
||||
return contextId;
|
||||
}
|
||||
|
||||
public void setContextId(final String contextId) {
|
||||
this.contextId = contextId;
|
||||
}
|
||||
|
||||
public String getCategoryId() {
|
||||
return categoryId;
|
||||
}
|
||||
|
||||
public void setCategoryId(final String categoryId) {
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(categoryId, contextId, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) { return true; }
|
||||
if (!(obj instanceof ConceptLevel0PK)) { return false; }
|
||||
final ConceptLevel0PK other = (ConceptLevel0PK) obj;
|
||||
return Objects.equals(categoryId, other.categoryId) && Objects.equals(contextId, other.contextId) && Objects.equals(id, other.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("ConceptLevel0PK [id=%s, contextId=%s, categoryId=%s]", id, contextId, categoryId);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package eu.dnetlib.is.context.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "context_cat_concepts_lvl_1")
|
||||
@IdClass(ConceptLevel1PK.class)
|
||||
public class ConceptLevel1 extends CtxInfoWithClaim {
|
||||
|
||||
private static final long serialVersionUID = -759398689766245784L;
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private String id;
|
||||
|
||||
@Id
|
||||
@Column(name = "ctx_id")
|
||||
private String contextId;
|
||||
|
||||
@Id
|
||||
@Column(name = "cat_id")
|
||||
private String categoryId;
|
||||
|
||||
@Id
|
||||
@Column(name = "c0_id")
|
||||
private String conceptLevel0Id;
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContextId() {
|
||||
return contextId;
|
||||
}
|
||||
|
||||
public void setContextId(final String contextId) {
|
||||
this.contextId = contextId;
|
||||
}
|
||||
|
||||
public String getCategoryId() {
|
||||
return categoryId;
|
||||
}
|
||||
|
||||
public void setCategoryId(final String categoryId) {
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
|
||||
public String getConceptLevel0Id() {
|
||||
return conceptLevel0Id;
|
||||
}
|
||||
|
||||
public void setConceptLevel0Id(final String conceptLevel0Id) {
|
||||
this.conceptLevel0Id = conceptLevel0Id;
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package eu.dnetlib.is.context.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ConceptLevel1PK implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7993480292203819163L;
|
||||
|
||||
private String id;
|
||||
|
||||
private String contextId;
|
||||
|
||||
private String categoryId;
|
||||
|
||||
private String conceptLevel0Id;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContextId() {
|
||||
return contextId;
|
||||
}
|
||||
|
||||
public void setContextId(final String contextId) {
|
||||
this.contextId = contextId;
|
||||
}
|
||||
|
||||
public String getCategoryId() {
|
||||
return categoryId;
|
||||
}
|
||||
|
||||
public void setCategoryId(final String categoryId) {
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
|
||||
public String getConceptLevel0Id() {
|
||||
return conceptLevel0Id;
|
||||
}
|
||||
|
||||
public void setConceptLevel0Id(final String conceptLevel0Id) {
|
||||
this.conceptLevel0Id = conceptLevel0Id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(categoryId, conceptLevel0Id, contextId, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) { return true; }
|
||||
if (!(obj instanceof ConceptLevel1PK)) { return false; }
|
||||
final ConceptLevel1PK other = (ConceptLevel1PK) obj;
|
||||
return Objects.equals(categoryId, other.categoryId) && Objects.equals(conceptLevel0Id, other.conceptLevel0Id)
|
||||
&& Objects.equals(contextId, other.contextId) && Objects.equals(id, other.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("ConceptLevel1PK [id=%s, contextId=%s, categoryId=%s, conceptLevel0Id=%s]", id, contextId, categoryId, conceptLevel0Id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package eu.dnetlib.is.context.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "context_cat_concepts_lvl_2")
|
||||
@IdClass(ConceptLevel2PK.class)
|
||||
public class ConceptLevel2 extends CtxInfoWithClaim {
|
||||
|
||||
private static final long serialVersionUID = 906131339592862096L;
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private String id;
|
||||
|
||||
@Id
|
||||
@Column(name = "ctx_id")
|
||||
private String contextId;
|
||||
|
||||
@Id
|
||||
@Column(name = "cat_id")
|
||||
private String categoryId;
|
||||
|
||||
@Id
|
||||
@Column(name = "c0_id")
|
||||
private String conceptLevel0Id;
|
||||
|
||||
@Id
|
||||
@Column(name = "c1_id")
|
||||
private String conceptLevel1Id;
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContextId() {
|
||||
return contextId;
|
||||
}
|
||||
|
||||
public void setContextId(final String contextId) {
|
||||
this.contextId = contextId;
|
||||
}
|
||||
|
||||
public String getCategoryId() {
|
||||
return categoryId;
|
||||
}
|
||||
|
||||
public void setCategoryId(final String categoryId) {
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
|
||||
public String getConceptLevel0Id() {
|
||||
return conceptLevel0Id;
|
||||
}
|
||||
|
||||
public void setConceptLevel0Id(final String conceptLevel0Id) {
|
||||
this.conceptLevel0Id = conceptLevel0Id;
|
||||
}
|
||||
|
||||
public String getConceptLevel1Id() {
|
||||
return conceptLevel1Id;
|
||||
}
|
||||
|
||||
public void setConceptLevel1Id(final String conceptLevel1Id) {
|
||||
this.conceptLevel1Id = conceptLevel1Id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package eu.dnetlib.is.context.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ConceptLevel2PK implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5543486531261862945L;
|
||||
|
||||
private String id;
|
||||
|
||||
private String contextId;
|
||||
|
||||
private String categoryId;
|
||||
|
||||
private String conceptLevel0Id;
|
||||
|
||||
private String conceptLevel1Id;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContextId() {
|
||||
return contextId;
|
||||
}
|
||||
|
||||
public void setContextId(final String contextId) {
|
||||
this.contextId = contextId;
|
||||
}
|
||||
|
||||
public String getCategoryId() {
|
||||
return categoryId;
|
||||
}
|
||||
|
||||
public void setCategoryId(final String categoryId) {
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
|
||||
public String getConceptLevel0Id() {
|
||||
return conceptLevel0Id;
|
||||
}
|
||||
|
||||
public void setConceptLevel0Id(final String conceptLevel0Id) {
|
||||
this.conceptLevel0Id = conceptLevel0Id;
|
||||
}
|
||||
|
||||
public String getConceptLevel1Id() {
|
||||
return conceptLevel1Id;
|
||||
}
|
||||
|
||||
public void setConceptLevel1Id(final String conceptLevel1Id) {
|
||||
this.conceptLevel1Id = conceptLevel1Id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(categoryId, conceptLevel0Id, conceptLevel1Id, contextId, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) { return true; }
|
||||
if (!(obj instanceof ConceptLevel2PK)) { return false; }
|
||||
final ConceptLevel2PK other = (ConceptLevel2PK) obj;
|
||||
return Objects.equals(categoryId, other.categoryId) && Objects.equals(conceptLevel0Id, other.conceptLevel0Id)
|
||||
&& Objects.equals(conceptLevel1Id, other.conceptLevel1Id) && Objects.equals(contextId, other.contextId) && Objects.equals(id, other.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String
|
||||
.format("ConceptLevel2PK [id=%s, contextId=%s, categoryId=%s, conceptLevel0Id=%s, conceptLevel1Id=%s]", id, contextId, categoryId, conceptLevel0Id, conceptLevel1Id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package eu.dnetlib.is.context.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "contexts")
|
||||
public class Context extends CtxInfo {
|
||||
|
||||
private static final long serialVersionUID = -8290775989306039922L;
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private String id;
|
||||
|
||||
@Column(name = "type")
|
||||
private String type;
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static long getSerialversionuid() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package eu.dnetlib.is.context.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.hibernate.annotations.TypeDef;
|
||||
import org.hibernate.annotations.TypeDefs;
|
||||
|
||||
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
|
||||
import com.vladmihalcea.hibernate.type.json.JsonStringType;
|
||||
|
||||
@MappedSuperclass
|
||||
@TypeDefs({
|
||||
@TypeDef(name = "json", typeClass = JsonStringType.class),
|
||||
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
|
||||
})
|
||||
public abstract class CtxInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4912082158208138795L;
|
||||
|
||||
@Column(name = "label")
|
||||
private String label;
|
||||
|
||||
@Type(type = "jsonb")
|
||||
@Column(name = "params")
|
||||
private Parameter[] parameters;
|
||||
|
||||
abstract public String getId();
|
||||
|
||||
abstract public void setId(final String id);
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(final String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public Parameter[] getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(final Parameter[] parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package eu.dnetlib.is.context.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
@MappedSuperclass
|
||||
public abstract class CtxInfoWithClaim extends CtxInfo {
|
||||
|
||||
private static final long serialVersionUID = -9005145235908917048L;
|
||||
|
||||
@Column(name = "claim")
|
||||
private boolean claim;
|
||||
|
||||
public boolean isClaim() {
|
||||
return claim;
|
||||
}
|
||||
|
||||
public void setClaim(final boolean claim) {
|
||||
this.claim = claim;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package eu.dnetlib.is.context.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class Parameter implements Serializable, Comparable<Parameter> {
|
||||
|
||||
private static final long serialVersionUID = 925189891223642100L;
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
public Parameter() {}
|
||||
|
||||
public Parameter(final String name, final String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(final String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) { return true; }
|
||||
if (!(obj instanceof Parameter)) { return false; }
|
||||
final Parameter other = (Parameter) obj;
|
||||
return Objects.equals(name, other.name) && Objects.equals(value, other.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Parameter [name=%s, value=%s]", name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final Parameter p) {
|
||||
return StringUtils.compare(getName(), p.getName());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package eu.dnetlib.is.context.model.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import eu.dnetlib.is.context.model.Category;
|
||||
import eu.dnetlib.is.context.model.CategoryPK;
|
||||
|
||||
public interface CategoryRepository extends JpaRepository<Category, CategoryPK> {
|
||||
|
||||
Iterable<Category> findByContextIdOrderById(String contextId);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package eu.dnetlib.is.context.model.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import eu.dnetlib.is.context.model.ConceptLevel0;
|
||||
import eu.dnetlib.is.context.model.ConceptLevel0PK;
|
||||
|
||||
public interface ConceptLevel0Repository extends JpaRepository<ConceptLevel0, ConceptLevel0PK> {
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package eu.dnetlib.is.context.model.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import eu.dnetlib.is.context.model.ConceptLevel1;
|
||||
import eu.dnetlib.is.context.model.ConceptLevel1PK;
|
||||
|
||||
public interface ConceptLevel1Repository extends JpaRepository<ConceptLevel1, ConceptLevel1PK> {
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package eu.dnetlib.is.context.model.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import eu.dnetlib.is.context.model.ConceptLevel2;
|
||||
import eu.dnetlib.is.context.model.ConceptLevel2PK;
|
||||
|
||||
public interface ConceptLevel2Repository extends JpaRepository<ConceptLevel2, ConceptLevel2PK> {
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package eu.dnetlib.is.context.model.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import eu.dnetlib.is.context.model.Context;
|
||||
|
||||
public interface ContextRepository extends JpaRepository<Context, String> {
|
||||
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
-- Vocabularies
|
||||
|
||||
CREATE TABLE vocabularies (
|
||||
id text PRIMARY KEY,
|
||||
name text NOT NULL,
|
||||
|
@ -14,3 +16,63 @@ CREATE TABLE vocabulary_terms (
|
|||
);
|
||||
|
||||
CREATE INDEX ON vocabulary_terms (vocabulary);
|
||||
|
||||
-- Contexts
|
||||
|
||||
CREATE TABLE contexts (
|
||||
id text PRIMARY KEY,
|
||||
label text NOT NULL,
|
||||
type text NOT NULL,
|
||||
params jsonb
|
||||
);
|
||||
|
||||
CREATE TABLE context_categories (
|
||||
ctx_id text NOT NULL REFERENCES contexts(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
id text NOT NULL,
|
||||
label text NOT NULL,
|
||||
claim boolean NOT NULL,
|
||||
params jsonb,
|
||||
PRIMARY KEY (ctx_id, id)
|
||||
);
|
||||
|
||||
CREATE TABLE context_cat_concepts_lvl_0 (
|
||||
ctx_id text NOT NULL REFERENCES contexts(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
cat_id text NOT NULL,
|
||||
id text NOT NULL,
|
||||
label text NOT NULL,
|
||||
claim boolean NOT NULL,
|
||||
params jsonb,
|
||||
PRIMARY KEY (ctx_id, cat_id, id),
|
||||
FOREIGN KEY (ctx_id, cat_id) REFERENCES context_categories(ctx_id, id) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE context_cat_concepts_lvl_1 (
|
||||
ctx_id text NOT NULL REFERENCES contexts(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
cat_id text NOT NULL,
|
||||
c0_id text NOT NULL,
|
||||
id text NOT NULL,
|
||||
label text NOT NULL,
|
||||
claim boolean NOT NULL,
|
||||
params jsonb,
|
||||
PRIMARY KEY (ctx_id, cat_id, c0_id, id),
|
||||
FOREIGN KEY (ctx_id, cat_id, c0_id) REFERENCES context_cat_concepts_lvl_0(ctx_id, cat_id, id) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE context_cat_concepts_lvl_2 (
|
||||
ctx_id text NOT NULL REFERENCES contexts(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
cat_id text NOT NULL,
|
||||
c0_id text NOT NULL,
|
||||
c1_id text NOT NULL,
|
||||
id text NOT NULL,
|
||||
label text NOT NULL,
|
||||
claim boolean NOT NULL,
|
||||
params jsonb,
|
||||
PRIMARY KEY (ctx_id, cat_id, c0_id, c1_id, id),
|
||||
FOREIGN KEY (ctx_id, cat_id, c0_id, c1_id) REFERENCES context_cat_concepts_lvl_1(ctx_id, cat_id, c0_id, id) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX ON context_categories (ctx_id);
|
||||
CREATE INDEX ON context_cat_concepts_lvl_0 (ctx_id, cat_id);
|
||||
CREATE INDEX ON context_cat_concepts_lvl_1 (ctx_id, cat_id, c0_id);
|
||||
CREATE INDEX ON context_cat_concepts_lvl_2 (ctx_id, cat_id, c0_id, c1_id);
|
||||
|
||||
|
|
Loading…
Reference in New Issue