use of EmployeeDefs.AEmployeeException.EmployeeNotConnected in project SmartCity-Market by TechnionYP5777.
the class Worker method isLoggedIn.
@Override
public boolean isLoggedIn() throws CriticalError, ConnectionFailure {
String serverResponse;
log.info("Creating is logged in command wrapper with senderID: " + getClientId());
serverResponse = sendRequestWithRespondToServer((new CommandWrapper(getClientId(), CommandDescriptor.IS_LOGGED_IN)).serialize());
CommandWrapper commandWrapper = getCommandWrapper(serverResponse);
try {
resultDescriptorHandler(commandWrapper.getResultDescriptor());
} catch (InvalidCommandDescriptor | InvalidParameter | EmployeeNotConnected | EmployeeAlreadyConnected | AuthenticationError | ProductNotExistInCatalog | ProductAlreadyExistInCatalog | ProductStillForSale | AmountBiggerThanAvailable | ProductPackageDoesNotExist | WorkerAlreadyExists | ParamIDAlreadyExists | ParamIDDoesNotExist | WorkerDoesNotExist | IngredientStillInUse | ManfacturerStillInUse e) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
log.info("is logged out from server succeed");
return Serialization.deserialize(commandWrapper.getData(), Boolean.class);
}
use of EmployeeDefs.AEmployeeException.EmployeeNotConnected in project SmartCity-Market by TechnionYP5777.
the class ManageCatalogProductDetailsTab method renameManuPressed.
void renameManuPressed() {
long id = manufacturars.get(selectedManu.iterator().next()).getId();
try {
manager.editManufacturer(new Manufacturer(id, renameManuLbl.getText()));
} catch (InvalidParameter | CriticalError | EmployeeNotConnected | ConnectionFailure | ParamIDDoesNotExist e) {
log.fatal(e);
log.debug(StackTraceUtil.getStackTrace(e));
e.showInfoToUser();
}
selectedManu.clear();
createManufacturerList();
enableButtons();
enableAddButtons();
}
use of EmployeeDefs.AEmployeeException.EmployeeNotConnected in project SmartCity-Market by TechnionYP5777.
the class ManageCatalogProductDetailsTab method addIngPressed.
void addIngPressed() {
try {
manager.addIngredient(new Ingredient(0, newIngr.getText()));
} catch (InvalidParameter | CriticalError | EmployeeNotConnected | ConnectionFailure | ParamIDAlreadyExists e) {
log.fatal(e);
log.debug(StackTraceUtil.getStackTrace(e));
e.showInfoToUser();
}
selectedIngr.clear();
createIngredientList();
enableButtons();
enableAddButtons();
}
use of EmployeeDefs.AEmployeeException.EmployeeNotConnected in project SmartCity-Market by TechnionYP5777.
the class Worker method login.
@Override
public CLIENT_TYPE login(String username, String password, boolean updateProductPictures) throws InvalidParameter, CriticalError, EmployeeAlreadyConnected, AuthenticationError, ConnectionFailure {
CommandWrapper $ = null;
log.info("Creating login command wrapper with username: " + username + " and password: " + password);
String serverResponse = sendRequestWithRespondToServer(new CommandWrapper(WorkerDefs.loginCommandSenderId, CommandDescriptor.LOGIN_EMPLOYEE, Serialization.serialize(new Login(username, password))).serialize());
try {
$ = getCommandWrapper(serverResponse);
resultDescriptorHandler($.getResultDescriptor());
} catch (InvalidCommandDescriptor | EmployeeNotConnected | ProductNotExistInCatalog | ProductAlreadyExistInCatalog | ProductStillForSale | AmountBiggerThanAvailable | ProductPackageDoesNotExist | WorkerAlreadyExists | ParamIDAlreadyExists | ParamIDDoesNotExist | WorkerDoesNotExist | IngredientStillInUse | ManfacturerStillInUse ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
setClientId($.getSenderID());
this.username = username;
this.password = password;
log.info("Login to server as " + $.getData() + " succeed. Client id is: " + getClientId());
if (updateProductPictures) {
UpdateProductPictures UpdateProductPicturesThread = new UpdateProductPictures();
UpdateProductPicturesThread.start();
}
return CLIENT_TYPE.deserialize($.getData());
}
use of EmployeeDefs.AEmployeeException.EmployeeNotConnected in project SmartCity-Market by TechnionYP5777.
the class ViewProductFromCatalogTest method ViewProductFromCatalogSuccessfulTest.
@Test
public void ViewProductFromCatalogSuccessfulTest() {
CatalogProduct testCatalogProduct = null, catalogProduct = new CatalogProduct(1234567890, "name", null, new Manufacturer(1, "Manufacturer"), "description", 22.0, null, null);
CommandWrapper commandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, Serialization.serialize(catalogProduct));
try {
Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(WorkerDefs.loginCommandSenderId, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, Serialization.serialize(new SmartCode(1234567890, null))).serialize())).thenReturn(commandWrapper.serialize());
} catch (IOException ¢) {
fail();
}
try {
testCatalogProduct = worker.viewProductFromCatalog(1234567890);
} catch (InvalidParameter | CriticalError | EmployeeNotConnected | ProductNotExistInCatalog | ConnectionFailure ¢) {
fail();
}
assertEquals(testCatalogProduct.getBarcode(), 1234567890);
assertEquals(testCatalogProduct.getManufacturer().getId(), 1);
assertEquals(testCatalogProduct.getManufacturer().getName(), "Manufacturer");
assertEquals(testCatalogProduct.getName(), "name");
}
Aggregations