Skip to content

Commit

Permalink
finish job fortunately
Browse files Browse the repository at this point in the history
  • Loading branch information
ashkan-khd committed Jul 29, 2020
1 parent 66c82c4 commit b7b1bd5
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 52 deletions.
Binary file removed database/Images/Supporter/1 pre.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/java/client/Protocol.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client;

public enum Protocol {
CLIENT_COMPONENT("127.0.0.1", 57184);
CLIENT_COMPONENT("127.0.0.1", 56478);

public String Ip;
public int port;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/client/view/Processor.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ protected Product getProductByID(String ID, String productType) {
}

protected Image getProductImageByID(String productID, int imageNumber, String productType) {
Command<String> productImageCommand = new Command<>("get " + productType + " image-1", Command.HandleType.PICTURE_GET, productID);
Command<String> productImageCommand = new Command<>("get " + productType + " image-" + imageNumber, Command.HandleType.PICTURE_GET, productID);
return client.getImage(productImageCommand);
}

Expand Down
75 changes: 38 additions & 37 deletions src/main/java/client/view/ProductProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -928,49 +928,50 @@ private List<Notification> sendProduct(ArrayList<File> productImageFiles, String
Command<Product> productCommand = new Command<>(sendType + " product", Command.HandleType.PRODUCT, products);
Response<Notification> productResponse = client.postAndGet(productCommand, Response.class, (Class<Notification>)Notification.class);

if(sendType.equals("edit")) {
Command<String> command = new Command<>("delete editing product pictures", Command.HandleType.PRODUCT, product.getID());
client.postAndGet(command, Response.class, (Class<Object>)Object.class);
} else {
if(productResponse.getData().size() != 0 && productResponse.getDatum() == Notification.ADD_PRODUCT) {
product.setID(productResponse.getAdditionalString());
if(productResponse.getDatum() == Notification.ADD_PRODUCT || productResponse.getDatum() == Notification.EDIT_PRODUCT) {
if(sendType.equals("edit")) {
Command<String> command = new Command<>("delete editing product pictures", Command.HandleType.PRODUCT, product.getID());
client.postAndGet(command, Response.class, (Class<Object>)Object.class);
} else {
if(productResponse.getData().size() != 0 && productResponse.getDatum() == Notification.ADD_PRODUCT) {
product.setID(productResponse.getAdditionalString());
}
}
}

for (File productImageFile : productImageFiles) {
String[] splitPath = productImageFile.getPath().split("\\.");
String fileExtension = splitPath[splitPath.length - 1];
Command<String> imageCommand = new Command<>(sendType + " product image", Command.HandleType.PICTURE_SEND, product.getID(), fileExtension);
client.sendImage(imageCommand, productImageFile);
}

if(isFileAdded) {
if(sendType.equals("add")) {
productFileInfo.setProductID(product.getID());
Command<String> command = new Command<>("init product file countability", Command.HandleType.PRODUCT, product.getID());
client.postAndGet(command, Response.class, (Class<Object>)Object.class);
for (File productImageFile : productImageFiles) {
String[] splitPath = productImageFile.getPath().split("\\.");
String fileExtension = splitPath[splitPath.length - 1];
Command<String> imageCommand = new Command<>(sendType + " product image", Command.HandleType.PICTURE_SEND, product.getID(), fileExtension);
client.sendImage(imageCommand, productImageFile);
}
if(sendType.equals("edit")) {
if(productFileInfo == null) {
String commandStr = doesEditingProductHaveFile(product.getID()) ? "get edit product file info" : "get product file info";
Command<String> command = new Command<>(commandStr, Command.HandleType.PRODUCT, product.getID());
Response<Product.ProductFileInfo> response = client.postAndGet(command, Response.class, (Class<Product.ProductFileInfo>)Product.ProductFileInfo.class);
productFileInfo = response.getDatum();

if(isFileAdded) {
if(sendType.equals("add")) {
productFileInfo.setProductID(product.getID());
Command<String> command = new Command<>("init product file countability", Command.HandleType.PRODUCT, product.getID());
client.postAndGet(command, Response.class, (Class<Object>)Object.class);
}
if(productFile == null) {
String commandStr = (doesEditingProductHaveFile(product.getID()) ? "get edit product file" : "get product file");
Command<String> command = new Command<>(commandStr, Command.HandleType.PICTURE_GET, product.getID());
productFile = client.getFile(command);
if(sendType.equals("edit")) {
if(productFileInfo == null) {
String commandStr = doesEditingProductHaveFile(product.getID()) ? "get edit product file info" : "get product file info";
Command<String> command = new Command<>(commandStr, Command.HandleType.PRODUCT, product.getID());
Response<Product.ProductFileInfo> response = client.postAndGet(command, Response.class, (Class<Product.ProductFileInfo>)Product.ProductFileInfo.class);
productFileInfo = response.getDatum();
}
if(productFile == null) {
String commandStr = (doesEditingProductHaveFile(product.getID()) ? "get edit product file" : "get product file");
Command<String> command = new Command<>(commandStr, Command.HandleType.PICTURE_GET, product.getID());
productFile = client.getFile(command);
}
}
Command<Product.ProductFileInfo> command = new Command<>(sendType + " product file info", Command.HandleType.PRODUCT, productFileInfo);
client.postAndGet(command, Response.class, (Class<Object>)Object.class);
String[] splitPath = productFile.getPath().split("\\.");
String fileExtension = splitPath[splitPath.length - 1];
Command<String> fileCommand = new Command<>(sendType + " product file", Command.HandleType.PICTURE_SEND, product.getID(), fileExtension);
client.sendFile(fileCommand, productFile);
}
Command<Product.ProductFileInfo> command = new Command<>(sendType + " product file info", Command.HandleType.PRODUCT, productFileInfo);
client.postAndGet(command, Response.class, (Class<Object>)Object.class);
String[] splitPath = productFile.getPath().split("\\.");
String fileExtension = splitPath[splitPath.length - 1];
Command<String> fileCommand = new Command<>(sendType + " product file", Command.HandleType.PICTURE_SEND, product.getID(), fileExtension);
client.sendFile(fileCommand, productFile);
}

return productResponse.getData();
}

Expand Down Expand Up @@ -1223,7 +1224,7 @@ private void showProductGeneralErrors(List<Notification> productNotifications) {
if(productNotifications.contains(Notification.EMPTY_PRODUCT_BRAND))
brandTextField.setStyle(errorTextFieldStyle);

if(productNotifications.contains(Notification.EMPTY_PRODUCT_NAME))
if(productNotifications.contains(Notification.EMPTY_PRODUCT_DESCRIPTION))
descriptionTextArea.setStyle(errorTextFieldStyle);
}

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/client/view/SaleProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,24 +461,28 @@ public void AddOffMouseClicked(MouseEvent mouseEvent) {
Response<String> response = client.postAndGet(command, Response.class, (Class<String>)String.class);
Notification resultNotification = response.getMessage();
off.setOffID(response.getDatum());
Command<String> extensionCommand = new Command<>("send off image", Command.HandleType.PICTURE_SEND, off.getOffID(), client.file2Extension.apply(imageFile));
client.sendImage(extensionCommand, imageFile);
if(imageFile != null) {
Command<String> extensionCommand = new Command<>("send off image", Command.HandleType.PICTURE_SEND, off.getOffID(), client.file2Extension.apply(imageFile));
client.sendImage(extensionCommand, imageFile);
}
if (resultNotification == Notification.ADD_OFF && this.parentProcessor instanceof TableViewProcessor) {
((TableViewProcessor) parentProcessor).updateTable();
((TableViewProcessor) parentProcessor).updateSelectedItem();
closeSubStage(myStage, parentProcessor);
closeSubStage(myStage, (parentProcessor).parentProcessor);
}
resultNotification.getAlert().show();
} else {
Command<Off> command = new Command<>("edit off", Command.HandleType.SALE, off);
Response response = client.postAndGet(command, Response.class, (Class<Object>)Object.class);
Notification resultNotification = response.getMessage();
Command<String> extensionCommand = new Command<>("send editing off image", Command.HandleType.PICTURE_SEND, off.getOffID(), client.file2Extension.apply(imageFile));
client.sendImage(extensionCommand, imageFile);
if(imageFile != null) {
Command<String> extensionCommand = new Command<>("send editing off image", Command.HandleType.PICTURE_SEND, off.getOffID(), client.file2Extension.apply(imageFile));
client.sendImage(extensionCommand, imageFile);
}
if (resultNotification == Notification.EDIT_OFF) {
((TableViewProcessor) parentProcessor).updateTable();
((TableViewProcessor) parentProcessor).updateSelectedItem();
closeSubStage(myStage, parentProcessor);
closeSubStage(myStage, (parentProcessor).parentProcessor);
}
resultNotification.getAlert().show();
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/server/controller/Validity.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ default boolean isUsernameValid(String username)
}

default boolean isGeneralIDValid(char idDeterminer, String id) {
if(id == null || id.isEmpty())
return true;
return getMatcher(id, "^" + idDeterminer + "\\d{7}$").matches();
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/server/model/db/AccountTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public static String getUserImageFilePath(String username) {
}

public static FileInputStream getProfileImageInputStream(String username) throws FileNotFoundException {
System.err.println(username);
return new FileInputStream(getUserImageFilePath(username));
}

Expand Down
7 changes: 1 addition & 6 deletions src/main/java/server/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class Server implements RandomGenerator{

public static final String MARKET_BANK_USERNAME = "boosmarket";
public static final String MARKET_BANK_PASSWORD = "a1234567";
public static final String MARKET_BANK_ACCOUNT_NUMBER = "10001";
public static final String MARKET_BANK_ACCOUNT_NUMBER = "2120728357";

public Server() {
try {
Expand Down Expand Up @@ -243,7 +243,6 @@ public String getReceipt(String token, String receiptType, String moneyString, S
}

String bankCommand = "create_receipt " + token + " " + receiptType + " " + moneyString + " " + sourceID + " " + destID + " " + description;
System.err.println("Command : " + bankCommand);
return BankAPI.getInstance().postAndGet(bankCommand);
}

Expand Down Expand Up @@ -302,15 +301,11 @@ public DataOutputStream getOutputStream(String username) {
Socket socket = chatterSockets.get(username);
DataOutputStream dataOutputStream;
if(chatterOutputStreams.containsKey(socket)) {
System.out.println("1");
dataOutputStream = chatterOutputStreams.get(socket);
} else {
System.out.println("2");
dataOutputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
chatterOutputStreams.put(socket, dataOutputStream);
// dataOutputStream = chatterOutputStreams.get(socket);
}
System.out.println("Init : Data Out : " + dataOutputStream);
return dataOutputStream;
} catch (IOException e) {
e.printStackTrace();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/server/server/bank/BankAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static BankAPI getInstance() {
return new BankAPI();
}

private static int PORT = 54818;
private static int PORT = 63293;
private final static String IP = "127.0.0.1";
private Socket mySocket;
private DataOutputStream outStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ public void run() {
}
outStream.writeUTF("invalid input");
System.err.println("Client Asked: Invalid Command");
System.err.println("Command: " + command);
outStream.flush();
System.out.println(new java.util.Date());
}
Expand Down

0 comments on commit b7b1bd5

Please sign in to comment.