Search in sources :

Example 1 with Manufacturer

use of BasicCommonClasses.Manufacturer in project SmartCity-Market by TechnionYP5777.

the class CommandExecuter method addNewManufacturer.

private void addNewManufacturer(SQLDatabaseConnection c) {
    Manufacturer manufacturer = null;
    log.info("Add new manufacturer from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        manufacturer = Serialization.deserialize(inCommandWrapper.getData(), Manufacturer.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Add New Manufacturer command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to add new manufacturer " + manufacturer + " to system");
    try {
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, c.addManufacturer(inCommandWrapper.getSenderID(), manufacturer.getName()));
    } catch (CriticalError e) {
        log.fatal("Add new manufacturer command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotConnected e) {
        log.info("Add new manufacturer command failed, client is not connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    }
    log.info("Add new manufacturer " + manufacturer + " to system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) CommandWrapper(ClientServerApi.CommandWrapper)

Example 2 with Manufacturer

use of BasicCommonClasses.Manufacturer in project SmartCity-Market by TechnionYP5777.

the class CommandExecuter method removeManufacturer.

private void removeManufacturer(SQLDatabaseConnection c) {
    Manufacturer manufacturer = null;
    log.info("Remove manufacturer from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        manufacturer = Serialization.deserialize(inCommandWrapper.getData(), Manufacturer.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Remove Manufacturer command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to remove manufacturer " + manufacturer + " from system");
    try {
        c.removeManufacturer(inCommandWrapper.getSenderID(), manufacturer);
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
    } catch (CriticalError e) {
        log.fatal("Remove manufacturer command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotConnected e) {
        log.info("Remove manufacturer command failed, client is not connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    } catch (ManufacturerNotExist e) {
        log.info("Remove manufacturer customer command failed, manufacturer does not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.PARAM_ID_IS_NOT_EXIST);
    } catch (ManufacturerStillUsed e) {
        log.info("Remove manufacturer customer command failed, manufacturer still in use");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_MANUFACTURER_STILL_IN_USE);
    }
    log.info("Remove manufacturer " + manufacturer + " from system finished");
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) CommandWrapper(ClientServerApi.CommandWrapper)

Example 3 with Manufacturer

use of BasicCommonClasses.Manufacturer in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testCantEditNotExistedManufacturer.

@Test
public void testCantEditNotExistedManufacturer() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    final String manufacturerName = "manydebug";
    Manufacturer manufacturer = new Manufacturer(999, manufacturerName);
    try {
        sqlConnection.editManufacturer(null, manufacturer);
        fail();
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    } catch (ManufacturerNotExist e) {
    }
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) Test(org.junit.Test)

Example 4 with Manufacturer

use of BasicCommonClasses.Manufacturer in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testCantRemoveNotExistedManufacturer.

@Test
public void testCantRemoveNotExistedManufacturer() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    final String manufacturerName = "manydebug";
    Manufacturer manufacturer = new Manufacturer(999, manufacturerName);
    try {
        sqlConnection.removeManufacturer(null, manufacturer);
        fail();
    } catch (CriticalError | ClientNotConnected | ManufacturerStillUsed e) {
        fail();
    } catch (ManufacturerNotExist e) {
    }
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) Test(org.junit.Test)

Example 5 with Manufacturer

use of BasicCommonClasses.Manufacturer in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testAddRemoveManufacturer.

@Test
public void testAddRemoveManufacturer() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    final String manufacturerName = "manydebug";
    String result = null;
    Manufacturer manufacturer = null;
    //test add ingredient
    try {
        String tempID = sqlConnection.addManufacturer(null, manufacturerName);
        manufacturer = Serialization.deserialize(tempID, Manufacturer.class);
        result = sqlConnection.getManufacturersList(null);
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
    assert result != null;
    HashSet<Manufacturer> set = Serialization.deserializeManufacturersHashSet(result);
    assert set != null;
    assert set.contains(manufacturer);
    //test remove ingredient
    try {
        sqlConnection.removeManufacturer(null, manufacturer);
        result = sqlConnection.getManufacturersList(null);
    } catch (CriticalError | ClientNotConnected | ManufacturerNotExist | ManufacturerStillUsed e) {
        fail();
    }
    assert result != null;
    set = Serialization.deserializeManufacturersHashSet(result);
    assert set != null;
    assert !set.contains(manufacturer);
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) Test(org.junit.Test)

Aggregations

Manufacturer (BasicCommonClasses.Manufacturer)22 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)13 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)12 Test (org.junit.Test)12 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)9 CatalogProduct (BasicCommonClasses.CatalogProduct)6 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)6 Ingredient (BasicCommonClasses.Ingredient)5 Location (BasicCommonClasses.Location)5 CommandWrapper (ClientServerApi.CommandWrapper)5 Gson (com.google.gson.Gson)5 HashSet (java.util.HashSet)5 CriticalError (SMExceptions.CommonExceptions.CriticalError)4 ManufacturerStillUsed (SQLDatabase.SQLDatabaseException.ManufacturerStillUsed)4 SmartCode (BasicCommonClasses.SmartCode)3 ConnectionFailure (EmployeeDefs.AEmployeeException.ConnectionFailure)3 EmployeeNotConnected (EmployeeDefs.AEmployeeException.EmployeeNotConnected)3 InvalidParameter (EmployeeDefs.AEmployeeException.InvalidParameter)3 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)3 ParamIDAlreadyExists (EmployeeDefs.AEmployeeException.ParamIDAlreadyExists)2