Search in sources :

Example 31 with CriticalError

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

the class RegisteredCustomer method updateCustomerProfile.

@Override
public void updateCustomerProfile(CustomerProfile p) throws CustomerNotConnected, InvalidParameter, AuthenticationError, CriticalError {
    String serverResponse;
    log.info("Creating updateCustomerProfile command wrapper to customer with username: " + p.getUserName());
    establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
    /* first: getting the product from the server */
    try {
        serverResponse = sendRequestWithRespondToServer(new CommandWrapper(id, CommandDescriptor.UPDATE_CUSTOMER_PROFILE, Serialization.serialize(p)).serialize());
    } catch (SocketTimeoutException e) {
        log.fatal("Critical bug: failed to get respond from server");
        throw new CriticalError();
    }
    terminateCommunication();
    CommandWrapper $ = getCommandWrapper(serverResponse);
    try {
        resultDescriptorHandler($.getResultDescriptor());
    } catch (InvalidCommandDescriptor | CriticalError | AmountBiggerThanAvailable | ProductPackageDoesNotExist | GroceryListIsEmpty | ProductCatalogDoesNotExist | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
        log.fatal("Critical bug: this command result isn't supposed to return here");
        throw new CriticalError();
    }
    customerProfile = p;
    log.info("updateCustomerProfile command succeed.");
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) CriticalError(SMExceptions.CommonExceptions.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper)

Example 32 with CriticalError

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

the class RegisteredCustomer method removeCustomer.

@Override
public void removeCustomer() throws CustomerNotConnected, InvalidParameter, AuthenticationError, CriticalError {
    String serverResponse;
    log.info("Creating removeCustomer command wrapper to customer with username: " + customerProfile.getUserName());
    establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
    /* first: getting the product from the server */
    try {
        serverResponse = sendRequestWithRespondToServer(new CommandWrapper(id, CommandDescriptor.REMOVE_CUSTOMER, Serialization.serialize(customerProfile.getUserName())).serialize());
    } catch (SocketTimeoutException e) {
        log.fatal("Critical bug: failed to get respond from server");
        throw new CriticalError();
    }
    terminateCommunication();
    CommandWrapper $ = getCommandWrapper(serverResponse);
    try {
        resultDescriptorHandler($.getResultDescriptor());
    } catch (InvalidCommandDescriptor | CriticalError | AmountBiggerThanAvailable | ProductPackageDoesNotExist | GroceryListIsEmpty | ProductCatalogDoesNotExist | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
        log.fatal("Critical bug: this command result isn't supposed to return here");
        throw new CriticalError();
    }
    log.info("removeCustomer command succeed.");
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) CriticalError(SMExceptions.CommonExceptions.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper)

Example 33 with CriticalError

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

the class IsFreeCustomerNameTest method isFreeCustomerNameConnectionFailureTest.

@Test
public void isFreeCustomerNameConnectionFailureTest() {
    try {
        Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(CustomerDefs.loginCommandSenderId, CommandDescriptor.IS_FREE_CUSTOMER_NAME, Serialization.serialize(username)).serialize())).thenThrow(new SocketTimeoutException());
    } catch (IOException ¢) {
        fail();
    }
    try {
        customer.isFreeUsername(username);
        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 34 with CriticalError

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

the class ManageEmployeesTab method finishBtnPressed.

@FXML
void finishBtnPressed(ActionEvent __) {
    try {
        manager.registerNewWorker(new Login(userTxt.getText(), passTxt.getText(), new ForgotPasswordData(securityCombo.getSelectionModel().getSelectedItem(), securityAnswerTxt.getText())));
    } catch (InvalidParameter | CriticalError | EmployeeNotConnected | ConnectionFailure | WorkerAlreadyExists e) {
        log.fatal(e);
        log.debug(StackTraceUtil.getStackTrace(e));
        e.showInfoToUser();
    }
    createEmployeesList();
    enableRemoveButton();
}
Also used : InvalidParameter(EmployeeDefs.AEmployeeException.InvalidParameter) CriticalError(SMExceptions.CommonExceptions.CriticalError) ConnectionFailure(EmployeeDefs.AEmployeeException.ConnectionFailure) WorkerAlreadyExists(EmployeeDefs.AEmployeeException.WorkerAlreadyExists) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) Login(BasicCommonClasses.Login) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected) FXML(javafx.fxml.FXML)

Example 35 with CriticalError

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

the class ManageCatalogProductDetailsTab method renameIngrPressed.

void renameIngrPressed() {
    long id = ingredients.get(selectedIngr.iterator().next()).getId();
    try {
        manager.editIngredient(new Ingredient(id, renameIngrLbl.getText()));
    } catch (InvalidParameter | CriticalError | EmployeeNotConnected | ConnectionFailure | ParamIDDoesNotExist e) {
        log.debug(StackTraceUtil.getStackTrace(e));
        log.fatal(e);
        e.showInfoToUser();
    }
    selectedIngr.clear();
    createIngredientList();
    enableButtons();
    enableAddButtons();
}
Also used : InvalidParameter(EmployeeDefs.AEmployeeException.InvalidParameter) CriticalError(SMExceptions.CommonExceptions.CriticalError) ConnectionFailure(EmployeeDefs.AEmployeeException.ConnectionFailure) Ingredient(BasicCommonClasses.Ingredient) ParamIDDoesNotExist(EmployeeDefs.AEmployeeException.ParamIDDoesNotExist) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected)

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