[jboss-cvs] JBossAS SVN: r100053 - in projects/snowdrop/examples/trunk/sportsclub: sportsclub-invoicing-webmvc/src/main/java/org/jboss/snowdrop/samples/sportsclub/springmvc and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jan 28 10:31:16 EST 2010
Author: lvlcek at redhat.com
Date: 2010-01-28 10:31:16 -0500 (Thu, 28 Jan 2010)
New Revision: 100053
Removed:
projects/snowdrop/examples/trunk/sportsclub/sportsclub-invoicing-webmvc/src/main/java/org/jboss/snowdrop/samples/sportsclub/springmvc/BooleanOption.java
Modified:
projects/snowdrop/examples/trunk/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/hibernate/HibernateAccountRepository.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-invoicing-webmvc/src/main/java/org/jboss/snowdrop/samples/sportsclub/springmvc/AccountController.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-invoicing-webmvc/src/main/webapp/WEB-INF/jsp/searchAccount.jsp
Log:
Spring MVC (work in progress) - added current invoice subquery
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/hibernate/HibernateAccountRepository.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/hibernate/HibernateAccountRepository.java 2010-01-28 15:22:35 UTC (rev 100052)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/hibernate/HibernateAccountRepository.java 2010-01-28 15:31:16 UTC (rev 100053)
@@ -1,17 +1,15 @@
package org.jboss.snowdrop.samples.sportsclub.dao.hibernate;
-import static org.hibernate.criterion.Restrictions.ilike;
-import static org.hibernate.criterion.Restrictions.or;
-
import java.util.List;
+import java.util.Date;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
-import org.hibernate.criterion.MatchMode;
-import org.hibernate.criterion.Projections;
-import org.hibernate.criterion.Restrictions;
+import org.hibernate.criterion.*;
+import static org.hibernate.criterion.Restrictions.*;
import org.jboss.snowdrop.samples.sportsclub.domain.entity.Account;
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.Invoice;
import org.jboss.snowdrop.samples.sportsclub.domain.repository.AccountRepository;
import org.jboss.snowdrop.samples.sportsclub.domain.repository.criteria.AccountSearchCriteria;
import org.jboss.snowdrop.samples.sportsclub.domain.repository.criteria.PersonSearchCriteria;
@@ -34,7 +32,7 @@
"or a.subscriber.name.lastName like :name " +
"or a.subscriber.name.middleName like :name");
query.setString("name", "%" + name + "%");
- return (List<Account>)query.list();
+ return (List<Account>) query.list();
}
@@ -42,13 +40,14 @@
{
Criteria criteria = convert(accountSearchCriteria);
criteria.setProjection(Projections.count("id"));
- return (Integer)criteria.uniqueResult();
+ return (Integer) criteria.uniqueResult();
}
private Criteria convert(AccountSearchCriteria accountSearchCriteria)
{
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Account.class);
- if (accountSearchCriteria.isActiveOnly()) {
+ if (accountSearchCriteria.isActiveOnly())
+ {
criteria.add(Restrictions.eq("closed", false));
}
if (accountSearchCriteria.getPersonSearchCriteria() != null)
@@ -59,21 +58,33 @@
{
personCriteria.add(
or(ilike("name.firstName", personSearchCriteria.getName(), MatchMode.ANYWHERE),
- or(ilike("name.lastName", personSearchCriteria.getName(), MatchMode.ANYWHERE),
- ilike("name.middleName", personSearchCriteria.getName(), MatchMode.ANYWHERE))));
+ or(ilike("name.lastName", personSearchCriteria.getName(), MatchMode.ANYWHERE),
+ ilike("name.middleName", personSearchCriteria.getName(), MatchMode.ANYWHERE))));
}
if (personSearchCriteria.getCity() != null)
{
personCriteria.add(ilike("address.city", personSearchCriteria.getCity(), MatchMode.ANYWHERE));
}
- }
+ }
+ if (accountSearchCriteria.getInvoiceSearchCriteria() != null)
+ {
+ Date now = new Date();
+ DetachedCriteria invcEntries = DetachedCriteria.forClass(Invoice.class)
+ .setProjection(Property.forName("id"));
+ invcEntries.add(and(ge("billingPeriod.startDate", now), le("billingPeriod.endDate", now)));
+
+ if (accountSearchCriteria.getInvoiceSearchCriteria().isCurrentInvoice())
+ criteria.add(Subqueries.propertyIn("id", invcEntries));
+ else
+ criteria.add(Subqueries.propertyNotIn("id", invcEntries));
+ }
return criteria;
}
public List<Account> findByCriteria(AccountSearchCriteria accountSearchCriteria)
{
Criteria criteria = convert(accountSearchCriteria);
- if (accountSearchCriteria.getRange()!=null)
+ if (accountSearchCriteria.getRange() != null)
{
criteria.setFirstResult(accountSearchCriteria.getRange().getMinIndex());
criteria.setMaxResults(accountSearchCriteria.getRange().length());
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-invoicing-webmvc/src/main/java/org/jboss/snowdrop/samples/sportsclub/springmvc/AccountController.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-invoicing-webmvc/src/main/java/org/jboss/snowdrop/samples/sportsclub/springmvc/AccountController.java 2010-01-28 15:22:35 UTC (rev 100052)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-invoicing-webmvc/src/main/java/org/jboss/snowdrop/samples/sportsclub/springmvc/AccountController.java 2010-01-28 15:31:16 UTC (rev 100053)
@@ -18,12 +18,10 @@
public class AccountController
{
- private static final BooleanOption[] invoiceStatus;
+ private static final String[] invoiceStatus;
static {
- invoiceStatus = new BooleanOption[2];
- invoiceStatus[0] = new BooleanOption(UserInput.INVOICE_WITH, true);
- invoiceStatus[1] = new BooleanOption(UserInput.INVOICE_WITHOUT, false);
+ invoiceStatus = new String[]{UserInput.INVOICE_WITHOUT, UserInput.INVOICE_WITH};
}
@EJB(mappedName = "sportsclub/SubscriptionService")
@@ -50,9 +48,12 @@
{
String nameFragment = userInput.getNameFragment();
Integer maxAccountNum = userInput.getMaxAccountNum();
-
- List<Account> accountList = subscriptionService.findAccountsBySubscriberName(nameFragment, 0, maxAccountNum);
+ boolean currentInvoice = (UserInput.INVOICE_WITH.equals(userInput.getInvoiceStatus()) ? true : false);
+ System.out.println("****** currentInvoice = " + currentInvoice);
+
+ List<Account> accountList = subscriptionService.findAccountsBySubscriberName(nameFragment, 0, maxAccountNum, currentInvoice);
+
ModelMap model = new ModelMap();
model.addAttribute(userInput)
.addAttribute(accountList)
Deleted: projects/snowdrop/examples/trunk/sportsclub/sportsclub-invoicing-webmvc/src/main/java/org/jboss/snowdrop/samples/sportsclub/springmvc/BooleanOption.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-invoicing-webmvc/src/main/java/org/jboss/snowdrop/samples/sportsclub/springmvc/BooleanOption.java 2010-01-28 15:22:35 UTC (rev 100052)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-invoicing-webmvc/src/main/java/org/jboss/snowdrop/samples/sportsclub/springmvc/BooleanOption.java 2010-01-28 15:31:16 UTC (rev 100053)
@@ -1,37 +0,0 @@
-package org.jboss.snowdrop.samples.sportsclub.springmvc;
-
-/**
- * Represents option for HTML select list.
- * @author <a href="mailto:lvlcek at redhat.com">Lukas Vlcek</a>
- */
-public class BooleanOption
-{
- private String label;
- private boolean value;
-
- public BooleanOption(String label, boolean value)
- {
- this.label = label;
- this.value = value;
- }
-
- public String getLabel()
- {
- return label;
- }
-
- public void setLabel(String label)
- {
- this.label = label;
- }
-
- public boolean isValue()
- {
- return value;
- }
-
- public void setValue(boolean value)
- {
- this.value = value;
- }
-}
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-invoicing-webmvc/src/main/webapp/WEB-INF/jsp/searchAccount.jsp
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-invoicing-webmvc/src/main/webapp/WEB-INF/jsp/searchAccount.jsp 2010-01-28 15:22:35 UTC (rev 100052)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-invoicing-webmvc/src/main/webapp/WEB-INF/jsp/searchAccount.jsp 2010-01-28 15:31:16 UTC (rev 100053)
@@ -9,7 +9,7 @@
<form:form commandName="userInput">
- Search accounts <form:select path="invoiceStatus" items="${booleanOptionList}" itemLabel="label" itemValue="value" /> current invoice by subscriber name:<br/>
+ Search accounts <form:select path="invoiceStatus" items="${stringList}"/> current invoice by subscriber name:<br/>
<form:input path="nameFragment"/> <input type="submit" value="Search"/><br/>
<span style="font-size:70%">
Display up to
More information about the jboss-cvs-commits
mailing list