[JAVA-13854] Half list moved (#12598)
* [JAVA-13854] added parent module * [JAVA-13854] moved apache-tapestry(submodule) to web-modules(parent) * [JAVA-13854] moved bootique(submodule) to web-modules(parent) * [JAVA-13854] moved dropwizard(submodule) to web-modules(parent) * [JAVA-13854] moved blade(submodule) to web-modules(parent) * [JAVA-13854] moved java-lite(submodule) to web-modules(parent) * [JAVA-13854] moved jooby(submodule) to web-modules(parent) * [JAVA-13854] moved linkrest(submodule) to web-modules(parent) * [JAVA-13854] moved ninja(submodule) to web-modules(parent) * [JAVA-13854] moved ratpack(submodule) to web-modules(parent) * [JAVA-13854] moved resteasy(submodule) to web-modules(parent) * [JAVA-13854] moved restx(submodule) to web-modules(parent) * [JAVA-13854] moved spark-java(submodule) to web-modules(parent) * [JAVA-13854] moved vraptor(submodule) to web-modules(parent) * [JAVA-13854] delete modules that were moved * [JAVA-13854] * [JAVA-13854] * [JAVA-13854] delete ninja submodule + moved raml(submodule) to web-modules(parent) * [JAVA-13854] moved gwt(submodule) to web-modules(parent) * [JAVA-13854] moved jakarta-ee(submodule) to web-modules(parent) * [JAVA-13854] moved javax-servlets(submodule) to web-modules(parent) * [JAVA-13854] moved javax-servlets-2(submodule) to web-modules(parent) * [JAVA-13854] moved jee-7(submodule) to web-modules(parent) * [JAVA-13854] moved play-framework(not a module) to web-modules * [JAVA-13854] fix failing test * [JAVA-13854] moved struts-2(submodule) to web-modules(parent) * [JAVA-13854] moved wicket(submodule) to web-modules(parent) * [JAVA-13854] deleted modules that were moved to web-modules * JAVA-13854 Removed moved modules from the main pom.xml Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com> Co-authored-by: Dhawal Kapil <dhawalkapil@gmail.com>
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.config;
|
||||
|
||||
import app.controllers.ProductsController;
|
||||
import org.javalite.activeweb.AbstractControllerConfig;
|
||||
import org.javalite.activeweb.AppContext;
|
||||
import org.javalite.activeweb.controller_filters.DBConnectionFilter;
|
||||
import org.javalite.activeweb.controller_filters.TimingFilter;
|
||||
|
||||
public class AppControllerConfig extends AbstractControllerConfig {
|
||||
@Override
|
||||
public void init(AppContext appContext) {
|
||||
addGlobalFilters(new TimingFilter());
|
||||
add(new DBConnectionFilter()).to(ProductsController.class);
|
||||
}
|
||||
}
|
||||
11
web-modules/java-lite/src/main/java/app/config/DbConfig.java
Normal file
11
web-modules/java-lite/src/main/java/app/config/DbConfig.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package app.config;
|
||||
|
||||
import org.javalite.activeweb.AbstractDBConfig;
|
||||
import org.javalite.activeweb.AppContext;
|
||||
|
||||
public class DbConfig extends AbstractDBConfig {
|
||||
@Override
|
||||
public void init(AppContext appContext) {
|
||||
this.configFile("/database.properties");
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package app.controllers;
|
||||
|
||||
import org.javalite.activeweb.AppController;
|
||||
|
||||
public class HomeController extends AppController {
|
||||
|
||||
public void index() {
|
||||
render("index");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package app.controllers;
|
||||
|
||||
import app.models.Product;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.javalite.activeweb.AppController;
|
||||
import org.javalite.activeweb.annotations.RESTful;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RESTful
|
||||
public class ProductsController extends AppController {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
public void index() {
|
||||
try {
|
||||
view("products", Product.findAll());
|
||||
render().contentType("application/json");
|
||||
} catch (Exception e) {
|
||||
view("message", "There was an error.", "code", 200);
|
||||
render("message");
|
||||
}
|
||||
}
|
||||
|
||||
public void create() {
|
||||
try {
|
||||
Map payload = mapper.readValue(getRequestString(), Map.class);
|
||||
Product p = new Product();
|
||||
p.fromMap(payload);
|
||||
p.saveIt();
|
||||
view("message", "Successfully saved product id " + p.get("id"), "code", 200);
|
||||
render("message");
|
||||
} catch (Exception e) {
|
||||
view("message", "There was an error.", "code", 200);
|
||||
render("message");
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
try {
|
||||
Map payload = mapper.readValue(getRequestString(), Map.class);
|
||||
String id = getId();
|
||||
Product p = Product.findById(id);
|
||||
if (p == null) {
|
||||
view("message", "Product id " + id + " not found.", "code", 200);
|
||||
render("message");
|
||||
return;
|
||||
}
|
||||
p.fromMap(payload);
|
||||
p.saveIt();
|
||||
view("message", "Successfully updated product id " + id, "code", 200);
|
||||
render("message");
|
||||
} catch (Exception e) {
|
||||
view("message", "There was an error.", "code", 200);
|
||||
render("message");
|
||||
}
|
||||
}
|
||||
|
||||
public void show() {
|
||||
try {
|
||||
String id = getId();
|
||||
Product p = Product.findById(id);
|
||||
if (p == null) {
|
||||
view("message", "Product id " + id + " not found.", "code", 200);
|
||||
render("message");
|
||||
return;
|
||||
}
|
||||
view("product", p);
|
||||
render("_product");
|
||||
} catch (Exception e) {
|
||||
view("message", "There was an error.", "code", 200);
|
||||
render("message");
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
try {
|
||||
String id = getId();
|
||||
Product p = Product.findById(id);
|
||||
if (p == null) {
|
||||
view("message", "Product id " + id + " not found.", "code", 200);
|
||||
render("message");
|
||||
return;
|
||||
}
|
||||
p.delete();
|
||||
view("message", "Successfully deleted product id " + id, "code", 200);
|
||||
render("message");
|
||||
} catch (Exception e) {
|
||||
view("message", "There was an error.", "code", 200);
|
||||
render("message");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getContentType() {
|
||||
return "application/json";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLayout() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
50
web-modules/java-lite/src/main/java/app/models/Article.java
Normal file
50
web-modules/java-lite/src/main/java/app/models/Article.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package app.models;
|
||||
|
||||
import org.javalite.activejdbc.Model;
|
||||
|
||||
public class Product extends Model {
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user