[seam-commits] Seam SVN: r13280 - examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Sat Jun 19 21:43:50 EDT 2010
Author: pete.muir at jboss.org
Date: 2010-06-19 21:43:49 -0400 (Sat, 19 Jun 2010)
New Revision: 13280
Removed:
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/ConfirmedLiteral.java
Modified:
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/Confirmed.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/ReservationDateRangeValidator.java
Log:
javadoc
Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java 2010-06-20 01:41:48 UTC (rev 13279)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java 2010-06-20 01:43:49 UTC (rev 13280)
@@ -23,6 +23,8 @@
import static javax.persistence.PersistenceContextType.EXTENDED;
+import java.util.Locale;
+
import javax.ejb.Stateful;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
@@ -37,6 +39,7 @@
import javax.persistence.PersistenceContext;
import org.jboss.seam.examples.booking.account.Authenticated;
+import org.jboss.seam.examples.booking.i18n.DefaultBundleKey;
import org.jboss.seam.examples.booking.model.Booking;
import org.jboss.seam.examples.booking.model.Hotel;
import org.jboss.seam.examples.booking.model.User;
@@ -47,16 +50,14 @@
import org.slf4j.Logger;
import com.ocpsoft.pretty.time.PrettyTime;
-import java.util.Locale;
-import org.jboss.seam.examples.booking.i18n.DefaultBundleKey;
-import org.jboss.seam.international.locale.UserLocale;
/**
+ * The BookingAgent manages the main booking flow
+ *
* @author Dan Allen
*/
- at Named
- at Stateful
- at ConversationScoped
+
+ at Stateful @ConversationScoped @Named
public class BookingAgent
{
@Inject
@@ -71,15 +72,13 @@
@Inject
private Messages messages;
- @Inject
- @Authenticated
+ @Inject @Authenticated
private User user;
@Inject
private Locale locale;
- @Inject
- @Confirmed
+ @Inject @Confirmed
private Event<Booking> bookingConfirmedEventSrc;
private Hotel hotelSelection;
@@ -138,17 +137,13 @@
messages.info(new DefaultBundleKey("booking_confirmed")).textDefault("You're booked to stay at the {0} {1}.").textParams(booking.getHotel().getName(), new PrettyTime(locale).format(booking.getCheckinDate()));
}
- @Produces
- @Named
- @ConversationScoped
+ @Produces @ConversationScoped @Named
public Booking getBooking()
{
return booking;
}
- @Produces
- @Named("hotel")
- @RequestScoped
+ @Produces @RequestScoped @Named("hotel")
public Hotel getSelectedHotel()
{
return booking != null ? booking.getHotel() : hotelSelection;
Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java 2010-06-20 01:41:48 UTC (rev 13279)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java 2010-06-20 01:43:49 UTC (rev 13280)
@@ -52,18 +52,18 @@
import org.slf4j.Logger;
/**
+ * The booking history exposes the current users existing bookings
+ *
* @author Dan Allen
*/
- at Named
- at Stateful
- at SessionScoped
+ at Stateful @SessionScoped @Named
public class BookingHistory
{
@Inject
private Logger log;
@PersistenceContext
- private EntityManager em;
+ private EntityManager entityManager;
@Inject
private Messages messages;
@@ -76,9 +76,7 @@
private List<Booking> bookingsForUser = null;
- @Produces
- @Authenticated
- @Named("bookings")
+ @Produces @Authenticated @Named("bookings")
public List<Booking> getBookingsForCurrentUser()
{
if (bookingsForUser == null && identity.isLoggedIn())
@@ -88,8 +86,7 @@
return bookingsForUser;
}
- public void onBookingComplete(@Observes(during = TransactionPhase.AFTER_SUCCESS, notifyObserver = Reception.IF_EXISTS)
- @Confirmed final Booking booking)
+ public void onBookingComplete(@Observes(during = TransactionPhase.AFTER_SUCCESS, notifyObserver = Reception.IF_EXISTS) @Confirmed Booking booking)
{
// optimization, save the db call
if (bookingsForUser != null)
@@ -106,10 +103,10 @@
public void cancelBooking(final Booking selectedBooking)
{
log.info("Canceling booking {0} for {1}", selectedBooking.getId(), currentUserInstance.get().getName());
- Booking booking = em.find(Booking.class, selectedBooking.getId());
+ Booking booking = entityManager.find(Booking.class, selectedBooking.getId());
if (booking != null)
{
- em.remove(booking);
+ entityManager.remove(booking);
messages.info(new DefaultBundleKey("booking_canceled"))
.textDefault("The booking at the {0} on {1} has been canceled.")
.textParams(selectedBooking.getHotel().getName(),
@@ -127,7 +124,7 @@
private void fetchBookingsForCurrentUser()
{
String username = currentUserInstance.get().getUsername();
- CriteriaBuilder builder = em.getCriteriaBuilder();
+ CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Booking> cquery = builder.createQuery(Booking.class);
Root<Booking> booking = cquery.from(Booking.class);
booking.fetch(Booking_.hotel, JoinType.INNER);
@@ -135,7 +132,7 @@
.where(builder.equal(booking.get(Booking_.user).get(User_.username), username))
.orderBy(builder.asc(booking.get(Booking_.checkinDate)));
- bookingsForUser = em.createQuery(cquery).getResultList();
+ bookingsForUser = entityManager.createQuery(cquery).getResultList();
}
}
Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/Confirmed.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/Confirmed.java 2010-06-20 01:41:48 UTC (rev 13279)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/Confirmed.java 2010-06-20 01:43:49 UTC (rev 13280)
@@ -34,12 +34,12 @@
import javax.inject.Qualifier;
/**
+ * A qualifier, used to differentiate confirmed and unconfirmed bookings
+ *
* @author Dan Allen
*/
@Target( { TYPE, METHOD, PARAMETER, FIELD })
@Retention(RUNTIME)
@Documented
@Qualifier
-public @interface Confirmed
-{
-}
+public @interface Confirmed {}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/ConfirmedLiteral.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/ConfirmedLiteral.java 2010-06-20 01:41:48 UTC (rev 13279)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/ConfirmedLiteral.java 2010-06-20 01:43:49 UTC (rev 13280)
@@ -1,29 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.seam.examples.booking.booking;
-
-import javax.enterprise.util.AnnotationLiteral;
-
-public class ConfirmedLiteral extends AnnotationLiteral<Confirmed> implements Confirmed
-{
- public static final ConfirmedLiteral INSTANCE = new ConfirmedLiteral();
-}
Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/ReservationDateRangeValidator.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/ReservationDateRangeValidator.java 2010-06-20 01:41:48 UTC (rev 13279)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/ReservationDateRangeValidator.java 2010-06-20 01:43:49 UTC (rev 13280)
@@ -40,7 +40,7 @@
import org.jboss.seam.international.status.builder.BundleTemplateMessage;
/**
- * A cross-field validator that validates the begin date is in the future and
+ * A cross-field validator that validates the start date is in the future and
* before the end date.
*
* @author Dan Allen
@@ -48,30 +48,31 @@
@FacesValidator("reservationDateRange")
public class ReservationDateRangeValidator implements Validator
{
- @Inject
- @InputField
- private Date beginDate;
+ @Inject @InputField
+ private Date startDate;
- @Inject
- @InputField
+ @Inject @InputField
private Date endDate;
@Inject
private Instance<BundleTemplateMessage> messageBuilder;
+
public void validate(final FacesContext ctx, final UIComponent form, final Object value) throws ValidatorException
{
+ @SuppressWarnings("unchecked")
Map<String, UIInput> fieldMap = (Map<String, UIInput>) value;
+
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -1);
- if (beginDate.before(calendar.getTime()))
+ if (startDate.before(calendar.getTime()))
{
String message = messageBuilder.get().text(new DefaultBundleKey("booking_checkInNotFutureDate"))
// FIXME the component should come through via injection
.targets(fieldMap.get("beginDate").getClientId()).build().getText();
throw new ValidatorException(new FacesMessage(message));
}
- else if (!beginDate.before(endDate))
+ else if (!startDate.before(endDate))
{
String message = messageBuilder.get().text(new DefaultBundleKey("booking_checkOutBeforeCheckIn"))
// FIXME the component should come through via injection
More information about the seam-commits
mailing list