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");
}
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");
}
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) {
}
}
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) {
}
}
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);
}
Aggregations