├── .gitignore ├── .idea ├── .gitignore ├── dataSources.xml ├── encodings.xml ├── misc.xml ├── uiDesigner.xml └── vcs.xml ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── LICENSE ├── README.md ├── app.log ├── mvnw ├── mvnw.cmd ├── pom.xml └── src └── main ├── java ├── org │ └── example │ │ └── coffeeshopposjavaeebackend │ │ ├── api │ │ ├── CustomerServlet.java │ │ ├── OrderDetailsServlet.java │ │ ├── OrdersServlet.java │ │ └── ProductServlet.java │ │ ├── bo │ │ ├── BOFactory.java │ │ ├── SuperBO.java │ │ └── custom │ │ │ ├── CustomerBO.java │ │ │ ├── OrderDetailsBO.java │ │ │ ├── OrdersBO.java │ │ │ ├── ProductBO.java │ │ │ └── impl │ │ │ ├── CustomerBOImpl.java │ │ │ ├── OrderDetailsBOImpl.java │ │ │ ├── OrdersBOImpl.java │ │ │ └── ProductBOImpl.java │ │ ├── dao │ │ ├── CrudDAO.java │ │ ├── DAOFactory.java │ │ ├── SuperDAO.java │ │ └── custom │ │ │ ├── CustomerDAO.java │ │ │ ├── OrderDetailsDAO.java │ │ │ ├── OrdersDAO.java │ │ │ ├── ProductDAO.java │ │ │ └── impl │ │ │ ├── CustomerDAOImpl.java │ │ │ ├── OrderDetailsDAOImpl.java │ │ │ ├── OrdersDAOImpl.java │ │ │ ├── ProductDAOImpl.java │ │ │ └── util │ │ │ └── SQLUtil.java │ │ ├── dto │ │ ├── CustomerDTO.java │ │ ├── OrderDetailsDTO.java │ │ ├── OrdersDTO.java │ │ └── ProductDTO.java │ │ ├── entity │ │ ├── Customer.java │ │ ├── OrderDetails.java │ │ ├── Orders.java │ │ └── Product.java │ │ └── filter │ │ ├── CORSFilter.java │ │ └── Security.java └── sql │ └── databasesQuary.sql ├── resources └── logback.xml └── webapp ├── META-INF └── context.xml └── WEB-INF └── web.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/dataSources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | mysql.8 6 | true 7 | com.mysql.cj.jdbc.Driver 8 | jdbc:mysql://localhost:3306/coffee_shop_pos 9 | 10 | 11 | 12 | 13 | 14 | $ProjectFileDir$ 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chamithKavinda/Coffee-Shop-POS-JavaEE-Backend/88dcec4f97738e9f9a183aa1372e0031af3a8fe8/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 chamithKavinda 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Caffeine Corner POS - JavaEE Backend 2 | Caffeine Corner is a comprehensive Point of Sale (POS) application designed specifically for coffee shops. It provides an efficient and intuitive system for managing customer interactions, 3 | product inventories, and order transactions. This project serves as an educational resource for mastering Java EE development. 4 | 5 | # Project Components 6 | ## Front-end 7 | The front-end of Caffeine Corner is crafted to offer a user-friendly interface with seamless interaction. 8 | It utilizes HTML, CSS, jQuery, and Fetch to create a dynamic web application, ensuring a smooth user experience. 9 | 10 | ## Back-end 11 | The back-end of Caffeine Corner handles server-side operations, data processing, and business logic. 12 | Implemented using Java EE and hosted on the Apache Tomcat server, it ensures robust performance and reliability for handling transactions and managing data. 13 | 14 | ### Dashboard View: 15 | ![dashboard](https://github.com/user-attachments/assets/c57d1df7-5465-472f-9690-43a8fd220f48) 16 | 17 | ### Customer Data View: 18 | ![Customer](https://github.com/user-attachments/assets/6b8d301c-efa2-4dd2-8046-262706b20ae5) 19 | 20 | ### Customer Register Form: 21 | ![customer add](https://github.com/user-attachments/assets/3d34cffa-a6d6-43ff-a62f-f750a7e04171) 22 | 23 | ### Customer Data Update Form: 24 | ![update customer](https://github.com/user-attachments/assets/abb7aa3c-b8ac-4a7f-a99a-b654649c5433) 25 | 26 | ### Product Data View: 27 | ![product](https://github.com/user-attachments/assets/31dee97a-8c56-4366-9e9e-be7338feec5a) 28 | 29 | ### Product Add Form: 30 | ![add product](https://github.com/user-attachments/assets/2897e147-c3e8-4924-b04b-8a4edb8cc156) 31 | 32 | ### Product Update Form: 33 | ![Update Product](https://github.com/user-attachments/assets/d0c110d8-e4f7-4fbb-879e-e4833bee3573) 34 | 35 | ### Place Order Form: 36 | ![placeOrder](https://github.com/user-attachments/assets/f1d7b6b2-d660-4d2a-80b2-7a73fb0fe813) 37 | 38 | # Features 39 | 40 | * User-friendly Interface: Designed with an intuitive layout for easy navigation and quick learning. Built using HTML, CSS , JS. 41 | * Reporting and Analytics: Generates detailed reports and alerts on orders, product, and customer data for informed decision-making. 42 | * JavaEE Architecture: Developed with the Java Platform, Enterprise Edition, offering a scalable architecture for enterprise-level applications. 43 | * Apache Tomcat Server: Configured to run on Apache Tomcat, ensuring efficient and reliable web application hosting. 44 | * Data Processing: Implements server-side logic to handle data processing and facilitate seamless communication between the front-end and database. 45 | * Business Rules: Enforces business logic and regulations specific to coffee shop operations. 46 | * Database Interactions: Manages interactions with the database, ensuring data integrity and security. 47 | 48 | # Tech Stack 49 | ## Front-end: 50 | - HTML 51 | - CSS 52 | - Bootstrap 53 | - jQuery 54 | - Fetch 55 | 56 | ## Back-end: 57 | - Java EE 58 | - Apache Tomcat 59 | 60 | # Database: 61 | * MySQL Connector: Java-based driver for connecting to MySQL databases (Version 8.0.32). 62 | * Java Naming and Directory Interface (JNDI): Java API for connecting to directory services, used for managing database connections efficiently through connection pooling. 63 | 64 | # Development Tools: 65 | * Maven: Build automation and project management tool (Version 4.0.0) 66 | 67 | ### Frontend Implementation : 68 | https://github.com/chamithKavinda/Coffee-Shop-POS-System-FrontEnd 69 | 70 | # API Endpoint Documentation 71 | * Customer - https://documenter.getpostman.com/view/35385399/2sA3s1oryn 72 | * Product - https://documenter.getpostman.com/view/35385399/2sA3s3FqT2 73 | * Order - https://documenter.getpostman.com/view/35385399/2sA3s3FqT3 74 | * Order Details - https://documenter.getpostman.com/view/35385399/2sA3s3FqT4 75 | 76 | ## License 77 | 78 | This project is licensed under the MIT License. See the [License File](https://github.com/chamithKavinda/Coffee-Shop-POS-JavaEE-Backend?tab=MIT-1-ov-file) for details. 79 | 80 | --- 81 | 82 | ## Contact 83 | 84 | For questions or support, please contact: 85 | 86 | - **Name**: Chamith Kavinda 87 | - **Email**: chamth13kavinda@gmail.com 88 | - **GitHub**: [Chamith Kavinda](https://github.com/chamithKavinda) 89 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | Coffee-Shop-POS-JavaEE-Backend 9 | 1.0-SNAPSHOT 10 | Coffee-Shop-POS-JavaEE-Backend 11 | war 12 | 13 | 14 | UTF-8 15 | 11 16 | 11 17 | 5.10.0 18 | 19 | 20 | 21 | 22 | jakarta.servlet 23 | jakarta.servlet-api 24 | 6.0.0 25 | provided 26 | 27 | 28 | 29 | org.junit.jupiter 30 | junit-jupiter-api 31 | ${junit.version} 32 | test 33 | 34 | 35 | 36 | org.junit.jupiter 37 | junit-jupiter-engine 38 | ${junit.version} 39 | test 40 | 41 | 42 | 43 | org.slf4j 44 | slf4j-api 45 | 1.7.32 46 | 47 | 48 | 49 | ch.qos.logback 50 | logback-classic 51 | 1.2.6 52 | 53 | 54 | 55 | org.eclipse 56 | yasson 57 | 2.0.4 58 | 59 | 60 | 61 | org.projectlombok 62 | lombok 63 | 1.18.30 64 | 65 | 66 | 67 | mysql 68 | mysql-connector-java 69 | 8.0.30 70 | 71 | 72 | 73 | 74 | 75 | 76 | org.apache.maven.plugins 77 | maven-war-plugin 78 | 3.4.0 79 | 80 | 81 | org.apache.maven.plugins 82 | maven-compiler-plugin 83 | 84 | 17 85 | 17 86 | 87 | 88 | 89 | org.apache.maven.plugins 90 | maven-compiler-plugin 91 | 92 | 21 93 | 21 94 | --enable-preview 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/api/CustomerServlet.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.api; 2 | 3 | import jakarta.json.bind.Jsonb; 4 | import jakarta.json.bind.JsonbBuilder; 5 | import jakarta.servlet.ServletException; 6 | import jakarta.servlet.annotation.WebServlet; 7 | import jakarta.servlet.http.HttpServlet; 8 | import jakarta.servlet.http.HttpServletRequest; 9 | import jakarta.servlet.http.HttpServletResponse; 10 | import org.example.coffeeshopposjavaeebackend.bo.BOFactory; 11 | import org.example.coffeeshopposjavaeebackend.bo.custom.CustomerBO; 12 | import org.example.coffeeshopposjavaeebackend.bo.custom.impl.CustomerBOImpl; 13 | import org.example.coffeeshopposjavaeebackend.dto.CustomerDTO; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | 17 | import javax.naming.InitialContext; 18 | import javax.naming.NamingException; 19 | import javax.sql.DataSource; 20 | import java.io.IOException; 21 | import java.sql.Connection; 22 | import java.sql.SQLException; 23 | 24 | @WebServlet(urlPatterns = "/customer") 25 | public class CustomerServlet extends HttpServlet { 26 | 27 | CustomerBO customerBO = BOFactory.getBoFactory().getBO(BOFactory.BOTypes.CUSTOMER_BO); 28 | 29 | static Logger logger = LoggerFactory.getLogger(CustomerServlet.class); 30 | Connection connection; 31 | 32 | @Override 33 | public void init() throws ServletException { 34 | try { 35 | var ctx = new InitialContext(); 36 | DataSource pool = (DataSource) ctx.lookup("java:comp/env/jdbc/pos"); 37 | this.connection = pool.getConnection(); 38 | logger.info("Connection initialized",this.connection); 39 | } catch (SQLException |NamingException e){ 40 | logger.error("DB connection not init"); 41 | e.printStackTrace(); 42 | } 43 | } 44 | 45 | @Override 46 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 47 | logger.debug("Received POST request for Customer"); 48 | if(req.getContentType() == null || !req.getContentType().toLowerCase().startsWith("application/json")){ 49 | resp.sendError(HttpServletResponse.SC_BAD_REQUEST); 50 | } 51 | try(var write = resp.getWriter()){ 52 | Jsonb jsonb = JsonbBuilder.create(); 53 | CustomerDTO customer = jsonb.fromJson(req.getReader(), CustomerDTO.class); 54 | 55 | write.write(customerBO.saveCustomer(customer,connection)); 56 | resp.setStatus(HttpServletResponse.SC_CREATED); 57 | }catch (Exception e){ 58 | resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 59 | e.printStackTrace(); 60 | } 61 | } 62 | 63 | @Override 64 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 65 | logger.debug("Received GET request for all Customers"); 66 | try (var writer = resp.getWriter()){ 67 | Jsonb jsonb = JsonbBuilder.create(); 68 | 69 | resp.setContentType("application/json"); 70 | jsonb.toJson(customerBO.getAllCustomer(connection),writer); 71 | }catch (Exception e){ 72 | e.printStackTrace(); 73 | } 74 | } 75 | 76 | @Override 77 | protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 78 | logger.debug("Received DELETE Request for Customer"); 79 | try(var write = resp.getWriter()){ 80 | var customerContact = req.getParameter("contact"); 81 | 82 | if (customerBO.deleteCustomer(customerContact,connection)){ 83 | // resp.setStatus(HttpServletResponse.SC_NO_CONTENT); 84 | write.write("Customer Deleted"); 85 | }else { 86 | write.write("Delete Failed"); 87 | resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); 88 | } 89 | }catch (Exception e){ 90 | e.printStackTrace(); 91 | } 92 | } 93 | 94 | @Override 95 | protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 96 | logger.debug("Received PUT Request for Customer"); 97 | try (var write = resp.getWriter()){ 98 | var customerContact = req.getParameter("contact"); 99 | Jsonb jsonb = JsonbBuilder.create(); 100 | CustomerDTO customer = jsonb.fromJson(req.getReader(),CustomerDTO.class); 101 | 102 | if(customerBO.updateCustomer(customerContact,customer,connection)){ 103 | // resp.setStatus(HttpServletResponse.SC_NO_CONTENT); 104 | write.write("Customer Update Sucessfully"); 105 | }else { 106 | write.write("Update Failed"); 107 | resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); 108 | } 109 | }catch (Exception e){ 110 | e.printStackTrace(); 111 | } 112 | } 113 | 114 | @Override 115 | public void destroy() { 116 | try { 117 | if (connection != null && !connection.isClosed()) { 118 | connection.close(); 119 | } 120 | } catch (SQLException e) { 121 | e.printStackTrace(); // Consider logging this exception 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/api/OrderDetailsServlet.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.api; 2 | 3 | import jakarta.json.bind.Jsonb; 4 | import jakarta.json.bind.JsonbBuilder; 5 | import jakarta.servlet.ServletException; 6 | import jakarta.servlet.annotation.WebServlet; 7 | import jakarta.servlet.http.HttpServlet; 8 | import jakarta.servlet.http.HttpServletRequest; 9 | import jakarta.servlet.http.HttpServletResponse; 10 | import org.example.coffeeshopposjavaeebackend.bo.BOFactory; 11 | import org.example.coffeeshopposjavaeebackend.bo.custom.OrderDetailsBO; 12 | import org.example.coffeeshopposjavaeebackend.bo.custom.OrdersBO; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | import javax.naming.InitialContext; 17 | import javax.naming.NamingException; 18 | import javax.sql.DataSource; 19 | import java.io.IOException; 20 | import java.sql.Connection; 21 | import java.sql.SQLException; 22 | 23 | @WebServlet(urlPatterns = "/orderDetails",loadOnStartup = 2) 24 | public class OrderDetailsServlet extends HttpServlet { 25 | 26 | OrderDetailsBO orderDetailsBO = (OrderDetailsBO) BOFactory.getBoFactory().getBO(BOFactory.BOTypes.ORDERDETAILS_BO); 27 | static Logger logger = LoggerFactory.getLogger(CustomerServlet.class); 28 | Connection connection; 29 | 30 | @Override 31 | public void init() throws ServletException { 32 | try { 33 | var ctx = new InitialContext(); 34 | DataSource pool = (DataSource) ctx.lookup("java:comp/env/jdbc/pos"); 35 | this.connection = pool.getConnection(); 36 | logger.info("Connection initialized",this.connection); 37 | } catch (SQLException | NamingException e){ 38 | logger.error("DB connection not init"); 39 | e.printStackTrace(); 40 | } 41 | } 42 | 43 | @Override 44 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 45 | logger.debug("Received GET request for all OrderDetails"); 46 | try (var writer = resp.getWriter()){ 47 | Jsonb jsonb = JsonbBuilder.create(); 48 | 49 | resp.setContentType("application/json"); 50 | jsonb.toJson(orderDetailsBO.getAllOrderDetails(connection),writer); 51 | }catch (Exception e){ 52 | e.printStackTrace(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/api/OrdersServlet.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.api; 2 | 3 | import jakarta.json.bind.Jsonb; 4 | import jakarta.json.bind.JsonbBuilder; 5 | import jakarta.servlet.ServletException; 6 | import jakarta.servlet.annotation.WebServlet; 7 | import jakarta.servlet.http.HttpServlet; 8 | import jakarta.servlet.http.HttpServletRequest; 9 | import jakarta.servlet.http.HttpServletResponse; 10 | import org.example.coffeeshopposjavaeebackend.bo.BOFactory; 11 | import org.example.coffeeshopposjavaeebackend.bo.custom.CustomerBO; 12 | import org.example.coffeeshopposjavaeebackend.bo.custom.OrdersBO; 13 | import org.example.coffeeshopposjavaeebackend.dto.CustomerDTO; 14 | import org.example.coffeeshopposjavaeebackend.dto.OrdersDTO; 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | 18 | import javax.naming.InitialContext; 19 | import javax.naming.NamingException; 20 | import javax.sql.DataSource; 21 | import java.io.IOException; 22 | import java.sql.Connection; 23 | import java.sql.SQLException; 24 | 25 | @WebServlet(urlPatterns = "/orders",loadOnStartup = 2) 26 | public class OrdersServlet extends HttpServlet { 27 | OrdersBO ordersBO = BOFactory.getBoFactory().getBO(BOFactory.BOTypes.ORDERS_BO); 28 | Connection connection; 29 | 30 | static Logger logger = LoggerFactory.getLogger(CustomerServlet.class); 31 | 32 | @Override 33 | public void init() throws ServletException { 34 | try { 35 | var ctx = new InitialContext(); 36 | DataSource pool = (DataSource) ctx.lookup("java:comp/env/jdbc/pos"); 37 | this.connection = pool.getConnection(); 38 | logger.info("Connection initialized",this.connection); 39 | } catch (SQLException | NamingException e){ 40 | logger.error("DB connection not init"); 41 | e.printStackTrace(); 42 | } 43 | } 44 | 45 | @Override 46 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 47 | logger.debug("Received Post Request for Order"); 48 | if(req.getContentType() == null || !req.getContentType().toLowerCase().startsWith("application/json")){ 49 | resp.sendError(HttpServletResponse.SC_BAD_REQUEST); 50 | } 51 | try(var write = resp.getWriter()){ 52 | Jsonb jsonb = JsonbBuilder.create(); 53 | OrdersDTO order = jsonb.fromJson(req.getReader(), OrdersDTO.class); 54 | 55 | boolean isSaved = ordersBO.purchseOrder(order, connection); 56 | if (isSaved){ 57 | write.write("orderSaved"); 58 | }else { 59 | write.write("not saved"); 60 | } 61 | 62 | // resp.setStatus(HttpServletResponse.SC_CREATED); 63 | }catch (Exception e){ 64 | resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 65 | e.printStackTrace(); 66 | } 67 | } 68 | 69 | @Override 70 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 71 | logger.debug("Received GET request for all Orders"); 72 | try (var writer = resp.getWriter()){ 73 | Jsonb jsonb = JsonbBuilder.create(); 74 | 75 | resp.setContentType("application/json"); 76 | jsonb.toJson(ordersBO.generateNewOrderID(connection),writer); 77 | }catch (Exception e){ 78 | e.printStackTrace(); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/api/ProductServlet.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.api; 2 | 3 | import jakarta.json.bind.Jsonb; 4 | import jakarta.json.bind.JsonbBuilder; 5 | import jakarta.servlet.ServletException; 6 | import jakarta.servlet.annotation.WebServlet; 7 | import jakarta.servlet.http.HttpServlet; 8 | import jakarta.servlet.http.HttpServletRequest; 9 | import jakarta.servlet.http.HttpServletResponse; 10 | import org.example.coffeeshopposjavaeebackend.bo.BOFactory; 11 | import org.example.coffeeshopposjavaeebackend.bo.custom.ProductBO; 12 | import org.example.coffeeshopposjavaeebackend.bo.custom.impl.CustomerBOImpl; 13 | import org.example.coffeeshopposjavaeebackend.bo.custom.impl.ProductBOImpl; 14 | import org.example.coffeeshopposjavaeebackend.dto.CustomerDTO; 15 | import org.example.coffeeshopposjavaeebackend.dto.ProductDTO; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | 19 | import javax.naming.InitialContext; 20 | import javax.naming.NamingException; 21 | import javax.sql.DataSource; 22 | import java.io.IOException; 23 | import java.sql.Connection; 24 | import java.sql.SQLException; 25 | 26 | @WebServlet(urlPatterns = "/product",loadOnStartup = 2) 27 | public class ProductServlet extends HttpServlet { 28 | 29 | ProductBO productBO = BOFactory.getBoFactory().getBO(BOFactory.BOTypes.PRODUCT_BO); 30 | 31 | static Logger logger = LoggerFactory.getLogger(ProductServlet.class); 32 | Connection connection; 33 | 34 | @Override 35 | public void init() throws ServletException { 36 | try { 37 | var ctx = new InitialContext(); 38 | DataSource pool = (DataSource) ctx.lookup("java:comp/env/jdbc/pos"); 39 | this.connection = pool.getConnection(); 40 | logger.info("Connection initialized",this.connection); 41 | } catch (SQLException |NamingException e){ 42 | logger.error("DB connection not init"); 43 | e.printStackTrace(); 44 | } 45 | } 46 | 47 | @Override 48 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 49 | logger.debug("Received POST request for Products"); 50 | if(req.getContentType() == null || !req.getContentType().toLowerCase().startsWith("application/json")){ 51 | resp.sendError(HttpServletResponse.SC_BAD_REQUEST); 52 | } 53 | try(var write = resp.getWriter()){ 54 | Jsonb jsonb = JsonbBuilder.create(); 55 | ProductDTO product = jsonb.fromJson(req.getReader(), ProductDTO.class); 56 | 57 | write.write(productBO.saveProduct(product,connection)); 58 | resp.setStatus(HttpServletResponse.SC_CREATED); 59 | // write.write("Product save Sucessfully"); 60 | }catch (Exception e){ 61 | resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 62 | e.printStackTrace(); 63 | } 64 | } 65 | 66 | @Override 67 | protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 68 | logger.debug("Received DELETE request for Products"); 69 | try(var write = resp.getWriter()){ 70 | var pro_id = req.getParameter("pro_id"); 71 | 72 | if (productBO.deleteProduct(pro_id,connection)){ 73 | // resp.setStatus(HttpServletResponse.SC_NO_CONTENT); 74 | write.write("Product Delete Sucessfully"); 75 | }else { 76 | write.write("Delete Failed"); 77 | resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); 78 | } 79 | }catch (Exception e){ 80 | e.printStackTrace(); 81 | } 82 | } 83 | 84 | @Override 85 | protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 86 | logger.debug("Received Update request for Products"); 87 | try (var write = resp.getWriter()){ 88 | var pro_id = req.getParameter("pro_id"); 89 | Jsonb jsonb = JsonbBuilder.create(); 90 | ProductDTO product = jsonb.fromJson(req.getReader(), ProductDTO.class); 91 | System.out.println(pro_id); 92 | System.out.println(product.getQuantity()); 93 | 94 | if(productBO.updateProduct(pro_id,product,connection)){ 95 | // resp.setStatus(HttpServletResponse.SC_NO_CONTENT); 96 | write.write("Product Update Sucessfully"); 97 | }else { 98 | write.write("Update Failed"); 99 | resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); 100 | } 101 | }catch (Exception e){ 102 | e.printStackTrace(); 103 | } 104 | } 105 | 106 | @Override 107 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 108 | logger.debug("Received Get All request for Products"); 109 | try (var writer = resp.getWriter()){ 110 | Jsonb jsonb = JsonbBuilder.create(); 111 | 112 | resp.setContentType("application/json"); 113 | jsonb.toJson(productBO.getAllProduct(connection),writer); 114 | }catch (Exception e){ 115 | e.printStackTrace(); 116 | } 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/bo/BOFactory.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.bo; 2 | 3 | import org.example.coffeeshopposjavaeebackend.bo.custom.impl.CustomerBOImpl; 4 | import org.example.coffeeshopposjavaeebackend.bo.custom.impl.OrderDetailsBOImpl; 5 | import org.example.coffeeshopposjavaeebackend.bo.custom.impl.OrdersBOImpl; 6 | import org.example.coffeeshopposjavaeebackend.bo.custom.impl.ProductBOImpl; 7 | 8 | public class BOFactory { 9 | private static BOFactory boFactory; 10 | 11 | private BOFactory(){} 12 | 13 | public static BOFactory getBoFactory(){ 14 | return (boFactory == null) ? boFactory = new BOFactory() : boFactory; 15 | } 16 | 17 | public enum BOTypes{ 18 | CUSTOMER_BO, 19 | PRODUCT_BO, 20 | ORDERS_BO, 21 | ORDERDETAILS_BO 22 | } 23 | 24 | public T getBO(BOTypes boTypes){ 25 | switch (boTypes) { 26 | case CUSTOMER_BO: 27 | return (T) new CustomerBOImpl(); 28 | case PRODUCT_BO: 29 | return (T) new ProductBOImpl(); 30 | case ORDERS_BO: 31 | return (T) new OrdersBOImpl(); 32 | case ORDERDETAILS_BO: 33 | return (T) new OrderDetailsBOImpl(); 34 | default: 35 | return null; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/bo/SuperBO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.bo; 2 | 3 | public interface SuperBO { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/bo/custom/CustomerBO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.bo.custom; 2 | 3 | import org.example.coffeeshopposjavaeebackend.bo.SuperBO; 4 | import org.example.coffeeshopposjavaeebackend.dto.CustomerDTO; 5 | 6 | import java.sql.Connection; 7 | import java.sql.SQLException; 8 | import java.util.List; 9 | 10 | public interface CustomerBO extends SuperBO { 11 | String saveCustomer(CustomerDTO customer, Connection connection)throws Exception; 12 | 13 | boolean deleteCustomer(String customerContact, Connection connection) throws Exception; 14 | 15 | boolean updateCustomer(String customerContact, CustomerDTO customer, Connection connection) throws SQLException; 16 | 17 | List getAllCustomer(Connection connection) throws Exception; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/bo/custom/OrderDetailsBO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.bo.custom; 2 | 3 | import org.example.coffeeshopposjavaeebackend.bo.SuperBO; 4 | import org.example.coffeeshopposjavaeebackend.dto.OrderDetailsDTO; 5 | 6 | import java.sql.Connection; 7 | import java.util.List; 8 | 9 | public interface OrderDetailsBO extends SuperBO { 10 | List getAllOrderDetails(Connection connection) throws Exception; 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/bo/custom/OrdersBO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.bo.custom; 2 | 3 | import org.example.coffeeshopposjavaeebackend.bo.SuperBO; 4 | import org.example.coffeeshopposjavaeebackend.dto.OrdersDTO; 5 | 6 | import java.sql.Connection; 7 | import java.sql.SQLException; 8 | import java.util.List; 9 | 10 | public interface OrdersBO extends SuperBO { 11 | boolean purchseOrder(OrdersDTO order, Connection connection) throws Exception; 12 | 13 | String generateNewOrderID(Connection connection) throws SQLException; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/bo/custom/ProductBO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.bo.custom; 2 | 3 | import org.example.coffeeshopposjavaeebackend.bo.SuperBO; 4 | import org.example.coffeeshopposjavaeebackend.dto.ProductDTO; 5 | 6 | import java.sql.Connection; 7 | import java.sql.SQLException; 8 | import java.util.List; 9 | 10 | public interface ProductBO extends SuperBO { 11 | String saveProduct(ProductDTO product, Connection connection) throws Exception; 12 | boolean deleteProduct(String proId, Connection connection) throws Exception; 13 | boolean updateProduct(String proId, ProductDTO product, Connection connection) throws SQLException; 14 | List getAllProduct(Connection connection) throws Exception; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/bo/custom/impl/CustomerBOImpl.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.bo.custom.impl; 2 | 3 | import org.example.coffeeshopposjavaeebackend.bo.custom.CustomerBO; 4 | import org.example.coffeeshopposjavaeebackend.dao.DAOFactory; 5 | import org.example.coffeeshopposjavaeebackend.dao.custom.CustomerDAO; 6 | import org.example.coffeeshopposjavaeebackend.dao.custom.ProductDAO; 7 | import org.example.coffeeshopposjavaeebackend.dao.custom.impl.CustomerDAOImpl; 8 | import org.example.coffeeshopposjavaeebackend.dto.CustomerDTO; 9 | import org.example.coffeeshopposjavaeebackend.entity.Customer; 10 | 11 | import java.sql.Connection; 12 | import java.sql.SQLException; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class CustomerBOImpl implements CustomerBO { 17 | 18 | CustomerDAO customerDAO = DAOFactory.getDaoFactory().getDAO(DAOFactory.DAOTypes.CUSTOMER_DAO); 19 | @Override 20 | public String saveCustomer(CustomerDTO customer, Connection connection) throws Exception { 21 | return customerDAO.saveCustomer(customer,connection); 22 | } 23 | 24 | public boolean deleteCustomer(String customerContact, Connection connection) throws Exception{ 25 | return customerDAO.deleteCustomer(customerContact,connection); 26 | } 27 | 28 | public boolean updateCustomer(String customerContact, CustomerDTO customer, Connection connection) throws SQLException { 29 | return customerDAO.updateCustomer(customerContact,customer,connection); 30 | } 31 | 32 | 33 | public List getAllCustomer( Connection connection) throws Exception { 34 | List customersList = customerDAO.getCustomer(connection); 35 | List customerDTOS = new ArrayList<>(); 36 | 37 | 38 | for (Customer customer : customersList) { 39 | customerDTOS.add(new CustomerDTO( 40 | customer.getCustId(), 41 | customer.getCustName(), 42 | customer.getCustAddress(), 43 | customer.getCustContact() 44 | )); 45 | } 46 | return customerDTOS; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/bo/custom/impl/OrderDetailsBOImpl.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.bo.custom.impl; 2 | 3 | import org.example.coffeeshopposjavaeebackend.bo.custom.OrderDetailsBO; 4 | import org.example.coffeeshopposjavaeebackend.dao.DAOFactory; 5 | import org.example.coffeeshopposjavaeebackend.dao.custom.OrderDetailsDAO; 6 | import org.example.coffeeshopposjavaeebackend.dao.custom.OrdersDAO; 7 | import org.example.coffeeshopposjavaeebackend.dao.custom.ProductDAO; 8 | import org.example.coffeeshopposjavaeebackend.dto.OrderDetailsDTO; 9 | import org.example.coffeeshopposjavaeebackend.dto.OrdersDTO; 10 | import org.example.coffeeshopposjavaeebackend.entity.OrderDetails; 11 | import org.example.coffeeshopposjavaeebackend.entity.Orders; 12 | 13 | import java.sql.Connection; 14 | import java.sql.SQLException; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | public class OrderDetailsBOImpl implements OrderDetailsBO { 19 | OrderDetailsDAO orderDetailsDAO = DAOFactory.getDaoFactory().getDAO(DAOFactory.DAOTypes.ORDERDETAILS_DAO); 20 | 21 | 22 | public List getAllOrderDetails(Connection connection) throws Exception { 23 | List OrderDetailsList = orderDetailsDAO.getAllOrderDetails(connection); 24 | List OrderDetailsDTOS = new ArrayList<>(); 25 | 26 | 27 | for (OrderDetails orderDetails : OrderDetailsList) { 28 | OrderDetailsDTOS.add(new OrderDetailsDTO( 29 | orderDetails.getOrder_id(), 30 | orderDetails.getPro_id(), 31 | orderDetails.getQty(), 32 | orderDetails.getUnitPrice() 33 | )); 34 | } 35 | return OrderDetailsDTOS; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/bo/custom/impl/OrdersBOImpl.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.bo.custom.impl; 2 | 3 | import org.example.coffeeshopposjavaeebackend.bo.custom.OrdersBO; 4 | import org.example.coffeeshopposjavaeebackend.dao.DAOFactory; 5 | import org.example.coffeeshopposjavaeebackend.dao.custom.OrderDetailsDAO; 6 | import org.example.coffeeshopposjavaeebackend.dao.custom.OrdersDAO; 7 | import org.example.coffeeshopposjavaeebackend.dao.custom.ProductDAO; 8 | import org.example.coffeeshopposjavaeebackend.dto.OrderDetailsDTO; 9 | import org.example.coffeeshopposjavaeebackend.dto.OrdersDTO; 10 | import org.example.coffeeshopposjavaeebackend.entity.OrderDetails; 11 | import org.example.coffeeshopposjavaeebackend.entity.Orders; 12 | import org.example.coffeeshopposjavaeebackend.entity.Product; 13 | 14 | import java.sql.Connection; 15 | import java.sql.SQLException; 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | public class OrdersBOImpl implements OrdersBO { 20 | OrdersDAO ordersDAO = DAOFactory.getDaoFactory().getDAO(DAOFactory.DAOTypes.ORDERS_DAO); 21 | 22 | ProductDAO productDAO = DAOFactory.getDaoFactory().getDAO(DAOFactory.DAOTypes.PRODUCT_DAO); 23 | 24 | OrderDetailsDAO orderDetailsDAO = DAOFactory.getDaoFactory().getDAO(DAOFactory.DAOTypes.ORDERDETAILS_DAO); 25 | 26 | @Override 27 | public boolean purchseOrder(OrdersDTO order, Connection connection) throws Exception { 28 | 29 | connection.setAutoCommit(false); 30 | 31 | Orders orders = new Orders(order.getOrder_id(),order.getDateAndTime(),order.getContact()); 32 | 33 | boolean saveOrder = ordersDAO.saveOrder(orders,connection); 34 | if (!saveOrder){ 35 | connection.rollback(); 36 | connection.setAutoCommit(true); 37 | return false; 38 | } 39 | 40 | for (OrderDetailsDTO orderDetail : order.getOrderDetails()) { 41 | boolean orderDetailSaved = orderDetailsDAO.save(connection, new OrderDetails( 42 | orderDetail.getOrder_id(), 43 | orderDetail.getPro_id(), 44 | orderDetail.getQty(), 45 | orderDetail.getUnitPrice())); 46 | if (!orderDetailSaved) { 47 | connection.rollback(); 48 | connection.setAutoCommit(true); 49 | return false; 50 | } 51 | 52 | Product product = productDAO.search(connection, orderDetail.getPro_id()); 53 | 54 | product.setQuantity(String.valueOf(Integer.parseInt(product.getQuantity()) - Integer.parseInt(orderDetail.getQty()))); 55 | 56 | boolean isUpdated = productDAO.update(connection, product); 57 | 58 | if (!isUpdated) { 59 | connection.rollback(); 60 | connection.setAutoCommit(true); 61 | return false; 62 | } 63 | } 64 | 65 | connection.commit(); 66 | connection.setAutoCommit(true); 67 | 68 | return true; 69 | 70 | } 71 | 72 | @Override 73 | public String generateNewOrderID(Connection connection) throws SQLException { 74 | String lastOrderId = ordersDAO.generateNextId(connection); 75 | if (lastOrderId != null){ 76 | String prefix = lastOrderId.substring(0, 1); 77 | int number = Integer.parseInt(lastOrderId.substring(1)); 78 | number++; 79 | String formattedNumber = String.format("%03d", number); 80 | return prefix + formattedNumber; 81 | } 82 | return "O001"; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/bo/custom/impl/ProductBOImpl.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.bo.custom.impl; 2 | 3 | import org.example.coffeeshopposjavaeebackend.bo.custom.ProductBO; 4 | import org.example.coffeeshopposjavaeebackend.dao.DAOFactory; 5 | import org.example.coffeeshopposjavaeebackend.dao.custom.ProductDAO; 6 | import org.example.coffeeshopposjavaeebackend.dao.custom.impl.CustomerDAOImpl; 7 | import org.example.coffeeshopposjavaeebackend.dao.custom.impl.ProductDAOImpl; 8 | import org.example.coffeeshopposjavaeebackend.dto.ProductDTO; 9 | import org.example.coffeeshopposjavaeebackend.entity.Product; 10 | 11 | import java.sql.Connection; 12 | import java.sql.SQLException; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class ProductBOImpl implements ProductBO { 17 | 18 | ProductDAO productDAO = DAOFactory.getDaoFactory().getDAO(DAOFactory.DAOTypes.PRODUCT_DAO); 19 | 20 | public String saveProduct(ProductDTO product, Connection connection) throws Exception { 21 | return productDAO.saveProduct(product,connection); 22 | } 23 | 24 | public boolean deleteProduct(String proId, Connection connection) throws Exception { 25 | return productDAO.deleteProduct(proId,connection); 26 | } 27 | 28 | public boolean updateProduct(String proId, ProductDTO product, Connection connection) throws SQLException { 29 | return productDAO.updateProduct(proId,product,connection); 30 | } 31 | 32 | public List getAllProduct(Connection connection) throws Exception{ 33 | List productList = productDAO.getAllProduct(connection); 34 | List productDTOS = new ArrayList<>(); 35 | 36 | for (Product product : productList){ 37 | productDTOS.add(new ProductDTO( 38 | product.getPro_id(), 39 | product.getPro_name(), 40 | product.getPrice(), 41 | product.getCategory(), 42 | product.getQuantity() 43 | )); 44 | } 45 | return productDTOS; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dao/CrudDAO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dao; 2 | 3 | import java.sql.SQLException; 4 | import java.util.ArrayList; 5 | 6 | public interface CrudDAO extends SuperDAO{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dao/DAOFactory.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dao; 2 | 3 | import org.example.coffeeshopposjavaeebackend.dao.custom.impl.CustomerDAOImpl; 4 | import org.example.coffeeshopposjavaeebackend.dao.custom.impl.OrderDetailsDAOImpl; 5 | import org.example.coffeeshopposjavaeebackend.dao.custom.impl.OrdersDAOImpl; 6 | import org.example.coffeeshopposjavaeebackend.dao.custom.impl.ProductDAOImpl; 7 | import org.example.coffeeshopposjavaeebackend.dto.OrdersDTO; 8 | 9 | public class DAOFactory { 10 | private static DAOFactory daoFactory; 11 | 12 | private DAOFactory(){} 13 | 14 | public static DAOFactory getDaoFactory(){ 15 | return (daoFactory == null)? daoFactory = new DAOFactory() : daoFactory; 16 | } 17 | 18 | public enum DAOTypes{ 19 | CUSTOMER_DAO, 20 | PRODUCT_DAO, 21 | ORDERS_DAO, 22 | ORDERDETAILS_DAO 23 | } 24 | 25 | public T getDAO(DAOTypes daoTypes){ 26 | switch (daoTypes){ 27 | case CUSTOMER_DAO: 28 | return (T) new CustomerDAOImpl(); 29 | case PRODUCT_DAO: 30 | return (T) new ProductDAOImpl(); 31 | case ORDERS_DAO: 32 | return (T) new OrdersDAOImpl(); 33 | case ORDERDETAILS_DAO: 34 | return (T) new OrderDetailsDAOImpl(); 35 | default: 36 | return null; 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dao/SuperDAO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dao; 2 | 3 | public interface SuperDAO { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dao/custom/CustomerDAO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dao.custom; 2 | 3 | import org.example.coffeeshopposjavaeebackend.dao.CrudDAO; 4 | import org.example.coffeeshopposjavaeebackend.dto.CustomerDTO; 5 | import org.example.coffeeshopposjavaeebackend.entity.Customer; 6 | 7 | import java.sql.Connection; 8 | import java.sql.SQLException; 9 | import java.util.List; 10 | 11 | public interface CustomerDAO extends CrudDAO { 12 | String saveCustomer(CustomerDTO customer, Connection connection) throws SQLException; 13 | 14 | boolean deleteCustomer(String customerContact, Connection connection) throws SQLException; 15 | 16 | boolean updateCustomer(String customerContact, CustomerDTO customer, Connection connection) throws SQLException; 17 | 18 | List getCustomer(Connection connection) throws Exception; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dao/custom/OrderDetailsDAO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dao.custom; 2 | 3 | import org.example.coffeeshopposjavaeebackend.dao.CrudDAO; 4 | import org.example.coffeeshopposjavaeebackend.entity.OrderDetails; 5 | 6 | import java.sql.Connection; 7 | import java.sql.SQLException; 8 | import java.util.List; 9 | 10 | public interface OrderDetailsDAO extends CrudDAO { 11 | List getAllOrderDetails(Connection connection) throws Exception; 12 | 13 | boolean save(Connection connection, OrderDetails entity) throws SQLException; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dao/custom/OrdersDAO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dao.custom; 2 | 3 | import org.example.coffeeshopposjavaeebackend.dao.CrudDAO; 4 | import org.example.coffeeshopposjavaeebackend.dto.OrdersDTO; 5 | import org.example.coffeeshopposjavaeebackend.entity.Orders; 6 | 7 | import java.sql.Connection; 8 | import java.sql.SQLException; 9 | import java.util.List; 10 | 11 | public interface OrdersDAO extends CrudDAO { 12 | boolean saveOrder(Orders order, Connection connection) throws SQLException; 13 | 14 | String generateNextId(Connection connection) throws SQLException; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dao/custom/ProductDAO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dao.custom; 2 | 3 | import org.example.coffeeshopposjavaeebackend.dao.CrudDAO; 4 | import org.example.coffeeshopposjavaeebackend.dto.ProductDTO; 5 | import org.example.coffeeshopposjavaeebackend.entity.Product; 6 | 7 | import java.sql.Connection; 8 | import java.sql.SQLException; 9 | import java.util.List; 10 | 11 | public interface ProductDAO extends CrudDAO { 12 | String saveProduct(ProductDTO product , Connection connection) throws SQLException; 13 | 14 | boolean deleteProduct(String proId, Connection connection) throws SQLException; 15 | 16 | boolean updateProduct(String proId, ProductDTO product, Connection connection) throws SQLException; 17 | 18 | List getAllProduct(Connection connection) throws SQLException; 19 | 20 | Product search(Connection connection, String proId) throws SQLException; 21 | 22 | boolean update(Connection connection, Product product) throws SQLException; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dao/custom/impl/CustomerDAOImpl.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dao.custom.impl; 2 | 3 | import org.example.coffeeshopposjavaeebackend.dao.custom.CustomerDAO; 4 | import org.example.coffeeshopposjavaeebackend.dto.CustomerDTO; 5 | import org.example.coffeeshopposjavaeebackend.entity.Customer; 6 | 7 | import java.sql.Connection; 8 | import java.sql.ResultSet; 9 | import java.sql.SQLException; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public class CustomerDAOImpl implements CustomerDAO { 14 | 15 | public static String SAVE_CUSTOMER = "INSERT INTO customer (cust_id,cust_name,address,contact) VALUES(?,?,?,?)"; 16 | 17 | public static String DELETE_CUSTOMER = "DELETE FROM customer where contact=?"; 18 | 19 | public static String UPDATE_CUSTOMER = "UPDATE customer SET cust_id=?,cust_name=?,address=? WHERE contact=?"; 20 | 21 | public static String GET_CUSTOMER = "SELECT * FROM customer"; 22 | @Override 23 | public String saveCustomer(CustomerDTO customer, Connection connection) throws SQLException { 24 | try{ 25 | 26 | var sc = connection.prepareStatement(SAVE_CUSTOMER); 27 | sc.setString(1,customer.getCustId()); 28 | sc.setString(2,customer.getCustName()); 29 | sc.setString(3,customer.getCustAddress()); 30 | sc.setString(4, customer.getCustContact()); 31 | if(sc.executeUpdate() != 0){ 32 | return "Customer Save Successfully"; 33 | }else { 34 | return "Failed to Save Student"; 35 | } 36 | }catch (SQLException e){ 37 | throw new SQLException(e.getMessage()); 38 | } 39 | } 40 | 41 | @Override 42 | public boolean deleteCustomer(String contact, Connection connection) throws SQLException { 43 | var sc = connection.prepareStatement(DELETE_CUSTOMER); 44 | sc.setString(1,contact); 45 | 46 | return sc.executeUpdate() !=0; 47 | } 48 | 49 | @Override 50 | public boolean updateCustomer(String customerContact, CustomerDTO customer, Connection connection) throws SQLException{ 51 | try{ 52 | var sc = connection.prepareStatement(UPDATE_CUSTOMER); 53 | sc.setString(1,customer.getCustId()); 54 | sc.setString(2,customer.getCustName()); 55 | sc.setString(3,customer.getCustAddress()); 56 | sc.setString(4, customer.getCustContact()); 57 | return sc.executeUpdate() !=0; 58 | }catch (SQLException e){ 59 | throw new SQLException(e.getMessage()); 60 | } 61 | } 62 | 63 | public List getCustomer(Connection connection) throws Exception { 64 | try { 65 | CustomerDTO customerDTO = new CustomerDTO(); 66 | var sc = connection.prepareStatement(GET_CUSTOMER); 67 | ResultSet rst = sc.executeQuery(); 68 | ArrayList customers = new ArrayList<>(); 69 | 70 | while (rst.next()){ 71 | customers.add(new Customer( 72 | rst.getString("cust_id"), 73 | rst.getString("cust_name"), 74 | rst.getString("address"), 75 | rst.getString("contact"))); 76 | } 77 | return customers; 78 | }catch (Exception e){ 79 | throw new SQLException(e.getMessage()); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dao/custom/impl/OrderDetailsDAOImpl.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dao.custom.impl; 2 | 3 | import org.example.coffeeshopposjavaeebackend.dao.CrudDAO; 4 | import org.example.coffeeshopposjavaeebackend.dao.custom.OrderDetailsDAO; 5 | import org.example.coffeeshopposjavaeebackend.dao.custom.impl.util.SQLUtil; 6 | import org.example.coffeeshopposjavaeebackend.dto.OrderDetailsDTO; 7 | import org.example.coffeeshopposjavaeebackend.dto.OrdersDTO; 8 | import org.example.coffeeshopposjavaeebackend.entity.OrderDetails; 9 | import org.example.coffeeshopposjavaeebackend.entity.Orders; 10 | 11 | import java.sql.Connection; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | public class OrderDetailsDAOImpl implements OrderDetailsDAO { 18 | 19 | public static String GET_ALL_ORDERDETAILS = "SELECT * FROM orderdetails"; 20 | public List getAllOrderDetails(Connection connection) throws Exception { 21 | try { 22 | OrderDetailsDTO orderDetailsDTO = new OrderDetailsDTO(); 23 | var sc = connection.prepareStatement(GET_ALL_ORDERDETAILS); 24 | ResultSet rst = sc.executeQuery(); 25 | ArrayList orderDetails = new ArrayList<>(); 26 | 27 | while (rst.next()){ 28 | orderDetails.add(new OrderDetails( 29 | rst.getString("order_id"), 30 | rst.getString("pro_Id"), 31 | rst.getString("qty"), 32 | rst.getString("unitPrice") 33 | )); 34 | } 35 | return orderDetails; 36 | }catch (Exception e){ 37 | throw new SQLException(e.getMessage()); 38 | } 39 | } 40 | 41 | @Override 42 | public boolean save(Connection connection, OrderDetails entity) throws SQLException { 43 | String sql = "INSERT INTO orderdetails VALUES(?, ?, ?,?)"; 44 | return SQLUtil.execute(sql, connection, entity.getOrder_id(), entity.getPro_id(), entity.getQty(),entity.getUnitPrice()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dao/custom/impl/OrdersDAOImpl.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dao.custom.impl; 2 | 3 | import org.example.coffeeshopposjavaeebackend.dao.custom.OrdersDAO; 4 | import org.example.coffeeshopposjavaeebackend.dao.custom.impl.util.SQLUtil; 5 | import org.example.coffeeshopposjavaeebackend.dto.OrdersDTO; 6 | import org.example.coffeeshopposjavaeebackend.entity.Orders; 7 | 8 | import java.sql.Connection; 9 | import java.sql.ResultSet; 10 | import java.sql.SQLException; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | public class OrdersDAOImpl implements OrdersDAO { 15 | 16 | public static String SAVE_ORDER = "INSERT INTO orders (order_id,dateAndTime,contact) VALUES(?,?,?)"; 17 | 18 | 19 | @Override 20 | public boolean saveOrder(Orders order, Connection connection) throws SQLException { 21 | 22 | try{ 23 | var sc = connection.prepareStatement(SAVE_ORDER); 24 | sc.setString(1,order.getOrder_id()); 25 | sc.setString(2, String.valueOf(order.getDateAndTime())); 26 | sc.setString(3,order.getContact()); 27 | System.out.println(order.getContact()); 28 | if(sc.executeUpdate() != 0){ 29 | return true; 30 | }else { 31 | return false; 32 | } 33 | }catch (SQLException e){ 34 | throw new SQLException(e.getMessage()); 35 | } 36 | } 37 | 38 | 39 | @Override 40 | public String generateNextId(Connection connection) throws SQLException { 41 | String sql = "SELECT order_id FROM orders ORDER BY order_id DESC LIMIT 1"; 42 | ResultSet resultSet = SQLUtil.execute(sql, connection); 43 | if (resultSet.next()) { 44 | String order_id = resultSet.getString(1); 45 | return order_id; 46 | } 47 | 48 | return null; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dao/custom/impl/ProductDAOImpl.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dao.custom.impl; 2 | 3 | import org.example.coffeeshopposjavaeebackend.dao.custom.ProductDAO; 4 | import org.example.coffeeshopposjavaeebackend.dao.custom.impl.util.SQLUtil; 5 | import org.example.coffeeshopposjavaeebackend.dto.CustomerDTO; 6 | import org.example.coffeeshopposjavaeebackend.dto.ProductDTO; 7 | import org.example.coffeeshopposjavaeebackend.entity.Product; 8 | 9 | import java.sql.Connection; 10 | import java.sql.ResultSet; 11 | import java.sql.SQLException; 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | public class ProductDAOImpl implements ProductDAO { 16 | public static String SAVE_PRODUCT = "INSERT INTO product (pro_id,pro_name,price,category,quantity) VALUES(?,?,?,?,?)"; 17 | 18 | public static String DELETE_PRODUCT = "DELETE FROM product where pro_id=?"; 19 | 20 | public static String UPDATE_PRODUCT = "UPDATE product SET pro_name=?, price=?, category=?, quantity=? WHERE pro_id=?"; 21 | 22 | public static String GET_PRODUCT = "SELECT * FROM product"; 23 | public String saveProduct(ProductDTO product , Connection connection) throws SQLException{ 24 | try{ 25 | var sc = connection.prepareStatement(SAVE_PRODUCT); 26 | sc.setString(1,product.getPro_id()); 27 | sc.setString(2,product.getPro_name()); 28 | sc.setString(3,product.getPrice()); 29 | sc.setString(4, product.getCategory()); 30 | sc.setString(5, product.getQuantity()); 31 | 32 | if(sc.executeUpdate() != 0){ 33 | return "Product Save Successfully"; 34 | }else { 35 | return "Failed to Save Product"; 36 | } 37 | }catch (SQLException e){ 38 | throw new SQLException(e.getMessage()); 39 | } 40 | } 41 | 42 | public boolean deleteProduct(String proId, Connection connection) throws SQLException { 43 | var sc = connection.prepareStatement(DELETE_PRODUCT); 44 | sc.setString(1,proId); 45 | return sc.executeUpdate() !=0; 46 | } 47 | 48 | public boolean updateProduct(String proId, ProductDTO product, Connection connection) throws SQLException { 49 | try{ 50 | var sc = connection.prepareStatement(UPDATE_PRODUCT); 51 | sc.setString(1,product.getPro_name()); 52 | sc.setString(2,product.getPrice()); 53 | sc.setString(3,product.getCategory()); 54 | sc.setString(4,product.getQuantity()); 55 | sc.setString(5,product.getPro_id()); 56 | return sc.executeUpdate() !=0; 57 | }catch (SQLException e){ 58 | throw new SQLException(e.getMessage()); 59 | } 60 | } 61 | 62 | public List getAllProduct(Connection connection) throws SQLException { 63 | try { 64 | ProductDTO productDTO = new ProductDTO(); 65 | var sc = connection.prepareStatement(GET_PRODUCT); 66 | ResultSet rst = sc.executeQuery(); 67 | ArrayList products = new ArrayList<>(); 68 | 69 | while (rst.next()){ 70 | products.add(new Product( 71 | rst.getString("pro_id"), 72 | rst.getString("pro_name"), 73 | rst.getString("price"), 74 | rst.getString("category"), 75 | rst.getString("quantity"))); 76 | } 77 | return products; 78 | }catch (Exception e){ 79 | throw new SQLException(e.getMessage()); 80 | } 81 | } 82 | 83 | @Override 84 | public Product search(Connection connection, String proId) throws SQLException { 85 | String sql = "SELECT * FROM product WHERE pro_id = ?"; 86 | ResultSet resultSet = SQLUtil.execute(sql, connection, proId); 87 | if (resultSet.next()) { 88 | return new Product( 89 | resultSet.getString(1), 90 | resultSet.getString(2), 91 | resultSet.getString(3), 92 | resultSet.getString(4), 93 | resultSet.getString(5) 94 | ); 95 | } 96 | return null; 97 | } 98 | 99 | @Override 100 | public boolean update(Connection connection, Product product) throws SQLException { 101 | String sql = "UPDATE product SET pro_name=?, price=?, category=?, quantity=? WHERE pro_id=?"; 102 | return SQLUtil.execute(sql, connection, 103 | product.getPro_name(), 104 | product.getPrice(), 105 | product.getCategory(), 106 | product.getQuantity(), 107 | product.getPro_id() 108 | ); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dao/custom/impl/util/SQLUtil.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dao.custom.impl.util; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.SQLException; 6 | 7 | public class SQLUtil { 8 | public static T execute(String sql, Connection connection, Object... args) throws SQLException { 9 | PreparedStatement preparedStatement = connection.prepareStatement(sql); 10 | for (int i = 0; i < args.length; i++){ 11 | preparedStatement.setObject((i+1), args[i]); 12 | } 13 | if (sql.startsWith("SELECT") || sql.startsWith("select")){ 14 | return (T) preparedStatement.executeQuery(); 15 | }else { 16 | return (T) (Boolean)(preparedStatement.executeUpdate() > 0); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dto/CustomerDTO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class CustomerDTO{ 11 | private String custId; 12 | private String custName; 13 | private String custAddress; 14 | private String custContact; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dto/OrderDetailsDTO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class OrderDetailsDTO { 11 | private String order_id; 12 | private String pro_id; 13 | private String qty; 14 | private String unitPrice; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dto/OrdersDTO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.time.LocalDateTime; 8 | import java.util.List; 9 | 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | public class OrdersDTO { 14 | private String order_id; 15 | private LocalDateTime dateAndTime; 16 | private String contact; 17 | private List orderDetails; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/dto/ProductDTO.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class ProductDTO { 11 | private String pro_id; 12 | private String pro_name; 13 | private String price; 14 | private String category; 15 | private String quantity; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/entity/Customer.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class Customer { 11 | private String custId; 12 | private String custName; 13 | private String custAddress; 14 | private String custContact; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/entity/OrderDetails.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class OrderDetails { 11 | private String order_id; 12 | private String pro_id; 13 | private String qty; 14 | private String unitPrice; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/entity/Orders.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.time.LocalDateTime; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class Orders { 13 | private String order_id; 14 | private LocalDateTime dateAndTime; 15 | private String contact; 16 | 17 | public Orders(String orderId, String dateAndTime, String contact) { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/entity/Product.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class Product { 11 | private String pro_id; 12 | private String pro_name; 13 | private String price; 14 | private String category; 15 | private String quantity; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/filter/CORSFilter.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.filter; 2 | 3 | import jakarta.servlet.FilterChain; 4 | import jakarta.servlet.ServletException; 5 | import jakarta.servlet.annotation.WebFilter; 6 | import jakarta.servlet.http.HttpFilter; 7 | import jakarta.servlet.http.HttpServletRequest; 8 | import jakarta.servlet.http.HttpServletResponse; 9 | 10 | import java.io.IOException; 11 | 12 | @WebFilter(urlPatterns = "/*") 13 | public class CORSFilter extends HttpFilter { 14 | @Override 15 | protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException { 16 | System.out.println("CORS Filter executed"); 17 | 18 | // Set CORS headers 19 | res.setHeader("Access-Control-Allow-Origin", "http://127.0.0.1:5501"); // Allow your frontend origin 20 | res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS"); // Allowed HTTP methods 21 | res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization"); // Allowed request headers 22 | res.setHeader("Access-Control-Expose-Headers", "Content-Type, Authorization"); // Exposed response headers 23 | res.setHeader("Access-Control-Allow-Credentials", "true"); // Allow cookies and credentials 24 | 25 | // Handle preflight (OPTIONS) requests 26 | if ("OPTIONS".equalsIgnoreCase(req.getMethod())) { 27 | res.setStatus(HttpServletResponse.SC_OK); // Respond OK to preflight requests 28 | return; 29 | } 30 | 31 | // Continue with the filter chain 32 | chain.doFilter(req, res); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/example/coffeeshopposjavaeebackend/filter/Security.java: -------------------------------------------------------------------------------- 1 | package org.example.coffeeshopposjavaeebackend.filter; 2 | 3 | import jakarta.servlet.FilterChain; 4 | import jakarta.servlet.ServletException; 5 | import jakarta.servlet.http.HttpFilter; 6 | import jakarta.servlet.http.HttpServletRequest; 7 | import jakarta.servlet.http.HttpServletResponse; 8 | 9 | import java.io.IOException; 10 | 11 | public class Security extends HttpFilter { 12 | @Override 13 | protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException { 14 | System.out.println("Security Filter"); 15 | chain.doFilter(req,res); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/sql/databasesQuary.sql: -------------------------------------------------------------------------------- 1 | create database if not exists coffee_shop_pos; 2 | 3 | use coffee_shop_pos; 4 | 5 | create table Customer( 6 | cust_id varchar(25), 7 | cust_name varchar(25), 8 | address varchar(40), 9 | contact varchar(10)PRIMARY KEY 10 | ); 11 | 12 | create table Product( 13 | pro_id varchar(25)PRIMARY KEY, 14 | pro_name varchar(25), 15 | price varchar(25), 16 | category varchar(25), 17 | quantity varchar(25) 18 | ); 19 | 20 | create table Orders( 21 | order_id varchar(50)PRIMARY KEY, 22 | dateAndTime DateTime, 23 | contact varchar(10), 24 | FOREIGN KEY (contact) REFERENCES Customer(contact) 25 | ); 26 | 27 | create table OrderDetails( 28 | order_id varchar(50), 29 | pro_id varchar(25), 30 | qty varchar(25), 31 | unitPrice varchar(25), 32 | FOREIGN KEY (order_id) REFERENCES Orders(order_id), 33 | FOREIGN KEY (pro_id) REFERENCES Product(pro_id) 34 | ); 35 | 36 | -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n 5 | 6 | 7 | 8 | H:\Projects\AAD\Coffee-Shop-POS-JavaEE-Backend\app.log 9 | true 10 | 11 | %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/main/webapp/META-INF/context.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | origin 9 | http://127.0.0.1:5500 10 | 11 | 12 | 13 | Security 14 | org.example.coffeeshopposjavaeebackend.filter.Security 15 | 16 | 17 | 18 | Security 19 | /* 20 | 21 | 22 | 23 | CORSFilter 24 | org.example.coffeeshopposjavaeebackend.filter.CORSFilter 25 | 26 | 27 | 28 | CORSFilter 29 | /* 30 | 31 | 32 | 33 | DB Connection 34 | jdbc/pos 35 | javax.sql.DataSource 36 | Container 37 | 38 | 39 | --------------------------------------------------------------------------------