Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 06095907

Přidáno uživatelem Jitka Poubová před více než 4 roky(ů)

Re #8031: Programová příručka BE
- uploadedDate ukazuje správné datum (a ukládá se do core files)

Zobrazit rozdíly:

be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/IndexController.java
80 80

  
81 81
        try {
82 82
            LOG.debug("Calling SolrService and its listAllFiles method");
83
            List<String> filenames = solrService.listAllFiles();
84
            int id = 0;
85
            for (String filename: filenames) {
86
                response.add(new DocumentResponse(filename, id++, new Date()));
87
            }
88

  
83
            response = solrService.listAllFiles();
89 84
            return response;
90 85
        } catch (SolrServerException e) {
91 86
            LOG.error("SolrServerException: " + e.toString());
be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/SolrService.java
1 1
package cz.zcu.kiv.aswi.fulltextsearch;
2 2

  
3 3
import cz.zcu.kiv.aswi.fulltextsearch.document.*;
4
import cz.zcu.kiv.aswi.fulltextsearch.model.DocumentResponse;
4 5
import cz.zcu.kiv.aswi.fulltextsearch.model.SearchRequest;
5 6
import cz.zcu.kiv.aswi.fulltextsearch.model.SearchResponse;
6 7
import javaxt.io.Image;
......
26 27
import java.awt.image.BufferedImage;
27 28
import java.io.ByteArrayInputStream;
28 29
import java.io.IOException;
30
import java.text.ParseException;
31
import java.text.SimpleDateFormat;
29 32
import java.util.*;
30 33
import java.util.stream.Collectors;
31 34

  
......
51 54
    private static final String FIELD_UPLOADED_DATE = "uploadedDate";
52 55

  
53 56
    private static final float IMG_OUTPUT_QUALITY = 0.5f;
57
    private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd");
54 58

  
55 59
    private static final int DEFAULT_LINE_FIELD_COUNT = 150;
56 60
    private static final int DEFAULT_WORD_FIELD_COUNT = 30;
......
196 200
        solrInputDocument.addField(FIELD_IMG_FILENAME, imageFile.getOriginalFilename());
197 201
        solrInputDocument.addField(FIELD_DOC_CONTENT, xmlFile.getBytes());
198 202
        solrInputDocument.addField(FIELD_IMG_CONTENT, Base64.getEncoder().encode(imageFile.getBytes()));
203
        solrInputDocument.addField(FIELD_UPLOADED_DATE, FORMAT.format(new Date()));
199 204

  
200 205
        // adding to core files
201 206
        solrClientFiles.add(solrInputDocument);
......
254 259
     * @throws IOException if IO problem occurs
255 260
     * @throws SolrServerException if SolrServer problem occurs
256 261
     */
257
    public byte[] getImageFromFilesCore(String filename) throws IOException, SolrServerException {
262
    private byte[] getImageFromFilesCore(String filename) throws IOException, SolrServerException {
258 263
        LOG.trace("SolrService method getImageFromFilesCore called");
259 264
        LOG.debug("Getting an image from Files core");
260 265
        SolrQuery solrQuery = new SolrQuery();
......
519 524
        }
520 525
    }
521 526

  
522
    public List<String> listAllFiles() throws IOException, SolrServerException {
527
    public List<DocumentResponse> listAllFiles() throws IOException, SolrServerException, ParseException {
523 528
        LOG.trace("SolrService method listAllFiles called");
524 529
        LOG.debug("Displaying ALL files in Solr");
525 530
        SolrQuery solrQuery = new SolrQuery();
526 531
        solrQuery.set("q", FIELD_DOC_FILENAME + ":*");
527 532
        SolrDocumentList docList = solrClientFiles.query(solrQuery).getResults();
528
        return docList.stream().map(doc -> doc.getFieldValue(FIELD_DOC_FILENAME).toString().replaceAll(".xml", "")).collect(Collectors.toList());
533

  
534
        int id = 0;
535
        List<DocumentResponse> responses = new LinkedList<>();
536
        for (SolrDocument doc: docList) {
537
            String filename = doc.getFieldValue(FIELD_DOC_FILENAME).toString().replaceAll(".xml", "");
538
            String dateStr = doc.getFieldValue(FIELD_UPLOADED_DATE).toString();
539
            Date date = FORMAT.parse(dateStr);
540
            responses.add(new DocumentResponse(filename, id++, date));
541
        }
542

  
543
        return responses;
529 544
    }
530 545

  
531 546
    public String listSingleFile(String documentName) throws IOException, SolrServerException {

Také k dispozici: Unified diff