Projekt

Obecné

Profil

« Předchozí | Další » 

Revize ce5bfed1

Přidáno uživatelem Jakub Šmíd před asi 2 roky(ů)

Changed coordinates to null from 0.0 when not known

re #9625

Zobrazit rozdíly:

backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItem.java
49 49
    /**
50 50
     * Certainty
51 51
     */
52
    private int certainty;
52
    private Integer certainty;
53 53

  
54 54
    /**
55 55
     * Longitude
56 56
     */
57
    private double longitude;
57
    private Double longitude;
58 58

  
59 59
    /**
60 60
     * Latitude
61 61
     */
62
    private double latitude;
62
    private Double latitude;
63 63

  
64 64
    /**
65 65
     * Description
......
138 138
        this.bibliography = stringList.stream().map(s -> new Bibliography(s, this)).collect(Collectors.toSet());
139 139
    }
140 140

  
141
    private int processIntField(String field) {
141
    private Integer processIntField(String field) {
142 142
        Matcher matcher = Pattern.compile(INTEGER_PATTERN).matcher(field);
143 143
        if (matcher.find()) {
144 144
            return Integer.parseInt(matcher.group());
145 145
        } else {
146
            return 0;
146
            return null;
147 147
        }
148 148
    }
149 149

  
150
    private double processDoubleField(String field) {
150
    private Double processDoubleField(String field) {
151 151
        Matcher matcher = Pattern.compile(DOUBLE_PATTERN).matcher(field);
152 152
        if (matcher.find()) {
153 153
            return Double.parseDouble(matcher.group());
154 154
        } else {
155
            return 0.0;
155
            return null;
156 156
        }
157 157
    }
158 158

  
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItemDto.java
55 55
    /**
56 56
     * Longitude
57 57
     */
58
    private double longitude;
58
    private Double longitude;
59 59

  
60 60
    /**
61 61
     * Latitude
62 62
     */
63
    private double latitude;
63
    private Double latitude;
64 64

  
65 65
    /**
66 66
     * Certainty
67 67
     */
68
    private int certainty;
68
    private Integer certainty;
69 69

  
70 70
    /**
71 71
     * Description
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItemServiceImpl.java
14 14
import org.springframework.stereotype.Service;
15 15
import org.springframework.transaction.annotation.Transactional;
16 16

  
17
import java.util.*;
17
import java.util.ArrayList;
18
import java.util.List;
19
import java.util.Set;
20
import java.util.UUID;
18 21
import java.util.function.Predicate;
19 22
import java.util.regex.Matcher;
20 23
import java.util.regex.Pattern;
......
73 76
     */
74 77
    private static final String CATALOG_ITEM_NOT_FOUND = "Catalog item not found";
75 78

  
76
    /**
77
     * Threshold for comparing doubles
78
     */
79
    private static final double DOUBLE_THRESHOLD = 0.001;
80 79

  
81 80
    /**
82 81
     * Catalog repository
......
123 122
        log.info("Catalog item deleted");
124 123
    }
125 124

  
126
    private final Map<String, AlternativeName> map = new HashMap<>();
127

  
128 125
    @Override
129 126
    public CatalogItemDto getCatalogItem(UUID id) {
130 127
        CatalogItem catalogItem = catalogItemRepository.findById(id).orElseThrow(() -> {
......
171 168
            } else {
172 169
                List<CatalogItem> foundItems = catalogItemRepository.getItemsByName(textToFind);
173 170
                if (!foundItems.isEmpty()) {
174
                    if (foundItems.stream().anyMatch(c -> Math.abs(c.getLatitude()) > DOUBLE_THRESHOLD && Math.abs(c.getLongitude()) > DOUBLE_THRESHOLD)) {
171
                    if (foundItems.stream().anyMatch(c -> c.getLatitude() != null && c.getLongitude() != null)) {
175 172
                        textToFind = "<span style='color:green'>" + textToFind + "</span>";
176 173
                    } else {
177 174
                        textToFind = "<span style='color:red'>" + textToFind + "</span>";
backend/src/test/java/cz/zcu/kiv/backendapi/catalog/CatalogItemServiceImplFilterTest.java
96 96
        catalogItem1.setCountries(Set.of(new Country(countryAaa, catalogItem1), new Country(countryDcd, catalogItem1)));
97 97
        catalogItem1.setWrittenForms(Set.of(new WrittenForm(writtenForm, catalogItem1)));
98 98

  
99
        catalogItemDto1 = new CatalogItemDto(catalogItemId1, nameFirst, Collections.emptySet(), Set.of(writtenForm), Set.of(country, city), Set.of(countryAaa, countryDcd), Collections.emptySet(), 0.0, 0.0, 0, "");
99
        catalogItemDto1 = new CatalogItemDto(catalogItemId1, nameFirst, Collections.emptySet(), Set.of(writtenForm), Set.of(country, city), Set.of(countryAaa, countryDcd), Collections.emptySet(), null, null, null, "");
100 100

  
101 101
        catalogItem2.setName(nameSecond);
102 102
        catalogItem2.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem2), new AlternativeName(nameThird, catalogItem2)));
......
104 104
        catalogItem2.setCountries(Set.of(new Country(countryAaa, catalogItem2), new Country(countryBbb, catalogItem2)));
105 105
        catalogItem2.setWrittenForms(Set.of(new WrittenForm(writtenFormUpper, catalogItem2)));
106 106

  
107
        catalogItemDto2 = new CatalogItemDto(catalogItemId2, nameSecond, Set.of(nameTwelve, nameThird), Set.of(writtenFormUpper), Set.of(country, cityUpper), Set.of(countryAaa, countryBbb), Collections.emptySet(), 0.0, 0.0, 0, "");
107
        catalogItemDto2 = new CatalogItemDto(catalogItemId2, nameSecond, Set.of(nameTwelve, nameThird), Set.of(writtenFormUpper), Set.of(country, cityUpper), Set.of(countryAaa, countryBbb), Collections.emptySet(), null, null, null, "");
108 108

  
109 109
        catalogItem3.setName(nameThird);
110 110
        catalogItem3.setAlternativeNames(Set.of(new AlternativeName(nameTwentyUpper, catalogItem3), new AlternativeName(nameSedond, catalogItem3)));
......
112 112
        catalogItem3.setCountries(Set.of(new Country(countryAaaUpper, catalogItem3), new Country(countryCcc, catalogItem3)));
113 113
        catalogItem3.setWrittenForms(Set.of(new WrittenForm(writtenFormForOr, catalogItem3)));
114 114

  
115
        catalogItemDto3 = new CatalogItemDto(catalogItemId3, nameThird, Set.of(nameTwentyUpper, nameSedond), Set.of(writtenFormForOr), Set.of(countri, capitalCityNew), Set.of(countryAaaUpper, countryCcc), Collections.emptySet(), 0.0, 0.0, 0, "");
115
        catalogItemDto3 = new CatalogItemDto(catalogItemId3, nameThird, Set.of(nameTwentyUpper, nameSedond), Set.of(writtenFormForOr), Set.of(countri, capitalCityNew), Set.of(countryAaaUpper, countryCcc), Collections.emptySet(), null, null, null, "");
116 116

  
117 117
        catalogItem4.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem4), new AlternativeName(nameFirstUpper, catalogItem4)));
118 118
        catalogItem4.setTypes(Set.of(typeCountri, typeCountry));
119 119
        catalogItem4.setCountries(Set.of(new Country(countryBccb, catalogItem4), new Country(countryDdd, catalogItem4)));
120 120
        catalogItem4.setWrittenForms(Set.of(new WrittenForm(writtenForm, catalogItem4), new WrittenForm(writtenFormForOr, catalogItem4)));
121 121

  
122
        catalogItemDto4 = new CatalogItemDto(catalogItemId4, "", Set.of(nameTwelve, nameFirstUpper), Set.of(writtenForm, writtenFormForOr), Set.of(countri, country), Set.of(countryBccb, countryDdd), Collections.emptySet(), 0.0, 0.0, 0, "");
122
        catalogItemDto4 = new CatalogItemDto(catalogItemId4, "", Set.of(nameTwelve, nameFirstUpper), Set.of(writtenForm, writtenFormForOr), Set.of(countri, country), Set.of(countryBccb, countryDdd), Collections.emptySet(), null, null, null, "");
123 123

  
124 124
        catalogItem5.setName(nameSedond);
125 125
        catalogItem5.setAlternativeNames(Set.of(new AlternativeName(nameThird, catalogItem5)));
126 126
        catalogItem5.setTypes(Set.of(typeCountri));
127 127

  
128
        catalogItemDto5 = new CatalogItemDto(catalogItemId5, nameSedond, Set.of(nameThird), Collections.emptySet(), Set.of(countri), Collections.emptySet(), Collections.emptySet(), 0.0, 0.0, 0, "");
128
        catalogItemDto5 = new CatalogItemDto(catalogItemId5, nameSedond, Set.of(nameThird), Collections.emptySet(), Set.of(countri), Collections.emptySet(), Collections.emptySet(), null, null, null, "");
129 129

  
130 130
        given(catalogItemRepository.findAll()).willReturn(List.of(catalogItem1, catalogItem2, catalogItem3, catalogItem4, catalogItem5));
131 131
    }
backend/src/test/java/cz/zcu/kiv/backendapi/catalog/CatalogItemServiceImplTest.java
311 311

  
312 312
        CatalogItem catalogItem1 = new CatalogItem();
313 313
        catalogItem1.setAlternativeNames(Stream.of(new AlternativeName("Azbar", catalogItem1)).collect(Collectors.toSet()));
314
        catalogItem1.setLatitude(5);
315
        catalogItem1.setLongitude(5);
314
        catalogItem1.setLatitude(5.0);
315
        catalogItem1.setLongitude(5.0);
316 316

  
317 317
        CatalogItem catalogItem2 = new CatalogItem();
318 318
        catalogItem2.setAlternativeNames(Stream.of(new AlternativeName("Azbar", catalogItem2), new AlternativeName("Azbarasdf", catalogItem2)).collect(Collectors.toSet()));
319
        catalogItem2.setLatitude(0.0);
320
        catalogItem2.setLongitude(0.0);
319
        catalogItem2.setLatitude(null);
320
        catalogItem2.setLongitude(null);
321 321

  
322 322
        CatalogItem catalogItem3 = new CatalogItem();
323 323
        catalogItem3.setAlternativeNames(Stream.of(new AlternativeName("U-re-me-re", catalogItem3)).collect(Collectors.toSet()));
324
        catalogItem3.setLatitude(55);
325
        catalogItem3.setLongitude(68);
324
        catalogItem3.setLatitude(55.0);
325
        catalogItem3.setLongitude(68.0);
326 326

  
327 327
        CatalogItem catalogItem4 = new CatalogItem();
328 328
        catalogItem4.setAlternativeNames(Stream.of(new AlternativeName("Huga", catalogItem4)).collect(Collectors.toSet()));
329
        catalogItem4.setLatitude(0.0);
330
        catalogItem4.setLongitude(0.0);
329
        catalogItem4.setLatitude(null);
330
        catalogItem4.setLongitude(null);
331 331

  
332 332
        CatalogItem catalogItem5 = new CatalogItem();
333 333
        catalogItem5.setAlternativeNames(Stream.of(new AlternativeName("Huga", catalogItem5), new AlternativeName("Hugaa", catalogItem5)).collect(Collectors.toSet()));
334
        catalogItem5.setLatitude(0.0);
335
        catalogItem5.setLongitude(0.0);
334
        catalogItem5.setLatitude(null);
335
        catalogItem5.setLongitude(null);
336 336

  
337 337
        CatalogItem catalogItem6 = new CatalogItem();
338 338
        catalogItem6.setAlternativeNames(Stream.of(new AlternativeName("Duga", catalogItem6)).collect(Collectors.toSet()));
339
        catalogItem6.setLatitude(0.0);
340
        catalogItem6.setLongitude(0.0);
339
        catalogItem6.setLatitude(null);
340
        catalogItem6.setLongitude(null);
341 341

  
342 342
        CatalogItemDto catalogItemDto1 = new CatalogItemDto();
343 343
        catalogItemDto1.setId(catalogItem1.getId());
344 344
        catalogItemDto1.setAlternativeNames(Stream.of("Azbar").collect(Collectors.toSet()));
345
        catalogItemDto1.setLatitude(5);
346
        catalogItemDto1.setLongitude(5);
345
        catalogItemDto1.setLatitude(5.0);
346
        catalogItemDto1.setLongitude(5.0);
347 347

  
348 348
        CatalogItemDto catalogItemDto2 = new CatalogItemDto();
349 349
        catalogItemDto2.setId(catalogItem2.getId());
350 350
        catalogItemDto2.setAlternativeNames(Stream.of("Azbar", "Azbarasdf").collect(Collectors.toSet()));
351
        catalogItemDto2.setLatitude(0.0);
352
        catalogItemDto2.setLongitude(0.0);
351
        catalogItemDto2.setLatitude(null);
352
        catalogItemDto2.setLongitude(null);
353 353

  
354 354
        CatalogItemDto catalogItemDto3 = new CatalogItemDto();
355 355
        catalogItemDto3.setId(catalogItem3.getId());
356 356
        catalogItemDto3.setAlternativeNames(Stream.of("U-re-me-re").collect(Collectors.toSet()));
357
        catalogItemDto3.setLatitude(55);
358
        catalogItemDto3.setLongitude(68);
357
        catalogItemDto3.setLatitude(55.0);
358
        catalogItemDto3.setLongitude(68.0);
359 359

  
360 360
        CatalogItemDto catalogItemDto4 = new CatalogItemDto();
361 361
        catalogItemDto4.setId(catalogItem4.getId());
362 362
        catalogItemDto4.setAlternativeNames(Stream.of("Huga").collect(Collectors.toSet()));
363
        catalogItemDto4.setLatitude(0.0);
364
        catalogItemDto4.setLongitude(0.0);
363
        catalogItemDto4.setLatitude(null);
364
        catalogItemDto4.setLongitude(null);
365 365

  
366 366
        CatalogItemDto catalogItemDto5 = new CatalogItemDto();
367 367
        catalogItemDto5.setId(catalogItem5.getId());
368 368
        catalogItemDto5.setAlternativeNames(Stream.of("Huga", "Hugaa").collect(Collectors.toSet()));
369
        catalogItemDto5.setLatitude(0.0);
370
        catalogItemDto5.setLongitude(0.0);
369
        catalogItemDto5.setLatitude(null);
370
        catalogItemDto5.setLongitude(null);
371 371

  
372 372
        CatalogItemDto catalogItemDto6 = new CatalogItemDto();
373 373
        catalogItemDto6.setId(catalogItem6.getId());
374 374
        catalogItemDto6.setAlternativeNames(Stream.of("Duga").collect(Collectors.toSet()));
375
        catalogItemDto6.setLatitude(0.0);
376
        catalogItemDto6.setLongitude(0.0);
375
        catalogItemDto6.setLatitude(null);
376
        catalogItemDto6.setLongitude(null);
377 377

  
378 378

  
379 379
        given(typeService.getAllTypesAsString()).willReturn(Stream.of("city", "ocean").collect(Collectors.toSet()));
backend/src/test/resources/application.properties
8 8
spring.jpa.open-in-view=false
9 9
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect
10 10
spring.jpa.properties.hibernate.format_sql=true
11
spring.jpa.show-sql=true
11
spring.jpa.show-sql=false
12 12

  

Také k dispozici: Unified diff