Author: manaRH
Date: 2010-11-16 05:48:55 -0500 (Tue, 16 Nov 2010)
New Revision: 13913
Added:
branches/community/Seam_2_2/examples/dvdstore/build-jboss6.xml
branches/community/Seam_2_2/examples/dvdstore/jboss6/
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/seam/
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/seam/FullTextSearchAction.java
Modified:
branches/community/Seam_2_2/examples/dvdstore/build.xml
branches/community/Seam_2_2/examples/dvdstore/readme.txt
branches/community/Seam_2_2/examples/dvdstore/resources/META-INF/persistence.xml
branches/community/Seam_2_2/examples/dvdstore/resources/WEB-INF/pages.xml
Log:
JBSEAM-4714 added jboss as6 build script for dvdstore example
Added: branches/community/Seam_2_2/examples/dvdstore/build-jboss6.xml
===================================================================
--- branches/community/Seam_2_2/examples/dvdstore/build-jboss6.xml
(rev 0)
+++ branches/community/Seam_2_2/examples/dvdstore/build-jboss6.xml 2010-11-16 10:48:55 UTC
(rev 13913)
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<project name="DvdStore" default="deploy"
basedir=".">
+
+ <!-- Naming -->
+ <property name="Name" value="Seam Dvd Store
Example"/>
+ <property name="example.name"
value="jboss-seam-dvdstore"/>
+ <property name="jboss6" value="yes"/>
+
+ <target name="init" depends="preparesrc">
+ <antcall target="SeamExample.init"/>
+ <path id="build.classpath.extras">
+ <fileset dir="${lib.search.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+ </target>
+
+ <target name="preparesrc">
+ <mkdir dir="${src.java.dir}"/>
+
+ <copy todir="${src.java.dir}">
+ <fileset includes="**" dir="jboss6/src" />
+ </copy>
+ <copy todir="${src.java.dir}">
+ <fileset includes="**"
excludes="src/com/jboss/dvd/seam/FullTextSearchAction.java"
dir="src"/>
+ </copy>
+
+ </target>
+
+ <import file="../build.xml"/>
+
+</project>
Property changes on: branches/community/Seam_2_2/examples/dvdstore/build-jboss6.xml
___________________________________________________________________
Name: svn:executable
+ *
Modified: branches/community/Seam_2_2/examples/dvdstore/build.xml
===================================================================
--- branches/community/Seam_2_2/examples/dvdstore/build.xml 2010-11-16 10:47:20 UTC (rev
13912)
+++ branches/community/Seam_2_2/examples/dvdstore/build.xml 2010-11-16 10:48:55 UTC (rev
13913)
@@ -16,6 +16,10 @@
<!-- Datasource -->
<property name="example.ds" value="jboss-seam-dvdstore-ds.xml"
/>
+
+ <target name="jboss6" description="Build the DVD Store example
artifacts, and deploy to JBoss AS 6">
+ <ant antfile="build-jboss6.xml"/>
+ </target>
<import file="../build.xml" />
@@ -40,5 +44,5 @@
<target name="jboss42" description="Build the DvdStore example
artifacts, and deploy to JBoss 4.2.x.GA">
<ant antfile="build-jboss42.xml"/>
</target>
-
+
</project>
Added:
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/seam/FullTextSearchAction.java
===================================================================
---
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/seam/FullTextSearchAction.java
(rev 0)
+++
branches/community/Seam_2_2/examples/dvdstore/jboss6/src/com/jboss/dvd/seam/FullTextSearchAction.java 2010-11-16
10:48:55 UTC (rev 13913)
@@ -0,0 +1,296 @@
+//$Id: FullTextSearchAction.java 7961 2008-04-17 04:30:44Z norman.richards(a)jboss.com $
+package com.jboss.dvd.seam;
+
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.queryParser.MultiFieldQueryParser;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.util.Version;
+import org.hibernate.search.jpa.FullTextEntityManager;
+import org.hibernate.search.jpa.FullTextQuery;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Begin;
+import org.jboss.seam.annotations.Destroy;
+import org.jboss.seam.annotations.End;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.datamodel.DataModel;
+import org.jboss.seam.util.Reflections;
+
+/**
+ * Hibernate Search version of the store querying mechanism
+ * @author Emmanuel Bernard
+ */
+@Stateful
+@Name("search")
+public class FullTextSearchAction
+ implements FullTextSearch,
+ Serializable
+{
+ static final long serialVersionUID = -6536629890251170098L;
+
+ @In(create=true)
+ ShoppingCart cart;
+
+ @PersistenceContext
+ EntityManager em;
+
+ //@RequestParameter
+ Long id;
+
+ int pageSize = 15;
+ int currentPage = 0;
+ boolean hasMore = false;
+ int numberOfResults;
+
+ String searchQuery;
+
+ @DataModel
+ List<Product> searchResults;
+
+ //@DataModelSelection
+ Product selectedProduct;
+
+ @Out(required = false)
+ Product dvd;
+
+ @Out(scope=ScopeType.CONVERSATION, required=false)
+ Map<Product, Boolean> searchSelections;
+
+
+ public String getSearchQuery() {
+ return searchQuery;
+ }
+
+ public void setSearchQuery(String searchQuery) {
+ this.searchQuery = searchQuery;
+ }
+
+
+ public int getNumberOfResults() {
+ return numberOfResults;
+ }
+
+ @Begin(join = true)
+ public String doSearch() {
+ currentPage = 0;
+ updateResults();
+
+ return "browse";
+ }
+
+ public void nextPage() {
+ if (!isLastPage()) {
+ currentPage++;
+ updateResults();
+ }
+ }
+
+ public void prevPage() {
+ if (!isFirstPage()) {
+ currentPage--;
+ updateResults();
+ }
+ }
+
+ @Begin(join = true)
+ public void selectFromRequest() {
+ if (id != null) {
+ dvd = em.find(Product.class, id);
+ } else if (selectedProduct != null) {
+ dvd = selectedProduct;
+ }
+ }
+
+ public boolean isLastPage() {
+ return ( searchResults != null ) && !hasMore;
+ }
+
+ public boolean isFirstPage() {
+ return ( searchResults != null ) && ( currentPage == 0 );
+ }
+
+ @SuppressWarnings("unchecked")
+ private void updateResults() {
+ FullTextQuery query;
+ try {
+ query = searchQuery(searchQuery);
+ } catch (ParseException pe) {
+ return;
+ }
+ System.out.println("Query " + query);
+ List<Product> items = query
+ .setMaxResults(pageSize + 1)
+ .setFirstResult(pageSize * currentPage)
+ .getResultList();
+ numberOfResults = query.getResultSize();
+
+ if (items.size() > pageSize) {
+ searchResults = new ArrayList(items.subList(0, pageSize));
+ hasMore = true;
+ } else {
+ searchResults = items;
+ hasMore = false;
+ }
+
+ searchSelections = new HashMap<Product, Boolean>();
+ }
+
+ private FullTextQuery searchQuery(String searchQuery) throws ParseException
+ {
+ Map<String,Float> boostPerField = new HashMap<String,Float>();
+ boostPerField.put("title", 4f);
+ boostPerField.put("description", 2f);
+ boostPerField.put("actors.name", 2f);
+ boostPerField.put("categories.name", 0.5f);
+
+ String[] productFields = {"title", "description",
"actors.name", "categories.name"};
+
+ Analyzer defaultAnalyzer = ((FullTextEntityManager)
em).getSearchFactory().getAnalyzer(Product.class);
+ QueryParser parser = createNewInstanceOfQueryParser(Version.LUCENE_30,
productFields, defaultAnalyzer, boostPerField);
+
+ parser.setAllowLeadingWildcard(true);
+ org.apache.lucene.search.Query luceneQuery = parser.parse(searchQuery);
+ return ( (FullTextEntityManager) em ).createFullTextQuery(luceneQuery,
Product.class);
+ }
+
+ @SuppressWarnings("finally")
+ private QueryParser createNewInstanceOfQueryParser(Object luceneVersion, String[]
productFields, Analyzer defaultAnalyzer, Map<String, Float> boostPerField)
+ {
+ //Class.forName("org.apache.lucene.queryParser.MultiFieldQueryParser");
+ Class targetClass = MultiFieldQueryParser.class;
+
+ Constructor properConstructor = null;
+ if ( luceneVersion == null )
+ {
+ //older constructor - String[] productFields, Analyzer defaultAnalyzer,
Map<String, Float> boostPerField
+ properConstructor = getProperConstructor(targetClass.getConstructors(), 3);
+ try
+ {
+ return (QueryParser) properConstructor.newInstance(productFields,
defaultAnalyzer, boostPerField);
+ }
+ catch (IllegalArgumentException e)
+ {
+ return null;
+ }
+ catch (InstantiationException e)
+ {
+ return null;
+ }
+ catch (IllegalAccessException e)
+ {
+ return null;
+ }
+ catch (InvocationTargetException e)
+ {
+ return null;
+ }
+
+ }
+ else
+ {
+ //newer constructor - Version luceneVersion. String[] productFields, Analyzer
defaultAnalyzer, Map<String, Float> boostPerField
+ properConstructor = getProperConstructor(targetClass.getConstructors(), 4);
+ try
+ {
+ return (QueryParser) properConstructor.newInstance(luceneVersion,
productFields, defaultAnalyzer, boostPerField);
+ }
+ catch (IllegalArgumentException e)
+ {
+ return null;
+ }
+ catch (InstantiationException e)
+ {
+ return null;
+ }
+ catch (IllegalAccessException e)
+ {
+ return null;
+ }
+ catch (InvocationTargetException e)
+ {
+ return null;
+ }
+ }
+
+ }
+
+ private Constructor getProperConstructor(Constructor[] constructors, int
properLength)
+ {
+ Constructor properConstructor = null;
+
+ for (int i = 0; i < constructors.length; i++ )
+ {
+ Constructor constructor = constructors[i];
+ Class[] parametersType = constructor.getParameterTypes();
+ if (parametersType.length == properLength)
+ {
+ // TODO: very weak condition, but for testing purpose
+ properConstructor = constructor;
+ return properConstructor;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Add the selected DVD to the cart
+ */
+ public void addToCart()
+ {
+ cart.addProduct(dvd, 1);
+ }
+
+ /**
+ * Add many items to cart
+ */
+ public void addAllToCart()
+ {
+ for (Product item : searchResults) {
+ Boolean selected = searchSelections.get(item);
+ if (selected != null && selected) {
+ searchSelections.put(item, false);
+ cart.addProduct(item, 1);
+ }
+ }
+ }
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public void setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ }
+
+ public Long getSelectedId() {
+ return id;
+ }
+
+ public void setSelectedId(Long id) {
+ this.id = id;
+ }
+
+ @End
+ public void reset() { }
+
+ @Destroy
+ @Remove
+ public void destroy() { }
+}
Modified: branches/community/Seam_2_2/examples/dvdstore/readme.txt
===================================================================
--- branches/community/Seam_2_2/examples/dvdstore/readme.txt 2010-11-16 10:47:20 UTC (rev
13912)
+++ branches/community/Seam_2_2/examples/dvdstore/readme.txt 2010-11-16 10:48:55 UTC (rev
13913)
@@ -7,4 +7,8 @@
JBoss AS 4.2 needs additional hibernate libraries, use ant target jboss42 for deploying
to it.
+JBoss AS 6 needs new hibernate search and hibernate-commons-annotations, and more source
code enhancement due Hibernate Search and Lucene-Core
+API changes. Therefore use ant target jboss6 for deploying to JBoss AS 6 M5 and later.
For instance:
+$ant jboss6 -Djboss6=yes
+
example.name=dvdstore
Modified:
branches/community/Seam_2_2/examples/dvdstore/resources/META-INF/persistence.xml
===================================================================
---
branches/community/Seam_2_2/examples/dvdstore/resources/META-INF/persistence.xml 2010-11-16
10:47:20 UTC (rev 13912)
+++
branches/community/Seam_2_2/examples/dvdstore/resources/META-INF/persistence.xml 2010-11-16
10:48:55 UTC (rev 13913)
@@ -19,11 +19,11 @@
value="org.hibernate.search.store.FSDirectoryProvider"/>
<!-- directory where the indexes will be stored -->
<property name="hibernate.search.default.indexBase"
value="./dvdindexes"/>
- <!-- Not needed with HA 3.3 -->
+ <!-- Not needed with HA 3.3
<property name="hibernate.ejb.event.post-insert"
value="org.hibernate.search.event.FullTextIndexEventListener"/>
<property name="hibernate.ejb.event.post-update"
value="org.hibernate.search.event.FullTextIndexEventListener"/>
<property name="hibernate.ejb.event.post-delete"
value="org.hibernate.search.event.FullTextIndexEventListener"/>
-
+ -->
<property name="jboss.entity.manager.factory.jndi.name"
value="java:/dvdstoreEntityManagerFactory" />
</properties>
Modified: branches/community/Seam_2_2/examples/dvdstore/resources/WEB-INF/pages.xml
===================================================================
--- branches/community/Seam_2_2/examples/dvdstore/resources/WEB-INF/pages.xml 2010-11-16
10:47:20 UTC (rev 13912)
+++ branches/community/Seam_2_2/examples/dvdstore/resources/WEB-INF/pages.xml 2010-11-16
10:48:55 UTC (rev 13913)
@@ -27,6 +27,10 @@
<rule if-outcome="accept">
<redirect view-id="/admin/accept.xhtml"/>
</rule>
+ <rule if-outcome="taskAssignedToActor">
+ <redirect view-id="/admin/admin.xhtml"/>
+ </rule>
+
</navigation>
</page>