diff --git a/pom.xml b/pom.xml
index 2719a3f..a49449e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,6 +52,11 @@
spring-boot-starter-test
test
+
+ guru.springframework
+ chuck-norris-for-actuator
+ 0.0.2
+
diff --git a/src/main/java/in/co/learningville/springbootsample/bootstrap/DevBootstrap.java b/src/main/java/in/co/learningville/springbootsample/bootstrap/DevBootstrap.java
new file mode 100644
index 0000000..de3dfcb
--- /dev/null
+++ b/src/main/java/in/co/learningville/springbootsample/bootstrap/DevBootstrap.java
@@ -0,0 +1,62 @@
+package in.co.learningville.springbootsample.bootstrap;
+
+import in.co.learningville.springbootsample.model.Author;
+import in.co.learningville.springbootsample.model.Book;
+import in.co.learningville.springbootsample.model.Publisher;
+import in.co.learningville.springbootsample.repositories.AuthorRepository;
+import in.co.learningville.springbootsample.repositories.BookRepository;
+import in.co.learningville.springbootsample.repositories.PublisherRepository;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.stereotype.Component;
+
+/**
+ * Created by pra_pri on 13-Aug-17.
+ */
+@Component
+public class DevBootstrap implements ApplicationListener {
+
+ private AuthorRepository authorRepository;
+ private BookRepository bookRepository;
+ private PublisherRepository publisherRepository;
+
+
+ public DevBootstrap(AuthorRepository authorRepository, BookRepository bookRepository, PublisherRepository publisherRepository) {
+ this.authorRepository = authorRepository;
+ this.bookRepository = bookRepository;
+ this.publisherRepository = publisherRepository;
+ }
+
+ @Override
+ public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
+ initData();
+ }
+ private void initData(){
+
+ Publisher publisher1 = new Publisher();
+ publisher1.setName("Piersons");
+ publisher1.setAddress("UK");
+ publisherRepository.save(publisher1);
+
+ Author rowling = new Author("JK","Rowling");
+ Book hp1 = new Book("Harry Potter And Chambers Of Secret" , "38891829", publisher1);
+ rowling.getBooks().add(hp1);
+ hp1.getAuthors().add(rowling);
+ authorRepository.save(rowling);
+ bookRepository.save(hp1);
+
+ Publisher publisher2 = new Publisher();
+ publisher2.setName("Worx");
+ publisher2.setAddress("US");
+ publisherRepository.save(publisher2);
+
+ Author rod = new Author("Rod" , "Johnson");
+ Book noEJB = new Book("J2EE Development Without EJB" , "1231234", publisher2);
+ rod.getBooks().add(noEJB);
+ authorRepository.save(rod);
+ bookRepository.save(noEJB);
+ //noEJB.getAuthors().add(rod);
+
+ }
+
+}
diff --git a/src/main/java/in/co/learningville/springbootsample/configuration/ChuckConfiguration.java b/src/main/java/in/co/learningville/springbootsample/configuration/ChuckConfiguration.java
new file mode 100644
index 0000000..62f841b
--- /dev/null
+++ b/src/main/java/in/co/learningville/springbootsample/configuration/ChuckConfiguration.java
@@ -0,0 +1,17 @@
+package in.co.learningville.springbootsample.configuration;
+
+import guru.springframework.norris.chuck.ChuckNorrisQuotes;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Created by pra_pri on 15-Aug-17.
+ */
+@Configuration
+public class ChuckConfiguration {
+
+ @Bean
+ public ChuckNorrisQuotes chuckNorrisQuotes(){
+ return new ChuckNorrisQuotes();
+ }
+}
diff --git a/src/main/java/in/co/learningville/springbootsample/controllers/AuthorController.java b/src/main/java/in/co/learningville/springbootsample/controllers/AuthorController.java
new file mode 100644
index 0000000..2d75be7
--- /dev/null
+++ b/src/main/java/in/co/learningville/springbootsample/controllers/AuthorController.java
@@ -0,0 +1,25 @@
+package in.co.learningville.springbootsample.controllers;
+
+import in.co.learningville.springbootsample.repositories.AuthorRepository;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * Created by pra_pri on 13-Aug-17.
+ */
+@Controller
+public class AuthorController {
+
+ private AuthorRepository authorRepository;
+
+ public AuthorController(AuthorRepository authorRepository) {
+ this.authorRepository = authorRepository;
+ }
+
+ @RequestMapping("/authors")
+ public String getAuthors(Model model){
+ model.addAttribute("authors",authorRepository.findAll());
+ return "authors";
+ }
+}
diff --git a/src/main/java/in/co/learningville/springbootsample/controllers/BookController.java b/src/main/java/in/co/learningville/springbootsample/controllers/BookController.java
new file mode 100644
index 0000000..244eb86
--- /dev/null
+++ b/src/main/java/in/co/learningville/springbootsample/controllers/BookController.java
@@ -0,0 +1,28 @@
+package in.co.learningville.springbootsample.controllers;
+
+import in.co.learningville.springbootsample.repositories.BookRepository;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * Created by pra_pri on 13-Aug-17.
+ */
+@Controller
+public class BookController {
+
+ private BookRepository bookRepository;
+
+ //Constructor Based Dependency Injection
+ public BookController(BookRepository bookRepository) {
+ this.bookRepository = bookRepository;
+ }
+
+ @RequestMapping("/books")
+ public String getBooks(Model model){
+
+ model.addAttribute("books",bookRepository.findAll());
+
+ return "books";//ThymeLeaf Template Name (View)
+ }
+}
diff --git a/src/main/java/in/co/learningville/springbootsample/controllers/JokeController.java b/src/main/java/in/co/learningville/springbootsample/controllers/JokeController.java
new file mode 100644
index 0000000..7dec73c
--- /dev/null
+++ b/src/main/java/in/co/learningville/springbootsample/controllers/JokeController.java
@@ -0,0 +1,25 @@
+package in.co.learningville.springbootsample.controllers;
+
+import in.co.learningville.springbootsample.service.JokeService;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * Created by pra_pri on 13-Aug-17.
+ */
+@Controller
+public class JokeController {
+ private JokeService jokeService;
+
+ public JokeController(JokeService jokeService) {
+ this.jokeService = jokeService;
+ }
+
+ @RequestMapping({"/",""})
+ public String showJoke(Model model){
+
+ model.addAttribute("joke",jokeService.getJoke());
+ return "chuknorris";
+ }
+}
diff --git a/src/main/java/in/co/learningville/springbootsample/model/Book.java b/src/main/java/in/co/learningville/springbootsample/model/Book.java
index 8572495..e0dd3e1 100644
--- a/src/main/java/in/co/learningville/springbootsample/model/Book.java
+++ b/src/main/java/in/co/learningville/springbootsample/model/Book.java
@@ -15,7 +15,8 @@ public class Book {
private Long id;
private String title;
private String isbn;
- private String publisher;
+ @OneToOne
+ private Publisher publisher;
@ManyToMany
@JoinTable(name = "author_book", joinColumns = @JoinColumn(name = "book_id"),
@@ -25,7 +26,7 @@ public class Book {
public Book() {
}
- public Book(String title, String isbn, String publisher, Set authors) {
+ public Book(String title, String isbn, Publisher publisher, Set authors) {
this.title = title;
this.isbn = isbn;
this.publisher = publisher;
@@ -33,7 +34,7 @@ public Book(String title, String isbn, String publisher, Set authors) {
}
- public Book(String title, String isbn, String publisher) {
+ public Book(String title, String isbn, Publisher publisher) {
this.title = title;
this.isbn = isbn;
this.publisher = publisher;
@@ -63,11 +64,11 @@ public void setIsbn(String isbn) {
this.isbn = isbn;
}
- public String getPublisher() {
+ public Publisher getPublisher() {
return publisher;
}
- public void setPublisher(String publisher) {
+ public void setPublisher(Publisher publisher) {
this.publisher = publisher;
}
diff --git a/src/main/java/in/co/learningville/springbootsample/model/Publisher.java b/src/main/java/in/co/learningville/springbootsample/model/Publisher.java
new file mode 100644
index 0000000..e6add55
--- /dev/null
+++ b/src/main/java/in/co/learningville/springbootsample/model/Publisher.java
@@ -0,0 +1,52 @@
+package in.co.learningville.springbootsample.model;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+/**
+ * Created by pra_pri on 13-Aug-17.
+ */
+@Entity
+public class Publisher{
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long id;
+ private String name;
+ private String address;
+
+ public Publisher() {
+ }
+
+ public Publisher(String name, String address) {
+ this.name = name;
+ this.address = address;
+ }
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+}
diff --git a/src/main/java/in/co/learningville/springbootsample/repositories/AuthorRepository.java b/src/main/java/in/co/learningville/springbootsample/repositories/AuthorRepository.java
new file mode 100644
index 0000000..84a6af4
--- /dev/null
+++ b/src/main/java/in/co/learningville/springbootsample/repositories/AuthorRepository.java
@@ -0,0 +1,10 @@
+package in.co.learningville.springbootsample.repositories;
+
+import in.co.learningville.springbootsample.model.Author;
+import org.springframework.data.repository.CrudRepository;
+
+/**
+ * Created by pra_pri on 13-Aug-17.
+ */
+public interface AuthorRepository extends CrudRepository{
+}
diff --git a/src/main/java/in/co/learningville/springbootsample/repositories/BookRepository.java b/src/main/java/in/co/learningville/springbootsample/repositories/BookRepository.java
new file mode 100644
index 0000000..927ba7d
--- /dev/null
+++ b/src/main/java/in/co/learningville/springbootsample/repositories/BookRepository.java
@@ -0,0 +1,10 @@
+package in.co.learningville.springbootsample.repositories;
+
+import in.co.learningville.springbootsample.model.Book;
+import org.springframework.data.repository.CrudRepository;
+
+/**
+ * Created by pra_pri on 13-Aug-17.
+ */
+public interface BookRepository extends CrudRepository {
+}
diff --git a/src/main/java/in/co/learningville/springbootsample/repositories/PublisherRepository.java b/src/main/java/in/co/learningville/springbootsample/repositories/PublisherRepository.java
new file mode 100644
index 0000000..74cb26d
--- /dev/null
+++ b/src/main/java/in/co/learningville/springbootsample/repositories/PublisherRepository.java
@@ -0,0 +1,10 @@
+package in.co.learningville.springbootsample.repositories;
+
+import in.co.learningville.springbootsample.model.Publisher;
+import org.springframework.data.repository.CrudRepository;
+
+/**
+ * Created by pra_pri on 13-Aug-17.
+ */
+public interface PublisherRepository extends CrudRepository {
+}
diff --git a/src/main/java/in/co/learningville/springbootsample/service/JokeService.java b/src/main/java/in/co/learningville/springbootsample/service/JokeService.java
new file mode 100644
index 0000000..2eb915f
--- /dev/null
+++ b/src/main/java/in/co/learningville/springbootsample/service/JokeService.java
@@ -0,0 +1,8 @@
+package in.co.learningville.springbootsample.service;
+
+/**
+ * Created by pra_pri on 13-Aug-17.
+ */
+public interface JokeService {
+ String getJoke();
+}
diff --git a/src/main/java/in/co/learningville/springbootsample/service/JokeServiceImpl.java b/src/main/java/in/co/learningville/springbootsample/service/JokeServiceImpl.java
new file mode 100644
index 0000000..b6e2bd7
--- /dev/null
+++ b/src/main/java/in/co/learningville/springbootsample/service/JokeServiceImpl.java
@@ -0,0 +1,27 @@
+package in.co.learningville.springbootsample.service;
+
+import guru.springframework.norris.chuck.ChuckNorrisQuotes;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * Created by pra_pri on 13-Aug-17.
+ */
+@Service
+public class JokeServiceImpl implements JokeService {
+
+
+ private final ChuckNorrisQuotes chuckNorrisQuote;
+
+ public JokeServiceImpl(ChuckNorrisQuotes chuckNorrisQuote) {
+ this.chuckNorrisQuote = chuckNorrisQuote;
+ }
+// public JokeServiceImpl() {
+// this.chuckNorrisQuote = new ChuckNorrisQuotes();
+// }
+
+ @Override
+ public String getJoke() {
+ return chuckNorrisQuote.getRandomQuote();
+ }
+}
diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt
new file mode 100644
index 0000000..ef07d8f
--- /dev/null
+++ b/src/main/resources/banner.txt
@@ -0,0 +1,8 @@
+
+## ######## ### ######## ## ## #### ## ## ###### ## ## #### ## ## ########
+## ## ## ## ## ## ### ## ## ### ## ## ## ## ## ## ## ## ##
+## ## ## ## ## ## #### ## ## #### ## ## ## ## ## ## ## ##
+## ###### ## ## ######## ## ## ## ## ## ## ## ## #### ## ## ## ## ## ######
+## ## ######### ## ## ## #### ## ## #### ## ## ## ## ## ## ## ##
+## ## ## ## ## ## ## ### ## ## ### ## ## ## ## ## ## ## ##
+######## ######## ## ## ## ## ## ## #### ## ## ###### ### #### ######## ######## ########
diff --git a/src/main/resources/templates/authors.html b/src/main/resources/templates/authors.html
new file mode 100644
index 0000000..56a3b48
--- /dev/null
+++ b/src/main/resources/templates/authors.html
@@ -0,0 +1,25 @@
+
+
+
+
+ Learning Ville
+
+
+Author List
+
+
+
+ ID |
+ First name |
+ Last Name |
+
+
+ 12222 |
+ Sam |
+ Miller |
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/templates/books.html b/src/main/resources/templates/books.html
new file mode 100644
index 0000000..dadd3ac
--- /dev/null
+++ b/src/main/resources/templates/books.html
@@ -0,0 +1,25 @@
+
+
+
+
+ Learning Ville
+
+
+Book List
+
+
+
+ ID |
+ Title |
+ Publisher |
+
+
+ 12222 |
+ Spring Framework |
+ Princeton |
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/templates/chuknorris.html b/src/main/resources/templates/chuknorris.html
new file mode 100644
index 0000000..25c0e39
--- /dev/null
+++ b/src/main/resources/templates/chuknorris.html
@@ -0,0 +1,10 @@
+
+
+
+
+ Joke Of The Day
+
+
+
+
+
\ No newline at end of file