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

Bootstrap implemented

parent e6d86d09
No related merge requests found
No preview for this file type
package com.dre0059.articleprocessor.controller;
import com.dre0059.articleprocessor.GrobidClient;
import com.dre0059.articleprocessor.model.Dokument;
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.HashMap;
import java.util.Map;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -64,7 +68,7 @@ public class FileUploadController {
String references = grobidClient.processReferences(tmpFile);
//System.out.println("GROBID Reference processed: " + references);
headerService.processHeader(header, categoryId, tmpFile);
Dokument savedDocument = headerService.processHeader(header, categoryId, tmpFile);
//System.out.println("Header saved to database.");
referenceService.extractReferences(references);
......@@ -72,6 +76,10 @@ public class FileUploadController {
tmpFile.delete();
Map<String, Object> response = new HashMap<>();
response.put("id", savedDocument.getId());
response.put("message", "Upload successful");
return ResponseEntity.ok(header);
......
......@@ -54,7 +54,7 @@ public class HeaderService {
this.categoryRepository = categoryRepository;
}
public void processHeader(String header, String categoryId, File pdfFile) {
public Dokument processHeader(String header, String categoryId, File pdfFile) {
this.title = this.parseHeaderFields(header, "title");
if(!this.parseHeaderFields(header, "doi").equals("Not found")){
......@@ -87,9 +87,11 @@ public class HeaderService {
// check duplicity of the document
if(documentRepository.existsByTitleAndAuthorsIn(title, authorLastNames)){
System.out.println("Document with this title and authors already exist");
return;
return null;
}
Dokument dok = new Dokument(title, year, doi, publisher, "PDF");
List<Author> savedAuthors = authorRepository.saveAll(authorList);
Dokument dokument = new Dokument(title, year, doi, publisher, "PDF");
Category category = categoryRepository.getReferenceById(categoryId);
......@@ -105,11 +107,12 @@ public class HeaderService {
System.err.println("Nepodarilo sa ulozit obsah suboru");
}
this.documentRepository.save(dokument); // output : Optional.empty
Dokument saved = this.documentRepository.save(dokument); // output : Optional.empty
// set the document, which has the list of references
referenceService.setFromDocument(dokument);
referenceService.setFromDocument(saved);
return saved;
}
private String parseHeaderFields(String header, String field){
......
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