Skip to content

stablekernel/menu-json-validator-demo

Repository files navigation

Menu JSON Validator Demo

A Java application for validating and comparing menu JSON documents from AWS S3, supporting both Spotlight and Digital Communications menu formats.

menu_diff_validator_flow

Features

  • Multi-Format Support: Validates both Spotlight and Digital Communications board menus
  • Deep Comparison: Performs recursive field-by-field comparison to detect differences
  • Hash-Based Optimization: Skips comparison if menu hash codes match
  • AWS S3 Integration: Fetch menu JSON files directly from S3 buckets
  • Comprehensive Logging: Detailed logging of validation results and differences
  • Flexible Models: Lombok-powered models supporting multiple menu types

Technologies

  • Java 21 (LTS)
  • Spring Boot 3.4.3
  • Jackson 2.15+ - JSON processing
  • Lombok 1.18.30 - Boilerplate reduction
  • AWS SDK 2.20.26 - S3 integration
  • Gradle 8.14 - Build automation
  • JUnit 5 & AssertJ - Testing

Project Structure

src/
├── main/java/com/menu/validator/
│   ├── model/              # Domain models
│   │   ├── MenuDocument.java
│   │   ├── MenuItem.java
│   │   ├── Item.java
│   │   ├── ItemGrouping.java
│   │   ├── Modifier.java
│   │   ├── ModifierGrouping.java
│   │   └── GeneratedMetadata.java
│   ├── enums/              # Enumerations
│   │   ├── ObjectType.java
│   │   └── ItemTypeTag.java
│   ├── util/               # Utilities
│   │   └── S3Helper.java   # AWS S3 integration
│   └── examples/           # Usage examples
│       └── S3HelperExample.java
└── test/
    └── java/com/menu/validator/
        ├── validators/
        │   └── SpotlightMenuValidatorTest.java
        └── util/
            └── S3HelperTest.java

Quick Start

Prerequisites

  1. Java 21: Ensure Java 21 is installed

    java -version  # Should show Java 21
  2. AWS Credentials (for S3 integration): Configure ~/.aws/credentials

    [default]
    aws_access_key_id = YOUR_ACCESS_KEY
    aws_secret_access_key = YOUR_SECRET_KEY

Build

./gradlew build

Run Tests

# Run all tests
./gradlew test

# Run specific test
./gradlew test --tests SpotlightMenuValidatorTest
./gradlew test --tests S3HelperTest

S3 Helper Usage

The S3Helper class enables fetching JSON files from AWS S3 buckets.

Basic Example

import com.fasterxml.jackson.databind.JsonNode;
import com.menu.validator.util.S3Helper;

S3Helper s3Helper = new S3Helper();

// Fetch JSON from S3
String s3Path = "s3://my-bucket/menus/menu.json";
JsonNode json = s3Helper.fetchJsonFromS3(s3Path);

// Access JSON data
String location = json.get("location").asText();
int categories = json.get("categories").size();

Advanced Usage

import software.amazon.awssdk.regions.Region;

S3Helper s3Helper = new S3Helper();

// Fetch with custom profile and region
JsonNode json = s3Helper.fetchJsonFromS3(
    "s3://prod-bucket/menu.json",
    "production",      // AWS profile name
    Region.US_WEST_2   // AWS region
);

See S3_HELPER_USAGE.md for comprehensive documentation.

Menu Validation

The validator compares menu documents and detects differences:

import com.fasterxml.jackson.databind.ObjectMapper;
import com.menu.validator.model.MenuDocument;

ObjectMapper mapper = new ObjectMapper()
    .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)
    .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

// Load menus
MenuDocument before = mapper.readValue(new File("before.json"), MenuDocument.class);
MenuDocument after = mapper.readValue(new File("after.json"), MenuDocument.class);

// Compare hashes
String hashBefore = before.getGenerated().getMenuPublishing().getMenuHashCode();
String hashAfter = after.getGenerated().getMenuPublishing().getMenuHashCode();

if (!hashBefore.equals(hashAfter)) {
    // Perform deep comparison
    // See SpotlightMenuValidatorTest for full example
}

Supported Menu Types

Spotlight Menus

  • Location-specific loyalty menus
  • Rich metadata (images, descriptions, pricing)
  • Object types: ITEM, ITEM_GROUPING
  • Offer types: spotlight-specific promotions

Digital Communications Menus

  • Digital board/kiosk menus
  • Modifier support for customization
  • Object types: ITEM, ITEM_GROUPING, MODIFIER, MODIFIER_GROUPING
  • Day part and meal configuration

Model Hierarchy

MenuDocument
├── location: String
├── language: String
├── country: String
├── destination: String
├── destinationType: String
├── categories: List<MenuItem>
└── generated: GeneratedMetadata
    └── menuPublishing
        ├── menuHashCode: String
        └── rawHashCode: String

MenuItem (abstract)
├── Item
├── ItemGrouping
├── Modifier
└── ModifierGrouping

Configuration

Java Version

Set Java 21 for Gradle:

export JAVA_HOME=$(/usr/libexec/java_home -v 21)
./gradlew build

Or use the wrapper with explicit Java home:

env JAVA_HOME="/path/to/java-21" ./gradlew build

AWS Region

Default region is us-east-1. Override in code:

import software.amazon.awssdk.regions.Region;

s3Helper.fetchJsonFromS3(path, "default", Region.US_WEST_2);

Examples

See the examples package for complete usage examples:

  • S3HelperExample.java - S3 integration examples

Testing

Unit Tests

# Run all tests
./gradlew test

# Run with coverage
./gradlew test jacocoTestReport

Integration Tests

For S3 integration tests, ensure valid AWS credentials are configured:

# Set credentials in ~/.aws/credentials
# Then run tests
./gradlew test --tests S3HelperTest

Troubleshooting

Java Version Issues

If you see "Unsupported class file major version 69":

# Check Java version
java -version

# Should be Java 21. If not, set JAVA_HOME:
export JAVA_HOME=$(/usr/libexec/java_home -v 21)

AWS Credentials

If you see "AWS credentials file not found":

  1. Create ~/.aws/credentials file
  2. Add your AWS credentials
  3. Verify file permissions: chmod 600 ~/.aws/credentials

Gradle Issues

If Gradle wrapper fails:

# Re-download wrapper
curl -L -o gradle/wrapper/gradle-wrapper.jar \
  https://raw.githubusercontent.com/gradle/gradle/v8.14.0/gradle/wrapper/gradle-wrapper.jar

# Make executable
chmod +x gradlew

License

[Specify your license here]

Contributing

[Add contribution guidelines here]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •