use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method getAllWorkers.
private void getAllWorkers(SQLDatabaseConnection c) {
log.info("Get all workers from serderID " + inCommandWrapper.getSenderID() + " command called");
try {
String workersList = c.getWorkersList(inCommandWrapper.getSenderID());
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, workersList);
} catch (ClientNotConnected e) {
log.info("Get all workers command failed, client is not connected");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
} catch (CriticalError e) {
log.fatal("Get all workers command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
}
log.info("Get all workers from system finished");
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method removeIngredient.
private void removeIngredient(SQLDatabaseConnection c) {
Ingredient ingredient = null;
log.info("Remove ingredient from serderID " + inCommandWrapper.getSenderID() + " command called");
try {
ingredient = Serialization.deserialize(inCommandWrapper.getData(), Ingredient.class);
} catch (java.lang.RuntimeException e) {
log.fatal("Failed to parse data for Remove Ingredient command");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
return;
}
log.info("Trying to remove ingredient " + ingredient + " from system");
try {
c.removeIngredient(inCommandWrapper.getSenderID(), ingredient);
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
} catch (CriticalError e) {
log.fatal("Remove ingredient command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (ClientNotConnected e) {
log.info("Remove ingredient customer command failed, client is not connected");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
} catch (IngredientNotExist e) {
log.info("Remove ingredient customer command failed, ingredient does not exist");
outCommandWrapper = new CommandWrapper(ResultDescriptor.PARAM_ID_IS_NOT_EXIST);
} catch (IngredientStillUsed e) {
log.info("Remove ingredient customer command failed, ingredient still in use");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INGREDIENT_STILL_IN_USE);
}
log.info("Remove ingredient " + ingredient + " from system finished");
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method isLoggedInCommand.
private void isLoggedInCommand(SQLDatabaseConnection c) {
log.info("Is logged in command called with senderID " + inCommandWrapper.getSenderID());
try {
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, Serialization.serialize(c.isClientLoggedIn(inCommandWrapper.getSenderID())));
} catch (CriticalError e) {
log.fatal("Is logged in command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
}
log.info("Is logged in command finished");
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method removeProductPackageFromStoreCommand.
private void removeProductPackageFromStoreCommand(SQLDatabaseConnection c) {
ProductPackage productPackage = null;
log.info("Remove Product Package From Store command called");
try {
productPackage = Serialization.deserialize(inCommandWrapper.getData(), ProductPackage.class);
} catch (java.lang.RuntimeException e) {
log.fatal("Failed to parse data for Remove Product Package From Store command");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
return;
}
if (!productPackage.isValid()) {
log.info("Remove Product Package From Store command failed, product package is invalid");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
} else {
try {
if (productPackage.getLocation().getPlaceInMarket().equals(PlaceInMarket.STORE))
c.removeProductPackageFromShelves(inCommandWrapper.getSenderID(), productPackage);
else
c.removeProductPackageFromWarehouse(inCommandWrapper.getSenderID(), productPackage);
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
} catch (CriticalError e) {
log.fatal("Remove Product Package From Store command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (ClientNotConnected e) {
log.info("Remove Product Package From Store command failed, username dosen't login to the system");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
} catch (ProductNotExistInCatalog e) {
log.info("Remove Product Package From Store command failed, product dosen't exist in the system");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST);
} catch (ProductPackageAmountNotMatch e) {
log.info("Remove Product Package From Store command failed, try to place more than available");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_PRODUCT_PACKAGE_AMOUNT_BIGGER_THEN_AVAILABLE);
} catch (ProductPackageNotExist e) {
log.info("Remove Product Package From Store command failed, package dosen't exist in the system");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_PRODUCT_PACKAGE_DOES_NOT_EXIST);
}
log.info("Remove Product Package From Store with product package barcode " + productPackage.getSmartCode().getBarcode() + " and amount " + productPackage.getAmount() + " finished");
}
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method registerNewCustomer.
private void registerNewCustomer(SQLDatabaseConnection c) {
CustomerProfile profile = null;
log.info("Register new customer from serderID " + inCommandWrapper.getSenderID() + " command called");
try {
profile = Serialization.deserialize(inCommandWrapper.getData(), CustomerProfile.class);
} catch (java.lang.RuntimeException e) {
log.fatal("Failed to parse data for Register New Customer command");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
return;
}
log.info("Trying to register new customer " + profile + " to system");
try {
c.registerCustomer(profile.getUserName(), profile.getPassword());
c.setCustomerProfile(profile.getUserName(), profile);
c.setSecurityQACustomer(profile.getUserName(), profile.getForgetPassword());
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
} catch (CriticalError e) {
log.fatal("Register new customer command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (ClientAlreadyExist e) {
log.info("Register new customer command failed, client already exists");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_ALREADY_EXISTS);
} catch (ClientNotExist e) {
log.fatal("Register new customer command failed, the sql report that the client not exists but i added it just now");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (IngredientNotExist e) {
log.info("Register new customer command failed, client try to use not existed ingredient");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
}
log.info("Register new customer " + profile + " to system finished");
}
Aggregations