Search in sources :

Example 11 with Manufacturer

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

the class SQLDatabaseConnection method addManufacturer.

@Override
public String addManufacturer(Integer sessionID, String manufacturerName) throws CriticalError, ClientNotConnected {
    log.debug("SQL Public addManufacturer: manufacturer name: " + manufacturerName + " (SESSION: " + sessionID + " )");
    validateSessionEstablished(sessionID);
    int $;
    // START transaction
    connectionStartTransaction();
    try {
        // WRITE part of transaction
        // get "fresh" id for the new manufacturer
        $ = allocateIDToTable(ManufacturerTable.table, ManufacturerTable.manufacturerIDCol);
        String insertQuery = new InsertQuery(ManufacturerTable.table).addColumn(ManufacturerTable.manufacturerIDCol, PARAM_MARK).addColumn(ManufacturerTable.manufacturerNameCol, PARAM_MARK).validate() + "";
        insertQuery.hashCode();
        getParameterizedQuery(insertQuery, $, manufacturerName).executeUpdate();
        // END transaction
        connectionCommitTransaction();
    } catch (CriticalError | SQLException e) {
        connectionRollbackTransaction();
        throw new CriticalError();
    } finally {
        connectionEndTransaction();
    }
    return Serialization.serialize(new Manufacturer($, manufacturerName));
}
Also used : InsertQuery(com.healthmarketscience.sqlbuilder.InsertQuery) SQLException(java.sql.SQLException) Manufacturer(BasicCommonClasses.Manufacturer)

Example 12 with Manufacturer

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

the class ManageCatalogProductTab method getManufacturer.

private Manufacturer getManufacturer() {
    Manufacturer $ = null;
    String man = productManufacturerCombo.getValue();
    switch(man) {
        case "אסם":
            $ = new Manufacturer(4, man);
            break;
        case "בייגל-בייגל":
            $ = new Manufacturer(5, man);
            break;
        case "מאפיות ברמן":
            $ = new Manufacturer(2, man);
            break;
        case "עלית":
            $ = new Manufacturer(3, man);
            break;
        case "תנובה":
            $ = new Manufacturer(1, man);
            break;
    }
    return $;
}
Also used : Manufacturer(BasicCommonClasses.Manufacturer)

Example 13 with Manufacturer

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

the class ManageCatalogProductDetailsTab method addManuPressed.

void addManuPressed() {
    try {
        manager.addManufacturer(new Manufacturer(0, newManu.getText()));
    } catch (InvalidParameter | CriticalError | EmployeeNotConnected | ConnectionFailure | ParamIDAlreadyExists e) {
        log.fatal(e);
        log.debug(StackTraceUtil.getStackTrace(e));
        e.showInfoToUser();
    }
    selectedManu.clear();
    createManufacturerList();
    enableButtons();
    enableAddButtons();
}
Also used : InvalidParameter(EmployeeDefs.AEmployeeException.InvalidParameter) CriticalError(SMExceptions.CommonExceptions.CriticalError) ConnectionFailure(EmployeeDefs.AEmployeeException.ConnectionFailure) Manufacturer(BasicCommonClasses.Manufacturer) ParamIDAlreadyExists(EmployeeDefs.AEmployeeException.ParamIDAlreadyExists) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected)

Example 14 with Manufacturer

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

the class Manager method getAllManufacturers.

@Override
public List<Manufacturer> getAllManufacturers() throws InvalidParameter, CriticalError, EmployeeNotConnected, ConnectionFailure {
    log.info("Creating getAllManufacturers command wrapper");
    String serverResponse = sendRequestWithRespondToServer((new CommandWrapper(getClientId(), CommandDescriptor.GET_ALL_MANUFACTURERS, Serialization.serialize(""))).serialize());
    CommandWrapper commandDescriptor = getCommandWrapper(serverResponse);
    try {
        resultDescriptorHandler(commandDescriptor.getResultDescriptor());
    } catch (InvalidCommandDescriptor | EmployeeAlreadyConnected | AuthenticationError | ProductStillForSale | AmountBiggerThanAvailable | ProductPackageDoesNotExist | ProductAlreadyExistInCatalog | 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("getAllManufacturers command succeed.");
    return new Gson().fromJson(commandDescriptor.getData(), new TypeToken<List<Manufacturer>>() {
    }.getType());
}
Also used : AuthenticationError(EmployeeDefs.AEmployeeException.AuthenticationError) ProductNotExistInCatalog(EmployeeDefs.AEmployeeException.ProductNotExistInCatalog) CriticalError(SMExceptions.CommonExceptions.CriticalError) Gson(com.google.gson.Gson) 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) TypeToken(com.google.gson.reflect.TypeToken) WorkerAlreadyExists(EmployeeDefs.AEmployeeException.WorkerAlreadyExists) ParamIDAlreadyExists(EmployeeDefs.AEmployeeException.ParamIDAlreadyExists) Manufacturer(BasicCommonClasses.Manufacturer) ParamIDDoesNotExist(EmployeeDefs.AEmployeeException.ParamIDDoesNotExist) ManfacturerStillInUse(EmployeeDefs.AEmployeeException.ManfacturerStillInUse) ProductPackageDoesNotExist(EmployeeDefs.AEmployeeException.ProductPackageDoesNotExist)

Example 15 with Manufacturer

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

the class SQLDatabaseConnectionTest method testGetManufacturersList.

@Test
public void testGetManufacturersList() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    String result = null;
    try {
        result = sqlConnection.getManufacturersList(null);
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
    assert result != null;
    HashSet<Manufacturer> set = Serialization.deserializeManufacturersHashSet(result);
    assert set != null;
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) 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