Skip to content
Snippets Groups Projects
Commit e1fae0bf authored by dre0059's avatar dre0059
Browse files

Implementované pridávanie TAGov pri nahratí PDF dokumentu

parent b9880c2d
No related merge requests found
Showing
with 213 additions and 12 deletions
# Articleprocessor GROBID version 1.0
- The main program runs at : *http://localhost:8080/api/grobid/upload*
- The main program runs at : *http://localhost:8080/upload* or *http://localhost:8080*
- H2 database can be found on : *http://localhost:8080/h2-console/login.jsp?jsessionid=9af0ea4b83284ff0a4574769b0336943*
- Password for the DBS can be found in : `resources/application.properties`
- GROBID server available on address *http://158.196.98.65:8080/* at university network
......
No preview for this file type
......@@ -676,3 +676,65 @@ Wrong user name or password [28000-232]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:522)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
... 50 more
2025-04-25 19:03:53.157120+02:00 database: wrong user or password; user: "SA"
org.h2.message.DbException: Nesprávne používateľské meno alebo heslo
Wrong user name or password [28000-232]
at org.h2.message.DbException.get(DbException.java:223)
at org.h2.message.DbException.get(DbException.java:199)
at org.h2.message.DbException.get(DbException.java:188)
at org.h2.engine.Engine.openSession(Engine.java:154)
at org.h2.engine.Engine.openSession(Engine.java:222)
at org.h2.engine.Engine.createSession(Engine.java:201)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:344)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:124)
at org.h2.util.JdbcUtils.getConnection(JdbcUtils.java:291)
at org.h2.server.web.WebServer.getConnection(WebServer.java:811)
at org.h2.server.web.WebApp.login(WebApp.java:1038)
at org.h2.server.web.WebApp.process(WebApp.java:226)
at org.h2.server.web.WebApp.processRequest(WebApp.java:176)
at org.h2.server.web.JakartaWebServlet.doGet(JakartaWebServlet.java:129)
at org.h2.server.web.JakartaWebServlet.doPost(JakartaWebServlet.java:166)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:483)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:397)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:905)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
at java.base/java.lang.Thread.run(Thread.java:1575)
Caused by: org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Nesprávne používateľské meno alebo heslo
Wrong user name or password [28000-232]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:522)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
... 50 more
2025-04-25 20:50:38.587546+02:00 jdbc[3]: exception
org.h2.jdbc.JdbcSQLDataException: Hodnota je príliš dlhá pre stĺpec "TITLE CHARACTER VARYING(255)": "'He received the PhD degree from the National University of Singapore and his ad... (448)"
Value too long for column "TITLE CHARACTER VARYING(255)": "'He received the PhD degree from the National University of Singapore and his ad... (448)"; SQL statement:
insert into documents (abstract_text,category_id,content,doi,publication_year,publisher,status,target,title,id) values (?,?,?,?,?,?,?,?,?,default) [22001-232]
......@@ -2,15 +2,20 @@ package com.dre0059.articleprocessor.controller;
import com.dre0059.articleprocessor.GrobidClient;
import com.dre0059.articleprocessor.model.Dokument;
import com.dre0059.articleprocessor.model.Tag;
import com.dre0059.articleprocessor.repository.TagRepository;
import com.dre0059.articleprocessor.service.CategoryService;
import com.dre0059.articleprocessor.service.HeaderService;
import com.dre0059.articleprocessor.service.ReferenceService;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -29,6 +34,7 @@ public class FileUploadController {
private final ReferenceService referenceService;
private final CategoryService categoryService;
public FileUploadController(GrobidClient grobidClient, HeaderService headerService, ReferenceService referenceService, CategoryService categoryService) {
this.grobidClient = grobidClient;
this.headerService = headerService;
......@@ -45,7 +51,11 @@ public class FileUploadController {
@PostMapping("/api/upload")
@ResponseBody
public ResponseEntity<?> handleFileUpload(@RequestParam("file") MultipartFile file, @RequestParam("categoryId") String categoryId) {
public ResponseEntity<?> handleFileUpload(
@RequestParam("file") MultipartFile file,
@RequestParam("categoryId") String categoryId,
@RequestParam("tags") List<String> tags) {
if (file.isEmpty()) {
return ResponseEntity.badRequest().body("No file uploaded!");
}
......@@ -68,7 +78,7 @@ public class FileUploadController {
String references = grobidClient.processReferences(tmpFile);
//System.out.println("GROBID Reference processed: " + references);
Dokument savedDocument = headerService.processHeader(header, categoryId, tmpFile);
Dokument savedDocument = headerService.processHeader(header, categoryId, tags, tmpFile);
//System.out.println("Header saved to database.");
referenceService.extractReferences(references);
......
package com.dre0059.articleprocessor.controller;
import com.dre0059.articleprocessor.repository.TagRepository;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/api")
public class TagController {
//@Autowired
private final TagRepository tagRepository;
public TagController(TagRepository tagRepository) {
this.tagRepository = tagRepository;
}
@GetMapping("/tags")
public List<Map<String, String>> getTags(@RequestParam("term") String term) {
return tagRepository.findByTitleContainingIgnoreCase(term).stream()
.map(tag -> Map.of("id", tag.getTitle(), "text", tag.getTitle())) // použijeme title ako ID pre select2
.collect(Collectors.toList());
}
}
......@@ -3,6 +3,9 @@ package com.dre0059.articleprocessor.dto;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
public class DocumentDto {
......@@ -15,5 +18,5 @@ public class DocumentDto {
private String publisher;
private String target;
private List<TagDto> tags;
}
package com.dre0059.articleprocessor.dto;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class TagDto {
private Long id;
private String title;
}
......@@ -8,7 +8,7 @@ import java.util.List;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@Mapper(componentModel = "spring")
@Mapper(componentModel = "spring", uses = {TagMapper.class})
public interface DocumentMapper {
//@Mapping(target = "publication_year", source = "year")
......@@ -28,4 +28,6 @@ public interface DocumentMapper {
}
}
}
package com.dre0059.articleprocessor.mapper;
import com.dre0059.articleprocessor.dto.TagDto;
import com.dre0059.articleprocessor.model.Tag;
import org.mapstruct.Mapper;
import java.util.List;
@Mapper(componentModel = "spring")
public interface TagMapper {
TagDto toTagDto(Tag tag);
Tag toTag(TagDto tagDto);
List<TagDto> toTagDtoList(List<Tag> tags);
List<Tag> toTagList(List<TagDto> tagDtos);
}
......@@ -63,10 +63,20 @@ public class Dokument {
joinColumns = @JoinColumn(name = "ID_document"),
inverseJoinColumns = @JoinColumn(name = "ID_author")
)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
private List<Author> authors = new ArrayList<>();
@ManyToMany
@JoinTable(
name = "document_tag",
joinColumns = @JoinColumn(name = "document_id"),
inverseJoinColumns = @JoinColumn(name = "tag_id")
)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
private List<Tag> tags = new ArrayList<>();
public Dokument() {}
public Dokument(String title, Integer year, String doi,String publisher, String status) {
......
......@@ -7,8 +7,10 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
......@@ -21,4 +23,10 @@ public class Tag {
@Column(nullable = false, unique = true)
private String title;
@ManyToMany(mappedBy = "tags")
private List<Dokument> documents = new ArrayList<>();
public Tag(String title) {
this.title = title;
}
}
......@@ -2,6 +2,7 @@ package com.dre0059.articleprocessor.repository;
import com.dre0059.articleprocessor.model.*;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
......@@ -14,6 +15,9 @@ import java.util.Optional;
@Repository
public interface DocumentRepository extends JpaRepository<Dokument, Long> {
@EntityGraph(attributePaths = {"tags"})
Optional<Dokument> findWithTagsById(Long id);
@Query(
"SELECT COUNT(d) > 0 " +
"FROM Dokument d " +
......
package com.dre0059.articleprocessor.repository;
import com.dre0059.articleprocessor.model.Tag;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
import java.util.Optional;
public interface TagRepository extends JpaRepository<Tag, Long> {
Optional<Tag> findByTitle(String title);
List<Tag> findByTitleContainingIgnoreCase(String term); // musí vracať List<Tag>
Optional<Tag> findByTitleIgnoreCase(String title);
}
......@@ -32,7 +32,9 @@ public class DocumentService {
@Transactional
public DocumentDto getDocumentById(Long documentId) {
Dokument dokument = documentRepository.findById(documentId).orElse(null);
//Dokument dokument = documentRepository.findById(documentId).orElse(null);
Dokument dokument = documentRepository.findWithTagsById(documentId)
.orElseThrow(() -> new IllegalArgumentException("Dokument not found with id: " + documentId));
// Použitie mappera na konverziu dokumentu do DTO
DocumentDto documentDto = documentMapper.toDocumentDto(dokument);
......
......@@ -4,6 +4,7 @@ import com.dre0059.articleprocessor.dto.CategoryDto;
import com.dre0059.articleprocessor.model.Author;
import com.dre0059.articleprocessor.model.Category;
import com.dre0059.articleprocessor.model.Dokument;
import com.dre0059.articleprocessor.model.Tag;
import com.dre0059.articleprocessor.repository.AuthorRepository;
import com.dre0059.articleprocessor.repository.CategoryRepository;
import com.dre0059.articleprocessor.repository.DocumentRepository;
......@@ -16,6 +17,8 @@ import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.dre0059.articleprocessor.repository.TagRepository;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -33,8 +36,7 @@ public class HeaderService {
private final AuthorRepository authorRepository;
private final ReferenceService referenceService;
private final CategoryRepository categoryRepository;
//public Dokument(String title, Integer year, String doi, String abstractText, Integer pages, String publisher) {
private final TagRepository tagRepository;
private String title;
private Integer year;
......@@ -47,14 +49,19 @@ public class HeaderService {
private String author;
@Autowired
public HeaderService(DocumentRepository documentRepository, AuthorRepository authorRepository, ReferenceService referenceService, CategoryRepository categoryRepository) {
public HeaderService(DocumentRepository documentRepository,
AuthorRepository authorRepository,
ReferenceService referenceService,
CategoryRepository categoryRepository,
TagRepository tagRepository) {
this.documentRepository = documentRepository;
this.authorRepository = authorRepository;
this.referenceService = referenceService;
this.categoryRepository = categoryRepository;
this.tagRepository = tagRepository;
}
public Dokument processHeader(String header, String categoryId, File pdfFile) {
public Dokument processHeader(String header, String categoryId, List<String> tags, File pdfFile) {
this.title = this.parseHeaderFields(header, "title");
if(!this.parseHeaderFields(header, "doi").equals("Not found")){
......@@ -101,6 +108,24 @@ public class HeaderService {
System.out.println("Category: " + category);
dokument.setCategory(category);
List<Tag> tagEntities = new ArrayList<>();
for (String tagName : tags) {
String lowerCase = tagName.trim().toLowerCase(); // konverzia na lowercase
Optional<Tag> existingTag = tagRepository.findByTitleIgnoreCase(lowerCase);
Tag tag = existingTag.orElseGet(() -> {
Tag newTag = new Tag(lowerCase);
return tagRepository.save(newTag); // uložíme nový iba ak neexistuje
});
tagEntities.add(tag);
}
dokument.setTags(tagEntities);
try {
dokument.setContent(FileUtils.readFileToByteArray(pdfFile));
} catch (IOException e) {
......
src/main/resources/static/assets/img/background.png

3.32 MiB

src/main/resources/static/assets/img/bg-showcase-1.jpg

298 KiB

src/main/resources/static/assets/img/bg-showcase-2.jpg

193 KiB

src/main/resources/static/assets/img/bg-showcase-3.jpg

35.2 KiB

src/main/resources/static/assets/img/bg_pdf.png

2.36 MiB

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