Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
349 changes: 349 additions & 0 deletions memex/ClassDescription.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.johnlpage.memex.dto.PageDto;
import com.johnlpage.memex.model.UpdateStrategy;
import com.johnlpage.memex.util.UpdateStrategy;
import com.johnlpage.memex.model.Vehicle;
import com.johnlpage.memex.model.VehicleInspection;
import com.johnlpage.memex.repository.VehicleInspectionRepository;
Expand Down Expand Up @@ -164,9 +164,10 @@ public ResponseEntity<String> atlasSearchQuery(@RequestBody String requestBody)
public ResponseEntity<StreamingResponseBody> streamJson() {

return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(outputStream ->
writeDocumentsToOutputStream(outputStream, downstreamService.jsonExtractStream()));
.contentType(MediaType.APPLICATION_JSON)
.body(
outputStream ->
writeDocumentsToOutputStream(outputStream, downstreamService.jsonExtractStream()));
}

/**
Expand Down Expand Up @@ -195,10 +196,13 @@ public ResponseEntity<StreamingResponseBody> streamJsonNative() {
""";

return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(outputStream -> {
try (BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
Stream<JsonObject> stream = downstreamService.nativeJsonExtractStream(formatRequired)) {
.contentType(MediaType.APPLICATION_JSON)
.body(
outputStream -> {
try (BufferedOutputStream bufferedOutputStream =
new BufferedOutputStream(outputStream);
Stream<JsonObject> stream =
downstreamService.nativeJsonExtractStream(formatRequired)) {
boolean isFirst = true;
Iterator<JsonObject> iterator = stream.iterator();
while (iterator.hasNext()) {
Expand All @@ -210,19 +214,21 @@ public ResponseEntity<StreamingResponseBody> streamJsonNative() {
isFirst = false;
}
} catch (IOException e) {
LOG.error("Error during streaming jsonObjects using native mode: {}", e.getMessage());
LOG.error(
"Error during streaming jsonObjects using native mode: {}", e.getMessage());
}
});
}

@GetMapping(value = "/inspections/asOf", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<StreamingResponseBody> dataAtDate(
@RequestParam(name = "asOfDate") @DateTimeFormat(pattern = "yyyyMMddHHmmss") Date asOfDate,
@RequestParam(name = "id") Long id) {
@RequestParam(name = "asOfDate") @DateTimeFormat(pattern = "yyyyMMddHHmmss") Date asOfDate,
@RequestParam(name = "id") Long id) {
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(outputStream ->
writeDocumentsToOutputStream(outputStream, historyService.asOfDate(id, asOfDate)));
.contentType(MediaType.APPLICATION_JSON)
.body(
outputStream ->
writeDocumentsToOutputStream(outputStream, historyService.asOfDate(id, asOfDate)));
}

private void writeDocumentsToOutputStream(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.johnlpage.memex.model.UpdateStrategy;
import com.johnlpage.memex.util.UpdateStrategy;
import com.johnlpage.memex.model.VehicleInspection;
import com.johnlpage.memex.repository.optimized.OptimizedMongoLoadRepository;
import com.johnlpage.memex.service.VehicleInspectionInvalidDataHandlerService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.johnlpage.memex.model;

import com.fasterxml.jackson.annotation.*;
import com.johnlpage.memex.util.DeleteFlag;
import com.johnlpage.memex.util.ObjectConverter;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -43,7 +44,7 @@ public class VehicleInspection {
Vehicle vehicle;
String files;

@Min(49)
@Min(1)
Long capacity;

Date firstusedate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface VehicleInspectionRepository
*
*
// Find inspections by engine capacity - auto generated query
List<VehicleInspection> findByCapacityGreaterThan(Long engineCapacity);
List<VehicleInspection> findAllByCapacityGreaterThan(Long engineCapacity);

// Custom query to find vehicle inspections by vehicle make and model
@Query("{ 'vehicle.make': ?0, 'vehicle.model': ?1 }")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.johnlpage.memex.repository.optimized;

import com.johnlpage.memex.model.UpdateStrategy;
import com.johnlpage.memex.util.UpdateStrategy;
import com.johnlpage.memex.service.generic.InvalidDataHandlerService;
import com.johnlpage.memex.service.generic.PostWriteTriggerService;
import com.mongodb.bulk.BulkWriteResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static com.johnlpage.memex.util.AnnotationExtractor.*;
import static org.springframework.data.mongodb.core.query.Criteria.where;

import com.johnlpage.memex.model.UpdateStrategy;
import com.johnlpage.memex.util.UpdateStrategy;
import com.johnlpage.memex.service.generic.InvalidDataHandlerService;
import com.johnlpage.memex.service.generic.PostWriteTriggerService;
import com.mongodb.bulk.BulkWriteInsert;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.johnlpage.memex.model.UpdateStrategy;
import com.johnlpage.memex.util.UpdateStrategy;
import com.johnlpage.memex.repository.optimized.OptimizedMongoLoadRepository;
import com.mongodb.bulk.BulkWriteResult;
import jakarta.annotation.Nullable;
Expand All @@ -24,17 +24,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;

@Service
@RequiredArgsConstructor
public abstract class MongoDbJsonStreamingLoaderService<T> {

private static final Logger LOG =
LoggerFactory.getLogger(MongoDbJsonStreamingLoaderService.class);
private static final int BATCH_SIZE = 200;
private final OptimizedMongoLoadRepository<T> repository;
private final ObjectMapper objectMapper;
private final JsonFactory jsonFactory;
Expand Down Expand Up @@ -79,7 +76,7 @@ public JsonStreamingLoadResponse loadFromJsonStream(
count++;

toSave.add(document);
if (toSave.size() >= 100) {
if (toSave.size() >= BATCH_SIZE) {
List<T> copyOfToSave = List.copyOf(toSave);
toSave.clear();
futures.add(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.johnlpage.memex.util;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.johnlpage.memex.model.DeleteFlag;
import jakarta.annotation.Nullable;
import java.lang.reflect.Field;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.johnlpage.memex.model;
package com.johnlpage.memex.util;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.johnlpage.memex.controller;
package com.johnlpage.memex.util;

import org.apache.catalina.connector.ClientAbortException;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.johnlpage.memex.model;
package com.johnlpage.memex.util;

/**
* This IS used to set whether we are using a simple replace ro a recursive field update to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void sendVehicleInspectionsToKafka(int count, long startId, String jsonTe
vehicleInspection.setTestid(testId);

String message = objectMapper.writeValueAsString(vehicleInspection);
kafkaTemplate.send("test", message);
kafkaTemplate.send("test", message); // test
}
}

Expand Down
5 changes: 2 additions & 3 deletions memex/src/test/resources/application-test.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#Keep this empty if you want tests to use Mongo test container
#spring.data.mongodb.uri=mongodb://localhost:63650
spring.data.mongodb.uri=
spring.data.mongodb.database=memex
spring.data.mongodb.database=memextest
memex.kafkaexmple.enabled=true

# To run tests against non-local environment, override memex.base-url with the actual URL of the server under test.
memex.base-url=http://localhost:${local.server.port}

memex.test.data.vehicleinspection-testid-range.start=10000
memex.test.data.vehicleinspection-testid-range.end=11000
Loading