ПРИЛОЖЕНИЕ А
(обязательное)
Функциональная модель сервиса электронного кафе
Рисунок А.1 - Контекстная диаграмма
функциональной модели
Рисунок А.2 - Общее функционирование системы
Рисунок А.3 - Декомпозиция создания меню
Рисунок А.4 - Декомпозиция обработки запросов клиента
Рисунок А.5 - Декомпозиция создания заказа
ПРИЛОЖЕНИЕ Б
(обязательное)
Диаграмма вариантов использования
Рисунок Б.1 - Диаграмма вариантов использования
пользователь
Рисунок Б.2 - Диаграмма вариантов использования
пользователь
ПРИЛОЖЕНИЕ В
(обязательное)
Диаграмма состояний
Рисунок В.1 - Диаграмма состояний
ПРИЛОЖЕНИЕ Г
(обязательное)
Диаграмма последовательностей
Рисунок Г.1 - Диаграмма последовательностей
ПРИЛОЖЕНИЕ Д
(обязательное)
Диаграмма классов
Рисунок Д.1 - Диаграмма классов иерархии
rmi-service-dao
ПРИЛОЖЕНИЕ Е
(обязательное)
Диаграмма компонентов
Рисунок Е.1 - Диаграмма компонентов клиентской
части
Рисунок Е.2 - Диаграмма компонентов серверной
части
ПРИЛОЖЕНИЕ Ж
(обязательное)
Диаграмма развёртывания
Рисунок Ж.1 - Диаграмма развёртывания
ПРИЛОЖЕНИЕ И
(обязательное)
Блок-схемы работы приложения
Рисунок И.1 - Блок-схема алгоритма
выборки блюд по категориям
Рисунок И.2 - Блок-схема алгоритма
добавления блюда в корзину
ПРИЛОЖЕНИЕ К
(обязательное)
Листинг алгоритмов, реализующих бизнес-логику
Листинг 1. Удалённые методы RMI-интерфейса
public interface IRmiForAdmin extends Remote {Admin getAdminByLogin(String login) throws RemoteException;ArrayList<DishDO> getDishesByDishType(String dishType) throws RemoteException;List<DishDO> findDishesByName(String dishName) throws RemoteException;List<DishDO> selectAllDishes() throws RemoteException;boolean deleteDishById(int dishId) throws RemoteException;boolean editDish(Dish dish) throws RemoteException;boolean addDish(Dish dish) throws RemoteException;boolean addClient(Client client) throws RemoteException;boolean addOrder(Order order) throws RemoteException;int countTotalCostTakingIntoDiscount(int totalCost) throws RemoteException;int getClientMaxId() throws RemoteException;List<Order> selectOrders() throws RemoteException;boolean deleteOrder(Order order) throws RemoteException;Client getClientById(int clientId) throws RemoteException;List<DishType> selectDishType() throws RemoteException;Order getOrderById(int orderId) throws RemoteException;String selectDiscount() throws RemoteException;
}
Листинг 2. Реализация удалённых методовclass RmiForAdminImpl extends UnicastRemoteObject implements IRmiForAdmin{AdminService adminService; DishService dishService;DishTypeService dishTypeService;ClientService clientService;OrderService orderService;RmiForAdminImpl () throws RemoteException {= new AdminService();= new DishService();= new ClientService();= new OrderService();= new DishTypeService();
}
// метод ищет по логину и возвращает экземпляр класса Admin
public Admin getAdminByLogin(String login)throws RemoteException {adminService.getAdminByLogin(login);
}
// метод ищет и составляет список блюд по типу блюда и возвращает его
public ArrayList<DishDO> getDishesByDishType(String dishType) throws RemoteException {dishService.getDishByDishType(dishType);
}List<DishDO> findDishesByName(String dishName) throws RemoteException {dishService.findDishesByName(dishName);
}List<DishDO> selectAllDishes() throws RemoteException {dishService.selectAllDishes();
}boolean deleteDishById(int dishId) throws RemoteException {dishService.deleteDishById(dishId);
}boolean editDish(Dish dish) throws RemoteException {dishService.editDish(dish);
}boolean addDish(Dish dish) throws RemoteException {dishService.addDish(dish);
}boolean addClient(Client client) throws RemoteException{clientService.addClient(client);
}boolean addOrder(Order order) throws RemoteException {orderService.createOrder(order);
}int countTotalCostTakingIntoDiscount(int totalCost) throws RemoteException{orderService.countTotalCostTakingIntoDiscount(totalCost);
}boolean deleteOrder(Order order){orderService.deleteOrder(order);
}List<DishType> selectDishType(){dishTypeService.selectDishTypes();
}Order getOrderById(int orderId){orderService.getOrderById(orderId);
}String selectDiscount(){discountDao = new DiscountDaoImpl();xstream = new XStream();.alias("discount",Discount.class);xml = xstream.toXML(discountDao.selectAll());xml;
}}
Листинг 3. DishService.javaclass DishService {dishDao;DishService(){= new DishDaoImpl();
}ArrayList<DishDO> getDishByDishType(String dishType){<DishDO> dishDoList = new ArrayList<DishDO>();<Dish> dishList = dishDao.selectDishesByDishType(dishType);(Dish dish : dishList ){<DishComposition> productsList = dishDao.selectDishCompositionByDishId(dish.getId());.add(new DishDO(dish, productsList));
}dishDoList;
}List<DishDO> findDishesByName(String dishName){<DishDO> dishList = new ArrayList<DishDO>();(Dish dish : dishDao.selectDishes()){(dish.getName().toLowerCase().contains(dishName.toLowerCase())){<DishComposition> productsList = dishDao.selectDishCompositionByDishId(dish.getId());.add(new DishDO(dish, productsList));
} return dishDoList; }boolean deleteDishById(int dishId){dishDao.deleteDish(dishId);
} public boolean editDish(Dish dish){dishDao.editDish(dish);
} public
boolean addDish(Dish dish){dishDao.addDish(dish); }}
Приложение Л
(обязательное)
Листинг основных элементов программы
Листинг 1. Discount.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<p >Наша компания может предложить вам следующую систему скидок:</p>
<table border="1" align="left">
<tr>
<td>Сумма*</td>
<td>Процент</td>
</tr>
<xsl:for-each select="list">
<xsl:for-each select="discount">
<tr>
<td>
<xsl:value-of select="amount"/>
</td>
<td>
<xsl:value-of select="percent"/>
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
<p >* - сумма, после которой начинает действовать скидка</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Листинг 2. Dish.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Сервис онлайн кафе</title>
<link rel="stylesheet" type="text/css" href="main.css" />
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<script type="text/javascript" src="jsp/countCheck.js"></script>
</head>
<body>
<div>
<jsp:include page = "mainPages/header.jsp" flush = "true"/>
<jsp:include page = "mainPages/left.jsp" flush = "true"/>
<jsp:include page = "mainPages/right.jsp" flush = "true"/>
<div>
<form action="Controller" method="post" >
<table style="border-color: tomato;background-color: #ffffff; font-size: medium;" >
<c:if test = "${dish_data != 'Sorry, information was not found'}">
<c:forEach var = "dishDO" items = "${dish_data}">
<tr >
<td><input type="checkbox" name="checkBox${dishDO.dish.name}"/><br/>
<input type="text" maxlength="3" size="1" onmouseout="return check(count${dishDO.dish.name})" name="count${dishDO.dish.name}" value="1" />
</td>
<td align="center">
<img alt="не найдено" src="${dishDO.dish.imagePath}"/>
</td>
<td align="center" style="color: chocolate">
<c:out value="${dishDO.dish.name}"/>
</td>
<td align="center">
<c:out value="${dishDO.dish.weight}"/>
</td>
<td align="center">
<c:out value="${dishDO.dish.price}"/>
</td>
<td align="center">
<c:forEach var = "dishComp" items = "${dishDO.composition}">
<c:out value="${dishComp.productName}"/>
<c:out ="${dishComp.productWeight}"/><br/>
</c:forEach>
</td>
</tr>
</c:forEach>
</c:if>
</table>
<input type="submit" value="Добавить в корзину"/>
<input type="hidden" name="command" value="addToBasket"/>
</form>
</div>
<jsp:include page = "mainPages/footer.jsp" flush = "true"/>
</div></body> </html>
Листинг 3. IDishDao.javainterface IDishDao {boolean addDish(Dish dish); // метод создаёт идобавляет в БД новое блюдоboolean deleteDish(int dishId); //метод удаляет блюдо из БД по его номеруboolean editDish(Dish dish); // метод обновлиет информацию о блюде в бдList<Dish> selectDishes(); // метод находит все блюдаArrayList<Dish> selectDishesByDishType(String dishType);List<DishComposition> selectDishCompositionByDishId(int dishId);}
Листинг 4. DishDaoImpl.javaDishDaoImpl() {= new DBConnection(); } boolean addDish(Dish dish) {{= (PreparedStatement) dbConnection.connect().prepareStatement(Dish.getMap().get("addDish"));.setInt(1, dish.getId());.setString(2, dish.getName());.setDouble(3, dish.getWeight());.setDouble(4, dish.getPrice());.setLong(5, dish.getType().getId());(statement.executeUpdate() > 0);
} catch (SQLException e) {.printStackTrace();false;
} }boolean deleteDish(int dishId) {{= (PreparedStatement) dbConnection.connect().prepareStatement(Dish.getMap().get("deleteDish"));.setInt(1, dishId);(statement.executeUpdate() > 0);
} catch (SQLException ex) {.getLogger(DishDaoImpl.class.getName()).log(Level.SEVERE, null, ex); return false;
} }boolean editDish(Dish dish) {{ statement = (PreparedStatement) dbConnection.connect().prepareStatement(Dish.getMap().get("updateDish"));.setString(1, dish.getName());.setDouble(2, dish.getWeight());.setDouble(3, dish.getPrice());.setInt(4, dish.getId());(statement.executeUpdate() > 0);
} catch (SQLException ex) {.getLogger(DishDaoImpl.class.getName()).log(Level.SEVERE,
Продолжение приложения Л, ex);
return false;
}
}List<Dish> selectDishes() {theSet;<Dish> dishList = null;{ps = (PreparedStatement) dbConnection.connect().(Dish.getMap().get("selectAll"));= ps.executeQuery();= new ArrayList<Dish>();(theSet.next()) {dish = new Dish();(dish, theSet);.add(dish);
}dishList;
} catch (SQLException ex) {.getLogger(DishDaoImpl.class.getName()).log(Level.SEVERE, null, ex);null;
}
}ArrayList<Dish> selectDishesByDishType(String dishType) {theSet;<Dish> dishList = new ArrayList<Dish>();{ps = (PreparedStatement) dbConnection.connect().(Dish.getMap().get("selectByType"));.setString(1, dishType);= ps.executeQuery();(theSet.next()) {dish = new Dish();(dish, theSet);.add(dish);
}dishList;
} catch (SQLException ex) {.getLogger(DishDaoImpl.class.getName()).log(Level.SEVERE, null, ex);null;
}
}List<DishComposition> selectDishCompositionByDishId(int dishId) {theSet;<DishComposition> productsList = new ArrayList<DishComposition>();{ps = (PreparedStatement) .connect().(Dish.getMap().get("selectCompositionByDishId"));.setInt(1, dishId);= ps.executeQuery();(theSet.next()) {composition = new DishComposition();.setProductName(theSet.getString("nameProduct"));.setProductWeight(theSet.getInt("productWieghtInDishComposition"));.add(composition);
}
} catch (SQLException ex) {.getLogger(DishDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
} return productsList; }}
Приложение М
(обязательное)
Листинг скрипта генерации базы данныхDATABASE IF NOT EXISTS `restaurant` TABLE IF NOT EXISTS `admin` (
`idadmin` int(11) NOT NULL AUTO_INCREMENT,
`loginadmin` varchar(45) NOT NULL,
`passwordadmin` int(11) NOT NULL,KEY (`idadmin`),KEY `loginAdmin_UNIQUE` (`loginadmin`),KEY `idadmin_UNIQUE` (`idadmin`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;INTO `admin` (`idadmin`, `loginadmin`, `passwordadmin`) VALUES (1, 'admin', 92668751), (7, 'olya', 1450575459), (8, 'kostya', 1508416), (9, 'kolya', 1824529005);TABLE IF NOT EXISTS `basket` (
`dishCountBasket` int(11) NOT NULL,
`dish_idDish` int(11) NOT NULL,
`order_idOrder` int(11) NOT NULL,KEY (`dish_idDish`,`order_idOrder`),`fk_basket_order1` (`order_idOrder`),`fk_basket_dish` FOREIGN KEY (`dish_idDish`) REFERENCES `dish` (`idDish`) ON DELETE NO ACTION ON UPDATE NO ACTION,`fk_basket_order1` FOREIGN KEY (`order_idOrder`) REFERENCES `order` (`idOrder`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;TABLE IF NOT EXISTS `client` (
`idClient` int(11) NOT NULL AUTO_INCREMENT,
`lastnameClient` varchar(45) NOT NULL,
`firstnameClient` varchar(45) NOT NULL,
`addressClient` varchar(45) NOT NULL,
`phoneClient` varchar(45) NOT NULL,KEY (`idClient`),KEY `idClient_UNIQUE` (`idClient`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8;INTO `client` (`idClient`, `lastnameClient`, `firstnameClient`, `addressClient`, `phoneClient`) VALUES (1, 'Страх', 'Ольга', 'Городецкая 58-110', '3070330'), (10, 'Страх', 'Наталья', 'Воронянского 23-89', '2456791'), (11, 'Сторук', 'Алексей', 'Кижевского 23-90', '1243546'), (13, 'Кожевников', 'Слава', 'Коренцова 34-123', '1234565'), (22, 'Дановский', 'Костя', 'Родная 7', '2345645');TABLE IF NOT EXISTS `composition` (
`productWieghtInDishComposition` int(11) NOT NULL,
`caloriesComposition` varchar(45) NOT NULL,
`dish_idDish` int(11) NOT NULL,
`product_idProduct` int(11) NOT NULL,KEY (`dish_idDish`,`product_idProduct`),`fk_composition_product1` (`product_idProduct`),`fk_composition_dish1` FOREIGN KEY (`dish_idDish`) REFERENCES `dish` (`idDish`) ON DELETE NO ACTION ON UPDATE NO ACTION,`fk_composition_product1` FOREIGN KEY (`product_idProduct`) REFERENCES `product` (`idProduct`) ON DELETE NO ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INTO `composition` (`productWieghtInDishComposition`, `caloriesComposition`, `dish_idDish`, `product_idProduct`) VALUES (230, '50', 1, 1), (137, '345', 1, 2), (30, '120', 2, 3), (212, '234', 2, 4), (123, '234', 3, 1), (23, '32', 3, 2), (234, '43', 3, 4), (34, '23', 4, 1), (23, '234', 4, 4), (23, '24', 5, 2);TABLE IF NOT EXISTS `discount` (
`iddiscount` int(11) NOT NULL AUTO_INCREMENT,
`amountdiscount` int(11) NOT NULL,
`percentdiscount` double NOT NULL,KEY (`iddiscount`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;INTO `discount` (`iddiscount`, `amountdiscount`, `percentdiscount`) VALUES (1, 200000, 0.2), (2, 150000, 0.15), (3, 100000, 0.1);
/*!40000 ALTER TABLE `discount` ENABLE KEYS */;TABLE IF NOT EXISTS `dish` (
`idDish` int(11) NOT NULL AUTO_INCREMENT,
`nameDish` varchar(45) NOT NULL,
`priceDish` double NOT NULL,
`weightDish` double NOT NULL,
`dishtype_idDishType` int(11) DEFAULT NULL,
`imagespath` varchar(45) DEFAULT NULL,KEY (`idDish`),KEY `idProduct_UNIQUE` (`idDish`),`fk_dish_dishtype1` (`dishtype_idDishType`),`fk_dish_dishtype1` FOREIGN KEY (`dishtype_idDishType`) REFERENCES `dishtype` (`idDishType`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8;INTO `dish` (`idDish`, `nameDish`, `priceDish`, `weightDish`,
`dishtype_idDishType`, `imagespath`) VALUES (1, 'Картофель фри', 2830, 120, 1, 'images/fri_patatoes.jpg'), (2, 'Спагетти со шпинатом', 15340, 260, 1, 'images/spagetti2.jpg'), (3, 'Спагетти Карбонара', 13830, 262, 1, 'images/spagetti1.jpg'), (4, 'Драники со сметаной', 6010, 155, 1, 'images/draniki_so_smetanoi.jpg'), (5, 'Куриная грудка с лисичками', 21250, 390, 1, 'images/chicken_rest.jpg'), (6, 'Омлет с беконом', 3780, 127, 3, 'images/breakfast1.jpg'), (7, 'Омлет с сыром', 2500, 127, 3, 'images/breakfast2.jpg'), (8, 'Салат \'Цезарь\' классический', 17540, 272, 2, 'images/salad_Cezar.jpg'), (10, 'Штрудель яблочный', 12900, 114, 4, 'images/apple_shtrudel.jpg'), (12, 'Пицца \'Курица с ананасами\'', 17820, 455, 6, 'images/checken_with_pineapple.jpg'), (13, 'Пицца \'Четыре сыра\'',
, 260, 6, 'images/pizza_4_cheezes.jpg'), (14, 'Пицца \'Овощная\'', 14890, 340, 6, 'images/pizza_vegatable.jpg'), (15, 'Имбирный чай', 7450, 170, 5, 'images/imb_tea.jpg'), (16, 'Сок апельсиновый', 2450, 250, 5, 'images/orange_juice.jpg'), (17, 'Штрудель твороженный', 3560, 130, 4, 'images/tvorog_shtrudel.jpg'), (18, 'Coca-Cola', 2970, 250, 5, 'images/cola.jpg'), (19, 'Бургер с курицей', 6880, 160, 3,
'images/chicken_burger.jpg'), (20, 'Fanta', 2970, 250, 5, 'images/fanta.jpg'), (21, 'Sprite', 2970, 250, 5, 'images/sprite.jpg'), (22,
'Свежий огурец', 1040, 30, 3, 'images/cucumber.jpg'), (23, 'Свежий помидор', 680, 30, 3, 'images/tomato.jpg'), (24, 'Салат из ростбифа', 24300, 190, 2, 'images/salad_from_rostbeaf.jpg'), (25, 'Салат от кролика Роджера', 6950, 177, 2, 'images/rabbit_salad.jpg');
/*!40000 ALTER TABLE `dish` ENABLE KEYS */;TABLE IF NOT EXISTS `dishtype` (
`idDishType` int(11) NOT NULL AUTO_INCREMENT,
`nameDishType` varchar(45) NOT NULL,KEY (`idDishType`),KEY `iddishType_UNIQUE` (`idDishType`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;INTO `dishtype` (`idDishType`, `nameDishType`) VALUES (1, 'Гарниры'), (2, 'Салаты'), (3, 'Завтраки'), (4, 'Десерты'), (5, 'Напитки'), (6, 'Пицца');TABLE IF NOT EXISTS `order` (
`idOrder` int(11) NOT NULL AUTO_INCREMENT,
`dishCostOrder` int(11) NOT NULL,
`secondaryCostOrder` int(11) NOT NULL,
`client_idClient` int(11) NOT NULL,KEY (`idOrder`),KEY `idOrder_UNIQUE` (`idOrder`),`fk_order_client1` (`client_idClient`),`fk_order_client1` FOREIGN KEY (`client_idClient`) REFERENCES `client` (`idClient`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;TABLE IF NOT EXISTS `product` (
`idProduct` int(11) NOT NULL AUTO_INCREMENT,
`nameProduct` varchar(45) NOT NULL,
`caloriesPer100grProduct` double DEFAULT NULL,KEY (`idProduct`),KEY `idProduct_UNIQUE` (`idProduct`),`composition` (`idProduct`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;INTO `product` (`idProduct`, `nameProduct`, `caloriesPer100grProduct`) VALUES (1, 'Помидоры', 50), (2, 'Мука', 1), (3, 'Огурец', 20), (4, 'Свинина', 300), (5, 'Майонез', 89)