Search in sources :

Example 16 with CriticalError

use of SMExceptions.CommonExceptions.CriticalError in project SmartCity-Market by TechnionYP5777.

the class Manager method editProductFromCatalog.

@Override
public void editProductFromCatalog(CatalogProduct p) throws InvalidParameter, CriticalError, EmployeeNotConnected, ProductNotExistInCatalog, ConnectionFailure {
    log.info("Creating editProductFromCatalog command wrapper with product: " + p);
    String serverResponse = sendRequestWithRespondToServer((new CommandWrapper(getClientId(), CommandDescriptor.EDIT_PRODUCT_FROM_CATALOG, Serialization.serialize(p))).serialize());
    CommandWrapper commandDescriptor = getCommandWrapper(serverResponse);
    try {
        resultDescriptorHandler(commandDescriptor.getResultDescriptor());
    } catch (InvalidCommandDescriptor | EmployeeAlreadyConnected | AuthenticationError | ProductStillForSale | AmountBiggerThanAvailable | ProductPackageDoesNotExist | ProductAlreadyExistInCatalog | WorkerAlreadyExists | ParamIDAlreadyExists | ParamIDDoesNotExist | WorkerDoesNotExist | IngredientStillInUse | ManfacturerStillInUse ¢) {
        log.fatal("Critical bug: this command result isn't supposed to return here");
        throw new CriticalError();
    }
    log.info("editProductFromCatalog command succeed.");
}
Also used : AuthenticationError(EmployeeDefs.AEmployeeException.AuthenticationError) CriticalError(SMExceptions.CommonExceptions.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) IngredientStillInUse(EmployeeDefs.AEmployeeException.IngredientStillInUse) EmployeeAlreadyConnected(EmployeeDefs.AEmployeeException.EmployeeAlreadyConnected) WorkerDoesNotExist(EmployeeDefs.AEmployeeException.WorkerDoesNotExist) ProductAlreadyExistInCatalog(EmployeeDefs.AEmployeeException.ProductAlreadyExistInCatalog) ProductStillForSale(EmployeeDefs.AEmployeeException.ProductStillForSale) AmountBiggerThanAvailable(EmployeeDefs.AEmployeeException.AmountBiggerThanAvailable) InvalidCommandDescriptor(EmployeeDefs.AEmployeeException.InvalidCommandDescriptor) WorkerAlreadyExists(EmployeeDefs.AEmployeeException.WorkerAlreadyExists) ParamIDAlreadyExists(EmployeeDefs.AEmployeeException.ParamIDAlreadyExists) ParamIDDoesNotExist(EmployeeDefs.AEmployeeException.ParamIDDoesNotExist) ManfacturerStillInUse(EmployeeDefs.AEmployeeException.ManfacturerStillInUse) ProductPackageDoesNotExist(EmployeeDefs.AEmployeeException.ProductPackageDoesNotExist)

Example 17 with CriticalError

use of SMExceptions.CommonExceptions.CriticalError in project SmartCity-Market by TechnionYP5777.

the class RemoveProductFromCartTest method setup.

@Before
public void setup() {
    PropertyConfigurator.configure("../log4j.properties");
    customer = new Customer(clientRequestHandler);
    try {
        Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(CustomerDefs.loginCommandSenderId, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, Serialization.serialize(pp)).serialize())).thenReturn(new CommandWrapper(ResultDescriptor.SM_OK).serialize());
    } catch (IOException ¢) {
        fail();
    }
    try {
        Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(CustomerDefs.loginCommandSenderId, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, Serialization.serialize(sc)).serialize())).thenReturn(new CommandWrapper(ResultDescriptor.SM_OK, Serialization.serialize(catalogProduct)).serialize());
    } catch (IOException ¢) {
        fail();
    }
    try {
        customer.addProductToCart(sc, amount);
    } catch (CriticalError | CustomerNotConnected | AmountBiggerThanAvailable | ProductPackageDoesNotExist | InvalidParameter e1) {
        fail();
    }
}
Also used : InvalidParameter(CustomerContracts.ACustomerExceptions.InvalidParameter) CriticalError(SMExceptions.CommonExceptions.CriticalError) AmountBiggerThanAvailable(CustomerContracts.ACustomerExceptions.AmountBiggerThanAvailable) ICustomer(CustomerContracts.ICustomer) Customer(CustomerImplementations.Customer) CustomerNotConnected(CustomerContracts.ACustomerExceptions.CustomerNotConnected) CommandWrapper(ClientServerApi.CommandWrapper) IOException(java.io.IOException) ProductPackageDoesNotExist(CustomerContracts.ACustomerExceptions.ProductPackageDoesNotExist) Before(org.junit.Before)

Example 18 with CriticalError

use of SMExceptions.CommonExceptions.CriticalError in project SmartCity-Market by TechnionYP5777.

the class GetAllIngredientsTest method getAllIngredientsConnectionFailureTest.

@Test
public void getAllIngredientsConnectionFailureTest() {
    try {
        Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(CustomerDefs.loginCommandSenderId, CommandDescriptor.GET_ALL_INGREDIENTS).serialize())).thenThrow(new SocketTimeoutException());
    } catch (IOException ¢) {
        fail();
    }
    try {
        customer.getAllIngredients();
        fail();
    } catch (CriticalError e) {
    /* success */
    }
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) CriticalError(SMExceptions.CommonExceptions.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) IOException(java.io.IOException) Test(org.junit.Test)

Example 19 with CriticalError

use of SMExceptions.CommonExceptions.CriticalError in project SmartCity-Market by TechnionYP5777.

the class Customer method addProductToCart.

@Override
public void addProductToCart(SmartCode c, int amount) throws CriticalError, CustomerNotConnected, AmountBiggerThanAvailable, ProductPackageDoesNotExist, InvalidParameter {
    String serverResponse;
    log.info("Creating viewProductFromCatalog (in order to addPtoductToCart) command wrapper to customer with id: " + id);
    CatalogProduct catalogProduct;
    try {
        catalogProduct = viewCatalogProduct(c);
    } catch (ProductCatalogDoesNotExist e1) {
        log.fatal("Critical bug: failed to get catalog product from server");
        throw new CriticalError();
    }
    establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
    try {
        serverResponse = sendRequestWithRespondToServer(new CommandWrapper(id, CommandDescriptor.ADD_PRODUCT_TO_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 | ProductCatalogDoesNotExist | GroceryListIsEmpty | AuthenticationError | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
        log.fatal("Critical bug: this command result isn't supposed to return here");
        throw new CriticalError();
    }
    ProductPackage productPackage1 = new ProductPackage(c, amount, null), productPackage2 = new ProductPackage(c, amount, null);
    groceryList.addProduct(productPackage1);
    addProductToCacheAndUpdateCartData(productPackage2, catalogProduct);
    log.info("addProductToGroceryList command succeed.");
}
Also used : AuthenticationError(CustomerContracts.ACustomerExceptions.AuthenticationError) CriticalError(SMExceptions.CommonExceptions.CriticalError) ProductPackage(BasicCommonClasses.ProductPackage) CatalogProduct(BasicCommonClasses.CatalogProduct) CommandWrapper(ClientServerApi.CommandWrapper) GroceryListIsEmpty(CustomerContracts.ACustomerExceptions.GroceryListIsEmpty) SocketTimeoutException(java.net.SocketTimeoutException) InvalidCommandDescriptor(CustomerContracts.ACustomerExceptions.InvalidCommandDescriptor) ForgotPasswordWrongAnswer(CustomerContracts.ACustomerExceptions.ForgotPasswordWrongAnswer) UsernameAlreadyExists(CustomerContracts.ACustomerExceptions.UsernameAlreadyExists) ProductCatalogDoesNotExist(CustomerContracts.ACustomerExceptions.ProductCatalogDoesNotExist)

Example 20 with CriticalError

use of SMExceptions.CommonExceptions.CriticalError in project SmartCity-Market by TechnionYP5777.

the class Customer method checkOutGroceryList.

@Override
public Double checkOutGroceryList() throws CriticalError, CustomerNotConnected, GroceryListIsEmpty {
    String serverResponse;
    Double $ = totalSum;
    log.info("Creating CHECKOUT_GROCERY_LIST command wrapper to customer with id: " + id);
    establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
    try {
        serverResponse = sendRequestWithRespondToServer((new CommandWrapper(id, CommandDescriptor.CHECKOUT_GROCERY_LIST)).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 | AmountBiggerThanAvailable | ProductPackageDoesNotExist | AuthenticationError | ProductCatalogDoesNotExist | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
        log.fatal("Critical bug: this command result isn't supposed to return here");
        throw new CriticalError();
    }
    /* update customer data: groceryList, cartProductCache, totalSum */
    groceryList = new GroceryList();
    cartProductCache = new HashMap<Long, CartProduct>();
    totalSum = Double.valueOf(0);
    totalProductsAmount = 0;
    log.info("CHECKOUT_GROCERY_LIST command succeed.");
    return $;
}
Also used : AuthenticationError(CustomerContracts.ACustomerExceptions.AuthenticationError) CriticalError(SMExceptions.CommonExceptions.CriticalError) GroceryList(BasicCommonClasses.GroceryList) CommandWrapper(ClientServerApi.CommandWrapper) InvalidParameter(CustomerContracts.ACustomerExceptions.InvalidParameter) SocketTimeoutException(java.net.SocketTimeoutException) AmountBiggerThanAvailable(CustomerContracts.ACustomerExceptions.AmountBiggerThanAvailable) InvalidCommandDescriptor(CustomerContracts.ACustomerExceptions.InvalidCommandDescriptor) ForgotPasswordWrongAnswer(CustomerContracts.ACustomerExceptions.ForgotPasswordWrongAnswer) CartProduct(BasicCommonClasses.CartProduct) ProductPackageDoesNotExist(CustomerContracts.ACustomerExceptions.ProductPackageDoesNotExist) UsernameAlreadyExists(CustomerContracts.ACustomerExceptions.UsernameAlreadyExists) ProductCatalogDoesNotExist(CustomerContracts.ACustomerExceptions.ProductCatalogDoesNotExist)

Aggregations

CriticalError (SMExceptions.CommonExceptions.CriticalError)45 CommandWrapper (ClientServerApi.CommandWrapper)39 InvalidCommandDescriptor (EmployeeDefs.AEmployeeException.InvalidCommandDescriptor)22 ParamIDAlreadyExists (EmployeeDefs.AEmployeeException.ParamIDAlreadyExists)22 WorkerAlreadyExists (EmployeeDefs.AEmployeeException.WorkerAlreadyExists)22 AuthenticationError (EmployeeDefs.AEmployeeException.AuthenticationError)21 EmployeeAlreadyConnected (EmployeeDefs.AEmployeeException.EmployeeAlreadyConnected)21 IngredientStillInUse (EmployeeDefs.AEmployeeException.IngredientStillInUse)21 ManfacturerStillInUse (EmployeeDefs.AEmployeeException.ManfacturerStillInUse)21 ProductAlreadyExistInCatalog (EmployeeDefs.AEmployeeException.ProductAlreadyExistInCatalog)21 ProductStillForSale (EmployeeDefs.AEmployeeException.ProductStillForSale)21 WorkerDoesNotExist (EmployeeDefs.AEmployeeException.WorkerDoesNotExist)21 AmountBiggerThanAvailable (EmployeeDefs.AEmployeeException.AmountBiggerThanAvailable)20 ParamIDDoesNotExist (EmployeeDefs.AEmployeeException.ParamIDDoesNotExist)20 ProductPackageDoesNotExist (EmployeeDefs.AEmployeeException.ProductPackageDoesNotExist)19 ProductNotExistInCatalog (EmployeeDefs.AEmployeeException.ProductNotExistInCatalog)17 SocketTimeoutException (java.net.SocketTimeoutException)14 AuthenticationError (CustomerContracts.ACustomerExceptions.AuthenticationError)10 ForgotPasswordWrongAnswer (CustomerContracts.ACustomerExceptions.ForgotPasswordWrongAnswer)10 InvalidCommandDescriptor (CustomerContracts.ACustomerExceptions.InvalidCommandDescriptor)10