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

Oprava - categories funguju

parent 14de49a5
Branches
No related merge requests found
......@@ -161,10 +161,6 @@
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<<<<<<< HEAD
</dependencies>
=======
<dependency>
<groupId>org.mapstruct</groupId>
......@@ -175,15 +171,12 @@
</dependencies>
>>>>>>> 9e1c76c (Categories of PDF initialized)
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<<<<<<< HEAD
=======
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......@@ -199,7 +192,6 @@
</annotationProcessorPaths>
</configuration>
</plugin>
>>>>>>> 9e1c76c (Categories of PDF initialized)
</plugins>
</build>
......
package com.dre0059.articleprocessor.controller;
import com.dre0059.articleprocessor.GrobidClient;
<<<<<<< HEAD
=======
import com.dre0059.articleprocessor.model.Category;
import com.dre0059.articleprocessor.repository.CategoryRepository;
>>>>>>> 9e1c76c (Categories of PDF initialized)
import com.dre0059.articleprocessor.service.HeaderService;
import com.dre0059.articleprocessor.service.ReferenceService;
......@@ -18,11 +15,8 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
<<<<<<< HEAD
=======
import java.util.List;
import java.util.Optional;
>>>>>>> 9e1c76c (Categories of PDF initialized)
@Controller
@RequestMapping("/api/grobid")
......@@ -30,13 +24,6 @@ public class FileUploadController {
private final GrobidClient grobidClient;
private final HeaderService headerService;
private final ReferenceService referenceService;
<<<<<<< HEAD
public FileUploadController(GrobidClient grobidClient, HeaderService headerService, ReferenceService referenceService) {
this.grobidClient = grobidClient;
this.headerService = headerService;
this.referenceService = referenceService;
=======
private final CategoryRepository categoryRepository;
public FileUploadController(GrobidClient grobidClient, HeaderService headerService, ReferenceService referenceService, CategoryRepository categoryRepository) {
......@@ -44,35 +31,24 @@ public class FileUploadController {
this.headerService = headerService;
this.referenceService = referenceService;
this.categoryRepository = categoryRepository;
>>>>>>> 9e1c76c (Categories of PDF initialized)
}
@GetMapping("/upload")
public String showUploadForm(Model model) {
<<<<<<< HEAD
=======
List<Category> categories = categoryRepository.findAll();
model.addAttribute("categories", categories);
>>>>>>> 9e1c76c (Categories of PDF initialized)
return "upload"; // vracia upload.html
}
@PostMapping("/upload")
@ResponseBody
<<<<<<< HEAD
public ResponseEntity<String> handleFileUpload(@RequestParam("file") MultipartFile file) {
=======
public ResponseEntity<String> handleFileUpload(@RequestParam("file") MultipartFile file, @RequestParam("category") String category) {
>>>>>>> 9e1c76c (Categories of PDF initialized)
if (file.isEmpty()) {
return ResponseEntity.badRequest().body("No file uploaded!");
}
System.out.println("Received file: " + file.getOriginalFilename());
<<<<<<< HEAD
=======
System.out.println("Received category: " + category);
>>>>>>> 9e1c76c (Categories of PDF initialized)
try {
// Vytvorenie dočasného súboru
......@@ -88,13 +64,6 @@ public class FileUploadController {
String header = grobidClient.processHeader(tmpFile);
String references = grobidClient.processReferences(tmpFile);
<<<<<<< HEAD
headerService.processHeader(header);
referenceService.extractReferences(references);
//System.out.println(header);
System.out.println(references);
=======
String categoryId = category.substring(0, 3);
Optional<Category> categoryOptional = categoryRepository.findById(categoryId);
......@@ -111,7 +80,6 @@ public class FileUploadController {
//System.out.println(references);
>>>>>>> 9e1c76c (Categories of PDF initialized)
tmpFile.delete();
......
......@@ -6,11 +6,6 @@ import org.hibernate.annotations.Cascade;
import java.util.ArrayList;
import java.util.List;
<<<<<<< HEAD
// TODO : int / boolean - či je PDF nahraté alebo je to dokument len z referencie
// 1. references -
=======
>>>>>>> 9e1c76c (Categories of PDF initialized)
@Entity
@Table(name = "documents")
......@@ -27,13 +22,10 @@ public class Dokument {
private Integer publicationYear;
private String doi;
<<<<<<< HEAD
=======
@ManyToOne
@JoinColumn(name = "category_id")
private Category category;
>>>>>>> 9e1c76c (Categories of PDF initialized)
// @Lob for huge text
//@Column(name = "abstractText", columnDefinition = "TEXT")
//private String abstractText;
......@@ -79,28 +71,6 @@ public class Dokument {
public void setAuthors(List<Author> authors) { this.authors = authors; }
public void setTitle(String title) { this.title = title; }
public void setTarget(String target) { this.target = target; }
<<<<<<< HEAD
public void setPublicationYear(Integer publicationYear) {
this.publicationYear = publicationYear;
}
public void setDoi(String doi) {
this.doi = doi;
}
public void setStatus(String status) {
this.status = status;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public void setReferences(List<Reference> references) {
this.references = references;
}
=======
public void setPublicationYear(Integer publicationYear) {
this.publicationYear = publicationYear;
}
......@@ -117,5 +87,4 @@ public class Dokument {
this.references = references;
}
public void setCategory(Category category) { this.category = category;}
>>>>>>> 9e1c76c (Categories of PDF initialized)
}
package com.dre0059.articleprocessor.service;
import com.dre0059.articleprocessor.model.Author;
<<<<<<< HEAD
import com.dre0059.articleprocessor.model.Dokument;
import com.dre0059.articleprocessor.repository.AuthorRepository;
=======
import com.dre0059.articleprocessor.model.Category;
import com.dre0059.articleprocessor.model.Dokument;
import com.dre0059.articleprocessor.repository.AuthorRepository;
import com.dre0059.articleprocessor.repository.CategoryRepository;
>>>>>>> 9e1c76c (Categories of PDF initialized)
import com.dre0059.articleprocessor.repository.DocumentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -31,10 +26,7 @@ public class HeaderService {
private final DocumentRepository documentRepository;
private final AuthorRepository authorRepository;
private final ReferenceService referenceService;
<<<<<<< HEAD
=======
private final CategoryRepository categoryRepository;
>>>>>>> 9e1c76c (Categories of PDF initialized)
//public Dokument(String title, Integer year, String doi, String abstractText, Integer pages, String publisher) {
......@@ -47,17 +39,6 @@ public class HeaderService {
private List<Author> authorList = new ArrayList<>();
private String author;
<<<<<<< HEAD
@Autowired
public HeaderService(DocumentRepository documentRepository, AuthorRepository authorRepository, ReferenceService referenceService) {
this.documentRepository = documentRepository;
this.authorRepository = authorRepository;
this.referenceService = referenceService;
}
public void processHeader(String header){
=======
private Category category;
@Autowired
......@@ -69,7 +50,6 @@ public class HeaderService {
}
public void processHeader(String header, Optional<Category> category) {
>>>>>>> 9e1c76c (Categories of PDF initialized)
this.title = this.parseHeaderFields(header, "title");
if(!this.parseHeaderFields(header, "doi").equals("Not found")){
......@@ -99,10 +79,6 @@ public class HeaderService {
System.out.println("Author list before checking duplicity: " + authorList);
System.out.println("Author last names before checking duplicity: " + authorLastNames);
<<<<<<< HEAD
// tu dostávam error :
=======
>>>>>>> 9e1c76c (Categories of PDF initialized)
boolean headerDuplicity = documentRepository.existsByTitleAndAuthorsIn(title, authorLastNames);
// check duplicity of the document
......@@ -114,10 +90,6 @@ public class HeaderService {
List<Author> savedAuthors = authorRepository.saveAll(authorList);
Dokument dokument = new Dokument(title, year, doi, publisher, "PDF");
<<<<<<< HEAD
dokument.setAuthors(savedAuthors);
this.documentRepository.save(dokument);
=======
//dokument.setCategory(category.get());
dokument.setAuthors(savedAuthors);
......@@ -125,7 +97,6 @@ public class HeaderService {
category.ifPresent(dokument::setCategory);
this.documentRepository.save(dokument); // output : Optional.empty
>>>>>>> 9e1c76c (Categories of PDF initialized)
// set the document, which has the list of references
referenceService.setFromDocument(dokument);
......
package com.dre0059.articleprocessor.service;
import com.dre0059.articleprocessor.model.*;
import com.dre0059.articleprocessor.repository.*;
import jakarta.transaction.Transactional;
import com.dre0059.articleprocessor.model.Author;
import com.dre0059.articleprocessor.model.Dokument;
import com.dre0059.articleprocessor.model.Reference;
import com.dre0059.articleprocessor.repository.AuthorRepository;
import com.dre0059.articleprocessor.repository.DocumentRepository;
import com.dre0059.articleprocessor.repository.ReferenceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
<<<<<<< HEAD
// TODO :
// 1. uložiť prepojenie toDocument a fromDocument do tabuľky referencie
// 2. vytiahnuť orderNumber z referencie (toto riešiť cez GROBID)
// 3. aktuálne sa mi toDocument ukladá vždy ako nový.. ja ho potrebujem vyhľadať a na základe toho uložiť alebo prepojiť
// 4. uložiť záznam do tabuľky references
// 5. ak už bolo PDF raz uložené, uloží sa mi "null" článok, prepojený s autormi - VYRIESIT
=======
>>>>>>> 9e1c76c (Categories of PDF initialized)
@Service
public class ReferenceService {
......
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