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

Dokumentácia update

parent 50c09547
No related merge requests found
......@@ -25,6 +25,13 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
/**
* Trieda na manipuláciu s dokumentmi.
* *
* * Poskytuje metódy na získavanie dokumentov, ako aj ich obsahov a referencií.
* * Obsah dokumentu je vracaný ako DTO objekt a operácie nad dokumentami sú zabezpečené pomocou repository.
* *
*/
@Service
public class DocumentService {
......@@ -43,9 +50,14 @@ public class DocumentService {
this.referenceRepository = referenceRepository;
}
/**
* Získa dokument na základe jeho ID.
*
* @param documentId ID dokumentu
* @return DTO objekt dokumentu
*/
@Transactional
public DocumentDto getDocumentById(Long documentId) {
//Dokument dokument = documentRepository.findById(documentId).orElse(null);
Dokument dokument = documentRepository.findWithTagsById(documentId)
.orElseThrow(() -> new IllegalArgumentException("Dokument not found with id: " + documentId));
......@@ -54,19 +66,43 @@ public class DocumentService {
return documentDto;
}
/**
* Získa obsah dokumentu na základe jeho ID.
*
* @param documentId ID dokumentu
* @return DTO objekt s obsahom dokumentu
*/
@Transactional
public DocumentContentDto getDocumentContentById(Long documentId) {
return documentMapper.toDocumentContentDto(documentRepository.findById(documentId).orElse(null));
}
/**
* Získa zoznam dokumentov, ktoré sú citované / referencované z daného dokumentu.
*
* @param documentId ID dokumentu
* @return Zoznam referencovaných dokumentov
*/
@Transactional
public List<SimpleDocumentDto> getReferencedDocumentsById(Long documentId) {
return documentMapper.toSimpleDocumentList(documentRepository.getReferencedDocumentsById(documentId));
}
@Transactional
public List<SimpleDocumentDto> getAllDocuments() {
return documentMapper.toSimpleDocumentList(documentRepository.findAll());
}
/**
* Predpripravená metóda :
* ODSTRÁNI DOKUEMENT Z DATABÁZY
*
* Dokument je odstránený spolu s referenciami a jeho autorom.
*
* @param id ID dokumentu
*/
@Transactional
public void deleteDocument(Long id) {
Dokument dokument = documentRepository.findById(id).orElse(null);
......@@ -83,10 +119,6 @@ public class DocumentService {
List<Reference> referencesFrom = referenceRepository.findByFromDocumentId(id);
referenceRepository.deleteAll(referencesFrom);
// DOSTÁVAM výnimku keď to je PDF a neexistuje ako toDocument
//List<Reference> referenceTo = referenceRepository.findByToDocumentId(id);
//referenceRepository.deleteAll(referenceTo);
// Odstránenie dokumentu zo zoznamov autorov
List<Author> authors = new ArrayList<>(dokument.getAuthors()); // Vytvoríme novú kolekciu, aby sme sa vyhli problémom pri zmene kolekcie počas iterácie
dokument.getAuthors().clear(); // Odstránime autora z dokumentu
......@@ -101,7 +133,6 @@ public class DocumentService {
// Vymazanie dokumentu z databázy
documentRepository.deleteById(id);
// všetko sa mi vykoná a na konci mi vyskočí error... neviem prečo a ako to ošetriť
}
......
......@@ -29,6 +29,15 @@ import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* * Trieds na spracovanie hlavičkových údajov dokumentov, ktoré boli nahraté ako PDF formát
* *
* * Táto trieda :
* - extrahuje a spracováva hlavičkové informácie
* (ako titul, autori, rok, DOI, atď.)
* - ukladá tieto informácie do databázy
*
*/
@Service
public class HeaderService {
......@@ -61,6 +70,17 @@ public class HeaderService {
this.tagRepository = tagRepository;
}
/**
* Spracuje text získaný z hlavičky dokumentu a uloží informácie o dokumente do databázy.
* Mení status z Referenced na PDF pokiaľ je to potrebné
*
* @param header Hlavička dokumentu
* @param categoryId ID kategórie dokumentu
* @param tags Zoznam tagov priradených dokumentu
* @param pdfFile Súbor PDF dokumentu
* @return Uložený dokument
*/
public Dokument processHeader(String header, String categoryId, List<String> tags, File pdfFile) {
this.title = this.parseHeaderFields(header, "title");
......@@ -104,7 +124,6 @@ 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
......@@ -136,6 +155,13 @@ public class HeaderService {
return saved;
}
/**
* Pomocná matóda na parsovanie informácií z hlavičky (pomocou regulárnych výrazov)
*
* @param header
* @param field - to čo chcem získať (DOI, publisher, year...)
* @return žiadaný údaj o dokumente (príp. Not found)
*/
private String parseHeaderFields(String header, String field){
String regex = field + "\\s*=\\s*\\{([^}]*)\\}";
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
......@@ -144,12 +170,18 @@ public class HeaderService {
if(matcher.find()){
return matcher.group(1).trim();
} else
return "Not found"; // should replace for NULL ?
return "Not found";
}
/**
* Metóda na parsovanie autorov dokumentu do poľa a ich následné uloženie do DBS
*
* @param author - jeden string so všetkými autormi dokumentu
* @return Zoznam uložených autorov
*/
private List<Author> saveAuthorNameAndSurname(String author){
// "and" divides our authors
// "and" divides our authors in the input String
String[] authorNames = author.split(" and ");
List<Author> authors = new ArrayList<>();
List<Author> databaseAuthors = authorRepository.findAll();
......
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