Skip to content

Commit 677fc01

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents d87d3e6 + 92e7c0e commit 677fc01

13 files changed

Lines changed: 383 additions & 30 deletions

memex/ClassDescription.md

Lines changed: 349 additions & 0 deletions
Large diffs are not rendered by default.

memex/src/main/java/com/johnlpage/memex/controller/VehicleInspectionController.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.johnlpage.memex.dto.PageDto;
6-
import com.johnlpage.memex.model.UpdateStrategy;
6+
import com.johnlpage.memex.util.UpdateStrategy;
77
import com.johnlpage.memex.model.Vehicle;
88
import com.johnlpage.memex.model.VehicleInspection;
99
import com.johnlpage.memex.repository.VehicleInspectionRepository;
@@ -164,9 +164,10 @@ public ResponseEntity<String> atlasSearchQuery(@RequestBody String requestBody)
164164
public ResponseEntity<StreamingResponseBody> streamJson() {
165165

166166
return ResponseEntity.ok()
167-
.contentType(MediaType.APPLICATION_JSON)
168-
.body(outputStream ->
169-
writeDocumentsToOutputStream(outputStream, downstreamService.jsonExtractStream()));
167+
.contentType(MediaType.APPLICATION_JSON)
168+
.body(
169+
outputStream ->
170+
writeDocumentsToOutputStream(outputStream, downstreamService.jsonExtractStream()));
170171
}
171172

172173
/**
@@ -195,10 +196,13 @@ public ResponseEntity<StreamingResponseBody> streamJsonNative() {
195196
""";
196197

197198
return ResponseEntity.ok()
198-
.contentType(MediaType.APPLICATION_JSON)
199-
.body(outputStream -> {
200-
try (BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
201-
Stream<JsonObject> stream = downstreamService.nativeJsonExtractStream(formatRequired)) {
199+
.contentType(MediaType.APPLICATION_JSON)
200+
.body(
201+
outputStream -> {
202+
try (BufferedOutputStream bufferedOutputStream =
203+
new BufferedOutputStream(outputStream);
204+
Stream<JsonObject> stream =
205+
downstreamService.nativeJsonExtractStream(formatRequired)) {
202206
boolean isFirst = true;
203207
Iterator<JsonObject> iterator = stream.iterator();
204208
while (iterator.hasNext()) {
@@ -210,19 +214,21 @@ public ResponseEntity<StreamingResponseBody> streamJsonNative() {
210214
isFirst = false;
211215
}
212216
} catch (IOException e) {
213-
LOG.error("Error during streaming jsonObjects using native mode: {}", e.getMessage());
217+
LOG.error(
218+
"Error during streaming jsonObjects using native mode: {}", e.getMessage());
214219
}
215220
});
216221
}
217222

218223
@GetMapping(value = "/inspections/asOf", produces = MediaType.APPLICATION_JSON_VALUE)
219224
public ResponseEntity<StreamingResponseBody> dataAtDate(
220-
@RequestParam(name = "asOfDate") @DateTimeFormat(pattern = "yyyyMMddHHmmss") Date asOfDate,
221-
@RequestParam(name = "id") Long id) {
225+
@RequestParam(name = "asOfDate") @DateTimeFormat(pattern = "yyyyMMddHHmmss") Date asOfDate,
226+
@RequestParam(name = "id") Long id) {
222227
return ResponseEntity.ok()
223-
.contentType(MediaType.APPLICATION_JSON)
224-
.body(outputStream ->
225-
writeDocumentsToOutputStream(outputStream, historyService.asOfDate(id, asOfDate)));
228+
.contentType(MediaType.APPLICATION_JSON)
229+
.body(
230+
outputStream ->
231+
writeDocumentsToOutputStream(outputStream, historyService.asOfDate(id, asOfDate)));
226232
}
227233

228234
private void writeDocumentsToOutputStream(

memex/src/main/java/com/johnlpage/memex/kafka/VehicleInspectionKafkaConsumer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.fasterxml.jackson.core.JsonFactory;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5-
import com.johnlpage.memex.model.UpdateStrategy;
5+
import com.johnlpage.memex.util.UpdateStrategy;
66
import com.johnlpage.memex.model.VehicleInspection;
77
import com.johnlpage.memex.repository.optimized.OptimizedMongoLoadRepository;
88
import com.johnlpage.memex.service.VehicleInspectionInvalidDataHandlerService;

memex/src/main/java/com/johnlpage/memex/model/VehicleInspection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.johnlpage.memex.model;
22

33
import com.fasterxml.jackson.annotation.*;
4+
import com.johnlpage.memex.util.DeleteFlag;
45
import com.johnlpage.memex.util.ObjectConverter;
56
import java.util.Date;
67
import java.util.HashMap;
@@ -43,7 +44,7 @@ public class VehicleInspection {
4344
Vehicle vehicle;
4445
String files;
4546

46-
@Min(49)
47+
@Min(1)
4748
Long capacity;
4849

4950
Date firstusedate;

memex/src/main/java/com/johnlpage/memex/repository/VehicleInspectionRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface VehicleInspectionRepository
2525
*
2626
*
2727
// Find inspections by engine capacity - auto generated query
28-
List<VehicleInspection> findByCapacityGreaterThan(Long engineCapacity);
28+
List<VehicleInspection> findAllByCapacityGreaterThan(Long engineCapacity);
2929
3030
// Custom query to find vehicle inspections by vehicle make and model
3131
@Query("{ 'vehicle.make': ?0, 'vehicle.model': ?1 }")

memex/src/main/java/com/johnlpage/memex/repository/optimized/OptimizedMongoLoadRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.johnlpage.memex.repository.optimized;
22

3-
import com.johnlpage.memex.model.UpdateStrategy;
3+
import com.johnlpage.memex.util.UpdateStrategy;
44
import com.johnlpage.memex.service.generic.InvalidDataHandlerService;
55
import com.johnlpage.memex.service.generic.PostWriteTriggerService;
66
import com.mongodb.bulk.BulkWriteResult;

memex/src/main/java/com/johnlpage/memex/repository/optimized/OptimizedMongoLoadRepositoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import static com.johnlpage.memex.util.AnnotationExtractor.*;
44
import static org.springframework.data.mongodb.core.query.Criteria.where;
55

6-
import com.johnlpage.memex.model.UpdateStrategy;
6+
import com.johnlpage.memex.util.UpdateStrategy;
77
import com.johnlpage.memex.service.generic.InvalidDataHandlerService;
88
import com.johnlpage.memex.service.generic.PostWriteTriggerService;
99
import com.mongodb.bulk.BulkWriteInsert;

memex/src/main/java/com/johnlpage/memex/service/generic/MongoDbJsonStreamingLoaderService.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.fasterxml.jackson.core.JsonToken;
66
import com.fasterxml.jackson.databind.JsonNode;
77
import com.fasterxml.jackson.databind.ObjectMapper;
8-
import com.johnlpage.memex.model.UpdateStrategy;
8+
import com.johnlpage.memex.util.UpdateStrategy;
99
import com.johnlpage.memex.repository.optimized.OptimizedMongoLoadRepository;
1010
import com.mongodb.bulk.BulkWriteResult;
1111
import jakarta.annotation.Nullable;
@@ -24,17 +24,14 @@
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
2626
import org.springframework.stereotype.Service;
27-
import jakarta.validation.ConstraintViolation;
28-
import jakarta.validation.Validation;
29-
import jakarta.validation.Validator;
30-
import jakarta.validation.ValidatorFactory;
3127

3228
@Service
3329
@RequiredArgsConstructor
3430
public abstract class MongoDbJsonStreamingLoaderService<T> {
3531

3632
private static final Logger LOG =
3733
LoggerFactory.getLogger(MongoDbJsonStreamingLoaderService.class);
34+
private static final int BATCH_SIZE = 200;
3835
private final OptimizedMongoLoadRepository<T> repository;
3936
private final ObjectMapper objectMapper;
4037
private final JsonFactory jsonFactory;
@@ -79,7 +76,7 @@ public JsonStreamingLoadResponse loadFromJsonStream(
7976
count++;
8077

8178
toSave.add(document);
82-
if (toSave.size() >= 100) {
79+
if (toSave.size() >= BATCH_SIZE) {
8380
List<T> copyOfToSave = List.copyOf(toSave);
8481
toSave.clear();
8582
futures.add(

memex/src/main/java/com/johnlpage/memex/util/AnnotationExtractor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.johnlpage.memex.util;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4-
import com.johnlpage.memex.model.DeleteFlag;
54
import jakarta.annotation.Nullable;
65
import java.lang.reflect.Field;
76
import java.util.HashMap;

memex/src/main/java/com/johnlpage/memex/model/DeleteFlag.java renamed to memex/src/main/java/com/johnlpage/memex/util/DeleteFlag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.johnlpage.memex.model;
1+
package com.johnlpage.memex.util;
22

33
import java.lang.annotation.ElementType;
44
import java.lang.annotation.Retention;

0 commit comments

Comments
 (0)