use of CustomerContracts.ACustomerExceptions.InvalidParameter in project SmartCity-Market by TechnionYP5777.
the class RemoveCustomerTest method setup.
@Before
public void setup() {
PropertyConfigurator.configure("../log4j.properties");
customer = new RegisteredCustomer(clientRequestHandler);
try {
Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(CustomerDefs.loginCommandSenderId, CommandDescriptor.UPDATE_CUSTOMER_PROFILE, Serialization.serialize(customerProfile)).serialize())).thenReturn(new CommandWrapper(ResultDescriptor.SM_OK).serialize());
} catch (IOException ¢) {
fail();
}
try {
customer.updateCustomerProfile(customerProfile);
} catch (CustomerNotConnected | InvalidParameter | AuthenticationError | CriticalError e) {
fail();
}
}
use of CustomerContracts.ACustomerExceptions.InvalidParameter in project SmartCity-Market by TechnionYP5777.
the class Customer method resume.
@Override
public void resume(int _id) throws CriticalError, CustomerNotConnected {
CommandWrapper $ = null;
String serverResponse;
log.info("Creating customer Load grocery list command wrapper with id: " + id);
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
try {
serverResponse = sendRequestWithRespondToServer((new CommandWrapper(id, CommandDescriptor.LOAD_GROCERY_LIST)).serialize());
} catch (SocketTimeoutException e) {
log.fatal("Critical bug: failed to get respond from server");
throw new CriticalError();
}
terminateCommunication();
try {
$ = getCommandWrapper(serverResponse);
resultDescriptorHandler($.getResultDescriptor());
id = _id;
groceryList = Serialization.deserialize($.getData(), GroceryList.class);
} catch (InvalidCommandDescriptor | InvalidParameter | ProductCatalogDoesNotExist | AmountBiggerThanAvailable | ProductPackageDoesNotExist | GroceryListIsEmpty | AuthenticationError | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
/* Restoring Grocery list */
try {
loadCartProductCacheAndUpdateCartData();
} catch (ProductCatalogDoesNotExist | CriticalError | CustomerNotConnected e) {
log.fatal("Critical bug: Failed to fetch grocery list items from server");
}
log.info("load grocery list from server succeed.");
}
use of CustomerContracts.ACustomerExceptions.InvalidParameter in project SmartCity-Market by TechnionYP5777.
the class Customer method isFreeUsername.
@Override
public Boolean isFreeUsername(String username) throws CriticalError {
Boolean isFree = true;
String serverResponse;
log.info("Creating isFreeUsername command wrapper");
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
/* first: getting the product from the server */
try {
serverResponse = sendRequestWithRespondToServer(new CommandWrapper(id, CommandDescriptor.IS_FREE_CUSTOMER_NAME, Serialization.serialize(username)).serialize());
} catch (SocketTimeoutException e) {
log.fatal("Critical bug: failed to get respond from server");
throw new CriticalError();
}
terminateCommunication();
CommandWrapper commandWrapper = getCommandWrapper(serverResponse);
try {
resultDescriptorHandler(commandWrapper.getResultDescriptor());
} catch (UsernameAlreadyExists e) {
isFree = false;
} catch (InvalidCommandDescriptor | CriticalError | AmountBiggerThanAvailable | ProductPackageDoesNotExist | GroceryListIsEmpty | AuthenticationError | CustomerNotConnected | ProductCatalogDoesNotExist | InvalidParameter | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
log.info("isFreeUsername command succeed.");
return isFree;
}
use of CustomerContracts.ACustomerExceptions.InvalidParameter in project SmartCity-Market by TechnionYP5777.
the class Customer method returnProductToShelf.
@Override
public void returnProductToShelf(SmartCode c, int amount) throws AmountBiggerThanAvailable, ProductPackageDoesNotExist, CriticalError, CustomerNotConnected {
String serverResponse;
log.info("Creating REMOVE_PRODUCT_FROM_GROCERY_LIST command wrapper to customer with id: " + id);
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
try {
serverResponse = sendRequestWithRespondToServer(new CommandWrapper(id, CommandDescriptor.REMOVE_PRODUCT_FROM_GROCERY_LIST, Serialization.serialize(new ProductPackage(c, amount, null))).serialize());
} catch (SocketTimeoutException e) {
log.fatal("Critical bug: failed to get respond from server");
throw new CriticalError();
}
terminateCommunication();
try {
resultDescriptorHandler(getCommandWrapper(serverResponse).getResultDescriptor());
} catch (InvalidCommandDescriptor | InvalidParameter | ProductCatalogDoesNotExist | GroceryListIsEmpty | AuthenticationError | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
/* update customer data: groceryList, cartProductCache, totalSum */
if (groceryList == null)
throw new CriticalError();
try {
groceryList.removeProduct(new ProductPackage(c, amount, null));
} catch (ProductNotInList | AmountIsBiggerThanAvailable ¢) {
throw new CriticalError();
}
long barcode = c.getBarcode();
CartProduct cartProduct = cartProductCache.get(barcode);
ProductPackage productPackage = new ProductPackage(c, amount, null);
cartProduct.removeProductPackage(productPackage);
if (cartProduct.getTotalAmount() <= 0)
cartProductCache.remove(barcode);
else
cartProductCache.put(barcode, cartProduct);
totalProductsAmount -= amount;
totalSum -= amount * cartProduct.getCatalogProduct().getPrice();
log.info("REMOVE_PRODUCT_FROM_GROCERY_LIST command succeed.");
}
use of CustomerContracts.ACustomerExceptions.InvalidParameter in project SmartCity-Market by TechnionYP5777.
the class Customer method getAllIngredients.
@Override
public List<Ingredient> getAllIngredients() throws CriticalError {
String serverResponse;
log.info("Creating getAllIngredients command wrapper");
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
/* first: getting the product from the server */
try {
serverResponse = sendRequestWithRespondToServer(new CommandWrapper(id, CommandDescriptor.GET_ALL_INGREDIENTS).serialize());
} catch (SocketTimeoutException e) {
log.fatal("Critical bug: failed to get respond from server");
throw new CriticalError();
}
terminateCommunication();
CommandWrapper commandWrapper = getCommandWrapper(serverResponse);
try {
resultDescriptorHandler(commandWrapper.getResultDescriptor());
} catch (InvalidCommandDescriptor | CriticalError | AmountBiggerThanAvailable | ProductPackageDoesNotExist | GroceryListIsEmpty | AuthenticationError | CustomerNotConnected | ProductCatalogDoesNotExist | InvalidParameter | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
log.info("getAllIngredients command succeed.");
return new Gson().fromJson(commandWrapper.getData(), new TypeToken<List<Ingredient>>() {
}.getType());
}
Aggregations