├── .classpath ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ └── feature_request.yml └── pull_request_template.md ├── .gitignore ├── .project ├── .settings ├── .jsdtscope ├── org.eclipse.jdt.core.prefs ├── org.eclipse.m2e.core.prefs ├── org.eclipse.wst.common.component ├── org.eclipse.wst.common.project.facet.core.xml ├── org.eclipse.wst.jsdt.ui.superType.container ├── org.eclipse.wst.jsdt.ui.superType.name └── org.eclipse.wst.validation.prefs ├── 1.sh ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Dummy_Database.md ├── Jenkinsfile ├── Procfile ├── README.md ├── WebContent ├── CustomerHome.html ├── CustomerLogin.html ├── CustomerRegister.html ├── META-INF │ └── MANIFEST.MF ├── Photo.jpg ├── SellerHome.html ├── SellerLogin.html ├── WEB-INF │ └── web.xml ├── favicons │ ├── android-chrome-192x192.png │ ├── android-chrome-512x512.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── favicon.ico │ └── site.webmanifest ├── index.html ├── loader.gif ├── login.html ├── logo.png ├── payment.html └── styles.css ├── appspec.yaml ├── buildspec.yaml ├── pom.xml ├── scripts ├── start_server.sh └── stop_server.sh ├── setup └── CreateDatastore.sql └── src └── main ├── java ├── com │ └── bittercode │ │ ├── constant │ │ ├── BookStoreConstants.java │ │ ├── ResponseCode.java │ │ └── db │ │ │ ├── BooksDBConstants.java │ │ │ └── UsersDBConstants.java │ │ ├── model │ │ ├── Address.java │ │ ├── Book.java │ │ ├── Cart.java │ │ ├── StoreException.java │ │ ├── User.java │ │ ├── UserRole.java │ │ └── package-info.java │ │ ├── service │ │ ├── BookService.java │ │ ├── UserService.java │ │ └── impl │ │ │ ├── BookServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ └── util │ │ ├── DBUtil.java │ │ ├── DatabaseConfig.java │ │ └── StoreUtil.java └── servlets │ ├── AboutServlet.java │ ├── AddBookServlet.java │ ├── BuyBooksServlet.java │ ├── CartServlet.java │ ├── CheckoutServlet.java │ ├── CustomerLoginServlet.java │ ├── CustomerRegisterServlet.java │ ├── ErrorHandlerServlet.java │ ├── LogoutServlet.java │ ├── ProcessPaymentServlet.java │ ├── ReceiptServlet.java │ ├── RemoveBookServlet.java │ ├── SellerLoginServlet.java │ ├── StoreBookServlet.java │ ├── UpdateBookServlet.java │ └── ViewBookServlet.java └── resources └── application.properties /.classpath: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug report 2 | description: Create a report to help us improve. Report bugs found while using the project 3 | title: "[BUG]" 4 | labels: [bug] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: "Provide a general summary of the issue in the Title above" 9 | - type: textarea 10 | id: description 11 | attributes: 12 | label: Description 13 | description: Provide a general summary of the issue in the Title above 14 | validations: 15 | required: true 16 | - type: input 17 | id: expectedbhv 18 | attributes: 19 | label: Expected behavior 20 | description: Tell us what should happen 21 | validations: 22 | required: true 23 | - type: input 24 | id: actualbhv 25 | attributes: 26 | label: Actual behavior 27 | description: Tell us what happens instead 28 | validations: 29 | required: true 30 | - type: input 31 | id: possiblefix 32 | attributes: 33 | label: Possible fix 34 | description: Not obligatory, but suggest a fix or reason for the bug 35 | validations: 36 | required: false 37 | - type: textarea 38 | id: steps 39 | attributes: 40 | label: Steps to reproduce 41 | description: | 42 | Provide a link to a live example, or an unambiguous set of steps to 43 | reproduce this bug. Include code to reproduce, if relevant 44 | placeholder: | 45 | 1. 46 | 2. 47 | 3. 48 | 4. 49 | validations: 50 | required: true 51 | - type: textarea 52 | id: context 53 | attributes: 54 | label: Context 55 | description: How has this bug affected you? What were you trying to accomplish? 56 | validations: 57 | required: true 58 | - type: textarea 59 | id: extrainformation 60 | attributes: 61 | label: Additional information 62 | description: Is there anything else we should know about this bug? 63 | validations: 64 | required: false 65 | 66 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: Feature request 2 | description: Suggest features, propose improvements, discuss new ideas. 3 | title: "[FEATURE]" 4 | labels: [enhancement] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: Provide a general summary of the issue in the Title above 9 | - type: textarea 10 | id: description 11 | attributes: 12 | label: Detailed description 13 | description: Provide a detailed description of the change or addition you are proposing 14 | validations: 15 | required: true 16 | - type: textarea 17 | id: context 18 | attributes: 19 | label: Context 20 | description: | 21 | Why is this change important to you? How would you use it? 22 | How can it benefit other users? 23 | validations: 24 | required: true 25 | - type: textarea 26 | id: possibleimpl 27 | attributes: 28 | label: Possible implementation 29 | description: Not obligatory, but suggest an idea for implementing addition or change 30 | validations: 31 | required: false 32 | - type: textarea 33 | id: extrainformation 34 | attributes: 35 | label: Additional information 36 | description: Is there anything else we should know about this feature? 37 | validations: 38 | required: false 39 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | #### Description of Change 2 | 3 | 9 | 10 | #### References 11 | 12 | 13 | ## Type of change 14 | 15 | 16 | - [ ] Bug fix (non-breaking change which fixes an issue) 17 | - [ ] New feature (non-breaking change which adds functionality) 18 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 19 | - [ ] This change requires a documentation update 20 | 21 | #### Checklist 22 | 23 | 24 | - [ ] Added description of change 25 | - [ ] Relevant documentation/comments is changed or added 26 | - [ ] Search previous suggestions before making a new one, as yours may be a duplicate. 27 | - [ ] I have performed a self-review of my own code by running the project in local 28 | - [ ] I acknowledge that all my contributions will be made under the project's license. 29 | 30 | Notes: 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /build/ 3 | .classpath 4 | .settings 5 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | onlinebookstore 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.m2e.core.maven2Nature 31 | org.eclipse.jem.workbench.JavaEMFNature 32 | org.eclipse.wst.common.modulecore.ModuleCoreNature 33 | org.eclipse.wst.common.project.facet.core.nature 34 | org.eclipse.jdt.core.javanature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | 39 | 1665573956898 40 | 41 | 30 42 | 43 | org.eclipse.core.resources.regexFilterMatcher 44 | node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Change the Git history of a repository 5 | # 6 | # Note: Running this script rewrites history for all repository collaborators. 7 | # After completing these steps, any person with forks or clones must fetch 8 | # the rewritten history and rebase any local changes into the rewritten history. 9 | # 10 | 11 | VERSION="v2.4.1" 12 | 13 | # Set Defaults 14 | SHOW_HELP=0 15 | SHOW_VERSION=0 16 | REPOSITORY_VERIFIED=0 # Set global REPOSITORY_VERIFIED function to false so user must confirm 17 | SHOULD_EXECUTE=0 # Set global SHOULD_EXECUTE function to false so user must confirm 18 | REMOTE_REPOSITORY= 19 | USER_OLD_EMAIL= 20 | USER_NEW_EMAIL= 21 | USER_NEW_NAME= 22 | USER_GIT_DIR= 23 | USER_WORK_TREE= 24 | UPDATE_REMOTE= 25 | DEFAULT_REMOTE="origin" 26 | USER_REMOTE= 27 | 28 | # Set Colors 29 | COLOR_RED=$'\e[31m' 30 | COLOR_CYAN=$'\e[36m' 31 | COLOR_YELLOW=$'\e[93m' 32 | COLOR_GREEN=$'\e[32m' 33 | COLOR_RESET=$'\e[0m' 34 | 35 | PARAMS="" 36 | 37 | # Loop through arguments and process them 38 | while (("$#")); do 39 | 40 | # Debug: Show flag being evaulated 41 | # echo " ${COLOR_CYAN}$1${COLOR_RESET}" 42 | 43 | case "$1" in 44 | -h | -\? | --help) 45 | SHOW_HELP=1 46 | ;; 47 | -v | -V | --version) 48 | SHOW_VERSION=1 49 | ;; 50 | -f | --force) 51 | REPOSITORY_VERIFIED=1 52 | SHOULD_EXECUTE=1 53 | ;; 54 | # USER_OLD_EMAIL 55 | -o | --old-email) 56 | if [ "$2" ]; then 57 | USER_OLD_EMAIL=$(echo "$2" | awk "{print tolower(\$0)}") 58 | shift # Remove argument name from processing 59 | else 60 | echo "${COLOR_RED}ERROR: Value for $1 is required."${COLOR_RESET} >&2 61 | exit 1 62 | fi 63 | ;; 64 | -o=*? | --old-email=*?) 65 | USER_OLD_EMAIL=$(echo "${1#*=}" | awk "{print tolower(\$0)}") 66 | ;; 67 | # USER_NEW_EMAIL 68 | -e | --new-email) 69 | if [ "$2" ]; then 70 | USER_NEW_EMAIL="$2" 71 | shift # Remove argument name from processing 72 | else 73 | echo "${COLOR_RED}ERROR: Value for $1 is required."${COLOR_RESET} >&2 74 | exit 1 75 | fi 76 | ;; 77 | -e=*? | --new-email=*?) 78 | USER_NEW_EMAIL="${1#*=}" 79 | ;; 80 | # USER_NEW_NAME 81 | -n | --new-name) 82 | if [ "$2" ]; then 83 | USER_NEW_NAME="$2" 84 | shift # Remove argument name from processing 85 | else 86 | echo "${COLOR_RED}ERROR: Value for $1 is required."${COLOR_RESET} >&2 87 | exit 1 88 | fi 89 | ;; 90 | -n=*? | --new-name=*?) 91 | USER_NEW_NAME="${1#*=}" 92 | ;; 93 | # USER_REMOTE 94 | -r | --remote) 95 | if [ "$2" ]; then 96 | USER_REMOTE="$2" 97 | # Automatically set UPDATE_REMOTE to true 98 | UPDATE_REMOTE=1 99 | shift # Remove argument name from processing 100 | else 101 | echo "${COLOR_RED}ERROR: Value for $1 is required."${COLOR_RESET} >&2 102 | exit 1 103 | fi 104 | ;; 105 | -r=*? | --remote=*?) 106 | USER_REMOTE="${1#*=}" 107 | # Automatically set UPDATE_REMOTE to true 108 | UPDATE_REMOTE=1 109 | ;; 110 | # USER_GIT_DIR 111 | -d | --git-dir) 112 | if [ "$2" ]; then 113 | USER_GIT_DIR="--git-dir=$2" 114 | shift # Remove argument name from processing 115 | else 116 | echo "${COLOR_RED}ERROR: Value for $1 is required."${COLOR_RESET} >&2 117 | exit 1 118 | fi 119 | ;; 120 | -d=*? | --git-dir=*?) 121 | USER_GIT_DIR="--git-dir=${1#*=}" 122 | ;; 123 | # USER_WORK_TREE 124 | -w | --work-tree) 125 | if [ "$2" ]; then 126 | USER_WORK_TREE="--work-tree=$2" 127 | shift # Remove argument name from processing 128 | else 129 | echo "${COLOR_RED}ERROR: Value for $1 is required."${COLOR_RESET} >&2 130 | exit 1 131 | fi 132 | ;; 133 | -w=*? | --work-tree=*?) 134 | USER_WORK_TREE="--work-tree=${1#*=}" 135 | ;; 136 | # End of all options 137 | -* | --*=) # unsupported flags 138 | echo "${COLOR_RED}ERROR: Flag $1 is not a supported option."${COLOR_RESET} >&2 139 | exit 1 140 | ;; 141 | # preserve positional arguments 142 | *) 143 | PARAMS="${PARAMS} $1" 144 | shift 145 | ;; 146 | esac 147 | shift 148 | done 149 | 150 | # Set positional arguments in their proper place 151 | eval set -- "$PARAMS" 152 | 153 | # Version 154 | showVersion() { 155 | echo "" 156 | echo "${COLOR_YELLOW}changeauthor $VERSION${COLOR_RESET}" 157 | footerInfo 158 | } 159 | 160 | footerInfo() { 161 | echo "" 162 | echo "For updates and more information:" 163 | echo " https://github.com/adamdehaven/change-git-author" 164 | echo "" 165 | echo "Created by Adam DeHaven" 166 | echo " @adamdehaven or https://www.adamdehaven.com/" 167 | echo "" 168 | } 169 | 170 | # Help text 171 | showHelp() { 172 | echo "" 173 | echo "Description:" 174 | echo " A bash script to update (change) a git repository's commit author history for a given author email address." 175 | echo "" 176 | echo "Usage:" 177 | echo " 1. Set execute permissions for the script:" 178 | echo " ${COLOR_CYAN}chmod +x ./changeauthor.sh${COLOR_RESET}" 179 | echo " 2. Navigate into the repository with the incorrect commit history:" 180 | echo " ${COLOR_CYAN}cd path/to/git/repository${COLOR_RESET}" 181 | echo "" 182 | echo " Alternatively, you can run from anywhere by passing the ${COLOR_CYAN}--git-dir${COLOR_RESET} and ${COLOR_CYAN}--work-tree${COLOR_RESET} flags." 183 | echo "" 184 | echo " 3. Enter the following to run the script (with or without options):" 185 | echo " ${COLOR_CYAN}./changeauthor.sh [OPTIONS]...${COLOR_RESET}" 186 | echo "" 187 | echo " Alternatively, you may execute with either of the following:" 188 | echo " a) ${COLOR_CYAN}sh ./changeauthor.sh [OPTIONS]...${COLOR_RESET}" 189 | echo " b) ${COLOR_CYAN}bash ./changeauthor.sh [OPTIONS]...${COLOR_RESET}" 190 | echo "" 191 | echo " ${COLOR_YELLOW}Note: The script will run in interactive mode if no options are passed.${COLOR_RESET}" 192 | echo "" 193 | echo "Options:" 194 | echo "" 195 | echo " -o, --old-email The old/incorrect email address of the author you would like to " 196 | echo " replace in the commit history." 197 | echo " Example: ${COLOR_CYAN}emmett.brown@example.com${COLOR_RESET}" 198 | echo "" 199 | echo " -e, --new-email The new/corrected email address to replace in commits matching" 200 | echo " the old email." 201 | echo " Example: ${COLOR_CYAN}marty.mcfly@example.com${COLOR_RESET}" 202 | echo "" 203 | echo " -n, --new-name The new/corrected name for the new commit author info." 204 | echo " ${COLOR_YELLOW}Be sure to enclose the name in quotes if passing as a flag${COLOR_RESET}" 205 | echo " Example: ${COLOR_CYAN}Marty McFly${COLOR_RESET}" 206 | echo "" 207 | echo " -r, --remote The name of the repository remote you would like to alter." 208 | echo " Default: ${COLOR_YELLOW}origin${COLOR_RESET}" 209 | echo " Example: ${COLOR_CYAN}github${COLOR_RESET}" 210 | echo "" 211 | echo " -f, --force Allows the script to run successfully in a non-interactive" 212 | echo " shell (assuming all required flags are set), bypassing " 213 | echo " the confirmation prompt." 214 | echo " ${COLOR_YELLOW}WARNING: By passing the --force flag (along with all other${COLOR_RESET}" 215 | echo " ${COLOR_YELLOW}required flags), there is no turning back. Once you start${COLOR_RESET}" 216 | echo " ${COLOR_YELLOW}the script, the process will start and can severely${COLOR_RESET}" 217 | echo " ${COLOR_YELLOW}damage your repository if used incorrectly.${COLOR_RESET}" 218 | echo "" 219 | echo " -d, --git-dir Set the path to the repository (\".git\" directory) if it" 220 | echo " differs from the current directory. It can be an absolute path or" 221 | echo " relative path to current working directory." 222 | echo " ${COLOR_YELLOW}This option should be used in conjunction with${COLOR_RESET}" 223 | echo " ${COLOR_YELLOW}the --work-tree flag.${COLOR_RESET}" 224 | echo "" 225 | echo " -w, --work-tree Set the path to the working tree. It can be an absolute" 226 | echo " path or a path relative to the current working directory." 227 | echo "" 228 | echo " -v, -V, --version Show version info." 229 | echo "" 230 | echo " -h, -?, --help Show this help message." 231 | echo "" 232 | echo "--------------------------------------------" 233 | footerInfo 234 | } 235 | 236 | # If user passed help flag 237 | if [ "$SHOW_HELP" == 1 ]; then 238 | showHelp 239 | exit 240 | # If user passed version flag 241 | elif [ "$SHOW_VERSION" == 1 ]; then 242 | showVersion 243 | exit 244 | fi 245 | 246 | # Check if --git-dir is inside git repository, if not, exit 247 | INSIDE_GIT_REPO="$(git ${USER_GIT_DIR} ${USER_WORK_TREE} rev-parse --is-inside-work-tree 2>/dev/null)" 248 | if [ ! "$INSIDE_GIT_REPO" ]; then 249 | echo "" 250 | echo "${COLOR_RED}ERROR: This is not a git repository.${COLOR_RESET}" 251 | echo "" 252 | echo "${COLOR_YELLOW}You must run the script from within a git repository or utilize${COLOR_RESET}" 253 | echo "${COLOR_YELLOW}the --git-dir and --work-tree flags to set the path to the${COLOR_RESET}" 254 | echo "${COLOR_YELLOW}repository and working tree. Run with --help for more info.${COLOR_RESET}" 255 | exit 256 | fi 257 | 258 | # USER_OLD_EMAIL 259 | if [ -z "$USER_OLD_EMAIL" ] && [ "$SHOULD_EXECUTE" == 0 ]; then 260 | echo "" 261 | echo "# ---------------------------------- #" 262 | echo "# Change Author for Existing Commits #" 263 | echo "# ---------------------------------- #" 264 | # Prompt user for email to replace ( USER_OLD_EMAIL ) 265 | echo "" 266 | echo "Commit Authors:" 267 | echo "--------------------------------------------" 268 | echo "$(git ${USER_GIT_DIR} ${USER_WORK_TREE} log --pretty=format:"${COLOR_CYAN}%an - %ae${COLOR_RESET}" | sort -u)" 269 | echo "--------------------------------------------" 270 | echo "" 271 | echo "Enter the email address of the author you " 272 | echo "would like to replace in the commit history." 273 | echo "--------------------------------------------" 274 | read -p "Email to Replace: ${COLOR_CYAN}" USER_OLD_EMAIL 275 | echo "${COLOR_RESET}" 276 | elif [ -z "$USER_OLD_EMAIL" ] && [ "$SHOULD_EXECUTE" == 1 ]; then 277 | echo "${COLOR_RED}ERROR: --old-email is required.${COLOR_RESET}" 278 | echo "${COLOR_RED}Try again by passing a valid old email address or removing the --force flag."${COLOR_RESET} >&2 279 | exit 1 280 | fi 281 | 282 | if [ -z "$USER_OLD_EMAIL" ]; then 283 | echo "${COLOR_RED}ERROR: Email to Replace is required.${COLOR_RESET}" 284 | echo "${COLOR_RED}Try again and be sure to provide a valid email address to replace."${COLOR_RESET} >&2 285 | exit 1 286 | else 287 | # Set USER_OLD_EMAIL and transform to lowercase 288 | USER_OLD_EMAIL=$(echo "$USER_OLD_EMAIL" | awk "{print tolower(\$0)}") 289 | fi 290 | 291 | # Check if USER_OLD_EMAIL exists in log 292 | USER_OLD_EMAIL_EXISTS="$(git ${USER_GIT_DIR} ${USER_WORK_TREE} log --pretty=format:"%ae" | grep -wxi ${USER_OLD_EMAIL})" 293 | 294 | # If USER_OLD_EMAIL does NOT exist in log 295 | if [ -z "$USER_OLD_EMAIL_EXISTS" ]; then 296 | # USER_OLD_EMAIL does not exist in log 297 | echo "${COLOR_YELLOW}The email '${USER_OLD_EMAIL}' does not exist in the commit history for ${COLOR_RESET}" 298 | echo "${COLOR_YELLOW}this repository. Please check your spelling and try again.${COLOR_RESET}" 299 | exit 1 300 | fi 301 | 302 | # USER_NEW_EMAIL 303 | if [ -z "$USER_NEW_EMAIL" ] && [ "$SHOULD_EXECUTE" == 0 ]; then 304 | # Prompt user for correct email ( USER_NEW_EMAIL ) 305 | echo "" 306 | echo "Enter a new/corrected email for this user." 307 | echo "------------------------------------------" 308 | read -p "New Email: ${COLOR_CYAN}" USER_NEW_EMAIL 309 | echo "${COLOR_RESET}" 310 | elif [ -z "$USER_NEW_EMAIL" ] && [ "$SHOULD_EXECUTE" == 1 ]; then 311 | echo "${COLOR_RED}ERROR: --new-email is required.${COLOR_RESET}" 312 | echo "${COLOR_RED}A new email address is required. Please try again.${COLOR_RESET}" 313 | exit 1 314 | fi 315 | 316 | if [ -z "$USER_NEW_EMAIL" ]; then 317 | echo "${COLOR_RED}ERROR: New Email is required.${COLOR_RESET}" 318 | echo "${COLOR_RED}Try again and be sure to provide a valid new email address."${COLOR_RESET} >&2 319 | exit 1 320 | else 321 | # Set USER_NEW_EMAIL and transform to lowercase 322 | USER_NEW_EMAIL="${USER_NEW_EMAIL}" 323 | fi 324 | 325 | # If old email address matches new email address 326 | if [ "$USER_OLD_EMAIL" == "$USER_NEW_EMAIL" ] && [ "$SHOULD_EXECUTE" == 0 ]; then 327 | # Check if user would like to update a remote repository 328 | while true; do 329 | echo "${COLOR_YELLOW}The old email address, '${USER_OLD_EMAIL}' matches the${COLOR_RESET}" 330 | echo "${COLOR_YELLOW}new email address you provided, '${USER_NEW_EMAIL}'.${COLOR_RESET}" 331 | echo "${COLOR_YELLOW}If you continue, you will only be updating the name.${COLOR_RESET}" 332 | echo "" 333 | read -p "${COLOR_YELLOW}Continue to updating the name only? [y/n]: ${COLOR_CYAN}" UPDATE_NAME 334 | echo "${COLOR_RESET}" 335 | case $UPDATE_NAME in 336 | [Yy]*) 337 | UPDATE_NAME=1 338 | break 339 | ;; 340 | [Nn]*) 341 | UPDATE_NAME=0 342 | break 343 | ;; 344 | *) 345 | echo "" 346 | echo " ${COLOR_YELLOW}You must enter 'y' or 'n' to signal if you would like to update just the name.${COLOR_RESET}" 347 | echo "" 348 | ;; 349 | esac 350 | done 351 | else 352 | UPDATE_NAME=1 353 | fi 354 | 355 | if [ "$UPDATE_NAME" == 0 ]; then 356 | echo "" 357 | echo "${COLOR_YELLOW}No changes are necessary.${COLOR_RESET}" 358 | SHOULD_EXECUTE=0 359 | exit 1 360 | fi 361 | 362 | # USER_NEW_NAME 363 | if [ -z "$USER_NEW_NAME" ] && [ "$SHOULD_EXECUTE" == 0 ]; then 364 | # Prompt user for correct name ( USER_NEW_NAME ) 365 | echo "" 366 | echo "Enter the new/corrected first and last name for this user." 367 | echo "----------------------------------------------------------" 368 | read -p "New Name: ${COLOR_CYAN}" USER_NEW_NAME 369 | echo "${COLOR_RESET}" 370 | elif [ -z "$USER_NEW_NAME" ] && [ "$SHOULD_EXECUTE" == 1 ]; then 371 | echo "${COLOR_RED}ERROR: --new-name is required.${COLOR_RESET}" 372 | echo "${COLOR_RED}Try again by passing a valid first and last name or removing the --force flag."${COLOR_RESET} >&2 373 | exit 1 374 | fi 375 | 376 | if [ -z "$USER_NEW_NAME" ]; then 377 | echo "${COLOR_RED}ERROR: New Name is required.${COLOR_RESET}" 378 | echo "${COLOR_RED}Try again and be sure to provide a valid first and last name."${COLOR_RESET} >&2 379 | exit 1 380 | else 381 | USER_NEW_NAME="${USER_NEW_NAME}" 382 | fi 383 | 384 | # Get a list of remote repositories, if they exist 385 | ALL_REMOTE_REPOSITORIES=$(git ${USER_GIT_DIR} ${USER_WORK_TREE} remote show) 386 | 387 | # If user wants to update remote and remote repositories exist, and user did not force 388 | if [ -z "$UPDATE_REMOTE" ] && [ -n "$ALL_REMOTE_REPOSITORIES" ] && [ "$SHOULD_EXECUTE" == 0 ]; then 389 | # Check if user would like to update a remote repository 390 | while true; do 391 | read -p "Would you like to update a remote repository? [y/n]: ${COLOR_CYAN}" UPDATE_REMOTE 392 | echo "${COLOR_RESET}" 393 | case $UPDATE_REMOTE in 394 | [Yy]*) 395 | UPDATE_REMOTE=1 396 | break 397 | ;; 398 | [Nn]*) 399 | UPDATE_REMOTE=0 400 | break 401 | ;; 402 | *) 403 | echo "" 404 | echo " ${COLOR_YELLOW}You must enter 'y' or 'n' to signal if you would like to update a remote repository.${COLOR_RESET}" 405 | echo "" 406 | ;; 407 | esac 408 | done 409 | elif [ "$SHOULD_EXECUTE" == 1 ] && [ -n "$ALL_REMOTE_REPOSITORIES" ]; then 410 | # User forced, and remote repositories exist, so set flag 411 | UPDATE_REMOTE=1 412 | elif [ -z "$ALL_REMOTE_REPOSITORIES" ]; then 413 | # Remote repositories do not exist, so set flag 414 | UPDATE_REMOTE=0 415 | fi 416 | 417 | # USER_REMOTE 418 | if [ "$UPDATE_REMOTE" == 1 ] && [ -z "$USER_REMOTE" ] && [ "$SHOULD_EXECUTE" == 0 ]; then 419 | # Prompt user for remote (Default: 'origin' ) 420 | echo "" 421 | echo "Existing Remote Repositories:" 422 | echo "--------------------------------------------" 423 | echo "${COLOR_CYAN}$(git ${USER_GIT_DIR} ${USER_WORK_TREE} remote show)${COLOR_RESET}" 424 | echo "--------------------------------------------" 425 | echo "" 426 | echo "Enter the name of the remote you would like to alter." 427 | echo "Default: ${COLOR_YELLOW}${DEFAULT_REMOTE}${COLOR_RESET}" 428 | echo "--------------------------------------------------------" 429 | read -p "Remote Name [Press enter to use ${COLOR_YELLOW}${DEFAULT_REMOTE}${COLOR_RESET}]: ${COLOR_CYAN}" USER_REMOTE 430 | USER_REMOTE=${USER_REMOTE:-"$DEFAULT_REMOTE"} 431 | echo "${COLOR_RESET}" 432 | elif [ -z "$USER_REMOTE" ] && [ "$SHOULD_EXECUTE" == 1 ]; then 433 | # Running non-interactive, so set to default 434 | USER_REMOTE="$DEFAULT_REMOTE" 435 | echo "" 436 | echo "${COLOR_YELLOW}--remote flag not present... proceeding with default remote '${USER_REMOTE}'.${COLOR_RESET}" 437 | fi 438 | 439 | # Double-check that USER_REMOTE is set 440 | if [ -z "$USER_REMOTE" ]; then 441 | USER_REMOTE="${DEFAULT_REMOTE}" 442 | else 443 | USER_REMOTE="${USER_REMOTE}" 444 | fi 445 | 446 | if [ "$UPDATE_REMOTE" == 1 ]; then 447 | # Check if USER_REMOTE exists 448 | USER_REMOTE_EXISTS="$(git ${USER_GIT_DIR} ${USER_WORK_TREE} remote show | grep -wxi ${USER_REMOTE})" 449 | # Get the remote repository URL, if there is one 450 | REMOTE_REPOSITORY=$(git ${USER_GIT_DIR} ${USER_WORK_TREE} config --get remote.${USER_REMOTE}.url) 451 | 452 | # If USER_REMOTE does NOT exist 453 | if [ -z "$USER_REMOTE_EXISTS" ] || [ -z "$REMOTE_REPOSITORY" ]; then 454 | echo "" 455 | echo "${COLOR_YELLOW}The remote '${USER_REMOTE}' does not exist in this repository. ${COLOR_RESET}" 456 | echo "${COLOR_YELLOW}You may run 'git remote show' to view available remotes, and then try again.${COLOR_RESET}" 457 | echo "" 458 | SHOULD_EXECUTE=0 459 | exit 1 460 | fi 461 | fi 462 | 463 | # Have user verify repository 464 | if [ "$UPDATE_REMOTE" == 1 ] && [ -n "$USER_REMOTE_EXISTS" ] && [ -n "$REMOTE_REPOSITORY" ] && [ "$REPOSITORY_VERIFIED" == 0 ]; then 465 | while true; do 466 | echo "" 467 | echo "Please verify that the remote repository shown below is correct:" 468 | echo "Remote URL: ${COLOR_YELLOW}${REMOTE_REPOSITORY}${COLOR_RESET}" 469 | echo "--------------------------------------------------------" 470 | read -p "${COLOR_RED}Is this the correct repository? [y/n]: ${COLOR_CYAN}" USER_CONFIRM 471 | echo "${COLOR_RESET}" 472 | case $USER_CONFIRM in 473 | [Yy]*) 474 | REPOSITORY_VERIFIED=1 475 | break 476 | ;; 477 | [Nn]*) 478 | REPOSITORY_VERIFIED=0 479 | break 480 | ;; 481 | *) 482 | echo "" 483 | echo " ${COLOR_YELLOW}You must enter 'y' to verify the repository, or 'n' to cancel${COLOR_RESET}" 484 | echo "" 485 | ;; 486 | esac 487 | done 488 | fi 489 | 490 | # Have the user confirm before executing (if they didn't already cancel) 491 | if [ "$SHOULD_EXECUTE" == 0 ] && { [ "$REPOSITORY_VERIFIED" == 1 ] || [ "$UPDATE_REMOTE" == 0 ]; }; then 492 | while true; do 493 | echo "" 494 | echo "Are you sure you want to rewrite the entire" 495 | echo "history of this Git repository?" 496 | echo "-------------------------------------------" 497 | echo "Old email: ${COLOR_CYAN}${USER_OLD_EMAIL}${COLOR_RESET}" 498 | echo "New email: ${COLOR_CYAN}${USER_NEW_EMAIL}${COLOR_RESET}" 499 | echo "New name: ${COLOR_CYAN}${USER_NEW_NAME}${COLOR_RESET}" 500 | if [ "$UPDATE_REMOTE" == 1 ] && [ -n "$USER_REMOTE" ] && [ -n "$REMOTE_REPOSITORY" ]; then 501 | echo "Remote: ${COLOR_CYAN}${USER_REMOTE}${COLOR_RESET}" 502 | echo "Remote URL: ${COLOR_CYAN}${REMOTE_REPOSITORY}${COLOR_RESET}" 503 | fi 504 | echo "" 505 | echo "${COLOR_YELLOW}Note: Running this script rewrites history for all${COLOR_RESET}" 506 | echo "${COLOR_YELLOW}repository collaborators. Any person with forks ${COLOR_RESET}" 507 | echo "${COLOR_YELLOW}or clones must fetch the rewritten history and${COLOR_RESET}" 508 | echo "${COLOR_YELLOW}rebase any local changes into the rewritten history.${COLOR_RESET}" 509 | echo "" 510 | read -p "${COLOR_RED}Continue? [y/n]: ${COLOR_CYAN}" USER_CONFIRM 511 | echo "${COLOR_RESET}" 512 | case $USER_CONFIRM in 513 | [Yy]*) 514 | SHOULD_EXECUTE=1 515 | break 516 | ;; 517 | [Nn]*) 518 | SHOULD_EXECUTE=0 519 | break 520 | ;; 521 | *) 522 | echo "" 523 | echo " ${COLOR_YELLOW}You must enter 'y' to confirm, or 'n' to cancel${COLOR_RESET}" 524 | echo "" 525 | ;; 526 | esac 527 | done 528 | fi 529 | 530 | echo "" 531 | 532 | # If SHOULD_EXECUTE is true, and REPOSITORY_VERIFIED is true, rewrite repo history, otherwise, exit 533 | if [ "$SHOULD_EXECUTE" == 1 ]; then 534 | # Alter commits and rewrite history 535 | git ${USER_GIT_DIR:+-$USER_GIT_DIR} ${USER_WORK_TREE:+-$USER_WORK_TREE} filter-branch -f --env-filter ' 536 | if [ "$(echo "$GIT_COMMITTER_EMAIL" | awk "{print tolower(\$0)}")" = "'"$USER_OLD_EMAIL"'" ] 537 | then 538 | export GIT_COMMITTER_NAME="'"$USER_NEW_NAME"'" 539 | export GIT_COMMITTER_EMAIL="'"$USER_NEW_EMAIL"'" 540 | fi 541 | if [ "$(echo "$GIT_AUTHOR_EMAIL" | awk "{print tolower(\$0)}")" = "'"$USER_OLD_EMAIL"'" ] 542 | then 543 | export GIT_AUTHOR_NAME="'"$USER_NEW_NAME"'" 544 | export GIT_AUTHOR_EMAIL="'"$USER_NEW_EMAIL"'" 545 | fi 546 | ' --tag-name-filter cat -- --branches --tags 547 | 548 | # Show Success Message 549 | echo "" 550 | echo "${COLOR_GREEN}Successfully updated local commit author info.${COLOR_RESET}" 551 | 552 | # If user wants to update remote and the remote is verified 553 | if [ "$UPDATE_REMOTE" == 1 ] && [ -n "$REPOSITORY_VERIFIED" ]; then 554 | echo "" 555 | echo "Preparing to push to remote '${USER_REMOTE}'..." 556 | echo "" 557 | echo "${COLOR_YELLOW}You have 5 seconds to cancel (Ctrl + C)${COLOR_RESET}" 558 | echo "" 559 | # Sleep to let user cancel 560 | sleep 5 561 | 562 | # Update Remote 563 | git ${USER_GIT_DIR:+-$USER_GIT_DIR} ${USER_WORK_TREE:+-$USER_WORK_TREE} push --force --tags "$USER_REMOTE" 'refs/heads/*' 564 | 565 | echo "" 566 | echo "${COLOR_GREEN}Successfully updated remote commit author info.${COLOR_RESET}" 567 | echo "" 568 | echo "The commits linked to '${COLOR_CYAN}${USER_OLD_EMAIL}${COLOR_RESET}' have" 569 | echo "been updated to '${COLOR_CYAN}${USER_NEW_NAME} <${USER_NEW_EMAIL}>${COLOR_RESET}' and" 570 | echo "the changes have been pushed to remote '${COLOR_CYAN}${USER_REMOTE}${COLOR_RESET}'." 571 | fi 572 | else 573 | # User Cancelled 574 | echo "${COLOR_YELLOW}Changes Cancelled.${COLOR_RESET}" 575 | echo "${COLOR_YELLOW}No changes were pushed to remote '${USER_REMOTE}'.${COLOR_RESET}" 576 | fi 577 | 578 | # Reset global vars 579 | REPOSITORY_VERIFIED=0 580 | SHOULD_EXECUTE=0 581 | UPDATE_REMOTE=0 582 | # Reset git environment variables 583 | USER_GIT_DIR= 584 | USER_WORK_TREE= 585 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [Contact Email Address](https://flowcv.me/shashirajraja). The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | [pr]: https://github.com/raise-dev/hacktoberfest/compare 4 | [style]: https://github.com/bbatsov/ruby-style-guide 5 | 6 | Hi there! We're thrilled that you'd like to contribute to Hacktoberfest. Your help is essential for keeping it great. 7 | 8 | Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE). 9 | 10 | ## Opening an issue 11 | 12 | Thank you for taking the time to open an issue, your feedback helps make Hacktoberfest better. 13 | Before opening an issue, please be sure that your issue hasn't already been asked by using [GitHub search](https://help.github.com/articles/searching-issues/) 14 | 15 | Here are a few things that will help us help resolve your issues: 16 | 17 | - A descriptive title that gives an idea of what your issue refers to 18 | - A thorough description of the issue, (one word descriptions are very hard to understand) 19 | - Screenshots (if appropriate) 20 | - Links (if appropriate) 21 | 22 | ## Submitting a pull request 23 | 24 | 0. Clone the repository 25 | 0. Configure and install the dependencies: (See the [README](README.md) for more details) 26 | 0. Make sure the tests pass on your machine: `script/test` 27 | 0. Create a new branch: `git checkout -b my-branch-name` 28 | 0. Make your change, add tests, and make sure the tests still pass 29 | 0. Push to your branch and [submit a pull request][pr] 30 | 0. Wait for your pull request to be reviewed and merged! 31 | 32 | Here are a few things you can do that will increase the likelihood of your pull request being accepted: 33 | 34 | - Follow the [style guide][style]. 35 | - Write tests. 36 | - Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests. 37 | - Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). 38 | 39 | ## Resources 40 | 41 | - [Contributing to Open Source on GitHub](https://guides.github.com/activities/contributing-to-open-source/) 42 | - [Using Pull Requests](https://help.github.com/articles/using-pull-requests/) 43 | - [GitHub Help](https://help.github.com) 44 | -------------------------------------------------------------------------------- /Dummy_Database.md: -------------------------------------------------------------------------------- 1 | ### Copy and Paste the following MYSQL commands to make a dummy database for this Project : 2 | 3 | 4 | create database if not exists onlinebookstore; 5 | 6 | use onlinebookstore; 7 | 8 | create table if not exists books(barcode varchar(100) primary key, name varchar(100), author varchar(100), price int, quantity int); 9 | 10 | create table if not exists users(username varchar(100) primary key,password varchar(100), firstname varchar(100),lastname varchar(100),address text, phone varchar(100),mailid varchar(100),usertype int); 11 | 12 | 13 | insert into books values('9780134190563','The Go Programming Language','Alan A. A. Donovan and Brian W. Kernighan',400,8); 14 | 15 | insert into books values('9780133053036','C++ Primer','Stanley Lippman and Josée Lajoie and Barbara Moo',976,13); 16 | 17 | insert into books values('9781718500457','The Rust Programming Language','Steve Klabnik and Carol Nichols',560,12); 18 | 19 | insert into books values('9781491910740','Head First Java','Kathy Sierra and Bert Bates and Trisha Gee',754,23); 20 | 21 | insert into books values('9781492056300','Fluent Python','Luciano Ramalho',1014,5); 22 | 23 | insert into books values('9781720043997','The Road to Learn React','Robin Wieruch',239,18); 24 | 25 | insert into books values('9780132350884','Clean Code: A Handbook of Agile Software Craftsmanship','Robert C Martin',288,3); 26 | 27 | insert into books values('9780132181273','Domain-Driven Design','Eric Evans',560,28); 28 | 29 | insert into books values('9781951204006','A Programmers Guide to Computer Science','William Springer',188,4); 30 | 31 | insert into books values('9780316204552','The Soul of a New Machine','Tracy Kidder',293,30); 32 | 33 | insert into books values('9780132778046','Effective Java','Joshua Bloch',368,21); 34 | 35 | insert into books values('9781484255995','Practical Rust Projects','Shing Lyu',257,15); 36 | 37 | insert into users values('demo','demo','Demo','User','Demo Home','42502216225','demo@gmail.com',2); 38 | 39 | insert into users values('Admin','Admin','Mr.','Admin','Haldia WB','9584552224521','admin@gmail.com',1); 40 | 41 | insert into users values('shashi','shashi','Shashi','Raj','Bihar','1236547089','shashi@gmail.com',2); 42 | 43 | commit; 44 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | stages { 4 | stage("git_checkout") { 5 | steps { 6 | echo "cloning repository" 7 | echo "repo cloned successfully" 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OnlineBookStore 2 | - A Java Web Developement Project 3 | - **Youtube VIDEO** for step by step Local Setup Guide : https://youtu.be/mLFPodZO8Iw 4 | - **Youtube VIDEO** for local setup of tender management project: https://www.youtube.com/watch?v=7CE3aY4e644 5 | 6 | - User Login Credentials: (shashi/shashi) 7 | - Admin Login Credentials: (Admin/Admin) 8 |
9 | 10 | ### About 11 | 12 | A user-friendly Online Bookstore project in which users can log in or register, view the available books, select books along with their quantity, and buy them. Users can also get payment receipts after successful payment. The project can also be used by the administrator, who can add new books, remove books, increase and decrease the quantity of books, change the price of the books as well as maintain the selling history of books. 13 | 14 | ![onlinebookstore](https://user-images.githubusercontent.com/34605595/137615096-8447d32d-bddc-4f13-a8ed-3c0f4dd5e04e.png) 15 | 16 | **This Website is built for following purpose:-** 17 | - For Selling books online. 18 | - Maintaining books selling history. 19 | - Adding and managing books. 20 | - User Friendly. 21 | - For Implementation of Http Servlets in Java. 22 | - This is a Mini-project developed using Java, Jdbc, And Servlets. 23 | 24 | **Admin Have Following Access for this online store site:-** 25 | - Add New Books. 26 | - View Books Available. 27 | - Remove Books. 28 | - Increase Books Amount. 29 | 30 | **Users Have Following Access for this online store site:-** 31 | - Create New Account or Register. 32 | - Login. 33 | - View Available Books. 34 | - Select Books to Buy. 35 | - Select Books Quantity. 36 | - Buy Books. 37 | - Get Payment Receipt. 38 | 39 | ### Technologies used:- 40 | 1. Front-End Development: 41 | - HTML 42 | - CSS 43 | - Javascript 44 | - BootStrap 45 | 46 | 2. Back-End Development: 47 | - Java [JDK 8+] 48 | - JDBC 49 | - Servlet 50 | 51 | 3. Database: 52 | - MySql 53 | 54 | ### ================ Software And Tools Required ================ 55 | - : Git [https://www.youtube.com/watch?v=gv7VPQ4LZ7g] 56 | - : Java JDK 8+ [https://www.youtube.com/watch?v=O9PWH9SeTTE] 57 | - : Eclipse EE (Enterprise Edition) [https://www.youtube.com/watch?v=8aDsEV7txXE] 58 | - : Apache Maven [https://www.youtube.com/watch?v=jd2zx3dLjuw] 59 | - : Tomcat v8.0+ [https://youtu.be/mLFPodZO8Iw?t=903] 60 | - : MySQL Server [https://www.youtube.com/watch?v=Ydh5jYA6Frs] 61 | - : MySQL Workbench (optional) [https://www.youtube.com/watch?v=t79oCeTXHwg] 62 | 63 | ### ================= Dummy Database Initialization ================= 64 | 65 | STEP 1: Open MySQL Command Prompt or MySQL Workbench 66 | 67 | STEP 2: Login to the administrator user as : ```mysql -u -p``` (Enter Password if asked) 68 | 69 | STEP 3: Copy paste the following MySql Commands- 70 | ```MySQL 71 | create database if not exists onlinebookstore; 72 | 73 | use onlinebookstore; 74 | 75 | create table if not exists books(barcode varchar(100) primary key, name varchar(100), author varchar(100), price int, quantity int); 76 | 77 | create table if not exists users(username varchar(100) primary key,password varchar(100), firstname varchar(100), 78 | lastname varchar(100),address text, phone varchar(100),mailid varchar(100),usertype int); 79 | 80 | insert into books values('9780134190563','The Go Programming Language','Alan A. A. Donovan and Brian W. Kernighan',400,8); 81 | insert into books values('9780133053036','C++ Primer','Stanley Lippman and Josée Lajoie and Barbara Moo',976,13); 82 | insert into books values('9781718500457','The Rust Programming Language','Steve Klabnik and Carol Nichols',560,12); 83 | insert into books values('9781491910740','Head First Java','Kathy Sierra and Bert Bates and Trisha Gee',754,23); 84 | insert into books values('9781492056300','Fluent Python','Luciano Ramalho',1014,5); 85 | insert into books values('9781720043997','The Road to Learn React','Robin Wieruch',239,18); 86 | insert into books values('9780132350884','Clean Code: A Handbook of Agile Software Craftsmanship','Robert C Martin',288,3); 87 | insert into books values('9780132181273','Domain-Driven Design','Eric Evans',560,28); 88 | insert into books values('9781951204006','A Programmers Guide to Computer Science','William Springer',188,4); 89 | insert into books values('9780316204552','The Soul of a New Machine','Tracy Kidder',293,30); 90 | insert into books values('9780132778046','Effective Java','Joshua Bloch',368,21); 91 | insert into books values('9781484255995','Practical Rust Projects','Shing Lyu',257,15); 92 | insert into users values('demo','demo','Demo','User','Demo Home','42502216225','demo@gmail.com',2); 93 | insert into users values('Admin','Admin','Mr.','Admin','Haldia WB','9584552224521','admin@gmail.com',1); 94 | insert into users values('shashi','shashi','Shashi','Raj','Bihar','1236547089','shashi@gmail.com',2); 95 | 96 | commit; 97 | 98 | ``` 99 | 100 | ### ========== Importing and Running The Project Through Eclipse EE ========== 101 | 102 | Step 0: Open Eclipse Enterprise Edition. [Install, if not already installed.] 103 | 104 | Step 1: Click On File > Import > Git > Projects From Git > Clone Uri > Paste The Repository Url as: ```https://github.com/shashirajraja/onlinebookstore.git```> Select master Branch > Next > Next > Finish. 105 | 106 | Step 2. a: Go inside ```src/main/resources > application.properties``` and update the value of database details as per your usage, like db.driver, db.host, db.username and db.password according to your installed mysql/postgresql admin user credentials. 107 | 108 | Step 2.b: Right Click on Project > Run as > Maven Build > In the goals field enter "clean install" > apply > run 109 | 110 | Step 2.c: Right Click On Project > Build Path > Configure Build Path > Libraries > Remove and Update Any Libraries if Red Mark Exists > Finish. 111 | 112 | Step 3: [Only If Tomcat Server is not configured in Eclipse] : Right Click On Project > Run As > Run On Server > Select Tomcat V8.0 > (Select Tomcat V8.0 Installation Location If Asked) Next > Add onlinebookstore > Finish. 113 | 114 | Step 4: In The Server Tab > Double Click On Tomcat Server > Ports > Change The Port Number For Http/1.1 To 8083 > Close And Save. 115 | 116 | Step 5: Right Click On Project > Run As > Run On Server > Select Tomcat v8.0 > Next > Add All> Done. 117 | 118 | Step 6: Check Running The Site At http://localhost:8083/onlinebookstore/ 119 | 120 | Step 7: Default Username And Password For Admin Is "Admin" And "Admin" 121 | 122 | Step 8: The default Username And Password For User Is "shashi" And "shashi" 123 | 124 | ## FAQ 125 | **Question:1** Unable to Connect to Database? 126 | 127 | **Answer:** Please check you have installed the mysql correctly and have updated the correct db details in application.properties file. Also you can try doing maven clean install and force update the project and restart. 128 |
129 | 130 | Note:- Considering this as a Sample Project, we have not much considered of web security. 131 | 132 | #### "Suggestions and project improvement ideas are welcomed!" 133 | 134 | Thanks a lot,
135 | Project Leader
136 | Roger Rodriguez 137 | -------------------------------------------------------------------------------- /WebContent/CustomerHome.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Book Store 5 | 7 | 9 | 11 | 12 | 14 | 15 | 16 | 18 | 22 | 26 | 29 | 30 | 31 |
32 | 63 |
64 | 65 | 66 | 67 | 69 | 71 | 74 | 75 | -------------------------------------------------------------------------------- /WebContent/CustomerLogin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Book Store 5 | 7 | 9 | 11 | 12 | 14 | 15 | 69 | 70 | 71 |
72 | 95 |
96 | 97 |
98 |

Welcome to Online Book Store

99 |
100 | 101 |
103 | 104 | 105 | 106 | 107 | 108 | 111 | 112 | 113 | 130 | 131 |
Customer LOGIN
Are you Seller?, Click 110 | Here to Login as Admin



118 |
119 | 120 |
121 |
46749
122 |
123 |
126 |
127 |

128 |
132 |
133 | 134 | 135 | 136 | 138 | 140 | 199 | 200 | 201 | -------------------------------------------------------------------------------- /WebContent/CustomerRegister.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Book Store 5 | 7 | 9 | 11 | 12 | 13 | 14 | 23 | 24 | 25 |
26 | 44 |
45 |
46 | 47 |
48 | 49 | 50 | 51 | 52 | 53 | 54 | 97 | 98 | 99 |
Enter the Registration Details
55 | 60 | 61 | 63 |
64 | 65 | 68 |
69 | 70 | 73 |
74 | 75 | 78 |
79 | 80 | 82 |
83 | 84 | 87 |
88 | 90 | 94 |
95 | 96 |
100 |
101 | 102 | 103 | 104 | 105 | 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /WebContent/Photo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonderdev007/online_book_store/67e274fedcf4e2973f9f6c9e2d3a7f208e2e480a/WebContent/Photo.jpg -------------------------------------------------------------------------------- /WebContent/SellerHome.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Book Store 5 | 7 | 9 | 11 | 12 | 14 | 15 | 16 | 18 | 22 | 26 | 29 | 30 | 31 |
32 | 66 |
67 | 68 | 69 | 70 | 72 | 74 | 77 | 78 | -------------------------------------------------------------------------------- /WebContent/SellerLogin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Book Store 5 | 7 | 9 | 11 | 12 | 13 | 14 | 39 | 40 | 41 |
42 | 60 |
61 | 62 |
63 |

Welcome to Online Book Store

64 |
65 | 66 |
67 | 68 | 69 | 70 | 71 | 72 | 73 | 86 | 87 |
Admin LOGIN
Not an Admin?, Click Here to Login as Customer
74 | 75 |
77 |
78 | 79 | 80 |

83 | 85 |
88 |
89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /WebContent/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | SellerLoginServlet 7 | servlets.SellerLoginServlet 8 | 9 | 10 | SellerLoginServlet 11 | /adminlog 12 | 13 | 14 | StoreBookServlet 15 | servlets.StoreBookServlet 16 | 17 | 18 | StoreBookServlet 19 | /storebooks 20 | 21 | 22 | UpdateBookServlet 23 | servlets.UpdateBookServlet 24 | 25 | 26 | UpdateBookServlet 27 | /updatebook 28 | 29 | 30 | CustomerLoginServlet 31 | servlets.CustomerLoginServlet 32 | 33 | 34 | CustomerLoginServlet 35 | /userlog 36 | 37 | 38 | AboutServlet 39 | servlets.AboutServlet 40 | 41 | 42 | AboutServlet 43 | /about 44 | 45 | 46 | LogoutServlet 47 | servlets.LogoutServlet 48 | 49 | 50 | LogoutServlet 51 | /logout 52 | 53 | 54 | CustomerRegisterServlet 55 | servlets.CustomerRegisterServlet 56 | 57 | 58 | CustomerRegisterServlet 59 | /userreg 60 | 61 | 62 | RemoveBookServlet 63 | servlets.RemoveBookServlet 64 | 65 | 66 | RemoveBookServlet 67 | /removebook 68 | 69 | 70 | AddBookServlet 71 | servlets.AddBookServlet 72 | 73 | 74 | AddBookServlet 75 | /addbook 76 | 77 | 78 | ViewBookServlet 79 | servlets.ViewBookServlet 80 | 81 | 82 | ViewBookServlet 83 | /viewbook 84 | 85 | 86 | CartServlet 87 | servlets.CartServlet 88 | 89 | 90 | CartServlet 91 | /cart 92 | 93 | 94 | BuyBooksServlet 95 | servlets.BuyBooksServlet 96 | 97 | 98 | BuyBooksServlet 99 | /buybook 100 | 101 | 102 | ReceiptServlet 103 | servlets.ReceiptServlet 104 | 105 | 106 | ReceiptServlet 107 | /buys 108 | 109 | 110 | CheckoutServlet 111 | servlets.CheckoutServlet 112 | 113 | 114 | CheckoutServlet 115 | /checkout 116 | 117 | 118 | ProcessPaymentServlet 119 | servlets.ProcessPaymentServlet 120 | 121 | 122 | ProcessPaymentServlet 123 | /pay 124 | 125 | 126 | 127 | 128 | ErrorHandlerServlet 129 | servlets.ErrorHandlerServlet 130 | 131 | 132 | ErrorHandlerServlet 133 | /error 134 | 135 | 136 | 137 | 404 138 | /error 139 | 140 | 141 | 405 142 | /error 143 | 144 | 145 | 146 | 147 | 148 | javax.servlet.ServletException 149 | 150 | /error 151 | 152 | 153 | 154 | java.lang.Throwable 155 | /error 156 | 157 | 158 | 159 | 160 | index.html 161 | 162 | -------------------------------------------------------------------------------- /WebContent/favicons/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonderdev007/online_book_store/67e274fedcf4e2973f9f6c9e2d3a7f208e2e480a/WebContent/favicons/android-chrome-192x192.png -------------------------------------------------------------------------------- /WebContent/favicons/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonderdev007/online_book_store/67e274fedcf4e2973f9f6c9e2d3a7f208e2e480a/WebContent/favicons/android-chrome-512x512.png -------------------------------------------------------------------------------- /WebContent/favicons/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonderdev007/online_book_store/67e274fedcf4e2973f9f6c9e2d3a7f208e2e480a/WebContent/favicons/apple-touch-icon.png -------------------------------------------------------------------------------- /WebContent/favicons/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonderdev007/online_book_store/67e274fedcf4e2973f9f6c9e2d3a7f208e2e480a/WebContent/favicons/favicon-16x16.png -------------------------------------------------------------------------------- /WebContent/favicons/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonderdev007/online_book_store/67e274fedcf4e2973f9f6c9e2d3a7f208e2e480a/WebContent/favicons/favicon-32x32.png -------------------------------------------------------------------------------- /WebContent/favicons/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonderdev007/online_book_store/67e274fedcf4e2973f9f6c9e2d3a7f208e2e480a/WebContent/favicons/favicon.ico -------------------------------------------------------------------------------- /WebContent/favicons/site.webmanifest: -------------------------------------------------------------------------------- 1 | {"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} -------------------------------------------------------------------------------- /WebContent/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Book Store 5 | 7 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 36 |
37 |
38 |

Welcome to Online
Book Store

39 |
40 | 41 | 42 | 43 | 44 |
Happy Learning!!
Welcome to our book store!
45 | 46 | 47 | 48 | 49 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /WebContent/loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonderdev007/online_book_store/67e274fedcf4e2973f9f6c9e2d3a7f208e2e480a/WebContent/loader.gif -------------------------------------------------------------------------------- /WebContent/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Book Store 5 | 7 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 36 |
37 |

Welcome to Online Book Store

38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
Login or SignUp Below
Login As Admin
Login As Customer
New user ! Register Here
54 | 55 | 56 | 57 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /WebContent/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonderdev007/online_book_store/67e274fedcf4e2973f9f6c9e2d3a7f208e2e480a/WebContent/logo.png -------------------------------------------------------------------------------- /WebContent/payment.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Book Store 5 | 7 | 9 | 11 | 12 | 14 | 15 | 16 | 18 | 22 | 23 | 27 | 28 | 113 | 114 | 115 |
116 | 143 |
144 | 145 | 147 | 149 |
150 |
Cart Checkout
151 |
152 |
153 |
154 |
155 |
156 |
157 |

Billing Address

158 | 159 | 164 | 168 | 169 |
170 |
171 | 173 |
174 |
175 | 177 |
178 |
179 |
180 | 181 |
182 |

Payment

183 | 184 |
185 | 189 |
190 | 192 | 197 | 198 |
199 |
200 | 202 |
203 |
204 | 206 |
207 |
208 |
209 | 210 |
211 | 214 | 215 | 216 | -------------------------------------------------------------------------------- /WebContent/styles.css: -------------------------------------------------------------------------------- 1 | * { 2 | box-sizing: border-box; 3 | } 4 | 5 | body { 6 | background-image: url("Photo.jpg"); 7 | font-family: 'Segoe UI','Open Sans', 'Helvetica Neue', sans-serif; 8 | } 9 | 10 | #topmid { 11 | border: 0px solid black; 12 | color: #FFFFFF; 13 | text-align: center; 14 | font-weight: bold; 15 | margin: auto; 16 | font-style: oblique; 17 | font-size: 25px; 18 | text-shadow: 2px 2px #ff0000; 19 | } 20 | 21 | .tab { 22 | font-weight: bold; 23 | margin: auto; 24 | width:35%; 25 | text-align:center; 26 | } 27 | 28 | .tab tr { 29 | border: 1px black hidden; 30 | border-radius: 10px; 31 | background-color: #FFE5CC; 32 | font-size: 22px; 33 | float:left; 34 | padding-left:17%; 35 | padding-bottom:5px; 36 | padding-top:2px; 37 | margin-bottom:10px; 38 | width:100%; 39 | } 40 | 41 | a:hover { 42 | color: red; 43 | } 44 | 45 | a:link { 46 | color: black; 47 | text-decoration: none; 48 | } 49 | 50 | header nav li :hover{ 51 | border-bottom: 2px #ffff80 solid; 52 | border-radius: 10px; 53 | color: #ffff80; 54 | padding-bottom:2px; 55 | } 56 | 57 | header nav li{ 58 | display: table; 59 | height: 80%; 60 | float: left; 61 | margin-right: 20px; 62 | padding-left: 10px; 63 | 64 | } 65 | 66 | header nav a{ 67 | color: #ffffff; 68 | } 69 | 70 | header nav li a.active { 71 | border-bottom: 2px #ffff80 solid; 72 | border-radius: 10px; 73 | color: #ffff80; 74 | padding-bottom:2px; 75 | } 76 | 77 | 78 | .holds-the-iframe { 79 | background: url(loader.gif) center center no-repeat; 80 | } -------------------------------------------------------------------------------- /appspec.yaml: -------------------------------------------------------------------------------- 1 | version: 0.0 2 | os: linux 3 | files: 4 | - source: /output/books.war 5 | destination: /opt/tomcat8/webapps 6 | hooks: 7 | BeforeInstall: 8 | - location: scripts/start_server.sh 9 | timeout: 300 10 | runas: root 11 | ApplicationStop: 12 | - location: scripts/stop_server.sh 13 | timeout: 300 14 | runas: root 15 | -------------------------------------------------------------------------------- /buildspec.yaml: -------------------------------------------------------------------------------- 1 | version: 0.2 2 | 3 | phases: 4 | install: 5 | runtime-versions: 6 | java: corretto8 7 | commands: 8 | - apt update -y 9 | build: 10 | commands: 11 | - mvn clean package 12 | - mkdir output 13 | - cp target/*.war output/books.war 14 | artifacts: 15 | files: 16 | - 'output/*.war' 17 | - appspec.yaml 18 | - scripts/* 19 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | onlinebookstore 6 | onlinebookstore 7 | 0.0.1-SNAPSHOT 8 | war 9 | 10 | src/main/java 11 | onlinebookstore 12 | 13 | 14 | org.apache.maven.plugins 15 | maven-dependency-plugin 16 | 2.3 17 | 18 | 19 | package 20 | 21 | copy 22 | 23 | 24 | 25 | 26 | com.github.jsimone 27 | webapp-runner 28 | 8.0.30.2 29 | webapp-runner.jar 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | maven-compiler-plugin 38 | 3.11.0 39 | 40 | 1.8 41 | 1.8 42 | 43 | 44 | 45 | maven-war-plugin 46 | 3.2.1 47 | 48 | WebContent 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.postgresql 57 | postgresql 58 | 42.3.7 59 | 60 | 61 | 62 | 63 | mysql 64 | mysql-connector-java 65 | 8.0.28 66 | 67 | 68 | 69 | 70 | javax.servlet 71 | javax.servlet-api 72 | 3.1.0 73 | 74 | 75 | -------------------------------------------------------------------------------- /scripts/start_server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd /opt/tomcat8/bin 3 | ./startup.sh 4 | -------------------------------------------------------------------------------- /scripts/stop_server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd /opt/tomcat8/bin 3 | ./shutdown.sh 4 | -------------------------------------------------------------------------------- /setup/CreateDatastore.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE if not exists onlinebookstore; 2 | 3 | \c onlinebookstore 4 | 5 | CREATE TABLE if not exists books 6 | ( 7 | barcode VARCHAR(100) PRIMARY KEY, 8 | name TEXT NOT NULL, 9 | author VARCHAR(100) NOT NULL, 10 | price INT, 11 | quantity REAL 12 | ); 13 | 14 | CREATE TABLE if not exists users 15 | ( 16 | username VARCHAR(100) PRIMARY KEY, 17 | password VARCHAR(100) NOT NULL, 18 | firstname VARCHAR(100) NOT NULL, 19 | lastname VARCHAR(100) NOT NULL, 20 | address TEXT NOT NULL, 21 | phone VARCHAR(100) NOT NULL, 22 | mailid VARCHAR(100) NOT NULL, 23 | usertype INT 24 | ); -------------------------------------------------------------------------------- /src/main/java/com/bittercode/constant/BookStoreConstants.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.constant; 2 | 3 | public interface BookStoreConstants { 4 | public static String CONTENT_TYPE_TEXT_HTML = "text/html"; 5 | 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/constant/ResponseCode.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.constant; 2 | 3 | import java.util.Arrays; 4 | import java.util.Optional; 5 | 6 | public enum ResponseCode { 7 | 8 | SUCCESS(200, "OK"), 9 | FAILURE(422, "Unprocessible Entity, Failed to Process"), 10 | PAGE_NOT_FOUND(404, "The Page You are Searching For is Not available"), 11 | ACCESS_DENIED(403, "Please Login First to continue"), 12 | BAD_REQUEST(400, "Bad Request, Please Try Again"), 13 | INTERNAL_SERVER_ERROR(500, "Internal Server Error, Try Again!!"), 14 | DATABASE_CONNECTION_FAILURE(406, 15 | "Unable to Connect to DB, Please Check your db credentials in application.properties"), 16 | METHOD_NOT_ALLOWED(405, "Requested HTTP method is not supported by this URL"), 17 | 18 | ; 19 | 20 | private final String message; 21 | private final int code; 22 | 23 | ResponseCode(int code, String message) { 24 | this.message = message; 25 | this.code = code; 26 | } 27 | 28 | public String getMessage() { 29 | return message; 30 | } 31 | 32 | public int getCode() { 33 | return code; 34 | } 35 | 36 | // Reverse lookup methods 37 | public static Optional getMessageByStatusCode(int statusCode) { 38 | return Arrays.stream(ResponseCode.values()) 39 | .filter(error -> error.getCode() == statusCode) 40 | .findFirst(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/constant/db/BooksDBConstants.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.constant.db; 2 | 3 | public interface BooksDBConstants { 4 | 5 | public static String TABLE_BOOK = "books"; 6 | 7 | public static String COLUMN_NAME = "name"; 8 | public static String COLUMN_BARCODE = "barcode"; 9 | public static String COLUMN_AUTHOR = "author"; 10 | public static String COLUMN_PRICE = "price"; 11 | public static String COLUMN_QUANTITY = "quantity"; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/constant/db/UsersDBConstants.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.constant.db; 2 | 3 | public interface UsersDBConstants { 4 | 5 | public static String TABLE_USERS = "users"; 6 | 7 | public static String COLUMN_USERNAME = "username"; 8 | public static String COLUMN_PASSWORD = "password"; 9 | public static String COLUMN_FIRSTNAME = "firstname"; 10 | public static String COLUMN_LASTNAME = "lastname"; 11 | public static String COLUMN_ADDRESS = "address"; 12 | public static String COLUMN_PHONE = "phone"; 13 | public static String COLUMN_MAILID = "mailid"; 14 | public static String COLUMN_USERTYPE = "usertype"; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/model/Address.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.model; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Address implements Serializable { 6 | 7 | private String addressLine1; 8 | private String addressLine2; 9 | private String city; 10 | private String state; 11 | private String country; 12 | private long pinCode; 13 | private String phone; 14 | 15 | public String getAddressLine1() { 16 | return addressLine1; 17 | } 18 | 19 | public void setAddressLine1(String addressLine1) { 20 | this.addressLine1 = addressLine1; 21 | } 22 | 23 | public String getAddressLine2() { 24 | return addressLine2; 25 | } 26 | 27 | public void setAddressLine2(String addressLine2) { 28 | this.addressLine2 = addressLine2; 29 | } 30 | 31 | public String getCity() { 32 | return city; 33 | } 34 | 35 | public void setCity(String city) { 36 | this.city = city; 37 | } 38 | 39 | public String getState() { 40 | return state; 41 | } 42 | 43 | public void setState(String state) { 44 | this.state = state; 45 | } 46 | 47 | public String getCountry() { 48 | return country; 49 | } 50 | 51 | public void setCountry(String country) { 52 | this.country = country; 53 | } 54 | 55 | public long getPinCode() { 56 | return pinCode; 57 | } 58 | 59 | public void setPinCode(long pinCode) { 60 | this.pinCode = pinCode; 61 | } 62 | 63 | public String getPhone() { 64 | return phone; 65 | } 66 | 67 | public void setPhone(String phone) { 68 | this.phone = phone; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/model/Book.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.model; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Book implements Serializable { 6 | 7 | private String barcode; 8 | private String name; 9 | private String author; 10 | private double price; 11 | private int quantity; 12 | 13 | public Book(String barcode, String name, String author, double price, int quantity) { 14 | this.barcode = barcode; 15 | this.name = name; 16 | this.author = author; 17 | this.setPrice(price); 18 | this.quantity = quantity; 19 | } 20 | 21 | public Book() { 22 | super(); 23 | } 24 | 25 | public String getBarcode() { 26 | return barcode; 27 | } 28 | 29 | public void setBarcode(String barcode) { 30 | this.barcode = barcode; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | public String getAuthor() { 42 | return author; 43 | } 44 | 45 | public void setAuthor(String author) { 46 | this.author = author; 47 | } 48 | 49 | public int getQuantity() { 50 | return quantity; 51 | } 52 | 53 | public void setQuantity(int quantity) { 54 | this.quantity = quantity; 55 | } 56 | 57 | public double getPrice() { 58 | return price; 59 | } 60 | 61 | public void setPrice(double price) { 62 | this.price = price; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/model/Cart.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.model; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Cart implements Serializable { 6 | 7 | private Book book; 8 | private int quantity; 9 | 10 | public Cart(Book book, int quantity) { 11 | this.book = book; 12 | this.quantity = quantity; 13 | } 14 | 15 | public Book getBook() { 16 | return book; 17 | } 18 | 19 | public void setBook(Book book) { 20 | this.book = book; 21 | } 22 | 23 | public int getQuantity() { 24 | return quantity; 25 | } 26 | 27 | public void setQuantity(int quantity) { 28 | this.quantity = quantity; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/model/StoreException.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.model; 2 | 3 | import java.io.IOException; 4 | 5 | import com.bittercode.constant.ResponseCode; 6 | 7 | public class StoreException extends IOException { 8 | 9 | private String errorCode; 10 | private String errorMessage; 11 | private int statusCode; 12 | 13 | public StoreException(String errorMessage) { 14 | super(errorMessage); 15 | this.errorCode = "BAD_REQUEST"; 16 | this.setStatusCode(400); 17 | this.errorMessage = errorMessage; 18 | } 19 | 20 | public StoreException(ResponseCode errorCodes) { 21 | super(errorCodes.getMessage()); 22 | this.statusCode = errorCodes.getCode(); 23 | this.errorMessage = errorCodes.getMessage(); 24 | this.setErrorCode(errorCodes.name()); 25 | } 26 | 27 | public StoreException(String errroCode, String errorMessage) { 28 | super(errorMessage); 29 | this.errorCode = errroCode; 30 | this.errorMessage = errorMessage; 31 | this.statusCode = 422; 32 | } 33 | 34 | public StoreException(int statusCode, String errorCode, String errorMessage) { 35 | super(errorMessage); 36 | this.statusCode = statusCode; 37 | this.errorCode = errorCode; 38 | this.errorMessage = errorMessage; 39 | } 40 | 41 | public String getErrorCode() { 42 | return errorCode; 43 | } 44 | 45 | public void setErrorCode(String errorCode) { 46 | this.errorCode = errorCode; 47 | } 48 | 49 | public String getErrorMessage() { 50 | return errorMessage; 51 | } 52 | 53 | public void setErrorMessage(String errorMessage) { 54 | this.errorMessage = errorMessage; 55 | } 56 | 57 | public int getStatusCode() { 58 | return statusCode; 59 | } 60 | 61 | public void setStatusCode(int statusCode) { 62 | this.statusCode = statusCode; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/model/User.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | public class User implements Serializable { 7 | 8 | private String emailId; 9 | private String password; 10 | private String firstName; 11 | private String lastName; 12 | private Long phone; 13 | private String address; 14 | private List roles; 15 | 16 | public String getEmailId() { 17 | return emailId; 18 | } 19 | 20 | public void setEmailId(String emailId) { 21 | this.emailId = emailId; 22 | } 23 | 24 | public String getPassword() { 25 | return password; 26 | } 27 | 28 | public void setPassword(String password) { 29 | this.password = password; 30 | } 31 | 32 | public String getFirstName() { 33 | return firstName; 34 | } 35 | 36 | public void setFirstName(String firstName) { 37 | this.firstName = firstName; 38 | } 39 | 40 | public String getLastName() { 41 | return lastName; 42 | } 43 | 44 | public void setLastName(String lastName) { 45 | this.lastName = lastName; 46 | } 47 | 48 | public Long getPhone() { 49 | return phone; 50 | } 51 | 52 | public void setPhone(Long phone) { 53 | this.phone = phone; 54 | } 55 | 56 | public String getAddress() { 57 | return address; 58 | } 59 | 60 | public void setAddress(String address) { 61 | this.address = address; 62 | } 63 | 64 | public List getRoles() { 65 | return roles; 66 | } 67 | 68 | public void setRoles(List roles) { 69 | this.roles = roles; 70 | } 71 | 72 | // public static User retrieveFromHttpServletRequest(HttpServletRequest req) { 73 | // User user = new User(); 74 | // String pWord = req.getParameter(UsersDBConstants.COLUMN_PASSWORD); 75 | // String fName = req.getParameter(UsersDBConstants.COLUMN_FIRSTNAME); 76 | // String lName = req.getParameter(UsersDBConstants.COLUMN_LASTNAME); 77 | // String addr = req.getParameter(UsersDBConstants.COLUMN_ADDRESS); 78 | // String phNo = req.getParameter(UsersDBConstants.COLUMN_PHONE); 79 | // String mailId = req.getParameter(UsersDBConstants.COLUMN_MAILID); 80 | // user.setEmailId(mailId); 81 | // user.setFirstName(fName); 82 | // user.setLastName(lName); 83 | // user.setPassword(pWord); 84 | // user.setPhone(Long.parseLong(phNo)); 85 | // user.setAddress(addr); 86 | // return user; 87 | // } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/model/UserRole.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.model; 2 | 3 | public enum UserRole { 4 | CUSTOMER, SELLER 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/model/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | /** 5 | * @author shashirajraja 6 | * 7 | */ 8 | package com.bittercode.model; -------------------------------------------------------------------------------- /src/main/java/com/bittercode/service/BookService.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.service; 2 | 3 | import java.util.List; 4 | 5 | import com.bittercode.model.Book; 6 | import com.bittercode.model.StoreException; 7 | 8 | public interface BookService { 9 | 10 | public Book getBookById(String bookId) throws StoreException; 11 | 12 | public List getAllBooks() throws StoreException; 13 | 14 | public List getBooksByCommaSeperatedBookIds(String commaSeperatedBookIds) throws StoreException; 15 | 16 | public String deleteBookById(String bookId) throws StoreException; 17 | 18 | public String addBook(Book book) throws StoreException; 19 | 20 | public String updateBookQtyById(String bookId, int quantity) throws StoreException; 21 | 22 | public String updateBook(Book book) throws StoreException; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.service; 2 | 3 | import javax.servlet.http.HttpSession; 4 | 5 | import com.bittercode.model.StoreException; 6 | import com.bittercode.model.User; 7 | import com.bittercode.model.UserRole; 8 | 9 | public interface UserService { 10 | 11 | public User login(UserRole role, String email, String password, HttpSession session) throws StoreException; 12 | 13 | public String register(UserRole role, User user) throws StoreException; 14 | 15 | public boolean isLoggedIn(UserRole role, HttpSession session); 16 | 17 | public boolean logout(HttpSession session); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/service/impl/BookServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.service.impl; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | import com.bittercode.constant.ResponseCode; 11 | import com.bittercode.constant.db.BooksDBConstants; 12 | import com.bittercode.model.Book; 13 | import com.bittercode.model.StoreException; 14 | import com.bittercode.service.BookService; 15 | import com.bittercode.util.DBUtil; 16 | 17 | public class BookServiceImpl implements BookService { 18 | 19 | private static final String getAllBooksQuery = "SELECT * FROM " + BooksDBConstants.TABLE_BOOK; 20 | private static final String getBookByIdQuery = "SELECT * FROM " + BooksDBConstants.TABLE_BOOK 21 | + " WHERE " + BooksDBConstants.COLUMN_BARCODE + " = ?"; 22 | 23 | private static final String deleteBookByIdQuery = "DELETE FROM " + BooksDBConstants.TABLE_BOOK + " WHERE " 24 | + BooksDBConstants.COLUMN_BARCODE + "=?"; 25 | 26 | private static final String addBookQuery = "INSERT INTO " + BooksDBConstants.TABLE_BOOK + " VALUES(?,?,?,?,?)"; 27 | 28 | private static final String updateBookQtyByIdQuery = "UPDATE " + BooksDBConstants.TABLE_BOOK + " SET " 29 | + BooksDBConstants.COLUMN_QUANTITY + "=? WHERE " + BooksDBConstants.COLUMN_BARCODE 30 | + "=?"; 31 | 32 | private static final String updateBookByIdQuery = "UPDATE " + BooksDBConstants.TABLE_BOOK + " SET " 33 | + BooksDBConstants.COLUMN_NAME + "=? , " 34 | + BooksDBConstants.COLUMN_AUTHOR + "=?, " 35 | + BooksDBConstants.COLUMN_PRICE + "=?, " 36 | + BooksDBConstants.COLUMN_QUANTITY + "=? " 37 | + " WHERE " + BooksDBConstants.COLUMN_BARCODE 38 | + "=?"; 39 | 40 | @Override 41 | public Book getBookById(String bookId) throws StoreException { 42 | Book book = null; 43 | Connection con = DBUtil.getConnection(); 44 | try { 45 | PreparedStatement ps = con.prepareStatement(getBookByIdQuery); 46 | ps.setString(1, bookId); 47 | ResultSet rs = ps.executeQuery(); 48 | 49 | while (rs.next()) { 50 | String bCode = rs.getString(1); 51 | String bName = rs.getString(2); 52 | String bAuthor = rs.getString(3); 53 | int bPrice = rs.getInt(4); 54 | int bQty = rs.getInt(5); 55 | 56 | book = new Book(bCode, bName, bAuthor, bPrice, bQty); 57 | } 58 | } catch (SQLException e) { 59 | 60 | } 61 | return book; 62 | } 63 | 64 | @Override 65 | public List getAllBooks() throws StoreException { 66 | List books = new ArrayList(); 67 | Connection con = DBUtil.getConnection(); 68 | 69 | try { 70 | PreparedStatement ps = con.prepareStatement(getAllBooksQuery); 71 | ResultSet rs = ps.executeQuery(); 72 | 73 | while (rs.next()) { 74 | String bCode = rs.getString(1); 75 | String bName = rs.getString(2); 76 | String bAuthor = rs.getString(3); 77 | int bPrice = rs.getInt(4); 78 | int bQty = rs.getInt(5); 79 | 80 | Book book = new Book(bCode, bName, bAuthor, bPrice, bQty); 81 | books.add(book); 82 | } 83 | } catch (SQLException e) { 84 | 85 | } 86 | return books; 87 | } 88 | 89 | @Override 90 | public String deleteBookById(String bookId) throws StoreException { 91 | String response = ResponseCode.FAILURE.name(); 92 | Connection con = DBUtil.getConnection(); 93 | try { 94 | PreparedStatement ps = con.prepareStatement(deleteBookByIdQuery); 95 | ps.setString(1, bookId); 96 | int k = ps.executeUpdate(); 97 | if (k == 1) { 98 | response = ResponseCode.SUCCESS.name(); 99 | } 100 | } catch (Exception e) { 101 | response += " : " + e.getMessage(); 102 | e.printStackTrace(); 103 | } 104 | return response; 105 | } 106 | 107 | @Override 108 | public String addBook(Book book) throws StoreException { 109 | String responseCode = ResponseCode.FAILURE.name(); 110 | Connection con = DBUtil.getConnection(); 111 | try { 112 | PreparedStatement ps = con.prepareStatement(addBookQuery); 113 | ps.setString(1, book.getBarcode()); 114 | ps.setString(2, book.getName()); 115 | ps.setString(3, book.getAuthor()); 116 | ps.setDouble(4, book.getPrice()); 117 | ps.setInt(5, book.getQuantity()); 118 | int k = ps.executeUpdate(); 119 | if (k == 1) { 120 | responseCode = ResponseCode.SUCCESS.name(); 121 | } 122 | } catch (Exception e) { 123 | responseCode += " : " + e.getMessage(); 124 | e.printStackTrace(); 125 | } 126 | return responseCode; 127 | } 128 | 129 | @Override 130 | public String updateBookQtyById(String bookId, int quantity) throws StoreException { 131 | String responseCode = ResponseCode.FAILURE.name(); 132 | Connection con = DBUtil.getConnection(); 133 | try { 134 | PreparedStatement ps = con.prepareStatement(updateBookQtyByIdQuery); 135 | ps.setInt(1, quantity); 136 | ps.setString(2, bookId); 137 | ps.executeUpdate(); 138 | responseCode = ResponseCode.SUCCESS.name(); 139 | } catch (Exception e) { 140 | responseCode += " : " + e.getMessage(); 141 | e.printStackTrace(); 142 | } 143 | return responseCode; 144 | } 145 | 146 | @Override 147 | public List getBooksByCommaSeperatedBookIds(String commaSeperatedBookIds) throws StoreException { 148 | List books = new ArrayList(); 149 | Connection con = DBUtil.getConnection(); 150 | try { 151 | String getBooksByCommaSeperatedBookIdsQuery = "SELECT * FROM " + BooksDBConstants.TABLE_BOOK 152 | + " WHERE " + 153 | BooksDBConstants.COLUMN_BARCODE + " IN ( " + commaSeperatedBookIds + " )"; 154 | PreparedStatement ps = con.prepareStatement(getBooksByCommaSeperatedBookIdsQuery); 155 | ResultSet rs = ps.executeQuery(); 156 | 157 | while (rs.next()) { 158 | String bCode = rs.getString(1); 159 | String bName = rs.getString(2); 160 | String bAuthor = rs.getString(3); 161 | int bPrice = rs.getInt(4); 162 | int bQty = rs.getInt(5); 163 | 164 | Book book = new Book(bCode, bName, bAuthor, bPrice, bQty); 165 | books.add(book); 166 | } 167 | } catch (SQLException e) { 168 | 169 | } 170 | return books; 171 | } 172 | 173 | @Override 174 | public String updateBook(Book book) throws StoreException { 175 | String responseCode = ResponseCode.FAILURE.name(); 176 | Connection con = DBUtil.getConnection(); 177 | try { 178 | PreparedStatement ps = con.prepareStatement(updateBookByIdQuery); 179 | ps.setString(1, book.getName()); 180 | ps.setString(2, book.getAuthor()); 181 | ps.setDouble(3, book.getPrice()); 182 | ps.setInt(4, book.getQuantity()); 183 | ps.setString(5, book.getBarcode()); 184 | ps.executeUpdate(); 185 | responseCode = ResponseCode.SUCCESS.name(); 186 | } catch (Exception e) { 187 | responseCode += " : " + e.getMessage(); 188 | e.printStackTrace(); 189 | } 190 | return responseCode; 191 | } 192 | 193 | } 194 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.service.impl; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | 8 | import javax.servlet.http.HttpSession; 9 | 10 | import com.bittercode.constant.ResponseCode; 11 | import com.bittercode.constant.db.UsersDBConstants; 12 | import com.bittercode.model.StoreException; 13 | import com.bittercode.model.User; 14 | import com.bittercode.model.UserRole; 15 | import com.bittercode.service.UserService; 16 | import com.bittercode.util.DBUtil; 17 | 18 | public class UserServiceImpl implements UserService { 19 | 20 | private static final String registerUserQuery = "INSERT INTO " + UsersDBConstants.TABLE_USERS 21 | + " VALUES(?,?,?,?,?,?,?,?)"; 22 | 23 | private static final String loginUserQuery = "SELECT * FROM " + UsersDBConstants.TABLE_USERS + " WHERE " 24 | + UsersDBConstants.COLUMN_USERNAME + "=? AND " + UsersDBConstants.COLUMN_PASSWORD + "=? AND " 25 | + UsersDBConstants.COLUMN_USERTYPE + "=?"; 26 | 27 | @Override 28 | public User login(UserRole role, String email, String password, HttpSession session) throws StoreException { 29 | Connection con = DBUtil.getConnection(); 30 | PreparedStatement ps; 31 | User user = null; 32 | try { 33 | String userType = UserRole.SELLER.equals(role) ? "1" : "2"; 34 | ps = con.prepareStatement(loginUserQuery); 35 | ps.setString(1, email); 36 | ps.setString(2, password); 37 | ps.setString(3, userType); 38 | ResultSet rs = ps.executeQuery(); 39 | if (rs.next()) { 40 | user = new User(); 41 | user.setFirstName(rs.getString("firstName")); 42 | user.setLastName(rs.getString("lastName")); 43 | user.setPhone(rs.getLong("phone")); 44 | user.setEmailId(email); 45 | user.setPassword(password); 46 | session.setAttribute(role.toString(), user.getEmailId()); 47 | } 48 | } catch (SQLException e) { 49 | e.printStackTrace(); 50 | } 51 | return user; 52 | } 53 | 54 | @Override 55 | public boolean isLoggedIn(UserRole role, HttpSession session) { 56 | if (role == null) 57 | role = UserRole.CUSTOMER; 58 | return session.getAttribute(role.toString()) != null; 59 | } 60 | 61 | @Override 62 | public boolean logout(HttpSession session) { 63 | session.removeAttribute(UserRole.CUSTOMER.toString()); 64 | session.removeAttribute(UserRole.SELLER.toString()); 65 | session.invalidate(); 66 | return true; 67 | } 68 | 69 | @Override 70 | public String register(UserRole role, User user) throws StoreException { 71 | String responseMessage = ResponseCode.FAILURE.name(); 72 | Connection con = DBUtil.getConnection(); 73 | try { 74 | PreparedStatement ps = con.prepareStatement(registerUserQuery); 75 | ps.setString(1, user.getEmailId()); 76 | ps.setString(2, user.getPassword()); 77 | ps.setString(3, user.getFirstName()); 78 | ps.setString(4, user.getLastName()); 79 | ps.setString(5, user.getAddress()); 80 | ps.setLong(6, user.getPhone()); 81 | ps.setString(7, user.getEmailId()); 82 | int userType = UserRole.SELLER.equals(role) ? 1 : 2; 83 | ps.setInt(8, userType); 84 | int k = ps.executeUpdate(); 85 | if (k == 1) { 86 | responseMessage = ResponseCode.SUCCESS.name(); 87 | ; 88 | } 89 | } catch (Exception e) { 90 | responseMessage += " : " + e.getMessage(); 91 | if (responseMessage.contains("Duplicate")) 92 | responseMessage = "User already registered with this email !!"; 93 | e.printStackTrace(); 94 | } 95 | return responseMessage; 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/util/DBUtil.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.util; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.SQLException; 6 | 7 | import com.bittercode.constant.ResponseCode; 8 | import com.bittercode.model.StoreException; 9 | 10 | public class DBUtil { 11 | 12 | private static Connection connection; 13 | 14 | static { 15 | 16 | try { 17 | 18 | Class.forName(DatabaseConfig.DRIVER_NAME); 19 | 20 | connection = DriverManager.getConnection(DatabaseConfig.CONNECTION_STRING, DatabaseConfig.DB_USER_NAME, 21 | DatabaseConfig.DB_PASSWORD); 22 | } catch (SQLException | ClassNotFoundException e) { 23 | 24 | e.printStackTrace(); 25 | 26 | } 27 | 28 | }// End of static block 29 | 30 | public static Connection getConnection() throws StoreException { 31 | 32 | if (connection == null) { 33 | throw new StoreException(ResponseCode.DATABASE_CONNECTION_FAILURE); 34 | } 35 | 36 | return connection; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/util/DatabaseConfig.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.util; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.util.Properties; 6 | 7 | class DatabaseConfig { 8 | 9 | static Properties prop = new Properties(); 10 | static { 11 | 12 | ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 13 | InputStream input = classLoader.getResourceAsStream("application.properties"); 14 | 15 | try { 16 | prop.load(input); 17 | } catch (IOException e) { 18 | e.printStackTrace(); 19 | } 20 | } 21 | 22 | public final static String DRIVER_NAME = prop.getProperty("db.driver"); 23 | public final static String DB_HOST = prop.getProperty("db.host"); 24 | public final static String DB_PORT = prop.getProperty("db.port"); 25 | public final static String DB_NAME = prop.getProperty("db.name"); 26 | public final static String DB_USER_NAME = prop.getProperty("db.username"); 27 | public final static String DB_PASSWORD = prop.getProperty("db.password"); 28 | public final static String CONNECTION_STRING = DB_HOST + ":" + DB_PORT + "/" + DB_NAME; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/bittercode/util/StoreUtil.java: -------------------------------------------------------------------------------- 1 | package com.bittercode.util; 2 | 3 | import java.io.PrintWriter; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpSession; 7 | 8 | import com.bittercode.model.UserRole; 9 | 10 | /* 11 | * Store UTil File To Store Commonly used methods 12 | */ 13 | public class StoreUtil { 14 | 15 | /** 16 | * Check if the User is logged in with the requested role 17 | */ 18 | public static boolean isLoggedIn(UserRole role, HttpSession session) { 19 | 20 | return session.getAttribute(role.toString()) != null; 21 | } 22 | 23 | /** 24 | * Modify the active tab in the page menu bar 25 | */ 26 | public static void setActiveTab(PrintWriter pw, String activeTab) { 27 | 28 | pw.println(""); 30 | pw.println(""); 31 | 32 | } 33 | 34 | /** 35 | * Add/Remove/Update Item in the cart using the session 36 | */ 37 | public static void updateCartItems(HttpServletRequest req) { 38 | String selectedBookId = req.getParameter("selectedBookId"); 39 | HttpSession session = req.getSession(); 40 | if (selectedBookId != null) { // add item to the cart 41 | 42 | // Items will contain comma separated bookIds that needs to be added in the cart 43 | String items = (String) session.getAttribute("items"); 44 | if (req.getParameter("addToCart") != null) { // add to cart 45 | if (items == null || items.length() == 0) 46 | items = selectedBookId; 47 | else if (!items.contains(selectedBookId)) 48 | items = items + "," + selectedBookId; // if items already contains bookId, don't add it 49 | 50 | // set the items in the session to be used later 51 | session.setAttribute("items", items); 52 | 53 | /* 54 | * Quantity of each item in the cart will be stored in the session as: 55 | * Prefixed with qty_ following its bookId 56 | * For example 2 no. of book with id 'myBook' in the cart will be 57 | * added to the session as qty_myBook=2 58 | */ 59 | int itemQty = 0; 60 | if (session.getAttribute("qty_" + selectedBookId) != null) 61 | itemQty = (int) session.getAttribute("qty_" + selectedBookId); 62 | itemQty += 1; 63 | session.setAttribute("qty_" + selectedBookId, itemQty); 64 | } else { // remove from the cart 65 | int itemQty = 0; 66 | if (session.getAttribute("qty_" + selectedBookId) != null) 67 | itemQty = (int) session.getAttribute("qty_" + selectedBookId); 68 | if (itemQty > 1) { 69 | itemQty--; 70 | session.setAttribute("qty_" + selectedBookId, itemQty); 71 | } else { 72 | session.removeAttribute("qty_" + selectedBookId); 73 | items = items.replace(selectedBookId + ",", ""); 74 | items = items.replace("," + selectedBookId, ""); 75 | items = items.replace(selectedBookId, ""); 76 | session.setAttribute("items", items); 77 | } 78 | } 79 | } 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/servlets/AboutServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.bittercode.model.UserRole; 13 | import com.bittercode.util.StoreUtil; 14 | 15 | public class AboutServlet extends HttpServlet { 16 | 17 | public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 18 | PrintWriter pw = res.getWriter(); 19 | res.setContentType("text/html"); 20 | if (StoreUtil.isLoggedIn(UserRole.CUSTOMER, req.getSession())) { 21 | RequestDispatcher rd = req.getRequestDispatcher("CustomerHome.html"); 22 | rd.include(req, res); 23 | StoreUtil.setActiveTab(pw, "about"); 24 | pw.println(""); 26 | 27 | } else if (StoreUtil.isLoggedIn(UserRole.SELLER, req.getSession())) { 28 | RequestDispatcher rd = req.getRequestDispatcher("SellerHome.html"); 29 | rd.include(req, res); 30 | StoreUtil.setActiveTab(pw, "about"); 31 | pw.println(""); 33 | 34 | } else { 35 | RequestDispatcher rd = req.getRequestDispatcher("login.html"); 36 | rd.include(req, res); 37 | pw.println("
Please Login First to Continue!!
"); 38 | } 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/servlets/AddBookServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.UUID; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.bittercode.constant.BookStoreConstants; 14 | import com.bittercode.constant.db.BooksDBConstants; 15 | import com.bittercode.model.Book; 16 | import com.bittercode.model.UserRole; 17 | import com.bittercode.service.BookService; 18 | import com.bittercode.service.impl.BookServiceImpl; 19 | import com.bittercode.util.StoreUtil; 20 | 21 | public class AddBookServlet extends HttpServlet { 22 | BookService bookService = new BookServiceImpl(); 23 | 24 | public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 25 | PrintWriter pw = res.getWriter(); 26 | res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML); 27 | 28 | if (!StoreUtil.isLoggedIn(UserRole.SELLER, req.getSession())) { 29 | RequestDispatcher rd = req.getRequestDispatcher("SellerLogin.html"); 30 | rd.include(req, res); 31 | pw.println("
Please Login First to Continue!!
"); 32 | return; 33 | } 34 | 35 | String bName = req.getParameter(BooksDBConstants.COLUMN_NAME); 36 | RequestDispatcher rd = req.getRequestDispatcher("SellerHome.html"); 37 | rd.include(req, res); 38 | StoreUtil.setActiveTab(pw, "addbook"); 39 | pw.println("
"); 40 | if(bName == null || bName.isBlank()) { 41 | //render the add book form; 42 | showAddBookForm(pw); 43 | return; 44 | } //else process the add book 45 | 46 | 47 | try { 48 | String uniqueID = UUID.randomUUID().toString(); 49 | String bCode = uniqueID; 50 | String bAuthor = req.getParameter(BooksDBConstants.COLUMN_AUTHOR); 51 | double bPrice = Integer.parseInt(req.getParameter(BooksDBConstants.COLUMN_PRICE)); 52 | int bQty = Integer.parseInt(req.getParameter(BooksDBConstants.COLUMN_QUANTITY)); 53 | 54 | Book book = new Book(bCode, bName, bAuthor, bPrice, bQty); 55 | String message = bookService.addBook(book); 56 | if ("SUCCESS".equalsIgnoreCase(message)) { 57 | pw.println( 58 | "
Book Detail Updated Successfully!
Add More Books
"); 59 | } else { 60 | pw.println("
Failed to Add Books! Fill up CareFully
"); 61 | //rd.include(req, res); 62 | } 63 | } catch (Exception e) { 64 | e.printStackTrace(); 65 | pw.println("
Failed to Add Books! Fill up CareFully
"); 66 | } 67 | } 68 | 69 | private static void showAddBookForm(PrintWriter pw) { 70 | String form = "\r\n" 71 | + " \r\n" 72 | + " \r\n" 82 | + " \r\n" 83 | + " \r\n" 86 | + "
\r\n" 73 | + " \r\n" 74 | + " \r\n" 75 | + "
\r\n" 76 | + "
\r\n" 77 | + "
\r\n" 78 | + "
\r\n" 79 | + " \r\n" 80 | + " \r\n" 81 | + "
"; 87 | pw.println(form); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/servlets/BuyBooksServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.List; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.bittercode.constant.BookStoreConstants; 14 | import com.bittercode.model.Book; 15 | import com.bittercode.model.UserRole; 16 | import com.bittercode.service.BookService; 17 | import com.bittercode.service.impl.BookServiceImpl; 18 | import com.bittercode.util.StoreUtil; 19 | 20 | public class BuyBooksServlet extends HttpServlet { 21 | BookService bookService = new BookServiceImpl(); 22 | 23 | public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 24 | PrintWriter pw = res.getWriter(); 25 | res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML); 26 | if (!StoreUtil.isLoggedIn(UserRole.CUSTOMER, req.getSession())) { 27 | RequestDispatcher rd = req.getRequestDispatcher("CustomerLogin.html"); 28 | rd.include(req, res); 29 | pw.println("
Please Login First to Continue!!
"); 30 | return; 31 | } 32 | try { 33 | List books = bookService.getAllBooks(); 34 | RequestDispatcher rd = req.getRequestDispatcher("CustomerHome.html"); 35 | rd.include(req, res); 36 | StoreUtil.setActiveTab(pw, "cart"); 37 | pw.println("
Books Available In Our Store
"); 38 | pw.println("
"); 39 | pw.println("\r\n" + 40 | " \r\n" + 41 | " \r\n" + 42 | " \r\n" + 43 | " \r\n" + 44 | " \r\n" + 45 | " \r\n" + 46 | " \r\n" + 47 | " \r\n" + 48 | " "); 49 | int i = 0; 50 | for (Book book : books) { 51 | String bCode = book.getBarcode(); 52 | String bName = book.getName(); 53 | String bAuthor = book.getAuthor(); 54 | double bPrice = book.getPrice(); 55 | int bAvl = book.getQuantity(); 56 | i = i + 1; 57 | String n = "checked" + Integer.toString(i); 58 | String q = "qty" + Integer.toString(i); 59 | pw.println("\r\n" + 60 | " "); 65 | pw.println(""); 66 | pw.println(""); 67 | pw.println(""); 68 | pw.println(""); 69 | pw.println(""); 70 | pw.println(""); 71 | 72 | } 73 | pw.println("
BooksCodeNameAuthorPriceAvailQty
\r\n" + 61 | " \r\n" + // Value is 62 | // made equal 63 | // to bcode 64 | " " + bCode + "" + bName + "" + bAuthor + "" + bPrice + "" + bAvl + "
\r\n" + "" + "
" + 74 | "
\r\n" + 75 | "
"); 76 | // pw.println(""); 78 | } catch (Exception e) { 79 | e.printStackTrace(); 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/servlets/CartServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import javax.servlet.RequestDispatcher; 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import javax.servlet.http.HttpSession; 14 | 15 | import com.bittercode.constant.BookStoreConstants; 16 | import com.bittercode.model.Book; 17 | import com.bittercode.model.Cart; 18 | import com.bittercode.model.UserRole; 19 | import com.bittercode.service.BookService; 20 | import com.bittercode.service.impl.BookServiceImpl; 21 | import com.bittercode.util.StoreUtil; 22 | 23 | public class CartServlet extends HttpServlet { 24 | 25 | BookService bookService = new BookServiceImpl(); 26 | 27 | public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 28 | PrintWriter pw = res.getWriter(); 29 | res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML); 30 | 31 | // Check if Customer is logged In 32 | if (!StoreUtil.isLoggedIn(UserRole.CUSTOMER, req.getSession())) { 33 | RequestDispatcher rd = req.getRequestDispatcher("CustomerLogin.html"); 34 | rd.include(req, res); 35 | pw.println("
Please Login First to Continue!!
"); 36 | return; 37 | } 38 | try { 39 | // Add/Remove Item from the cart if requested 40 | // store the comma separated bookIds of cart in the session 41 | StoreUtil.updateCartItems(req); 42 | 43 | HttpSession session = req.getSession(); 44 | String bookIds = ""; 45 | if (session.getAttribute("items") != null) 46 | bookIds = (String) session.getAttribute("items");// read comma separated bookIds from session 47 | 48 | RequestDispatcher rd = req.getRequestDispatcher("CustomerHome.html"); 49 | rd.include(req, res); 50 | 51 | // Set the active tab as cart 52 | StoreUtil.setActiveTab(pw, "cart"); 53 | 54 | // Read the books from the database with the respective bookIds 55 | List books = bookService.getBooksByCommaSeperatedBookIds(bookIds); 56 | List cartItems = new ArrayList(); 57 | pw.println("
Shopping Cart
"); 58 | pw.println("\r\n" 59 | + " \r\n" 60 | + " \r\n" 61 | + " \r\n" 62 | + " \r\n" 63 | + " \r\n" 64 | + " \r\n" 65 | + " \r\n" 66 | + " \r\n" 67 | + " \r\n" 68 | + " \r\n" 69 | + " \r\n"); 70 | double amountToPay = 0; 71 | if (books == null || books.size() == 0) { 72 | pw.println(" \r\n" 73 | + " \r\n" 74 | + " \r\n"); 75 | } 76 | for (Book book : books) { 77 | int qty = (int) session.getAttribute("qty_" + book.getBarcode()); 78 | Cart cart = new Cart(book, qty); 79 | cartItems.add(cart); 80 | amountToPay += (qty * book.getPrice()); 81 | pw.println(getRowData(cart)); 82 | } 83 | 84 | // set cartItems and amountToPay in the session 85 | session.setAttribute("cartItems", cartItems); 86 | session.setAttribute("amountToPay", amountToPay); 87 | 88 | if (amountToPay > 0) { 89 | pw.println(" \r\n" 90 | + " \r\n" 91 | + " \r\n" 94 | + " \r\n"); 95 | } 96 | pw.println(" \r\n" 97 | + "
BookIdNameAuthorPrice/ItemQuantityAmount
No Items In the Cart
Total Amount To Pay " 92 | + amountToPay 93 | + "
"); 98 | if (amountToPay > 0) { 99 | pw.println("
\r\n" 100 | + "
" 101 | + "
" 103 | + "
"); 104 | } 105 | } catch (Exception e) { 106 | e.printStackTrace(); 107 | } 108 | } 109 | 110 | public String getRowData(Cart cart) { 111 | Book book = cart.getBook(); 112 | return " \r\n" 113 | + " " + book.getBarcode() + "\r\n" 114 | + " " + book.getName() + "\r\n" 115 | + " " + book.getAuthor() + "\r\n" 116 | + " " + book.getPrice() + "\r\n" 117 | + "
" 118 | + "" 119 | + cart.getQuantity() 120 | + "
\r\n" 121 | + " " + (book.getPrice() * cart.getQuantity()) + "\r\n" 122 | + " \r\n"; 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/servlets/CheckoutServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.bittercode.constant.BookStoreConstants; 13 | import com.bittercode.model.UserRole; 14 | import com.bittercode.util.StoreUtil; 15 | 16 | public class CheckoutServlet extends HttpServlet { 17 | public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 18 | PrintWriter pw = res.getWriter(); 19 | res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML); 20 | if (!StoreUtil.isLoggedIn(UserRole.CUSTOMER, req.getSession())) { 21 | RequestDispatcher rd = req.getRequestDispatcher("CustomerLogin.html"); 22 | rd.include(req, res); 23 | pw.println("
Please Login First to Continue!!
"); 24 | return; 25 | } 26 | try { 27 | 28 | RequestDispatcher rd = req.getRequestDispatcher("payment.html"); 29 | rd.include(req, res); 30 | StoreUtil.setActiveTab(pw, "cart"); 31 | pw.println("Total Amount₹ " 32 | + req.getSession().getAttribute("amountToPay") 33 | + ""); 34 | 35 | pw.println("" 36 | + ""); 37 | 38 | pw.println("
\r\n" 39 | + "
\r\n" 40 | + "
\r\n" 41 | + "
"); 42 | } catch (Exception e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/servlets/CustomerLoginServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.bittercode.constant.BookStoreConstants; 13 | import com.bittercode.constant.db.UsersDBConstants; 14 | import com.bittercode.model.User; 15 | import com.bittercode.model.UserRole; 16 | import com.bittercode.service.UserService; 17 | import com.bittercode.service.impl.UserServiceImpl; 18 | 19 | public class CustomerLoginServlet extends HttpServlet { 20 | 21 | UserService authService = new UserServiceImpl(); 22 | 23 | public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 24 | PrintWriter pw = res.getWriter(); 25 | res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML); 26 | String uName = req.getParameter(UsersDBConstants.COLUMN_USERNAME); 27 | String pWord = req.getParameter(UsersDBConstants.COLUMN_PASSWORD); 28 | User user = authService.login(UserRole.CUSTOMER, uName, pWord, req.getSession()); 29 | 30 | try { 31 | 32 | if (user != null) { 33 | 34 | RequestDispatcher rd = req.getRequestDispatcher("CustomerHome.html"); 35 | rd.include(req, res); 36 | pw.println("

Welcome to Online
Book Store

\r\n" 37 | + "
\r\n" 38 | + " \r\n" 39 | + " \r\n" 40 | + " \r\n" 41 | + " \r\n" 42 | + "

Welcome "+user.getFirstName()+", Happy Learning !!

"); 43 | 44 | } else { 45 | 46 | RequestDispatcher rd = req.getRequestDispatcher("CustomerLogin.html"); 47 | rd.include(req, res); 48 | pw.println("
Incorrect UserName or PassWord
"); 49 | } 50 | 51 | } catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /src/main/java/servlets/CustomerRegisterServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.bittercode.constant.BookStoreConstants; 13 | import com.bittercode.constant.ResponseCode; 14 | import com.bittercode.constant.db.UsersDBConstants; 15 | import com.bittercode.model.User; 16 | import com.bittercode.model.UserRole; 17 | import com.bittercode.service.UserService; 18 | import com.bittercode.service.impl.UserServiceImpl; 19 | 20 | public class CustomerRegisterServlet extends HttpServlet { 21 | 22 | UserService userService = new UserServiceImpl(); 23 | 24 | public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 25 | PrintWriter pw = res.getWriter(); 26 | res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML); 27 | 28 | String pWord = req.getParameter(UsersDBConstants.COLUMN_PASSWORD); 29 | String fName = req.getParameter(UsersDBConstants.COLUMN_FIRSTNAME); 30 | String lName = req.getParameter(UsersDBConstants.COLUMN_LASTNAME); 31 | String addr = req.getParameter(UsersDBConstants.COLUMN_ADDRESS); 32 | String phNo = req.getParameter(UsersDBConstants.COLUMN_PHONE); 33 | String mailId = req.getParameter(UsersDBConstants.COLUMN_MAILID); 34 | User user = new User(); 35 | user.setEmailId(mailId); 36 | user.setFirstName(fName); 37 | user.setLastName(lName); 38 | user.setPassword(pWord); 39 | user.setPhone(Long.parseLong(phNo)); 40 | user.setAddress(addr); 41 | try { 42 | String respCode = userService.register(UserRole.CUSTOMER, user); 43 | System.out.println(respCode); 44 | if (ResponseCode.SUCCESS.name().equalsIgnoreCase(respCode)) { 45 | RequestDispatcher rd = req.getRequestDispatcher("CustomerLogin.html"); 46 | rd.include(req, res); 47 | pw.println("
User Registered Successfully
"); 48 | } else { 49 | RequestDispatcher rd = req.getRequestDispatcher("CustomerRegister.html"); 50 | rd.include(req, res); 51 | pw.println("
" + respCode + "
"); 52 | pw.println("Sorry for interruption! Try again"); 53 | } 54 | } catch (Exception e) { 55 | e.printStackTrace(); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/java/servlets/ErrorHandlerServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.Optional; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.bittercode.constant.ResponseCode; 14 | import com.bittercode.model.StoreException; 15 | import com.bittercode.model.UserRole; 16 | import com.bittercode.util.StoreUtil; 17 | 18 | public class ErrorHandlerServlet extends HttpServlet { 19 | 20 | public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 21 | PrintWriter pw = res.getWriter(); 22 | res.setContentType("text/html"); 23 | 24 | // Fetch the exceptions 25 | Throwable throwable = (Throwable) req.getAttribute("javax.servlet.error.exception"); 26 | Integer statusCode = (Integer) req.getAttribute("javax.servlet.error.status_code"); 27 | String servletName = (String) req.getAttribute("javax.servlet.error.servlet_name"); 28 | String requestUri = (String) req.getAttribute("javax.servlet.error.request_uri"); 29 | String errorMessage = ResponseCode.INTERNAL_SERVER_ERROR.getMessage(); 30 | String errorCode = ResponseCode.INTERNAL_SERVER_ERROR.name(); 31 | 32 | if (statusCode == null) 33 | statusCode = 0; 34 | Optional errorCodes = ResponseCode.getMessageByStatusCode(statusCode); 35 | if (errorCodes.isPresent()) { 36 | errorMessage = errorCodes.get().getMessage(); 37 | errorCode = errorCodes.get().name(); 38 | } 39 | 40 | if (throwable != null && throwable instanceof StoreException) { 41 | StoreException storeException = (StoreException) throwable; 42 | if (storeException != null) { 43 | errorMessage = storeException.getMessage(); 44 | statusCode = storeException.getStatusCode(); 45 | errorCode = storeException.getErrorCode(); 46 | storeException.printStackTrace(); 47 | } 48 | } 49 | 50 | System.out.println("======ERROR TRIGGERED========"); 51 | System.out.println("Servlet Name: " + servletName); 52 | System.out.println("Request URI: " + requestUri); 53 | System.out.println("Status Code: " + statusCode); 54 | System.out.println("Error Code: " + errorCode); 55 | System.out.println("Error Message: " + errorMessage); 56 | System.out.println("============================="); 57 | 58 | if (StoreUtil.isLoggedIn(UserRole.CUSTOMER, req.getSession())) { 59 | RequestDispatcher rd = req.getRequestDispatcher("CustomerHome.html"); 60 | rd.include(req, res); 61 | StoreUtil.setActiveTab(pw, "home"); 62 | showErrorMessage(pw, errorCode, errorMessage); 63 | 64 | } else if (StoreUtil.isLoggedIn(UserRole.SELLER, req.getSession())) { 65 | RequestDispatcher rd = req.getRequestDispatcher("SellerHome.html"); 66 | rd.include(req, res); 67 | StoreUtil.setActiveTab(pw, "home"); 68 | showErrorMessage(pw, errorCode, errorMessage); 69 | 70 | } else { 71 | RequestDispatcher rd = req.getRequestDispatcher("index.html"); 72 | rd.include(req, res); 73 | pw.println(""); 77 | showErrorMessage(pw, errorCode, errorMessage); 78 | } 79 | 80 | } 81 | 82 | private void showErrorMessage(PrintWriter pw, String errorCode, String errorMessage) { 83 | pw.println("
" 84 | + "
\r\n" 85 | + "

" 86 | + errorCode 87 | + "

\r\n" 88 | + "
\r\n" 89 | + "

" 90 | + errorMessage 91 | + "

\r\n" 92 | + "
" 93 | + "
"); 94 | 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/servlets/LogoutServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.bittercode.constant.BookStoreConstants; 13 | import com.bittercode.service.UserService; 14 | import com.bittercode.service.impl.UserServiceImpl; 15 | 16 | public class LogoutServlet extends HttpServlet { 17 | 18 | UserService authService = new UserServiceImpl(); 19 | 20 | public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 21 | PrintWriter pw = res.getWriter(); 22 | res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML); 23 | try { 24 | 25 | boolean logout = authService.logout(req.getSession()); 26 | 27 | RequestDispatcher rd = req.getRequestDispatcher("CustomerLogin.html"); 28 | rd.include(req, res); 29 | // StoreUtil.setActiveTab(pw, "logout"); 30 | if (logout) { 31 | pw.println("
Successfully logged out!
"); 32 | } 33 | 34 | } catch (Exception e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/main/java/servlets/ProcessPaymentServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.List; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import javax.servlet.http.HttpSession; 13 | 14 | import com.bittercode.constant.BookStoreConstants; 15 | import com.bittercode.model.Book; 16 | import com.bittercode.model.Cart; 17 | import com.bittercode.model.UserRole; 18 | import com.bittercode.service.BookService; 19 | import com.bittercode.service.impl.BookServiceImpl; 20 | import com.bittercode.util.StoreUtil; 21 | 22 | public class ProcessPaymentServlet extends HttpServlet { 23 | 24 | BookService bookService = new BookServiceImpl(); 25 | 26 | @SuppressWarnings("unchecked") 27 | public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 28 | PrintWriter pw = res.getWriter(); 29 | res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML); 30 | if (!StoreUtil.isLoggedIn(UserRole.CUSTOMER, req.getSession())) { 31 | RequestDispatcher rd = req.getRequestDispatcher("CustomerLogin.html"); 32 | rd.include(req, res); 33 | pw.println("
Please Login First to Continue!!
"); 34 | return; 35 | } 36 | try { 37 | 38 | RequestDispatcher rd = req.getRequestDispatcher("CustomerHome.html"); 39 | rd.include(req, res); 40 | StoreUtil.setActiveTab(pw, "cart"); 41 | pw.println("
Your Orders
"); 42 | pw.println("
\r\n" 43 | + "
"); 44 | HttpSession session = req.getSession(); 45 | List cartItems = null; 46 | if (session.getAttribute("cartItems") != null) 47 | cartItems = (List) session.getAttribute("cartItems"); 48 | for (Cart cart : cartItems) { 49 | Book book = cart.getBook(); 50 | double bPrice = book.getPrice(); 51 | String bCode = book.getBarcode(); 52 | String bName = book.getName(); 53 | String bAuthor = book.getAuthor(); 54 | int availableQty = book.getQuantity(); 55 | int qtToBuy = cart.getQuantity(); 56 | availableQty = availableQty - qtToBuy; 57 | bookService.updateBookQtyById(bCode, availableQty); 58 | pw.println(this.addBookToCard(bCode, bName, bAuthor, bPrice, availableQty)); 59 | session.removeAttribute("qty_" + bCode); 60 | } 61 | session.removeAttribute("amountToPay"); 62 | session.removeAttribute("cartItems"); 63 | session.removeAttribute("items"); 64 | session.removeAttribute("selectedBookId"); 65 | pw.println("
\r\n" 66 | + "
"); 67 | } catch (Exception e) { 68 | e.printStackTrace(); 69 | } 70 | } 71 | 72 | public String addBookToCard(String bCode, String bName, String bAuthor, double bPrice, int bQty) { 73 | String button = "Order Placed\r\n"; 74 | return "
\r\n" 75 | + "
\r\n" 76 | + " \"Card\r\n" 77 | + "
\r\n" 78 | + "
" + bName + "
\r\n" 79 | + "

\r\n" 80 | + " Author: " + bAuthor 81 | + "
\r\n" 82 | + "

\r\n" 83 | + " \r\n" 84 | + "
\r\n" 85 | + "
\r\n" 86 | + "
\r\n" 87 | + "
\r\n" 88 | + "

\r\n" 89 | + " Order Id: ORD" + bCode + "TM \r\n" 90 | + "
Item Yet to be Delivered\r\n" 91 | + "

\r\n" 92 | + "
\r\n" 93 | + "
\r\n" 94 | + "

\r\n" 95 | + " Amout Paid: ₹ " + bPrice 96 | + " \r\n" 97 | + "

\r\n" 98 | + button 99 | + "
\r\n" 100 | + "
\r\n" 101 | + "
"; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/servlets/ReceiptServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.List; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.bittercode.constant.BookStoreConstants; 14 | import com.bittercode.model.Book; 15 | import com.bittercode.model.UserRole; 16 | import com.bittercode.service.BookService; 17 | import com.bittercode.service.impl.BookServiceImpl; 18 | import com.bittercode.util.StoreUtil; 19 | 20 | public class ReceiptServlet extends HttpServlet { 21 | BookService bookService = new BookServiceImpl(); 22 | 23 | //NOT_IN_USED 24 | public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 25 | PrintWriter pw = res.getWriter(); 26 | res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML); 27 | if (!StoreUtil.isLoggedIn(UserRole.CUSTOMER, req.getSession())) { 28 | RequestDispatcher rd = req.getRequestDispatcher("CustomerLogin.html"); 29 | rd.include(req, res); 30 | pw.println("
Please Login First to Continue!!
"); 31 | return; 32 | } 33 | try { 34 | List books = bookService.getAllBooks(); 35 | int i = 0; 36 | RequestDispatcher rd = req.getRequestDispatcher("CustomerHome.html"); 37 | rd.include(req, res); 38 | StoreUtil.setActiveTab(pw, "cart"); 39 | pw.println("
Your order status is as below
"); 40 | pw.println( 41 | "
\r\n" + " \r\n" + " \r\n" + " \r\n" 42 | + " \r\n" + " \r\n" 43 | + " \r\n" + " \r\n" 44 | + "
\r\n" + "
\r\n" 45 | + " "); 46 | double total = 0.0; 47 | for (Book book : books) { 48 | double bPrice = book.getPrice(); 49 | String bCode = book.getBarcode(); 50 | String bName = book.getName(); 51 | String bAuthor = book.getAuthor(); 52 | int bQty = book.getQuantity(); 53 | i = i + 1; 54 | 55 | String qt = "qty" + Integer.toString(i); 56 | int quantity = Integer.parseInt(req.getParameter(qt)); 57 | try { 58 | String check1 = "checked" + Integer.toString(i); 59 | String getChecked = req.getParameter(check1); 60 | if (bQty < quantity) { 61 | pw.println( 62 | "
Book CodeBook NameBook AuthorBook PriceQuantityAmount
Please Select the Qty less than Available Books Quantity
"); 63 | break; 64 | } 65 | 66 | if (getChecked.equals("pay")) { 67 | pw.println("" + bCode + ""); 68 | pw.println("" + bName + ""); 69 | pw.println("" + bAuthor + ""); 70 | pw.println("" + bPrice + ""); 71 | pw.println("" + quantity + ""); 72 | double amount = bPrice * quantity; 73 | total = total + amount; 74 | pw.println("" + amount + ""); 75 | bQty = bQty - quantity; 76 | System.out.println(bQty); 77 | bookService.updateBookQtyById(bCode, bQty); 78 | } 79 | } catch (Exception e) { 80 | } 81 | } 82 | pw.println("
Total Paid Amount: " + total + "
"); 83 | // String fPay = req.getParameter("f_pay"); 84 | } catch (Exception e) { 85 | e.printStackTrace(); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/servlets/RemoveBookServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.bittercode.constant.ResponseCode; 13 | import com.bittercode.model.UserRole; 14 | import com.bittercode.service.BookService; 15 | import com.bittercode.service.impl.BookServiceImpl; 16 | import com.bittercode.util.StoreUtil; 17 | 18 | public class RemoveBookServlet extends HttpServlet { 19 | 20 | BookService bookService = new BookServiceImpl(); 21 | 22 | public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 23 | PrintWriter pw = res.getWriter(); 24 | res.setContentType("text/html"); 25 | if (!StoreUtil.isLoggedIn(UserRole.SELLER, req.getSession())) { 26 | RequestDispatcher rd = req.getRequestDispatcher("SellerLogin.html"); 27 | rd.include(req, res); 28 | pw.println("
Please Login First to Continue!!
"); 29 | return; 30 | } 31 | 32 | try { 33 | String bookId = req.getParameter("bookId"); 34 | RequestDispatcher rd = req.getRequestDispatcher("SellerHome.html"); 35 | rd.include(req, res); 36 | StoreUtil.setActiveTab(pw, "removebook"); 37 | pw.println("
"); 38 | if (bookId == null || bookId.isBlank()) { 39 | // render the remove book form; 40 | showRemoveBookForm(pw); 41 | return; 42 | } // else continue 43 | 44 | String responseCode = bookService.deleteBookById(bookId.trim()); 45 | if (ResponseCode.SUCCESS.name().equalsIgnoreCase(responseCode)) { 46 | pw.println("
Book Removed Successfully
"); 47 | pw.println( 48 | "
Remove more Books
"); 49 | 50 | } else { 51 | pw.println("
Book Not Available In The Store
"); 52 | pw.println( 53 | "
Remove more Books
"); 54 | } 55 | pw.println("
"); 56 | } catch (Exception e) { 57 | e.printStackTrace(); 58 | pw.println("
Failed to Remove Books! Try Again
"); 59 | } 60 | } 61 | 62 | private static void showRemoveBookForm(PrintWriter pw) { 63 | String form = "
\r\n" 64 | + " \r\n" 65 | + " \r\n" 66 | + " \r\n" 71 | + " \r\n" 72 | + "\r\n" 73 | + "
\r\n" 67 | + " \r\n" 68 | + " \r\n" 69 | + " \r\n" 70 | + "
\r\n" 74 | + "
"; 75 | pw.println(form); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/servlets/SellerLoginServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.bittercode.constant.BookStoreConstants; 13 | import com.bittercode.constant.db.UsersDBConstants; 14 | import com.bittercode.model.User; 15 | import com.bittercode.model.UserRole; 16 | import com.bittercode.service.UserService; 17 | import com.bittercode.service.impl.UserServiceImpl; 18 | 19 | public class SellerLoginServlet extends HttpServlet { 20 | 21 | UserService userService = new UserServiceImpl(); 22 | 23 | public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 24 | PrintWriter pw = res.getWriter(); 25 | res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML); 26 | String uName = req.getParameter(UsersDBConstants.COLUMN_USERNAME); 27 | String pWord = req.getParameter(UsersDBConstants.COLUMN_PASSWORD); 28 | try { 29 | User user = userService.login(UserRole.SELLER, uName, pWord, req.getSession()); 30 | if (user != null) { 31 | RequestDispatcher rd = req.getRequestDispatcher("SellerHome.html"); 32 | 33 | rd.include(req, res); 34 | pw.println("

Welcome to Online
Book Store

\r\n" 35 | + "
\r\n" 36 | + " \r\n" 37 | + " \r\n" 38 | + " \r\n" 39 | + " \r\n" 40 | + "

Welcome "+user.getFirstName()+", Happy Learning !!

"); 41 | } else { 42 | 43 | RequestDispatcher rd = req.getRequestDispatcher("SellerLogin.html"); 44 | rd.include(req, res); 45 | pw.println("
Incorrect UserName or PassWord
"); 46 | } 47 | 48 | } catch (Exception e) { 49 | e.printStackTrace(); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/java/servlets/StoreBookServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.List; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.bittercode.model.Book; 14 | import com.bittercode.model.UserRole; 15 | import com.bittercode.service.BookService; 16 | import com.bittercode.service.impl.BookServiceImpl; 17 | import com.bittercode.util.StoreUtil; 18 | 19 | public class StoreBookServlet extends HttpServlet { 20 | 21 | // book service for database operations and logics 22 | BookService bookService = new BookServiceImpl(); 23 | 24 | public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 25 | PrintWriter pw = res.getWriter(); 26 | res.setContentType("text/html"); 27 | 28 | // Check if the customer is logged in, or else return to login page 29 | if (!StoreUtil.isLoggedIn(UserRole.SELLER, req.getSession())) { 30 | RequestDispatcher rd = req.getRequestDispatcher("SellerLogin.html"); 31 | rd.include(req, res); 32 | pw.println("
Please Login First to Continue!!
"); 33 | return; 34 | } 35 | try { 36 | 37 | // Add/Remove Item from the cart if requested 38 | // store the comma separated bookIds of cart in the session 39 | // StoreUtil.updateCartItems(req); 40 | 41 | RequestDispatcher rd = req.getRequestDispatcher("SellerHome.html"); 42 | rd.include(req, res); 43 | pw.println("
"); 44 | // Set the active tab as cart 45 | StoreUtil.setActiveTab(pw, "storebooks"); 46 | 47 | // Read the books from the database with the respective bookIds 48 | List books = bookService.getAllBooks(); 49 | pw.println("
Books Available In the Store
"); 50 | pw.println("\r\n" 51 | + " \r\n" 52 | + " \r\n" 53 | + " \r\n" 54 | + " \r\n" 55 | + " \r\n" 56 | + " \r\n" 57 | + " \r\n" 58 | + " \r\n" 59 | + " \r\n" 60 | + " \r\n" 61 | + " \r\n"); 62 | if (books == null || books.size() == 0) { 63 | pw.println(" \r\n" 64 | + " \r\n" 65 | + " \r\n"); 66 | } 67 | for (Book book : books) { 68 | pw.println(getRowData(book)); 69 | } 70 | 71 | pw.println(" \r\n" 72 | + "
BookIdNameAuthorPriceQuantityAction
No Books Available in the store
"); 73 | 74 | } catch (Exception e) { 75 | e.printStackTrace(); 76 | } 77 | } 78 | 79 | public String getRowData(Book book) { 80 | return " \r\n" 81 | + " " + book.getBarcode() + "\r\n" 82 | + " " + book.getName() + "\r\n" 83 | + " " + book.getAuthor() + "\r\n" 84 | + " " + book.getPrice() + "\r\n" 85 | + " " 86 | + book.getQuantity() 87 | + " \r\n" 88 | + "
" 89 | + " " 90 | + " " 91 | + "
" 92 | + " \r\n"; 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/servlets/UpdateBookServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.bittercode.constant.BookStoreConstants; 13 | import com.bittercode.constant.ResponseCode; 14 | import com.bittercode.constant.db.BooksDBConstants; 15 | import com.bittercode.model.Book; 16 | import com.bittercode.model.UserRole; 17 | import com.bittercode.service.BookService; 18 | import com.bittercode.service.impl.BookServiceImpl; 19 | import com.bittercode.util.StoreUtil; 20 | 21 | public class UpdateBookServlet extends HttpServlet { 22 | BookService bookService = new BookServiceImpl(); 23 | 24 | public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 25 | PrintWriter pw = res.getWriter(); 26 | res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML); 27 | 28 | if (!StoreUtil.isLoggedIn(UserRole.SELLER, req.getSession())) { 29 | RequestDispatcher rd = req.getRequestDispatcher("SellerLogin.html"); 30 | rd.include(req, res); 31 | pw.println("
Please Login First to Continue!!
"); 32 | return; 33 | } 34 | 35 | RequestDispatcher rd = req.getRequestDispatcher("SellerHome.html"); 36 | rd.include(req, res); 37 | StoreUtil.setActiveTab(pw, "storebooks"); 38 | pw.println("
"); 39 | 40 | try { 41 | if (req.getParameter("updateFormSubmitted") != null) { 42 | String bName = req.getParameter(BooksDBConstants.COLUMN_NAME); 43 | String bCode = req.getParameter(BooksDBConstants.COLUMN_BARCODE); 44 | String bAuthor = req.getParameter(BooksDBConstants.COLUMN_AUTHOR); 45 | double bPrice = Double.parseDouble(req.getParameter(BooksDBConstants.COLUMN_PRICE)); 46 | int bQty = Integer.parseInt(req.getParameter(BooksDBConstants.COLUMN_QUANTITY)); 47 | 48 | Book book = new Book(bCode, bName, bAuthor, bPrice, bQty); 49 | String message = bookService.updateBook(book); 50 | if (ResponseCode.SUCCESS.name().equalsIgnoreCase(message)) { 51 | pw.println( 52 | "
Book Detail Updated Successfully!
"); 53 | } else { 54 | pw.println("
Failed to Update Book!!
"); 55 | // rd.include(req, res); 56 | } 57 | 58 | return; 59 | } 60 | 61 | String bookId = req.getParameter("bookId"); 62 | 63 | if (bookId != null) { 64 | Book book = bookService.getBookById(bookId); 65 | showUpdateBookForm(pw, book); 66 | } 67 | 68 | } catch (Exception e) { 69 | e.printStackTrace(); 70 | pw.println("
Failed to Load Book data!!
"); 71 | } 72 | } 73 | 74 | private static void showUpdateBookForm(PrintWriter pw, Book book) { 75 | String form = "\r\n" 76 | + " \r\n" 77 | + " \r\n" 92 | + " \r\n" 93 | + "
\r\n" 78 | + "
\r\n" 79 | + "
" 81 | + "
\r\n" 83 | + "
\r\n" 85 | + "
\r\n" 87 | + "
\r\n" 89 | + " \r\n" 90 | + "
\r\n" 91 | + "
"; 94 | pw.println(form); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/servlets/ViewBookServlet.java: -------------------------------------------------------------------------------- 1 | package servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.List; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import javax.servlet.http.HttpSession; 13 | 14 | import com.bittercode.model.Book; 15 | import com.bittercode.model.UserRole; 16 | import com.bittercode.service.BookService; 17 | import com.bittercode.service.impl.BookServiceImpl; 18 | import com.bittercode.util.StoreUtil; 19 | 20 | public class ViewBookServlet extends HttpServlet { 21 | 22 | // book service for database operations and logics 23 | BookService bookService = new BookServiceImpl(); 24 | 25 | public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 26 | PrintWriter pw = res.getWriter(); 27 | res.setContentType("text/html"); 28 | 29 | // Check if the customer is logged in, or else return to login page 30 | if (!StoreUtil.isLoggedIn(UserRole.CUSTOMER, req.getSession())) { 31 | RequestDispatcher rd = req.getRequestDispatcher("CustomerLogin.html"); 32 | rd.include(req, res); 33 | pw.println("
Please Login First to Continue!!
"); 34 | return; 35 | } 36 | try { 37 | 38 | // Read All available books from the database 39 | List books = bookService.getAllBooks(); 40 | 41 | // Default Page to load data into 42 | RequestDispatcher rd = req.getRequestDispatcher("CustomerHome.html"); 43 | rd.include(req, res); 44 | 45 | // Set Available Books tab as active 46 | StoreUtil.setActiveTab(pw, "books"); 47 | 48 | // Show the heading for the page 49 | pw.println("
Available Books" 50 | + "
" 51 | + "
" 52 | + "
"); 53 | pw.println("
\r\n" 54 | + "
"); 55 | 56 | // Add or Remove items from the cart, if requested 57 | StoreUtil.updateCartItems(req); 58 | 59 | HttpSession session = req.getSession(); 60 | for (Book book : books) { 61 | 62 | // Add each book to display as a card 63 | pw.println(this.addBookToCard(session, book)); 64 | 65 | } 66 | 67 | // Checkout Button 68 | pw.println("
" 69 | + "
" 70 | + "
" 71 | + "
"); 72 | 73 | } catch (Exception e) { 74 | e.printStackTrace(); 75 | } 76 | } 77 | 78 | public String addBookToCard(HttpSession session, Book book) { 79 | String bCode = book.getBarcode(); 80 | int bQty = book.getQuantity(); 81 | 82 | // Quantity of the current book added to the cart 83 | int cartItemQty = 0; 84 | if (session.getAttribute("qty_" + bCode) != null) { 85 | // Quantity of each book in the cart will be added in the session prefixed with 86 | // 'qty_' following with bookId 87 | cartItemQty = (int) session.getAttribute("qty_" + bCode); 88 | } 89 | 90 | // Button To Add/Remove item from the cart 91 | String button = ""; 92 | if (bQty > 0) { 93 | // If no items in the cart, show add to cart button 94 | // If items is added to the cart, then show +, - button to add/remove more items 95 | button = "
" 96 | + "" 97 | + "" 98 | + (cartItemQty == 0 99 | ? "
" 100 | : "
" 101 | + " " 102 | + "" 103 | + cartItemQty 104 | + "
") 105 | + ""; 106 | } else { 107 | // If available Quantity is zero, show out of stock button 108 | button = "

Out Of Stock

\r\n"; 109 | } 110 | 111 | // Bootstrap card to show the book data 112 | return "
\r\n" 113 | + "
\r\n" 114 | + " \"Card\r\n" 115 | + "
\r\n" 116 | + "
" + book.getName() + "
\r\n" 117 | + "

\r\n" 118 | + " Author: " 119 | + book.getAuthor() 120 | + "
\r\n" 121 | + "

\r\n" 122 | + " \r\n" 123 | + "
\r\n" 124 | + "
\r\n" 125 | + "
\r\n" 126 | + "
\r\n" 127 | + "

\r\n" 128 | + " Id: " + bCode + "\r\n" 129 | + (bQty < 20 ? "
Only " + bQty + " items left\r\n" 130 | : "
Trending\r\n") 131 | + "

\r\n" 132 | + "
\r\n" 133 | + "
\r\n" 134 | + "

\r\n" 135 | + " Price: ₹ " 136 | + book.getPrice() 137 | + " \r\n" 138 | + "

\r\n" 139 | + button 140 | + "
\r\n" 141 | + "
\r\n" 142 | + "
"; 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | db.driver=com.mysql.cj.jdbc.Driver 2 | db.host=jdbc:mysql://localhost 3 | db.port=3306 4 | db.name=onlinebookstore 5 | db.username=root 6 | db.password=root --------------------------------------------------------------------------------