commit 6d9b0887b73c0c603e87f6821199c6a8649eb6d8
Author: smoldas15 <jan.smolar@seznam.cz>
Date:   Thu Apr 23 12:11:46 2020 +0200

    Re #7915: Zobrazení celého dokumentu na BE
    
    - vytvořeno posílání jednoho dokumentu na FE
    - úprava posílání názvů dokumentů na FE: nyní bez koncovky

diff --git a/be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/IndexController.java b/be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/IndexController.java
index 1f29c4e..a045307 100644
--- a/be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/IndexController.java
+++ b/be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/IndexController.java
@@ -68,6 +68,21 @@ public class IndexController {
         return response;
     }
 
+    @GetMapping("/documents/{documentName}")
+    public DocumentDetailResponse listSingleDocument(@PathVariable String documentName) {
+        LOG.trace("Method listSingleDocument called");
+        String ret = "";
+
+        try {
+            LOG.debug("Calling SolrService and its listSingleFile method");
+            ret = solrService.listSingleFile(documentName);
+        } catch (Exception e) {
+            LOG.error("Cannot get method listSingleFile from SolrService");
+            LOG.error(e.toString());
+        }
+        return new DocumentDetailResponse(ret);
+    }
+
     @GetMapping("/delete")
     public String delete() {
         LOG.trace("Method delete called");
diff --git a/be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/SolrService.java b/be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/SolrService.java
index 3a55a62..6d4e736 100644
--- a/be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/SolrService.java
+++ b/be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/SolrService.java
@@ -46,7 +46,7 @@ public class SolrService {
     private static final String FIELD_TEXT_REGION_COORDS = "text_region" + SUFFIX_COORDS;
     private static final String FIELD_DOC_CONTENT = "doc_content";
     private static final String FIELD_IMG_CONTENT = "img_content";
-    private static final float IMG_OUTPUT_QUALITY = 0.1f;
+    private static final float IMG_OUTPUT_QUALITY = 0.5f;
     private static final Logger LOG = LoggerFactory.getLogger(IndexController.class);
 
     private static final int SEARCH_QUERY_ROWS = 100;
@@ -478,7 +478,40 @@ public class SolrService {
         solrQuery.set("q", FIELD_DOC_FILENAME + ":*");
         solrQuery.setRows(500); // todo not a magic number!
         SolrDocumentList docList = solrClientFiles.query(solrQuery).getResults();
-        return docList.stream().map(doc -> doc.getFieldValue(FIELD_DOC_FILENAME).toString()).collect(Collectors.toList());
+        return docList.stream().map(doc -> doc.getFieldValue(FIELD_DOC_FILENAME).toString().replaceAll(".xml", "")).collect(Collectors.toList());
+    }
+
+    public String listSingleFile(String documentName) throws IOException, SolrServerException {
+        LOG.trace("SolrService method listSingleFile called");
+        LOG.debug("Displaying single file in Solr");
+        SolrQuery solrQuery = new SolrQuery();
+        solrQuery.set("q", FIELD_DOC_FILENAME + ":*");
+        //solrQuery.set("q", FIELD_DOC_FILENAME + ":" + documentName + ".xml");
+        solrQuery.setRows(500); // todo not a magic number!
+        SolrDocumentList docList = solrClientFiles.query(solrQuery).getResults();
+        String ret = "";
+
+        for (SolrDocument solrDocument : docList){
+            if (solrDocument.getFieldValue(FIELD_DOC_FILENAME).toString().equals(documentName + ".xml")){
+                String imgFilename = (String) solrDocument.getFieldValue(FIELD_IMG_FILENAME);
+                byte[] imageBytes = getImageFromFilesCore(imgFilename);
+
+                BufferedImage img = ImageIO.read(new ByteArrayInputStream(Base64.getDecoder().decode(imageBytes)));
+                Image cropImg = new Image(img);
+                cropImg.setOutputQuality(IMG_OUTPUT_QUALITY);
+
+                imageBytes = cropImg.getByteArray();
+                imageBytes = Base64.getEncoder().encode(imageBytes);
+                ret = new String(imageBytes);
+                break;
+            }
+        }
+        if (ret.equals("")){
+            LOG.error("File was NOT found in Solr");
+        } else{
+            LOG.debug("File was found in Solr");
+        }
+        return ret;
     }
 
 }
diff --git a/be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/model/DocumentDetailResponse.java b/be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/model/DocumentDetailResponse.java
new file mode 100644
index 0000000..7fca6db
--- /dev/null
+++ b/be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/model/DocumentDetailResponse.java
@@ -0,0 +1,19 @@
+package cz.zcu.kiv.aswi.fulltextsearch.model;
+
+import java.util.Date;
+
+public class DocumentDetailResponse {
+    private String documentName;
+
+    public DocumentDetailResponse(String documentName) {
+        this.documentName = documentName;
+    }
+
+    public String getDocumentName() {
+        return documentName;
+    }
+
+    public void setDocumentName(String documentName) {
+        this.documentName = documentName;
+    }
+}
