first methods
This commit is contained in:
parent
a17a7dc3a0
commit
0d722526c0
|
@ -24,29 +24,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-json</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- JAXB API, java.xml.bind module -->
|
||||
<dependency>
|
||||
<groupId>jakarta.xml.bind</groupId>
|
||||
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- JAXB Runtime, com.sun.xml.bind module -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jaxb</groupId>
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
<groupId>jaxen</groupId>
|
||||
<artifactId>jaxen</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- hot swapping, disable cache for template, enable live reload -->
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package eu.dnetlib.organizations;
|
||||
package eu.dnetlib.is;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
@ -28,7 +28,7 @@ public class MainApplication extends AbstractDnetApp {
|
|||
protected void configSwagger(final Docket docket) {
|
||||
docket.select()
|
||||
.apis(RequestHandlerSelectors.any())
|
||||
.paths(p -> p.contains("/is/"))
|
||||
.paths(p -> p.contains("/api/"))
|
||||
.build()
|
||||
.apiInfo(new ApiInfoBuilder()
|
||||
.title("D-Net Information Service APIs")
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package eu.dnetlib.is;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class SwaggerController {
|
||||
|
||||
@GetMapping({
|
||||
"/doc", "/swagger"
|
||||
})
|
||||
public String apiDoc() {
|
||||
return "redirect:swagger-ui/";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
package eu.dnetlib.is.vocabulary;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
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.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.web.bind.annotation.DeleteMapping;
|
||||
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.common.controller.AbstractDnetController;
|
||||
import eu.dnetlib.is.vocabulary.model.Vocabulary;
|
||||
import eu.dnetlib.is.vocabulary.model.VocabularyTerm;
|
||||
import eu.dnetlib.is.vocabulary.repository.VocabularyRepository;
|
||||
import eu.dnetlib.is.vocabulary.repository.VocabularyTermRepository;
|
||||
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/vocs")
|
||||
public class VocabularyRestController extends AbstractDnetController {
|
||||
|
||||
@Autowired
|
||||
private VocabularyRepository vocabularyRepository;
|
||||
|
||||
@Autowired
|
||||
private VocabularyTermRepository vocabularyTermRepository;
|
||||
|
||||
@GetMapping("/")
|
||||
public List<Vocabulary> listVocs() {
|
||||
return vocabularyRepository.findAll()
|
||||
.stream()
|
||||
.sorted((v1, v2) -> StringUtils.compare(v1.getName(), v2.getName()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@GetMapping("/{vocabulary}")
|
||||
public Iterable<VocabularyTerm> listVocs(@PathVariable final String vocabulary) {
|
||||
return vocabularyTermRepository.findByVocabularyOrderByCode(vocabulary);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{vocabulary}")
|
||||
public List<Vocabulary> deleteVocs(@PathVariable final String vocabulary) {
|
||||
vocabularyRepository.deleteById(vocabulary);
|
||||
return listVocs();
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
public List<Vocabulary> saveVoc(@RequestBody final Vocabulary voc) {
|
||||
vocabularyRepository.save(voc);
|
||||
return listVocs();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/load", consumes = "text/plain")
|
||||
public Vocabulary loadFromOldProfile(final HttpServletRequest request) throws DocumentException, IOException {
|
||||
|
||||
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));
|
||||
|
||||
final Vocabulary voc = new Vocabulary();
|
||||
final String vocId = doc.valueOf("//VOCABULARY_NAME/@code");
|
||||
final String vocName = doc.valueOf("//VOCABULARY_NAME");
|
||||
final String vocDesc = doc.valueOf("//VOCABULARY_DESCRIPTION");
|
||||
|
||||
voc.setId(vocId);
|
||||
voc.setName(vocName);
|
||||
voc.setDescription(vocDesc);
|
||||
|
||||
vocabularyRepository.save(voc);
|
||||
|
||||
for (final Node n : doc.selectNodes("//TERM")) {
|
||||
final VocabularyTerm term = new VocabularyTerm();
|
||||
term.setVocabulary(vocId);
|
||||
term.setCode(n.valueOf("@code"));
|
||||
term.setEnglishName(n.valueOf("@english_name"));
|
||||
term.setNativeName(n.valueOf("@native_name"));
|
||||
term.setSynonyms(n.selectNodes(".//SYNONYM")
|
||||
.stream()
|
||||
.map(ns -> ns.valueOf("@term"))
|
||||
.sorted()
|
||||
.distinct()
|
||||
.toArray(String[]::new));
|
||||
|
||||
vocabularyTermRepository.save(term);
|
||||
}
|
||||
|
||||
return voc;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
server.port=8280
|
||||
|
||||
spring.profiles.active=dev
|
||||
|
||||
maven.pom.path = /META-INF/maven/eu.dnetlib.dhp/dnet-is-application/effective-pom.xml
|
||||
|
||||
spring.main.banner-mode = off
|
||||
|
||||
logging.level.root = INFO
|
||||
#logging.level.org.springframework = DEBUG
|
||||
|
||||
management.endpoints.web.exposure.include = prometheus,health
|
||||
management.endpoints.web.base-path = /
|
||||
management.endpoints.web.path-mapping.prometheus = metrics
|
||||
management.endpoints.web.path-mapping.health = health
|
||||
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/new_is
|
||||
spring.datasource.username=
|
||||
spring.datasource.password=
|
||||
|
||||
# Hibernate ddl auto (create, create-drop, validate, update)
|
||||
spring.jpa.hibernate.ddl-auto = validate
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
|
||||
spring.jpa.properties.hibernate.hbm2dll.extra_physical_table_types = MATERIALIZED VIEW
|
||||
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
|
||||
spring.jpa.open-in-view=true
|
||||
spring.jpa.properties.hibernate.show_sql=false
|
||||
spring.jpa.properties.hibernate.use_sql_comments=false
|
||||
spring.jpa.properties.hibernate.format_sql=false
|
|
@ -12,12 +12,21 @@
|
|||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Gson -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<scope>provided</scope>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-json</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vladmihalcea</groupId>
|
||||
<artifactId>hibernate-types-52</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Tests -->
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package eu.dnetlib.is.vocabulary.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "vocabularies")
|
||||
public class Vocabulary implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3769069980972518780L;
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private String id;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
|
||||
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 String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(final String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package eu.dnetlib.is.vocabulary.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.hibernate.annotations.TypeDef;
|
||||
import org.hibernate.annotations.TypeDefs;
|
||||
|
||||
import com.vladmihalcea.hibernate.type.array.StringArrayType;
|
||||
|
||||
@Entity
|
||||
@Table(name = "vocabulary_terms")
|
||||
@IdClass(VocabularyTermPK.class)
|
||||
@TypeDefs({
|
||||
@TypeDef(name = "string-array", typeClass = StringArrayType.class)
|
||||
})
|
||||
public class VocabularyTerm implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3995855638130512114L;
|
||||
|
||||
@Id
|
||||
@Column(name = "code")
|
||||
private String code;
|
||||
|
||||
@Id
|
||||
@Column(name = "vocabulary")
|
||||
private String vocabulary;
|
||||
|
||||
@Column(name = "english_name")
|
||||
private String englishName;
|
||||
|
||||
@Column(name = "native_name")
|
||||
private String nativeName;
|
||||
|
||||
@Type(type = "string-array")
|
||||
@Column(name = "synonyms", columnDefinition = "text[]")
|
||||
private String[] synonyms;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(final String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getVocabulary() {
|
||||
return vocabulary;
|
||||
}
|
||||
|
||||
public void setVocabulary(final String vocabulary) {
|
||||
this.vocabulary = vocabulary;
|
||||
}
|
||||
|
||||
public String getEnglishName() {
|
||||
return englishName;
|
||||
}
|
||||
|
||||
public void setEnglishName(final String englishName) {
|
||||
this.englishName = englishName;
|
||||
}
|
||||
|
||||
public String getNativeName() {
|
||||
return nativeName;
|
||||
}
|
||||
|
||||
public void setNativeName(final String nativeName) {
|
||||
this.nativeName = nativeName;
|
||||
}
|
||||
|
||||
public String[] getSynonyms() {
|
||||
return synonyms;
|
||||
}
|
||||
|
||||
public void setSynonyms(final String[] synonyms) {
|
||||
this.synonyms = synonyms;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package eu.dnetlib.is.vocabulary.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
public class VocabularyTermPK implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7726004241883017275L;
|
||||
|
||||
private String code;
|
||||
|
||||
private String vocabulary;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(final String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getVocabulary() {
|
||||
return vocabulary;
|
||||
}
|
||||
|
||||
public void setVocabulary(final String vocabulary) {
|
||||
this.vocabulary = vocabulary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(code, vocabulary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) { return true; }
|
||||
if (!(obj instanceof VocabularyTermPK)) { return false; }
|
||||
final VocabularyTermPK other = (VocabularyTermPK) obj;
|
||||
return Objects.equals(code, other.code) && Objects.equals(vocabulary, other.vocabulary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("VocabularyTermPK [code=%s, vocabulary=%s]", code, vocabulary);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package eu.dnetlib.is.vocabulary.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import eu.dnetlib.is.vocabulary.model.Vocabulary;
|
||||
|
||||
public interface VocabularyRepository extends JpaRepository<Vocabulary, String> {
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package eu.dnetlib.is.vocabulary.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import eu.dnetlib.is.vocabulary.model.VocabularyTerm;
|
||||
import eu.dnetlib.is.vocabulary.model.VocabularyTermPK;
|
||||
|
||||
public interface VocabularyTermRepository extends JpaRepository<VocabularyTerm, VocabularyTermPK> {
|
||||
|
||||
Iterable<VocabularyTerm> findByVocabularyOrderByCode(String vocabulary);
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
CREATE TABLE vocabularies (
|
||||
id text PRIMARY KEY,
|
||||
name text NOT NULL,
|
||||
description text
|
||||
);
|
||||
|
||||
CREATE TABLE vocabulary_terms (
|
||||
code text NOT NULL,
|
||||
vocabulary text NOT NULL REFERENCES vocabularies(id),
|
||||
english_name text NOT NULL,
|
||||
native_name text NOT NULL,
|
||||
synonyms text[],
|
||||
PRIMARY KEY (code, vocabulary)
|
||||
);
|
||||
|
||||
CREATE INDEX ON vocabulary_terms (vocabulary);
|
Loading…
Reference in New Issue