Search in sources :

Example 6 with ProductNotExistInCatalog

use of EmployeeDefs.AEmployeeException.ProductNotExistInCatalog 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());
}
Also used : ProductNotExistInCatalog(EmployeeDefs.AEmployeeException.ProductNotExistInCatalog) CriticalError(SMExceptions.CommonExceptions.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) Login(BasicCommonClasses.Login) IngredientStillInUse(EmployeeDefs.AEmployeeException.IngredientStillInUse) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected) 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 7 with ProductNotExistInCatalog

use of EmployeeDefs.AEmployeeException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.

the class Manager method addProductToCatalog.

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

use of EmployeeDefs.AEmployeeException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.

the class Manager method editManufacturer.

@Override
public void editManufacturer(Manufacturer m) throws InvalidParameter, CriticalError, EmployeeNotConnected, ConnectionFailure, ParamIDDoesNotExist {
    log.info("Creating editManufacturer command wrapper with Manufacturer: " + m);
    String serverResponse = sendRequestWithRespondToServer((new CommandWrapper(getClientId(), CommandDescriptor.EDIT_MANUFACTURER, Serialization.serialize(m))).serialize());
    CommandWrapper commandDescriptor = getCommandWrapper(serverResponse);
    try {
        resultDescriptorHandler(commandDescriptor.getResultDescriptor());
    } catch (InvalidCommandDescriptor | EmployeeAlreadyConnected | AuthenticationError | ProductStillForSale | AmountBiggerThanAvailable | ProductPackageDoesNotExist | ProductAlreadyExistInCatalog | ProductNotExistInCatalog | WorkerAlreadyExists | ParamIDAlreadyExists | WorkerDoesNotExist | IngredientStillInUse | ManfacturerStillInUse ¢) {
        log.fatal("Critical bug: this command result isn't supposed to return here");
        throw new CriticalError();
    }
    log.info("editManufacturer command succeed.");
}
Also used : AuthenticationError(EmployeeDefs.AEmployeeException.AuthenticationError) ProductNotExistInCatalog(EmployeeDefs.AEmployeeException.ProductNotExistInCatalog) 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) ManfacturerStillInUse(EmployeeDefs.AEmployeeException.ManfacturerStillInUse) ProductPackageDoesNotExist(EmployeeDefs.AEmployeeException.ProductPackageDoesNotExist)

Example 9 with ProductNotExistInCatalog

use of EmployeeDefs.AEmployeeException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.

the class Manager method registerNewWorker.

@Override
public void registerNewWorker(Login l) throws InvalidParameter, CriticalError, EmployeeNotConnected, ConnectionFailure, WorkerAlreadyExists {
    log.info("Creating registerNewWorker command wrapper with username: " + l.getUserName());
    String serverResponse = sendRequestWithRespondToServer((new CommandWrapper(getClientId(), CommandDescriptor.REGISTER_NEW_WORKER, Serialization.serialize(l))).serialize());
    CommandWrapper commandDescriptor = getCommandWrapper(serverResponse);
    try {
        resultDescriptorHandler(commandDescriptor.getResultDescriptor());
    } catch (InvalidCommandDescriptor | EmployeeAlreadyConnected | AuthenticationError | ProductStillForSale | AmountBiggerThanAvailable | ProductPackageDoesNotExist | ProductAlreadyExistInCatalog | ProductNotExistInCatalog | ParamIDAlreadyExists | ParamIDDoesNotExist | WorkerDoesNotExist | IngredientStillInUse | ManfacturerStillInUse ¢) {
        log.fatal("Critical bug: this command result isn't supposed to return here");
        throw new CriticalError();
    }
    log.info("registerNewWorker command succeed.");
}
Also used : AuthenticationError(EmployeeDefs.AEmployeeException.AuthenticationError) ProductNotExistInCatalog(EmployeeDefs.AEmployeeException.ProductNotExistInCatalog) 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) ParamIDAlreadyExists(EmployeeDefs.AEmployeeException.ParamIDAlreadyExists) ParamIDDoesNotExist(EmployeeDefs.AEmployeeException.ParamIDDoesNotExist) ManfacturerStillInUse(EmployeeDefs.AEmployeeException.ManfacturerStillInUse) ProductPackageDoesNotExist(EmployeeDefs.AEmployeeException.ProductPackageDoesNotExist)

Example 10 with ProductNotExistInCatalog

use of EmployeeDefs.AEmployeeException.ProductNotExistInCatalog 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");
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(EmployeeDefs.AEmployeeException.ProductNotExistInCatalog) InvalidParameter(EmployeeDefs.AEmployeeException.InvalidParameter) CriticalError(SMExceptions.CommonExceptions.CriticalError) ConnectionFailure(EmployeeDefs.AEmployeeException.ConnectionFailure) Manufacturer(BasicCommonClasses.Manufacturer) CatalogProduct(BasicCommonClasses.CatalogProduct) CommandWrapper(ClientServerApi.CommandWrapper) IOException(java.io.IOException) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected) Test(org.junit.Test)

Aggregations

CommandWrapper (ClientServerApi.CommandWrapper)17 ProductNotExistInCatalog (EmployeeDefs.AEmployeeException.ProductNotExistInCatalog)17 CriticalError (SMExceptions.CommonExceptions.CriticalError)17 AmountBiggerThanAvailable (EmployeeDefs.AEmployeeException.AmountBiggerThanAvailable)16 InvalidCommandDescriptor (EmployeeDefs.AEmployeeException.InvalidCommandDescriptor)16 ProductStillForSale (EmployeeDefs.AEmployeeException.ProductStillForSale)16 AuthenticationError (EmployeeDefs.AEmployeeException.AuthenticationError)15 EmployeeAlreadyConnected (EmployeeDefs.AEmployeeException.EmployeeAlreadyConnected)15 IngredientStillInUse (EmployeeDefs.AEmployeeException.IngredientStillInUse)15 ManfacturerStillInUse (EmployeeDefs.AEmployeeException.ManfacturerStillInUse)15 ProductAlreadyExistInCatalog (EmployeeDefs.AEmployeeException.ProductAlreadyExistInCatalog)15 ProductPackageDoesNotExist (EmployeeDefs.AEmployeeException.ProductPackageDoesNotExist)15 WorkerAlreadyExists (EmployeeDefs.AEmployeeException.WorkerAlreadyExists)15 WorkerDoesNotExist (EmployeeDefs.AEmployeeException.WorkerDoesNotExist)15 ParamIDAlreadyExists (EmployeeDefs.AEmployeeException.ParamIDAlreadyExists)14 ParamIDDoesNotExist (EmployeeDefs.AEmployeeException.ParamIDDoesNotExist)12 EmployeeNotConnected (EmployeeDefs.AEmployeeException.EmployeeNotConnected)4 InvalidParameter (EmployeeDefs.AEmployeeException.InvalidParameter)3 Gson (com.google.gson.Gson)3 TypeToken (com.google.gson.reflect.TypeToken)3