Marc Hauschildt
Web Technologies and Computer Software Development Instructor at Kirkwood Community College in Cedar Rapids, IA.
Week 14
The ->>
arrows represent the direction of the message flow.
The -->>
arrows indicate a self-message.
The labels on the arrows describe the actions or events occurring at each step in the sequence.
sequenceDiagram
actor User
actor AdminUser
participant System
participant AzureCommunication
User ->> System: <br>Http Request
System -->> System: Detect 500 error
System ->> AzureCommunication: NotifyAdminByEmail
AzureCommunication -->> AzureCommunication: Prepare<br>Email Notification
AzureCommunication ->> AdminUser: Email Notification
CREATE PROCEDURE sp_update_vendor_admin(
IN orig_vend_id VARCHAR(10),
IN orig_vend_name VARCHAR(50),
IN orig_vend_address VARCHAR(50),
IN orig_vend_city VARCHAR(50),
IN orig_vend_state VARCHAR(5),
IN orig_vend_zip VARCHAR(10),
IN orig_vend_country VARCHAR(50),
IN new_vend_id VARCHAR(10),
IN new_vend_name VARCHAR(50),
IN new_vend_address VARCHAR(50),
IN new_vend_city VARCHAR(50),
IN new_vend_state VARCHAR(5),
IN new_vend_zip VARCHAR(10),
IN new_vend_country VARCHAR(50)
)
BEGIN
UPDATE vendors
SET vend_name = new_vend_name,
vend_address = new_vend_address,
vend_city = new_vend_city,
vend_state = new_vend_state,
vend_zip = new_vend_zip,
vend_country = new_vend_country
WHERE vend_id = orig_vend_id
AND vend_name = orig_vend_name
AND vend_address = orig_vend_address
AND vend_city = orig_vend_city
AND vend_state = orig_vend_state
AND vend_zip = orig_vend_zip
AND vend_country = orig_vend_country;
END;
public static boolean updateVendor(Vendor vendor) {
try(Connection connection = getConnection()) {
CallableStatement statement = connection.prepareCall("{CALL sp_update_vendor_admin(?, ?, ?, ?, ?, ?, ?)}");
statement.setString(1, vendor.getVend_id());
statement.setString(2, vendor.getVend_name());
statement.setString(3, vendor.getAddress().getAddress());
statement.setString(4, vendor.getAddress().getCity());
statement.setString(5, vendor.getAddress().getState());
statement.setString(6, vendor.getAddress().getZip());
statement.setString(7, vendor.getAddress().getCountry());
int rowsAffected = statement.executeUpdate();
return rowsAffected == 1;
} catch(SQLException e) {
// System.out.println(e.getMessage()); // Uncomment in case nothing is inserting
return false;
}
}
<a href="edit-vendor?vend_id=${vendor.vend_id}"
import edu.kirkwood.ecommerce.model.Vendor;
import edu.kirkwood.ecommerce.model.VendorDAO;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(value="/edit-vendor")
public class AdminUpdateVendor extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String vend_id = req.getParameter("vend_id");
Vendor vendor = VendorDAO.getVendor(vend_id);
req.setAttribute("vendor", vendor);
req.getRequestDispatcher("WEB-INF/ecommerce/admin-update-vendor.jsp").forward(req, resp);
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Admin - Update Vendor</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<%@ include file="../../main-nav.jsp"%>
<div class="container py-4">
<a href="vendors" class="btn btn-primary mb-4" role="button">View All Vendors</a>
<h2>Admin - Update Vendor</h2>
<c:choose>
<c:when test="${empty vendor}">
<p class="lead">No vendor found</p>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
</body>
</html>
<c:if test="${not empty vendorAdded}">
<div class="alert <c:choose><c:when test="${vendorAdded == true}">alert-success</c:when><c:otherwise>alert-danger</c:otherwise></c:choose>" role="alert">
${vendorAddedMessage}
</div>
</c:if>
<form class="row g-3" method="POST" action="add-vendor">
<div class="col-md-3">
<label for="vendorId" class="form-label">Vendor Id</label>
<input type="text" class="form-control <c:choose><c:when test="${vendorIdError == true}">is-invalid</c:when><c:when test="${vendorIdError == false}">is-valid</c:when><c:otherwise></c:otherwise></c:choose>" id="vendorId" name="vendorId" value="${vendor.vend_id}">
<div class="<c:choose><c:when test="${vendorIdError == true}">invalid-feedback</c:when><c:when test="${vendorIdError == false}">valid-feedback</c:when><c:otherwise></c:otherwise></c:choose>">
${vendorIdMessage}
</div>
</div>
<div class="col-md-9">
<label for="vendorName" class="form-label">Vendor name</label>
<input type="text" class="form-control <c:choose><c:when test="${vendorNameError == true}">is-invalid</c:when><c:when test="${vendorNameError == false}">is-valid</c:when><c:otherwise></c:otherwise></c:choose>" id="vendorName" name="vendorName" value="${vendor.vend_name}">
<div class="<c:choose><c:when test="${vendorNameError == true}">invalid-feedback</c:when><c:when test="${vendorNameError == false}">valid-feedback</c:when><c:otherwise></c:otherwise></c:choose>">
${vendorNameMessage}
</div>
</div>
<div class="col-md-4">
<label for="country" class="form-label">Country Abbreviation</label>
<input type="text" class="form-control <c:choose><c:when test="${countryError == true}">is-invalid</c:when><c:when test="${countryError == false}">is-valid</c:when><c:otherwise></c:otherwise></c:choose>" id="country" name="country" value="${vendor.address.country}" maxlength="3">
<div class="<c:choose><c:when test="${countryError == true}">invalid-feedback</c:when><c:when test="${countryError == false}">valid-feedback</c:when><c:otherwise></c:otherwise></c:choose>">
${countryMessage}
</div>
</div>
<div class="col-md-8">
<label for="streetAddress" class="form-label">Street Address</label>
<input type="text" class="form-control <c:choose><c:when test="${streetAddressError == true}">is-invalid</c:when><c:when test="${streetAddressError == false}">is-valid</c:when><c:otherwise></c:otherwise></c:choose>" id="streetAddress" name="streetAddress" value="${vendor.address.address}">
<div class="<c:choose><c:when test="${streetAddressError == true}">invalid-feedback</c:when><c:when test="${streetAddressError == false}">valid-feedback</c:when><c:otherwise></c:otherwise></c:choose>">
${streetAddressMessage}
</div>
</div>
<div class="col-md-4">
<label for="city" class="form-label">City</label>
<input type="text" class="form-control <c:choose><c:when test="${cityError == true}">is-invalid</c:when><c:when test="${cityError == false}">is-valid</c:when><c:otherwise></c:otherwise></c:choose>" id="city" name="city" value="${vendor.address.city}">
<div class="<c:choose><c:when test="${cityError == true}">invalid-feedback</c:when><c:when test="${cityError == false}">valid-feedback</c:when><c:otherwise></c:otherwise></c:choose>">
${cityMessage}
</div>
</div>
<div class="col-md-4">
<label for="state" class="form-label">State Abbreviation</label>
<input type="text" class="form-control <c:choose><c:when test="${stateError == true}">is-invalid</c:when><c:when test="${stateError == false}">is-valid</c:when><c:otherwise></c:otherwise></c:choose>" id="state" name="state" value="${vendor.address.state}" maxlength="2">
<div class="<c:choose><c:when test="${stateError == true}">invalid-feedback</c:when><c:when test="${stateError == false}">valid-feedback</c:when><c:otherwise></c:otherwise></c:choose>">
${stateMessage}
</div>
</div>
<div class="col-md-4">
<label for="zip" class="form-label">Zip</label>
<input type="text" class="form-control <c:choose><c:when test="${zipError == true}">is-invalid</c:when><c:when test="${zipError == false}">is-valid</c:when><c:otherwise></c:otherwise></c:choose>" id="zip" name="zip" value="${vendor.address.zip}">
<div class="<c:choose><c:when test="${zipError == true}">invalid-feedback</c:when><c:when test="${zipError == false}">valid-feedback</c:when><c:otherwise></c:otherwise></c:choose>">
${zipMessage}
</div>
</div>
<div class="col-12">
<button class="btn btn-dark" type="submit">Submit form</button>
</div>
</form>
CREATE PROCEDURE sp_delete_product(IN p_vend_id varchar(10))
BEGIN
DELETE FROM vendors WHERE vend_id = p_vend_id;
END;
By Marc Hauschildt
Web Technologies and Computer Software Development Instructor at Kirkwood Community College in Cedar Rapids, IA.