1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
|
package ecom.session;
import ecom.exception.EcomException;
import ecom.entity.Account;
import ecom.entity.Adress;
import ecom.entity.Categories;
import ecom.entity.Country;
import ecom.entity.Customers;
import ecom.entity.Products;
import ecom.entity.ProductStore;
import ecom.entity.Stores;
import ecom.entityFacade.*;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Remote;
import javax.ejb.Stateful;
@Stateful
//@Remote(EcomAdminRemote.class)
public class EcomAdminBean extends EcomGenericBean implements EcomAdminRemote {
/********** METHODE POUR LES ACCOUNT
* createAccount
* listAccount
* modifyAccount
* deleteAccount
*/
/**
*
* @param iban : iban du compte
* @param accountOwner : correspond au nom dans le cas d'un client, ou du nom du magazin dans le cas d'un store
* @param balance : balance du compte
*/
@Override
public void createAccount(String iban, String accountOwner, double balance) throws EcomException {
//Creation de l'Account
Account account = new Account();
account.setIban(iban);
account.setBalance(Double.valueOf(balance));
// Creation du DAO pour creer le compte
AccountFacade accountDao = new AccountFacade();
accountDao.create(account);
// mise a jour de l'utilisateur qui possede le nouveau compte
CustomersFacade customerDao = new CustomersFacade();
Customers c = customerDao.findByName(accountOwner);
if (null == c) {
// il s'agit d'un store
throw new EcomException("On ne peut pas encore ajouter de compte pour un store");
} else {
// il s'agit d'un customer
c.setAccountId(account);
customerDao.edit(c);
}
}
@Override
public void createCategory(String label, String description) throws EcomException {
//Creation de l'Account
Categories category = new Categories();
category.setLabel(label);
category.setDescription(description);
// Creation du DAO pour creer le compte
CategoriesFacade categoryDao = new CategoriesFacade();
categoryDao.create(category);
}
@Override
public void deleteCategory(int id) {
Categories c = null;
CategoriesFacade categoryDao = new CategoriesFacade();
c = categoryDao.find(id);
categoryDao.remove(c);
}
@Override
/**
* List
*/
public List<Account> listAccount() {
AccountFacade accountDao = new AccountFacade();
List<Account> accountList = accountDao.findAll();
return accountList;
}
@Override
/**
* List
*/
public Account getAccountByIban(String iban) {
AccountFacade accountDao = new AccountFacade();
Account account = accountDao.findByIban(iban);
return account;
}
@Override
/**
* List
*/
public Account getAccountById(int id) {
AccountFacade accountDao = new AccountFacade();
Account account = accountDao.find(id);
return account;
}
@Override
/**
* Permet de modifier la balance d'un compte a partir de son iban
*/
public void modifyAccount(int id, String iban, double balance) {
AccountFacade accountDao = new AccountFacade();
Account account = accountDao.find(id);
account.setIban(iban);
account.setBalance(balance);
accountDao.edit(account);
}
@Override
public void deleteAccount(int id) {
Account a = null;
AccountFacade accountDao = new AccountFacade();
a = accountDao.find(id);
accountDao.remove(a);
}
/********** METHODE POUR LES STORES
* createStore
* listStore
* modifyStore
* deleteStore
*/
/**
* Créer un magasin à partir de son nom
* @param name
*/
public void createStore(String name) {
//Creation de l'Account
Account account = new Account();
Integer idAccount =0;
account.setIdAccount(idAccount);
//Création du store
Stores store = new Stores();
store.setName(name);
store.setAccountId(account);
// Creation du DAO pour creer le compte
StoresFacade storeDAO = new StoresFacade();
storeDAO.create(store);
}
@Override
public void modifyStore(Integer storeId, String newNameStore) {
//Recherche du store correspondant à l'id
Stores store = new Stores();
//Création des dao
StoresFacade storeDAO = new StoresFacade();
store = storeDAO.find(storeId);
//changement
store.setName(newNameStore);
//transaction
storeDAO.edit(store);
}
@Override
public void associateProductToStore(int productId, int storeId, int stock, Double price) throws EcomException {
Stores store = new Stores();
Products product = new Products();
StoresFacade storeDAO = new StoresFacade();
ProductsFacade productDAO = new ProductsFacade();
store = storeDAO.find(storeId);
product = productDAO.find(productId);
if(null == store) {
throw new EcomException("le Store avec l'id "+storeId+" n'existe pas");
} else if(null == product) {
throw new EcomException("le Product avec l'id "+productId+" n'existe pas");
} else {
ProductStore productStore = new ProductStore(storeId, productId);
ProductStoreFacade productStoreDAO = new ProductStoreFacade();
productStore.setPrice(price);
productStore.setStock(stock);
productStoreDAO.create(productStore);
}
}
@Override
public void associateAccountToStore(Integer storeId, Integer accountID) {
//Recherche du store correspondant à l'id
Stores store = new Stores();
StoresFacade storeDAO = new StoresFacade();
store = storeDAO.find(storeId);
//recherche du compte
Account account = new Account();
AccountFacade accountDAO = new AccountFacade();
account = accountDAO.find(accountID);
//association du compte au store
store.setAccountId(account) ;
//transaction
storeDAO.edit(store);
}
/**
* Supprime un magasin a partir de son ID
* @param storeId
*/
@Override
public void deleteStore(Integer storeId) {
//Recherche du store correspondant à l'id
Stores store = new Stores();
//Création des dao
StoresFacade storeDAO = new StoresFacade();
store = storeDAO.find(storeId);
//suprresion du store
storeDAO.remove(store);
}
public void createProduct(String productName, String description, int categoryId) throws EcomException {
Products product = new Products();
ProductsFacade productDAO = new ProductsFacade();
CategoriesFacade categoryDAO = new CategoriesFacade();
product.setName(productName);
product.setDescription(description);
Categories category = categoryDAO.find(categoryId);
if (null == category) {
throw new EcomException("La categorie n'existe pas");
} else {
// il s'agit d'un customer
product.setCategoryId(category);
productDAO.create(product);
}
}
/********** METHODE POUR LES CUSTOMERS
* createCustomer
* listCustomer
* modifyCustomer
* deleteCustomer
*/
@Override
public List<Customers> listCustomer() {
List<Customers> customerList ;
CustomersFacade customerDao = new CustomersFacade();
customerList = customerDao.findAll2();
return customerList;
}
/**
* Permet de creer un customer a partir d'un compte existant
* @param lastName
* @param firstName
* @param email
* @param password
* @param street
* @param zipCode
* @param city
* @param countryId
* @param idAccount
* @throws EcomException
*/
@Override
public void createCustomer(String lastName, String firstName, String email, String password, String street, String zipCode, String city, int countryId, int idAccount) throws EcomException {
// Declarations des DAOs
CustomersFacade customerDAO = new CustomersFacade();
AdressFacade adressDAO = new AdressFacade();
AccountFacade accountDAO = new AccountFacade();
// Creation des references de l'objet customer
Customers customer = new Customers();
Adress adress = new Adress();
List<Adress> adressList = new ArrayList();
adress.setCity(city);
adress.setStreet(street);
adress.setZipcode(zipCode);
adress.setCountryId(new Country(countryId));
adressList.add(adress);
customer.setFirstName(firstName);
customer.setLastName(lastName);
customer.setEmail(email);
customer.setPassword(password);
customer.setAdressCollection(adressList);
Account a= accountDAO.find(idAccount);
if (null == a) {
throw new EcomException("L'account n'existe pas");
} else {
// Debut des transactions
customer.setAccountId(a);
adressDAO.create(adress);
customerDAO.create(customer);
}
// fermeture des session
}
/**
* Permet de creer un customer y compris le compte
* @param lastName
* @param firstName
* @param email
* @param password
* @param street
* @param zipCode
* @param city
* @param countryId
* @param iban
* @param balance
* @throws EcomException
*/
public void createCustomer(String lastName, String firstName, String email, String password, String street, String zipCode, String city, int countryId, String iban, double balance) {
// Declarations des DAOs
CustomersFacade customerDAO = new CustomersFacade();
AdressFacade adressDAO = new AdressFacade();
AccountFacade accountDAO = new AccountFacade();
// Creation des references de l'objet customer
Customers customer = new Customers();
Adress adress = new Adress();
List<Adress> adressList = new ArrayList();
Account account = new Account();
adress.setCity(city);
adress.setStreet(street);
adress.setZipcode(zipCode);
adress.setCountryId(new Country(countryId));
adressList.add(adress);
account.setIban(iban);
account.setBalance(balance);
customer.setFirstName(firstName);
customer.setLastName(lastName);
customer.setEmail(email);
customer.setPassword(password);
customer.setAdressCollection(adressList);
customer.setAccountId(account);
// Debut des transactions
accountDAO.create(account);
adressDAO.create(adress);
customerDAO.create(customer);
}
@Override
public void modifyCustomer(String lastName, String firtName, String email) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void deleteCustomer(int id) {
Customers c = null;
CustomersFacade customerDao = new CustomersFacade();
c = customerDao.find(id);
customerDao.remove(c);
}
@Override
public void addAdressToCustomer(Customers c) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
/**
* Permet de lister les country afin de saisir la totalite de l'adresse pour la creation d'un customer
*/
public List<Country> listCountry() {
List<Country> countryList = null;
CountryFacade dao = new CountryFacade();
countryList = dao.findAll();
return countryList;
}
@Override
public List<Products> listProducts() {
List<Products> productList = null;
ProductsFacade productDAO = new ProductsFacade();
productList = productDAO.findAll();
return productList;
}
/**
* liste les produits d'un store
* @param idStore
* @return la liste des produits d'un store
*/
@Override
public List<ProductStore> listProductsStore(int idStore) {
List<ProductStore> productStoreList = null;
ProductStoreFacade productStoreDAO = new ProductStoreFacade();
productStoreList = productStoreDAO.findByStoreId(idStore);
return productStoreList;
}
/**
* Liste les produits d'un catégorie
* @param idCategory
* @return une liste de produit
*/
/*
@Override
public List<Product> listProductsByCategory(int idCategory) {
List<Product> productList = null;
ProductDAO productDAO = new ProductDAO();
productList = productDAO.findAllByCategory(idCategory);
productDAO.closeSession();
return productList;
}
*/
/**
* Liste toutes les catégories
*/
public List<Categories> listCategory() {
CategoriesFacade categoryDao = new CategoriesFacade();
List<Categories> categoryList = categoryDao.findAll();
return categoryList;
}
@Override
/**
* Retourne la catégorie en fonction de l'id
*/
public Categories findCategory(int idCategory) {
CategoriesFacade categoryDao = new CategoriesFacade();
Categories category = categoryDao.find(idCategory);
return category;
}
@Override
public List<Products> findProductsByInName(String inName) {
throw new UnsupportedOperationException("Not supported yet.");
}
} |
Partager