updates
This commit is contained in:
@@ -34,8 +34,6 @@ public interface Api {
|
|||||||
* is not already in the inventory before adding
|
* is not already in the inventory before adding
|
||||||
*/
|
*/
|
||||||
|
|
||||||
InventoryManager.getInstance().getArtPieceTypes().forEach(System.out::println);
|
|
||||||
|
|
||||||
/* Add Inventory */
|
/* Add Inventory */
|
||||||
|
|
||||||
InventoryManager.getInstance().add(make(new Drawing()));
|
InventoryManager.getInstance().add(make(new Drawing()));
|
||||||
@@ -45,17 +43,24 @@ public interface Api {
|
|||||||
InventoryManager.getInstance().add(make(new Sculpture()));
|
InventoryManager.getInstance().add(make(new Sculpture()));
|
||||||
InventoryManager.getInstance().add(make(new Sculpture()));
|
InventoryManager.getInstance().add(make(new Sculpture()));
|
||||||
|
|
||||||
|
/* Add Customer */
|
||||||
|
//CustomerManager.getInstance().add(new Customer("Kate", "Demsey", "310-676-4844", "kate@museum.com"));
|
||||||
|
//CustomerManager.getInstance().add(new Customer("Jim", "Gumbly", "203-676-4844", "jim@homedeco.com"));
|
||||||
|
CustomerManager.getInstance().load();
|
||||||
/*
|
/*
|
||||||
* 2. Remove art object from the inventory
|
* 2. Remove art object from the inventory
|
||||||
*/
|
*/
|
||||||
InventoryManager imgr = InventoryManager.getInstance();
|
InventoryManager imgr = InventoryManager.getInstance();
|
||||||
InventoryPiece art = imgr.find("####");
|
System.out.println(String.format("Art Pieces in INVENTORY: count %d", imgr.INVENTORY.size()));
|
||||||
imgr.Remove(art);
|
InventoryPiece art = imgr.INVENTORY.getLast();
|
||||||
|
InventoryPiece piece = imgr.find(art.getId());
|
||||||
|
imgr.Remove(piece);
|
||||||
|
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
|
* 3. Return a list of all art objects from inventory
|
||||||
*/
|
*/
|
||||||
CustomerManager cmgr = CustomerManager.getInstance();
|
CustomerManager cmgr = CustomerManager.getInstance();
|
||||||
Customer customer = cmgr.findByEmail("kate@it.com");
|
Customer customer = cmgr.findByEmail("kate@museum.com");
|
||||||
InventoryList customerCart = new InventoryList();
|
InventoryList customerCart = new InventoryList();
|
||||||
|
|
||||||
TransactionManager tmgr = TransactionManager.getInstance();
|
TransactionManager tmgr = TransactionManager.getInstance();
|
||||||
|
|||||||
16
Api/src/resources/db/customers.json
Normal file
16
Api/src/resources/db/customers.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"email": "kate@museum.com",
|
||||||
|
"id": "1039445606",
|
||||||
|
"nameFirst": "Kate",
|
||||||
|
"nameLast": "Demsey",
|
||||||
|
"phone": "310-676-4844"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"email": "jim@homedeco.com",
|
||||||
|
"id": "4312148107",
|
||||||
|
"nameFirst": "Jim",
|
||||||
|
"nameLast": "Gumbly",
|
||||||
|
"phone": "203-676-4844"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -20,10 +20,11 @@ public class Customer {
|
|||||||
this.nameLast = nameLast;
|
this.nameLast = nameLast;
|
||||||
this.phone = phone;
|
this.phone = phone;
|
||||||
this.email = email;
|
this.email = email;
|
||||||
|
this.id = DataRepository.generateRandom10DigitID();
|
||||||
this.updated = ZonedDateTime.now();
|
this.updated = ZonedDateTime.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Customer(){}
|
protected Customer(){}
|
||||||
|
|
||||||
public String getEmail() {
|
public String getEmail() {
|
||||||
return email;
|
return email;
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
package edu.inventorym.model;
|
package edu.inventorym.model;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class CustomerManager {
|
public class CustomerManager {
|
||||||
|
|
||||||
final static CustomerManager INSTANCE = new CustomerManager();
|
final static CustomerManager INSTANCE = new CustomerManager();
|
||||||
@@ -28,6 +30,29 @@ public class CustomerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Customer findByEmail(String email){
|
public Customer findByEmail(String email){
|
||||||
|
for (Customer c : CUSTOMERS) {
|
||||||
|
if (email.equalsIgnoreCase(c.getEmail())) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
try {
|
||||||
|
DataRepository.write(this);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load(){
|
||||||
|
try {
|
||||||
|
DataRepository.read(this);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch(Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,18 @@
|
|||||||
*/
|
*/
|
||||||
package edu.inventorym.model;
|
package edu.inventorym.model;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.OpenOption;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
@@ -51,7 +60,6 @@ public class DataRepository {
|
|||||||
public static void WalkFileSystemTree(final TransactionManager manager) throws IOException {
|
public static void WalkFileSystemTree(final TransactionManager manager) throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void serialize_deserialize() {
|
static void serialize_deserialize() {
|
||||||
String jsonResponse = "";
|
String jsonResponse = "";
|
||||||
try {
|
try {
|
||||||
@@ -61,7 +69,6 @@ public class DataRepository {
|
|||||||
|
|
||||||
System.out.println("json string: " + jsonResponse);
|
System.out.println("json string: " + jsonResponse);
|
||||||
|
|
||||||
|
|
||||||
InventoryPiece response = jsonb.fromJson(jsonResponse, Drawing.class);
|
InventoryPiece response = jsonb.fromJson(jsonResponse, Drawing.class);
|
||||||
|
|
||||||
System.out.println("Result: " + response);
|
System.out.println("Result: " + response);
|
||||||
@@ -96,10 +103,10 @@ public class DataRepository {
|
|||||||
Jsonb jsonb = JsonbBuilder.create();
|
Jsonb jsonb = JsonbBuilder.create();
|
||||||
String result = jsonb.toJson(rpcs);
|
String result = jsonb.toJson(rpcs);
|
||||||
|
|
||||||
|
|
||||||
// Deserialize back
|
// Deserialize back
|
||||||
rpcs = jsonb.fromJson(result,
|
rpcs = jsonb.fromJson(result,
|
||||||
new ArrayList<Drawing>() {}
|
new ArrayList<Drawing>() {
|
||||||
|
}
|
||||||
.getClass()
|
.getClass()
|
||||||
.getGenericSuperclass());
|
.getGenericSuperclass());
|
||||||
|
|
||||||
@@ -111,7 +118,7 @@ public class DataRepository {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> List<T> mapJsonToObjectList(String body, Class<T> baseClass) {
|
public static <T> List<T> mapJsonToObjectList(String body, Class<T> baseClass) throws Exception {
|
||||||
try (var reader = Json.createReader(new StringReader(body));
|
try (var reader = Json.createReader(new StringReader(body));
|
||||||
Jsonb jsonb = JsonbBuilder.create()) {
|
Jsonb jsonb = JsonbBuilder.create()) {
|
||||||
JsonArray jsonArray = reader.readArray();
|
JsonArray jsonArray = reader.readArray();
|
||||||
@@ -119,16 +126,51 @@ public class DataRepository {
|
|||||||
return jsonArray.stream()
|
return jsonArray.stream()
|
||||||
.map(jsonValue -> jsonb.fromJson(jsonValue.toString(), baseClass))
|
.map(jsonValue -> jsonb.fromJson(jsonValue.toString(), baseClass))
|
||||||
.toList();
|
.toList();
|
||||||
} catch (Exception e) {
|
|
||||||
return (List<T>) new ArrayList<Drawing>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void write(CustomerManager mgr) throws IOException{
|
||||||
|
JsonbConfig config = new JsonbConfig()
|
||||||
|
.withFormatting(true); // Enable pretty-printing
|
||||||
|
Jsonb jsonb = JsonbBuilder.create(config);
|
||||||
|
String result = jsonb.toJson(mgr.CUSTOMERS);
|
||||||
|
|
||||||
|
|
||||||
|
String dataRoot = getRepositoryConfig.getPath();
|
||||||
|
dataRoot = dataRoot + "/customers.json";
|
||||||
|
Path path = Paths.get(dataRoot);
|
||||||
|
try (BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
|
||||||
|
writer.write(result);
|
||||||
|
writer.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void read(CustomerManager customerManager) throws IOException, Exception {
|
||||||
|
String dataRoot = getRepositoryConfig.getPath();
|
||||||
|
dataRoot = dataRoot + "/customers.json";
|
||||||
|
Path path = Paths.get(dataRoot);
|
||||||
|
String result;
|
||||||
|
try (BufferedReader in = new BufferedReader(new FileReader(path.toFile(), StandardCharsets.UTF_8))){
|
||||||
|
result = in.readAllAsString();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Customer> customers = mapJsonToObjectList(result, Customer.class);
|
||||||
|
/* Jsonb jsonb = JsonbBuilder.create();
|
||||||
|
CustomerList customers = jsonb.fromJson(result, new CustomerList() { }
|
||||||
|
.getClass()
|
||||||
|
.getGenericSuperclass()); */
|
||||||
|
customerManager.CUSTOMERS.clear();
|
||||||
|
customerManager.CUSTOMERS.addAll(customers);
|
||||||
|
}
|
||||||
|
|
||||||
public final static class getRepositoryConfig {
|
public final static class getRepositoryConfig {
|
||||||
public final static String getPath() {
|
public final static String getPath() {
|
||||||
String home = System.getenv("HOME") != null ? System.getenv("HOME")
|
String home = System.getenv("HOME") != null ? System.getenv("HOME")
|
||||||
: System.getenv("HOMEDRIVE") + System.getenv("HOMEPATH");
|
: System.getenv("HOMEDRIVE") + System.getenv("HOMEPATH");
|
||||||
return home.replace('\\', '/') + "/workspace/reservationsystem/src/resources/db";
|
return home.replace('\\', '/') + "/workspace/inventorym/Api/src/resources/db";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ public class Drawing extends InventoryPiece {
|
|||||||
public String category;
|
public String category;
|
||||||
|
|
||||||
public Drawing() {
|
public Drawing() {
|
||||||
super(InventoryType.DRAWING);
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float computePrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,15 +21,17 @@ public class InventoryManager {
|
|||||||
private InventoryManager() {
|
private InventoryManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<InventoryType> getArtPieceTypes() {
|
|
||||||
return EnumSet.allOf(InventoryType.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(InventoryPiece iPiece) {
|
public void add(InventoryPiece iPiece) {
|
||||||
INVENTORY.add(iPiece);
|
INVENTORY.add(iPiece);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryPiece find(String id) {
|
public InventoryPiece find(String id) {
|
||||||
|
for (InventoryPiece iv : INVENTORY) {
|
||||||
|
if (iv.getId() == id) {
|
||||||
|
return iv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,11 +51,9 @@ public class InventoryManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(InventoryPiece iPiece) {
|
public InventoryPiece Remove(InventoryPiece iPiece) {
|
||||||
|
int i = INVENTORY.indexOf(iPiece);
|
||||||
//int i = find(iPiece);
|
return INVENTORY.remove(i);
|
||||||
//INVENTORY.remove(i)
|
|
||||||
//*** multiple quantiies of iPiece */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,23 +23,14 @@ public abstract class InventoryPiece {
|
|||||||
|
|
||||||
public String Author;
|
public String Author;
|
||||||
|
|
||||||
InventoryType iventoryType;
|
public InventoryPiece() {
|
||||||
|
|
||||||
public InventoryPiece(InventoryType iventoryType) {
|
|
||||||
this.iventoryType = iventoryType;
|
|
||||||
this.created = ZonedDateTime.now();
|
this.created = ZonedDateTime.now();
|
||||||
this.id = DataRepository.generateRandom10DigitID();
|
this.id = DataRepository.generateRandom10DigitID();
|
||||||
}
|
this.price = 10.99F;
|
||||||
|
|
||||||
public InventoryPiece() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean isArt(InventoryPiece piece) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return this.iventoryType.toString();
|
return this.getClass().getSimpleName().toUpperCase();
|
||||||
};
|
};
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
@@ -89,4 +80,6 @@ public abstract class InventoryPiece {
|
|||||||
public void setAuthor(String author) {
|
public void setAuthor(String author) {
|
||||||
Author = author;
|
Author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract float computePrice();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
/**
|
|
||||||
* license: GPLv3
|
|
||||||
edu.inventorym
|
|
||||||
*/
|
|
||||||
package edu.inventorym.model;
|
|
||||||
|
|
||||||
public enum InventoryType {
|
|
||||||
PAINTING, DRAWING, PRINT, SCULPTURE
|
|
||||||
}
|
|
||||||
@@ -5,14 +5,77 @@
|
|||||||
package edu.inventorym.model;
|
package edu.inventorym.model;
|
||||||
|
|
||||||
public class Painting extends InventoryPiece {
|
public class Painting extends InventoryPiece {
|
||||||
|
|
||||||
int height;
|
int height;
|
||||||
int width;
|
int width;
|
||||||
String style;
|
String style;
|
||||||
String technique;
|
String technique;
|
||||||
String category;
|
String category;
|
||||||
|
|
||||||
|
public Painting(int height, int width) {
|
||||||
|
super();
|
||||||
|
this.height = height;
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
public Painting() {
|
public Painting() {
|
||||||
super(InventoryType.PAINTING);
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeight(int height) {
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWidth(int width) {
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStyle() {
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStyle(String style) {
|
||||||
|
this.style = style;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTechnique() {
|
||||||
|
return technique;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTechnique(String technique) {
|
||||||
|
this.technique = technique;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategory(String category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float computePrice() {
|
||||||
|
|
||||||
|
int sqarea = height * width;
|
||||||
|
float additional = 0;
|
||||||
|
if (sqarea < 100) {
|
||||||
|
additional = 5.99F;
|
||||||
|
}
|
||||||
|
if (sqarea > 100 && sqarea < 300) {
|
||||||
|
additional = 10.99F;
|
||||||
|
}
|
||||||
|
if (sqarea > 300) {
|
||||||
|
additional = 15.99F;
|
||||||
|
}
|
||||||
|
return price + additional;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class Print extends InventoryPiece {
|
|||||||
String category;
|
String category;
|
||||||
|
|
||||||
public Print(){
|
public Print(){
|
||||||
super(InventoryType.PRINT);
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Print(String openEditionType, String category) {
|
public Print(String openEditionType, String category) {
|
||||||
@@ -33,4 +33,9 @@ public class Print extends InventoryPiece {
|
|||||||
public void setCategory(String category) {
|
public void setCategory(String category) {
|
||||||
this.category = category;
|
this.category = category;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float computePrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,33 @@ public class Sculpture extends InventoryPiece {
|
|||||||
String material;
|
String material;
|
||||||
float weight;
|
float weight;
|
||||||
|
|
||||||
public Sculpture (){
|
public Sculpture(float weight) {
|
||||||
super(InventoryType.SCULPTURE);
|
super();
|
||||||
|
this.weight = weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Sculpture() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMaterial() {
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaterial(String material) {
|
||||||
|
this.material = material;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getWeight() {
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeight(float weight) {
|
||||||
|
this.weight = weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float computePrice() {
|
||||||
|
return price + (weight * 0.20F);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public class Transaction {
|
|||||||
String customerId;
|
String customerId;
|
||||||
Address shipToAddress;
|
Address shipToAddress;
|
||||||
InventoryList customerInventoryList;
|
InventoryList customerInventoryList;
|
||||||
|
float totalPrice = 0.0F;
|
||||||
JsonArray attributes;
|
JsonArray attributes;
|
||||||
|
|
||||||
public Transaction() {
|
public Transaction() {
|
||||||
@@ -33,6 +34,38 @@ public class Transaction {
|
|||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCustomerId() {
|
||||||
|
return customerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Address getShipToAddress() {
|
||||||
|
return shipToAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryList getCustomerInventoryList() {
|
||||||
|
return customerInventoryList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomerInventoryList(InventoryList customerInventoryList) {
|
||||||
|
this.customerInventoryList = customerInventoryList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getTotalPrice() {
|
||||||
|
return totalPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalPrice(float totalPrice) {
|
||||||
|
this.totalPrice = totalPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonArray getAttributes() {
|
||||||
|
return attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttributes(JsonArray attributes) {
|
||||||
|
this.attributes = attributes;
|
||||||
|
}
|
||||||
|
|
||||||
public void setCreated(ZonedDateTime created) {
|
public void setCreated(ZonedDateTime created) {
|
||||||
this.created = created;
|
this.created = created;
|
||||||
}
|
}
|
||||||
@@ -45,5 +78,12 @@ public class Transaction {
|
|||||||
this.completed = completed;
|
this.completed = completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setShipToAddress(Address mailing) {
|
||||||
|
this.shipToAddress = mailing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomerId(String id) {
|
||||||
|
this.customerId = id;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,19 +17,23 @@ public class TransactionManager {
|
|||||||
public TransactionList TRANSACTIONS = new TransactionList();
|
public TransactionList TRANSACTIONS = new TransactionList();
|
||||||
|
|
||||||
public Transaction TransactRequest(Customer customer, InventoryList iPieces, Transaction transacted) {
|
public Transaction TransactRequest(Customer customer, InventoryList iPieces, Transaction transacted) {
|
||||||
|
transacted.setCustomerId(customer.getId());
|
||||||
|
transacted.setShipToAddress(customer.getMailing());
|
||||||
|
transacted.setCustomerInventoryList(iPieces);
|
||||||
|
compute(transacted);
|
||||||
return transacted;
|
return transacted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void compute(Transaction tran, TransactionOperationEnum operation) {
|
public void complete(Transaction tran) {
|
||||||
|
tran.setCompleted(ZonedDateTime.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void compute(Transaction tran) {
|
public void compute(Transaction tran) {
|
||||||
|
float price = 0.0F;
|
||||||
|
for (InventoryPiece piece : tran.customerInventoryList) {
|
||||||
|
price += piece.computePrice();
|
||||||
}
|
}
|
||||||
|
tran.totalPrice = price;
|
||||||
public void complete(Transaction tran) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransactionList findByCustomerEmail(String email) {
|
public TransactionList findByCustomerEmail(String email) {
|
||||||
@@ -49,8 +53,7 @@ public class TransactionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'save'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
/**
|
|
||||||
* license: GPLv3
|
|
||||||
edu.inventorym
|
|
||||||
*/
|
|
||||||
package edu.inventorym.model;
|
|
||||||
|
|
||||||
public enum TransactionOperationEnum {
|
|
||||||
Completed,
|
|
||||||
Draft,
|
|
||||||
Pricing,
|
|
||||||
Removed,
|
|
||||||
Shipping
|
|
||||||
}
|
|
||||||
|
|
||||||
28
README.md
28
README.md
@@ -1,24 +1,16 @@
|
|||||||
# inventorym
|
# inventorym
|
||||||
|
|
||||||
Inheritance: Shows inheritance relationships (Drawing, Painting, Print, Sculpture extending InventoryPiece)
|
|
||||||
Associations: Shows composition relationships (Customer has Address, Transaction has Address and InventoryList)
|
|
||||||
Enumerations: InventoryType and TransactionOperationEnum
|
Enumerations: InventoryType and TransactionOperationEnum
|
||||||
Exceptions: four application exception classes extend RuntimeException
|
Exception Classes: Four custom exception types
|
||||||
Manager Classes: Singleton pattern managers with their collections
|
Value Object: Address class
|
||||||
Collections: Custom list classes extending ArrayList
|
Customer Management: Customer, CustomerList, and CustomerManager
|
||||||
|
Inventory Management: Abstract InventoryPiece with concrete implementations (Drawing, Painting, Print, Sculpture), plus InventoryList and InventoryManager
|
||||||
|
Transaction Management: Transaction, TransactionList, and TransactionManager
|
||||||
Abstract base class (InventoryPiece) with 4 concrete implementations (Drawing, Painting, Print, Sculpture)
|
Data Repository: Singleton DataRepository for data operations
|
||||||
Enumerations (InventoryType, TransactionOperationEnum)
|
|
||||||
Manager classes (Singleton pattern): InventoryManager, CustomerManager, TransactionManager
|
|
||||||
Model classes: Customer, Address, Transaction
|
|
||||||
Collection classes: InventoryList, CustomerList, TransactionList
|
|
||||||
Repository: DataRepository for persistence
|
|
||||||
Exception classes: 4 custom runtime exceptions
|
|
||||||
|
|
||||||
Relationships shown:
|
Relationships shown:
|
||||||
|
|
||||||
Inheritance (empty arrow heads)
|
Inheritance (hollow arrows)
|
||||||
Composition (diamond arrow heads)
|
Associations (regular arrows)
|
||||||
Associations (open arrow heads)
|
Composition (diamond arrows)
|
||||||
Dependencies (dashed lines)
|
Dependencies (dashed arrows)
|
||||||
@@ -72,8 +72,8 @@ digraph InventoryManagementSystem {
|
|||||||
TransactionManager -> TransactionList [arrowhead=diamond, label="TRANSACTIONS"];
|
TransactionManager -> TransactionList [arrowhead=diamond, label="TRANSACTIONS"];
|
||||||
|
|
||||||
// List contains relationships
|
// List contains relationships
|
||||||
InventoryList -> InventoryPiece [arrowhead=diamond, style=dashed, label="contains"];
|
InventoryList -> InventoryPiece [arrowhead=odiamond, style=dashed, label="contains 0..*"];
|
||||||
CustomerList -> Customer [arrowhead=diamond, style=dashed, label="contains"];
|
CustomerList -> Customer [arrowhead=odiamond, style=dashed, label="contains 0..*"];
|
||||||
TransactionList -> Transaction [arrowhead=diamond, style=dashed, label="contains"];
|
TransactionList -> Transaction [arrowhead=diamond, style=dashed, label="contains"];
|
||||||
|
|
||||||
// Manager relationships
|
// Manager relationships
|
||||||
|
|||||||
84
uml/classdiagram2.dot
Normal file
84
uml/classdiagram2.dot
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
digraph InventorySystem {
|
||||||
|
// Graph settings
|
||||||
|
rankdir=TB;
|
||||||
|
node [shape=record, fontname="Arial", fontsize=10];
|
||||||
|
edge [fontname="Arial", fontsize=9];
|
||||||
|
|
||||||
|
// Abstract Class
|
||||||
|
InventoryPiece [label="{InventoryPiece\n«abstract»|+ id : String\l+ price : float\l+ created : ZonedDateTime\l+ title : String\l+ description : String\l+ Author : String\l- iventoryType : InventoryType\l|+ InventoryPiece(InventoryType)\l+ InventoryPiece()\l+ isArt(InventoryPiece) : Boolean\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}", style=filled, fillcolor=lightyellow];
|
||||||
|
|
||||||
|
// Concrete Classes extending InventoryPiece
|
||||||
|
Drawing [label="{Drawing|+ style : String\l+ technique : String\l+ category : String\l|+ Drawing()\l}"];
|
||||||
|
Painting [label="{Painting|- height : int\l- width : int\l- style : String\l- technique : String\l- category : String\l|+ Painting()\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}"];
|
||||||
|
Sculpture [label="{Sculpture|- material : String\l- weight : float\l|+ Sculpture()\l}"];
|
||||||
|
|
||||||
|
// Enums
|
||||||
|
InventoryType [label="{«enumeration»\nInventoryType|PAINTING\lDRAWING\lPRINT\lSCULPTURE\l}", style=filled, fillcolor=lightblue];
|
||||||
|
TransactionOperationEnum [label="{«enumeration»\nTransactionOperationEnum|Completed\lDraft\lPricing\lRemoved\lShipping\l}", style=filled, fillcolor=lightblue];
|
||||||
|
|
||||||
|
// Value Objects
|
||||||
|
Address [label="{Address|- street : String\l- city : String\l- state : String\l- zip : String\l|+ Address()\l+ Address(String, String, String, 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}"];
|
||||||
|
|
||||||
|
// Domain Classes
|
||||||
|
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+ Customer()\l+ getEmail() : String\l+ getId() : String\l+ setId(String) : void\l+ getPhone() : String\l+ setPhone(String) : void\l+ getMailing() : Address\l+ setMailing(Address) : void\l+ setEmail(String) : void\l+ getNameFirst() : String\l+ setNameFirst(String) : void\l+ getNameLast() : String\l+ setNameLast(String) : void\l}"];
|
||||||
|
|
||||||
|
Transaction [label="{Transaction|- id : String\l- created : ZonedDateTime\l- completed : ZonedDateTime\l- customerId : String\l- shipToAddress : Address\l- customerInventoryList : InventoryList\l- attributes : JsonArray\l|+ Transaction()\l+ getId() : String\l+ setId(String) : void\l+ getCreated() : ZonedDateTime\l+ setCreated(ZonedDateTime) : void\l+ getCompleted() : ZonedDateTime\l+ setCompleted(ZonedDateTime) : void\l}"];
|
||||||
|
|
||||||
|
// Collection Classes
|
||||||
|
InventoryList [label="{InventoryList|+ InventoryList()\l}", style=filled, fillcolor=lightgreen];
|
||||||
|
CustomerList [label="{CustomerList|+ CustomerList()\l}", style=filled, fillcolor=lightgreen];
|
||||||
|
TransactionList [label="{TransactionList|+ TransactionList()\l+ add(Transaction) : boolean\l}", style=filled, fillcolor=lightgreen];
|
||||||
|
|
||||||
|
// Manager Classes (Singletons)
|
||||||
|
InventoryManager [label="{«singleton»\nInventoryManager|- INSTANCE : InventoryManager\l+ INVENTORY : InventoryList\l|- InventoryManager()\l+ getInstance() : InventoryManager\l+ getArtPieceTypes() : Set\<InventoryType\>\l+ add(InventoryPiece) : void\l+ find(String) : InventoryPiece\l+ update(InventoryPiece) : InventoryPiece\l+ save() : void\l+ loadAll() : void\l+ Remove(InventoryPiece) : void\l}", style=filled, fillcolor=lightcoral];
|
||||||
|
|
||||||
|
CustomerManager [label="{«singleton»\nCustomerManager|- 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}", style=filled, fillcolor=lightcoral];
|
||||||
|
|
||||||
|
TransactionManager [label="{«singleton»\nTransactionManager|- INSTANCE : TransactionManager\l+ TRANSACTIONS : TransactionList\l|+ getInstance() : TransactionManager\l+ TransactRequest(Customer, InventoryList, Transaction) : Transaction\l+ compute(Transaction, TransactionOperationEnum) : void\l+ compute(Transaction) : void\l+ complete(Transaction) : void\l+ findByCustomerEmail(String) : TransactionList\l+ findByTransactionId(String) : TransactionList\l+ findByTransactionDate(ZonedDateTime) : TransactionList\l+ remove(Transaction) : void\l+ save() : void\l}", style=filled, fillcolor=lightcoral];
|
||||||
|
|
||||||
|
// Utility Class
|
||||||
|
DataRepository [label="{«singleton»\nDataRepository|- 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\<T\>) : List\<T\>\l}", style=filled, fillcolor=lavender];
|
||||||
|
|
||||||
|
// Exception Classes
|
||||||
|
InvalidArtOperationException [label="{InvalidArtOperationException|+ InvalidArtOperationException(String)\l+ InvalidArtOperationException(String, Throwable)\l+ InvalidArtOperationException(Throwable)\l}", style=filled, fillcolor=pink];
|
||||||
|
|
||||||
|
InvalidRecordDataException [label="{InvalidRecordDataException|+ InvalidRecordDataException(String)\l+ InvalidRecordDataException(String, Throwable)\l+ InvalidRecordDataException(Throwable)\l}", style=filled, fillcolor=pink];
|
||||||
|
|
||||||
|
InvalidTransactionException [label="{InvalidTransactionException|+ InvalidTransactionException(String)\l+ InvalidTransactionException(String, Throwable)\l+ InvalidTransactionException(Throwable)\l}", style=filled, fillcolor=pink];
|
||||||
|
|
||||||
|
InvalidTransOperationException [label="{InvalidTransOperationException|+ InvalidTransOperationException(String)\l+ InvalidTransOperationException(String, Throwable)\l+ InvalidTransOperationException(Throwable)\l}", style=filled, fillcolor=pink];
|
||||||
|
|
||||||
|
// Inheritance relationships
|
||||||
|
InventoryPiece -> Drawing [dir=back, arrowtail=empty, label="extends"];
|
||||||
|
InventoryPiece -> Painting [dir=back, arrowtail=empty, label="extends"];
|
||||||
|
InventoryPiece -> Print [dir=back, arrowtail=empty, label="extends"];
|
||||||
|
InventoryPiece -> Sculpture [dir=back, arrowtail=empty, label="extends"];
|
||||||
|
|
||||||
|
// Collection inheritance
|
||||||
|
InventoryList -> InventoryPiece [arrowhead=diamond, label="contains *"];
|
||||||
|
CustomerList -> Customer [arrowhead=diamond, label="contains *"];
|
||||||
|
TransactionList -> Transaction [arrowhead=diamond, label="contains *"];
|
||||||
|
|
||||||
|
// Composition relationships
|
||||||
|
Customer -> Address [arrowhead=diamond, label="mailing"];
|
||||||
|
Transaction -> Address [arrowhead=diamond, label="shipToAddress"];
|
||||||
|
Transaction -> InventoryList [arrowhead=diamond, label="customerInventoryList"];
|
||||||
|
|
||||||
|
// Manager aggregations
|
||||||
|
InventoryManager -> InventoryList [arrowhead=diamond, label="INVENTORY"];
|
||||||
|
CustomerManager -> CustomerList [arrowhead=diamond, label="CUSTOMERS"];
|
||||||
|
TransactionManager -> TransactionList [arrowhead=diamond, label="TRANSACTIONS"];
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
|
InventoryPiece -> InventoryType [style=dashed, arrowhead=open, label="uses"];
|
||||||
|
CustomerManager -> InvalidRecordDataException [style=dashed, arrowhead=open, label="throws"];
|
||||||
|
TransactionManager -> TransactionOperationEnum [style=dashed, arrowhead=open, label="uses"];
|
||||||
|
InventoryManager -> DataRepository [style=dashed, arrowhead=open, label="uses"];
|
||||||
|
CustomerManager -> DataRepository [style=dashed, arrowhead=open, label="uses"];
|
||||||
|
TransactionManager -> DataRepository [style=dashed, arrowhead=open, label="uses"];
|
||||||
|
InventoryPiece -> DataRepository [style=dashed, arrowhead=open, label="uses"];
|
||||||
|
TransactionManager -> Customer [style=dashed, arrowhead=open, label="uses"];
|
||||||
|
TransactionManager -> InventoryList [style=dashed, arrowhead=open, label="uses"];
|
||||||
|
DataRepository -> InventoryPiece [style=dashed, arrowhead=open, label="serializes"];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user