BAEL-1275 Introduction to ActiveWeb (#3638)

* BAEL-1275 Introduction to active web first commit

* BAEL-1275 Added the module to parent pom

* BAEL-1275 Introduction to ActiveWeb
This commit is contained in:
Dhrubajyoti Bhattacharjee
2018-02-24 12:48:53 +05:30
committed by Grzegorz Piwowarek
parent 2399b4d817
commit d7aecc83de
18 changed files with 277 additions and 11 deletions

View File

@@ -3,7 +3,15 @@ package app.config;
import org.javalite.activeweb.AppContext;
import org.javalite.activeweb.Bootstrap;
import com.google.inject.Guice;
import com.google.inject.Injector;
import app.services.ArticleServiceModule;
public class AppBootstrap extends Bootstrap {
public void init(AppContext context) {
}
public Injector getInjector() {
return Guice.createInjector(new ArticleServiceModule());
}
}

View File

@@ -0,0 +1,28 @@
package app.controllers;
import javax.inject.Inject;
import org.javalite.activeweb.AppController;
import app.services.ArticleService;
public class ArticleController extends AppController {
@Inject
private ArticleService articleService;
public void index() {
view("articles", articleService.getArticles());
}
public void search() {
String keyword = param("key");
if (null != keyword) {
assign("article", articleService.search(keyword));
} else {
render("/common/error");
}
}
}

View File

@@ -0,0 +1,11 @@
package app.controllers;
import org.javalite.activeweb.AppController;
public class HomeController extends AppController {
public void index() {
render("index");
}
}

View File

@@ -0,0 +1,50 @@
package app.models;
public class Article {
private String title;
private String author;
private String words;
private String date;
public Article(String title, String author, String words, String date) {
super();
this.title = title;
this.author = author;
this.words = words;
this.date = date;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getWords() {
return words;
}
public void setWords(String words) {
this.words = words;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}

View File

@@ -0,0 +1,13 @@
package app.services;
import java.util.List;
import app.models.Article;
public interface ArticleService {
List<Article> getArticles();
Article search(String keyword);
}

View File

@@ -0,0 +1,34 @@
package app.services;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import app.models.Article;
public class ArticleServiceImpl implements ArticleService {
public List<Article> getArticles() {
return fetchArticles();
}
public Article search(String keyword) {
Article ar = new Article("Article with " + keyword, "baeldung", "1250", Instant.now()
.toString());
return ar;
}
private List<Article> fetchArticles() {
Article ar1 = new Article("Introduction to ActiveWeb", "baeldung", "1650", Instant.now()
.toString());
Article ar = new Article("Introduction to Mule", "baeldung", "1650", Instant.now()
.toString());
List<Article> articles = new ArrayList<Article>();
articles.add(ar);
articles.add(ar1);
return articles;
}
}

View File

@@ -0,0 +1,12 @@
package app.services;
import com.google.inject.AbstractModule;
public class ArticleServiceModule extends AbstractModule {
@Override
protected void configure() {
bind(ArticleService.class).to(ArticleServiceImpl.class)
.asEagerSingleton();
}
}