Search in sources :

Example 21 with Manufacturer

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

the class SQLJsonGenerator method ProductToJson.

/**
	 * convert product from ResultSet to Json representation of product
	 * 
	 * @param product
	 *            - ResultSet of the product\s joined with manufactures table
	 *            (assuming the ResultSet ordered by product barcode) the
	 *            ResultSet need to point to the product to convert). this
	 *            object will point the next product after returning.
	 * @param productIngredients
	 *            - ResultSet of the product\s ingredients (assuming the
	 *            ResultSet ordered by product barcode) the ResultSet should
	 *            pointing the product to convert, if it has ingredients. if so,
	 *            this object will point the next product after returning.
	 * @param productLocations
	 *            - ResultSet of the product\s locations (assuming the ResultSet
	 *            ordered by product barcode) the ResultSet should pointing the
	 *            product to convert, if it has ingredients. if so, this object
	 *            will point the next product after returning.
	 * @return
	 * @throws CriticalError
	 */
static String ProductToJson(ResultSet product, ResultSet productIngredients, ResultSet productLocations) throws CriticalError {
    HashSet<Location> locations;
    HashSet<Ingredient> ingredients;
    try {
        long productBarcode = product.getLong(ProductsCatalogTable.barcodeCol.getColumnNameSQL());
        // adding all ingredients
        ingredients = createIngredientsListByBarcode(productBarcode, productIngredients);
        // adding all locations
        locations = createLocationsList(productBarcode, productLocations);
        // get product other details
        String productManufacturerName = getStringFromResultset(product, ManufacturerTable.manufacturerNameCol);
        int productManufacturerID = product.getInt(ManufacturerTable.manufacturerIDCol.getColumnNameSQL());
        String productDescription = getStringFromResultset(product, ProductsCatalogTable.productDescriptionCol), productName = getStringFromResultset(product, ProductsCatalogTable.productNameCol), productPicture = getStringFromResultset(product, ProductsCatalogTable.productPictureCol);
        double productPrice = product.getDouble(ProductsCatalogTable.productPriceCol.getColumnNameSQL());
        product.next();
        return Serialization.serialize(new CatalogProduct(productBarcode, productName, ingredients, new Manufacturer(productManufacturerID, productManufacturerName), productDescription, productPrice, productPicture, locations));
    } catch (SQLException e) {
        throw new SQLDatabaseException.CriticalError();
    }
}
Also used : SQLException(java.sql.SQLException) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CatalogProduct(BasicCommonClasses.CatalogProduct) Ingredient(BasicCommonClasses.Ingredient) Manufacturer(BasicCommonClasses.Manufacturer) Location(BasicCommonClasses.Location)

Example 22 with Manufacturer

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

the class Serialization method deserializeManufacturersHashSet.

public static HashSet<Manufacturer> deserializeManufacturersHashSet(String hashsetToDeserialize) {
    Gson gson = new Gson();
    Type hashsetType = new TypeToken<HashSet<Manufacturer>>() {
    }.getType();
    HashSet<Manufacturer> result = gson.fromJson(hashsetToDeserialize, hashsetType);
    return result;
}
Also used : Type(java.lang.reflect.Type) Manufacturer(BasicCommonClasses.Manufacturer) Gson(com.google.gson.Gson) HashSet(java.util.HashSet)

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