[lambico.archetypes] 3 new revisions pushed by lucio.be...@gmail.com on 2013-09-28 13:44 GMT

5 views
Skip to first unread message

lam...@googlecode.com

unread,
Sep 28, 2013, 9:44:35 AM9/28/13
to lambico...@googlegroups.com
3 new revisions:

Revision: 08d968f50c92
Branch: default
Author: lucio.benfante <lucio.b...@gmail.com>
Date: Sat Sep 28 13:29:19 2013 UTC
Log: Initial commit
http://code.google.com/p/lambico/source/detail?r=08d968f50c92&repo=archetypes

Revision: a3901e9d02cd
Branch: default
Author: lucio.benfante <lucio.b...@gmail.com>
Date: Sat Sep 28 13:35:58 2013 UTC
Log: Removed changing version information.
http://code.google.com/p/lambico/source/detail?r=a3901e9d02cd&repo=archetypes

Revision: e48645b2c709
Branch: default
Author: lucio.benfante <lucio.b...@gmail.com>
Date: Sat Sep 28 13:43:39 2013 UTC
Log: Added ignored file
http://code.google.com/p/lambico/source/detail?r=e48645b2c709&repo=archetypes

==============================================================================
Revision: 08d968f50c92
Branch: default
Author: lucio.benfante <lucio.b...@gmail.com>
Date: Sat Sep 28 13:29:19 2013 UTC
Log: Initial commit
http://code.google.com/p/lambico/source/detail?r=08d968f50c92&repo=archetypes

Added:
/lambico-ws-archetype/pom.xml

/lambico-ws-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
/lambico-ws-archetype/src/main/resources/archetype-resources/.gitignore
/lambico-ws-archetype/src/main/resources/archetype-resources/LICENSE_HEADER
/lambico-ws-archetype/src/main/resources/archetype-resources/core/pom.xml

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/bean/PageImpl.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/bean/PaginatedResult.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/bean/StringResult.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/bo/PersonBo.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/dao/PersonDao.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/po/Person.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/rest/SampleService.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/AuthService.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/AuthenticationHandler.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/ClientUserDetailsService.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/FakeAuthService.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/SecurityExceptionMapper.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/User.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/java/core/bo/PersonBoTest.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/java/core/rest/SampleServiceTest.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/java/core/security/SecurityCXFJAXRSFilter.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/java/core/test/BaseRSTest.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/java/core/test/BaseWSTest.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/resources/applicationContext-test.xml

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/resources/database-test.xml

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/resources/fixtures/Person.yml

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/resources/org/lambico/ws/archetype/template/core/rest/client-beans-test.xml

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/resources/org/lambico/ws/archetype/template/core/service/client-beans-test.xml

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/resources/simplelogger.properties
/lambico-ws-archetype/src/main/resources/archetype-resources/pom.xml
/lambico-ws-archetype/src/main/resources/archetype-resources/server/pom.xml

/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/java/server/filter/UserServletFilter.java

/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/java/server/security/ClientAuthenticationManager.java

/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/resources/logback.xml

/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/webapp/META-INF/context.xml

/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/webapp/WEB-INF/applicationContext.xml

/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/webapp/WEB-INF/beans.xml

/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/webapp/WEB-INF/database.xml

/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/webapp/WEB-INF/web.xml

/lambico-ws-archetype/src/test/resources/projects/basic/archetype.properties
/lambico-ws-archetype/src/test/resources/projects/basic/goal.txt

/lambico-ws-archetype/src/test/resources/projects/basic/reference/.gitignore

/lambico-ws-archetype/src/test/resources/projects/basic/reference/LICENSE_HEADER

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/pom.xml

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/bean/PageImpl.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/bean/PaginatedResult.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/bean/StringResult.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/bo/PersonBo.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/dao/PersonDao.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/po/Person.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/rest/SampleService.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/security/AuthService.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/security/AuthenticationHandler.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/security/ClientUserDetailsService.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/security/FakeAuthService.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/security/SecurityExceptionMapper.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/security/User.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/test/java/org/lambico/ws/archetype/template/core/bo/PersonBoTest.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/test/java/org/lambico/ws/archetype/template/core/rest/SampleServiceTest.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/test/java/org/lambico/ws/archetype/template/core/security/SecurityCXFJAXRSFilter.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/test/java/org/lambico/ws/archetype/template/core/test/BaseRSTest.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/test/java/org/lambico/ws/archetype/template/core/test/BaseWSTest.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/test/resources/applicationContext-test.xml

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/test/resources/database-test.xml

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/test/resources/fixtures/Person.yml

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/test/resources/org/lambico/ws/archetype/template/core/rest/client-beans-test.xml

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/test/resources/org/lambico/ws/archetype/template/core/service/client-beans-test.xml

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/test/resources/simplelogger.properties
/lambico-ws-archetype/src/test/resources/projects/basic/reference/pom.xml

/lambico-ws-archetype/src/test/resources/projects/basic/reference/server/pom.xml

/lambico-ws-archetype/src/test/resources/projects/basic/reference/server/src/main/java/org/lambico/ws/archetype/template/server/filter/UserServletFilter.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/server/src/main/java/org/lambico/ws/archetype/template/server/security/ClientAuthenticationManager.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/server/src/main/resources/logback.xml

/lambico-ws-archetype/src/test/resources/projects/basic/reference/server/src/main/webapp/META-INF/context.xml

/lambico-ws-archetype/src/test/resources/projects/basic/reference/server/src/main/webapp/WEB-INF/applicationContext.xml

/lambico-ws-archetype/src/test/resources/projects/basic/reference/server/src/main/webapp/WEB-INF/beans.xml

/lambico-ws-archetype/src/test/resources/projects/basic/reference/server/src/main/webapp/WEB-INF/database.xml

/lambico-ws-archetype/src/test/resources/projects/basic/reference/server/src/main/webapp/WEB-INF/web.xml

=======================================
--- /dev/null
+++ /lambico-ws-archetype/pom.xml Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-ws-archetype</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>maven-archetype</packaging>
+
+ <name>lambico-ws-archetype</name>
+
+ <build>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.archetype</groupId>
+ <artifactId>archetype-packaging</artifactId>
+ <version>2.2</version>
+ </extension>
+ </extensions>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <url>http://www.lambico.org</url>
+</project>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archetype-descriptor
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0
http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
name="lambico-ws-archetype-parent"
+
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <fileSets>
+ <fileSet encoding="UTF-8">
+ <directory></directory>
+ <includes>
+ <include>.gitignore</include>
+ <include>LICENSE_HEADER</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+ <modules>
+ <module id="core" dir="core" name="core">
+ <fileSets>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/test/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>src/test/resources</directory>
+ <includes>
+ <include>**/*.xml</include>
+ <include>**/*.properties</include>
+ </includes>
+ </fileSet>
+ <fileSet encoding="UTF-8">
+ <directory>src/test/resources</directory>
+ <includes>
+ <include>**/*.yml</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+ </module>
+ <module id="server" dir="server" name="server">
+ <fileSets>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>src/main/webapp</directory>
+ <includes>
+ <include>**/*.xml</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.xml</include>
+ <include>**/*.properties</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+ </module>
+ </modules>
+</archetype-descriptor>
=======================================
--- /dev/null
+++ /lambico-ws-archetype/src/main/resources/archetype-resources/.gitignore
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,3 @@
+/server/nb-configuration.xml
+/server/target/
+/core/target/
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/LICENSE_HEADER
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,3 @@
+Copyright (C) ${year} ${holder} <${contact}>
+
+This file is part of ${name}.
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/pom.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>${groupId}</groupId>
+ <artifactId>${rootArtifactId}</artifactId>
+ <version>${version}</version>
+ </parent>
+ <groupId>${groupId}</groupId>
+ <artifactId>${rootArtifactId}-core</artifactId>
+ <packaging>jar</packaging>
+ <version>${version}</version>
+ <name>${rootArtifactId} - Core</name>
+ <url>http://www.lambico.org</url>
+ <properties>
+ <main.basedir>${basedir}/..</main.basedir>
+ </properties>
+ <build>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <filtering>true</filtering>
+ </testResource>
+ </testResources>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-spring-hibernate</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxws</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-extension-providers</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-local</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <groupId>javax.ws.rs</groupId>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.jaxrs</groupId>
+ <artifactId>jackson-jaxrs-json-provider</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-config</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-web</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-api</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jettison</groupId>
+ <artifactId>jettison</artifactId>
+ <version>1.3.2</version>
+ <type>jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/bean/PageImpl.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,152 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.bean;
+
+import java.util.Collections;
+import java.util.List;
+import ${groupId}.dao.generic.Page;
+
+/**
+ * Bean for managing list paginations.
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+public class PageImpl<T> implements Page<T> {
+ /**
+ * The content of the page.
+ */
+ private List<T> results;
+ /**
+ * The size of the page, i.e. the max number of rows in a single page.
+ */
+ private int pageSize;
+ /**
+ * The index of the current page.
+ */
+ private int page;
+ /**
+ * The total rows count.
+ */
+ private int rowCount;
+ /**
+ * An empty page.
+ */
+ @SuppressWarnings("unchecked")
+ public static final Page EMPTY =
+ new PageImpl(Collections.EMPTY_LIST, 1, 1, 0);
+
+ public PageImpl() {
+ }
+
+ /**
+ * The constructor of a page.
+ *
+ * @param list The page content.
+ * @param page The index of the page.
+ * @param pageSize The size of the page.
+ * @param rowCount The total rows count.
+ */
+ public PageImpl(final List<T> list, final int page,
+ final int pageSize, final int rowCount) {
+ this.page = page;
+ this.pageSize = pageSize;
+ this.rowCount = rowCount;
+ results = list;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public int getPage() {
+ return page;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public boolean isNextPage() {
+ return page < getLastPage();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public boolean isPreviousPage() {
+ return page > 1;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public List<T> getList() {
+ return results;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public int getLastPage() {
+ int lastPage = rowCount / pageSize;
+ if (rowCount % pageSize > 0) {
+ lastPage++;
+ }
+ return lastPage;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public int getRowCount() {
+ return rowCount;
+ }
+
+ public List<T> getResults() {
+ return results;
+ }
+
+ public void setResults(
+ List<T> results) {
+ this.results = results;
+ }
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public void setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ }
+
+ public void setPage(int page) {
+ this.page = page;
+ }
+
+ public void setRowCount(int rowCount) {
+ this.rowCount = rowCount;
+ }
+
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/bean/PaginatedResult.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,85 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.bean;
+
+import java.util.List;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSeeAlso;
+import ${package}.core.po.Person;
+
+/**
+ * A bean for returning a paged result of items (or even a
+ * single page of results).
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+@XmlRootElement(name = "items")
+@XmlSeeAlso(Person.class)
+public class PaginatedResult<T> {
+
+ private List<T> items;
+ private int page;
+ private int rowCount;
+ private int lastPage;
+ private boolean nextPage;
+ private boolean previousPage;
+
+ @XmlElement(name = "item")
+ @XmlElementWrapper(name = "items")
+ public List<T> getItems() {
+ return items;
+ }
+
+ public void setItems(List<T> items) {
+ this.items = items;
+ }
+
+ public int getPage() {
+ return page;
+ }
+
+ public void setPage(int page) {
+ this.page = page;
+ }
+
+ public int getRowCount() {
+ return rowCount;
+ }
+
+ public void setRowCount(int rowCount) {
+ this.rowCount = rowCount;
+ }
+
+ public int getLastPage() {
+ return lastPage;
+ }
+
+ public void setLastPage(int lastPage) {
+ this.lastPage = lastPage;
+ }
+
+ public boolean isNextPage() {
+ return nextPage;
+ }
+
+ public void setNextPage(boolean nextPage) {
+ this.nextPage = nextPage;
+ }
+
+ public boolean isPreviousPage() {
+ return previousPage;
+ }
+
+ public void setPreviousPage(boolean previousPage) {
+ this.previousPage = previousPage;
+ }
+
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/bean/StringResult.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,37 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.bean;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * A result containing a single string.
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+@XmlRootElement
+public class StringResult {
+
+ private String content;
+
+ public StringResult() {
+ }
+
+ public StringResult(String content) {
+ this.content = content;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/bo/PersonBo.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,94 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.bo;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import javax.annotation.Resource;
+import org.hibernate.criterion.DetachedCriteria;
+import ${groupId}.dao.generic.Page;
+import ${groupId}.dao.generic.PageDefaultImpl;
+import ${groupId}.dao.spring.hibernate.HibernateGenericDao;
+import ${package}.core.dao.PersonDao;
+import ${package}.core.po.Person;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * A BO to be used for the tests of the generic DAO.
+ *
+ * @author <a href="mailto:lu...@benfante.com">Lucio Benfante</a>
+ * @version ${symbol_dollar}Revision: a8d8760b3552 ${symbol_dollar}
+ */
+@Service
+public class PersonBo {
+
+ private static final Logger log =
LoggerFactory.getLogger(PersonBo.class);
+ @Resource
+ private PersonDao personDao;
+
+ @Transactional
+ public void initializeArchive() throws ParseException {
+ log.debug("Executing initializeArchive.");
+ personDao.deleteAll();
+ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
+ createPerson("Mario", "Rossi", sdf.parse("25/04/1970"));
+ createPerson("Francesca", "Verdi", sdf.parse("30/08/1990"));
+ createPerson("Giovanni", "Bianchi", sdf.parse("15/03/1980"));
+ log.debug("Created {} persons.", 3);
+ }
+
+ @Transactional(readOnly = true)
+ public Page<Person> getPaginatedPersons(Integer page, Integer
pageSize) {
+ log.debug("Executing getPaginatedPersons.");
+ DetachedCriteria crit = DetachedCriteria.forClass(Person.class);
+ crit.addOrder(org.hibernate.criterion.Order.asc("lastName"))
+ .addOrder(org.hibernate.criterion.Order.asc("firstName"));
+ Page<Person> result;
+ if (pageSize != null) {
+ if (page == null) {
+ page = new Integer(1);
+ }
+ result = ((HibernateGenericDao)
personDao).searchPaginatedByCriteria(page, pageSize, crit);
+ } else {
+ List persons = ((HibernateGenericDao)
personDao).searchByCriteria(crit);
+ result = new PageDefaultImpl<Person>(persons, new Integer(1),
persons.size(), persons.size());
+ }
+ log.debug("Retrieved {} persons.", result.getList().size());
+ return result;
+ }
+
+ @Transactional(readOnly = true)
+ public void printPerson(Long id) {
+ Person p = personDao.read(id);
+ if (p != null) {
+ System.out.println(p.getFirstName() + " " + p.getLastName()
+ " "
+ + p.getBirthDate());
+ } else {
+ System.out.println("Person (" + id + ") not found");
+ }
+ }
+
+ private void createPerson(String firstName, String lastName, Date
birthDate) throws ParseException {
+ List<Person> searches = null;
+ searches = personDao.findByFirstNameAndLastName(firstName,
lastName);
+ if (searches.isEmpty()) {
+ Person p = new Person();
+ p.setFirstName(firstName);
+ p.setLastName(lastName);
+ p.setBirthDate(birthDate);
+ personDao.create(p);
+ }
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/dao/PersonDao.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,33 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.dao;
+
+import java.util.Date;
+import java.util.List;
+import ${groupId}.dao.generic.Dao;
+import ${groupId}.dao.generic.GenericDao;
+import ${package}.core.po.Person;
+
+/**
+ * The DAO interface for the Person entity.
+ *
+ * @author <a href="mailto:lu...@benfante.com">Lucio Benfante</a>
+ * @version ${symbol_dollar}Revision: ae7fb2fab619 ${symbol_dollar}
+ */
+@Dao(entity = Person.class)
+public interface PersonDao extends GenericDao<Person, Long> {
+
+ List<Person> findByLastName(String lastName);
+
+ List<Person> findByFirstNameAndLastName(String firstName, String
lastName);
+
+ List<Person> findByBirthDate(Date birthDate);
+
+ List<Person> findByFirstName(String firstName);
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/po/Person.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,66 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.po;
+
+import java.util.Date;
+
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSeeAlso;
+import ${groupId}.po.hibernate.EntityBase;
+
+/**
+ * An example of a persistent object containing personal data.
+ *
+ * @author <a href="mailto:lu...@benfante.com">Lucio Benfante</a>
+ * @version ${symbol_dollar}Revision: ae7fb2fab619 ${symbol_dollar}
+ */
+...@javax.persistence.Entity
+@XmlRootElement
+@XmlSeeAlso(EntityBase.class)
+public class Person extends EntityBase {
+
+ private String firstName;
+ private String lastName;
+ private Date birthDate;
+
+ public Person() {
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ @Temporal(TemporalType.DATE)
+ public Date getBirthDate() {
+ return birthDate;
+ }
+
+ public void setBirthDate(Date birthDate) {
+ this.birthDate = birthDate;
+ }
+
+ @Override
+ public String toString() {
+ return this.firstName + " " + this.lastName + " (" +
this.birthDate + ")";
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/rest/SampleService.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,189 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.rest;
+
+import ${package}.core.bean.StringResult;
+import java.security.Principal;
+import java.text.ParseException;
+import java.util.List;
+import javax.annotation.Resource;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.SecurityContext;
+import ${groupId}.dao.generic.Page;
+import ${package}.core.bean.PaginatedResult;
+import ${package}.core.bo.PersonBo;
+import ${package}.core.dao.PersonDao;
+import ${package}.core.po.Person;
+import ${package}.core.security.User;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+
+/**
+ * Some sample REST services.
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+@Path("/sample")
+@Produces({"application/json", "application/xml"})
+@Consumes({"application/json", "application/xml"})
+public class SampleService {
+
+ private static final Logger log =
LoggerFactory.getLogger(SampleService.class);
+ @Resource
+ private PersonDao personDao;
+ @Resource
+ private PersonBo personBo;
+
+ /**
+ * A sample for a simple GET service, using path parameters and the
security
+ * context.
+ *
+ * @param message The message.
+ * @param securityContext The security context.
+ * @return A string with a welcome to the user and the message,
showing the
+ * username of the caller.
+ */
+ @GET
+ @Path("/hello/{message}")
+ public StringResult hello(@PathParam("message") String message,
+ @Context SecurityContext securityContext) {
+ log.debug("Calling hello.");
+ Principal userPrincipal = securityContext.getUserPrincipal();
+ UsernamePasswordAuthenticationToken
usernamePasswordAuthenticationToken =
+ (UsernamePasswordAuthenticationToken) userPrincipal;
+ User user = (User)
usernamePasswordAuthenticationToken.getPrincipal();
+ String name = user.getUsername();
+ return new StringResult("Hello, " + name + ": " + message);
+ }
+
+ @GET
+ @Path("/initialize")
+ public void initializeDb() throws ParseException {
+ personBo.initializeArchive();
+ }
+
+ @GET
+ @Path("/persons")
+ public PaginatedResult<Person> getPersons(@QueryParam("page") Integer
page, @QueryParam("pageSize") Integer pageSize) {
+ log.debug("Calling getPersons.");
+ PaginatedResult<Person> result = new PaginatedResult<Person>();
+ try {
+ Page<Person> persons = personBo.getPaginatedPersons(page,
pageSize);
+ result.setItems(persons.getList());
+ result.setPage(persons.getPage());
+ result.setRowCount(persons.getRowCount());
+ result.setLastPage(persons.getLastPage());
+ result.setNextPage(persons.isNextPage());
+ result.setPreviousPage(persons.isPreviousPage());
+ } catch (Exception ex) {
+ throw new WebApplicationException(ex,
Status.INTERNAL_SERVER_ERROR);
+ }
+ return result;
+ }
+
+ @GET
+ @Path("/persons/{id}")
+ public Person getPerson(@PathParam("id") Long id) {
+ log.debug("Calling getPerson with {}.", id);
+ Person person = personDao.get(id);
+ if (person == null) {
+ ResponseBuilder builder =
+ Response.status(Status.BAD_REQUEST);
+ builder.entity(new StringResult("Person Not Found"));
+ throw new WebApplicationException(builder.build());
+ } else {
+ return person;
+ }
+ }
+
+ /**
+ * Delete a person.
+ *
+ * @param id The identifier of the person.
+ * @return
+ */
+ @DELETE
+ @Path("/persons/{id}")
+ public Response deletePerson(@PathParam("id") Long id) {
+ log.debug("Calling deletePerson with {}.", id);
+ Person person = personDao.get(id);
+ if (person == null) {
+ ResponseBuilder builder =
+ Response.status(Status.BAD_REQUEST);
+ builder.entity(new StringResult("Person Not Found"));
+ throw new WebApplicationException(builder.build());
+ } else {
+ personDao.delete(person);
+ }
+ return Response.ok().build();
+ }
+
+ /**
+ * Add a Person.
+ *
+ * @param person The person data.
+ * @return
+ */
+ @POST
+ @Path("/persons")
+ @Consumes({"application/json", "application/xml"})
+ public Response addPerson(Person person) {
+ log.info("Calling addPerson for {} {}.", person.getFirstName(),
person.getLastName());
+ List<Person> persons =
personDao.findByFirstNameAndLastName(person.getFirstName(),
person.getLastName());
+ if (persons != null && persons.size() > 0) {
+ ResponseBuilder builder =
+ Response.status(Status.BAD_REQUEST);
+ builder.entity(new StringResult("Person already existant."));
+ throw new WebApplicationException(builder.build());
+ } else {
+ personDao.store(person);
+ }
+ return Response.ok().build();
+ }
+
+ /**
+ * Update a person.
+ *
+ * @param membershipInfo The member data.
+ * @return
+ */
+ @PUT
+ @Path("/persons")
+ @Consumes({"application/json", "application/xml"})
+ public Response updatePerson(Person person) {
+ log.debug("Calling updatePerson for {}.", person.getId());
+ Person dbPerson = personDao.get(person.getId());
+ if (dbPerson == null) {
+ ResponseBuilder builder =
+ Response.status(Status.BAD_REQUEST);
+ builder.entity(new StringResult("Person Not Found"));
+ throw new WebApplicationException(builder.build());
+ } else {
+ dbPerson.setFirstName(person.getFirstName());
+ dbPerson.setLastName(person.getLastName());
+ dbPerson.setBirthDate(person.getBirthDate());
+ personDao.store(person);
+ }
+ return Response.ok().build();
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/AuthService.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,27 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.security;
+
+import java.util.List;
+
+/**
+ * The authorization and authentication services.
+ *
+ * @author Lucio Benfante <lucio.b...@gmail.com>
+ * @version ${symbol_dollar}Revision: 307a1ab9c32c ${symbol_dollar}
+ */
+public interface AuthService {
+
+ public boolean checkLogin(String username, String password);
+
+ public User getUserData(String username);
+
+ public List<User> getUsers(List<String>usernames);
+
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/AuthenticationHandler.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,42 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.security;
+
+import javax.ws.rs.core.Response;
+import org.apache.cxf.configuration.security.AuthorizationPolicy;
+import org.apache.cxf.jaxrs.ext.RequestHandler;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.message.Message;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Handler for the authentication to services.
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+public class AuthenticationHandler implements RequestHandler {
+
+ private static final Logger log =
LoggerFactory.getLogger(AuthenticationHandler.class);
+
+ @Override
+ public Response handleRequest(Message m, ClassResourceInfo
resourceClass) {
+ log.debug("Checking authentication.");
+ AuthorizationPolicy policy = (AuthorizationPolicy)
m.get(AuthorizationPolicy.class);
+ if (policy != null) {
+ String username = policy.getUserName();
+ log.debug("{} is authenticated.", username);
+ return null;
+ } else {
+ // authentication failed, request the authetication, add the
realm name if needed to the value of WWW-Authenticate
+ log.debug("Not yet authenticated.");
+ return
Response.status(401).header("WWW-Authenticate", "Basic").build();
+ }
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/ClientUserDetailsService.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,52 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.security;
+
+import javax.annotation.Resource;
+import org.springframework.dao.DataAccessException;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import
org.springframework.security.core.userdetails.UsernameNotFoundException;
+
+/**
+ * An {@link UserDetailsService} that use the UserDao for retrieving user
details using remote WS.
+ *
+ * @author Lucio Benfante <lucio.b...@gmail.com>
+ */
+public class ClientUserDetailsService implements UserDetailsService {
+
+ @Resource
+ private AuthService authServiceClient;
+
+ public AuthService getAuthServiceClient() {
+ return authServiceClient;
+ }
+
+ public void setAuthServiceClient(AuthService authServiceClient) {
+ this.authServiceClient = authServiceClient;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param username {@inheritDoc}
+ * @return {@inheritDoc}
+ * @throws UsernameNotFoundException {@inheritDoc}
+ * @throws DataAccessException {@inheritDoc}
+ */
+ @Override
+ public UserDetails loadUserByUsername(String username) throws
+ UsernameNotFoundException {
+ UserDetails result = authServiceClient.getUserData(username);
+ if (result == null) {
+ throw new UsernameNotFoundException("Can't find user: " +
username);
+ }
+ return result;
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/FakeAuthService.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,49 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.security;
+
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+
+/**
+ * A simple auth service that simulate the existence of a user with
+ * username=username, password=password and a role ROLE_DEFAULT.
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+public class FakeAuthService implements AuthService {
+
+ @Override
+ public boolean checkLogin(String username, String password) {
+ return true;
+ }
+
+ @Override
+ public User getUserData(String username) {
+ User user = createFakeUser();
+ return user;
+ }
+
+ @Override
+ public List<User> getUsers(List<String> usernames) {
+ LinkedList<User> result = new LinkedList<User>();
+ result.add(createFakeUser());
+ return result;
+ }
+
+ private User createFakeUser() {
+ User user = new
User("username", "ec7b8c3f180cc77ff2b8c4486545e766", null, true, true,
true, true);
+ HashSet<SimpleGrantedAuthority> authorities = new
HashSet<SimpleGrantedAuthority>();
+ authorities.add(new SimpleGrantedAuthority("ROLE_DEFAULT"));
+ user.setAuthorities(authorities);
+ return user;
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/SecurityExceptionMapper.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,28 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.security;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+import org.springframework.security.access.AccessDeniedException;
+
+/**
+ * Exception mapper for the {@link
org.springframework.security.access.AccessDeniedException}.
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+public class SecurityExceptionMapper implements
ExceptionMapper<AccessDeniedException> {
+
+ @Override
+ public Response toResponse(AccessDeniedException exception) {
+ return Response.status(Response.Status.FORBIDDEN).build();
+ }
+
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/User.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,105 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.security;
+
+import java.util.Collection;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+
+/**
+ * The user.
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+public class User implements UserDetails {
+
+ private String username;
+ private String password;
+ private Collection<? extends GrantedAuthority> authorities;
+ private boolean accountNotExpired;
+ private boolean accountNotLocked;
+ private boolean credentialsNotExpired;
+ private boolean enabled;
+
+ public User() {
+ }
+
+ public User(String username, String password, Collection<? extends
GrantedAuthority> authorities, boolean accountNotExpired, boolean
accountNotLocked, boolean credentialsNotExpired, boolean enabled) {
+ this.username = username;
+ this.password = password;
+ this.authorities = authorities;
+ this.accountNotExpired = accountNotExpired;
+ this.accountNotLocked = accountNotLocked;
+ this.credentialsNotExpired = credentialsNotExpired;
+ this.enabled = enabled;
+ }
+
+ @Override
+ public Collection<? extends GrantedAuthority> getAuthorities() {
+ return authorities;
+ }
+
+ @Override
+ public String getPassword() {
+ return password;
+ }
+
+ @Override
+ public String getUsername() {
+ return username;
+ }
+
+ @Override
+ public boolean isAccountNonExpired() {
+ return accountNotExpired;
+ }
+
+ @Override
+ public boolean isAccountNonLocked() {
+ return accountNotLocked;
+ }
+
+ @Override
+ public boolean isCredentialsNonExpired() {
+ return credentialsNotExpired;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public void setAuthorities(Collection<? extends GrantedAuthority>
authorities) {
+ this.authorities = authorities;
+ }
+
+ public void setAccountNonExpired(boolean accountNotExpired) {
+ this.accountNotExpired = accountNotExpired;
+ }
+
+ public void setAccountNonLocked(boolean accountNotLocked) {
+ this.accountNotLocked = accountNotLocked;
+ }
+
+ public void setCredentialsNonExpired(boolean credentialsNotExpired) {
+ this.credentialsNotExpired = credentialsNotExpired;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/java/core/bo/PersonBoTest.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,54 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.bo;
+
+import java.util.List;
+import javax.annotation.Resource;
+import org.junit.Test;
+import ${groupId}.dao.generic.Page;
+import ${groupId}.test.spring.hibernate.junit4.AbstractBaseTest;
+import ${groupId}.test.spring.hibernate.junit4.FixtureSet;
+import ${package}.core.dao.PersonDao;
+import ${package}.core.po.Person;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
+
+/**
+ * Tests of the PersonBo methods.
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+@FixtureSet(modelClasses = {Person.class})
+public class PersonBoTest extends AbstractBaseTest {
+
+ @Resource
+ private PersonBo personBo;
+ @Resource
+ private PersonDao personDao;
+
+ /**
+ * Test of initializeArchive method, of class PersonBo.
+ */
+ @Test
+ public void testPopulateArchive() throws Exception {
+ personBo.initializeArchive();
+ List<Person> persons = personDao.findAll();
+ assertThat(persons, hasSize(3));
+ }
+
+ /**
+ * Test of getPaginatedPersons method, of class PersonBo.
+ */
+ @Test
+ public void testGetPaginatedPersons() {
+ Page<Person> paginatedPersons = personBo.getPaginatedPersons(null,
null);
+ assertThat(paginatedPersons.getList(), hasSize(7));
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/java/core/rest/SampleServiceTest.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,157 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.rest;
+
+import java.util.LinkedList;
+import java.util.List;
+import javax.annotation.Resource;
+import javax.ws.rs.BadRequestException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.junit.Test;
+import org.junit.Ignore;
+import ${package}.core.bean.PaginatedResult;
+import ${package}.core.bean.StringResult;
+import ${package}.core.po.Person;
+import ${package}.core.test.BaseRSTest;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
+
+/**
+ * Test the REST SampleService.
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+public class SampleServiceTest extends BaseRSTest {
+
+ public static final String ENDPOINT_ADDRESS
= "local://RestSampleService";
+ public static final String DEFAULT_USERNAME = "username";
+ public static final String DEFAULT_PASSWORD = "password";
+ @Resource
+ private SampleService sampleService;
+
+ @Override
+ protected String getServerEndpointAddress() {
+ return ENDPOINT_ADDRESS;
+ }
+
+ @Override
+ protected List<Class<?>> getServerResourceClasses() {
+ List<Class<?>> result = new LinkedList<Class<?>>();
+ result.add(SampleService.class);
+ return result;
+ }
+
+ @Override
+ protected List<ResourceProvider> getServerResourceProviders() {
+ List<ResourceProvider> result = new LinkedList<ResourceProvider>();
+ result.add(new SingletonResourceProvider(sampleService, true));
+ return result;
+ }
+
+ /**
+ * Test of hello method, of class SampleService.
+ */
+ @Test
+ public void testHello() {
+ WebClient client = createWebClient(ENDPOINT_ADDRESS,
DEFAULT_USERNAME, DEFAULT_PASSWORD, null);
+ String message = "prova";
+ client.path("/sample/hello/" + message);
+ StringResult result = client.get(StringResult.class);
+ assertThat(result.getContent(), equalTo("Hello, " +
DEFAULT_USERNAME + ": " + message));
+ }
+
+ /**
+ * Test of getPersons method, of class SampleService.
+ */
+ @Test
+ public void testGetPersons() {
+ SampleService client = createProxyClient(ENDPOINT_ADDRESS,
DEFAULT_USERNAME, DEFAULT_PASSWORD, null);
+ PaginatedResult<Person> persons = client.getPersons(null, null);
+ assertThat(persons.getItems(), hasSize(7));
+ }
+
+ /**
+ * Test of getPersons method, of class SampleService.
+ */
+ @Test
+ @Ignore
+ public void testJsonGetPersons() {
+ SampleService client = createProxyClient(ENDPOINT_ADDRESS,
DEFAULT_USERNAME, DEFAULT_PASSWORD, MediaType.APPLICATION_JSON);
+ PaginatedResult<Person> persons = client.getPersons(null, null);
+ assertThat(persons.getItems(), hasSize(7));
+ }
+
+ /**
+ * Test of getPerson method, of class SampleService.
+ */
+ @Test
+ public void testGetPerson() {
+ SampleService client = createProxyClient(ENDPOINT_ADDRESS,
DEFAULT_USERNAME, DEFAULT_PASSWORD, null);
+ PaginatedResult<Person> persons = client.getPersons(null, null);
+ Person person1 = persons.getItems().get(0);
+ Person person2 = client.getPerson(person1.getId());
+ assertThat(person2, is(not(nullValue())));
+ assertThat(person2.getId(), equalTo(person1.getId()));
+ }
+
+ /**
+ * Test of deletePerson method, of class SampleService.
+ */
+ @Test
+ public void testDeletePerson() {
+ SampleService client = createProxyClient(ENDPOINT_ADDRESS,
DEFAULT_USERNAME, DEFAULT_PASSWORD, null);
+ PaginatedResult<Person> persons = client.getPersons(null, null);
+ Person person = persons.getItems().get(0);
+ Response response = client.deletePerson(person.getId());
+ assertThat(response.getStatus(),
equalTo(Response.Status.OK.getStatusCode()));
+ try {
+ Person deletedPerson = client.getPerson(person.getId());
+ } catch (BadRequestException e) {
+ assertThat(e.getResponse().getStatus(),
equalTo(Response.Status.BAD_REQUEST.getStatusCode()));
+ }
+ }
+
+ /**
+ * Test of addPerson method, of class SampleService.
+ */
+ @Test
+ public void testAddPerson() {
+ SampleService client = createProxyClient(ENDPOINT_ADDRESS,
DEFAULT_USERNAME, DEFAULT_PASSWORD, null);
+ Person newPerson = new Person();
+ newPerson.setFirstName("New");
+ newPerson.setLastName("Person");
+ client.addPerson(newPerson);
+ PaginatedResult<Person> persons = client.getPersons(null, null);
+ assertThat(persons.getItems(), hasSize(8));
+ }
+
+ /**
+ * Test of updatePerson method, of class SampleService.
+ */
+ @Test
+ public void testUpdatePerson() {
+ SampleService client = createProxyClient(ENDPOINT_ADDRESS,
DEFAULT_USERNAME, DEFAULT_PASSWORD, null);
+ PaginatedResult<Person> persons = client.getPersons(null, null);
+ Person person = persons.getItems().get(0);
+ person.setFirstName("Updated");
+ client.updatePerson(person);
+ Person updatedPerson = client.getPerson(person.getId());
+ assertThat(updatedPerson.getFirstName(), equalTo("Updated"));
+ }
+
+
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/java/core/security/SecurityCXFJAXRSFilter.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,142 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.security;
+
+import java.util.List;
+import java.security.Principal;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.ext.Provider;
+import org.apache.cxf.interceptor.security.AuthenticationException;
+
+import org.apache.cxf.jaxrs.ext.RequestHandler;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.message.Message;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.crypto.codec.Base64;
+
+/**
+ * A request handler for managing authentication in tests.
+ *
+ * Based on {@link
https://github.com/gmazza/jersey-samples-on-cxf/blob/master/https-clientserver-grizzly/src/main/java/com/sun/jersey/samples/https_grizzly/auth/SecurityCXFJAXRSFilter.java}
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+@Provider
+public class SecurityCXFJAXRSFilter implements RequestHandler {
+
+ @Context
+ UriInfo uriInfo;
+ @Context
+ HttpHeaders httpHeaders;
+ private static final Logger log =
LoggerFactory.getLogger(SecurityCXFJAXRSFilter.class);
+
+ private Map<String, User> users = new HashMap<String, User>();
+
+ public Map<String, User> getUsers() {
+ return users;
+ }
+
+ public void setUsers(Map<String, User> users) {
+ this.users = users;
+ }
+
+ @Override
+ public Response handleRequest(Message inputMessage, ClassResourceInfo
resourceClass) {
+ Authentication authentication = authenticate();
+ inputMessage.put(SecurityContext.class, new
Authorizer(authentication));
+ return null;
+ }
+
+ private Authentication authenticate() {
+ // Extract authentication credentials
+ List<String> authenticationList =
httpHeaders.getRequestHeader(HttpHeaders.AUTHORIZATION);
+ if (authenticationList.size() < 1) {
+ throw new AuthenticationException("Authentication credentials
are required");
+ }
+ String authentication = authenticationList.get(0);
+ if (!authentication.startsWith("Basic ")) {
+ return null;
+ // additional checks should be done here
+ // "Only HTTP Basic authentication is supported"
+ }
+ authentication = authentication.substring("Basic ".length());
+ String[] values = new
String(Base64.decode(authentication.getBytes())).split(":");
+ if (values.length < 2) {
+ throw new WebApplicationException(400);
+ // "Invalid syntax for username and password"
+ }
+ String username = values[0];
+ String password = values[1];
+ if ((username == null) || (password == null)) {
+ throw new WebApplicationException(400);
+ }
+
+ // Validate the extracted credentials
+ User user = users.get(username);
+ UsernamePasswordAuthenticationToken auth = null;
+ if (user != null && username.equals("username") &&
password.equals("password")) {
+ auth = new UsernamePasswordAuthenticationToken(user, null,
user.getAuthorities());
+ log.info("User {} authenticated.", username);
+ } else {
+ log.info("User {} not authenticated.", username);
+ throw new AuthenticationException("Invalid username or
password");
+ }
+ return auth;
+ }
+
+ public class Authorizer implements SecurityContext {
+
+ private Authentication authentication;
+
+ public Authorizer(final Authentication authentication) {
+ this.authentication = authentication;
+ }
+
+ @Override
+ public Principal getUserPrincipal() {
+ return authentication;
+ }
+
+ @Override
+ public boolean isUserInRole(String role) {
+ Collection<? extends GrantedAuthority> authorities =
authentication.getAuthorities();
+ boolean result = false;
+ for (GrantedAuthority authority : authorities) {
+ if (role.equals(authority.getAuthority())) {
+ result = true;
+ break;
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isSecure() {
+ return "https".equals(uriInfo.getRequestUri().getScheme());
+ }
+
+ @Override
+ public String getAuthenticationScheme() {
+ return SecurityContext.BASIC_AUTH;
+ }
+ }
+
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/java/core/test/BaseRSTest.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,136 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.test;
+
+import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Resource;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.client.Client;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.ext.RequestHandler;
+import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.transport.local.LocalConduit;
+import org.junit.After;
+import org.junit.Before;
+import ${groupId}.test.spring.hibernate.junit4.AbstractBaseTest;
+import ${groupId}.test.spring.hibernate.junit4.FixtureSet;
+import ${package}.core.po.Person;
+import ${package}.core.rest.SampleService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * A base class for web service tests.
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+@ContextConfiguration(locations =
{"/${packageInPathFormat}/core/rest/client-beans-test.xml"})
+@FixtureSet(modelClasses = {Person.class})
+public abstract class BaseRSTest extends AbstractBaseTest {
+
+ public static final String DEFAULT_ACCEPT_TYPE = "application/xml";
+ private Server server;
+ @Autowired(required = false)
+ @Qualifier("securityFilter")
+ private RequestHandler securityFilter;
+
+ @Before
+ public void startServer() throws Exception {
+ JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+ sf.setProviders(getServerProviders());
+ sf.setResourceClasses(getServerResourceClasses());
+ sf.setResourceProviders(getServerResourceProviders());
+ sf.setAddress(getServerEndpointAddress());
+ sf.getOutInterceptors().add(new LoggingOutInterceptor());
+ sf.getInInterceptors().add(new LoggingInInterceptor());
+ this.server = sf.create();
+ }
+
+ @After
+ public void stopServer() throws Exception {
+ server.stop();
+ server.destroy();
+ }
+
+ protected List<Object> getServerProviders() {
+ List<Object> providers = new ArrayList<Object>();
+ if (securityFilter != null) {
+ providers.add(securityFilter);
+ }
+ providers.add(new JacksonJaxbJsonProvider());
+ return providers;
+ }
+
+ abstract protected String getServerEndpointAddress();
+
+ abstract protected List<Class<?>> getServerResourceClasses();
+
+ abstract protected List<ResourceProvider> getServerResourceProviders();
+
+ private String buildBasicAuthorizationHeader(String username, String
password) {
+ String authorizationHeader = "Basic "
+ +
org.apache.cxf.common.util.Base64Utility.encode((username + ":" +
password).getBytes());
+ return authorizationHeader;
+ }
+
+ protected void setAuthorizationHeader(String username, String
password, Client client) {
+ String authorizationHeader =
buildBasicAuthorizationHeader(username, password);
+ client.header("Authorization", authorizationHeader);
+ }
+
+ protected WebClient createWebClient(String endpointAddress, String
username, String password, String acceptType) {
+ WebClient client = WebClient.create(endpointAddress);
+ configureClient(client, username, password, acceptType);
+ return client;
+ }
+
+ protected SampleService createProxyClient(String endpointAddress,
String username, String password, String acceptType) {
+ List<Object> providers = new ArrayList<Object>();
+ providers.add(new JacksonJaxbJsonProvider());
+ SampleService proxy = JAXRSClientFactory.create(endpointAddress,
SampleService.class, providers);
+ Client client = WebClient.client(proxy);
+ configureClient(client, username, password, acceptType);
+ return proxy;
+ }
+
+ protected void configureClient(Client client, String username, String
password, String acceptType) {
+ configureClientDirectDispatch(client, isDirectlyDispatched());
+ configureClientAcceptType(client, acceptType);
+ configureClientAuthorization(client, username, password);
+ }
+
+ protected void configureClientDirectDispatch(Client client, boolean
directlyDispatched) {
+
WebClient.getConfig(client).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
directlyDispatched);
+ }
+
+ protected boolean isDirectlyDispatched() {
+ return true;
+ }
+
+ protected void configureClientAcceptType(Client client, String
acceptType) {
+ if (acceptType == null) {
+ acceptType = DEFAULT_ACCEPT_TYPE;
+ }
+ client.accept(acceptType);
+ }
+
+ protected void configureClientAuthorization(Client client, String
username, String password) {
+ if (username != null && password != null) {
+ setAuthorizationHeader(username, password, client);
+ }
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/java/core/test/BaseWSTest.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,21 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package ${package}.core.test;
+
+import org.springframework.test.context.ContextConfiguration;
+import
org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
+
+/**
+ * A base class for web service tests.
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+@ContextConfiguration(locations =
{"/${packageInPathFormat}/core/service/client-beans-test.xml"})
+public abstract class BaseWSTest extends
AbstractTransactionalJUnit4SpringContextTests {
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/resources/applicationContext-test.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,33 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2013 Lambico Team <in...@lambico.org>
+
+ This file is part of Lambico WS Archetype Template - Core.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:lambico="http://www.lambico.org/schema/lambico"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.lambico.org/schema/lambico
http://www.lambico.org/schema/lambico.xsd
+ http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+ <import resource="database-test.xml"/>
+
+ <context:component-scan base-package="${package}.core.bo"/>
+ <context:component-scan base-package="${package}.core.service"/>
+
+ <!-- Authomatic discovering of persistent classes -->
+ <lambico:discover-persistent-classes basePackage="${package}.core.po"/>
+ <!-- Authomatic DAO definition from persistent classes -->
+ <lambico:define-daos baseInterfacePackage="${package}.core.dao"/>
+
+ <bean id="exceptionManager"
class="org.lambico.dao.BypassingExceptionManager"/>
+
+</beans>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/resources/database-test.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,44 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2013 Lambico Team <in...@lambico.org>
+
+ This file is part of Lambico WS Archetype Template - Core.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
+
+ <tx:annotation-driven/>
+
+ <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
+ <property name="url" value="jdbc:hsqldb:mem:testSrvDB"/>
+ <property name="username" value="sa"/>
+ <property name="password" value=""/>
+ </bean>
+
+ <bean id="sessionFactory" parent="abstractSessionFactory">
+ <property name="hibernateProperties">
+ <props merge="true">
+ <!-- prop
key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop -->
+ <prop key="hibernate.hbm2ddl.auto">create</prop>
+ <prop key="hibernate.show_sql">false</prop>
+ </props>
+ </property>
+ <property name="eventListeners">
+ <map>
+ <entry key="merge">
+ <bean
class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
+ </entry>
+ </map>
+ </property>
+ </bean>
+
+</beans>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/resources/fixtures/Person.yml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,34 @@
+#
+# Copyright (C) 2013 Lambico Team <in...@lambico.org>
+#
+# This file is part of Lambico WS Archetype Template - Core.
+#
+
+- &Person-lucio
+ firstName: Lucio
+ lastName: Benfante
+ birthDate: 1971-03-26
+- &Person-ugo
+ firstName: Ugo
+ lastName: Benfante
+ birthDate: 1943-02-06
+- &Person-guido
+ firstName: Guido
+ lastName: Benfante
+ birthDate: 1973-10-28
+- &Person-chiara
+ firstName: Chiara
+ lastName: Benfante
+ birthDate: 1972-07-31
+- &Person-Carlo
+ firstName: Carlo
+ lastName: Benfante
+ birthDate: 2004-10-17
+- &Person-Silvia
+ firstName: Silvia
+ lastName: Benfante
+ birthDate: 2006-08-13
+- &Person-Filippo
+ firstName: Filippo
+ lastName: Benfante
+ birthDate: 1973-05-11
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/resources/org/lambico/ws/archetype/template/core/rest/client-beans-test.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,49 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2013 Lambico Team <in...@lambico.org>
+
+ This file is part of Lambico WS Archetype Template - Core.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:security="http://www.springframework.org/schema/security"
+ xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+ xmlns:cxf="http://cxf.apache.org/core"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
+ http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
+ http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
+
+ <bean id="sampleRestService"
class="${package}.core.rest.SampleService"/>
+
+ <bean id="securityFilter"
class="${package}.core.security.SecurityCXFJAXRSFilter">
+ <property name="users">
+ <map>
+ <entry key="username">
+ <bean class="${package}.core.security.User">
+ <property name="username" value="username"/>
+ <property name="password" value="password"/>
+ <property name="accountNonExpired" value="true"/>
+ <property name="accountNonLocked" value="true"/>
+ <property name="credentialsNonExpired"
value="true"/>
+ <property name="enabled" value="true"/>
+ <property name="authorities">
+ <set>
+ <bean
class="org.springframework.security.core.authority.SimpleGrantedAuthority">
+ <constructor-arg value="ROLE_DEFAULT"/>
+ </bean>
+ </set>
+ </property>
+ </bean>
+ </entry>
+ </map>
+ </property>
+ </bean>
+
+</beans>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/resources/org/lambico/ws/archetype/template/core/service/client-beans-test.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,22 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2013 Lambico Team <in...@lambico.org>
+
+ This file is part of Lambico WS Archetype Template - Core.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:jaxws="http://cxf.apache.org/jaxws"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
+
+<!-- <jaxws:client id="sampleSoapServiceClient"
serviceClass="${package}.core.service.SampleSoapService"
+ address="local://SampleSoapService" />-->
+
+</beans>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/test/resources/simplelogger.properties
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,13 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+org.slf4j.simpleLogger.logFile=System.out
+org.slf4j.simpleLogger.defaultLogLevel=info
+
+${symbol_pound} test the project classes at debug level
+org.slf4j.simpleLogger.log.${package}.core=debug
+
+${symbol_pound} put to debug log level for full inspecting Hibernate
operations
+org.slf4j.simpleLogger.log.org.hibernate.SQL=info
+org.slf4j.simpleLogger.log.org.hibernate=info
+org.slf4j.simpleLogger.log.org.hibernate.type=info
=======================================
--- /dev/null
+++ /lambico-ws-archetype/src/main/resources/archetype-resources/pom.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,311 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>${groupId}</groupId>
+ <artifactId>${artifactId}</artifactId>
+ <version>${version}</version>
+ <packaging>pom</packaging>
+
+ <name>${rootArtifactId} - Parent</name>
+ <url>http://www.lambico.org</url>
+ <inceptionYear>2013</inceptionYear>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <main.basedir>${basedir}</main.basedir>
+ <year>2013</year>
+ <app.lambico.version>1.1-SNAPSHOT</app.lambico.version>
+
<app.springframework.version>3.0.7.RELEASE</app.springframework.version>
+
<app.springsecurity.version>3.1.4.RELEASE</app.springsecurity.version>
+ <app.hibernate.version>3.6.2.GA</app.hibernate.version>
+
<app.hibernate-validator.version>4.1.0.Final</app.hibernate-validator.version>
+ <app.logback.version>1.0.9</app.logback.version>
+ <app.log4j.version>1.2.14</app.log4j.version>
+ <app.junit4.version>4.11</app.junit4.version>
+ <app.hsqldb.version>2.2.9</app.hsqldb.version>
+ <app.slf4j.version>1.7.2</app.slf4j.version>
+ <app.gson.version>1.7.1</app.gson.version>
+ <app.cxf.version>2.7.3</app.cxf.version>
+ <app.hamcrest.version>1.3</app.hamcrest.version>
+
+ <app.datasource.name>${rootArtifactId}_DS</app.datasource.name>
+
<app.datasource>java:comp/env/jdbc/${app.datasource.name}</app.datasource>
+
<app.datasource.driver>org.hsqldb.jdbcDriver</app.datasource.driver>
+
<app.datasource.url>jdbc:hsqldb:mem:${app.datasource.name}</app.datasource.url>
+ <app.datasource.username>sa</app.datasource.username>
+ <app.datasource.password></app.datasource.password>
+ <app.hibernate.show_sql>true</app.hibernate.show_sql>
+ <app.log.console.level>INFO</app.log.console.level>
+ <app.log.file.level>DEBUG</app.log.file.level>
+ <app.log.rootdir>${java.io.tmpdir}</app.log.rootdir>
+
<tomcat_integration.remote.container.id>tomcat7x</tomcat_integration.remote.container.id>
+
<tomcat_integration.remote.manager.url>http://localhost:8080/manager/text</tomcat_integration.remote.manager.url>
+
<tomcat_integration.remote.username>admin</tomcat_integration.remote.username>
+
<tomcat_integration.remote.password>admin</tomcat_integration.remote.password>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-core</artifactId>
+ <version>${app.springsecurity.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-taglibs</artifactId>
+ <version>${app.springsecurity.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-config</artifactId>
+ <version>${app.springsecurity.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>${app.hibernate-validator.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-web</artifactId>
+ <version>${app.springsecurity.version}</version>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${app.junit4.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>${app.hsqldb.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-spring-hibernate</artifactId>
+ <version>${app.lambico.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-test</artifactId>
+ <version>${app.lambico.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${app.slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>${app.slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${app.logback.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxws</artifactId>
+ <version>${app.cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http</artifactId>
+ <version>${app.cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http-jetty</artifactId>
+ <version>${app.cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-local</artifactId>
+ <version>${app.cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>${app.cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-common-utilities</artifactId>
+ <version>${app.cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-api</artifactId>
+ <version>${app.cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-extension-providers</artifactId>
+ <version>${app.cxf.version}</version>
+ </dependency>
+ <dependency>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <groupId>javax.ws.rs</groupId>
+ <version>2.0-m10</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.jaxrs</groupId>
+ <artifactId>jackson-jaxrs-json-provider</artifactId>
+ <version>2.1.4</version>
+ </dependency>
+ <dependency>
+ <artifactId>gson</artifactId>
+ <groupId>com.google.code.gson</groupId>
+ <type>jar</type>
+ <version>${app.gson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>${app.log4j.version}</version>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <version>${app.hamcrest.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>src/assembly/bin.xml</descriptor>
+
<descriptor>src/assembly/bin-with-dependencies.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.5.1</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.12</version>
+ <configuration>
+ <skip>false</skip>
+ <useFile>true</useFile>
+ <forkMode>once</forkMode> <!-- pertest once or never
-->
+ <!-- <reportFormat>plain</reportFormat> -->
+ <!--argLine>-Xmx512M</argLine--> <!-- don't use if you
want to debug tests in NetBeans -->
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.5</version>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.mycila.maven-license-plugin</groupId>
+ <artifactId>maven-license-plugin</artifactId>
+ <version>1.9.0</version>
+ <configuration>
+ <header>${main.basedir}/LICENSE_HEADER</header>
+ <excludes>
+ <exclude>target/**</exclude>
+ <exclude>m2-target/**</exclude>
+ <exclude>**/*.properties</exclude>
+ <exclude>LICENSE_HEADER</exclude>
+ <exclude>nb-configuration.xml</exclude>
+ <exclude>nbactions.xml</exclude>
+ <exclude>profiles.xml</exclude>
+ <exclude>**/catalog.xml</exclude>
+ <exclude>**/logback*.xml</exclude>
+ </excludes>
+ <properties>
+ <name>${project.name}</name>
+ <year>${project.inceptionYear}</year>
+ <holder>${rootArtifactId} Team</holder>
+ <contact>info@${rootArtifactId}.org</contact>
+ </properties>
+ <encoding>UTF-8</encoding>
+ <mapping>
+ <yml>SCRIPT_STYLE</yml>
+ <jspf>DYNASCRIPT_STYLE</jspf>
+ <less>JAVADOC_STYLE</less>
+ </mapping>
+ <strictCheck>true</strictCheck>
+ <aggregate>false</aggregate>
+ <failIfMissing>true</failIfMissing>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <repositories>
+ <repository>
+ <id>jboss-maven2-repository</id>
+ <name>JBoss Repository for Maven</name>
+
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
+ <layout>default</layout>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>sonatype-nexus-snapshots</id>
+ <name>Sonatype Nexus snapshot repository</name>
+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+ <organization>
+ <name>${rootArtifactId} Team</name>
+ <url>http://www.lambico.org</url>
+ </organization>
+
+ <modules>
+ <module>core</module>
+ <module>server</module>
+ </modules>
+</project>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/server/pom.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>${groupId}</groupId>
+ <artifactId>${rootArtifactId}</artifactId>
+ <version>${version}</version>
+ </parent>
+ <groupId>${groupId}</groupId>
+ <artifactId>${rootArtifactId}-server</artifactId>
+ <packaging>war</packaging>
+ <version>${version}</version>
+ <name>${rootArtifactId} - Server</name>
+ <url>http://www.lambico.org</url>
+ <properties>
+ <main.basedir>${basedir}/..</main.basedir>
+ </properties>
+ <build>
+ <finalName>services-${project.version}</finalName>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ <webResources>
+ <resource>
+ <filtering>true</filtering>
+ <targetPath>META-INF</targetPath>
+ <!-- this is relative to the pom.xml directory
-->
+
<directory>${basedir}/src/main/webapp/META-INF</directory>
+ <includes>
+ <include>context.xml</include>
+ </includes>
+ </resource>
+ <resource>
+ <filtering>false</filtering>
+ <targetPath>META-INF</targetPath>
+ <!-- this is relative to the pom.xml directory
-->
+
<directory>${basedir}/src/main/webapp/META-INF</directory>
+ <excludes>
+ <exclude>context.xml</exclude>
+ </excludes>
+ </resource>
+ <resource>
+ <filtering>true</filtering>
+ <targetPath>WEB-INF</targetPath>
+ <!-- this is relative to the pom.xml directory
-->
+
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
+ <includes>
+ <include>database.xml</include>
+ <include>applicationContext.xml</include>
+ <include>beans.xml</include>
+ <include>web.xml</include>
+ </includes>
+ </resource>
+ <resource>
+ <filtering>false</filtering>
+ <targetPath>WEB-INF</targetPath>
+ <!-- this is relative to the pom.xml directory
-->
+
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
+ <excludes>
+ <exclude>database.xml</exclude>
+ <exclude>applicationContext.xml</exclude>
+ <exclude>beans.xml</exclude>
+ <exclude>web.xml</exclude>
+ </excludes>
+ </resource>
+ </webResources>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-maven2-plugin</artifactId>
+ <version>1.4.0</version>
+ <configuration>
+ <wait>false</wait>
+ <container>
+
<containerId>${tomcat_integration.remote.container.id}</containerId>
+ <type>remote</type>
+ </container>
+ <configuration>
+ <type>runtime</type>
+ <properties>
+
<cargo.remote.uri>${tomcat_integration.remote.manager.url}</cargo.remote.uri>
+
<cargo.remote.username>${tomcat_integration.remote.username}</cargo.remote.username>
+
<cargo.remote.password>${tomcat_integration.remote.password}</cargo.remote.password>
+ </properties>
+ </configuration>
+ <deployables>
+ <deployable>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>${project.artifactId}</artifactId>
+ <type>war</type>
+ </deployable>
+ </deployables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>${rootArtifactId}-core</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ <type>jar</type>
+ </dependency>
+ </dependencies>
+</project>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/java/server/filter/UserServletFilter.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,77 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Server.
+ */
+package ${package}.server.filter;
+
+import java.io.IOException;
+import java.security.Principal;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import org.slf4j.MDC;
+
+/**
+ * A filter for setting the user data in the log MDC.
+ *
+ * {@link http://logback.qos.ch/manual/mdc.html}
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+public class UserServletFilter implements Filter {
+
+ private final String USER_KEY = "username";
+
+ @Override
+ public void init(FilterConfig fc) throws ServletException {
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws
+ IOException,
+ ServletException {
+ boolean successfulRegistration = false;
+
+ HttpServletRequest req = (HttpServletRequest) request;
+ Principal principal = req.getUserPrincipal();
+
+ if (principal != null) {
+ String username = principal.getName();
+ successfulRegistration = registerUsername(username);
+ }
+
+ try {
+ chain.doFilter(request, response);
+ } finally {
+ if (successfulRegistration) {
+ MDC.remove(USER_KEY);
+ }
+ }
+ }
+
+ @Override
+ public void destroy() {
+ }
+
+ /**
+ * Register the user in the MDC under USER_KEY.
+ *
+ * @param username
+ * @return true if the user can be successfully registered
+ */
+ private boolean registerUsername(String username) {
+ if (username != null && username.trim().length() > 0) {
+ MDC.put(USER_KEY, username);
+ return true;
+ }
+ return false;
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/java/server/security/ClientAuthenticationManager.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,46 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Server.
+ */
+package ${package}.server.security;
+
+import javax.annotation.Resource;
+import ${package}.core.security.AuthService;
+import ${package}.core.security.User;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.BadCredentialsException;
+import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+
+/**
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+public class ClientAuthenticationManager implements AuthenticationManager {
+
+ @Resource
+ private AuthService authServiceClient;
+
+ public AuthService getAuthServiceClient() {
+ return authServiceClient;
+ }
+
+ public void setAuthServiceClient(AuthService authServiceClient) {
+ this.authServiceClient = authServiceClient;
+ }
+
+ @Override
+ public Authentication authenticate(Authentication a) throws
AuthenticationException {
+ if (authServiceClient.checkLogin((String) a.getPrincipal(),
(String) a.getCredentials())) {
+ User user = authServiceClient.getUserData((String)
a.getPrincipal());
+ return new UsernamePasswordAuthenticationToken(user,
a.getCredentials(),
+ user.getAuthorities());
+ }
+ throw new BadCredentialsException("Bad Credentials");
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/resources/logback.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,17 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<configuration>
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread]
[%X{username}] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>>
+
+ <logger name="org.parancoe"
level="${symbol_dollar}{logger-level.org.parancoe}"/>
+ <logger name="it.cai"
level="${symbol_dollar}{logger-level.it.cai.integration}"/>
+
+ <root level="ERROR">
+ <appender-ref ref="CONSOLE" />
+ </root>
+</configuration>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/webapp/META-INF/context.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,13 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2013 Lambico Team <in...@lambico.org>
+
+ This file is part of Lambico WS Archetype Template - Server.
+
+-->
+<Context antiJARLocking="true" path="/${rootArtifactId}">
+</Context>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/webapp/WEB-INF/applicationContext.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,28 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2013 Lambico Team <in...@lambico.org>
+
+ This file is part of Lambico WS Archetype Template - Server.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:lambico="http://www.lambico.org/schema/lambico"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.lambico.org/schema/lambico
http://www.lambico.org/schema/lambico.xsd
+ http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+ <context:component-scan base-package="${package}.core.bo"/>
+ <context:component-scan base-package="${package}.core.service"/>
+
+ <!-- Authomatic discovering of persistent classes -->
+ <lambico:discover-persistent-classes basePackage="${package}.core.po"/>
+ <!-- Authomatic DAO definition from persistent classes -->
+ <lambico:define-daos baseInterfacePackage="${package}.core.dao"/>
+
+</beans>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/webapp/WEB-INF/beans.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,70 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2013 Lambico Team <in...@lambico.org>
+
+ This file is part of Lambico WS Archetype Template - Server.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:security="http://www.springframework.org/schema/security"
+ xmlns:jaxws="http://cxf.apache.org/jaxws"
+ xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+ xmlns:cxf="http://cxf.apache.org/core"
+ xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
+ http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
+ http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
+ http://cxf.apache.org/core
http://cxf.apache.org/schemas/core.xsd">
+
+ <import resource="classpath:META-INF/cxf/cxf.xml" />
+
+ <jaxrs:server id="sampleRESTService" address="/secured"
publishedEndpointUrl="http://localhost:38080/${rootArtifactId}/secured">
+ <jaxrs:features>
+ <cxf:logging/>
+ </jaxrs:features>
+ <jaxrs:providers>
+ <bean class="${package}.core.security.AuthenticationHandler">
+ <!--<property name="authServiceClient"
ref="authServiceClient"/>-->
+ </bean>
+ <bean
class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider"/>
+ <bean
class="${package}.core.security.SecurityExceptionMapper"/>
+ </jaxrs:providers>
+ <jaxrs:serviceBeans>
+ <ref bean="sampleRestService" />
+ </jaxrs:serviceBeans>
+ </jaxrs:server>
+
+ <bean id="sampleRestService"
class="${package}.core.rest.SampleService"/>
+
+ <security:global-method-security secured-annotations="enabled">
+ <security:protect-pointcut expression="execution(*
${package}.core.rest.SampleService.*(..))" access="ROLE_DEFAULT"/>
+ <!--
+ <security:protect-pointcut expression="execution(*
demo.jaxrs.service.CustomerService.addCustomer(*))" access="ROLE_ADMIN"/>
+ <security:protect-pointcut expression="execution(*
demo.jaxrs.service.CustomerService.updateCustomer(Long,demo.jaxrs.service.Customer))"
access="ROLE_ADMIN"/>
+ <security:protect-pointcut expression="execution(*
demo.jaxrs.service.CustomerService.deleteCustomer(*))" access="ROLE_ADMIN"/>
+ <security:protect-pointcut expression="execution(*
demo.jaxrs.service.CustomerService.getOrder(*))" access="ROLE_CUSTOMER,
ROLE_ADMIN"/>
+ -->
+ </security:global-method-security>
+ <security:http auto-config="true" use-expressions="true">
+ <security:http-basic/>
+ </security:http>
+ <security:authentication-manager>
+ <security:authentication-provider
user-service-ref="userDetailsService">
+ <security:password-encoder hash="md5">
+ <security:salt-source user-property="username"/>
+ </security:password-encoder>
+ </security:authentication-provider>
+ </security:authentication-manager>
+
+ <bean id="userDetailsService"
class="${package}.core.security.ClientUserDetailsService">
+ <property name="authServiceClient" ref="authServiceClient"/>
+ </bean>
+
+ <bean id="authServiceClient"
class="${package}.core.security.FakeAuthService"/>
+
+</beans>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/webapp/WEB-INF/database.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,44 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2013 Lambico Team <in...@lambico.org>
+
+ This file is part of Lambico WS Archetype Template - Server.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
+
+ <tx:annotation-driven/>
+
+ <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
+ <property name="url" value="jdbc:hsqldb:mem:testSrvDB"/>
+ <property name="username" value="sa"/>
+ <property name="password" value=""/>
+ </bean>
+
+ <bean id="sessionFactory" parent="abstractSessionFactory">
+ <property name="hibernateProperties">
+ <props merge="true">
+ <!-- prop
key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop -->
+ <prop key="hibernate.hbm2ddl.auto">create</prop>
+ <prop key="hibernate.show_sql">false</prop>
+ </props>
+ </property>
+ <property name="eventListeners">
+ <map>
+ <entry key="merge">
+ <bean
class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
+ </entry>
+ </map>
+ </property>
+ </bean>
+
+</beans>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/server/src/main/webapp/WEB-INF/web.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,79 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2013 Lambico Team <in...@lambico.org>
+
+ This file is part of Lambico WS Archetype Template - Server.
+
+-->
+<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+ <description>${rootArtifactId} - Server</description>
+ <display-name>${rootArtifactId}</display-name>
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+
<param-value>classpath:org/lambico/spring/dao/hibernate/genericDao.xml,classpath:org/lambico/spring/dao/hibernate/applicationContextBase.xml,/WEB-INF/database.xml,/WEB-INF/applicationContext.xml,/WEB-INF/beans.xml</param-value>
+
<!--<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/beans.xml</param-value>-->
+ </context-param>
+ <!--
+ <filter>
+ <filter-name>openSessionInView</filter-name>
+
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>openSessionInView</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+ -->
+ <listener>
+ <listener-class>
+ org.springframework.web.context.ContextLoaderListener
+ </listener-class>
+ </listener>
+ <filter>
+ <filter-name>springSecurityFilterChain</filter-name>
+ <filter-class>
+ org.springframework.web.filter.DelegatingFilterProxy
+ </filter-class>
+ </filter>
+ <filter>
+ <filter-name>userServletFilter</filter-name>
+ <filter-class>
+ ${package}.server.filter.UserServletFilter
+ </filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>springSecurityFilterChain</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+ <filter-mapping>
+ <filter-name>userServletFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+ <servlet>
+ <display-name>CXF Servlet</display-name>
+ <servlet-name>CXFServlet</servlet-name>
+ <servlet-class>
+ org.apache.cxf.transport.servlet.CXFServlet
+ </servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>CXFServlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>HTTPSOnly</web-resource-name>
+ <url-pattern>/*</url-pattern>
+ </web-resource-collection>
+ <!-- <user-data-constraint>
+ <transport-guarantee>CONFIDENTIAL</transport-guarantee>
+ </user-data-constraint>-->
+ </security-constraint>
+</web-app>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/test/resources/projects/basic/archetype.properties
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,5 @@
+#Fri Sep 27 16:50:54 CEST 2013
+package=org.lambico.ws.archetype.template
+version=1.0-SNAPSHOT
+groupId=org.lambico
+artifactId=lambico-ws-archetype-template
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/test/resources/projects/basic/reference/.gitignore
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,3 @@
+/server/nb-configuration.xml
+/server/target/
+/core/target/
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/test/resources/projects/basic/reference/LICENSE_HEADER
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,3 @@
+Copyright (C) ${year} ${holder} <${contact}>
+
+This file is part of ${name}.
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/pom.xml
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-ws-archetype-template</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-ws-archetype-template-core</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>lambico-ws-archetype-template - Core</name>
+ <url>http://www.lambico.org</url>
+ <properties>
+ <main.basedir>${basedir}/..</main.basedir>
+ </properties>
+ <build>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <filtering>true</filtering>
+ </testResource>
+ </testResources>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-spring-hibernate</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.lambico</groupId>
+ <artifactId>lambico-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxws</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-extension-providers</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-local</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <groupId>javax.ws.rs</groupId>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.jaxrs</groupId>
+ <artifactId>jackson-jaxrs-json-provider</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-config</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-web</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-api</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jettison</groupId>
+ <artifactId>jettison</artifactId>
+ <version>1.3.2</version>
+ <type>jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/bean/PageImpl.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,149 @@
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package org.lambico.ws.archetype.template.core.bean;
+
+import java.util.Collections;
+import java.util.List;
+import org.lambico.dao.generic.Page;
+
+/**
+ * Bean for managing list paginations.
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+public class PageImpl<T> implements Page<T> {
+ /**
+ * The content of the page.
+ */
+ private List<T> results;
+ /**
+ * The size of the page, i.e. the max number of rows in a single page.
+ */
+ private int pageSize;
+ /**
+ * The index of the current page.
+ */
+ private int page;
+ /**
+ * The total rows count.
+ */
+ private int rowCount;
+ /**
+ * An empty page.
+ */
+ @SuppressWarnings("unchecked")
+ public static final Page EMPTY =
+ new PageImpl(Collections.EMPTY_LIST, 1, 1, 0);
+
+ public PageImpl() {
+ }
+
+ /**
+ * The constructor of a page.
+ *
+ * @param list The page content.
+ * @param page The index of the page.
+ * @param pageSize The size of the page.
+ * @param rowCount The total rows count.
+ */
+ public PageImpl(final List<T> list, final int page,
+ final int pageSize, final int rowCount) {
+ this.page = page;
+ this.pageSize = pageSize;
+ this.rowCount = rowCount;
+ results = list;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public int getPage() {
+ return page;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public boolean isNextPage() {
+ return page < getLastPage();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public boolean isPreviousPage() {
+ return page > 1;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public List<T> getList() {
+ return results;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public int getLastPage() {
+ int lastPage = rowCount / pageSize;
+ if (rowCount % pageSize > 0) {
+ lastPage++;
+ }
+ return lastPage;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public int getRowCount() {
+ return rowCount;
+ }
+
+ public List<T> getResults() {
+ return results;
+ }
+
+ public void setResults(
+ List<T> results) {
+ this.results = results;
+ }
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public void setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ }
+
+ public void setPage(int page) {
+ this.page = page;
+ }
+
+ public void setRowCount(int rowCount) {
+ this.rowCount = rowCount;
+ }
+
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/bean/PaginatedResult.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,82 @@
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package org.lambico.ws.archetype.template.core.bean;
+
+import java.util.List;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSeeAlso;
+import org.lambico.ws.archetype.template.core.po.Person;
+
+/**
+ * A bean for returning a paged result of items (or even a
+ * single page of results).
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+@XmlRootElement(name = "items")
+@XmlSeeAlso(Person.class)
+public class PaginatedResult<T> {
+
+ private List<T> items;
+ private int page;
+ private int rowCount;
+ private int lastPage;
+ private boolean nextPage;
+ private boolean previousPage;
+
+ @XmlElement(name = "item")
+ @XmlElementWrapper(name = "items")
+ public List<T> getItems() {
+ return items;
+ }
+
+ public void setItems(List<T> items) {
+ this.items = items;
+ }
+
+ public int getPage() {
+ return page;
+ }
+
+ public void setPage(int page) {
+ this.page = page;
+ }
+
+ public int getRowCount() {
+ return rowCount;
+ }
+
+ public void setRowCount(int rowCount) {
+ this.rowCount = rowCount;
+ }
+
+ public int getLastPage() {
+ return lastPage;
+ }
+
+ public void setLastPage(int lastPage) {
+ this.lastPage = lastPage;
+ }
+
+ public boolean isNextPage() {
+ return nextPage;
+ }
+
+ public void setNextPage(boolean nextPage) {
+ this.nextPage = nextPage;
+ }
+
+ public boolean isPreviousPage() {
+ return previousPage;
+ }
+
+ public void setPreviousPage(boolean previousPage) {
+ this.previousPage = previousPage;
+ }
+
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/bean/StringResult.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,34 @@
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package org.lambico.ws.archetype.template.core.bean;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * A result containing a single string.
+ *
+ * @author Lucio Benfante <lu...@benfante.com>
+ */
+@XmlRootElement
+public class StringResult {
+
+ private String content;
+
+ public StringResult() {
+ }
+
+ public StringResult(String content) {
+ this.content = content;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/bo/PersonBo.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,91 @@
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package org.lambico.ws.archetype.template.core.bo;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import javax.annotation.Resource;
+import org.hibernate.criterion.DetachedCriteria;
+import org.lambico.dao.generic.Page;
+import org.lambico.dao.generic.PageDefaultImpl;
+import org.lambico.dao.spring.hibernate.HibernateGenericDao;
+import org.lambico.ws.archetype.template.core.dao.PersonDao;
+import org.lambico.ws.archetype.template.core.po.Person;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * A BO to be used for the tests of the generic DAO.
+ *
+ * @author <a href="mailto:lu...@benfante.com">Lucio Benfante</a>
+ * @version $Revision$
+ */
+@Service
+public class PersonBo {
+
+ private static final Logger log =
LoggerFactory.getLogger(PersonBo.class);
+ @Resource
+ private PersonDao personDao;
+
+ @Transactional
+ public void initializeArchive() throws ParseException {
+ log.debug("Executing initializeArchive.");
+ personDao.deleteAll();
+ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
+ createPerson("Mario", "Rossi", sdf.parse("25/04/1970"));
+ createPerson("Francesca", "Verdi", sdf.parse("30/08/1990"));
+ createPerson("Giovanni", "Bianchi", sdf.parse("15/03/1980"));
+ log.debug("Created {} persons.", 3);
+ }
+
+ @Transactional(readOnly = true)
+ public Page<Person> getPaginatedPersons(Integer page, Integer
pageSize) {
+ log.debug("Executing getPaginatedPersons.");
+ DetachedCriteria crit = DetachedCriteria.forClass(Person.class);
+ crit.addOrder(org.hibernate.criterion.Order.asc("lastName"))
+ .addOrder(org.hibernate.criterion.Order.asc("firstName"));
+ Page<Person> result;
+ if (pageSize != null) {
+ if (page == null) {
+ page = new Integer(1);
+ }
+ result = ((HibernateGenericDao)
personDao).searchPaginatedByCriteria(page, pageSize, crit);
+ } else {
+ List persons = ((HibernateGenericDao)
personDao).searchByCriteria(crit);
+ result = new PageDefaultImpl<Person>(persons, new Integer(1),
persons.size(), persons.size());
+ }
+ log.debug("Retrieved {} persons.", result.getList().size());
+ return result;
+ }
+
+ @Transactional(readOnly = true)
+ public void printPerson(Long id) {
+ Person p = personDao.read(id);
+ if (p != null) {
+ System.out.println(p.getFirstName() + " " + p.getLastName()
+ " "
+ + p.getBirthDate());
+ } else {
+ System.out.println("Person (" + id + ") not found");
+ }
+ }
+
+ private void createPerson(String firstName, String lastName, Date
birthDate) throws ParseException {
+ List<Person> searches = null;
+ searches = personDao.findByFirstNameAndLastName(firstName,
lastName);
+ if (searches.isEmpty()) {
+ Person p = new Person();
+ p.setFirstName(firstName);
+ p.setLastName(lastName);
+ p.setBirthDate(birthDate);
+ personDao.create(p);
+ }
+ }
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/dao/PersonDao.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,30 @@
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package org.lambico.ws.archetype.template.core.dao;
+
+import java.util.Date;
+import java.util.List;
+import org.lambico.dao.generic.Dao;
+import org.lambico.dao.generic.GenericDao;
+import org.lambico.ws.archetype.template.core.po.Person;
+
+/**
+ * The DAO interface for the Person entity.
+ *
+ * @author <a href="mailto:lu...@benfante.com">Lucio Benfante</a>
+ * @version $Revision$
+ */
+@Dao(entity = Person.class)
+public interface PersonDao extends GenericDao<Person, Long> {
+
+ List<Person> findByLastName(String lastName);
+
+ List<Person> findByFirstNameAndLastName(String firstName, String
lastName);
+
+ List<Person> findByBirthDate(Date birthDate);
+
+ List<Person> findByFirstName(String firstName);
+}
=======================================
--- /dev/null
+++
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/po/Person.java
Sat Sep 28 13:29:19 2013 UTC
@@ -0,0 +1,63 @@
+/**
+ * Copyright (C) 2013 Lambico Team <in...@lambico.org>
+ *
+ * This file is part of Lambico WS Archetype Template - Core.
+ */
+package org.lambico.ws.archetype.template.core.po;
+
+import java.util.Date;
+
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSeeAlso;
+import org.lambico.po.hibernate.EntityBase;
+
+/**
+ * An example of a persistent object containing personal data.
+ *
+ * @author <a href="mailto:lu...@benfante.com">Lucio Benfante</a>
+ * @version $Revision$
+ */
+...@javax.persistence.Entity
+@XmlRootElement
+@XmlSeeAlso(EntityBase.class)
+public class Person extends EntityBase {
+
+ private String firstName;
+ private String lastName;
+ private Date birthDate;
+
+ public Person() {
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ @Temporal(TemporalType.DATE)
+ public Date getBirthDate() {
+ return birthDate;
+ }
+
+ public void setBirthDate(Date birthDate) {
+ this.birthDate = birthDate;
+ }
+
+ @Override
+ public String toString() {
+ return this.firstName + " " + this.lastName + " (" +
this.birthDate + ")";
+ }
+}
=======================================
***Additional files exist in this changeset.***

==============================================================================
Revision: a3901e9d02cd
Branch: default
Author: lucio.benfante <lucio.b...@gmail.com>
Date: Sat Sep 28 13:35:58 2013 UTC
Log: Removed changing version information.
http://code.google.com/p/lambico/source/detail?r=a3901e9d02cd&repo=archetypes

Modified:

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/bo/PersonBo.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/dao/PersonDao.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/po/Person.java

/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/AuthService.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/bo/PersonBo.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/dao/PersonDao.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/po/Person.java

/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/security/AuthService.java

=======================================
---
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/bo/PersonBo.java
Sat Sep 28 13:29:19 2013 UTC
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/bo/PersonBo.java
Sat Sep 28 13:35:58 2013 UTC
@@ -29,7 +29,6 @@
* A BO to be used for the tests of the generic DAO.
*
* @author <a href="mailto:lu...@benfante.com">Lucio Benfante</a>
- * @version ${symbol_dollar}Revision: a8d8760b3552 ${symbol_dollar}
*/
@Service
public class PersonBo {
=======================================
---
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/dao/PersonDao.java
Sat Sep 28 13:29:19 2013 UTC
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/dao/PersonDao.java
Sat Sep 28 13:35:58 2013 UTC
@@ -18,7 +18,6 @@
* The DAO interface for the Person entity.
*
* @author <a href="mailto:lu...@benfante.com">Lucio Benfante</a>
- * @version ${symbol_dollar}Revision: ae7fb2fab619 ${symbol_dollar}
*/
@Dao(entity = Person.class)
public interface PersonDao extends GenericDao<Person, Long> {
=======================================
---
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/po/Person.java
Sat Sep 28 13:29:19 2013 UTC
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/po/Person.java
Sat Sep 28 13:35:58 2013 UTC
@@ -20,7 +20,6 @@
* An example of a persistent object containing personal data.
*
* @author <a href="mailto:lu...@benfante.com">Lucio Benfante</a>
- * @version ${symbol_dollar}Revision: ae7fb2fab619 ${symbol_dollar}
*/
@javax.persistence.Entity
@XmlRootElement
=======================================
---
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/AuthService.java
Sat Sep 28 13:29:19 2013 UTC
+++
/lambico-ws-archetype/src/main/resources/archetype-resources/core/src/main/java/core/security/AuthService.java
Sat Sep 28 13:35:58 2013 UTC
@@ -14,7 +14,6 @@
* The authorization and authentication services.
*
* @author Lucio Benfante <lucio.b...@gmail.com>
- * @version ${symbol_dollar}Revision: 307a1ab9c32c ${symbol_dollar}
*/
public interface AuthService {

=======================================
---
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/bo/PersonBo.java
Sat Sep 28 13:29:19 2013 UTC
+++
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/bo/PersonBo.java
Sat Sep 28 13:35:58 2013 UTC
@@ -26,7 +26,6 @@
* A BO to be used for the tests of the generic DAO.
*
* @author <a href="mailto:lu...@benfante.com">Lucio Benfante</a>
- * @version $Revision$
*/
@Service
public class PersonBo {
=======================================
---
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/dao/PersonDao.java
Sat Sep 28 13:29:19 2013 UTC
+++
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/dao/PersonDao.java
Sat Sep 28 13:35:58 2013 UTC
@@ -15,7 +15,6 @@
* The DAO interface for the Person entity.
*
* @author <a href="mailto:lu...@benfante.com">Lucio Benfante</a>
- * @version $Revision$
*/
@Dao(entity = Person.class)
public interface PersonDao extends GenericDao<Person, Long> {
=======================================
---
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/po/Person.java
Sat Sep 28 13:29:19 2013 UTC
+++
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/po/Person.java
Sat Sep 28 13:35:58 2013 UTC
@@ -17,7 +17,6 @@
* An example of a persistent object containing personal data.
*
* @author <a href="mailto:lu...@benfante.com">Lucio Benfante</a>
- * @version $Revision$
*/
@javax.persistence.Entity
@XmlRootElement
=======================================
---
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/security/AuthService.java
Sat Sep 28 13:29:19 2013 UTC
+++
/lambico-ws-archetype/src/test/resources/projects/basic/reference/core/src/main/java/org/lambico/ws/archetype/template/core/security/AuthService.java
Sat Sep 28 13:35:58 2013 UTC
@@ -11,7 +11,6 @@
* The authorization and authentication services.
*
* @author Lucio Benfante <lucio.b...@gmail.com>
- * @version $Revision$
*/
public interface AuthService {


==============================================================================
Revision: e48645b2c709
Branch: default
Author: lucio.benfante <lucio.b...@gmail.com>
Date: Sat Sep 28 13:43:39 2013 UTC
Log: Added ignored file
http://code.google.com/p/lambico/source/detail?r=e48645b2c709&repo=archetypes

Added:
/.hgignore

=======================================
--- /dev/null
+++ /.hgignore Sat Sep 28 13:43:39 2013 UTC
@@ -0,0 +1,2 @@
+syntag: regexp
+^lambico-ws-archetype/target
Reply all
Reply to author
Forward
0 new messages