From 60b0ebf98970fc1479663b47782eb403a214cf74 Mon Sep 17 00:00:00 2001 From: akashboora Date: Sat, 19 Oct 2024 19:19:53 +0530 Subject: [PATCH 01/18] spring: added first spriong project --- telusko/Spring/first-project/.gitattributes | 2 + telusko/Spring/first-project/.gitignore | 33 +++ .../.mvn/wrapper/maven-wrapper.properties | 20 ++ telusko/Spring/first-project/mvnw | 259 ++++++++++++++++++ telusko/Spring/first-project/mvnw.cmd | 149 ++++++++++ telusko/Spring/first-project/pom.xml | 54 ++++ .../FirstProjectApplication.java | 13 + .../akash/learning/first_project/Greet.java | 13 + .../src/main/resources/application.properties | 1 + .../FirstProjectApplicationTests.java | 13 + 10 files changed, 557 insertions(+) create mode 100644 telusko/Spring/first-project/.gitattributes create mode 100644 telusko/Spring/first-project/.gitignore create mode 100644 telusko/Spring/first-project/.mvn/wrapper/maven-wrapper.properties create mode 100644 telusko/Spring/first-project/mvnw create mode 100644 telusko/Spring/first-project/mvnw.cmd create mode 100644 telusko/Spring/first-project/pom.xml create mode 100644 telusko/Spring/first-project/src/main/java/com/akash/learning/first_project/FirstProjectApplication.java create mode 100644 telusko/Spring/first-project/src/main/java/com/akash/learning/first_project/Greet.java create mode 100644 telusko/Spring/first-project/src/main/resources/application.properties create mode 100644 telusko/Spring/first-project/src/test/java/com/akash/learning/first_project/FirstProjectApplicationTests.java diff --git a/telusko/Spring/first-project/.gitattributes b/telusko/Spring/first-project/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/telusko/Spring/first-project/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/telusko/Spring/first-project/.gitignore b/telusko/Spring/first-project/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/telusko/Spring/first-project/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/telusko/Spring/first-project/.mvn/wrapper/maven-wrapper.properties b/telusko/Spring/first-project/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..fe9deed --- /dev/null +++ b/telusko/Spring/first-project/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip +distributionSha256Sum=4ec3f26fb1a692473aea0235c300bd20f0f9fe741947c82c1234cefd76ac3a3c diff --git a/telusko/Spring/first-project/mvnw b/telusko/Spring/first-project/mvnw new file mode 100644 index 0000000..19529dd --- /dev/null +++ b/telusko/Spring/first-project/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/telusko/Spring/first-project/mvnw.cmd b/telusko/Spring/first-project/mvnw.cmd new file mode 100644 index 0000000..249bdf3 --- /dev/null +++ b/telusko/Spring/first-project/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/telusko/Spring/first-project/pom.xml b/telusko/Spring/first-project/pom.xml new file mode 100644 index 0000000..627fee6 --- /dev/null +++ b/telusko/Spring/first-project/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.4 + + + com.akash.learning + first-project + 0.0.1-SNAPSHOT + first-project + Demo project for Spring Boot + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/telusko/Spring/first-project/src/main/java/com/akash/learning/first_project/FirstProjectApplication.java b/telusko/Spring/first-project/src/main/java/com/akash/learning/first_project/FirstProjectApplication.java new file mode 100644 index 0000000..1465851 --- /dev/null +++ b/telusko/Spring/first-project/src/main/java/com/akash/learning/first_project/FirstProjectApplication.java @@ -0,0 +1,13 @@ +package com.akash.learning.first_project; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class FirstProjectApplication { + + public static void main(String[] args) { + SpringApplication.run(FirstProjectApplication.class, args); + } + +} diff --git a/telusko/Spring/first-project/src/main/java/com/akash/learning/first_project/Greet.java b/telusko/Spring/first-project/src/main/java/com/akash/learning/first_project/Greet.java new file mode 100644 index 0000000..7481ac0 --- /dev/null +++ b/telusko/Spring/first-project/src/main/java/com/akash/learning/first_project/Greet.java @@ -0,0 +1,13 @@ +package com.akash.learning.first_project; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController() +public class Greet { + + @RequestMapping("/") + public String greet(){ + return "Hi, I am Akash."; + } +} diff --git a/telusko/Spring/first-project/src/main/resources/application.properties b/telusko/Spring/first-project/src/main/resources/application.properties new file mode 100644 index 0000000..a76c597 --- /dev/null +++ b/telusko/Spring/first-project/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=first-project diff --git a/telusko/Spring/first-project/src/test/java/com/akash/learning/first_project/FirstProjectApplicationTests.java b/telusko/Spring/first-project/src/test/java/com/akash/learning/first_project/FirstProjectApplicationTests.java new file mode 100644 index 0000000..14e0793 --- /dev/null +++ b/telusko/Spring/first-project/src/test/java/com/akash/learning/first_project/FirstProjectApplicationTests.java @@ -0,0 +1,13 @@ +package com.akash.learning.first_project; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class FirstProjectApplicationTests { + + @Test + void contextLoads() { + } + +} From e674dfa2eef972e03f8b1ade54dcfcfa1572fe94 Mon Sep 17 00:00:00 2001 From: akashboora Date: Sun, 3 Nov 2024 11:02:10 +0530 Subject: [PATCH 02/18] dependency injection --- .../.gitattributes | 2 + .../.gitignore | 33 +++ .../.mvn/wrapper/maven-wrapper.properties | 20 ++ .../second-project-dependecy-injection/mvnw | 259 ++++++++++++++++++ .../mvnw.cmd | 149 ++++++++++ .../pom.xml | 54 ++++ .../Dev.java | 11 + ...dProjectDependecyInjectionApplication.java | 19 ++ .../src/main/resources/application.properties | 1 + ...ectDependecyInjectionApplicationTests.java | 13 + 10 files changed, 561 insertions(+) create mode 100644 telusko/Spring/second-project-dependecy-injection/.gitattributes create mode 100644 telusko/Spring/second-project-dependecy-injection/.gitignore create mode 100644 telusko/Spring/second-project-dependecy-injection/.mvn/wrapper/maven-wrapper.properties create mode 100644 telusko/Spring/second-project-dependecy-injection/mvnw create mode 100644 telusko/Spring/second-project-dependecy-injection/mvnw.cmd create mode 100644 telusko/Spring/second-project-dependecy-injection/pom.xml create mode 100644 telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Dev.java create mode 100644 telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/SecondProjectDependecyInjectionApplication.java create mode 100644 telusko/Spring/second-project-dependecy-injection/src/main/resources/application.properties create mode 100644 telusko/Spring/second-project-dependecy-injection/src/test/java/com/akash/learning/second_project_dependecy_injection/SecondProjectDependecyInjectionApplicationTests.java diff --git a/telusko/Spring/second-project-dependecy-injection/.gitattributes b/telusko/Spring/second-project-dependecy-injection/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/telusko/Spring/second-project-dependecy-injection/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/telusko/Spring/second-project-dependecy-injection/.gitignore b/telusko/Spring/second-project-dependecy-injection/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/telusko/Spring/second-project-dependecy-injection/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/telusko/Spring/second-project-dependecy-injection/.mvn/wrapper/maven-wrapper.properties b/telusko/Spring/second-project-dependecy-injection/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..fe9deed --- /dev/null +++ b/telusko/Spring/second-project-dependecy-injection/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip +distributionSha256Sum=4ec3f26fb1a692473aea0235c300bd20f0f9fe741947c82c1234cefd76ac3a3c diff --git a/telusko/Spring/second-project-dependecy-injection/mvnw b/telusko/Spring/second-project-dependecy-injection/mvnw new file mode 100644 index 0000000..19529dd --- /dev/null +++ b/telusko/Spring/second-project-dependecy-injection/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/telusko/Spring/second-project-dependecy-injection/mvnw.cmd b/telusko/Spring/second-project-dependecy-injection/mvnw.cmd new file mode 100644 index 0000000..249bdf3 --- /dev/null +++ b/telusko/Spring/second-project-dependecy-injection/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/telusko/Spring/second-project-dependecy-injection/pom.xml b/telusko/Spring/second-project-dependecy-injection/pom.xml new file mode 100644 index 0000000..0886efd --- /dev/null +++ b/telusko/Spring/second-project-dependecy-injection/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.4 + + + com.akash.learning + second-project-dependecy-injection + 0.0.1-SNAPSHOT + second-project-dependecy-injection + Demo project for Spring Boot + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Dev.java b/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Dev.java new file mode 100644 index 0000000..2202743 --- /dev/null +++ b/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Dev.java @@ -0,0 +1,11 @@ +package com.akash.learning.second_project_dependecy_injection; + +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +@Component +public class Dev { + public void learn(){ + System.out.println("Learning Spring Boot"); + } +} diff --git a/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/SecondProjectDependecyInjectionApplication.java b/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/SecondProjectDependecyInjectionApplication.java new file mode 100644 index 0000000..4472a0d --- /dev/null +++ b/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/SecondProjectDependecyInjectionApplication.java @@ -0,0 +1,19 @@ +package com.akash.learning.second_project_dependecy_injection; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; + +@SpringBootApplication +public class SecondProjectDependecyInjectionApplication { + + public static void main(String[] args) { + ApplicationContext context = SpringApplication.run(SecondProjectDependecyInjectionApplication.class, args); + + Dev dev = context.getBean(Dev.class); + + dev.learn(); + } + +} diff --git a/telusko/Spring/second-project-dependecy-injection/src/main/resources/application.properties b/telusko/Spring/second-project-dependecy-injection/src/main/resources/application.properties new file mode 100644 index 0000000..83a6b2d --- /dev/null +++ b/telusko/Spring/second-project-dependecy-injection/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=second-project-dependecy-injection diff --git a/telusko/Spring/second-project-dependecy-injection/src/test/java/com/akash/learning/second_project_dependecy_injection/SecondProjectDependecyInjectionApplicationTests.java b/telusko/Spring/second-project-dependecy-injection/src/test/java/com/akash/learning/second_project_dependecy_injection/SecondProjectDependecyInjectionApplicationTests.java new file mode 100644 index 0000000..0825300 --- /dev/null +++ b/telusko/Spring/second-project-dependecy-injection/src/test/java/com/akash/learning/second_project_dependecy_injection/SecondProjectDependecyInjectionApplicationTests.java @@ -0,0 +1,13 @@ +package com.akash.learning.second_project_dependecy_injection; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SecondProjectDependecyInjectionApplicationTests { + + @Test + void contextLoads() { + } + +} From a6139e273d39da1d775ac177c09f90a38407c165 Mon Sep 17 00:00:00 2001 From: akashboora Date: Sun, 3 Nov 2024 11:20:29 +0530 Subject: [PATCH 03/18] learn/spring: Autowiring(field, constructor, setter) primary and qualifier --- .../Computer.java | 5 +++++ .../Desktop.java | 11 ++++++++++ .../Dev.java | 21 ++++++++++++++++++- .../Laptop.java | 13 ++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Computer.java create mode 100644 telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Desktop.java create mode 100644 telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Laptop.java diff --git a/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Computer.java b/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Computer.java new file mode 100644 index 0000000..a77b47a --- /dev/null +++ b/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Computer.java @@ -0,0 +1,5 @@ +package com.akash.learning.second_project_dependecy_injection; + +public interface Computer { + public void compile(); +} diff --git a/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Desktop.java b/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Desktop.java new file mode 100644 index 0000000..5510911 --- /dev/null +++ b/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Desktop.java @@ -0,0 +1,11 @@ +package com.akash.learning.second_project_dependecy_injection; + +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; + +@Component +public class Desktop implements Computer { + public void compile(){ + System.out.println("Compiling in desktop"); + } +} diff --git a/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Dev.java b/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Dev.java index 2202743..c6f6cec 100644 --- a/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Dev.java +++ b/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Dev.java @@ -1,11 +1,30 @@ package com.akash.learning.second_project_dependecy_injection; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; @Component public class Dev { + + // Field Injection + @Autowired + @Qualifier("laptop") + private Computer comp; + +// constructor injection +// public Dev(Laptop laptop) { +// this.laptop = laptop; +// } + +// setter injection +// @Autowired +// public void setLaptop(Laptop laptop) { +// this.laptop = laptop; +// } + public void learn(){ + comp.compile(); System.out.println("Learning Spring Boot"); } } diff --git a/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Laptop.java b/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Laptop.java new file mode 100644 index 0000000..4c3827a --- /dev/null +++ b/telusko/Spring/second-project-dependecy-injection/src/main/java/com/akash/learning/second_project_dependecy_injection/Laptop.java @@ -0,0 +1,13 @@ +package com.akash.learning.second_project_dependecy_injection; + +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; + +@Component +//@Primary +public class Laptop implements Computer { + public void compile(){ + System.out.println("Compiling in laptop"); + } +} From 770fbf77f3657db4679fd7079a364d1409b2c569 Mon Sep 17 00:00:00 2001 From: akashboora Date: Sun, 3 Nov 2024 13:52:52 +0530 Subject: [PATCH 04/18] learn/spring: spring framework, xml config --- .../Spring/third-spring-frmaework/.gitignore | 38 +++++++++++++++++++ .../third-spring-frmaework/.idea/.gitignore | 3 ++ .../.idea/encodings.xml | 7 ++++ .../third-spring-frmaework/.idea/misc.xml | 14 +++++++ .../third-spring-frmaework/.idea/vcs.xml | 6 +++ telusko/Spring/third-spring-frmaework/pom.xml | 31 +++++++++++++++ .../third-spring-frmaework/src/Dev.java | 30 +++++++++++++++ .../main/java/org/akash/learn/spring/App.java | 17 +++++++++ .../main/java/org/akash/learn/spring/Dev.java | 10 +++++ .../java/org/akash/learn/spring/Laptop.java | 7 ++++ .../src/main/resources/spring.xml | 10 +++++ .../java/org/akash/learn/spring/AppTest.java | 38 +++++++++++++++++++ 12 files changed, 211 insertions(+) create mode 100644 telusko/Spring/third-spring-frmaework/.gitignore create mode 100644 telusko/Spring/third-spring-frmaework/.idea/.gitignore create mode 100644 telusko/Spring/third-spring-frmaework/.idea/encodings.xml create mode 100644 telusko/Spring/third-spring-frmaework/.idea/misc.xml create mode 100644 telusko/Spring/third-spring-frmaework/.idea/vcs.xml create mode 100644 telusko/Spring/third-spring-frmaework/pom.xml create mode 100644 telusko/Spring/third-spring-frmaework/src/Dev.java create mode 100644 telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/App.java create mode 100644 telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Dev.java create mode 100644 telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Laptop.java create mode 100644 telusko/Spring/third-spring-frmaework/src/main/resources/spring.xml create mode 100644 telusko/Spring/third-spring-frmaework/src/test/java/org/akash/learn/spring/AppTest.java diff --git a/telusko/Spring/third-spring-frmaework/.gitignore b/telusko/Spring/third-spring-frmaework/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/telusko/Spring/third-spring-frmaework/.idea/.gitignore b/telusko/Spring/third-spring-frmaework/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/telusko/Spring/third-spring-frmaework/.idea/encodings.xml b/telusko/Spring/third-spring-frmaework/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/telusko/Spring/third-spring-frmaework/.idea/misc.xml b/telusko/Spring/third-spring-frmaework/.idea/misc.xml new file mode 100644 index 0000000..fdc35ea --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/telusko/Spring/third-spring-frmaework/.idea/vcs.xml b/telusko/Spring/third-spring-frmaework/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/telusko/Spring/third-spring-frmaework/pom.xml b/telusko/Spring/third-spring-frmaework/pom.xml new file mode 100644 index 0000000..5b114f2 --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/pom.xml @@ -0,0 +1,31 @@ + + 4.0.0 + + org.akash.learn.spring + third-spring-frmaework + 1.0-SNAPSHOT + jar + + third-spring-frmaework + http://maven.apache.org + + + UTF-8 + + + + + org.springframework + spring-context + 6.1.14 + + + + junit + junit + 3.8.1 + test + + + diff --git a/telusko/Spring/third-spring-frmaework/src/Dev.java b/telusko/Spring/third-spring-frmaework/src/Dev.java new file mode 100644 index 0000000..c6f6cec --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/src/Dev.java @@ -0,0 +1,30 @@ +package com.akash.learning.second_project_dependecy_injection; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +@Component +public class Dev { + + // Field Injection + @Autowired + @Qualifier("laptop") + private Computer comp; + +// constructor injection +// public Dev(Laptop laptop) { +// this.laptop = laptop; +// } + +// setter injection +// @Autowired +// public void setLaptop(Laptop laptop) { +// this.laptop = laptop; +// } + + public void learn(){ + comp.compile(); + System.out.println("Learning Spring Boot"); + } +} diff --git a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/App.java b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/App.java new file mode 100644 index 0000000..3772eb0 --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/App.java @@ -0,0 +1,17 @@ +package org.akash.learn.spring; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.util.Arrays; + +public class App { + public static void main(String[] args) { + ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); + String[] names = context.getBeanDefinitionNames(); +// Dev obj = context.getBean(Dev.class); +// obj.learn(); + System.out.println("In main method"); + System.out.println(Arrays.toString(names)); + } +} diff --git a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Dev.java b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Dev.java new file mode 100644 index 0000000..375b80b --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Dev.java @@ -0,0 +1,10 @@ +package org.akash.learn.spring; + +import org.springframework.stereotype.Component; + +public class Dev +{ + public void learn(){ + System.out.println("Learning Spring Boot"); + } +} diff --git a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Laptop.java b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Laptop.java new file mode 100644 index 0000000..58544c5 --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Laptop.java @@ -0,0 +1,7 @@ +package org.akash.learn.spring; + +public class Laptop { + public void compile(){ + System.out.println("Compiling........."); + } +} diff --git a/telusko/Spring/third-spring-frmaework/src/main/resources/spring.xml b/telusko/Spring/third-spring-frmaework/src/main/resources/spring.xml new file mode 100644 index 0000000..30fa02f --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/src/main/resources/spring.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/telusko/Spring/third-spring-frmaework/src/test/java/org/akash/learn/spring/AppTest.java b/telusko/Spring/third-spring-frmaework/src/test/java/org/akash/learn/spring/AppTest.java new file mode 100644 index 0000000..d7c2d37 --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/src/test/java/org/akash/learn/spring/AppTest.java @@ -0,0 +1,38 @@ +package org.akash.learn.spring; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} From 035e11ce04d5b19fb94d84f8b6237881b73908ef Mon Sep 17 00:00:00 2001 From: akashboora Date: Sun, 3 Nov 2024 16:54:26 +0530 Subject: [PATCH 05/18] learn/spring: setter and constrcutor injection in spring using xml --- .../main/java/org/akash/learn/spring/App.java | 6 ++-- .../main/java/org/akash/learn/spring/Dev.java | 30 +++++++++++++++++++ .../src/main/resources/spring.xml | 7 +++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/App.java b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/App.java index 3772eb0..3bd3026 100644 --- a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/App.java +++ b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/App.java @@ -9,9 +9,11 @@ public class App { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); String[] names = context.getBeanDefinitionNames(); -// Dev obj = context.getBean(Dev.class); -// obj.learn(); System.out.println("In main method"); System.out.println(Arrays.toString(names)); + + Dev obj = (Dev) context.getBean("dev"); + System.out.println(obj.getAge()); + obj.learn(); } } diff --git a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Dev.java b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Dev.java index 375b80b..4f26154 100644 --- a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Dev.java +++ b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Dev.java @@ -4,7 +4,37 @@ public class Dev { + private Laptop laptop; + private int age; + +// public Dev(int age) { +// this.age = age; +// } + + + public Dev(int age, Laptop laptop) { + this.age = age; + this.laptop = laptop; + } + + public Laptop getLaptop() { + return laptop; + } + + public void setLaptop(Laptop laptop) { + this.laptop = laptop; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + public void learn(){ System.out.println("Learning Spring Boot"); + laptop.compile(); } } diff --git a/telusko/Spring/third-spring-frmaework/src/main/resources/spring.xml b/telusko/Spring/third-spring-frmaework/src/main/resources/spring.xml index 30fa02f..2220136 100644 --- a/telusko/Spring/third-spring-frmaework/src/main/resources/spring.xml +++ b/telusko/Spring/third-spring-frmaework/src/main/resources/spring.xml @@ -4,6 +4,13 @@ xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> + + + + + + + From fe2d5907d99d9eaa26db758b6428082f3c713a71 Mon Sep 17 00:00:00 2001 From: akashboora Date: Sun, 3 Nov 2024 17:08:59 +0530 Subject: [PATCH 06/18] learn/spring: autowire in spring using xml --- .../main/java/org/akash/learn/spring/App.java | 4 +- .../java/org/akash/learn/spring/Computer.java | 5 +++ .../java/org/akash/learn/spring/Desktop.java | 8 ++++ .../main/java/org/akash/learn/spring/Dev.java | 38 +++++++++---------- .../java/org/akash/learn/spring/Laptop.java | 5 ++- .../src/main/resources/spring.xml | 11 ++++-- 6 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Computer.java create mode 100644 telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Desktop.java diff --git a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/App.java b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/App.java index 3bd3026..735ad88 100644 --- a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/App.java +++ b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/App.java @@ -12,8 +12,8 @@ public static void main(String[] args) { System.out.println("In main method"); System.out.println(Arrays.toString(names)); - Dev obj = (Dev) context.getBean("dev"); - System.out.println(obj.getAge()); + Dev obj = context.getBean(Dev.class); +// System.out.println(obj.getAge()); obj.learn(); } } diff --git a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Computer.java b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Computer.java new file mode 100644 index 0000000..f438a64 --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Computer.java @@ -0,0 +1,5 @@ +package org.akash.learn.spring; + +public interface Computer { + void compile(); +} diff --git a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Desktop.java b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Desktop.java new file mode 100644 index 0000000..872aeb6 --- /dev/null +++ b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Desktop.java @@ -0,0 +1,8 @@ +package org.akash.learn.spring; + +public class Desktop implements Computer { + @Override + public void compile(){ + System.out.println("Compiling in Desktop"); + } +} diff --git a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Dev.java b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Dev.java index 4f26154..379327a 100644 --- a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Dev.java +++ b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Dev.java @@ -1,40 +1,38 @@ package org.akash.learn.spring; -import org.springframework.stereotype.Component; - public class Dev { - private Laptop laptop; - private int age; + private Computer computer; +// private int age; // public Dev(int age) { // this.age = age; // } - public Dev(int age, Laptop laptop) { - this.age = age; - this.laptop = laptop; - } - - public Laptop getLaptop() { - return laptop; - } +// public Dev(int age, Laptop laptop) { +// this.age = age; +// this.laptop = laptop; +// } - public void setLaptop(Laptop laptop) { - this.laptop = laptop; + public Computer getComputer() { + return computer; } - public int getAge() { - return age; + public void setComputer(Computer computer) { + this.computer = computer; } - public void setAge(int age) { - this.age = age; - } +// public int getAge() { +// return age; +// } +// +// public void setAge(int age) { +// this.age = age; +// } public void learn(){ System.out.println("Learning Spring Boot"); - laptop.compile(); + computer.compile(); } } diff --git a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Laptop.java b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Laptop.java index 58544c5..a87c4f0 100644 --- a/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Laptop.java +++ b/telusko/Spring/third-spring-frmaework/src/main/java/org/akash/learn/spring/Laptop.java @@ -1,7 +1,8 @@ package org.akash.learn.spring; -public class Laptop { +public class Laptop implements Computer { + @Override public void compile(){ - System.out.println("Compiling........."); + System.out.println("Compiling in Laptop"); } } diff --git a/telusko/Spring/third-spring-frmaework/src/main/resources/spring.xml b/telusko/Spring/third-spring-frmaework/src/main/resources/spring.xml index 2220136..a873e47 100644 --- a/telusko/Spring/third-spring-frmaework/src/main/resources/spring.xml +++ b/telusko/Spring/third-spring-frmaework/src/main/resources/spring.xml @@ -3,15 +3,18 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - + - - + + + - + + + \ No newline at end of file From fd1b52b93630ff992b48977e2bdf313629fb17b6 Mon Sep 17 00:00:00 2001 From: akashboora Date: Sun, 3 Nov 2024 18:21:19 +0530 Subject: [PATCH 07/18] learn/spring: simple web application --- .../fourth-project-simple-web/.gitattributes | 2 + .../fourth-project-simple-web/.gitignore | 33 +++ .../.mvn/wrapper/maven-wrapper.properties | 19 ++ telusko/Spring/fourth-project-simple-web/mvnw | 259 ++++++++++++++++++ .../Spring/fourth-project-simple-web/mvnw.cmd | 149 ++++++++++ .../Spring/fourth-project-simple-web/pom.xml | 60 ++++ .../FourthProjectSimpleWebApplication.java | 13 + .../HomeController.java | 17 ++ .../LoginController.java | 12 + .../src/main/resources/application.properties | 1 + ...ourthProjectSimpleWebApplicationTests.java | 13 + 11 files changed, 578 insertions(+) create mode 100644 telusko/Spring/fourth-project-simple-web/.gitattributes create mode 100644 telusko/Spring/fourth-project-simple-web/.gitignore create mode 100644 telusko/Spring/fourth-project-simple-web/.mvn/wrapper/maven-wrapper.properties create mode 100644 telusko/Spring/fourth-project-simple-web/mvnw create mode 100644 telusko/Spring/fourth-project-simple-web/mvnw.cmd create mode 100644 telusko/Spring/fourth-project-simple-web/pom.xml create mode 100644 telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/FourthProjectSimpleWebApplication.java create mode 100644 telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/HomeController.java create mode 100644 telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/LoginController.java create mode 100644 telusko/Spring/fourth-project-simple-web/src/main/resources/application.properties create mode 100644 telusko/Spring/fourth-project-simple-web/src/test/java/com/akash/learn/spring/fourth_project_simple_web/FourthProjectSimpleWebApplicationTests.java diff --git a/telusko/Spring/fourth-project-simple-web/.gitattributes b/telusko/Spring/fourth-project-simple-web/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/telusko/Spring/fourth-project-simple-web/.gitignore b/telusko/Spring/fourth-project-simple-web/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/telusko/Spring/fourth-project-simple-web/.mvn/wrapper/maven-wrapper.properties b/telusko/Spring/fourth-project-simple-web/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..d58dfb7 --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip diff --git a/telusko/Spring/fourth-project-simple-web/mvnw b/telusko/Spring/fourth-project-simple-web/mvnw new file mode 100644 index 0000000..19529dd --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/telusko/Spring/fourth-project-simple-web/mvnw.cmd b/telusko/Spring/fourth-project-simple-web/mvnw.cmd new file mode 100644 index 0000000..249bdf3 --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/telusko/Spring/fourth-project-simple-web/pom.xml b/telusko/Spring/fourth-project-simple-web/pom.xml new file mode 100644 index 0000000..2ccb181 --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.5 + + + com.akash.learn.spring + fourth-project-simple-web + 0.0.1-SNAPSHOT + fourth-project-simple-web + Demo project for Spring Boot + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/FourthProjectSimpleWebApplication.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/FourthProjectSimpleWebApplication.java new file mode 100644 index 0000000..5aa6403 --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/FourthProjectSimpleWebApplication.java @@ -0,0 +1,13 @@ +package com.akash.learn.spring.fourth_project_simple_web; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class FourthProjectSimpleWebApplication { + + public static void main(String[] args) { + SpringApplication.run(FourthProjectSimpleWebApplication.class, args); + } + +} diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/HomeController.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/HomeController.java new file mode 100644 index 0000000..5da612f --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/HomeController.java @@ -0,0 +1,17 @@ +package com.akash.learn.spring.fourth_project_simple_web; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HomeController { + @RequestMapping("/") + public String greet(){ + return "Welcome to Akash's learnings"; + } + + @RequestMapping("/about") + public String about(){ + return "Am still learning"; + } +} diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/LoginController.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/LoginController.java new file mode 100644 index 0000000..8c3391b --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/LoginController.java @@ -0,0 +1,12 @@ +package com.akash.learn.spring.fourth_project_simple_web; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class LoginController { + @RequestMapping("/login") + public String login(){ + return "Login Page"; + } +} diff --git a/telusko/Spring/fourth-project-simple-web/src/main/resources/application.properties b/telusko/Spring/fourth-project-simple-web/src/main/resources/application.properties new file mode 100644 index 0000000..87e2e92 --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=fourth-project-simple-web diff --git a/telusko/Spring/fourth-project-simple-web/src/test/java/com/akash/learn/spring/fourth_project_simple_web/FourthProjectSimpleWebApplicationTests.java b/telusko/Spring/fourth-project-simple-web/src/test/java/com/akash/learn/spring/fourth_project_simple_web/FourthProjectSimpleWebApplicationTests.java new file mode 100644 index 0000000..31f9912 --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/src/test/java/com/akash/learn/spring/fourth_project_simple_web/FourthProjectSimpleWebApplicationTests.java @@ -0,0 +1,13 @@ +package com.akash.learn.spring.fourth_project_simple_web; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class FourthProjectSimpleWebApplicationTests { + + @Test + void contextLoads() { + } + +} From c613bf06c296e17474bf0ee5a319e7b77b4b54ac Mon Sep 17 00:00:00 2001 From: akashboora Date: Sun, 3 Nov 2024 19:31:08 +0530 Subject: [PATCH 08/18] learn/spring: mvc layers products --- .../Spring/fourth-project-simple-web/pom.xml | 17 ++++++- .../{ => controller}/HomeController.java | 2 +- .../{ => controller}/LoginController.java | 2 +- .../controller/ProductController.java | 20 +++++++++ .../model/Product.java | 45 +++++++++++++++++++ .../service/ProductService.java | 19 ++++++++ 6 files changed, 101 insertions(+), 4 deletions(-) rename telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/{ => controller}/HomeController.java (84%) rename telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/{ => controller}/LoginController.java (79%) create mode 100644 telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/ProductController.java create mode 100644 telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/model/Product.java create mode 100644 telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java diff --git a/telusko/Spring/fourth-project-simple-web/pom.xml b/telusko/Spring/fourth-project-simple-web/pom.xml index 2ccb181..4530f81 100644 --- a/telusko/Spring/fourth-project-simple-web/pom.xml +++ b/telusko/Spring/fourth-project-simple-web/pom.xml @@ -1,6 +1,6 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot @@ -41,6 +41,11 @@ runtime true + + org.projectlombok + lombok + true + org.springframework.boot spring-boot-starter-test @@ -53,8 +58,16 @@ org.springframework.boot spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + - + \ No newline at end of file diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/HomeController.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/HomeController.java similarity index 84% rename from telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/HomeController.java rename to telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/HomeController.java index 5da612f..72a2faf 100644 --- a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/HomeController.java +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/HomeController.java @@ -1,4 +1,4 @@ -package com.akash.learn.spring.fourth_project_simple_web; +package com.akash.learn.spring.fourth_project_simple_web.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/LoginController.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/LoginController.java similarity index 79% rename from telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/LoginController.java rename to telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/LoginController.java index 8c3391b..e0a2063 100644 --- a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/LoginController.java +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/LoginController.java @@ -1,4 +1,4 @@ -package com.akash.learn.spring.fourth_project_simple_web; +package com.akash.learn.spring.fourth_project_simple_web.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/ProductController.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/ProductController.java new file mode 100644 index 0000000..056fb76 --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/ProductController.java @@ -0,0 +1,20 @@ +package com.akash.learn.spring.fourth_project_simple_web.controller; + +import com.akash.learn.spring.fourth_project_simple_web.model.Product; +import com.akash.learn.spring.fourth_project_simple_web.service.ProductService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +public class ProductController { + @Autowired + ProductService productService; + + @RequestMapping("/products") + public List getProducts(){ + return productService.getProducts(); + } +} diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/model/Product.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/model/Product.java new file mode 100644 index 0000000..41ce5e8 --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/model/Product.java @@ -0,0 +1,45 @@ +package com.akash.learn.spring.fourth_project_simple_web.model; + + +import lombok.Data; +import org.springframework.stereotype.Component; + +@Component +public class Product { + private int id; + private String name; + private int price; + + public Product() { + } + + public Product(int id, String name, int price) { + this.id = id; + this.name = name; + this.price = price; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getPrice() { + return price; + } + + public void setPrice(int price) { + this.price = price; + } +} diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java new file mode 100644 index 0000000..6406206 --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java @@ -0,0 +1,19 @@ +package com.akash.learn.spring.fourth_project_simple_web.service; + +import com.akash.learn.spring.fourth_project_simple_web.model.Product; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.List; + +@Service +public class ProductService { + private List products = Arrays.asList( + new Product(101, "IPhone", 50000), + new Product(102, "Google", 25000), + new Product(103, "Oneplus", 20000)); + + public List getProducts(){ + return products; + } +} From 18e4a362df26ec22a0d075e31b5afe89a39ea89c Mon Sep 17 00:00:00 2001 From: akashboora Date: Sun, 3 Nov 2024 19:52:41 +0530 Subject: [PATCH 09/18] learn/spring: post get by id --- .../controller/ProductController.java | 15 ++++++++++++--- .../service/ProductService.java | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/ProductController.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/ProductController.java index 056fb76..570e972 100644 --- a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/ProductController.java +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/ProductController.java @@ -3,8 +3,7 @@ import com.akash.learn.spring.fourth_project_simple_web.model.Product; import com.akash.learn.spring.fourth_project_simple_web.service.ProductService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -13,8 +12,18 @@ public class ProductController { @Autowired ProductService productService; - @RequestMapping("/products") + @GetMapping("/products") public List getProducts(){ return productService.getProducts(); } + + @GetMapping("/products/{productId}") + public Product getProductById(@PathVariable int productId){ + return productService.getProductById(productId); + } + + @PostMapping("/products") + public Product createProduct(@RequestBody Product product){ + return productService.createProduct(product); + } } diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java index 6406206..a0a858a 100644 --- a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java @@ -3,17 +3,27 @@ import com.akash.learn.spring.fourth_project_simple_web.model.Product; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @Service public class ProductService { - private List products = Arrays.asList( + private List products = new ArrayList<>(Arrays.asList( new Product(101, "IPhone", 50000), new Product(102, "Google", 25000), - new Product(103, "Oneplus", 20000)); + new Product(103, "Oneplus", 20000))); public List getProducts(){ return products; } + + public Product getProductById(int productId){ + return products.stream().filter(p -> p.getId() == productId).findFirst().get(); + } + + public Product createProduct(Product product) { + products.add(product); + return product; + } } From b0a8f89f24ee4e561d3ebc6d0ac738464fa2f79c Mon Sep 17 00:00:00 2001 From: akashboora Date: Sun, 3 Nov 2024 21:33:05 +0530 Subject: [PATCH 10/18] learn/spring: added mappings for deletion and update --- .../controller/ProductController.java | 11 ++++++++++ .../service/ProductService.java | 20 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/ProductController.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/ProductController.java index 570e972..844c933 100644 --- a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/ProductController.java +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/controller/ProductController.java @@ -26,4 +26,15 @@ public Product getProductById(@PathVariable int productId){ public Product createProduct(@RequestBody Product product){ return productService.createProduct(product); } + + @PutMapping("/products/{productId}") + public Product updateProduct(@PathVariable int productId, @RequestBody Product product) { + return productService.updateProduct(productId, product); + } + + @DeleteMapping("/products/{productId}") + public String deleteProduct(@PathVariable int productId){ + productService.deleteProduct(productId); + return "Deleted Successfully"; + } } diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java index a0a858a..4f5bbbf 100644 --- a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java @@ -26,4 +26,24 @@ public Product createProduct(Product product) { products.add(product); return product; } + + public Product updateProduct(int productId, Product product) { + int index = 0; + for (int i=0;i Date: Tue, 5 Nov 2024 22:00:06 +0530 Subject: [PATCH 11/18] Added h2 Dabase for sample project --- .../Spring/fourth-project-simple-web/pom.xml | 11 ++++- .../model/Product.java | 43 +++++-------------- .../repository/ProductRepo.java | 9 ++++ .../service/ProductService.java | 31 +++++-------- .../src/main/resources/application.properties | 7 +++ 5 files changed, 46 insertions(+), 55 deletions(-) create mode 100644 telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/repository/ProductRepo.java diff --git a/telusko/Spring/fourth-project-simple-web/pom.xml b/telusko/Spring/fourth-project-simple-web/pom.xml index 4530f81..b742866 100644 --- a/telusko/Spring/fourth-project-simple-web/pom.xml +++ b/telusko/Spring/fourth-project-simple-web/pom.xml @@ -30,6 +30,10 @@ 21 + + org.springframework.boot + spring-boot-starter-data-jpa + org.springframework.boot spring-boot-starter-web @@ -41,10 +45,15 @@ runtime true + + com.h2database + h2 + runtime + org.projectlombok lombok - true + false org.springframework.boot diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/model/Product.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/model/Product.java index 41ce5e8..03d00ea 100644 --- a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/model/Product.java +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/model/Product.java @@ -1,45 +1,22 @@ package com.akash.learn.spring.fourth_project_simple_web.model; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; @Component +@NoArgsConstructor +@AllArgsConstructor +@Data +@Entity public class Product { + @Id private int id; private String name; private int price; - - public Product() { - } - - public Product(int id, String name, int price) { - this.id = id; - this.name = name; - this.price = price; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getPrice() { - return price; - } - - public void setPrice(int price) { - this.price = price; - } } diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/repository/ProductRepo.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/repository/ProductRepo.java new file mode 100644 index 0000000..f1aefcf --- /dev/null +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/repository/ProductRepo.java @@ -0,0 +1,9 @@ +package com.akash.learn.spring.fourth_project_simple_web.repository; + +import com.akash.learn.spring.fourth_project_simple_web.model.Product; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ProductRepo extends JpaRepository { +} diff --git a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java index 4f5bbbf..bfdf83f 100644 --- a/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java +++ b/telusko/Spring/fourth-project-simple-web/src/main/java/com/akash/learn/spring/fourth_project_simple_web/service/ProductService.java @@ -1,6 +1,8 @@ package com.akash.learn.spring.fourth_project_simple_web.service; import com.akash.learn.spring.fourth_project_simple_web.model.Product; +import com.akash.learn.spring.fourth_project_simple_web.repository.ProductRepo; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -9,41 +11,28 @@ @Service public class ProductService { - private List products = new ArrayList<>(Arrays.asList( - new Product(101, "IPhone", 50000), - new Product(102, "Google", 25000), - new Product(103, "Oneplus", 20000))); + @Autowired + ProductRepo productRepo; public List getProducts(){ - return products; + return productRepo.findAll(); } public Product getProductById(int productId){ - return products.stream().filter(p -> p.getId() == productId).findFirst().get(); + return productRepo.findById(productId).get(); } public Product createProduct(Product product) { - products.add(product); + productRepo.save(product); return product; } public Product updateProduct(int productId, Product product) { - int index = 0; - for (int i=0;i Date: Tue, 5 Nov 2024 22:04:14 +0530 Subject: [PATCH 12/18] learn/spring/project: added init setup --- telusko/Spring/project/ecom-frontend-1 | 1 + .../project/ecom-project/.gitattributes | 2 + .../Spring/project/ecom-project/.gitignore | 33 +++ telusko/Spring/project/ecom-project/mvnw | 259 ++++++++++++++++++ telusko/Spring/project/ecom-project/mvnw.cmd | 149 ++++++++++ telusko/Spring/project/ecom-project/pom.xml | 82 ++++++ .../ecom_project/EcomProjectApplication.java | 13 + .../src/main/resources/application.properties | 1 + .../EcomProjectApplicationTests.java | 13 + .../wrapper/maven-wrapper.properties | 19 ++ 10 files changed, 572 insertions(+) create mode 160000 telusko/Spring/project/ecom-frontend-1 create mode 100644 telusko/Spring/project/ecom-project/.gitattributes create mode 100644 telusko/Spring/project/ecom-project/.gitignore create mode 100644 telusko/Spring/project/ecom-project/mvnw create mode 100644 telusko/Spring/project/ecom-project/mvnw.cmd create mode 100644 telusko/Spring/project/ecom-project/pom.xml create mode 100644 telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/EcomProjectApplication.java create mode 100644 telusko/Spring/project/ecom-project/src/main/resources/application.properties create mode 100644 telusko/Spring/project/ecom-project/src/test/java/com/akash/learn/spring/ecom_project/EcomProjectApplicationTests.java create mode 100644 telusko/Spring/project/ecom-project/wrapper/maven-wrapper.properties diff --git a/telusko/Spring/project/ecom-frontend-1 b/telusko/Spring/project/ecom-frontend-1 new file mode 160000 index 0000000..09622c6 --- /dev/null +++ b/telusko/Spring/project/ecom-frontend-1 @@ -0,0 +1 @@ +Subproject commit 09622c65afdf972bff2c6d6b97878bdb9fffb03e diff --git a/telusko/Spring/project/ecom-project/.gitattributes b/telusko/Spring/project/ecom-project/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/telusko/Spring/project/ecom-project/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/telusko/Spring/project/ecom-project/.gitignore b/telusko/Spring/project/ecom-project/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/telusko/Spring/project/ecom-project/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/telusko/Spring/project/ecom-project/mvnw b/telusko/Spring/project/ecom-project/mvnw new file mode 100644 index 0000000..19529dd --- /dev/null +++ b/telusko/Spring/project/ecom-project/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/telusko/Spring/project/ecom-project/mvnw.cmd b/telusko/Spring/project/ecom-project/mvnw.cmd new file mode 100644 index 0000000..249bdf3 --- /dev/null +++ b/telusko/Spring/project/ecom-project/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/telusko/Spring/project/ecom-project/pom.xml b/telusko/Spring/project/ecom-project/pom.xml new file mode 100644 index 0000000..68b9f95 --- /dev/null +++ b/telusko/Spring/project/ecom-project/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.5 + + + com.akash.learn.spring + ecom-project + 0.0.1-SNAPSHOT + ecom-project + Demo project for Spring Boot + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + com.h2database + h2 + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/EcomProjectApplication.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/EcomProjectApplication.java new file mode 100644 index 0000000..6f4e1e3 --- /dev/null +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/EcomProjectApplication.java @@ -0,0 +1,13 @@ +package com.akash.learn.spring.ecom_project; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class EcomProjectApplication { + + public static void main(String[] args) { + SpringApplication.run(EcomProjectApplication.class, args); + } + +} diff --git a/telusko/Spring/project/ecom-project/src/main/resources/application.properties b/telusko/Spring/project/ecom-project/src/main/resources/application.properties new file mode 100644 index 0000000..7c480b2 --- /dev/null +++ b/telusko/Spring/project/ecom-project/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=ecom-project diff --git a/telusko/Spring/project/ecom-project/src/test/java/com/akash/learn/spring/ecom_project/EcomProjectApplicationTests.java b/telusko/Spring/project/ecom-project/src/test/java/com/akash/learn/spring/ecom_project/EcomProjectApplicationTests.java new file mode 100644 index 0000000..3a65db8 --- /dev/null +++ b/telusko/Spring/project/ecom-project/src/test/java/com/akash/learn/spring/ecom_project/EcomProjectApplicationTests.java @@ -0,0 +1,13 @@ +package com.akash.learn.spring.ecom_project; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class EcomProjectApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/telusko/Spring/project/ecom-project/wrapper/maven-wrapper.properties b/telusko/Spring/project/ecom-project/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..d58dfb7 --- /dev/null +++ b/telusko/Spring/project/ecom-project/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip From 0b66c5645ddc7aedb1be63b1b933ed7963d90c4a Mon Sep 17 00:00:00 2001 From: akashboora Date: Tue, 5 Nov 2024 22:15:25 +0530 Subject: [PATCH 13/18] learn/spring/project: added h2 database properties --- .../src/main/resources/application.properties | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/telusko/Spring/project/ecom-project/src/main/resources/application.properties b/telusko/Spring/project/ecom-project/src/main/resources/application.properties index 7c480b2..fe27a1c 100644 --- a/telusko/Spring/project/ecom-project/src/main/resources/application.properties +++ b/telusko/Spring/project/ecom-project/src/main/resources/application.properties @@ -1 +1,9 @@ spring.application.name=ecom-project + +spring.datasource.url=jdbc:h2:mem:akash +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=akash +spring.datasource.password=password + +spring.jpa.show-sql=true +spring.jpa.hibernate.ddl-auto=update \ No newline at end of file From d87b02003816602306b15400c3bb30b6c5af649f Mon Sep 17 00:00:00 2001 From: akashboora Date: Tue, 5 Nov 2024 22:43:58 +0530 Subject: [PATCH 14/18] learn/spring/project: added h2 database properties and get products feat --- .../controller/ProductController.java | 26 ++++++++++++++++ .../spring/ecom_project/model/Product.java | 31 +++++++++++++++++++ .../ecom_project/repo/ProductRepository.java | 9 ++++++ .../ecom_project/service/ProductService.java | 20 ++++++++++++ .../src/main/resources/application.properties | 4 ++- .../ecom-project/src/main/resources/data.sql | 13 ++++++++ 6 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java create mode 100644 telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/model/Product.java create mode 100644 telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/repo/ProductRepository.java create mode 100644 telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java create mode 100644 telusko/Spring/project/ecom-project/src/main/resources/data.sql diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java new file mode 100644 index 0000000..bcca59a --- /dev/null +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java @@ -0,0 +1,26 @@ +package com.akash.learn.spring.ecom_project.controller; + +import com.akash.learn.spring.ecom_project.model.Product; +import com.akash.learn.spring.ecom_project.service.ProductService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@CrossOrigin +@RequestMapping("/api/products") +public class ProductController { + + @Autowired + private ProductService service; + + @GetMapping("") + public List getAllProducts(){ + return service.getAllProducts(); + } + +} diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/model/Product.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/model/Product.java new file mode 100644 index 0000000..174a350 --- /dev/null +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/model/Product.java @@ -0,0 +1,31 @@ +package com.akash.learn.spring.ecom_project.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.Date; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Entity +public class Product { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + private String name; + private String description; + private String brand; + private BigDecimal price; + private String category; + private Date releaseDate; + private boolean available; + private int quantity; +} diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/repo/ProductRepository.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/repo/ProductRepository.java new file mode 100644 index 0000000..ce479d6 --- /dev/null +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/repo/ProductRepository.java @@ -0,0 +1,9 @@ +package com.akash.learn.spring.ecom_project.repo; + +import com.akash.learn.spring.ecom_project.model.Product; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ProductRepository extends JpaRepository { +} diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java new file mode 100644 index 0000000..bdeb6ba --- /dev/null +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java @@ -0,0 +1,20 @@ +package com.akash.learn.spring.ecom_project.service; + +import com.akash.learn.spring.ecom_project.model.Product; +import com.akash.learn.spring.ecom_project.repo.ProductRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class ProductService { + + @Autowired + private ProductRepository productRepository; + + + public List getAllProducts() { + return productRepository.findAll(); + } +} diff --git a/telusko/Spring/project/ecom-project/src/main/resources/application.properties b/telusko/Spring/project/ecom-project/src/main/resources/application.properties index fe27a1c..40e26c6 100644 --- a/telusko/Spring/project/ecom-project/src/main/resources/application.properties +++ b/telusko/Spring/project/ecom-project/src/main/resources/application.properties @@ -6,4 +6,6 @@ spring.datasource.username=akash spring.datasource.password=password spring.jpa.show-sql=true -spring.jpa.hibernate.ddl-auto=update \ No newline at end of file +spring.jpa.hibernate.ddl-auto=update + +spring.jpa.defer-datasource-initialization=true \ No newline at end of file diff --git a/telusko/Spring/project/ecom-project/src/main/resources/data.sql b/telusko/Spring/project/ecom-project/src/main/resources/data.sql new file mode 100644 index 0000000..9b8a456 --- /dev/null +++ b/telusko/Spring/project/ecom-project/src/main/resources/data.sql @@ -0,0 +1,13 @@ +INSERT INTO Product (name, description, brand, price, category, release_date, available, quantity) +VALUES + ('Laptop', 'A high-performance laptop for gaming and work', 'Acer', 799.99, 'Electronics', '2023-01-15', true, 10), + ('Smartphone', 'Latest Android smartphone with high-resolution display', 'Samsung', 599.99, 'Electronics', '2023-03-20', true, 25), + ('Headphones', 'Noise-cancelling over-ear headphones', 'Sony', 129.99, 'Accessories', '2022-10-10', true, 50), + ('Coffee Maker', 'Automatic coffee maker with timer function', 'Philips', 89.99, 'Home Appliances', '2021-12-01', true, 15), + ('Running Shoes', 'Lightweight running shoes for everyday use', 'Nike', 49.99, 'Fashion', '2023-05-05', true, 30), + ('Tablet', '10-inch tablet with stylus support', 'Apple', 699.99, 'Electronics', '2022-07-15', false, 0), + ('Water Bottle', 'Stainless steel water bottle, 1-liter capacity', 'Hydro Flask', 19.99, 'Accessories', '2021-08-30', true, 100), + ('Desk Lamp', 'Adjustable LED desk lamp with USB charging', 'Ikea', 39.99, 'Home Decor', '2022-04-22', true, 20), + ('Blender', 'High-power blender for smoothies and juices', 'NutriBullet', 59.99, 'Kitchen Appliances', '2022-11-18', true, 40), + ('Backpack', 'Durable backpack with laptop compartment', 'Adidas', 45.99, 'Accessories', '2022-09-10', true, 25); + From 9ecf82da55fed8a16a73d04798a6edcab5ec2f15 Mon Sep 17 00:00:00 2001 From: akashboora Date: Tue, 5 Nov 2024 22:59:14 +0530 Subject: [PATCH 15/18] learn/spring/project: added get product by id --- telusko/Spring/project/ecom-frontend-2 | 1 + .../controller/ProductController.java | 25 +++++++++++++------ .../spring/ecom_project/model/Product.java | 2 ++ .../ecom_project/service/ProductService.java | 4 +++ 4 files changed, 24 insertions(+), 8 deletions(-) create mode 160000 telusko/Spring/project/ecom-frontend-2 diff --git a/telusko/Spring/project/ecom-frontend-2 b/telusko/Spring/project/ecom-frontend-2 new file mode 160000 index 0000000..1082927 --- /dev/null +++ b/telusko/Spring/project/ecom-frontend-2 @@ -0,0 +1 @@ +Subproject commit 10829279e1fab864420f74a8c36c9f348f81a456 diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java index bcca59a..9a628f8 100644 --- a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java @@ -3,24 +3,33 @@ import com.akash.learn.spring.ecom_project.model.Product; import com.akash.learn.spring.ecom_project.service.ProductService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @CrossOrigin -@RequestMapping("/api/products") +@RequestMapping("/api") public class ProductController { @Autowired private ProductService service; - @GetMapping("") - public List getAllProducts(){ - return service.getAllProducts(); + @GetMapping("/products") + public ResponseEntity> getAllProducts(){ + return new ResponseEntity<>(service.getAllProducts(), HttpStatus.OK); + } + + @GetMapping("/product/{productId}") + public ResponseEntity getProductById(@PathVariable int productId){ + Product product = service.getProductById(productId); + if(product != null){ + return new ResponseEntity<>(product, HttpStatus.OK); + } else { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } } } diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/model/Product.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/model/Product.java index 174a350..d7e9790 100644 --- a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/model/Product.java +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/model/Product.java @@ -1,5 +1,6 @@ package com.akash.learn.spring.ecom_project.model; +import com.fasterxml.jackson.annotation.JsonFormat; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -25,6 +26,7 @@ public class Product { private String brand; private BigDecimal price; private String category; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy") private Date releaseDate; private boolean available; private int quantity; diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java index bdeb6ba..6e741d1 100644 --- a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java @@ -17,4 +17,8 @@ public class ProductService { public List getAllProducts() { return productRepository.findAll(); } + + public Product getProductById(int productId) { + return productRepository.findById(productId).orElse(null); + } } From 11473ac10b65faab2da08a809e13cfced76d4773 Mon Sep 17 00:00:00 2001 From: akashboora Date: Sun, 10 Nov 2024 18:05:10 +0530 Subject: [PATCH 16/18] learn/spring/project: added create and update for products --- telusko/Spring/project/ecom-frontend-3 | 1 + .../controller/ProductController.java | 19 +++++++++++++++++++ .../spring/ecom_project/model/Product.java | 15 ++++++++------- .../ecom_project/service/ProductService.java | 9 +++++++++ .../main/resources/{data.sql => data.sql1} | 0 5 files changed, 37 insertions(+), 7 deletions(-) create mode 160000 telusko/Spring/project/ecom-frontend-3 rename telusko/Spring/project/ecom-project/src/main/resources/{data.sql => data.sql1} (100%) diff --git a/telusko/Spring/project/ecom-frontend-3 b/telusko/Spring/project/ecom-frontend-3 new file mode 160000 index 0000000..9273883 --- /dev/null +++ b/telusko/Spring/project/ecom-frontend-3 @@ -0,0 +1 @@ +Subproject commit 9273883bb8cee451012c582eaa78db8f635ddedc diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java index 9a628f8..077a410 100644 --- a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java @@ -4,8 +4,10 @@ import com.akash.learn.spring.ecom_project.service.ProductService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -32,4 +34,21 @@ public ResponseEntity getProductById(@PathVariable int productId){ } } + @PostMapping("/product") + public ResponseEntity addProduct(@RequestPart Product product, @RequestPart MultipartFile imageFile){ + try { + Product product1 = service.addProduct(product, imageFile); + return new ResponseEntity<>(product1, HttpStatus.CREATED); + }catch (Exception e){ + return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + @GetMapping("/product/{productId}/image") + public ResponseEntity getImageByProductId(@PathVariable int productId){ + Product product = service.getProductById(productId); + byte[] imageFile = product.getImageData(); + + return ResponseEntity.ok().contentType(MediaType.valueOf(product.getImageType())).body(imageFile); + } } diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/model/Product.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/model/Product.java index d7e9790..d9381d9 100644 --- a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/model/Product.java +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/model/Product.java @@ -1,10 +1,7 @@ package com.akash.learn.spring.ecom_project.model; import com.fasterxml.jackson.annotation.JsonFormat; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -26,8 +23,12 @@ public class Product { private String brand; private BigDecimal price; private String category; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy") private Date releaseDate; - private boolean available; - private int quantity; + private boolean productAvailable; + private int stockQuantity; + + private String imageName; + private String imageType; + @Lob + private byte[] imageData; } diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java index 6e741d1..db1dd4e 100644 --- a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java @@ -4,7 +4,9 @@ import com.akash.learn.spring.ecom_project.repo.ProductRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.util.List; @Service @@ -21,4 +23,11 @@ public List getAllProducts() { public Product getProductById(int productId) { return productRepository.findById(productId).orElse(null); } + + public Product addProduct(Product product, MultipartFile imageFile) throws IOException { + product.setImageName(imageFile.getOriginalFilename()); + product.setImageType(imageFile.getContentType()); + product.setImageData(imageFile.getBytes()); + return productRepository.save(product); + } } diff --git a/telusko/Spring/project/ecom-project/src/main/resources/data.sql b/telusko/Spring/project/ecom-project/src/main/resources/data.sql1 similarity index 100% rename from telusko/Spring/project/ecom-project/src/main/resources/data.sql rename to telusko/Spring/project/ecom-project/src/main/resources/data.sql1 From 2ccebec1e45f64a0793b2397a15c4d6d5a689332 Mon Sep 17 00:00:00 2001 From: akashboora Date: Sat, 30 Nov 2024 20:46:23 +0530 Subject: [PATCH 17/18] telusko/spring/project: addded search and update functionlaity --- telusko/Spring/project/ecom-frontend-4 | 1 + telusko/Spring/project/ecom-frontend-5 | 1 + .../controller/ProductController.java | 34 +++++++++++++++++++ .../ecom_project/repo/ProductRepository.java | 10 ++++++ .../ecom_project/service/ProductService.java | 15 ++++++++ 5 files changed, 61 insertions(+) create mode 160000 telusko/Spring/project/ecom-frontend-4 create mode 160000 telusko/Spring/project/ecom-frontend-5 diff --git a/telusko/Spring/project/ecom-frontend-4 b/telusko/Spring/project/ecom-frontend-4 new file mode 160000 index 0000000..0b862cf --- /dev/null +++ b/telusko/Spring/project/ecom-frontend-4 @@ -0,0 +1 @@ +Subproject commit 0b862cf3d87219d477e81f328d0af780fc879a4f diff --git a/telusko/Spring/project/ecom-frontend-5 b/telusko/Spring/project/ecom-frontend-5 new file mode 160000 index 0000000..e9baecd --- /dev/null +++ b/telusko/Spring/project/ecom-frontend-5 @@ -0,0 +1 @@ +Subproject commit e9baecd8b0ce2279b934c5e45178fd657cdc2d6b diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java index 077a410..0dce35f 100644 --- a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/controller/ProductController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.util.List; @RestController @@ -51,4 +52,37 @@ public ResponseEntity getImageByProductId(@PathVariable int productId){ return ResponseEntity.ok().contentType(MediaType.valueOf(product.getImageType())).body(imageFile); } + + @PutMapping("/product/{productId}") + public ResponseEntity updateProduct(@PathVariable int productId, + @RequestPart Product product, + @RequestPart MultipartFile imageFile){ + Product product1 = null; + try { + product1 = service.updateProduct(productId, product, imageFile); + } catch (IOException e) { + return new ResponseEntity<>("Failed to Update", HttpStatus.BAD_REQUEST); + } + if(product1!=null) + return new ResponseEntity<>("Updated", HttpStatus.OK); + else + return new ResponseEntity<>("Failed to Update", HttpStatus.BAD_REQUEST); + + } + + @DeleteMapping("/product/{productId}") + public ResponseEntity updateProduct(@PathVariable int productId) { + Product product = service.getProductById(productId); + if(product != null) + service.deleteProduct(productId); + else + return new ResponseEntity<>("Product Not Found", HttpStatus.NOT_FOUND); + return new ResponseEntity<>("Product Deleted", HttpStatus.OK); + } + + @GetMapping("/products/search") + public ResponseEntity> searchProducts(@RequestParam String keyword){ + List products = service.searchProducts(keyword); + return new ResponseEntity<>(products, HttpStatus.OK); + } } diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/repo/ProductRepository.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/repo/ProductRepository.java index ce479d6..3413ac6 100644 --- a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/repo/ProductRepository.java +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/repo/ProductRepository.java @@ -2,8 +2,18 @@ import com.akash.learn.spring.ecom_project.model.Product; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface ProductRepository extends JpaRepository { + + @Query("SELECT p from Product p WHERE "+ + "LOWER(p.name) LIKE LOWER(CONCAT('%', :keyword, '%')) OR "+ + "LOWER(p.description) LIKE LOWER(CONCAT('%', :keyword, '%')) OR "+ + "LOWER(p.brand) LIKE LOWER(CONCAT('%', :keyword, '%')) OR "+ + "LOWER(p.category) LIKE LOWER(CONCAT('%', :keyword, '%'))") + List searchProducts(String keyword); } diff --git a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java index db1dd4e..eddb122 100644 --- a/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java +++ b/telusko/Spring/project/ecom-project/src/main/java/com/akash/learn/spring/ecom_project/service/ProductService.java @@ -30,4 +30,19 @@ public Product addProduct(Product product, MultipartFile imageFile) throws IOExc product.setImageData(imageFile.getBytes()); return productRepository.save(product); } + + public Product updateProduct(int productId, Product product, MultipartFile imageFile) throws IOException { + product.setImageName(imageFile.getOriginalFilename()); + product.setImageType(imageFile.getContentType()); + product.setImageData(imageFile.getBytes()); + return productRepository.save(product); + } + + public void deleteProduct(int productId) { + productRepository.deleteById(productId); + } + + public List searchProducts(String keyword) { + return productRepository.searchProducts(keyword); + } } From be6ec3a5391c5edca2324687cfabeaa454dd5c13 Mon Sep 17 00:00:00 2001 From: akashboora Date: Tue, 3 Dec 2024 00:11:09 +0530 Subject: [PATCH 18/18] learn/spring: added spring security --- telusko/Spring/SpringSecurity/.gitattributes | 2 + telusko/Spring/SpringSecurity/.gitignore | 33 +++ .../.mvn/wrapper/maven-wrapper.properties | 19 ++ telusko/Spring/SpringSecurity/mvnw | 259 ++++++++++++++++++ telusko/Spring/SpringSecurity/mvnw.cmd | 149 ++++++++++ telusko/Spring/SpringSecurity/pom.xml | 69 +++++ .../SpringSecurityApplication.java | 13 + .../controller/HomeController.java | 13 + .../src/main/resources/application.properties | 1 + .../SpringSecurityApplicationTests.java | 13 + 10 files changed, 571 insertions(+) create mode 100644 telusko/Spring/SpringSecurity/.gitattributes create mode 100644 telusko/Spring/SpringSecurity/.gitignore create mode 100644 telusko/Spring/SpringSecurity/.mvn/wrapper/maven-wrapper.properties create mode 100644 telusko/Spring/SpringSecurity/mvnw create mode 100644 telusko/Spring/SpringSecurity/mvnw.cmd create mode 100644 telusko/Spring/SpringSecurity/pom.xml create mode 100644 telusko/Spring/SpringSecurity/src/main/java/com/akash/learn/SpringSecurity/SpringSecurityApplication.java create mode 100644 telusko/Spring/SpringSecurity/src/main/java/com/akash/learn/SpringSecurity/controller/HomeController.java create mode 100644 telusko/Spring/SpringSecurity/src/main/resources/application.properties create mode 100644 telusko/Spring/SpringSecurity/src/test/java/com/akash/learn/SpringSecurity/SpringSecurityApplicationTests.java diff --git a/telusko/Spring/SpringSecurity/.gitattributes b/telusko/Spring/SpringSecurity/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/telusko/Spring/SpringSecurity/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/telusko/Spring/SpringSecurity/.gitignore b/telusko/Spring/SpringSecurity/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/telusko/Spring/SpringSecurity/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/telusko/Spring/SpringSecurity/.mvn/wrapper/maven-wrapper.properties b/telusko/Spring/SpringSecurity/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..d58dfb7 --- /dev/null +++ b/telusko/Spring/SpringSecurity/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip diff --git a/telusko/Spring/SpringSecurity/mvnw b/telusko/Spring/SpringSecurity/mvnw new file mode 100644 index 0000000..19529dd --- /dev/null +++ b/telusko/Spring/SpringSecurity/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/telusko/Spring/SpringSecurity/mvnw.cmd b/telusko/Spring/SpringSecurity/mvnw.cmd new file mode 100644 index 0000000..249bdf3 --- /dev/null +++ b/telusko/Spring/SpringSecurity/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/telusko/Spring/SpringSecurity/pom.xml b/telusko/Spring/SpringSecurity/pom.xml new file mode 100644 index 0000000..b39dc57 --- /dev/null +++ b/telusko/Spring/SpringSecurity/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.0 + + + com.akash.learn + SpringSecurity + 0.0.1-SNAPSHOT + SpringSecurity + Demo project for Spring Boot + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/telusko/Spring/SpringSecurity/src/main/java/com/akash/learn/SpringSecurity/SpringSecurityApplication.java b/telusko/Spring/SpringSecurity/src/main/java/com/akash/learn/SpringSecurity/SpringSecurityApplication.java new file mode 100644 index 0000000..7c6ecb5 --- /dev/null +++ b/telusko/Spring/SpringSecurity/src/main/java/com/akash/learn/SpringSecurity/SpringSecurityApplication.java @@ -0,0 +1,13 @@ +package com.akash.learn.SpringSecurity; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringSecurityApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringSecurityApplication.class, args); + } + +} diff --git a/telusko/Spring/SpringSecurity/src/main/java/com/akash/learn/SpringSecurity/controller/HomeController.java b/telusko/Spring/SpringSecurity/src/main/java/com/akash/learn/SpringSecurity/controller/HomeController.java new file mode 100644 index 0000000..0df64d7 --- /dev/null +++ b/telusko/Spring/SpringSecurity/src/main/java/com/akash/learn/SpringSecurity/controller/HomeController.java @@ -0,0 +1,13 @@ +package com.akash.learn.SpringSecurity.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HomeController { + + @GetMapping("/") + public String homePage(){ + return "Welcome to learning"; + } +} diff --git a/telusko/Spring/SpringSecurity/src/main/resources/application.properties b/telusko/Spring/SpringSecurity/src/main/resources/application.properties new file mode 100644 index 0000000..52709b9 --- /dev/null +++ b/telusko/Spring/SpringSecurity/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=SpringSecurity diff --git a/telusko/Spring/SpringSecurity/src/test/java/com/akash/learn/SpringSecurity/SpringSecurityApplicationTests.java b/telusko/Spring/SpringSecurity/src/test/java/com/akash/learn/SpringSecurity/SpringSecurityApplicationTests.java new file mode 100644 index 0000000..900ae30 --- /dev/null +++ b/telusko/Spring/SpringSecurity/src/test/java/com/akash/learn/SpringSecurity/SpringSecurityApplicationTests.java @@ -0,0 +1,13 @@ +package com.akash.learn.SpringSecurity; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SpringSecurityApplicationTests { + + @Test + void contextLoads() { + } + +}