├── movies-home-page.png
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ ├── maven-wrapper.properties
│ └── MavenWrapperDownloader.java
├── src
├── main
│ ├── resources
│ │ ├── static
│ │ │ ├── images
│ │ │ │ └── movie-projector-icon.png
│ │ │ ├── index.html
│ │ │ ├── css
│ │ │ │ └── site.css
│ │ │ └── js
│ │ │ │ └── site.js
│ │ ├── templates
│ │ │ ├── error.html
│ │ │ ├── result.html
│ │ │ ├── welcome.html
│ │ │ ├── logout.html
│ │ │ ├── login.html
│ │ │ ├── seats.html
│ │ │ ├── registration.html
│ │ │ ├── screenings.html
│ │ │ └── movies.html
│ │ ├── movies.small.csv
│ │ ├── validation.properties
│ │ ├── application.properties
│ │ ├── data.sql
│ │ ├── schema.sql
│ │ └── movies.medium.csv
│ └── java
│ │ └── com
│ │ └── vaibhavsood
│ │ ├── business
│ │ ├── service
│ │ │ ├── SecurityService.java
│ │ │ ├── UserService.java
│ │ │ ├── UserServiceImpl.java
│ │ │ ├── UserDetailsServiceImpl.java
│ │ │ ├── SecurityServiceImpl.java
│ │ │ └── ScreeningService.java
│ │ └── domain
│ │ │ └── MovieScreening.java
│ │ ├── data
│ │ ├── repository
│ │ │ ├── UserRepository.java
│ │ │ ├── ScreenRepository.java
│ │ │ ├── MovieRepository.java
│ │ │ ├── TicketRepository.java
│ │ │ ├── TheatreRepository.java
│ │ │ └── ScreeningRepository.java
│ │ └── entity
│ │ │ ├── Ticket.java
│ │ │ ├── Screen.java
│ │ │ ├── User.java
│ │ │ ├── Theatre.java
│ │ │ ├── Seat.java
│ │ │ ├── Movie.java
│ │ │ └── Screening.java
│ │ ├── ReservationsApplication.java
│ │ ├── web
│ │ └── application
│ │ │ ├── SeatsController.java
│ │ │ ├── MovieController.java
│ │ │ ├── UserController.java
│ │ │ └── ScreeningController.java
│ │ ├── validator
│ │ └── UserValidator.java
│ │ ├── config
│ │ └── WebSecurityConfig.java
│ │ └── runner
│ │ └── DataLoader.java
└── test
│ └── java
│ └── com
│ └── vaibhavsood
│ ├── ReservationsApplicationTests.java
│ ├── MovieScreeningTestSuite.java
│ ├── data
│ └── repository
│ │ ├── MovieRepositoryIntegrationTest.java
│ │ ├── TheatreRepositoryIntegrationTest.java
│ │ └── ScreeningRepositoryIntegrationTest.java
│ ├── web
│ └── application
│ │ ├── ScreeningControllerIntegrationTest.java
│ │ └── ScreeningControllerUnitTest.java
│ ├── runner
│ └── DataLoaderIntegrationTest.java
│ └── business
│ └── service
│ ├── ScreeningServiceIntegrationTest.java
│ └── ScreeningServiceUnitTest.java
├── .idea
├── encodings.xml
├── vcs.xml
├── modules.xml
├── misc.xml
├── compiler.xml
└── uiDesigner.xml
├── .travis.yml
├── Dockerfile
├── .gitignore
├── README.md
├── pom.xml
├── mvnw.cmd
├── mvnw
├── MovieBookingSystem.iml
└── reservations.iml
/movies-home-page.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vaibhavsood/BookMyMovie/HEAD/movies-home-page.png
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vaibhavsood/BookMyMovie/HEAD/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
--------------------------------------------------------------------------------
/src/main/resources/static/images/movie-projector-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vaibhavsood/BookMyMovie/HEAD/src/main/resources/static/images/movie-projector-icon.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Spring test
6 |
7 |
8 | Hello World!
9 |
10 |
--------------------------------------------------------------------------------
/src/main/resources/templates/error.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Booking Error!
6 |
7 |
8 | Error! Cannot complete this booking!
9 |
10 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/business/service/SecurityService.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.business.service;
2 |
3 | public interface SecurityService {
4 | String findLoggedInUsername();
5 |
6 | void autologin(String username, String password);
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/resources/movies.small.csv:
--------------------------------------------------------------------------------
1 | movieId,title,genres
2 | 1,Toy Story (1995),Adventure|Animation|Children|Comedy|Fantasy
3 | 2,Jumanji (1995),Adventure|Children|Fantasy
4 | 3,Grumpier Old Men (1995),Comedy|Romance
5 | 4,Waiting to Exhale (1995),Comedy|Drama|Romance
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/business/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.business.service;
2 |
3 | import com.vaibhavsood.data.entity.User;
4 |
5 | public interface UserService {
6 | void save(User user);
7 |
8 | User findByUsername(String username);
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/resources/templates/result.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Result Page
5 |
6 |
7 |
8 | Dummy result page
9 |
10 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/main/resources/validation.properties:
--------------------------------------------------------------------------------
1 | NotEmpty=This field is required.
2 | Size.userForm.username=Please use between 6 and 32 characters.
3 | Duplicate.userForm.username=Someone already has that username.
4 | Size.userForm.password=Try one with at least 8 characters.
5 | Diff.userForm.passwordConfirm=These passwords don't match.
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.jpa.hibernate.ddl-auto=auto
2 |
3 | # H2
4 | spring.h2.console.enabled=true
5 | spring.h2.console.path=/h2
6 |
7 | # Datasource
8 | spring.datasource.url=jdbc:h2:mem:test
9 | spring.datasource.username=sa
10 | spring.datasource.password=
11 | spring.datasource.driver-class-name=org.h2.Driver
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/data/repository/UserRepository.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.repository;
2 |
3 | import com.vaibhavsood.data.entity.User;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 |
6 | public interface UserRepository extends JpaRepository {
7 | User findByUsername(String username);
8 | }
9 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/ReservationsApplication.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ReservationsApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(ReservationsApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/data/repository/ScreenRepository.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.repository;
2 |
3 | import com.vaibhavsood.data.entity.Screen;
4 | import org.springframework.data.repository.CrudRepository;
5 |
6 | import java.util.List;
7 |
8 | public interface ScreenRepository extends CrudRepository {
9 | public Screen findByScreenId(long screenId);
10 | public List findByTheatreId(long theatreId);
11 | }
12 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | services:
2 | - docker
3 |
4 | language: java
5 | jdk: oraclejdk8
6 |
7 | env:
8 | global:
9 | - COMMIT=${TRAVIS_COMMIT::7}
10 |
11 | script: true
12 |
13 | after_success:
14 | - docker login -u $DOCKER_USER -p $DOCKER_PASS
15 | - export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH ; fi`
16 | - docker build -t vaibhavsood/bookmymovie:$COMMIT .
17 | - docker push vaibhavsood/bookmymovie:$COMMIT
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM java:8-jdk
2 | MAINTAINER Vaibhav Sood
3 |
4 | RUN apt-get update \
5 | && apt-get install -y git
6 |
7 | RUN git clone https://github.com/vaibhavsood/BookMyMovie.git \
8 | && cd BookMyMovie \
9 | && chmod +x mvnw \
10 | && ./mvnw -DskipTests=true package
11 |
12 | ADD ./target/reservations-0.0.1-SNAPSHOT.jar /root/
13 | CMD ["java", "-jar", "/root/reservations-0.0.1-SNAPSHOT.jar"]
14 |
15 | EXPOSE 8080
16 |
--------------------------------------------------------------------------------
/src/test/java/com/vaibhavsood/ReservationsApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class ReservationsApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/data/repository/MovieRepository.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.repository;
2 |
3 | import com.vaibhavsood.data.entity.Movie;
4 | import org.springframework.data.repository.CrudRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface MovieRepository extends CrudRepository {
9 | Movie findByMovieName(String movieName);
10 | Movie findByMovieId(long movieId);
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/data/repository/TicketRepository.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.repository;
2 |
3 | import com.vaibhavsood.data.entity.Ticket;
4 | import org.springframework.data.repository.CrudRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import java.util.List;
8 |
9 | @Repository
10 | public interface TicketRepository extends CrudRepository {
11 | List findByScreeningId(long screeningId);
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/data/repository/TheatreRepository.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.repository;
2 |
3 | import com.vaibhavsood.data.entity.Theatre;
4 | import org.springframework.data.repository.CrudRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface TheatreRepository extends CrudRepository {
9 | Theatre findByTheatreId(Long theatreId);
10 | Theatre findByTheatreNameAndTheatreCity(String theatreName, String theatreCity);
11 | }
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Java template
3 | # Compiled class file
4 | *.class
5 |
6 | # Log file
7 | *.log
8 |
9 | # BlueJ files
10 | *.ctxt
11 |
12 | # Mobile Tools for Java (J2ME)
13 | .mtj.tmp/
14 |
15 | # Package Files #
16 | *.jar
17 | *.war
18 | *.nar
19 | *.ear
20 | *.zip
21 | *.tar.gz
22 | *.rar
23 |
24 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
25 | hs_err_pid*
26 |
27 | .idea/workspace.xml
28 | src/main/java/com/vaibhavsood/config/
29 | target/
30 | .idea/libraries/
31 |
--------------------------------------------------------------------------------
/src/test/java/com/vaibhavsood/MovieScreeningTestSuite.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood;
2 |
3 | import com.vaibhavsood.business.service.ScreeningServiceIntegrationTest;
4 | import com.vaibhavsood.data.repository.ScreeningRepositoryIntegrationTest;
5 | import com.vaibhavsood.web.application.ScreeningControllerIntegrationTest;
6 | import org.junit.runner.RunWith;
7 | import org.junit.runners.Suite;
8 |
9 | @RunWith(Suite.class)
10 | @Suite.SuiteClasses({ScreeningServiceIntegrationTest.class, ScreeningControllerIntegrationTest.class,
11 | ScreeningRepositoryIntegrationTest.class})
12 | public class MovieScreeningTestSuite {
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/data/repository/ScreeningRepository.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.repository;
2 |
3 | import com.vaibhavsood.data.entity.Screening;
4 | import org.springframework.data.repository.CrudRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import java.sql.Date;
8 | import java.sql.Time;
9 | import java.util.List;
10 |
11 | @Repository
12 | public interface ScreeningRepository extends CrudRepository {
13 | List findByScreeningDate(Date screeningDate);
14 | List findByMovieName(String movieName);
15 | Screening findByMovieNameAndTheatreIdAndScreeningDateAndScreeningTime(String movieName, long theatreId, Date screeningDate, Time screeningTime);
16 | }
17 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/business/service/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.business.service;
2 |
3 | import com.vaibhavsood.data.entity.User;
4 | import com.vaibhavsood.data.repository.UserRepository;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
7 | import org.springframework.stereotype.Service;
8 |
9 | @Service
10 | public class UserServiceImpl implements UserService {
11 | @Autowired
12 | private UserRepository userRepository;
13 | @Autowired
14 | private BCryptPasswordEncoder bCryptPasswordEncoder;
15 |
16 | @Override
17 | public void save(User user) {
18 | user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
19 | userRepository.save(user);
20 | }
21 |
22 | @Override
23 | public User findByUsername(String username) {
24 | return userRepository.findByUsername(username);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/data/entity/Ticket.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.entity;
2 |
3 | import javax.persistence.*;
4 |
5 | @Entity
6 | public class Ticket {
7 | @Id
8 | @Column(name = "TICKET_ID")
9 | @GeneratedValue(strategy = GenerationType.AUTO)
10 | private long ticketId;
11 | @Column(name = "SCREENING_ID")
12 | private long screeningId;
13 | @Column(name = "SEAT_NUM")
14 | private int seatNum;
15 |
16 | public long getTicketId() {
17 | return ticketId;
18 | }
19 |
20 | public void setTicketId(long ticketId) {
21 | this.ticketId = ticketId;
22 | }
23 |
24 | public long getScreeningId() {
25 | return screeningId;
26 | }
27 |
28 | public void setScreeningId(long screeningId) {
29 | this.screeningId = screeningId;
30 | }
31 |
32 | public int getSeatNum() {
33 | return seatNum;
34 | }
35 |
36 | public void setSeatNum(int seatNum) {
37 | this.seatNum = seatNum;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/data/entity/Screen.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.entity;
2 |
3 | import javax.persistence.*;
4 |
5 | @Entity
6 | @Table(name = "SCREEN")
7 | public class Screen {
8 | @Id
9 | @Column(name = "SCREEN_ID")
10 | @GeneratedValue(strategy = GenerationType.AUTO)
11 | private long screenId;
12 | @Column(name = "THEATRE_ID")
13 | private long theatreId;
14 | @Column(name = "SEATS_NUM")
15 | private int seatsNum;
16 |
17 | public long getScreenId() {
18 | return screenId;
19 | }
20 |
21 | public void setScreenId(long screenId) {
22 | this.screenId = screenId;
23 | }
24 |
25 | public long getTheatreId() {
26 | return theatreId;
27 | }
28 |
29 | public void setTheatreId(long theatreId) {
30 | this.theatreId = theatreId;
31 | }
32 |
33 | public int getSeatsNum() {
34 | return seatsNum;
35 | }
36 |
37 | public void setSeatsNum(int seatsNum) {
38 | this.seatsNum = seatsNum;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/data/entity/User.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.entity;
2 |
3 | import javax.persistence.*;
4 | import java.util.Set;
5 |
6 | @Entity
7 | @Table(name = "USER")
8 | public class User {
9 | @Id
10 | @Column(name="USER_ID")
11 | @GeneratedValue(strategy = GenerationType.AUTO)
12 | private Long id;
13 | @Column(name="USERNAME", nullable = false, unique = true)
14 | private String username;
15 | @Column(name="PASSWORD")
16 | private String password;
17 |
18 | public Long getId() {
19 | return id;
20 | }
21 |
22 | public void setId(Long id) {
23 | this.id = id;
24 | }
25 |
26 | public String getUsername() {
27 | return username;
28 | }
29 |
30 | public void setUsername(String username) {
31 | this.username = username;
32 | }
33 |
34 | public String getPassword() {
35 | return password;
36 | }
37 |
38 | public void setPassword(String password) {
39 | this.password = password;
40 | }
41 | }
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/data/entity/Theatre.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.entity;
2 |
3 | import javax.persistence.*;
4 |
5 | @Entity
6 | @Table(name = "THEATRE")
7 | public class Theatre {
8 | @Id
9 | @Column(name = "THEATRE_ID")
10 | @GeneratedValue(strategy = GenerationType.AUTO)
11 | private long theatreId;
12 | @Column(name = "THEATRE_NAME")
13 | private String theatreName;
14 | @Column(name = "THEATRE_CITY")
15 | private String theatreCity;
16 |
17 | public long getTheatreId() {
18 | return theatreId;
19 | }
20 |
21 | public void setTheatreId(long theatreId) {
22 | this.theatreId = theatreId;
23 | }
24 |
25 | public String getTheatreName() {
26 | return theatreName;
27 | }
28 |
29 | public void setTheatreName(String theatreName) {
30 | this.theatreName = theatreName;
31 | }
32 |
33 | public String getTheatreCity() {
34 | return theatreCity;
35 | }
36 |
37 | public void setTheatreCity(String theatreCity) {
38 | this.theatreCity = theatreCity;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/data/entity/Seat.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.entity;
2 |
3 | import javax.persistence.*;
4 |
5 | @Entity
6 | @Table(name = "SEAT")
7 | public class Seat {
8 | @Id
9 | @Column(name = "SEAT_ID")
10 | @GeneratedValue(strategy = GenerationType.AUTO)
11 | private long seat_id;
12 | @Column(name = "ROW_ID")
13 | private char row_id;
14 | @Column(name = "ROW_NUMBER")
15 | private int row_number;
16 | @Column(name = "SCREEN_ID")
17 | private long screen_id;
18 |
19 | public long getSeat_id() {
20 | return seat_id;
21 | }
22 |
23 | public void setSeat_id(long seat_id) {
24 | this.seat_id = seat_id;
25 | }
26 |
27 | public char getRow_id() {
28 | return row_id;
29 | }
30 |
31 | public void setRow_id(char row_id) {
32 | this.row_id = row_id;
33 | }
34 |
35 | public int getRow_number() {
36 | return row_number;
37 | }
38 |
39 | public void setRow_number(int row_number) {
40 | this.row_number = row_number;
41 | }
42 |
43 | public long getScreen_id() {
44 | return screen_id;
45 | }
46 |
47 | public void setScreen_id(long screen_id) {
48 | this.screen_id = screen_id;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/web/application/SeatsController.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.web.application;
2 |
3 | import com.vaibhavsood.business.domain.MovieScreening;
4 | import com.vaibhavsood.business.service.ScreeningService;
5 | import com.vaibhavsood.data.repository.MovieRepository;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Controller;
10 | import org.springframework.ui.Model;
11 | import org.springframework.web.bind.annotation.ModelAttribute;
12 | import org.springframework.web.bind.annotation.RequestMapping;
13 | import org.springframework.web.bind.annotation.RequestMethod;
14 | import org.springframework.web.bind.annotation.RequestParam;
15 |
16 | import javax.validation.Valid;
17 | import java.util.List;
18 |
19 | @Controller
20 | @RequestMapping("/seats")
21 | public class SeatsController {
22 | private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
23 |
24 | @RequestMapping(method = RequestMethod.GET)
25 | public String bookSeats(@RequestParam(value = "count", required = true)int seatCount, Model model) {
26 | model.addAttribute("count", seatCount);
27 | return "seats";
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/data/entity/Movie.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.entity;
2 |
3 | import javax.persistence.*;
4 |
5 | @Entity
6 | @Table(name = "MOVIE")
7 | public class Movie {
8 | @Id
9 | @Column(name = "MOVIE_NAME")
10 | private String movieName;
11 | @Column(name = "MOVIE_ID")
12 | private long movieId;
13 | @Column(name = "MOVIE_POSTER_URL")
14 | private String moviePosterUrl;
15 | @Column(name = "MOVIE_TAGS")
16 | private String movieTags;
17 |
18 | public String getMovieTags() {
19 | return movieTags;
20 | }
21 |
22 | public void setMovieTags(String movieTags) {
23 | this.movieTags = movieTags;
24 | }
25 |
26 | public String getMovieName() {
27 | return movieName;
28 | }
29 |
30 | public void setMovieName(String movieName) {
31 | this.movieName = movieName;
32 | }
33 |
34 | public long getMovieId() {
35 | return movieId;
36 | }
37 |
38 | public void setMovieId(long movieId) {
39 | this.movieId = movieId;
40 | }
41 |
42 | public String getMoviePosterUrl() {
43 | return moviePosterUrl;
44 | }
45 |
46 | public void setMoviePosterUrl(String moviePosterUrl) {
47 | this.moviePosterUrl = moviePosterUrl;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/validator/UserValidator.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.validator;
2 |
3 | import com.vaibhavsood.business.service.UserService;
4 | import com.vaibhavsood.data.entity.User;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Component;
7 | import org.springframework.validation.Errors;
8 | import org.springframework.validation.ValidationUtils;
9 | import org.springframework.validation.Validator;
10 |
11 | @Component
12 | public class UserValidator implements Validator {
13 | @Autowired
14 | private UserService userService;
15 |
16 | @Override
17 | public boolean supports(Class> aClass) {
18 | return User.class.equals(aClass);
19 | }
20 |
21 | @Override
22 | public void validate(Object o, Errors errors) {
23 | User user = (User) o;
24 |
25 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "NotEmpty");
26 | if (user.getUsername().length() < 6 || user.getUsername().length() > 32) {
27 | errors.rejectValue("username", "Size.userForm.username");
28 | }
29 | if (userService.findByUsername(user.getUsername()) != null) {
30 | errors.rejectValue("username", "Duplicate.userForm.username");
31 | }
32 |
33 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "NotEmpty");
34 | if (user.getPassword().length() < 8 || user.getPassword().length() > 32) {
35 | errors.rejectValue("password", "Size.userForm.password");
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/business/service/UserDetailsServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.business.service;
2 |
3 | import com.vaibhavsood.data.entity.User;
4 | import com.vaibhavsood.data.repository.UserRepository;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.core.GrantedAuthority;
7 | import org.springframework.security.core.userdetails.UserDetails;
8 | import org.springframework.security.core.userdetails.UserDetailsService;
9 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
10 | import org.springframework.stereotype.Service;
11 | import org.springframework.transaction.annotation.Transactional;
12 |
13 | import java.util.HashSet;
14 | import java.util.Set;
15 |
16 | @Service
17 | public class UserDetailsServiceImpl implements UserDetailsService {
18 | @Autowired
19 | private UserRepository userRepository;
20 |
21 | @Override
22 | @Transactional(readOnly = true)
23 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
24 | User user = userRepository.findByUsername(username);
25 |
26 | Set grantedAuthorities = new HashSet<>();
27 | /*Set grantedAuthorities = new HashSet<>();
28 | for (Role role : user.getRoles()){
29 | grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
30 | }*/
31 |
32 | return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), grantedAuthorities);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/test/java/com/vaibhavsood/data/repository/MovieRepositoryIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.repository;
2 |
3 | import com.vaibhavsood.data.entity.Movie;
4 | import org.junit.Ignore;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestDatabase;
9 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
10 | import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 |
13 | import static org.junit.Assert.*;
14 |
15 | @RunWith(SpringJUnit4ClassRunner.class)
16 | @DataJpaTest
17 | @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
18 | public class MovieRepositoryIntegrationTest {
19 |
20 | @Autowired
21 | MovieRepository movieRepository;
22 |
23 | @Autowired
24 | TestEntityManager testEntityManager;
25 |
26 | /*
27 | @Test
28 | @Ignore
29 | public void findByMovieName() {
30 | Movie aNewMovie = new Movie();
31 | aNewMovie.setMovieName("Pataakha");
32 | aNewMovie.setMovieLanguage("Hindi");
33 | aNewMovie.setMovieLength(180);
34 |
35 | testEntityManager.persist(aNewMovie);
36 | testEntityManager.flush();
37 |
38 | Movie foundMovie = movieRepository.findByMovieName("Pataakha");
39 |
40 | assertNotNull(foundMovie);
41 | assertEquals(foundMovie.getMovieName(), aNewMovie.getMovieName());
42 | }*/
43 | }
--------------------------------------------------------------------------------
/src/main/resources/data.sql:
--------------------------------------------------------------------------------
1 | INSERT INTO THEATRE (THEATRE_ID, THEATRE_NAME, THEATRE_CITY) VALUES (DEFAULT, 'CARNIVAL', 'PUNE');
2 | INSERT INTO THEATRE (THEATRE_ID, THEATRE_NAME, THEATRE_CITY) VALUES (DEFAULT, 'INOX', 'PUNE');
3 | INSERT INTO THEATRE (THEATRE_ID, THEATRE_NAME, THEATRE_CITY) VALUES (DEFAULT, 'PVR', 'PUNE');
4 | INSERT INTO THEATRE (THEATRE_ID, THEATRE_NAME, THEATRE_CITY) VALUES (DEFAULT, 'ALANKAR', 'PUNE');
5 | INSERT INTO THEATRE (THEATRE_ID, THEATRE_NAME, THEATRE_CITY) VALUES (DEFAULT, 'JAI GANESH', 'PUNE');
6 |
7 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 1, 100);
8 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 1, 64);
9 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 1, 25);
10 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 1, 100);
11 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 1, 100);
12 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 2, 100);
13 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 2, 100);
14 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 2, 25);
15 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 3, 100);
16 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 3, 100);
17 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 3, 25);
18 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 4, 100);
19 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 5, 100);
20 | INSERT INTO SCREEN (SCREEN_ID, THEATRE_ID, SEATS_NUM) VALUES (DEFAULT, 5, 100);
--------------------------------------------------------------------------------
/src/main/resources/schema.sql:
--------------------------------------------------------------------------------
1 | /*todo: constraint to makesure screening times dont overlap*/
2 |
3 | CREATE TABLE THEATRE (
4 | THEATRE_ID BIGINT AUTO_INCREMENT PRIMARY KEY,
5 | THEATRE_NAME VARCHAR(50) NOT NULL,
6 | THEATRE_CITY VARCHAR(20) NOT NULL
7 | );
8 |
9 | CREATE TABLE SCREEN (
10 | SCREEN_ID BIGINT AUTO_INCREMENT PRIMARY KEY,
11 | THEATRE_ID BIGINT NOT NULL REFERENCES THEATRE (THEATRE_ID),
12 | SEATS_NUM INTEGER NOT NULL
13 | );
14 |
15 | CREATE TABLE MOVIE (
16 | MOVIE_ID INTEGER PRIMARY KEY,
17 | MOVIE_NAME VARCHAR(50),
18 | MOVIE_POSTER_URL VARCHAR(500),
19 | MOVIE_TAGS VARCHAR(100)
20 | );
21 |
22 | CREATE TABLE SCREENING (
23 | SCREENING_ID BIGINT AUTO_INCREMENT PRIMARY KEY,
24 | THEATRE_ID BIGINT NOT NULL REFERENCES THEATRE (THEATRE_ID),
25 | SCREEN_ID BIGINT NOT NULL REFERENCES SCREEN (SCREEN_ID),
26 | MOVIE_NAME VARCHAR(50) NOT NULL REFERENCES MOVIE (MOVIE_NAME),
27 | SCREENING_DATE DATE NOT NULL,
28 | SCREENING_TIME TIME NOT NULL,
29 | BOOKED_TICKETS INTEGER NOT NULL,
30 | CONSTRAINT UNIQUE_SCREENING UNIQUE(THEATRE_ID, SCREEN_ID, SCREENING_DATE, SCREENING_TIME)
31 | );
32 |
33 | CREATE TABLE TICKET (
34 | TICKET_ID BIGINT AUTO_INCREMENT PRIMARY KEY,
35 | SCREENING_ID BIGINT NOT NULL REFERENCES SCREENING (SCREENING_ID),
36 | SEAT_NUM INTEGER NOT NULL,
37 | );
38 |
39 | CREATE TABLE SEAT (
40 | SEAT_ID BIGINT AUTO_INCREMENT PRIMARY KEY,
41 | ROW_ID CHAR(1) NOT NULL,
42 | ROW_NUMBER INTEGER NOT NULL,
43 | SCREEN_ID BIGINT,
44 | CONSTRAINT SEAT_FK FOREIGN KEY (SCREEN_ID) REFERENCES SCREEN (SCREEN_ID)
45 | );
46 |
47 | CREATE TABLE USER (
48 | USER_ID BIGINT AUTO_INCREMENT PRIMARY KEY,
49 | USERNAME VARCHAR(128) NOT NULL UNIQUE,
50 | PASSWORD VARCHAR(256) NOT NULL
51 | );
--------------------------------------------------------------------------------
/src/test/java/com/vaibhavsood/web/application/ScreeningControllerIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.web.application;
2 |
3 | import com.vaibhavsood.business.domain.MovieScreening;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | @RunWith(SpringJUnit4ClassRunner.class)
13 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
14 | public class ScreeningControllerIntegrationTest {
15 |
16 | @Autowired
17 | ScreeningController screeningController;
18 |
19 | @Test
20 | public void getScreenings() {
21 | }
22 |
23 | @Test
24 | public void testBookSeats() {
25 | MovieScreening aMovieScreening = new MovieScreening();
26 | aMovieScreening.setMovieName("Race 3");
27 | aMovieScreening.setScreeningDate("2018-05-25");
28 | aMovieScreening.setScreeningTime("18:00:00");
29 | aMovieScreening.setTheatreCity("PUNE");
30 | aMovieScreening.setTheatreName("INOX");
31 | aMovieScreening.setNumSeats(5);
32 |
33 | String result = screeningController.bookSeats(aMovieScreening);
34 |
35 | assertEquals(result, "result");
36 | }
37 |
38 | @Test
39 | public void testBookSeatsExceedCapacity() {
40 | /* Theatre capacity set to 100 in data.sql */
41 | MovieScreening aMovieScreening = new MovieScreening();
42 | aMovieScreening.setMovieName("Race 3");
43 | aMovieScreening.setScreeningDate("2018-05-25");
44 | aMovieScreening.setScreeningTime("18:00:00");
45 | aMovieScreening.setTheatreCity("PUNE");
46 | aMovieScreening.setTheatreName("INOX");
47 | aMovieScreening.setNumSeats(96);
48 |
49 | String result = screeningController.bookSeats(aMovieScreening);
50 |
51 | assertEquals(result, "error");
52 | }
53 | }
--------------------------------------------------------------------------------
/src/test/java/com/vaibhavsood/data/repository/TheatreRepositoryIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.repository;
2 |
3 | import com.vaibhavsood.data.entity.Theatre;
4 | import org.junit.Before;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestDatabase;
11 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
12 | import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
14 |
15 | import static org.hamcrest.Matchers.equalTo;
16 | import static org.hamcrest.Matchers.is;
17 | import static org.junit.Assert.*;
18 |
19 | @RunWith(SpringJUnit4ClassRunner.class)
20 | @DataJpaTest
21 | @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
22 | public class TheatreRepositoryIntegrationTest {
23 | @Autowired
24 | private TheatreRepository theatreRepository;
25 |
26 | @Autowired
27 | private TestEntityManager testEntityManager;
28 |
29 | @Before
30 | public void init() {
31 | Theatre aNewTheatre = new Theatre();
32 | aNewTheatre.setTheatreName("RAHUL");
33 | aNewTheatre.setTheatreCity("PUNE");
34 |
35 | testEntityManager.persist(aNewTheatre);
36 | testEntityManager.flush();
37 | }
38 |
39 | @Test
40 | public void testFindByTheatreId() {
41 | Theatre foundTheatre = theatreRepository.findByTheatreId(2L);
42 |
43 | assertNotNull(foundTheatre);
44 | assertEquals(foundTheatre.getTheatreName(), "INOX");
45 | }
46 |
47 | @Test
48 | public void testFindByTheatreNameAndTheatreCity() {
49 | Theatre foundTheatre = theatreRepository.findByTheatreNameAndTheatreCity("RAHUL", "PUNE");
50 |
51 | assertNotNull(foundTheatre);
52 | assertThat(foundTheatre.getTheatreName(), is(equalTo("RAHUL")));
53 | }
54 | }
--------------------------------------------------------------------------------
/src/main/resources/templates/welcome.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Movie Reservations
8 |
9 |
10 |
11 |
12 |
13 |
27 |
28 |
Welcome
29 |
30 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/vaibhavsood/BookMyMovie)
2 | # BookMyMovie
3 | This is a simple movie ticket booking application using Spring Boot, Spring Security and HTML/CSS/Bootstrap for the frontend.
4 |
5 | It uses the [MovieLens dataset (small)](http://files.grouplens.org/datasets/movielens/) to populate movie info
6 |
7 |
8 | 
9 |
10 | ## Running BookMyMovie locally
11 |
12 | BookMyMovie is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/). It can be run either from the command line or through an IDE or as a docker image
13 |
14 | ### Prerequisites
15 |
16 | * Java 8+
17 | * git command line tool (https://help.github.com/articles/set-up-git)
18 | * Maven
19 | * Your prefered IDE (optional but recommended, i use Intellij)
20 |
21 | ### Steps:
22 |
23 | 1) Clone the project from git
24 | ```
25 | git clone https://github.com/vaibhavsood/BookMyMovie.git
26 | ```
27 | 2a) To run from the command line:
28 | ```
29 | cd BookMyMovie
30 | ./mvnw package
31 | java -jar target/*.jar
32 | ```
33 | or run it directly from Maven using the Spring Boot Maven plugin
34 | ```
35 | cd BookMyMovie
36 | ./mvnw spring-boot:run
37 | ```
38 | 2b) To run using an IDE (Intellij):
39 | From the main menu, choose ```File->Open``` and navigate to the BookMyMovie folder cloned from step 1
40 | Right click ```ReservationsApplication``` class file and choose Run
41 |
42 | The application can then be accessed by pointing your browser to http://localhost:8080/movies
43 |
44 | 2c) The application can also be run as a docker image. To run as a docker image (docker needs to be preinstalled):
45 | ```
46 | cd BookMyMovie
47 | docker build -t bookmymovie
48 | docker run -p 8080:8080 -d bookmymovie
49 | ```
50 | Note: A prebuilt docker image is available at https://hub.docker.com/r/vaibhavsood/bookmymovie/
51 |
52 | ## Contributing
53 |
54 | This is intended to be a learning project so please feel free to fork this repo or suggest improvements!
55 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/business/domain/MovieScreening.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.business.domain;
2 |
3 | import java.util.Date;
4 |
5 | public class MovieScreening {
6 | private String movieName;
7 | private String moviePosterURL;
8 | private long theatreId;
9 | private String theatreName;
10 | private String theatreCity;
11 | private String screeningDate;
12 | private String screeningTime;
13 | private int numSeats;
14 |
15 | public String getMoviePosterURL() {
16 | return moviePosterURL;
17 | }
18 |
19 | public void setMoviePosterURL(String moviePosterURL) {
20 | this.moviePosterURL = moviePosterURL;
21 | }
22 |
23 | public int getNumSeats() {
24 | return numSeats;
25 | }
26 |
27 | public void setNumSeats(int numSeats) {
28 | this.numSeats = numSeats;
29 | }
30 |
31 | public String getScreeningDate() {
32 | return screeningDate;
33 | }
34 |
35 | public void setScreeningDate(String screeningDate) {
36 | this.screeningDate = screeningDate;
37 | }
38 |
39 | public String getScreeningTime() {
40 | return screeningTime;
41 | }
42 |
43 | public void setScreeningTime(String screeningTime) {
44 | this.screeningTime = screeningTime;
45 | }
46 |
47 | public String getMovieName() {
48 | return movieName;
49 | }
50 |
51 | public void setMovieName(String movieName) {
52 | this.movieName = movieName;
53 | }
54 |
55 | public long getTheatreId() {
56 | return theatreId;
57 | }
58 |
59 | public void setTheatreId(long theatreId) {
60 | this.theatreId = theatreId;
61 | }
62 |
63 | public String getTheatreName() {
64 | return theatreName;
65 | }
66 |
67 | public void setTheatreName(String theatreName) {
68 | this.theatreName = theatreName;
69 | }
70 |
71 | public String getTheatreCity() {
72 | return theatreCity;
73 | }
74 |
75 | public void setTheatreCity(String theatreCity) {
76 | this.theatreCity = theatreCity;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/business/service/SecurityServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.business.service;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.authentication.AuthenticationManager;
7 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
8 | import org.springframework.security.core.context.SecurityContextHolder;
9 | import org.springframework.security.core.userdetails.UserDetails;
10 | import org.springframework.security.core.userdetails.UserDetailsService;
11 | import org.springframework.stereotype.Service;
12 |
13 | @Service
14 | public class SecurityServiceImpl implements SecurityService {
15 | @Autowired
16 | private AuthenticationManager authenticationManager;
17 |
18 | @Autowired
19 | private UserDetailsService userDetailsService;
20 |
21 | private static final Logger logger = LoggerFactory.getLogger(SecurityServiceImpl.class);
22 |
23 | @Override
24 | public String findLoggedInUsername() {
25 | Object userDetails = SecurityContextHolder.getContext().getAuthentication().getDetails();
26 | if (userDetails instanceof UserDetails) {
27 | return ((UserDetails)userDetails).getUsername();
28 | }
29 |
30 | return null;
31 | }
32 |
33 | @Override
34 | public void autologin(String username, String password) {
35 | UserDetails userDetails = userDetailsService.loadUserByUsername(username);
36 | UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities());
37 |
38 | authenticationManager.authenticate(usernamePasswordAuthenticationToken);
39 |
40 | if (usernamePasswordAuthenticationToken.isAuthenticated()) {
41 | SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken);
42 | logger.debug(String.format("Auto login %s successfully!", username));
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/web/application/MovieController.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.web.application;
2 |
3 | import com.vaibhavsood.business.domain.MovieScreening;
4 | import com.vaibhavsood.business.service.ScreeningService;
5 | import com.vaibhavsood.data.entity.Movie;
6 | import com.vaibhavsood.data.entity.Screening;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.stereotype.Controller;
11 | import org.springframework.ui.Model;
12 | import org.springframework.web.bind.annotation.ModelAttribute;
13 | import org.springframework.web.bind.annotation.RequestMapping;
14 | import org.springframework.web.bind.annotation.RequestMethod;
15 | import org.springframework.web.bind.annotation.RequestParam;
16 |
17 | import javax.validation.Valid;
18 | import java.text.DateFormat;
19 | import java.text.ParseException;
20 | import java.text.SimpleDateFormat;
21 | import java.util.Date;
22 | import java.util.List;
23 | import java.util.Set;
24 |
25 | @Controller
26 | @RequestMapping("/movies")
27 | public class MovieController {
28 | private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
29 | private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
30 |
31 | @Autowired
32 | private ScreeningService screeningService;
33 |
34 | @RequestMapping(method = RequestMethod.GET)
35 | public String getMovies(@RequestParam(value = "date", required = false)String dateString, Model model) {
36 | Date date = null;
37 | if (dateString != null) {
38 | try {
39 | date = DATE_FORMAT.parse(dateString);
40 |
41 | } catch (ParseException pe) {
42 | date = new Date();
43 | }
44 | } else {
45 | date = new Date();
46 | }
47 |
48 | Set result = this.screeningService.getMoviesByDate(date);
49 | model.addAttribute("movies", result);
50 | model.addAttribute("movieBooking", new MovieScreening());
51 | return "movies";
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/config/WebSecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.config;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
9 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
10 | import org.springframework.security.core.userdetails.UserDetailsService;
11 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
12 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
13 |
14 | @Configuration
15 | @EnableWebSecurity
16 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
17 | @Autowired
18 | private UserDetailsService userDetailsService;
19 |
20 | @Bean
21 | public BCryptPasswordEncoder bCryptPasswordEncoder() {
22 | return new BCryptPasswordEncoder();
23 | }
24 |
25 | @Override
26 | protected void configure(HttpSecurity http) throws Exception {
27 | http
28 | .csrf().disable()
29 | .authorizeRequests()
30 | .antMatchers("/static/**", "/r egistration", "/movies/**").permitAll()
31 | .anyRequest().authenticated()
32 | .and()
33 | .formLogin()
34 | .defaultSuccessUrl("/movies", true)
35 | .loginPage("/login")
36 | .permitAll()
37 | .and()
38 | .logout().invalidateHttpSession(true)
39 | .clearAuthentication(true)
40 | .permitAll();
41 | }
42 |
43 | @Autowired
44 | public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
45 | auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/test/java/com/vaibhavsood/data/repository/ScreeningRepositoryIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.repository;
2 |
3 | import com.vaibhavsood.data.entity.Screening;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestDatabase;
8 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
9 | import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11 |
12 | import java.text.DateFormat;
13 | import java.text.ParseException;
14 | import java.text.SimpleDateFormat;
15 | import java.util.Date;
16 | import java.util.List;
17 |
18 | import static org.junit.Assert.*;
19 |
20 | @RunWith(SpringJUnit4ClassRunner.class)
21 | @DataJpaTest
22 | @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
23 | public class ScreeningRepositoryIntegrationTest {
24 |
25 | @Autowired
26 | ScreeningRepository screeningRepository;
27 |
28 | @Autowired
29 | TestEntityManager testEntityManager;
30 |
31 | private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
32 |
33 | @Test
34 | public void findByScreeningDate() {
35 | Date date;
36 | try {
37 | date = DATE_FORMAT.parse("2018-05-25");
38 | } catch (ParseException e) {
39 | date = new Date();
40 | }
41 |
42 | List foundScreenings = screeningRepository.findByScreeningDate(new java.sql.Date(date.getTime()));
43 |
44 | assertNotNull(foundScreenings);
45 | assertNotEquals(foundScreenings.size(), 0);
46 | }
47 |
48 | @Test
49 | public void findByMovieNameAndTheatreIdAndScreeningDateAndScreeningTime() {
50 | Screening foundScreening = screeningRepository.findByMovieNameAndTheatreIdAndScreeningDateAndScreeningTime("Deadpool 2",
51 | 1, java.sql.Date.valueOf("2018-05-25"), java.sql.Time.valueOf("10:00:00"));
52 |
53 | assertNotNull(foundScreening);
54 | assertEquals(foundScreening.getMovieName(), "Deadpool 2");
55 | }
56 | }
--------------------------------------------------------------------------------
/src/test/java/com/vaibhavsood/runner/DataLoaderIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.runner;
2 |
3 | import com.vaibhavsood.data.entity.Screening;
4 | import com.vaibhavsood.data.repository.MovieRepository;
5 | import com.vaibhavsood.data.repository.ScreenRepository;
6 | import com.vaibhavsood.data.repository.ScreeningRepository;
7 | import org.junit.Before;
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 | import org.mockito.InjectMocks;
11 | import org.mockito.Mock;
12 | import org.mockito.MockitoAnnotations;
13 | import org.mockito.runners.MockitoJUnitRunner;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.boot.test.context.SpringBootTest;
16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
17 |
18 | import java.sql.Date;
19 | import java.util.List;
20 |
21 | import static org.junit.Assert.*;
22 |
23 | @RunWith(SpringJUnit4ClassRunner.class)
24 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
25 | public class DataLoaderIntegrationTest {
26 | @Autowired
27 | private DataLoader dataLoader;
28 |
29 | @Before
30 | public void setUp() throws Exception {
31 | try {
32 | dataLoader.run(null);
33 | } catch (Exception e) {
34 | e.printStackTrace();
35 | }
36 | }
37 |
38 | @Test
39 | public void testPopulateMovieTable() {
40 | MovieRepository movieRepository = dataLoader.getMovieRepository();
41 |
42 | assertNotNull(movieRepository.findByMovieName("Toy Story"));
43 | assertEquals(movieRepository.findByMovieName("Toy Story").getMovieName(), "Toy Story");
44 | assertEquals(movieRepository.findByMovieName("Toy Story").getMoviePosterUrl(),
45 | "https://m.media-amazon.com/images/M/MV5BMDU2ZWJlMjktMTRhMy00ZTA5LWEzNDgtYmNmZTEwZTViZWJkXkEyXkFqcGdeQXVyNDQ2OTk4MzI@._V1_UX182_CR0,0,182,268_AL__QL50.jpg");
46 | }
47 |
48 | @Test
49 | public void testPopulateScreeningsTable() {
50 | ScreeningRepository screeningRepository = dataLoader.getScreeningRepository();
51 |
52 | List screenings = screeningRepository.findByScreeningDate(new Date((new java.util.Date()).getTime()));
53 | assertNotEquals(screenings.size(), 0);
54 | }
55 | }
--------------------------------------------------------------------------------
/src/main/resources/movies.medium.csv:
--------------------------------------------------------------------------------
1 | movieId,title,genres
2 | 1,Toy Story (1995),Adventure|Animation|Children|Comedy|Fantasy
3 | 2,Jumanji (1995),Adventure|Children|Fantasy
4 | 3,Grumpier Old Men (1995),Comedy|Romance
5 | 4,Waiting to Exhale (1995),Comedy|Drama|Romance
6 | 5,Father of the Bride Part II (1995),Comedy
7 | 6,Heat (1995),Action|Crime|Thriller
8 | 7,Sabrina (1995),Comedy|Romance
9 | 8,Tom and Huck (1995),Adventure|Children
10 | 9,Sudden Death (1995),Action
11 | 10,GoldenEye (1995),Action|Adventure|Thriller
12 | 11,"American President, The (1995)",Comedy|Drama|Romance
13 | 12,Dracula: Dead and Loving It (1995),Comedy|Horror
14 | 13,Balto (1995),Adventure|Animation|Children
15 | 14,Nixon (1995),Drama
16 | 15,Cutthroat Island (1995),Action|Adventure|Romance
17 | 16,Casino (1995),Crime|Drama
18 | 17,Sense and Sensibility (1995),Drama|Romance
19 | 18,Four Rooms (1995),Comedy
20 | 19,Ace Ventura: When Nature Calls (1995),Comedy
21 | 20,Money Train (1995),Action|Comedy|Crime|Drama|Thriller
22 | 21,Get Shorty (1995),Comedy|Crime|Thriller
23 | 22,Copycat (1995),Crime|Drama|Horror|Mystery|Thriller
24 | 23,Assassins (1995),Action|Crime|Thriller
25 | 24,Powder (1995),Drama|Sci-Fi
26 | 25,Leaving Las Vegas (1995),Drama|Romance
27 | 26,Othello (1995),Drama
28 | 27,Now and Then (1995),Children|Drama
29 | 28,Persuasion (1995),Drama|Romance
30 | 29,"City of Lost Children, The (Cité des enfants perdus, La) (1995)",Adventure|Drama|Fantasy|Mystery|Sci-Fi
31 | 30,Shanghai Triad (Yao a yao yao dao waipo qiao) (1995),Crime|Drama
32 | 31,Dangerous Minds (1995),Drama
33 | 32,Twelve Monkeys (a.k.a. 12 Monkeys) (1995),Mystery|Sci-Fi|Thriller
34 | 34,Babe (1995),Children|Drama
35 | 36,Dead Man Walking (1995),Crime|Drama
36 | 38,It Takes Two (1995),Children|Comedy
37 | 39,Clueless (1995),Comedy|Romance
38 | 40,"Cry, the Beloved Country (1995)",Drama
39 | 41,Richard III (1995),Drama|War
40 | 42,Dead Presidents (1995),Action|Crime|Drama
41 | 43,Restoration (1995),Drama
42 | 44,Mortal Kombat (1995),Action|Adventure|Fantasy
43 | 45,To Die For (1995),Comedy|Drama|Thriller
44 | 46,How to Make an American Quilt (1995),Drama|Romance
45 | 47,Seven (a.k.a. Se7en) (1995),Mystery|Thriller
46 | 48,Pocahontas (1995),Animation|Children|Drama|Musical|Romance
47 | 49,When Night Is Falling (1995),Drama|Romance
48 | 50,"Usual Suspects, The (1995)",Crime|Mystery|Thriller
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/web/application/UserController.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.web.application;
2 |
3 | import com.vaibhavsood.business.service.SecurityService;
4 | import com.vaibhavsood.business.service.UserService;
5 | import com.vaibhavsood.data.entity.User;
6 | import com.vaibhavsood.validator.UserValidator;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Controller;
9 | import org.springframework.ui.Model;
10 | import org.springframework.validation.BindingResult;
11 | import org.springframework.web.bind.annotation.ModelAttribute;
12 | import org.springframework.web.bind.annotation.RequestMapping;
13 | import org.springframework.web.bind.annotation.RequestMethod;
14 |
15 | @Controller
16 | public class UserController {
17 | @Autowired
18 | private UserService userService;
19 |
20 | @Autowired
21 | private SecurityService securityService;
22 |
23 | @Autowired
24 | private UserValidator userValidator;
25 |
26 | @RequestMapping(value = "/registration", method = RequestMethod.GET)
27 | public String registration(Model model) {
28 | model.addAttribute("userForm", new User());
29 |
30 | return "registration";
31 | }
32 |
33 | @RequestMapping(value = "/registration", method = RequestMethod.POST)
34 | public String registration(@ModelAttribute("userForm") User userForm, BindingResult bindingResult, Model model) {
35 | //userValidator.validate(userForm, bindingResult);
36 |
37 | //if (bindingResult.hasErrors()) {
38 | // return "registration";
39 | //}
40 |
41 | userService.save(userForm);
42 |
43 | securityService.autologin(userForm.getUsername(), userForm.getPassword());
44 |
45 | return "welcome";
46 | }
47 |
48 | @RequestMapping(value = "/login", method = RequestMethod.GET)
49 | public String login(Model model, String error, String logout) {
50 | if (error != null)
51 | model.addAttribute("error", "Your username and password is invalid.");
52 |
53 | if (logout != null)
54 | return "logout";
55 |
56 | return "login";
57 | }
58 |
59 | @RequestMapping(value = "/welcome", method = RequestMethod.GET)
60 | public String welcome(Model model) {
61 | return "welcome";
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/data/entity/Screening.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.data.entity;
2 |
3 | import javax.persistence.*;
4 | import java.sql.Date;
5 | import java.sql.Time;
6 |
7 | @Entity
8 | @Table(name = "SCREENING")
9 | public class Screening implements Cloneable {
10 | @Id
11 | @Column(name = "SCREENING_ID")
12 | @GeneratedValue(strategy = GenerationType.AUTO)
13 | private long screeningId;
14 | @Column(name = "THEATRE_ID")
15 | private long theatreId;
16 | @Column(name = "SCREEN_ID")
17 | private long screenId;
18 | @Column(name = "MOVIE_NAME")
19 | private String movieName;
20 | @Column(name = "SCREENING_DATE")
21 | private java.sql.Date screeningDate;
22 | @Column(name = "SCREENING_TIME")
23 | private java.sql.Time screeningTime;
24 | @Column(name = "BOOKED_TICKETS")
25 | private int bookedTickets;
26 |
27 | public Object clone() throws CloneNotSupportedException{
28 | return super.clone();
29 | }
30 |
31 | public int getBookedTickets() {
32 | return bookedTickets;
33 | }
34 |
35 | public void setBookedTickets(int bookedTickets) {
36 | this.bookedTickets = bookedTickets;
37 | }
38 |
39 | public long getScreeningId() {
40 | return screeningId;
41 | }
42 |
43 | public void setScreeningId(long screeningId) {
44 | this.screeningId = screeningId;
45 | }
46 |
47 | public long getTheatreId() {
48 | return theatreId;
49 | }
50 |
51 | public void setTheatreId(long theatreId) {
52 | this.theatreId = theatreId;
53 | }
54 |
55 | public long getScreenId() {
56 | return screenId;
57 | }
58 |
59 | public void setScreenId(long screenId) {
60 | this.screenId = screenId;
61 | }
62 |
63 | public String getMovieName() {
64 | return movieName;
65 | }
66 |
67 | public void setMovieName(String movieName) {
68 | this.movieName = movieName;
69 | }
70 |
71 | public Date getScreeningDate() {
72 | return screeningDate;
73 | }
74 |
75 | public void setScreeningDate(Date screeningDate) {
76 | this.screeningDate = screeningDate;
77 | }
78 |
79 | public Time getScreeningTime() {
80 | return screeningTime;
81 | }
82 |
83 | public void setScreeningTime(Time screeningTime) {
84 | this.screeningTime = screeningTime;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/resources/static/css/site.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding-top: 70px;
3 | padding-bottom: 60px;
4 | }
5 |
6 | footer{
7 | height: 50px;
8 | }
9 |
10 | .movie-card {
11 | display: flex;
12 | flex-direction: column;
13 | justify-content: flex-end;
14 | padding: 10px;
15 | align-items: stretch;
16 |
17 | .card {
18 | flex: 1 1 auto;
19 | }
20 | }
21 |
22 | .movie-cards {
23 | padding: 20px 0;
24 | display: flex;
25 | justify-content: space-around;
26 | align-items: stretch;
27 | flex-wrap: nowrap;
28 | overflow-x: auto;
29 | }
30 |
31 | ul li {
32 | display: inline-block;
33 | }
34 |
35 | .booking-seats {
36 | animation-name: show;
37 | animation-duration: 10s;
38 | animation-timing-function: linear;
39 | animation-fill-mode: forwards;
40 | margin: 10% 50%;
41 | }
42 |
43 | @keyframes show {
44 | from { visibility: visible; }
45 | to { visibility: hidden; width: 0px; height: 0px;}
46 | }
47 |
48 | .booking-success {
49 | animation-name: hide;
50 | animation-duration: 10s;
51 | animation-timing-function: linear;
52 | animation-fill-mode: forwards;
53 | visibility: hidden;
54 | opacity: 0;
55 | margin: 10% 50%;
56 | }
57 |
58 | @keyframes hide {
59 | 99% { visibility: hidden; opacity: 0;}
60 | 100% { visibility: visible; opacity: 1;}
61 | }
62 |
63 | .loader {
64 | border: 16px solid #f3f3f3; /* Light grey */
65 | border-top: 16px solid #3498db; /* Blue */
66 | border-radius: 50%;
67 | width: 120px;
68 | height: 120px;
69 | animation: spin 2s linear 5;
70 | }
71 |
72 | @keyframes spin {
73 | 0% { transform: rotate(0deg); }
74 | 100% { transform: rotate(360deg); }
75 | }
76 |
77 | .form-signin {
78 | max-width: 330px;
79 | padding: 15px;
80 | margin: 0 auto;
81 | }
82 |
83 | .form-signin .form-control {
84 | position: relative;
85 | height: auto;
86 | -webkit-box-sizing: border-box;
87 | -moz-box-sizing: border-box;
88 | box-sizing: border-box;
89 | padding: 10px;
90 | font-size: 16px;
91 | }
92 |
93 | .form-signin .form-control:focus {
94 | z-index: 2;
95 | }
96 |
97 | .form-signin input {
98 | margin-top: 10px;
99 | border-bottom-right-radius: 0;
100 | border-bottom-left-radius: 0;
101 | }
102 |
103 | .form-signin button {
104 | margin-top: 10px;
105 | }
--------------------------------------------------------------------------------
/src/test/java/com/vaibhavsood/business/service/ScreeningServiceIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.business.service;
2 |
3 | import com.vaibhavsood.business.domain.MovieScreening;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | @RunWith(SpringJUnit4ClassRunner.class)
13 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
14 | public class ScreeningServiceIntegrationTest {
15 |
16 | @Autowired
17 | ScreeningService screeningService;
18 |
19 | @Test
20 | public void testBookSeats() {
21 | MovieScreening aMovieScreening = new MovieScreening();
22 | aMovieScreening.setMovieName("Race 3");
23 | aMovieScreening.setScreeningDate("2018-05-25");
24 | aMovieScreening.setScreeningTime("18:00:00");
25 | aMovieScreening.setTheatreCity("PUNE");
26 | aMovieScreening.setTheatreName("INOX");
27 | aMovieScreening.setNumSeats(5);
28 |
29 | int expectedBookedSeats = screeningService.getBookedSeats(aMovieScreening)+5;
30 |
31 | int actualBookedSeats = screeningService.bookSeats(aMovieScreening, expectedBookedSeats);
32 |
33 | assertEquals(actualBookedSeats, expectedBookedSeats);
34 | }
35 |
36 | @Test
37 | public void testGetBookedSeats() {
38 | MovieScreening aMovieScreening = new MovieScreening();
39 | aMovieScreening.setMovieName("Race 3");
40 | aMovieScreening.setScreeningDate("2018-05-25");
41 | aMovieScreening.setScreeningTime("18:00:00");
42 | aMovieScreening.setTheatreCity("PUNE");
43 | aMovieScreening.setTheatreName("INOX");
44 |
45 | assertEquals(5, screeningService.getBookedSeats(aMovieScreening));
46 | }
47 |
48 | @Test
49 | public void testGetTotalSeats() {
50 | MovieScreening aMovieScreening = new MovieScreening();
51 | aMovieScreening.setMovieName("Race 3");
52 | aMovieScreening.setScreeningDate("2018-05-25");
53 | aMovieScreening.setScreeningTime("18:00:00");
54 | aMovieScreening.setTheatreCity("PUNE");
55 | aMovieScreening.setTheatreName("INOX");
56 |
57 | assertEquals(100, screeningService.getTotalSeats(aMovieScreening));
58 | }
59 |
60 | @Test
61 | public void getMovieScreeningsByDate() {
62 | }
63 | }
--------------------------------------------------------------------------------
/src/test/java/com/vaibhavsood/web/application/ScreeningControllerUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.web.application;
2 |
3 | import com.vaibhavsood.business.domain.MovieScreening;
4 | import com.vaibhavsood.business.service.ScreeningService;
5 | import org.junit.Ignore;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
10 | import org.springframework.boot.test.mock.mockito.MockBean;
11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 | import org.springframework.test.web.servlet.MockMvc;
13 |
14 | import java.text.DateFormat;
15 | import java.text.SimpleDateFormat;
16 |
17 | import static org.hamcrest.CoreMatchers.containsString;
18 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
19 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
20 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
21 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
22 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
23 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
24 |
25 | @RunWith(SpringJUnit4ClassRunner.class)
26 | @WebMvcTest(ScreeningController.class)
27 | public class ScreeningControllerUnitTest {
28 | private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
29 | @MockBean
30 | private ScreeningService screeningService;
31 | @Autowired
32 | private MockMvc mockMvc;
33 |
34 | @Test
35 | @Ignore
36 | public void getScreenings() throws Exception {
37 | this.mockMvc.perform(get("/screenings?date=2018-05-25")).andDo(print()).andExpect(status().isOk()).andExpect(content().string(containsString("")));
38 |
39 | }
40 |
41 | @Test
42 | public void testBookSeats() throws Exception {
43 | MovieScreening aMovieScreening = new MovieScreening();
44 | aMovieScreening.setMovieName("Pataakha");
45 | aMovieScreening.setScreeningDate("2018-09-27");
46 | aMovieScreening.setScreeningTime("21:00:00");
47 | aMovieScreening.setTheatreCity("Pune");
48 | aMovieScreening.setTheatreName("Inox");
49 | aMovieScreening.setNumSeats(500);
50 |
51 | this.mockMvc.perform(post("/screenings", aMovieScreening)).andExpect(status().isOk())
52 | .andExpect(view().name("result"));
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/resources/templates/logout.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Logout
8 |
9 |
10 |
11 |
12 |
13 |
32 |
33 |
34 |
35 | You have been successfully logged out.
36 |
37 |
Return home
38 |
39 |
40 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/web/application/ScreeningController.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.web.application;
2 |
3 | import com.vaibhavsood.business.domain.MovieScreening;
4 | import com.vaibhavsood.business.service.ScreeningService;
5 | import com.vaibhavsood.data.entity.Movie;
6 | import com.vaibhavsood.data.entity.Screening;
7 | import com.vaibhavsood.data.entity.Ticket;
8 | import com.vaibhavsood.data.repository.MovieRepository;
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.stereotype.Controller;
13 | import org.springframework.ui.Model;
14 | import org.springframework.validation.BindingResult;
15 | import org.springframework.web.bind.annotation.ModelAttribute;
16 | import org.springframework.web.bind.annotation.RequestMapping;
17 | import org.springframework.web.bind.annotation.RequestMethod;
18 | import org.springframework.web.bind.annotation.RequestParam;
19 |
20 | import javax.validation.Valid;
21 | import java.text.DateFormat;
22 | import java.text.ParseException;
23 | import java.text.SimpleDateFormat;
24 | import java.util.Date;
25 | import java.util.List;
26 | import java.util.Set;
27 |
28 | @Controller
29 | @RequestMapping("/screenings")
30 | public class ScreeningController {
31 | private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
32 |
33 | @Autowired
34 | private MovieRepository movieRepository;
35 |
36 | @Autowired
37 | private ScreeningService screeningService;
38 |
39 | @RequestMapping(method = RequestMethod.GET)
40 | public String getScreenings(@RequestParam(value = "movie", required = true)String movieString, Model model) {
41 | List result = this.screeningService.getMovieScreeningsByMovie(movieString);
42 | model.addAttribute("screenings", result);
43 | model.addAttribute("movie", movieRepository.findByMovieName(movieString));
44 | return "screenings";
45 | }
46 |
47 | @RequestMapping(method = RequestMethod.POST)
48 | public String bookSeats(@Valid @ModelAttribute MovieScreening movieBooking) {
49 |
50 | LOGGER.info(movieBooking.getMovieName());
51 | LOGGER.info(movieBooking.getTheatreCity());
52 | LOGGER.info(movieBooking.getTheatreName());
53 | LOGGER.info(movieBooking.getScreeningTime());
54 | LOGGER.info(movieBooking.getScreeningDate());
55 | LOGGER.info(Integer.toString(movieBooking.getNumSeats()));
56 |
57 | int bookedSeats = this.screeningService.getBookedSeats(movieBooking);
58 | int totalSeats = this.screeningService.getTotalSeats(movieBooking);
59 |
60 | if ((bookedSeats+movieBooking.getNumSeats()) > totalSeats)
61 | return "error";
62 |
63 | this.screeningService.bookSeats(movieBooking, bookedSeats+movieBooking.getNumSeats());
64 |
65 | return "result";
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/resources/static/js/site.js:
--------------------------------------------------------------------------------
1 | function setPicker(){
2 | $( "#datepicker" ).datepicker(
3 | { dateFormat: 'yy-mm-dd',
4 | onSelect: function(d,i) {
5 | if (d !== i.lastVal) {
6 | reloadPageForDateSelection();
7 | }
8 | }
9 | });
10 | };
11 |
12 | function getRequestParam(p){
13 | return (window.location.search.match(new RegExp('[?&]' + p + '=([^&]+)')) || [, null])[1];
14 | };
15 |
16 | function setInitialDate(){
17 | var requestDate = getRequestParam('date');
18 | if(requestDate == null){
19 | requestDate = new Date();
20 | }else{
21 | requestDate = formatDate(requestDate);
22 | }
23 | $('#datepicker').datepicker('setDate', requestDate);
24 |
25 | };
26 |
27 | function reloadPageForDateSelection(){
28 | var selectedDate = document.getElementById('datepicker').value;
29 | var redirectLink = window.location.protocol + "//" + window.location.host + window.location.pathname + '?date=' + selectedDate;
30 | console.log('Redirecting to: ' + redirectLink);
31 | window.location.href = redirectLink;
32 | };
33 |
34 | function formatDate(input) {
35 | var dateFormat = 'yyyy-mm-dd';
36 | var parts = input.match(/(\d+)/g),
37 | i = 0, fmt = {};
38 | dateFormat.replace(/(yyyy|dd|mm)/g, function(part) { fmt[part] = i++; });
39 |
40 | return new Date(parts[fmt['yyyy']], parts[fmt['mm']]-1, parts[fmt['dd']]);
41 | };
42 |
43 | function bookTickets(selectedMovie) {
44 | var redirectLink = window.location.protocol + "//" + window.location.host + "/"+ "screenings" + "?movie=" + selectedMovie;
45 | window.location.href = redirectLink;
46 | }
47 |
48 | var popoverContent = ``;
55 |
56 | $(document).ready(function(){
57 | setPicker();
58 | setInitialDate();
59 | $('[data-toggle="popover"]').popover({
60 | container: 'body',
61 | html:true,
62 | animation: true,
63 | content: popoverContent
64 | });
65 | //$(".bookButton").click(function() {
66 |
67 | //}
68 | //);
69 | });
--------------------------------------------------------------------------------
/src/main/resources/templates/login.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Login
8 |
9 |
10 |
11 |
12 |
13 |
27 |
44 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/src/main/resources/templates/seats.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Movie Reservations
8 |
9 |
10 |
11 |
12 |
13 |
14 |
36 |
37 |
Booking seats...
38 |
39 |
40 |
41 |
42 |
43 | Success! Enjoy the show!
44 |
45 |
46 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/src/main/resources/templates/registration.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Movie Reservations
8 |
9 |
10 |
11 |
12 |
13 |
30 |
42 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.frankmoley
7 | reservations
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | reservations
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.4.3.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-actuator
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-data-jpa
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-thymeleaf
39 |
40 |
41 | org.thymeleaf.extras
42 | thymeleaf-extras-springsecurity4
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-starter-web
47 |
48 |
49 | com.h2database
50 | h2
51 | runtime
52 |
53 |
54 | org.springframework.boot
55 | spring-boot-starter-test
56 | test
57 |
58 |
59 | javax.xml.bind
60 | jaxb-api
61 | 2.3.0
62 |
63 |
64 | mysql
65 | mysql-connector-java
66 |
67 |
68 | org.springframework.boot
69 | spring-boot-devtools
70 | true
71 |
72 |
73 | org.jsoup
74 | jsoup
75 | 1.11.3
76 |
77 |
78 | org.springframework.boot
79 | spring-boot-starter-security
80 |
81 |
82 |
83 |
84 |
85 | org.springframework.boot
86 | spring-boot-maven-plugin
87 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/src/test/java/com/vaibhavsood/business/service/ScreeningServiceUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.business.service;
2 |
3 | import com.vaibhavsood.business.domain.MovieScreening;
4 | import com.vaibhavsood.data.entity.Screening;
5 | import com.vaibhavsood.data.entity.Theatre;
6 | import com.vaibhavsood.data.repository.ScreeningRepository;
7 | import com.vaibhavsood.data.repository.TheatreRepository;
8 | import org.junit.Before;
9 | import org.junit.Test;
10 | import org.junit.runner.RunWith;
11 | import org.mockito.InjectMocks;
12 | import org.mockito.Mock;
13 | import org.mockito.MockitoAnnotations;
14 | import org.mockito.runners.MockitoJUnitRunner;
15 | import org.springframework.boot.test.context.SpringBootTest;
16 | import static org.junit.Assert.*;
17 | import static org.mockito.Matchers.any;
18 | import static org.mockito.Matchers.anyLong;
19 | import static org.mockito.Matchers.anyString;
20 | import static org.mockito.Mockito.when;
21 |
22 | @RunWith(MockitoJUnitRunner.class)
23 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
24 | public class ScreeningServiceUnitTest {
25 | @Mock
26 | private ScreeningRepository screeningRepository;
27 |
28 | @Mock
29 | private TheatreRepository theatreRepository;
30 |
31 | @InjectMocks
32 | private ScreeningService screeningService;
33 |
34 | @Before
35 | public void setUp() throws Exception {
36 | MockitoAnnotations.initMocks(this);
37 | }
38 |
39 | @Test
40 | public void testBookSeats() {
41 | Theatre aMockTheatre = new Theatre();
42 | aMockTheatre.setTheatreName("INOX");
43 | aMockTheatre.setTheatreCity("PUNE");
44 | aMockTheatre.setTheatreId(2);
45 |
46 | when(theatreRepository.findByTheatreNameAndTheatreCity(anyString(), anyString())).thenReturn(aMockTheatre);
47 |
48 | Screening aMockScreening = new Screening();
49 | aMockScreening.setMovieName("Race 3");
50 | aMockScreening.setScreenId(2);
51 | aMockScreening.setScreeningDate(java.sql.Date.valueOf("2018-05-25"));
52 | aMockScreening.setScreeningTime(java.sql.Time.valueOf("18:00:00"));
53 | aMockScreening.setScreeningId(1);
54 | aMockScreening.setBookedTickets(0);
55 |
56 | when(screeningRepository.findByMovieNameAndTheatreIdAndScreeningDateAndScreeningTime(any(String.class),
57 | any(Long.class), java.sql.Date.valueOf(any(String.class)), java.sql.Time.valueOf(any(String.class)))).thenReturn(aMockScreening);
58 |
59 | MovieScreening aMovieScreening = new MovieScreening();
60 |
61 | int actualBookedSeats = screeningService.bookSeats(aMovieScreening, 5);
62 |
63 | assertEquals(actualBookedSeats, 5);
64 | }
65 |
66 | @Test
67 | public void testGetBookedSeats() {
68 | MovieScreening aMovieScreening = new MovieScreening();
69 |
70 | assertEquals(5, screeningService.getBookedSeats(aMovieScreening));
71 | }
72 |
73 | @Test
74 | public void testGetTotalSeats() {
75 | MovieScreening aMovieScreening = new MovieScreening();
76 |
77 | assertEquals(100, screeningService.getTotalSeats(aMovieScreening));
78 | }
79 |
80 | @Test
81 | public void getMovieScreeningsByDate() {
82 | }
83 | }
--------------------------------------------------------------------------------
/src/main/resources/templates/screenings.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Movie Reservations
8 |
9 |
10 |
11 |
12 |
13 |
14 |
36 |
37 |
![]()
38 |
39 |
40 |
45 |
62 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/src/main/resources/templates/movies.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Movie Reservations
8 |
9 |
10 |
11 |
12 |
13 |
14 |
36 |
37 |
Movies
38 |
50 |
51 |
52 |
53 |
54 |
55 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/business/service/ScreeningService.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.business.service;
2 |
3 | import com.vaibhavsood.business.domain.MovieScreening;
4 | import com.vaibhavsood.data.entity.*;
5 | import com.vaibhavsood.data.repository.*;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | import java.text.DateFormat;
10 | import java.text.SimpleDateFormat;
11 | import java.util.*;
12 |
13 | @Service
14 | public class ScreeningService {
15 | private ScreeningRepository screeningRepository;
16 | private MovieRepository movieRepository;
17 | private TheatreRepository theatreRepository;
18 | private TicketRepository ticketRepository;
19 | private ScreenRepository screenRepository;
20 |
21 | private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
22 |
23 | public ScreeningService(ScreeningRepository screeningRepository, MovieRepository movieRepository, TheatreRepository theatreRepository
24 | , TicketRepository ticketRepository, ScreenRepository screenRepository) {
25 | this.screeningRepository = screeningRepository;
26 | this.movieRepository = movieRepository;
27 | this.theatreRepository = theatreRepository;
28 | this.ticketRepository = ticketRepository;
29 | this.screenRepository = screenRepository;
30 | }
31 |
32 | private Screening getScreening(MovieScreening movieScreening) {
33 | Theatre theatre = theatreRepository.findByTheatreNameAndTheatreCity(movieScreening.getTheatreName(), movieScreening.getTheatreCity());
34 | if (theatre == null)
35 | return null;
36 | return screeningRepository.findByMovieNameAndTheatreIdAndScreeningDateAndScreeningTime(movieScreening.getMovieName(), theatre.getTheatreId(),
37 | java.sql.Date.valueOf(movieScreening.getScreeningDate()), java.sql.Time.valueOf(movieScreening.getScreeningTime()));
38 | }
39 |
40 | public int bookSeats(MovieScreening movieScreening, int seats) {
41 | Screening screening = getScreening(movieScreening);
42 | screening.setBookedTickets(seats);
43 | screeningRepository.save(screening);
44 | return getBookedSeats(movieScreening);
45 | }
46 |
47 | public int getBookedSeats(MovieScreening movieScreening) {
48 | Screening screening = getScreening(movieScreening);
49 | return screening.getBookedTickets();
50 | }
51 |
52 | public int getTotalSeats(MovieScreening movieScreening) {
53 | Screening screening = getScreening(movieScreening);
54 | long screenId = screening.getScreenId();
55 | return screenRepository.findByScreenId(screenId).getSeatsNum();
56 | }
57 |
58 | public Set getMoviesByDate(Date date) {
59 | Iterable screenings = this.screeningRepository.findByScreeningDate(new java.sql.Date(date.getTime()));
60 | Set movies = new HashSet<>();
61 |
62 | if (screenings != null) {
63 | for (Screening screening : screenings) {
64 | Movie movie = movieRepository.findByMovieName(screening.getMovieName());
65 | movies.add(movie);
66 | }
67 | }
68 |
69 | return movies;
70 | }
71 |
72 | public List getScreeningsByMovie(String movieName) {
73 | return this.screeningRepository.findByMovieName(movieName);
74 | }
75 |
76 | public List getMovieScreeningsByMovie(String movieName) {
77 | Iterable screenings = this.screeningRepository.findByMovieName(movieName);
78 | List movieScreenings = new ArrayList<>();
79 |
80 | if (screenings != null) {
81 | for (Screening screening : screenings) {
82 | MovieScreening movieScreening = new MovieScreening();
83 | Theatre theatre = theatreRepository.findByTheatreId(screening.getTheatreId());
84 | Movie movie = movieRepository.findByMovieName(screening.getMovieName());
85 |
86 | movieScreening.setMovieName(screening.getMovieName());
87 | movieScreening.setMoviePosterURL(movie.getMoviePosterUrl());
88 |
89 | if (theatre != null) {
90 | movieScreening.setTheatreId(theatre.getTheatreId());
91 | movieScreening.setTheatreName(theatre.getTheatreName());
92 | movieScreening.setTheatreCity(theatre.getTheatreCity());
93 | }
94 |
95 |
96 | movieScreening.setScreeningDate(screening.getScreeningDate().toString());
97 | movieScreening.setScreeningTime(screening.getScreeningTime().toString());
98 |
99 | movieScreenings.add(movieScreening);
100 | }
101 | }
102 |
103 | return movieScreenings;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/.mvn/wrapper/MavenWrapperDownloader.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | import java.net.*;
21 | import java.io.*;
22 | import java.nio.channels.*;
23 | import java.util.Properties;
24 |
25 | public class MavenWrapperDownloader {
26 |
27 | /**
28 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
29 | */
30 | private static final String DEFAULT_DOWNLOAD_URL =
31 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
32 |
33 | /**
34 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
35 | * use instead of the default one.
36 | */
37 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
38 | ".mvn/wrapper/maven-wrapper.properties";
39 |
40 | /**
41 | * Path where the maven-wrapper.jar will be saved to.
42 | */
43 | private static final String MAVEN_WRAPPER_JAR_PATH =
44 | ".mvn/wrapper/maven-wrapper.jar";
45 |
46 | /**
47 | * Name of the property which should be used to override the default download url for the wrapper.
48 | */
49 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
50 |
51 | public static void main(String args[]) {
52 | System.out.println("- Downloader started");
53 | File baseDirectory = new File(args[0]);
54 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
55 |
56 | // If the maven-wrapper.properties exists, read it and check if it contains a custom
57 | // wrapperUrl parameter.
58 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
59 | String url = DEFAULT_DOWNLOAD_URL;
60 | if(mavenWrapperPropertyFile.exists()) {
61 | FileInputStream mavenWrapperPropertyFileInputStream = null;
62 | try {
63 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
64 | Properties mavenWrapperProperties = new Properties();
65 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
66 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
67 | } catch (IOException e) {
68 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
69 | } finally {
70 | try {
71 | if(mavenWrapperPropertyFileInputStream != null) {
72 | mavenWrapperPropertyFileInputStream.close();
73 | }
74 | } catch (IOException e) {
75 | // Ignore ...
76 | }
77 | }
78 | }
79 | System.out.println("- Downloading from: : " + url);
80 |
81 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
82 | if(!outputFile.getParentFile().exists()) {
83 | if(!outputFile.getParentFile().mkdirs()) {
84 | System.out.println(
85 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
86 | }
87 | }
88 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
89 | try {
90 | downloadFileFromURL(url, outputFile);
91 | System.out.println("Done");
92 | System.exit(0);
93 | } catch (Throwable e) {
94 | System.out.println("- Error downloading");
95 | e.printStackTrace();
96 | System.exit(1);
97 | }
98 | }
99 |
100 | private static void downloadFileFromURL(String urlString, File destination) throws Exception {
101 | URL website = new URL(urlString);
102 | ReadableByteChannel rbc;
103 | rbc = Channels.newChannel(website.openStream());
104 | FileOutputStream fos = new FileOutputStream(destination);
105 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
106 | fos.close();
107 | rbc.close();
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM set title of command window
39 | title %0
40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
42 |
43 | @REM set %HOME% to equivalent of $HOME
44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
45 |
46 | @REM Execute a user defined script before this one
47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
51 | :skipRcPre
52 |
53 | @setlocal
54 |
55 | set ERROR_CODE=0
56 |
57 | @REM To isolate internal variables from possible post scripts, we use another setlocal
58 | @setlocal
59 |
60 | @REM ==== START VALIDATION ====
61 | if not "%JAVA_HOME%" == "" goto OkJHome
62 |
63 | echo.
64 | echo Error: JAVA_HOME not found in your environment. >&2
65 | echo Please set the JAVA_HOME variable in your environment to match the >&2
66 | echo location of your Java installation. >&2
67 | echo.
68 | goto error
69 |
70 | :OkJHome
71 | if exist "%JAVA_HOME%\bin\java.exe" goto init
72 |
73 | echo.
74 | echo Error: JAVA_HOME is set to an invalid directory. >&2
75 | echo JAVA_HOME = "%JAVA_HOME%" >&2
76 | echo Please set the JAVA_HOME variable in your environment to match the >&2
77 | echo location of your Java installation. >&2
78 | echo.
79 | goto error
80 |
81 | @REM ==== END VALIDATION ====
82 |
83 | :init
84 |
85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86 | @REM Fallback to current working directory if not found.
87 |
88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90 |
91 | set EXEC_DIR=%CD%
92 | set WDIR=%EXEC_DIR%
93 | :findBaseDir
94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
95 | cd ..
96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
97 | set WDIR=%CD%
98 | goto findBaseDir
99 |
100 | :baseDirFound
101 | set MAVEN_PROJECTBASEDIR=%WDIR%
102 | cd "%EXEC_DIR%"
103 | goto endDetectBaseDir
104 |
105 | :baseDirNotFound
106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107 | cd "%EXEC_DIR%"
108 |
109 | :endDetectBaseDir
110 |
111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112 |
113 | @setlocal EnableExtensions EnableDelayedExpansion
114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116 |
117 | :endReadAdditionalConfig
118 |
119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122 |
123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
126 | )
127 |
128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data.
130 | if exist %WRAPPER_JAR% (
131 | echo Found %WRAPPER_JAR%
132 | ) else (
133 | echo Couldn't find %WRAPPER_JAR%, downloading it ...
134 | echo Downloading from: %DOWNLOAD_URL%
135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
136 | echo Finished downloading %WRAPPER_JAR%
137 | )
138 | @REM End of extension
139 |
140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
141 | if ERRORLEVEL 1 goto error
142 | goto end
143 |
144 | :error
145 | set ERROR_CODE=1
146 |
147 | :end
148 | @endlocal & set ERROR_CODE=%ERROR_CODE%
149 |
150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
154 | :skipRcPost
155 |
156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
158 |
159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
160 |
161 | exit /B %ERROR_CODE%
162 |
--------------------------------------------------------------------------------
/src/main/java/com/vaibhavsood/runner/DataLoader.java:
--------------------------------------------------------------------------------
1 | package com.vaibhavsood.runner;
2 |
3 | import com.vaibhavsood.data.entity.Movie;
4 | import com.vaibhavsood.data.entity.Screen;
5 | import com.vaibhavsood.data.entity.Screening;
6 | import com.vaibhavsood.data.repository.MovieRepository;
7 | import com.vaibhavsood.data.repository.ScreenRepository;
8 | import com.vaibhavsood.data.repository.ScreeningRepository;
9 | import org.jsoup.HttpStatusException;
10 | import org.jsoup.Jsoup;
11 | import org.jsoup.nodes.Document;
12 | import org.jsoup.nodes.Element;
13 | import org.slf4j.Logger;
14 | import org.slf4j.LoggerFactory;
15 | import org.springframework.beans.factory.annotation.Autowired;
16 | import org.springframework.boot.ApplicationArguments;
17 | import org.springframework.boot.ApplicationRunner;
18 | import org.springframework.core.io.ClassPathResource;
19 | import org.springframework.core.task.TaskExecutor;
20 | import org.springframework.stereotype.Component;
21 | import org.springframework.util.ResourceUtils;
22 |
23 | import java.io.*;
24 | import java.sql.Date;
25 | import java.sql.Time;
26 | import java.util.List;
27 | import java.util.Random;
28 | import java.util.concurrent.ThreadLocalRandom;
29 |
30 | @Component
31 | public class DataLoader implements ApplicationRunner {
32 | private MovieRepository movieRepository;
33 | private ScreenRepository screenRepository;
34 | private ScreeningRepository screeningRepository;
35 | private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
36 |
37 | @Autowired
38 | private TaskExecutor taskExecutor;
39 |
40 | public MovieRepository getMovieRepository() {
41 | return movieRepository;
42 | }
43 |
44 | public ScreeningRepository getScreeningRepository() {
45 | return screeningRepository;
46 | }
47 |
48 | public ScreenRepository getScreenRepository() {
49 | return screenRepository;
50 | }
51 |
52 | @Autowired
53 | public DataLoader(MovieRepository movieRepository, ScreeningRepository screeningRepository,
54 | ScreenRepository screenRepository) {
55 | this.movieRepository = movieRepository;
56 | this.screeningRepository = screeningRepository;
57 | this.screenRepository = screenRepository;
58 | }
59 |
60 | private class ProcessMovie implements Runnable {
61 | private String movieLine;
62 | private String linkLine;
63 |
64 | ProcessMovie(String movieLine, String linkLine) {
65 | this.movieLine = movieLine;
66 | this.linkLine = linkLine;
67 | }
68 |
69 | @Override
70 | public void run() {
71 | LOGGER.info(Thread.currentThread().getId() + ":" + linkLine);
72 | String[] movieInfo = movieLine.split(",");
73 |
74 | String movieName = "";
75 |
76 | for (int i = 1; i < movieInfo.length-1; i++) {
77 | if (i == movieInfo.length-2)
78 | movieName += movieInfo[i];
79 | else
80 | movieName += movieInfo[i] + ",";
81 | }
82 |
83 | Movie movie = new Movie();
84 | movie.setMovieId(Long.parseLong(movieInfo[0]));
85 | movie.setMovieName(movieName.substring(0, movieName.indexOf('(')).trim());
86 | movie.setMovieTags(movieInfo[2]);
87 |
88 | String[] linkInfo = linkLine.split(",");
89 | Document movieLensPage = null;
90 | try {
91 | movieLensPage = Jsoup.connect("https://www.imdb.com/title/tt" + linkInfo[1]).get();
92 | } catch (HttpStatusException e) {
93 | return;
94 | } catch (IOException e) {
95 | e.printStackTrace();
96 | }
97 |
98 | if (movieLensPage != null) {
99 | Element image = movieLensPage.getElementsByClass("poster").first().children().first().children().first();
100 | movie.setMoviePosterUrl(image.attr("src"));
101 | }
102 |
103 | movieRepository.save(movie);
104 | }
105 | }
106 |
107 | private void populateMovieTable() {
108 | try (BufferedReader brMovies = new BufferedReader(new InputStreamReader(new ClassPathResource("movies.medium.csv").getInputStream()));
109 | BufferedReader brLinks = new BufferedReader(new InputStreamReader(new ClassPathResource("links.csv").getInputStream()))) {
110 | String movieLine;
111 | String linkLine;
112 | brMovies.readLine(); // Skip header line
113 | brLinks.readLine(); // Skip header line
114 | while ((movieLine = brMovies.readLine()) != null) {
115 | linkLine = brLinks.readLine();
116 | //taskExecutor.execute(new ProcessMovie(movieLine, linkLine));
117 | new ProcessMovie(movieLine, linkLine).run();
118 | }
119 | } catch (FileNotFoundException e) {
120 | e.printStackTrace();
121 | } catch (IOException e) {
122 | e.printStackTrace();
123 | }
124 | }
125 |
126 | private void populateScreeningsTable() throws CloneNotSupportedException {
127 | /* schema.sql lists 5 theaters, generate 2 screenings randomly for
128 | * each screen in each theater
129 | */
130 | for (int i = 1; i <= 5; i++) {
131 | List screens = screenRepository.findByTheatreId(i);
132 | for (int j = 0; j < screens.size(); j++) {
133 | Screening screening1 = new Screening();
134 | Screening screening2 = new Screening();
135 |
136 | screening1.setTheatreId(i);
137 | screening1.setScreenId(j+1);
138 | screening2.setTheatreId(i);
139 | screening2.setScreenId(j+1);
140 |
141 | // Randomly select 2 movies from the movies db, 1 each for each screen
142 | long totalMovies = movieRepository.count();
143 | Random random = new Random();
144 |
145 | long movieId1 = random.nextInt((int)totalMovies)+1;
146 | Movie movie1 = null;
147 | while ((movie1 = movieRepository.findByMovieId(movieId1)) == null)
148 | movieId1 = random.nextInt((int)totalMovies)+1;
149 |
150 | long movieId2 = random.nextInt((int)totalMovies)+1;
151 | Movie movie2 = null;
152 | while ((movie2 = movieRepository.findByMovieId(movieId2)) == null)
153 | movieId2 = random.nextInt((int)totalMovies)+1;
154 |
155 | screening1.setMovieName(movie1.getMovieName());
156 | screening2.setMovieName(movie2.getMovieName());
157 |
158 | // Get a random date between current date and 3 days from current date
159 | Date date1 = new Date((new java.util.Date()).getTime());
160 | Date date2 = new Date(date1.getTime()+3*24*60*60*1000);
161 | Date randomDate1 = new Date(ThreadLocalRandom.current().nextLong(date1.getTime(), date2.getTime()));
162 | Date randomDate2 = new Date(ThreadLocalRandom.current().nextLong(date1.getTime(), date2.getTime()));
163 |
164 | screening1.setScreeningDate(randomDate1);
165 | screening2.setScreeningDate(randomDate2);
166 |
167 | screening1.setBookedTickets(0);
168 | screening2.setBookedTickets(0);
169 |
170 | // 2 screenings per screen
171 | screening1.setScreeningTime(Time.valueOf("10:00:00"));
172 | screeningRepository.save(screening1);
173 |
174 | Screening screening1Clone = (Screening)screening1.clone();
175 | screening1.setScreeningTime(Time.valueOf("18:00:00"));
176 | screeningRepository.save(screening1Clone);
177 |
178 | if (randomDate1.getDate() != randomDate2.getDate()) {
179 | screening2.setScreeningTime(Time.valueOf("10:00:00"));
180 | screeningRepository.save(screening2);
181 |
182 | Screening screening2Clone = (Screening)screening2.clone();
183 | screening2.setScreeningTime(Time.valueOf("18:00:00"));
184 | screeningRepository.save(screening2Clone);
185 | }
186 | }
187 | }
188 | }
189 |
190 | @Override
191 | public void run(ApplicationArguments applicationArguments) throws Exception {
192 | populateMovieTable();
193 | populateScreeningsTable();
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Mingw, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | ##########################################################################################
204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
205 | # This allows using the maven wrapper in projects that prohibit checking in binary data.
206 | ##########################################################################################
207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
208 | if [ "$MVNW_VERBOSE" = true ]; then
209 | echo "Found .mvn/wrapper/maven-wrapper.jar"
210 | fi
211 | else
212 | if [ "$MVNW_VERBOSE" = true ]; then
213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
214 | fi
215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
216 | while IFS="=" read key value; do
217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
218 | esac
219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
220 | if [ "$MVNW_VERBOSE" = true ]; then
221 | echo "Downloading from: $jarUrl"
222 | fi
223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
224 |
225 | if command -v wget > /dev/null; then
226 | if [ "$MVNW_VERBOSE" = true ]; then
227 | echo "Found wget ... using wget"
228 | fi
229 | wget "$jarUrl" -O "$wrapperJarPath"
230 | elif command -v curl > /dev/null; then
231 | if [ "$MVNW_VERBOSE" = true ]; then
232 | echo "Found curl ... using curl"
233 | fi
234 | curl -o "$wrapperJarPath" "$jarUrl"
235 | else
236 | if [ "$MVNW_VERBOSE" = true ]; then
237 | echo "Falling back to using Java to download"
238 | fi
239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
240 | if [ -e "$javaClass" ]; then
241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
242 | if [ "$MVNW_VERBOSE" = true ]; then
243 | echo " - Compiling MavenWrapperDownloader.java ..."
244 | fi
245 | # Compiling the Java class
246 | ("$JAVA_HOME/bin/javac" "$javaClass")
247 | fi
248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
249 | # Running the downloader
250 | if [ "$MVNW_VERBOSE" = true ]; then
251 | echo " - Running MavenWrapperDownloader.java ..."
252 | fi
253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
254 | fi
255 | fi
256 | fi
257 | fi
258 | ##########################################################################################
259 | # End of extension
260 | ##########################################################################################
261 |
262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
263 | if [ "$MVNW_VERBOSE" = true ]; then
264 | echo $MAVEN_PROJECTBASEDIR
265 | fi
266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
267 |
268 | # For Cygwin, switch paths to Windows format before running java
269 | if $cygwin; then
270 | [ -n "$M2_HOME" ] &&
271 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
272 | [ -n "$JAVA_HOME" ] &&
273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
274 | [ -n "$CLASSPATH" ] &&
275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
276 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
278 | fi
279 |
280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
281 |
282 | exec "$JAVACMD" \
283 | $MAVEN_OPTS \
284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
287 |
--------------------------------------------------------------------------------
/MovieBookingSystem.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/reservations.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------