/RestauraceFelServer/src/main/java/cz/cvut/fel/restauracefel/service/ServiceFacadePDA.java

https://github.com/kosekma1/cashBob · Java · 533 lines · 387 code · 116 blank · 30 comment · 6 complexity · 27004ef0a73ae98996a286d7ee931786 MD5 · raw file

  1. package cz.cvut.fel.restauracefel.service;
  2. import cz.cvut.fel.restauracefel.hibernate.Account;
  3. import cz.cvut.fel.restauracefel.hibernate.AccountStatusType;
  4. import cz.cvut.fel.restauracefel.hibernate.DiscountType;
  5. import cz.cvut.fel.restauracefel.hibernate.Menu;
  6. import cz.cvut.fel.restauracefel.hibernate.MenuItem;
  7. import cz.cvut.fel.restauracefel.hibernate.MenuItemType;
  8. import cz.cvut.fel.restauracefel.hibernate.Order;
  9. import cz.cvut.fel.restauracefel.hibernate.OrderMenuItem;
  10. import cz.cvut.fel.restauracefel.hibernate.Role;
  11. import cz.cvut.fel.restauracefel.hibernate.Table;
  12. import cz.cvut.fel.restauracefel.hibernate.User;
  13. import cz.cvut.fel.restauracefel.hibernate.UserRole;
  14. import cz.cvut.fel.restauracefel.library.service.ConfigParser;
  15. import java.io.FileNotFoundException;
  16. import java.net.InetAddress;
  17. import java.rmi.*;
  18. import java.rmi.registry.Registry;
  19. import java.rmi.server.*;
  20. import java.util.Date;
  21. import java.util.List;
  22. import cz.cvut.fel.restauracefel.server.service.controllers.AccountController;
  23. import cz.cvut.fel.restauracefel.server.service.controllers.AccountStatusTypeController;
  24. import cz.cvut.fel.restauracefel.server.service.controllers.DiscountTypeController;
  25. import cz.cvut.fel.restauracefel.server.service.controllers.MenuController;
  26. import cz.cvut.fel.restauracefel.server.service.controllers.MenuItemController;
  27. import cz.cvut.fel.restauracefel.server.service.controllers.MenuItemTypeController;
  28. import cz.cvut.fel.restauracefel.server.service.controllers.OrderController;
  29. import cz.cvut.fel.restauracefel.server.service.controllers.OrderMenuItemController;
  30. import cz.cvut.fel.restauracefel.server.service.controllers.RoleController;
  31. import cz.cvut.fel.restauracefel.server.service.controllers.TableController;
  32. import cz.cvut.fel.restauracefel.server.service.controllers.UserController;
  33. import cz.cvut.fel.restauracefel.server.service.controllers.UserRoleController;
  34. /**
  35. *
  36. * @author Jarda
  37. */
  38. public class ServiceFacadePDA extends UnicastRemoteObject implements IServiceFacadePDA {
  39. //singleton
  40. protected static ServiceFacadePDA instance = null;
  41. public ServiceFacadePDA() throws RemoteException {
  42. super();
  43. }
  44. public void initServiceFacadeRMI(Registry reg) throws java.net.UnknownHostException, RemoteException, FileNotFoundException {
  45. if (System.getSecurityManager() == null) {
  46. System.setSecurityManager(new RMISecurityManager());
  47. }
  48. String name = "ServiceFacadePDA";
  49. ConfigParser config = new ConfigParser();
  50. InetAddress inetAddress = InetAddress.getByName(config.getServerIP());
  51. //Stub
  52. IServiceFacadePDA facade = ServiceFacadePDA.getInstance();
  53. reg.rebind(name, facade);
  54. System.out.println("Servisni fasada pro modul PDA zaregistrovana pod jmenem \"ServiceFacadePDA\"");
  55. System.out.println("Pripojeni pres adresu:" + inetAddress.toString() + "\n\n");
  56. }
  57. //Vraci instanci tridy ServiceFacadePDA
  58. public static ServiceFacadePDA getInstance() throws RemoteException {
  59. if (instance == null) {
  60. instance = new ServiceFacadePDA();
  61. }
  62. return instance;
  63. }
  64. /*
  65. *
  66. * Zde bude implementace metod deklarovanych v rozhrani IServiceFacadePDA
  67. *
  68. * metody pro modul PDA
  69. */
  70. @Override
  71. public String getSomething() throws RemoteException {
  72. return "Message from PDA";
  73. }
  74. @Override
  75. public User verifyUser(String username, char[] password) throws RemoteException {
  76. return null;
  77. }
  78. /*
  79. * Copy paste z ServiceFasadeManager
  80. * pridana metoda getMenuByName
  81. *
  82. */
  83. //ACCOUNTSTATUSTYPE
  84. public List getAllAccountStatusTypes() throws RemoteException {
  85. return AccountStatusTypeController.getInstance().getAllAccountStatusTypes();
  86. }
  87. public boolean createAccountStatusType(String name, String note) throws RemoteException {
  88. return AccountStatusTypeController.getInstance().createAccountStatusType(name, note);
  89. }
  90. public AccountStatusType getAccountStatusTypeById(int id) throws RemoteException {
  91. return AccountStatusTypeController.getInstance().getAccountStatusTypeById(id);
  92. }
  93. public AccountStatusType getAccountStatusTypeByName(String name) throws RemoteException {
  94. AccountStatusType a = AccountStatusTypeController.getInstance().getAccountStatusTypeByName(name);
  95. return a;
  96. }
  97. public boolean deleteAccountStatusType(int accountStatusTypeId) throws RemoteException {
  98. return AccountStatusTypeController.getInstance().deleteAccountStatusType(accountStatusTypeId);
  99. }
  100. public String[] getAccountStatusTypeNames() throws RemoteException {
  101. return AccountStatusTypeController.getInstance().getAccountStatusTypeNames();
  102. }
  103. public Object[][] getAccountStatusTypes() throws RemoteException {
  104. return AccountStatusTypeController.getInstance().getAccountStatusTypes();
  105. }
  106. //ACCOUNT
  107. public List getAllAccounts() throws RemoteException {
  108. return AccountController.getInstance().getAllAccounts();
  109. }
  110. public boolean createAccount(String name, int accountStatusTypeId, int accountCategoryId, int tableId, int userId, int discountTypeId, String note) throws RemoteException {
  111. return AccountController.getInstance().createAccount(name, accountStatusTypeId, accountCategoryId, tableId, userId, discountTypeId, note);
  112. }
  113. public boolean updateAccount(int accountId,String name, int accountStatusTypeId, int tableId, int userId, int discountTypeId) throws RemoteException {
  114. return AccountController.getInstance().updateAccount(accountId, name, accountStatusTypeId, tableId, userId, discountTypeId);
  115. }
  116. public Account getAccountById(int id) throws RemoteException {
  117. return AccountController.getInstance().getAccountById(id);
  118. }
  119. public Account getAccountByName(String name) throws RemoteException {
  120. Account a = AccountController.getInstance().getAccountByName(name);
  121. return a;
  122. }
  123. public Object[][] getAccountsByTable(int tableId) throws RemoteException {
  124. return AccountController.getInstance().getAccountsByTable(tableId);
  125. }
  126. public Object[][] getAccountsByUser(int userId) throws RemoteException {
  127. return AccountController.getInstance().getAccountsByUser(userId);
  128. }
  129. public Object[][] getAccountsByDiscountType(int discountTypeId) throws RemoteException {
  130. return AccountController.getInstance().getAccountsByDiscountType(discountTypeId);
  131. }
  132. public Object[][] getAccountsByAccountStatusType(int accountStatusTypeId) throws RemoteException {
  133. return AccountController.getInstance().getAccountsByAccountStatusType(accountStatusTypeId);
  134. }
  135. public boolean deleteAccount(int accountId) throws RemoteException {
  136. return AccountController.getInstance().deleteAccount(accountId);
  137. }
  138. public String[] getAccountNames() throws RemoteException {
  139. return AccountController.getInstance().getAccountNames();
  140. }
  141. public Object[][] getAccounts() throws RemoteException {
  142. return AccountController.getInstance().getAccounts();
  143. }
  144. //DISCOUNTTYPE
  145. public List getAllDiscountTypes() throws RemoteException {
  146. return DiscountTypeController.getInstance().getAllDiscountTypes();
  147. }
  148. public boolean createDiscountType(String name) throws RemoteException {
  149. return DiscountTypeController.getInstance().createDiscountType(name);
  150. }
  151. public DiscountType getDiscountTypeById(int id) throws RemoteException {
  152. return DiscountTypeController.getInstance().getDiscountTypeById(id);
  153. }
  154. public DiscountType getDiscountTypeByName(String name) throws RemoteException {
  155. return DiscountTypeController.getInstance().getDiscountTypeByName(name);
  156. }
  157. public boolean deleteDiscountType(int discountTypeId) throws RemoteException {
  158. return DiscountTypeController.getInstance().deleteDiscountType(discountTypeId);
  159. }
  160. public String[] getDiscountTypeNames() throws RemoteException {
  161. return DiscountTypeController.getInstance().getDiscountTypeNames();
  162. }
  163. public Object[][] getDiscountTypes() throws RemoteException {
  164. return DiscountTypeController.getInstance().getDiscountTypes();
  165. }
  166. //ORDER methods
  167. public List getAllOrders() throws RemoteException {
  168. return OrderController.getInstance().getAllOrders();
  169. }
  170. public boolean createOrder(int isPaid, Date time, int accountId, int userId) throws RemoteException {
  171. return OrderController.getInstance().createOrder(isPaid, time, accountId, userId);
  172. }
  173. public boolean deleteOrder(int orderId) throws RemoteException {
  174. return OrderController.getInstance().deleteOrder(orderId);
  175. }
  176. public Order getOrderById(int orderId) throws RemoteException {
  177. return OrderController.getInstance().getOrderById(orderId);
  178. }
  179. public String [] getOrderNames() throws RemoteException {
  180. return OrderController.getInstance().getOrderNames();
  181. }
  182. public Object [][] getOrders() throws RemoteException {
  183. return OrderController.getInstance().getOrders();
  184. }
  185. public Object [][] getOrdersByAccount(int accountId) throws RemoteException {
  186. return OrderController.getInstance().getOrdersByAccount(accountId);
  187. }
  188. public boolean payNMenuItemsByAccount(int n, int menuItemId, int accountId) throws RemoteException {
  189. return OrderController.getInstance().payNMenuItemsByAccount(n, menuItemId, accountId);
  190. }
  191. public boolean moveNMenutItemsByAccount(int n, int menuItemId, int sourceAccountId, int targetAccountId) throws RemoteException {
  192. return OrderController.getInstance().moveNMenuItemsByAccount(n, menuItemId, sourceAccountId, targetAccountId);
  193. }
  194. //ORDERMENUITEM methods
  195. public List getAllOrderMenuItems() throws RemoteException {
  196. return OrderMenuItemController.getInstance().getAllOrderMenuItems();
  197. }
  198. public boolean createOrderMenuItem(int menuItemId, int orderId) throws RemoteException {
  199. return OrderMenuItemController.getInstance().createOrderMenuItem(menuItemId, orderId);
  200. }
  201. public boolean deleteOrderMenuItem(int orderMenuItemId) throws RemoteException {
  202. return OrderMenuItemController.getInstance().deleteOrderMenuItem(orderMenuItemId);
  203. }
  204. public OrderMenuItem getOrderMenuItemById(int orderMenuItemId) throws RemoteException {
  205. return OrderMenuItemController.getInstance().getOrderMenuItemById(orderMenuItemId);
  206. }
  207. public String [] getOrderMenuItemNames() throws RemoteException {
  208. return OrderMenuItemController.getInstance().getOrderMenuItemNames();
  209. }
  210. public Object [][] getOrderMenuItems() throws RemoteException {
  211. return OrderMenuItemController.getInstance().getOrderMenuItems();
  212. }
  213. //USER
  214. public List getAllUsers() throws RemoteException {
  215. return UserController.getInstance().getAllUsers();
  216. }
  217. public boolean createUser(String name, String surname, String pid, String username, String passwd) throws RemoteException {
  218. return UserController.getInstance().createUser(name, surname, pid, username, passwd);
  219. }
  220. public boolean createUser(String name, String surname, String pid, String username) throws RemoteException {
  221. return UserController.getInstance().createUser(name, surname, username);
  222. }
  223. public boolean isValidUser(String username, String passwd) throws RemoteException {
  224. return UserController.getInstance().isValidUser(username, passwd);
  225. }
  226. public User getUserByPID(String pid) throws RemoteException {
  227. return UserController.getInstance().getUserByPID(pid);
  228. }
  229. public User getUserByUsername(String userName) throws RemoteException {
  230. return UserController.getInstance().getUserByUsername(userName);
  231. }
  232. public User getUserById(int id) throws RemoteException {
  233. return UserController.getInstance().getUserById(id);
  234. }
  235. public boolean deleteUser(int userId) throws RemoteException {
  236. return UserController.getInstance().deleteUser(userId);
  237. }
  238. public String[] getUserNames() throws RemoteException {
  239. return UserController.getInstance().getUserNames();
  240. }
  241. public String[] getUserUsernames() throws RemoteException {
  242. return UserController.getInstance().getUserUsernames();
  243. }
  244. public Object[][] getUsers() throws RemoteException {
  245. return UserController.getInstance().getUsers();
  246. }
  247. public boolean updateUser(Integer userId, String name, String surname, String pid, String username) throws RemoteException {
  248. return UserController.getInstance().updateUser(userId, name, surname, pid, username);
  249. }
  250. public boolean updateUser(Integer userId, double credit) throws RemoteException {
  251. return UserController.getInstance().updateUser(userId, credit);
  252. }
  253. public String getDefaultPasswd() throws RemoteException {
  254. return UserController.getInstance().getDefaultPasswd();
  255. }
  256. public boolean updateUserPassword(Integer userId, String newPassword) throws RemoteException {
  257. return UserController.getInstance().updateUserPassword(userId, newPassword);
  258. }
  259. public boolean isValidOldPasswd(Integer userId, String passwd) throws RemoteException {
  260. return UserController.getInstance().isValidOldPasswd(userId, passwd);
  261. }
  262. //ROLE
  263. public List getAllRoles() throws RemoteException {
  264. return RoleController.getInstance().getAllRoles();
  265. }
  266. public String[] getRoleNames() throws RemoteException {
  267. return RoleController.getInstance().getRoleNames();
  268. }
  269. public Role getRoleByID(int id) throws RemoteException {
  270. return RoleController.getInstance().getRoleByID(id);
  271. }
  272. public Role getRoleByName(String name) throws RemoteException {
  273. return RoleController.getInstance().getRoleByName(name);
  274. }
  275. //MENUITEM
  276. public boolean createMenuItem(String name, double price, String quantity, int isAvailable, int menuItemTypeId) throws RemoteException {
  277. return MenuItemController.getInstance().createMenuItem(name, price, quantity, isAvailable, menuItemTypeId);
  278. }
  279. public boolean deleteMenuItem(int menuItemId) throws RemoteException {
  280. return MenuItemController.getInstance().deleteMenuItem(menuItemId);
  281. }
  282. public boolean updateMenuItem(int menuItemId, String name, double price, String quantity, int isAvailable, int menuItemTypeId) throws RemoteException {
  283. return MenuItemController.getInstance().updateMenuItem(menuItemId, name, price, quantity, isAvailable, menuItemTypeId);
  284. }
  285. public MenuItem getMenuItemById(int menuItemId) throws RemoteException {
  286. return MenuItemController.getInstance().getMenuItemById(menuItemId);
  287. }
  288. public MenuItem getMenuItemByName(String name) throws RemoteException {
  289. return MenuItemController.getInstance().getMenuItemByName(name);
  290. }
  291. public String[] getMenuItemNames() throws RemoteException {
  292. return MenuItemController.getInstance().getMenuItemNames();
  293. }
  294. public Object[][] getMenuItems() throws RemoteException {
  295. return MenuItemController.getInstance().getMenuItems();
  296. }
  297. public Object[][] getMenuItemsByMenu(int menuId) throws RemoteException {
  298. return MenuItemController.getInstance().getMenuItemsByMenu(menuId);
  299. }
  300. public List<MenuItem> getMenuItemsByMenuList(int menuId) throws RemoteException {
  301. return MenuItemController.getInstance().getMenuItemsByMenuList(menuId);
  302. }
  303. public Object[][] getMenuItemsByAccount(int accountId) throws RemoteException {
  304. return MenuItemController.getInstance().getMenuItemsByAccount(accountId);
  305. }
  306. public Object[][] getMenuItemsByMenuItemType(int menuItemTypeId) throws RemoteException {
  307. return MenuItemController.getInstance().getMenuItemsByMenuItemType(menuItemTypeId);
  308. }
  309. public Object [][] getAllMenuItemsByAccount(int accountId) throws RemoteException {
  310. return MenuItemController.getInstance().getAllMenuItemsByAccount(accountId);
  311. }
  312. public List<MenuItem> getMenuItemsByMenuItemTypeList(int menuItemTypeId) throws RemoteException {
  313. return MenuItemController.getInstance().getMenuItemsByMenuItemTypeList(menuItemTypeId);
  314. }
  315. //MENU
  316. public boolean createMenu(int userId, String name, Date date) throws RemoteException {
  317. return MenuController.getInstance().createMenu(userId, name, date);
  318. }
  319. public boolean deleteMenu(int menuId) throws RemoteException {
  320. return MenuController.getInstance().deleteMenu(menuId);
  321. }
  322. public boolean updateMenu(int menuId, int userId, String name, Date date) throws RemoteException {
  323. return MenuController.getInstance().updateMenu(menuId, userId, name, date);
  324. }
  325. public Menu getMenuById(int menuId) throws RemoteException {
  326. Menu menu = MenuController.getInstance().getMenuById(menuId);
  327. return menu;
  328. }
  329. public Menu getMenuByName(String name) throws RemoteException {
  330. return MenuController.getInstance().getMenuByName(name);
  331. }
  332. public Object[][] getMenus() throws RemoteException {
  333. return MenuController.getInstance().getMenus();
  334. }
  335. public String[] getMenuNames() throws RemoteException {
  336. return MenuController.getInstance().getMenuNames();
  337. }
  338. //USERROLE
  339. public boolean createUserRole(int userId, int roleId) throws RemoteException {
  340. return UserRoleController.getInstance().createUserRole(userId, roleId);
  341. }
  342. public void deleteUserRole(int userId, int roleId) throws RemoteException {
  343. UserRoleController.getInstance().deleteUserRole(userId, roleId);
  344. }
  345. public UserRole getUserRoleById(int userRoleId) throws RemoteException {
  346. return UserRoleController.getInstance().getUserRoleById(userRoleId);
  347. }
  348. public List getUserRoleByUserId(int userId) throws RemoteException {
  349. return UserRoleController.getInstance().getUserRoleByUserId(userId);
  350. }
  351. public boolean isExistedUserRole(int userId, int roleId) throws RemoteException {
  352. UserRole ur = UserRoleController.getInstance().getUserRoleByUserAndRole(userId, roleId);
  353. if (ur == null) {
  354. return false;
  355. }
  356. return true;
  357. }
  358. public boolean[] getUserRoles(int userId) throws RemoteException {
  359. return UserRoleController.getInstance().getUserRoles(userId);
  360. }
  361. public boolean isUserRole(int userId, int roleId) throws RemoteException {
  362. return UserRoleController.getInstance().isUserRole(userId, roleId);
  363. }
  364. //TABLE
  365. public boolean createTable(int tableNumber, int numberOfPlaces) throws RemoteException {
  366. return TableController.getInstance().createTable(tableNumber, numberOfPlaces);
  367. }
  368. public boolean deleteTable(int tableId) throws RemoteException {
  369. return TableController.getInstance().deleteTable(tableId);
  370. }
  371. public boolean updateTable(int tableId, int tableNumber, int numberOfPlaces) throws RemoteException {
  372. return TableController.getInstance().updateTable(tableId, tableNumber, numberOfPlaces);
  373. }
  374. public Table getTableById(int tableId) throws RemoteException {
  375. return TableController.getInstance().getTableById(tableId);
  376. }
  377. public Table getTableByTableNumber(int tableNumber) throws RemoteException {
  378. return TableController.getInstance().getTableByTableNumber(tableNumber);
  379. }
  380. public int[] getTableNumbers() throws RemoteException {
  381. return TableController.getInstance().getTableNumbers();
  382. }
  383. public String[] getTableNames() throws RemoteException {
  384. return TableController.getInstance().getTableNames();
  385. }
  386. public Object[][] getTables() throws RemoteException {
  387. return TableController.getInstance().getTables();
  388. }
  389. //MENUITEMTYPE
  390. public boolean createMenuItemType(String name) throws RemoteException {
  391. return MenuItemTypeController.getInstance().createMenuItemType(name);
  392. }
  393. public boolean deleteMenuItemType(int menuItemTypeId) throws RemoteException {
  394. return MenuItemTypeController.getInstance().deleteMenuItemType(menuItemTypeId);
  395. }
  396. public boolean updateMenuItemType(int menuItemTypeId, String name) throws RemoteException {
  397. return MenuItemTypeController.getInstance().updateMenuItemType(menuItemTypeId, name);
  398. }
  399. public MenuItemType getMenuItemTypeById(int menuItemTypeId) throws RemoteException {
  400. return MenuItemTypeController.getInstance().getMenuItemTypeById(menuItemTypeId);
  401. }
  402. public MenuItemType getMenuItemTypeByName(String name) throws RemoteException {
  403. return MenuItemTypeController.getInstance().getMenuItemTypeByName(name);
  404. }
  405. public String[] getMenuItemTypeNames() throws RemoteException {
  406. return MenuItemTypeController.getInstance().getMenuItemTypeNames();
  407. }
  408. public List<MenuItemType> getMenuItemTypesList() throws RemoteException {
  409. return MenuItemTypeController.getInstance().getMenuItemTypesList();
  410. }
  411. public Object[][] getMenuItemTypes() throws RemoteException {
  412. return MenuItemTypeController.getInstance().getMenuItemTypes();
  413. }
  414. public boolean isDeletableMenuItemType(int menuItemTypeId) throws RemoteException {
  415. return MenuItemTypeController.getInstance().isDeletableMenuItemType(menuItemTypeId);
  416. }
  417. }