Search in sources :

Example 16 with CommandWrapper

use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.

the class UpdateProductPicturesEmployeeTest method updateIsNeededTest.

@Test
public void updateIsNeededTest() {
    try {
        LocalDate currentPicturesDate = PictureManager.getCurrentDate();
        Mockito.when(clientRequestHandler.sendRequestWithRespond((new CommandWrapper(w.getClientId(), CommandDescriptor.UPDATE_PRODUCTS_PICTURES, Serialization.serialize(currentPicturesDate))).serialize())).thenReturn(new CommandWrapper(ResultDescriptor.SM_OK, Serialization.serialize(encodedZipFile4Testing)).serialize());
    } catch (IOException ยข) {
        fail();
    }
    try {
        updateProductPicturesThread.start();
        updateProductPicturesThread.join();
    } catch (Exception e) {
        System.out.println(e + "");
        fail();
    }
}
Also used : CommandWrapper(ClientServerApi.CommandWrapper) IOException(java.io.IOException) LocalDate(java.time.LocalDate) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with CommandWrapper

use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.

the class CommandExecuter method getProductPackageAmount.

private void getProductPackageAmount(SQLDatabaseConnection c) {
    ProductPackage productPackage = null;
    log.info("Get Product Package Amount command called");
    try {
        productPackage = Serialization.deserialize(inCommandWrapper.getData(), ProductPackage.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Get Product Package Amount command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    if (!productPackage.isValid()) {
        log.info("Get Product Package Amount command failed, product package is invalid");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
    } else {
        String amount = "";
        try {
            amount = productPackage.getLocation().getPlaceInMarket().equals(PlaceInMarket.STORE) ? c.getProductPackageAmonutOnShelves(inCommandWrapper.getSenderID(), productPackage) : c.getProductPackageAmonutInWarehouse(inCommandWrapper.getSenderID(), productPackage);
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, amount);
        } catch (CriticalError e) {
            log.fatal("Get Product Package Amount command failed, critical error occured from SQL Database connection");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        } catch (ClientNotConnected e) {
            log.info("Get Product Package Amount command failed, username dosen't login to the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
        } catch (ProductNotExistInCatalog e) {
            log.info("Get Product Package Amount command failed, product dosen't exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST);
        }
        log.info("Get Product Package Amount returned with amount " + amount + " finished");
    }
}
Also used : ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) CommandWrapper(ClientServerApi.CommandWrapper)

Example 18 with CommandWrapper

use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.

the class CommandExecuter method forgetPasswordGetQuestion.

private void forgetPasswordGetQuestion(SQLDatabaseConnection c) {
    String username;
    log.info("Get question for forget password command called with from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        username = Serialization.deserialize(inCommandWrapper.getData(), String.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Get question for forget password command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    try {
        if (inCommandWrapper.getSenderID() == 0) {
            /* Command sent from employee */
            String SecurityQuestion = c.getSecurityQuestionWorker(username);
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, SecurityQuestion);
        } else {
            /* Command sent from customer */
            String SecurityQuestion = c.getSecurityQuestionCustomer(username);
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, SecurityQuestion);
        }
        log.info("Get question for forget password command for user: " + username + "succeded. the question is: " + outCommandWrapper.getData());
    } catch (CriticalError e) {
        log.fatal("Get question for forget password command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotExist e) {
        log.info("Get question for forget password command failed, client is not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST);
    }
    log.info("Get question for forget password command system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist)

Example 19 with CommandWrapper

use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.

the class CommandExecuter method viewProductFromCatalogCommand.

private void viewProductFromCatalogCommand(SQLDatabaseConnection c) {
    SmartCode smartCode = null;
    log.info("View Product From Catalog command called");
    try {
        smartCode = Serialization.deserialize(inCommandWrapper.getData(), SmartCode.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for View Product From Catalog command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    if (!smartCode.isValid()) {
        log.info("View Product From Catalog command failed, barcode can't be negative");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
        return;
    }
    try {
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, c.getProductFromCatalog(inCommandWrapper.getSenderID(), smartCode.getBarcode()));
        log.info("Get product from catalog command secceeded with barcode " + smartCode.getBarcode());
    } catch (ProductNotExistInCatalog e) {
        log.info("Get product from catalog command failed, product dosen't exist in the system");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST);
    } catch (ClientNotConnected e) {
        log.info("Get product from catalog command failed, username dosen't login to the system");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    } catch (CriticalError e) {
        log.fatal("Get product from catalog command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    }
    log.info("View Product From Catalog with product barcode " + smartCode.getBarcode() + " finished");
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CommandWrapper(ClientServerApi.CommandWrapper)

Example 20 with CommandWrapper

use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.

the class CommandExecuter method loginClientCommand.

private void loginClientCommand(SQLDatabaseConnection c) {
    Login login = null;
    log.info("Login client command called");
    try {
        login = Serialization.deserialize(inCommandWrapper.getData(), Login.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for login command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    if (!login.isValid()) {
        log.info("Login command failed, username and password can't be empty");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
        return;
    }
    try {
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
        int senderID = c.loginCustomer(login.getUserName(), login.getPassword());
        outCommandWrapper.setSenderID(senderID);
        try {
            outCommandWrapper.setData(c.getCustomerProfile(login.getUserName()));
        } catch (ClientNotExist e) {
            log.fatal("Client is not exist with username: " + outCommandWrapper.getSenderID());
        }
        log.info("Login command succeded with sender ID " + outCommandWrapper.getSenderID() + " with client type " + outCommandWrapper.getData());
    } catch (AuthenticationError e) {
        log.info("Login command failed, username dosen't exist or wrong password received");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST_WRONG_PASSWORD);
    } catch (CriticalError e) {
        log.fatal("Login command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientAlreadyConnected e) {
        log.info("Login command failed, user already connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_ALREADY_CONNECTED);
    } catch (NumberOfConnectionsExceeded e) {
        log.fatal("Login command failed, too much connections (try to increase TRYS_NUMBER)");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    }
    log.info("Login client with User " + login.getUserName() + " finished");
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) Login(BasicCommonClasses.Login) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist)

Aggregations

CommandWrapper (ClientServerApi.CommandWrapper)218 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)162 Test (org.junit.Test)144 CommandExecuter (CommandHandler.CommandExecuter)135 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)124 Gson (com.google.gson.Gson)123 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)57 SmartCode (BasicCommonClasses.SmartCode)51 ProductPackage (BasicCommonClasses.ProductPackage)45 CriticalError (SMExceptions.CommonExceptions.CriticalError)39 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)39 Location (BasicCommonClasses.Location)37 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)27 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)27 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)27 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)23 InvalidCommandDescriptor (EmployeeDefs.AEmployeeException.InvalidCommandDescriptor)22 AuthenticationError (EmployeeDefs.AEmployeeException.AuthenticationError)21 EmployeeAlreadyConnected (EmployeeDefs.AEmployeeException.EmployeeAlreadyConnected)21 IngredientStillInUse (EmployeeDefs.AEmployeeException.IngredientStillInUse)21