This commit is contained in:
2025-10-26 22:43:30 -04:00
parent 8cf15672d6
commit 1ee497dd99
50 changed files with 1243 additions and 0 deletions

3
App/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"java.dependency.packagePresentation": "hierarchical"
}

41
App/build.gradle Normal file
View File

@@ -0,0 +1,41 @@
/*
* This file was generated by the Gradle 'init' task.
*
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'java'
id 'application'
}
// Apply a specific Java toolchain to ease working on different environments.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(24)
}
}
application {
// Define the main class for the application.
mainClass = 'edu.inventorym.RpcDeserializer'
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
implementation 'io.helidon:helidon:4.3.1'
implementation 'io.helidon.common:helidon-common:4.3.1'
implementation 'io.helidon.media:helidon-media-jsonb:3.2.12'
implementation 'io.helidon.media.jsonb:helidon-media-jsonb-common:1.4.16'
implementation 'io.helidon.media.jsonb:helidon-media-jsonb-server:1.4.16'
implementation 'jakarta.json.bind:jakarta.json.bind-api:3.0.1'
implementation 'io.helidon.webserver:helidon-webserver:4.3.1'
}

94
App/gradlew.bat vendored Normal file
View File

@@ -0,0 +1,94 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@@ -0,0 +1,30 @@
/*
* This source file was generated by the Gradle 'init' task
*/
package edu.inventorym;
import io.helidon.http.Status;
import io.helidon.webserver.WebServer;
import io.helidon.webserver.http.HttpRouting;
public class App{
public static void main(String[] args) {
WebServer.builder()
.routing(App::routing)
.build()
.start();
}
private static void routing(HttpRouting.Builder rules) {
rules.get("/hello", (req, res) -> res.send("Hello, World!"))
.get("/greet/{name}", (req, res) -> {
String name = req.path().pathParameters().get("name");
res.send("Hello, " + name + "!");
})
.post("/data", (req, res) -> {
String body = req.content().as(String.class);
res.send("Received: " + body);
});
}
}

View File

@@ -0,0 +1,83 @@
package edu.inventorym;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import edu.inventorym.model.Drawing;
import edu.inventorym.model.InventoryPiece;
import jakarta.json.JsonArray;
import jakarta.json.Json;
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
public class RpcDeserializer {
public static void main(String[] args) {
String jsonResponse = "{\"jsonrpc\":\"2.0\",\"result\":19,\"id\":1}";
try{
// Deserialize the JSON string to a Java RpcResponse object
Jsonb jsonb = JsonbBuilder.create();
jsonResponse = jsonb.toJson(new Drawing());
System.out.println("json string: " + jsonResponse);
InventoryPiece response = jsonb.fromJson(jsonResponse, Drawing.class);
System.out.println("Result: " + response);
System.out.println("ID: " + response.getId());
}catch(Exception e){
e.printStackTrace();
}
List<Drawing> rpcs = new ArrayList<Drawing>();
try{
// Configure pretty-printing and other settings
JsonbConfig config = new JsonbConfig()
.withFormatting(true); // Enable pretty-printing
Jsonb jsonb = JsonbBuilder.create(config);
// Serialize using the custom configuration
String prettyJsonString = jsonb.toJson(new Drawing());
System.out.println("json string: " + prettyJsonString);
rpcs.add(new Drawing());
}catch(Exception e){
}
try {
// Create Jsonb and serialize
Jsonb jsonb = JsonbBuilder.create();
String result = jsonb.toJson(rpcs);
// Deserialize back
rpcs = jsonb.fromJson(result, new ArrayList<Drawing>() {
}.getClass().getGenericSuperclass());
} catch (Exception e) {
}
}
public static <T> List<T> mapJsonToObjectList(String body, Class<T> baseClass) {
try (var reader = Json.createReader(new StringReader(body));
Jsonb jsonb = JsonbBuilder.create()){
JsonArray jsonArray = reader.readArray();
return jsonArray.stream()
.map(jsonValue -> jsonb.fromJson(jsonValue.toString(), baseClass))
.toList();
} catch (Exception e) {
return (List<T>) new ArrayList<Drawing>();
}
}
}

View File

@@ -0,0 +1,13 @@
package edu.inventorym.model;
public class Customer {
String nameFirst;
String nameLast;
String mailing;
String phone;
String email;
public Customer(){}
}

View File

@@ -0,0 +1,5 @@
package edu.inventorym.model;
public class CustomerList {
}

View File

@@ -0,0 +1,5 @@
package edu.inventorym.model;
public class CustomerManager {
}

View File

@@ -0,0 +1,12 @@
package edu.inventorym.model;
public class Drawing extends InventoryPiece {
public String style;
public String technique;
public String category;
public Drawing() {
super(InventoryType.DRAWING);
}
}

View File

@@ -0,0 +1,15 @@
package edu.inventorym.model;
public class InvalidArtOperationException extends RuntimeException {
public InvalidArtOperationException(String message) {
super(message);
}
public InvalidArtOperationException(String message, Throwable cause) {
super(message, cause);
}
public InvalidArtOperationException(Throwable cause) {
super(cause);
}
}

View File

@@ -0,0 +1,17 @@
package edu.inventorym.model;
public class InvalidTransOperationException extends RuntimeException {
public InvalidTransOperationException(String message) {
super(message);
}
public InvalidTransOperationException(String message, Throwable cause) {
super(message, cause);
}
public InvalidTransOperationException(Throwable cause) {
super(cause);
}
}

View File

@@ -0,0 +1,17 @@
package edu.inventorym.model;
public class InvalidTransactionException extends RuntimeException {
public InvalidTransactionException(String message) {
super(message);
}
public InvalidTransactionException(String message, Throwable cause) {
super(message, cause);
}
public InvalidTransactionException(Throwable cause) {
super(cause);
}
}

View File

@@ -0,0 +1,9 @@
package edu.inventorym.model;
import java.util.ArrayList;
public class InventoryList extends ArrayList<InventoryPiece> {
public InventoryList() {
super();
}
}

View File

@@ -0,0 +1,25 @@
package edu.inventorym.model;
import java.util.EnumSet;
import java.util.Set;
public class InventoryManager {
final static InventoryManager INSTANCE = new InventoryManager();
public static InventoryManager getInstance() {
return INSTANCE;
}
public InventoryList INVENTORY = new InventoryList();
public CustomerList CUSTOMERS = new CustomerList();
public TransactionList TRANSACTIONS = new TransactionList();
private InventoryManager() {
}
public Set<InventoryType> getArtPieceTypes(){
return EnumSet.allOf(InventoryType.class);
}
}

View File

@@ -0,0 +1,84 @@
package edu.inventorym.model;
import java.time.ZonedDateTime;
public abstract class InventoryPiece {
public String Id;
public float price;
public ZonedDateTime created;
public String title;
/**
* max 500 characters
*/
public String description;
public String Author;
InventoryType iventoryType;
public InventoryPiece(InventoryType iventoryType) {
this.iventoryType = iventoryType;
this.created = ZonedDateTime.now();
this.Id = TransactionManager.generateTransactionRandomID(10);
}
public InventoryPiece() {
}
public Boolean isArt(InventoryPiece piece) {
return false;
}
public String getType() {
return this.iventoryType.toString();
};
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public ZonedDateTime getCreated() {
return created;
}
public void setCreated(ZonedDateTime created) {
this.created = created;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getAuthor() {
return Author;
}
public void setAuthor(String author) {
Author = author;
}
}

View File

@@ -0,0 +1,5 @@
package edu.inventorym.model;
public enum InventoryType {
PAINTING, DRAWING, PRINT, SCULPTURE
}

View File

@@ -0,0 +1,14 @@
package edu.inventorym.model;
public class Painting extends InventoryPiece {
int height;
int width;
String style;
String technique;
String category;
public Painting (){
super(InventoryType.PAINTING);
}
}

View File

@@ -0,0 +1,11 @@
package edu.inventorym.model;
public class Print extends InventoryPiece {
String openEditionType;
String category;
public Print(){
super(InventoryType.PRINT);
}
}

View File

@@ -0,0 +1,12 @@
package edu.inventorym.model;
public class Sculpture extends InventoryPiece {
String material;
float weight;
public Sculpture (){
super(InventoryType.SCULPTURE);
}
}

View File

@@ -0,0 +1,8 @@
package edu.inventorym.model;
import java.time.ZonedDateTime;
public class Transaction {
ZonedDateTime created = ZonedDateTime.now();
ZonedDateTime completed = null;
}

View File

@@ -0,0 +1,5 @@
package edu.inventorym.model;
public class TransactionList {
}

View File

@@ -0,0 +1,14 @@
package edu.inventorym.model;
import java.security.SecureRandom;
import java.util.Base64;
public class TransactionManager {
final public static String generateTransactionRandomID(int byteLength) {
SecureRandom secureRandom = new SecureRandom();
byte[] bytes = new byte[byteLength];
secureRandom.nextBytes(bytes);
return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
}
}