This commit is contained in:
parent
a4a2489643
commit
d81a72b896
|
@ -0,0 +1,89 @@
|
|||
package eu.dnetlib.is;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
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.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import eu.dnetlib.is.context.model.Context;
|
||||
import eu.dnetlib.is.context.model.repository.ContextRepository;
|
||||
import eu.dnetlib.is.resource.model.SimpleResourceType;
|
||||
import eu.dnetlib.is.resource.repository.SimpleResourceTypeRepository;
|
||||
import eu.dnetlib.is.vocabulary.model.Vocabulary;
|
||||
import eu.dnetlib.is.vocabulary.repository.VocabularyRepository;
|
||||
import eu.dnetlib.is.wfs.WfHistoryRestController;
|
||||
|
||||
@Controller
|
||||
public class MainController {
|
||||
|
||||
@Autowired
|
||||
private ContextRepository contextRepository;
|
||||
|
||||
@Autowired
|
||||
private VocabularyRepository vocabularyRepository;
|
||||
|
||||
@Autowired
|
||||
private SimpleResourceTypeRepository simpleResourceTypeRepository;
|
||||
|
||||
@GetMapping("/main")
|
||||
public void mainPage() {}
|
||||
|
||||
@GetMapping("/contextEditor")
|
||||
public void contextEditor(@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() {}
|
||||
|
||||
@GetMapping("/vocabularyEditor")
|
||||
public void vocabularyEditor(@RequestParam final String id, final ModelMap map) {
|
||||
final Vocabulary voc = vocabularyRepository.getById(id);
|
||||
map.put("vocId", voc.getId());
|
||||
map.put("vocName", voc.getName());
|
||||
map.put("vocDesc", voc.getDescription());
|
||||
}
|
||||
|
||||
@GetMapping("/vocabularies")
|
||||
public void vocabularies() {}
|
||||
|
||||
@GetMapping("/simpleResources")
|
||||
public void simpleResources(@RequestParam final String type, final ModelMap map) {
|
||||
|
||||
System.out.println("TYPE: " + type);
|
||||
|
||||
final Optional<SimpleResourceType> restype = simpleResourceTypeRepository.findById(type);
|
||||
|
||||
System.out.println("OP TYPE: " + restype);
|
||||
System.out.println("OP TYPE: " + restype.isPresent());
|
||||
|
||||
if (restype.isPresent()) {
|
||||
map.addAttribute("type", restype.get());
|
||||
} else {
|
||||
map.addAttribute("type", new SimpleResourceType("not_present", "???", 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/wf_history")
|
||||
public void wfHistory(final ModelMap map,
|
||||
@RequestParam(required = false, defaultValue = "-1") final Long from,
|
||||
@RequestParam(required = false, defaultValue = "-1") final Long to) {
|
||||
map.put("maxNumberOfRecentWfs", WfHistoryRestController.MAX_NUMBER_OF_RECENT_WFS);
|
||||
map.put("fromDate", from);
|
||||
map.put("toDate", to);
|
||||
}
|
||||
|
||||
@ModelAttribute("resTypes")
|
||||
public Iterable<SimpleResourceType> resourceTypes() {
|
||||
return simpleResourceTypeRepository.findAll();
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
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) {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package eu.dnetlib.is.main;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class MainController {
|
||||
|
||||
@GetMapping("/main")
|
||||
public void vocabularies(final ModelMap map) {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,6 +1,29 @@
|
|||
package eu.dnetlib.is.resources;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import eu.dnetlib.is.resource.model.SimpleResource;
|
||||
import eu.dnetlib.is.resource.repository.SimpleResourceRepository;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/resources")
|
||||
public class ResourcesRestController {
|
||||
|
||||
@Autowired
|
||||
private SimpleResourceRepository simpleResourceRepository;
|
||||
|
||||
@GetMapping("/")
|
||||
public List<SimpleResource> listVocs() {
|
||||
return simpleResourceRepository.findAll()
|
||||
.stream()
|
||||
.sorted((r1, r2) -> StringUtils.compareIgnoreCase(r1.getName(), r2.getName()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
package eu.dnetlib.is.resources;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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.resource.model.SimpleResourceType;
|
||||
import eu.dnetlib.is.resource.repository.SimpleResourceTypeRepository;
|
||||
|
||||
@Controller
|
||||
public class ResourcesUIController {
|
||||
|
||||
@Autowired
|
||||
private SimpleResourceTypeRepository simpleResourceTypeRepository;
|
||||
|
||||
@GetMapping("/simpleResources")
|
||||
public void simpleResources(@RequestParam final String type, final ModelMap map) {
|
||||
map.addAttribute("type", type);
|
||||
map.addAttribute("types", simpleResourceTypeRepository.findAll()
|
||||
.stream()
|
||||
.map(SimpleResourceType::getType)
|
||||
.sorted()
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package eu.dnetlib.is.vocabulary;
|
||||
|
||||
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.vocabulary.model.Vocabulary;
|
||||
import eu.dnetlib.is.vocabulary.repository.VocabularyRepository;
|
||||
|
||||
@Controller
|
||||
public class VocabularyUIController {
|
||||
|
||||
@Autowired
|
||||
private VocabularyRepository vocabularyRepository;
|
||||
|
||||
@GetMapping("/vocabularyEditor")
|
||||
public void vocabularyEditor(@RequestParam final String id, final ModelMap map) {
|
||||
final Vocabulary voc = vocabularyRepository.getById(id);
|
||||
|
||||
map.put("vocId", voc.getId());
|
||||
map.put("vocName", voc.getName());
|
||||
map.put("vocDesc", voc.getDescription());
|
||||
}
|
||||
|
||||
@GetMapping("/vocabularies")
|
||||
public void vocabularies(final ModelMap map) {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package eu.dnetlib.is.wfs;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@Controller
|
||||
public class WfHistoryController {
|
||||
|
||||
@GetMapping("/wf_history")
|
||||
public void wfHistory(final ModelMap map,
|
||||
@RequestParam(required = false, defaultValue = "-1") final Long from,
|
||||
@RequestParam(required = false, defaultValue = "-1") final Long to) {
|
||||
map.put("maxNumberOfRecentWfs", WfHistoryRestController.MAX_NUMBER_OF_RECENT_WFS);
|
||||
map.put("fromDate", from);
|
||||
map.put("toDate", to);
|
||||
}
|
||||
}
|
|
@ -33,8 +33,13 @@
|
|||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="./vocabularies">Vocabularies</a>
|
||||
<a class="dropdown-item" href="./contexts">Contexts</a>
|
||||
<a class="dropdown-item" href="./simpleResources?type=transformation_rules">Transformation rules</a>
|
||||
<a class="dropdown-item" href="./simpleResources?type=cleaning_rules">Cleaning rules</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a th:each="t: ${resTypes}"
|
||||
class="dropdown-item"
|
||||
th:href="@{'./simpleResources?type=' + ${t.id}}">
|
||||
<span th:text="${t.name}"></span>
|
||||
<span th:text="${t.count}" class="badge badge-primary"></span>
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head th:replace="fragments/mainParts.html :: htmlHeader('Resources: ' + ${type})"></head>
|
||||
<head th:replace="fragments/mainParts.html :: htmlHeader('Resources: ' + ${type.name})"></head>
|
||||
|
||||
<body ng-app="resourcesApp" ng-controller="resourcesController">
|
||||
|
||||
<nav th:replace="fragments/mainParts.html :: mainMenu('Resources: ' + ${type})"></nav>
|
||||
<nav th:replace="fragments/mainParts.html :: mainMenu('Resources: ' + ${type.name})"></nav>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
|
@ -63,7 +63,7 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<label>Type</label>
|
||||
<input type="text" readonly class="form-control-plaintext" th-value="${type}" />
|
||||
<input type="text" readonly class="form-control-plaintext" th-value="${type.id}" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package eu.dnetlib.is.common;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
||||
@NoRepositoryBean
|
||||
public interface ReadOnlyRepository<T, ID> extends Repository<T, ID> {
|
||||
|
||||
Optional<T> findById(ID id);
|
||||
|
||||
boolean existsById(ID id);
|
||||
|
||||
Page<T> findAll(Pageable pageable);
|
||||
|
||||
Iterable<T> findAll();
|
||||
|
||||
long count();
|
||||
}
|
|
@ -8,20 +8,51 @@ import javax.persistence.Id;
|
|||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "resource_types")
|
||||
@Table(name = "resource_types_view")
|
||||
public class SimpleResourceType implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -152368127918595773L;
|
||||
|
||||
@Id
|
||||
@Column(name = "type")
|
||||
private String type;
|
||||
@Column(name = "id")
|
||||
private String id;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@Column(name = "count")
|
||||
private long count;
|
||||
|
||||
public SimpleResourceType() {}
|
||||
|
||||
public SimpleResourceType(final String id, final String name, final long count) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public void setType(final String type) {
|
||||
this.type = type;
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(final long count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package eu.dnetlib.is.resource.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import eu.dnetlib.is.common.ReadOnlyRepository;
|
||||
import eu.dnetlib.is.resource.model.SimpleResourceType;
|
||||
|
||||
public interface SimpleResourceTypeRepository extends JpaRepository<SimpleResourceType, String> {
|
||||
public interface SimpleResourceTypeRepository extends ReadOnlyRepository<SimpleResourceType, String> {
|
||||
|
||||
}
|
||||
|
|
|
@ -80,15 +80,25 @@ CREATE TABLE wf_history (
|
|||
|
||||
-- Other Resources
|
||||
|
||||
CREATE TABLE resource_types(type text PRIMARY KEY);
|
||||
INSERT INTO resource_types(type) VALUES ('transformation_rule'), ('cleaning_rule');
|
||||
CREATE TABLE resource_types(id text PRIMARY KEY, name text);
|
||||
INSERT INTO resource_types(id, name) VALUES ('transformation_rule', 'Transformation Rules'), ('cleaning_rule', 'Cleaning Rules');
|
||||
|
||||
CREATE TABLE resources (
|
||||
id text PRIMARY KEY,
|
||||
name text NOT NULL,
|
||||
description text,
|
||||
content_type text NOT NULL,
|
||||
content text NOT NULL,
|
||||
type text NOT NULL REFERENCES resource_types(type),
|
||||
type text NOT NULL REFERENCES resource_types(id),
|
||||
creation_date timestamp NOT NULL DEFAULT now(),
|
||||
modification_date timestamp NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE VIEW resource_types_view AS SELECT
|
||||
t.id AS id,
|
||||
t.name AS name,
|
||||
count(r.id) AS count
|
||||
FROM resource_types t
|
||||
LEFT OUTER JOIN resources r ON (r.type = t.id)
|
||||
GROUP BY t.id, t.name
|
||||
ORDER BY t.name;
|
||||
|
|
Loading…
Reference in New Issue