This commit is contained in:
2025-10-30 13:13:30 -04:00
parent 731dd2b991
commit f81d6ebd0e
5 changed files with 161 additions and 73 deletions

View File

@@ -34,15 +34,18 @@ public interface Api {
* is not already in the inventory before adding
*/
/* Inventory pieces */
InventoryManager.getInstance().load();
if (InventoryManager.getInstance().INVENTORY.isEmpty()) {
/* Add Inventory */
InventoryManager.getInstance().add(make(new Drawing()));
InventoryManager.getInstance().add(make(new Print()));
InventoryManager.getInstance().add(make(new Painting()));
InventoryManager.getInstance().add(make(new Sculpture()));
InventoryManager.getInstance().add(make(new Sculpture()));
InventoryManager.getInstance().add(make(new Sculpture()));
}
/* Customers */
CustomerManager.getInstance().load();
if (CustomerManager.getInstance().CUSTOMERS.isEmpty()) {
/* Add Customer */
@@ -62,17 +65,25 @@ public interface Api {
InventoryPiece art = imgr.INVENTORY.getLast();
InventoryPiece piece = imgr.find(art.getId());
imgr.Remove(piece);
imgr.save();
System.out.println(String.format("Removed 1 Art Pieces from INVENTORY: count %d", imgr.INVENTORY.size()));
/*
* 3. Return a list of all art objects from inventory
*/
System.out.println( "============= Inventory List ===============");
System.out.println("============= Inventory List ===============");
imgr.INVENTORY.forEach(System.out::println);
System.out.println( "\n");
System.out.println("\n");
if (imgr.INVENTORY.isEmpty()) {
System.out.println(String.format("%s: No Inventoried Art Piecies Available !!!. ", Api.class));
return;
}
CustomerManager cmgr = CustomerManager.getInstance();
Customer customer = cmgr.findByEmail("kate@museum.com");
InventoryList customerCart = new InventoryList();
customerCart.add(imgr.INVENTORY.getFirst());
customerCart.add(imgr.INVENTORY.getLast());
TransactionManager tmgr = TransactionManager.getInstance();

View File

@@ -1,56 +0,0 @@
[
{
"Author": "Dave Janson",
"author": "Dave Janson",
"created": "2025-10-30T10:47:09.3038539-04:00[America/New_York]",
"description": "East Market Square find. Local Author.",
"id": "4187213045",
"price": 10.99,
"title": "Windy Rowing",
"type": "DRAWING"
},
{
"Author": "Dave Janson",
"author": "Dave Janson",
"created": "2025-10-30T10:47:13.3647577-04:00[America/New_York]",
"description": "East Market Square find. Local Author.",
"id": "3284384487",
"price": 10.99,
"title": "Different day same thing",
"type": "PRINT"
},
{
"Author": "Dave Janson",
"author": "Dave Janson",
"created": "2025-10-30T10:47:14.3174866-04:00[America/New_York]",
"description": "East Market Square find. Local Author.",
"id": "3420570978",
"price": 10.99,
"title": "Walking by the beach.",
"type": "PAINTING",
"height": 0,
"width": 0
},
{
"Author": "Dave Janson",
"author": "Dave Janson",
"created": "2025-10-30T10:47:14.9196999-04:00[America/New_York]",
"description": "East Market Square find. Local Author.",
"id": "4652544628",
"price": 10.99,
"title": "Jolly Romp",
"type": "SCULPTURE",
"weight": 1.0
},
{
"Author": "Dave Janson",
"author": "Dave Janson",
"created": "2025-10-30T10:47:15.4510495-04:00[America/New_York]",
"description": "East Market Square find. Local Author.",
"id": "3160354998",
"price": 10.99,
"title": "Jolly Romp",
"type": "SCULPTURE",
"weight": 1.0
}
]

View File

@@ -15,12 +15,15 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import jakarta.json.Json;
import jakarta.json.JsonArray;
import jakarta.json.JsonException;
import jakarta.json.JsonObject;
import jakarta.json.JsonValue;
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
@@ -144,11 +147,39 @@ public class DataRepository {
result = in.readAllAsString();
}
List<InventoryPiece> inventory = mapJsonToObjectList(result, InventoryPiece.class);
List<InventoryPiece> inventory;
try (var reader = Json.createReader(new StringReader(result));
Jsonb jsonb = JsonbBuilder.create()) {
JsonArray jsonArray = reader.readArray();
inventory = new ArrayList<InventoryPiece>();
jsonArray.forEach(item -> {
try {
switch (item.asJsonObject().getString("type")) {
case "DRAWING":
inventory.add(jsonb.fromJson(item.toString(), Drawing.class));
break;
case "PAINTING":
inventory.add(jsonb.fromJson(item.toString(), Painting.class));
break;
case "PRINT":
inventory.add(jsonb.fromJson(item.toString(), Print.class));
break;
case "SCULPTURE":
inventory.add(jsonb.fromJson(item.toString(), Sculpture.class));
break;
}
} catch (Exception e) {
e.printStackTrace();
}
});
manager.INVENTORY.clear();
manager.INVENTORY.addAll(inventory);
}
}
public final static class getRepositoryConfig {
public final static String getPath() {

View File

@@ -4,6 +4,7 @@
*/
package edu.inventorym.model;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.EnumSet;
import java.util.Set;
@@ -50,6 +51,8 @@ public class InventoryManager {
public void load() {
try {
DataRepository.WalkFileSystemTree(this);
} catch (FileNotFoundException e) {
System.out.println(String.format("INVENTORY: %s", e.getLocalizedMessage().toString()));
} catch (Exception e) {
e.printStackTrace();
}

99
uml/classdiagram3.dot Normal file
View File

@@ -0,0 +1,99 @@
digraph InventoryManagementSystem {
rankdir=TB;
node [shape=record, fontname="Arial", fontsize=10];
edge [fontname="Arial", fontsize=9];
// Core Model Classes
Address [label="{Address|+ street: String\l+ city: String\l+ state: String\l+ zip: String\l|+ getStreet(): String\l+ setStreet(String): void\l+ getCity(): String\l+ setCity(String): void\l+ getState(): String\l+ setState(String): void\l+ getZip(): String\l+ setZip(String): void\l+ hashCode(): int\l+ equals(Object): boolean\l+ toString(): String\l}"];
Customer [label="{Customer|# id: String\l# updated: ZonedDateTime\l- phone: String\l- mailing: Address\l- email: String\l- nameFirst: String\l- nameLast: String\l|+ Customer(String, String, String, String)\l+ getId(): String\l+ setId(String): void\l+ getPhone(): String\l+ setPhone(String): void\l+ getMailing(): Address\l+ setMailing(Address): void\l+ getEmail(): String\l+ setEmail(String): void\l+ getNameFirst(): String\l+ setNameFirst(String): void\l+ getNameLast(): String\l+ setNameLast(String): void\l}"];
InventoryPiece [label="{«abstract»\lInventoryPiece|+ id: String\l+ price: float\l+ created: ZonedDateTime\l+ title: String\l+ description: String\l+ Author: String\l|+ InventoryPiece()\l+ getType(): String\l+ getId(): String\l+ setId(String): void\l+ getPrice(): float\l+ setPrice(float): void\l+ getCreated(): ZonedDateTime\l+ setCreated(ZonedDateTime): void\l+ getTitle(): String\l+ setTitle(String): void\l+ getDescription(): String\l+ setDescription(String): void\l+ getAuthor(): String\l+ setAuthor(String): void\l+ «abstract» computePrice(): float\l}"];
Drawing [label="{Drawing|+ style: String\l+ technique: String\l+ category: String\l|+ Drawing()\l+ computePrice(): float\l}"];
Painting [label="{Painting|- height: int\l- width: int\l- style: String\l- technique: String\l- category: String\l|+ Painting()\l+ Painting(int, int)\l+ getHeight(): int\l+ setHeight(int): void\l+ getWidth(): int\l+ setWidth(int): void\l+ getStyle(): String\l+ setStyle(String): void\l+ getTechnique(): String\l+ setTechnique(String): void\l+ getCategory(): String\l+ setCategory(String): void\l+ computePrice(): float\l}"];
Print [label="{Print|- openEditionType: String\l- category: String\l|+ Print()\l+ Print(String, String)\l+ getOpenEditionType(): String\l+ setOpenEditionType(String): void\l+ getCategory(): String\l+ setCategory(String): void\l+ computePrice(): float\l}"];
Sculpture [label="{Sculpture|- material: String\l- weight: float\l|+ Sculpture()\l+ Sculpture(float)\l+ getMaterial(): String\l+ setMaterial(String): void\l+ getWeight(): float\l+ setWeight(float): void\l+ computePrice(): float\l}"];
Transaction [label="{Transaction|- id: String\l- created: ZonedDateTime\l- completed: ZonedDateTime\l- customerId: String\l- shipToAddress: Address\l- customerInventoryList: InventoryList\l- totalPrice: float\l- attributes: JsonArray\l|# Transaction(Customer, InventoryList)\l# Transaction()\l+ getId(): String\l+ setId(String): void\l+ getCreated(): ZonedDateTime\l+ setCreated(ZonedDateTime): void\l+ getCompleted(): ZonedDateTime\l+ setCompleted(ZonedDateTime): void\l+ getCustomerId(): String\l+ setCustomerId(String): void\l+ getShipToAddress(): Address\l+ setShipToAddress(Address): void\l+ getCustomerInventoryList(): InventoryList\l+ setCustomerInventoryList(InventoryList): void\l+ getTotalPrice(): float\l+ setTotalPrice(float): void\l+ getAttributes(): JsonArray\l+ setAttributes(JsonArray): void\l+ toString(): String\l}"];
// Collection Classes
CustomerList [label="{CustomerList|+ CustomerList()\l}"];
InventoryList [label="{InventoryList|+ InventoryList()\l+ add(InventoryPiece): boolean\l}"];
TransactionList [label="{TransactionList|+ TransactionList()\l+ add(Transaction): boolean\l}"];
// Manager Classes
CustomerManager [label="{«singleton»\lCustomerManager|- INSTANCE: CustomerManager\l+ CUSTOMERS: CustomerList\l|+ getInstance(): CustomerManager\l+ add(Customer): boolean\l- check(Customer): void\l+ findById(String): Customer\l+ findByEmail(String): Customer\l+ save(): void\l+ load(): void\l}"];
InventoryManager [label="{«singleton»\lInventoryManager|- INSTANCE: InventoryManager\l+ INVENTORY: InventoryList\l|+ getInstance(): InventoryManager\l+ add(InventoryPiece): void\l+ find(String): InventoryPiece\l+ update(InventoryPiece): InventoryPiece\l+ Remove(InventoryPiece): InventoryPiece\l+ save(): void\l+ load(): void\l}"];
TransactionManager [label="{«singleton»\lTransactionManager|- INSTANCE: TransactionManager\l+ TRANSACTIONS: TransactionList\l|+ getInstance(): TransactionManager\l+ TransactRequest(Customer, InventoryList): Transaction\l+ complete(Transaction): void\l+ compute(Transaction): void\l+ findByCustomerEmail(String): TransactionList\l+ findByTransactionId(String): TransactionList\l+ findByTransactionDate(ZonedDateTime): TransactionList\l+ remove(Transaction): void\l+ save(): void\l}"];
DataRepository [label="{«singleton»\lDataRepository|- INSTANCE: DataRepository\l|+ getInstance(): DataRepository\l+ generateRandomID(int): String\l+ generateRandom10DigitID(): String\l+ WalkFileSystemTree(InventoryManager): void\l+ WalkFileSystemTree(CustomerManager): void\l+ WalkFileSystemTree(TransactionManager): void\l+ mapJsonToObjectList(String, Class): List\l- write(CustomerManager): void\l- write(InventoryManager): void\l- read(CustomerManager, Path): void\l- read(InventoryManager, Path): void\l}"];
// Exception Classes
InvalidArtOperationException [label="{«exception»\lInvalidArtOperationException|+ InvalidArtOperationException(String)\l+ InvalidArtOperationException(String, Throwable)\l+ InvalidArtOperationException(Throwable)\l}"];
InvalidRecordDataException [label="{«exception»\lInvalidRecordDataException|+ InvalidRecordDataException(String)\l+ InvalidRecordDataException(String, Throwable)\l+ InvalidRecordDataException(Throwable)\l}"];
InvalidTransactionException [label="{«exception»\lInvalidTransactionException|+ InvalidTransactionException(String)\l+ InvalidTransactionException(String, Throwable)\l+ InvalidTransactionException(Throwable)\l}"];
InvalidTransOperationException [label="{«exception»\lInvalidTransOperationException|+ InvalidTransOperationException(String)\l+ InvalidTransOperationException(String, Throwable)\l+ InvalidTransOperationException(Throwable)\l}"];
// Inheritance Relationships
Drawing -> InventoryPiece [arrowhead=empty, label="extends"];
Painting -> InventoryPiece [arrowhead=empty, label="extends"];
Print -> InventoryPiece [arrowhead=empty, label="extends"];
Sculpture -> InventoryPiece [arrowhead=empty, label="extends"];
CustomerList -> Customer [arrowhead=diamond, label="contains"];
InventoryList -> InventoryPiece [arrowhead=diamond, label="contains"];
TransactionList -> Transaction [arrowhead=diamond, label="contains"];
// Composition/Association Relationships
Customer -> Address [arrowhead=diamond, label="has"];
Transaction -> Address [arrowhead=diamond, label="has"];
Transaction -> InventoryList [arrowhead=diamond, label="has"];
// Manager Relationships
CustomerManager -> CustomerList [arrowhead=diamond, label="manages"];
InventoryManager -> InventoryList [arrowhead=diamond, label="manages"];
TransactionManager -> TransactionList [arrowhead=diamond, label="manages"];
// Dependencies
CustomerManager -> DataRepository [arrowhead=vee, style=dashed, label="uses"];
InventoryManager -> DataRepository [arrowhead=vee, style=dashed, label="uses"];
TransactionManager -> Customer [arrowhead=vee, style=dashed, label="uses"];
TransactionManager -> InventoryList [arrowhead=vee, style=dashed, label="uses"];
Customer -> DataRepository [arrowhead=vee, style=dashed, label="uses"];
InventoryPiece -> DataRepository [arrowhead=vee, style=dashed, label="uses"];
Transaction -> DataRepository [arrowhead=vee, style=dashed, label="uses"];
// Exception Usage
CustomerManager -> InvalidRecordDataException [arrowhead=vee, style=dashed, label="throws"];
subgraph cluster_exceptions {
label="Exception Classes";
style=filled;
color=lightyellow;
InvalidArtOperationException; InvalidRecordDataException; InvalidTransactionException; InvalidTransOperationException;
}
// Subgraphs for organization
subgraph cluster_model {
label="Model Classes";
style=filled;
color=lightgrey;
Address; Customer; InventoryPiece; Drawing; Painting; Print; Sculpture; Transaction;
}
subgraph cluster_managers {
label="Manager Classes (Singletons)";
style=filled;
color=lightgreen;
CustomerManager; InventoryManager; TransactionManager; DataRepository; CustomerList; InventoryList; TransactionList;
}
}