diff --git a/dhp-applications/dhp-mdstore-manager-app/pom.xml b/dhp-applications/dhp-mdstore-manager-app/pom.xml new file mode 100644 index 0000000000..066b33981e --- /dev/null +++ b/dhp-applications/dhp-mdstore-manager-app/pom.xml @@ -0,0 +1,92 @@ + + + 4.0.0 + eu.dnetlib + dhp-mdstore-manager-app + 1.1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-parent + 2.1.3.RELEASE + + + + + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-json + + + org.postgresql + postgresql + + + com.vladmihalcea + hibernate-types-52 + 2.3.5 + + + commons-io + commons-io + 2.6 + + + + + io.springfox + springfox-swagger2 + 2.9.2 + + + + io.springfox + springfox-swagger-ui + 2.9.2 + + + + + junit + junit + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + diff --git a/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/MainApplication.java b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/MainApplication.java new file mode 100644 index 0000000000..f23b3529b5 --- /dev/null +++ b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/MainApplication.java @@ -0,0 +1,49 @@ +package eu.dnetlib.data.mdstore.manager; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; + +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@SpringBootApplication +@EnableSwagger2 +@EnableCaching +public class MainApplication { + + private static final Logger log = LoggerFactory.getLogger(MainApplication.class); + + public static void main(final String[] args) { + SpringApplication.run(MainApplication.class, args); + } + + @Bean + public static Docket newSwaggerDocket() { + log.info("Initializing SWAGGER..."); + + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(p -> p.startsWith("/api/")) + .build().apiInfo(new ApiInfoBuilder() + .title("MDStore Manager APIs") + .description("APIs documentation") + .version("1.1") + .contact(ApiInfo.DEFAULT_CONTACT) + .license("Apache 2.0") + .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0") + .build()); + + } + + +} diff --git a/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/SwaggerController.java b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/SwaggerController.java new file mode 100644 index 0000000000..b6cfb7dc3d --- /dev/null +++ b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/SwaggerController.java @@ -0,0 +1,14 @@ +package eu.dnetlib.data.mdstore.manager; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +@Controller +public class SwaggerController { + + @RequestMapping(value = { "/", "/apidoc", "/api-doc", "/doc", "/swagger" }, method = RequestMethod.GET) + public String apiDoc() { + return "redirect:swagger-ui.html"; + } +} diff --git a/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/controller/MDStoreController.java b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/controller/MDStoreController.java new file mode 100644 index 0000000000..8954843d07 --- /dev/null +++ b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/controller/MDStoreController.java @@ -0,0 +1,61 @@ +package eu.dnetlib.data.mdstore.manager.controller; + +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import eu.dnetlib.data.mdstore.manager.model.MDStore; +import eu.dnetlib.data.mdstore.manager.repository.MDStoreRepository; + +@RestController +@RequestMapping("/api/mdstores") +public class MDStoreController { + + @Autowired + private MDStoreRepository repo; + + @RequestMapping(value = "/", method = RequestMethod.GET) + public final List find() { + return repo.findAll(); + } + + @RequestMapping(value = "/identifiers", method = RequestMethod.GET) + public final List findIdentifiers() { + return repo.findAll().stream().map(MDStore::getId).collect(Collectors.toList()); + } + + @RequestMapping(value = "/{id}", method = RequestMethod.GET) + public final MDStore get(@PathVariable final String id) { + return repo.findById(id).orElse(null); + } + + @RequestMapping(value = "/count", method = RequestMethod.GET) + public final long count() { + return repo.count(); + } + + @RequestMapping(value = "/", method = RequestMethod.PUT) + public final void save(@RequestBody final MDStore entity) { + repo.save(entity); + } + + @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) + public void delete(@PathVariable final String id) { + repo.deleteById(id); + } + + @RequestMapping(value = "/{id}", method = RequestMethod.POST) + public void update(@PathVariable final String id, @RequestBody final MDStore entity) { + if (repo.existsById(id)) { + entity.setId(id); + repo.save(entity); + } + } + +} diff --git a/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/controller/TransactionController.java b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/controller/TransactionController.java new file mode 100644 index 0000000000..d4ae4b1d52 --- /dev/null +++ b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/controller/TransactionController.java @@ -0,0 +1,41 @@ +package eu.dnetlib.data.mdstore.manager.controller; + +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import eu.dnetlib.data.mdstore.manager.model.Transaction; +import eu.dnetlib.data.mdstore.manager.repository.TransactionRepository; + +@RestController +@RequestMapping("/api/transactions") +public class TransactionController { + + @Autowired + private TransactionRepository repo; + + @RequestMapping(value = "/", method = RequestMethod.GET) + public final List find() { + return repo.findAll(); + } + + @RequestMapping(value = "/identifiers", method = RequestMethod.GET) + public final List findIdentifiers() { + return repo.findAll().stream().map(Transaction::getId).collect(Collectors.toList()); + } + + @RequestMapping(value = "/{id}", method = RequestMethod.GET) + public final Transaction get(@PathVariable final String id) { + return repo.findById(id).orElse(null); + } + + @RequestMapping(value = "/count", method = RequestMethod.GET) + public final long count() { + return repo.count(); + } +} diff --git a/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/model/MDStore.java b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/model/MDStore.java new file mode 100644 index 0000000000..ff4508b40c --- /dev/null +++ b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/model/MDStore.java @@ -0,0 +1,92 @@ +package eu.dnetlib.data.mdstore.manager.model; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "mdstores") +public class MDStore implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 3160530489149700055L; + + @Id + @Column(name = "id") + private String id; + + @Column(name = "format") + private String format; + + @Column(name = "layout") + private String layout; + + + @Column(name = "interpretation") + private String interpretation; + + @Column(name = "datasource_id") + private String datasourceId; + + @Column(name = "api_id") + private String apiId ; + + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getFormat() { + return format; + } + + public void setFormat(String format) { + this.format = format; + } + + public String getLayout() { + return layout; + } + + public void setLayout(String layout) { + this.layout = layout; + } + + public String getInterpretation() { + return interpretation; + } + + public void setInterpretation(String interpretation) { + this.interpretation = interpretation; + } + + public String getDatasourceId() { + return datasourceId; + } + + public void setDatasourceId(String datasourceId) { + this.datasourceId = datasourceId; + } + + public String getApiId() { + return apiId; + } + + public void setApiId(String apiId) { + this.apiId = apiId; + } + + + + + +} diff --git a/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/model/Transaction.java b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/model/Transaction.java new file mode 100644 index 0000000000..c24a1e0f26 --- /dev/null +++ b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/model/Transaction.java @@ -0,0 +1,79 @@ +package eu.dnetlib.data.mdstore.manager.model; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Table(name = "transactions") +public class Transaction implements Serializable{ + /** + * + */ + private static final long serialVersionUID = -4763494442274298339L; + + @Id + @Column(name = "id") + private String id; + + @Column(name = "mdstore") + private String mdstore; + + @Column(name = "active") + private boolean active; + + @Column(name = "lastupdate") + @Temporal(TemporalType.TIMESTAMP) + private Date lastUpdate; + + @Column(name = "size") + private int size; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getMdstore() { + return mdstore; + } + + public void setMdstore(String mdstore) { + this.mdstore = mdstore; + } + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public Date getLastUpdate() { + return lastUpdate; + } + + public void setLastUpdate(Date lastUpdate) { + this.lastUpdate = lastUpdate; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + +} diff --git a/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/repository/MDStoreRepository.java b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/repository/MDStoreRepository.java new file mode 100644 index 0000000000..ab499a3a1d --- /dev/null +++ b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/repository/MDStoreRepository.java @@ -0,0 +1,11 @@ +package eu.dnetlib.data.mdstore.manager.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import eu.dnetlib.data.mdstore.manager.model.MDStore; + +@Repository +public interface MDStoreRepository extends JpaRepository { + +} diff --git a/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/repository/TransactionRepository.java b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/repository/TransactionRepository.java new file mode 100644 index 0000000000..24fcc70059 --- /dev/null +++ b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/repository/TransactionRepository.java @@ -0,0 +1,11 @@ +package eu.dnetlib.data.mdstore.manager.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import eu.dnetlib.data.mdstore.manager.model.Transaction; + +@Repository +public interface TransactionRepository extends JpaRepository { + +} diff --git a/dhp-applications/dhp-mdstore-manager-app/src/main/resources/application.properties b/dhp-applications/dhp-mdstore-manager-app/src/main/resources/application.properties new file mode 100644 index 0000000000..e72d78cc83 --- /dev/null +++ b/dhp-applications/dhp-mdstore-manager-app/src/main/resources/application.properties @@ -0,0 +1,14 @@ +spring.main.banner-mode = console +logging.level.root = INFO + +spring.datasource.url=jdbc:postgresql://localhost:5432/mdstoremanager +spring.datasource.username= +spring.datasource.password= + +spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect + +# Hibernate ddl auto (create, create-drop, validate, update) +spring.jpa.hibernate.ddl-auto = validate +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 diff --git a/dhp-applications/dhp-mdstore-manager-app/src/main/resources/schema.sql b/dhp-applications/dhp-mdstore-manager-app/src/main/resources/schema.sql new file mode 100644 index 0000000000..865f8ad064 --- /dev/null +++ b/dhp-applications/dhp-mdstore-manager-app/src/main/resources/schema.sql @@ -0,0 +1,16 @@ +CREATE TABLE mdstores ( + id text PRIMARY KEY, + format text, + layout text, + interpretation text, + datasource_id text, + api_id text +); + +CREATE TABLE transactions ( + id text PRIMARY KEY, + mdstore text REFERENCES mdstores(id), + active boolean, + lastupdate timestamp, + size int +); diff --git a/dhp-applications/pom.xml b/dhp-applications/pom.xml new file mode 100644 index 0000000000..51d4047ac9 --- /dev/null +++ b/dhp-applications/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + eu.dnetlib.dhp + dhp + 1.0.0-SNAPSHOT + + dhp-applications + pom + + dhp-mdstore-manager-app + + +