Skip to content
Snippets Groups Projects
Commit 1fce4a7c authored by Lukas Maruniak's avatar Lukas Maruniak
Browse files

List of references

parent 1c09cf51
No related merge requests found
...@@ -161,14 +161,37 @@ ...@@ -161,14 +161,37 @@
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>2.11.0</version> <version>2.11.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.6.0.Beta1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.6.0.Beta1</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
......
docker run --rm --gpus all --init --ulimit core=0 -p 8070:8070 grobid/grobid:0.8.1
\ No newline at end of file
package com.dre0059.articleprocessor.controller;
import com.dre0059.articleprocessor.dto.DocumentDto;
import com.dre0059.articleprocessor.dto.SimpleDocumentDto;
import com.dre0059.articleprocessor.service.DocumentService;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@Controller("api/document")
public class DocumentController {
private final DocumentService documentService;
public DocumentController(DocumentService documentService) {
this.documentService = documentService;
}
@GetMapping("/{id}")
public DocumentDto getDocumentById(@PathVariable Long id) {
return documentService.getDocumentById(id);
}
@GetMapping("/references/{id}")
public List<SimpleDocumentDto> getReferencesFromDocument(@PathVariable Long id) {
return documentService.getDocumentReferences(id);
}
@GetMapping("/view/{id}")
public String viewPdf(Model model, @PathVariable("id") Long id) {
var references = documentService.getDocumentReferences(id);
model.addAttribute("references", references);
return "view-pdf";
}
}
package com.dre0059.articleprocessor.dto;
public class DocumentDto {
private Long id;
private String title;
private Integer publicationYear;
private String doi;
private String abstractText;
private String status;
private String publisher;
private String target;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Integer getPublicationYear() {
return publicationYear;
}
public void setPublicationYear(Integer publicationYear) {
this.publicationYear = publicationYear;
}
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
public String getAbstractText() {
return abstractText;
}
public void setAbstractText(String abstractText) {
this.abstractText = abstractText;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
}
package com.dre0059.articleprocessor.dto;
public class SimpleDocumentDto {
private Long id;
private String title;
public String getLink() {
return "/api/document/"+getId();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
package com.dre0059.articleprocessor.mapper;
import com.dre0059.articleprocessor.dto.DocumentDto;
import com.dre0059.articleprocessor.dto.SimpleDocumentDto;
import com.dre0059.articleprocessor.model.Dokument;
import java.util.List;
import org.mapstruct.Mapper;
@Mapper
public interface DocumentMapper {
DocumentDto toDocumentDto(Dokument entity);
SimpleDocumentDto toSimpleDocument(Dokument entity);
List<SimpleDocumentDto> toSimpleDocumentList(List<Dokument> entities);
}
...@@ -32,6 +32,16 @@ public interface DocumentRepository extends JpaRepository<Dokument, Long> { ...@@ -32,6 +32,16 @@ public interface DocumentRepository extends JpaRepository<Dokument, Long> {
) )
Optional<Dokument> findByTitleAndAuthorsIn(@Param("title") String title, @Param("lastNames") List<String> lastNames); Optional<Dokument> findByTitleAndAuthorsIn(@Param("title") String title, @Param("lastNames") List<String> lastNames);
@Query(
"""
SELECT r.toDocument FROM Dokument d
JOIN d.references r
WHERE d.id = :id
"""
)
List<Dokument> getReferencedDocumentsById(@Param("id") Long id);
} }
/* /*
......
package com.dre0059.articleprocessor.service; package com.dre0059.articleprocessor.service;
import com.dre0059.articleprocessor.dto.DocumentDto;
import com.dre0059.articleprocessor.dto.SimpleDocumentDto;
import com.dre0059.articleprocessor.mapper.DocumentMapper;
import com.dre0059.articleprocessor.repository.*; import com.dre0059.articleprocessor.repository.*;
import com.dre0059.articleprocessor.model.*; import com.dre0059.articleprocessor.model.*;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Service @Service
public class DocumentService { public class DocumentService {
@Autowired
private DocumentRepository documentRepository; private final DocumentMapper documentMapper;
@Autowired private final DocumentRepository documentRepository;
private AuthorRepository authorRepository; private final AuthorRepository authorRepository;
@Transactional public DocumentService(DocumentMapper documentMapper, DocumentRepository documentRepository,
public Dokument saveDocument(Dokument document) { AuthorRepository authorRepository) {
Dokument dok = new Dokument(); this.documentMapper = documentMapper;
return dok; this.documentRepository = documentRepository;
} this.authorRepository = authorRepository;
}
@Transactional
public DocumentDto getDocumentById(Long id) {
return documentMapper.toDocumentDto(documentRepository.findById(id).orElse(null));
}
@Transactional
public List<SimpleDocumentDto> getDocumentReferences(Long id) {
return documentMapper.toSimpleDocumentList(documentRepository.getReferencedDocumentsById(id));
}
@Transactional
public Dokument saveDocument(Dokument document) {
Dokument dok = new Dokument();
return dok;
}
} }
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
<pre id = "json-output"></pre> <pre id = "json-output"></pre>
</div> </div>
<a href="/api/document/22">click here</a>
<!-- .js na zobrazenie PDF --> <!-- .js na zobrazenie PDF -->
<script> <script>
document.getElementById('fileInput').addEventListener('change', function(event){ document.getElementById('fileInput').addEventListener('change', function(event){
......
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload PDF</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
#pdf-preview {
width: 500px;
height: 600px;
border: 1px solid #ddd;
margin-top: 10px;
}
</style>
</head>
<body>
<h1>PDF files</h1>
<!-- zobrazenie PDF -->
<div id="pdf-container">
<iframe id="pdf-preview" src="" style="display: none;"></iframe>
</div>
<table>
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>Link</th>
</tr>
</thead>
<tbody>
<tr th:each="ref: ${references}">
<td th:text="${ref.id}"></td>
<td th:text="${ref.title}"></td>
<td th:text="${ref.link}"></td>
</tr>
</tbody>
</table>
</body>
</html>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment