Merge pull request #3 from garyrussell/INTSAMPLES-28
INTSAMPLES-28 Push-in IDTs and remove Roo from project
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
<name>Spring Integration Loan Shark Sample</name>
|
||||
<packaging>war</packaging>
|
||||
<properties>
|
||||
<roo.version>1.1.0.M3</roo.version>
|
||||
<spring.version>3.0.5.RELEASE</spring.version>
|
||||
<aspectj.version>1.6.10</aspectj.version>
|
||||
<slf4j.version>1.6.1</slf4j.version>
|
||||
@@ -24,12 +23,7 @@
|
||||
<name>Spring Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-roo-repository</id>
|
||||
<name>Spring Roo Repository</name>
|
||||
<url>http://spring-roo-repository.springsource.org/release</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<repository>
|
||||
<id>JBoss Repo</id>
|
||||
<url>https://repository.jboss.org/nexus/content/repositories/releases</url>
|
||||
<name>JBoss Repo</name>
|
||||
@@ -46,11 +40,6 @@
|
||||
<name>Spring Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-roo-repository</id>
|
||||
<name>Spring Roo Repository</name>
|
||||
<url>http://spring-roo-repository.springsource.org/release</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<dependencies>
|
||||
<!-- General dependencies for standard applications -->
|
||||
@@ -96,13 +85,6 @@
|
||||
<artifactId>flexjson</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<!-- ROO dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.roo</groupId>
|
||||
<artifactId>org.springframework.roo.annotations</artifactId>
|
||||
<version>${roo.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Spring dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
@@ -474,8 +456,6 @@
|
||||
</buildCommand>
|
||||
</additionalBuildcommands>
|
||||
<additionalProjectnatures>
|
||||
<projectnature>org.eclipse.ajdt.ui.ajnature</projectnature>
|
||||
<projectnature>com.springsource.sts.roo.core.nature</projectnature>
|
||||
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
|
||||
</additionalProjectnatures>
|
||||
</configuration>
|
||||
|
||||
@@ -1,14 +1,27 @@
|
||||
package org.springframework.integration.samples.loanbroker.loanshark.domain;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import org.springframework.roo.addon.javabean.RooJavaBean;
|
||||
import org.springframework.roo.addon.tostring.RooToString;
|
||||
import org.springframework.roo.addon.entity.RooEntity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.Version;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import flexjson.JSONDeserializer;
|
||||
import flexjson.JSONSerializer;
|
||||
|
||||
@Configurable
|
||||
@Entity
|
||||
@RooJavaBean
|
||||
@RooToString
|
||||
@RooEntity(finders = { "findLoanSharksByName" })
|
||||
public class LoanShark {
|
||||
|
||||
private String name;
|
||||
@@ -16,4 +29,146 @@ public class LoanShark {
|
||||
private Long counter;
|
||||
|
||||
private Double averageRate;
|
||||
|
||||
public String toJson() {
|
||||
return new JSONSerializer().exclude("*.class").serialize(this);
|
||||
}
|
||||
|
||||
public static LoanShark fromJsonToLoanShark(String json) {
|
||||
return new JSONDeserializer<LoanShark>().use(null, LoanShark.class).deserialize(json);
|
||||
}
|
||||
|
||||
public static String toJsonArray(Collection<LoanShark> collection) {
|
||||
return new JSONSerializer().exclude("*.class").serialize(collection);
|
||||
}
|
||||
|
||||
public static Collection<LoanShark> fromJsonArrayToLoanSharks(String json) {
|
||||
return new JSONDeserializer<List<LoanShark>>().use(null, ArrayList.class).use("values", LoanShark.class).deserialize(json);
|
||||
}
|
||||
|
||||
@PersistenceContext
|
||||
transient EntityManager entityManager;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
@Version
|
||||
@Column(name = "version")
|
||||
private Integer version;
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public void setVersion(Integer version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void persist() {
|
||||
if (this.entityManager == null) this.entityManager = entityManager();
|
||||
this.entityManager.persist(this);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void remove() {
|
||||
if (this.entityManager == null) this.entityManager = entityManager();
|
||||
if (this.entityManager.contains(this)) {
|
||||
this.entityManager.remove(this);
|
||||
} else {
|
||||
LoanShark attached = this.entityManager.find(this.getClass(), this.id);
|
||||
this.entityManager.remove(attached);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void flush() {
|
||||
if (this.entityManager == null) this.entityManager = entityManager();
|
||||
this.entityManager.flush();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public LoanShark merge() {
|
||||
if (this.entityManager == null) this.entityManager = entityManager();
|
||||
LoanShark merged = this.entityManager.merge(this);
|
||||
this.entityManager.flush();
|
||||
return merged;
|
||||
}
|
||||
|
||||
public static final EntityManager entityManager() {
|
||||
EntityManager em = new LoanShark().entityManager;
|
||||
if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
|
||||
return em;
|
||||
}
|
||||
|
||||
public static long countLoanSharks() {
|
||||
return ((Number) entityManager().createQuery("select count(o) from LoanShark o").getSingleResult()).longValue();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<LoanShark> findAllLoanSharks() {
|
||||
return entityManager().createQuery("select o from LoanShark o").getResultList();
|
||||
}
|
||||
|
||||
public static LoanShark findLoanShark(Long id) {
|
||||
if (id == null) return null;
|
||||
return entityManager().find(LoanShark.class, id);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<LoanShark> findLoanSharkEntries(int firstResult, int maxResults) {
|
||||
return entityManager().createQuery("select o from LoanShark o").setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getCounter() {
|
||||
return this.counter;
|
||||
}
|
||||
|
||||
public void setCounter(Long counter) {
|
||||
this.counter = counter;
|
||||
}
|
||||
|
||||
public Double getAverageRate() {
|
||||
return this.averageRate;
|
||||
}
|
||||
|
||||
public void setAverageRate(Double averageRate) {
|
||||
this.averageRate = averageRate;
|
||||
}
|
||||
|
||||
public static Query findLoanSharksByName(String name) {
|
||||
if (name == null || name.length() == 0) throw new IllegalArgumentException("The name argument is required");
|
||||
EntityManager em = LoanShark.entityManager();
|
||||
Query q = em.createQuery("SELECT LoanShark FROM LoanShark AS loanshark WHERE loanshark.name = :name");
|
||||
q.setParameter("name", name);
|
||||
return q;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Id: ").append(getId()).append(", ");
|
||||
sb.append("Version: ").append(getVersion()).append(", ");
|
||||
sb.append("Name: ").append(getName()).append(", ");
|
||||
sb.append("Counter: ").append(getCounter()).append(", ");
|
||||
sb.append("AverageRate: ").append(getAverageRate());
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,138 @@
|
||||
package org.springframework.integration.samples.loanbroker.loanshark.web;
|
||||
|
||||
import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
|
||||
import org.springframework.integration.samples.loanbroker.loanshark.domain.LoanShark;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.integration.samples.loanbroker.loanshark.domain.LoanShark;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@RooWebScaffold(path = "loansharks", formBackingObject = LoanShark.class)
|
||||
@RequestMapping("/loansharks")
|
||||
@Controller
|
||||
public class SharkController {
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public String create(@Valid LoanShark loanShark, BindingResult result, Model model) {
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("loanShark", loanShark);
|
||||
return "loansharks/create";
|
||||
}
|
||||
loanShark.persist();
|
||||
return "redirect:/loansharks/" + loanShark.getId();
|
||||
}
|
||||
|
||||
@RequestMapping(params = "form", method = RequestMethod.GET)
|
||||
public String createForm(Model model) {
|
||||
model.addAttribute("loanShark", new LoanShark());
|
||||
return "loansharks/create";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
public String show(@PathVariable("id") Long id, Model model) {
|
||||
model.addAttribute("loanshark", LoanShark.findLoanShark(id));
|
||||
model.addAttribute("itemId", id);
|
||||
return "loansharks/show";
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public String list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model model) {
|
||||
if (page != null || size != null) {
|
||||
int sizeNo = size == null ? 10 : size.intValue();
|
||||
model.addAttribute("loansharks", LoanShark.findLoanSharkEntries(page == null ? 0 : (page.intValue() - 1) * sizeNo, sizeNo));
|
||||
float nrOfPages = (float) LoanShark.countLoanSharks() / sizeNo;
|
||||
model.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));
|
||||
} else {
|
||||
model.addAttribute("loansharks", LoanShark.findAllLoanSharks());
|
||||
}
|
||||
return "loansharks/list";
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT)
|
||||
public String update(@Valid LoanShark loanShark, BindingResult result, Model model) {
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("loanShark", loanShark);
|
||||
return "loansharks/update";
|
||||
}
|
||||
loanShark.merge();
|
||||
return "redirect:/loansharks/" + loanShark.getId();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}", params = "form", method = RequestMethod.GET)
|
||||
public String updateForm(@PathVariable("id") Long id, Model model) {
|
||||
model.addAttribute("loanShark", LoanShark.findLoanShark(id));
|
||||
return "loansharks/update";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
public String delete(@PathVariable("id") Long id, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model model) {
|
||||
LoanShark.findLoanShark(id).remove();
|
||||
model.addAttribute("page", (page == null) ? "1" : page.toString());
|
||||
model.addAttribute("size", (size == null) ? "10" : size.toString());
|
||||
return "redirect:/loansharks?page=" + ((page == null) ? "1" : page.toString()) + "&size=" + ((size == null) ? "10" : size.toString());
|
||||
}
|
||||
|
||||
@RequestMapping(params = { "find=ByName", "form" }, method = RequestMethod.GET)
|
||||
public String findLoanSharksByNameForm(Model model) {
|
||||
return "loansharks/findLoanSharksByName";
|
||||
}
|
||||
|
||||
@RequestMapping(params = "find=ByName", method = RequestMethod.GET)
|
||||
public String findLoanSharksByName(@RequestParam("name") String name, Model model) {
|
||||
model.addAttribute("loansharks", LoanShark.findLoanSharksByName(name).getResultList());
|
||||
return "loansharks/list";
|
||||
}
|
||||
|
||||
Converter<LoanShark, String> getLoanSharkConverter() {
|
||||
return new Converter<LoanShark, String>() {
|
||||
public String convert(LoanShark loanShark) {
|
||||
return new StringBuilder().append(loanShark.getName()).append(" ").append(loanShark.getCounter()).append(" ").append(loanShark.getAverageRate()).toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
void registerConverters(WebDataBinder binder) {
|
||||
if (binder.getConversionService() instanceof GenericConversionService) {
|
||||
GenericConversionService conversionService = (GenericConversionService) binder.getConversionService();
|
||||
conversionService.addConverter(getLoanSharkConverter());
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
|
||||
@ResponseBody
|
||||
public String showJson(@PathVariable("id") Long id) {
|
||||
return LoanShark.findLoanShark(id).toJson();
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, headers = "Accept=application/json")
|
||||
public ResponseEntity<String> createFromJson(@RequestBody String json) {
|
||||
LoanShark.fromJsonToLoanShark(json).persist();
|
||||
return new ResponseEntity<String>("LoanShark created", HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@RequestMapping(headers = "Accept=application/json")
|
||||
@ResponseBody
|
||||
public String listJson() {
|
||||
return LoanShark.toJsonArray(LoanShark.findAllLoanSharks());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/jsonArray", method = RequestMethod.POST, headers = "Accept=application/json")
|
||||
public ResponseEntity<String> createFromJsonArray(@RequestBody String json) {
|
||||
for (LoanShark loanshark: LoanShark.fromJsonArrayToLoanSharks(json)) {
|
||||
loanshark.persist();
|
||||
}
|
||||
return new ResponseEntity<String>("LoanShark created", HttpStatus.CREATED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,5 @@
|
||||
#Tue Sep 07 17:11:52 EDT 2010
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.rootLogger=DEBUG, stdout
|
||||
log4j.appender.R.File=application.log
|
||||
log4j.appender.R.MaxFileSize=100KB
|
||||
log4j.appender.R.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.R.MaxBackupIndex=1
|
||||
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.R=org.apache.log4j.RollingFileAppender
|
||||
|
||||
Reference in New Issue
Block a user