blob: afaeb7b312ddf952c644917c1c0b5192aa6ca1d3 [file] [log] [blame]
margaretha351777b2017-12-13 19:55:04 +01001package de.ids_mannheim.korap.dto.converter;
2
margaretha23aae222017-12-22 15:08:23 +01003import org.springframework.stereotype.Component;
margaretha351777b2017-12-13 19:55:04 +01004
5import com.fasterxml.jackson.databind.JsonNode;
6
7import de.ids_mannheim.korap.dto.VirtualCorpusDto;
8import de.ids_mannheim.korap.entity.VirtualCorpus;
9import de.ids_mannheim.korap.exceptions.KustvaktException;
10import de.ids_mannheim.korap.utils.JsonUtils;
11
margaretha6b3ecdd2018-03-01 18:23:56 +010012/**
margaretha398f4722019-01-09 19:07:20 +010013 * VirtualCorpusConverter prepares data transfer objects (DTOs) from
14 * {@link VirtualCorpus} entities. DTO structure defines controllers
15 * output, namely the structure of JSON objects in HTTP responses.
margaretha6b3ecdd2018-03-01 18:23:56 +010016 *
17 * @author margaretha
18 *
19 */
margaretha23aae222017-12-22 15:08:23 +010020@Component
margaretha351777b2017-12-13 19:55:04 +010021public class VirtualCorpusConverter {
22
23 public VirtualCorpusDto createVirtualCorpusDto (VirtualCorpus vc,
24 String statistics) throws KustvaktException {
25
26 VirtualCorpusDto dto = new VirtualCorpusDto();
27 dto.setId(vc.getId());
28 dto.setName(vc.getName());
29 dto.setCreatedBy(vc.getCreatedBy());
margarethad3bc71f2018-01-03 20:35:06 +010030 dto.setRequiredAccess(vc.getRequiredAccess().name());
margaretha351777b2017-12-13 19:55:04 +010031 dto.setStatus(vc.getStatus());
32 dto.setDescription(vc.getDescription());
33 dto.setType(vc.getType().displayName());
margaretha90adf312021-02-17 10:12:41 +010034 JsonNode kq = JsonUtils.readTree(vc.getKoralQuery());
35 dto.setKoralQuery(kq);
margaretha351777b2017-12-13 19:55:04 +010036
Akronda080152020-12-03 13:53:29 +010037 if (statistics != null) {
38 JsonNode node = JsonUtils.readTree(statistics);
39 dto.setNumberOfDoc(node.at("/documents").asInt());
40 dto.setNumberOfParagraphs(node.at("/paragraphs").asInt());
41 dto.setNumberOfSentences(node.at("/sentences").asInt());
42 dto.setNumberOfTokens(node.at("/tokens").asInt());
43 }
margaretha351777b2017-12-13 19:55:04 +010044 return dto;
45
46 }
47}