[seam-commits] Seam SVN: r13218 - in examples/trunk/booking-simplified/src: main/java/org/jboss/seam/examples/booking/booking and 6 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Jun 17 13:41:31 EDT 2010
Author: lincolnthree
Date: 2010-06-17 13:41:30 -0400 (Thu, 17 Jun 2010)
New Revision: 13218
Added:
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountHolder.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/CurrentPasswordValidator.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java
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/bootstrap/ApplicationInitializer.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/Authenticator.java
Removed:
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountHolder.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountHolderBean.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/ChangePasswordValidator.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/PasswordManagerBean.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/RegistrarBean.java
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/BookingAgentBean.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/BookingHistoryBean.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationSetup.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationSetupBean.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearchBean.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/Authenticator.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/AuthenticatorBean.java
Modified:
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/ConfirmPasswordValidator.java
examples/trunk/booking-simplified/src/main/webapp/WEB-INF/beans.xml
examples/trunk/booking-simplified/src/main/webapp/password.xhtml
examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/booking/BookingAgentTest.java
Log:
Removed @Local interfaces - updated Password Validators
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountHolder.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountHolder.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountHolder.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,40 +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.account;
-
-import javax.ejb.Local;
-import org.jboss.seam.examples.booking.model.User;
-
-/**
- * The <strong>AccountProducer</strong> produces the object that
- * represents the current user's account information. The account
- * information is represented by the {@link User} entity.
- *
- * @author Dan Allen
- */
- at Local
-public interface AccountHolder
-{
- User getCurrentAccount();
-
- void onLogin(User user);
-}
Copied: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountHolder.java (from rev 13217, examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountHolderBean.java)
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountHolder.java (rev 0)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountHolder.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -0,0 +1,53 @@
+/*
+ * 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.account;
+
+import javax.ejb.Stateful;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+
+import org.jboss.seam.examples.booking.model.User;
+
+/**
+ * @author Dan Allen
+ */
+ at Stateful
+ at SessionScoped
+public class AccountHolder
+{
+ private User currentUser;
+
+ @Produces
+ @Authenticated
+ @Named("currentUser")
+ public User getCurrentAccount()
+ {
+ return currentUser;
+ }
+
+ public void onLogin(@Observes @Authenticated User user)
+ {
+ currentUser = user;
+ }
+}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountHolderBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountHolderBean.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountHolderBean.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,53 +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.account;
-
-import javax.ejb.Stateful;
-import javax.enterprise.context.SessionScoped;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Produces;
-import javax.inject.Named;
-
-import org.jboss.seam.examples.booking.model.User;
-
-/**
- * @author Dan Allen
- */
- at Stateful
- at SessionScoped
-public class AccountHolderBean implements AccountHolder
-{
- private User currentUser;
-
- @Produces
- @Authenticated
- @Named("currentUser")
- public User getCurrentAccount()
- {
- return currentUser;
- }
-
- public void onLogin(@Observes @Authenticated User user)
- {
- currentUser = user;
- }
-}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/ChangePasswordValidator.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/ChangePasswordValidator.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/ChangePasswordValidator.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,56 +0,0 @@
-package org.jboss.seam.examples.booking.account;
-
-import java.util.Map;
-
-import javax.enterprise.inject.Instance;
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIInput;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.FacesValidator;
-import javax.faces.validator.Validator;
-import javax.faces.validator.ValidatorException;
-import javax.inject.Inject;
-
-import org.jboss.seam.examples.booking.Bundles;
-import org.jboss.seam.examples.booking.model.User;
-import org.jboss.seam.faces.validation.InputField;
-import org.jboss.seam.international.status.builder.BundleKey;
-import org.jboss.seam.international.status.builder.BundleTemplateMessage;
-
-/**
- * @author Dan Allen
- */
- at FacesValidator(value = "changePasswordValidator")
-public class ChangePasswordValidator implements Validator
-// extending throws an unsatisified dependency exception
-// extends ConfirmPasswordValidator
-{
- @Inject
- private Instance<BundleTemplateMessage> messageBuilder;
-
- @Inject
- @Authenticated
- private User currentUser;
-
- @Inject
- @InputField
- private String currentPassword;
-
- public void validate(final FacesContext ctx, final UIComponent form, final Object value) throws ValidatorException
- {
- Map<String, UIInput> fieldMap = (Map<String, UIInput>) value;
- if ((currentUser.getPassword() != null) && !currentUser.getPassword().equals(currentPassword))
- {
- /*
- * This is an ugly way to put i18n in FacesMessages:
- * https://jira.jboss.org/browse/SEAMFACES-24
- */
- throw new ValidatorException(new FacesMessage(messageBuilder.get().text(new BundleKey(Bundles.MESSAGES, "account.passwordNotConfirmed")).targets(fieldMap.get("oldPassword").getClientId()).build().getText()));
- }
-
- // TODO enable when we can extend
- // super.validate(ctx, form, value);
- }
-
-}
Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/ConfirmPasswordValidator.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/ConfirmPasswordValidator.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/ConfirmPasswordValidator.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -29,8 +29,8 @@
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import javax.inject.Inject;
+
import org.jboss.seam.examples.booking.Bundles;
-
import org.jboss.seam.faces.validation.InputField;
import org.jboss.seam.international.status.builder.BundleKey;
import org.jboss.seam.international.status.builder.BundleTemplateMessage;
@@ -54,11 +54,11 @@
public void validate(final FacesContext ctx, final UIComponent c, final Object value) throws ValidatorException
{
- if (newPassword != null && !newPassword.equals(confirmPassword))
+ if ((newPassword != null) && !newPassword.equals(confirmPassword))
{
throw new ValidatorException(
- new FacesMessage(messageBuilder.get().text(
- new BundleKey(Bundles.MESSAGES, "account.passwordsDoNotMatch"))
+ new FacesMessage(messageBuilder.get().text(
+ new BundleKey(Bundles.MESSAGES, "account.passwordsDoNotMatch"))
.build().getText()));
}
}
Copied: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/CurrentPasswordValidator.java (from rev 13217, examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/ChangePasswordValidator.java)
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/CurrentPasswordValidator.java (rev 0)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/CurrentPasswordValidator.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -0,0 +1,45 @@
+package org.jboss.seam.examples.booking.account;
+
+import javax.enterprise.inject.Instance;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.FacesValidator;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+import javax.inject.Inject;
+
+import org.jboss.seam.examples.booking.Bundles;
+import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.international.status.builder.BundleKey;
+import org.jboss.seam.international.status.builder.BundleTemplateMessage;
+
+/**
+ * @author Dan Allen
+ */
+ at FacesValidator(value = "currentPasswordValidator")
+public class CurrentPasswordValidator implements Validator
+{
+ @Inject
+ private Instance<BundleTemplateMessage> msg;
+
+ @Inject
+ @Authenticated
+ private User currentUser;
+
+ @SuppressWarnings("unchecked")
+ public void validate(final FacesContext ctx, final UIComponent comp, final Object value) throws ValidatorException
+ {
+ String currentPassword = (String) value;
+ if ((currentUser.getPassword() != null) && !currentUser.getPassword().equals(currentPassword))
+ {
+ /*
+ * This is an ugly way to put i18n in FacesMessages: https://jira.jboss.org/browse/SEAMFACES-24
+ */
+ throw new ValidatorException(new FacesMessage(msg.get().text(
+ new BundleKey(Bundles.MESSAGES, "account.passwordNotConfirmed")).build()
+ .getText()));
+ }
+ }
+
+}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,43 +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.account;
-
-import javax.ejb.Local;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-/**
- * @author Dan Allen
- */
- at Local
-public interface PasswordManager
-{
- void changePassword();
-
- boolean isChanged();
-
- void setConfirmPassword(String password);
-
- @NotNull
- @Size(min = 5, max = 15)
- String getConfirmPassword();
-}
Copied: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java (from rev 13217, examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/PasswordManagerBean.java)
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java (rev 0)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -0,0 +1,83 @@
+/*
+ * 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.account;
+
+import javax.ejb.Stateful;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import org.jboss.seam.examples.booking.Bundles;
+import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.international.status.Messages;
+import org.jboss.seam.international.status.builder.BundleKey;
+
+/**
+ * @author Dan Allen
+ */
+ at Named
+ at Stateful
+ at RequestScoped
+public class PasswordManager
+{
+ @PersistenceContext
+ private EntityManager em;
+
+ @Inject
+ private Messages messages;
+
+ @Inject
+ @Authenticated
+ private User user;
+
+ @NotNull
+ @Size(min = 5, max = 15)
+ private String confirmPassword;
+
+ private boolean changed;
+
+ public void changePassword()
+ {
+ em.merge(user);
+ messages.info(new BundleKey(Bundles.MESSAGES, "account.passwordChanged")).textDefault("Password successfully updated.");
+ changed = true;
+ }
+
+ public boolean isChanged()
+ {
+ return changed;
+ }
+
+ public void setConfirmPassword(final String password)
+ {
+ this.confirmPassword = password;
+ }
+
+ public String getConfirmPassword()
+ {
+ return this.confirmPassword;
+ }
+}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/PasswordManagerBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/PasswordManagerBean.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/PasswordManagerBean.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,80 +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.account;
-
-import javax.ejb.Stateful;
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.jboss.seam.examples.booking.Bundles;
-
-import org.jboss.seam.examples.booking.model.User;
-import org.jboss.seam.international.status.Messages;
-import org.jboss.seam.international.status.builder.BundleKey;
-
-/**
- * @author Dan Allen
- */
- at Named("passwordManager")
- at Stateful
- at RequestScoped
-public class PasswordManagerBean implements PasswordManager
-{
- @PersistenceContext
- private EntityManager em;
-
- @Inject
- private Messages messages;
-
- @Inject
- @Authenticated
- private User user;
-
- private String confirmPassword;
-
- private boolean changed;
-
- public void changePassword()
- {
- em.merge(user);
- messages.info(new BundleKey(Bundles.MESSAGES, "account.passwordChanged"))
- .textDefault("Password successfully updated.");
- changed = true;
- }
-
- public boolean isChanged()
- {
- return changed;
- }
-
- public void setConfirmPassword(final String password)
- {
- this.confirmPassword = password;
- }
-
- public String getConfirmPassword()
- {
- return this.confirmPassword;
- }
-}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,55 +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.account;
-
-import javax.ejb.Local;
-import javax.faces.component.UIInput;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-import org.jboss.seam.examples.booking.model.User;
-
-/**
- * @author Dan Allen
- */
- at Local
-public interface Registrar
-{
- void register();
-
- boolean isRegistrationInvalid();
-
- void notifyIfRegistrationIsInvalid();
-
- User getNewUser();
-
- boolean isRegistered();
-
- @NotNull
- @Size(min = 5, max = 15)
- String getConfirmPassword();
-
- void setConfirmPassword(String password);
-
- UIInput getUsernameInput();
-
- void setUsernameInput(UIInput input);
-}
Copied: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java (from rev 13217, examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/RegistrarBean.java)
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java (rev 0)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -0,0 +1,153 @@
+/*
+ * 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.account;
+
+import javax.ejb.Stateful;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+import javax.faces.component.UIInput;
+import javax.faces.context.FacesContext;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import org.jboss.seam.examples.booking.Bundles;
+import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.international.status.Messages;
+import org.jboss.seam.international.status.builder.BundleKey;
+
+/**
+ * @author Dan Allen
+ */
+ at Named
+ at Stateful
+ at RequestScoped
+public class Registrar
+{
+ @PersistenceContext
+ private EntityManager em;
+
+ @Inject
+ private Messages messages;
+
+ @Inject
+ private FacesContext facesContext;
+
+ private UIInput usernameInput;
+
+ private final User newUser = new User();
+
+ @NotNull
+ @Size(min = 5, max = 15)
+ private String confirmPassword;
+
+ private boolean registered;
+
+ private boolean registrationInvalid;
+
+ public void register()
+ {
+ if (verifyUsernameIsAvailable())
+ {
+ registered = true;
+ em.persist(newUser);
+
+ messages.info(new BundleKey(Bundles.MESSAGES, "registration.registered")).textDefault("You have been successfully registered as the user {0}! You can now login.").textParams(newUser.getUsername());
+ }
+ else
+ {
+ registrationInvalid = true;
+ }
+ }
+
+ public boolean isRegistrationInvalid()
+ {
+ return registrationInvalid;
+ }
+
+ /**
+ * This method just shows another approach to adding a status message.
+ * <p>
+ * Invoked by:
+ * </p>
+ *
+ * <pre>
+ * <f:event type="preRenderView" listener="#{registrar.notifyIfRegistrationIsInvalid}"/>
+ * </pre>
+ */
+ public void notifyIfRegistrationIsInvalid()
+ {
+ if (facesContext.isValidationFailed() || registrationInvalid)
+ {
+ messages.warn(new BundleKey(Bundles.MESSAGES, "registration.invalid")).textDefault("Invalid registration. Please correct the errors and try again.");
+ }
+ }
+
+ @Produces
+ @RequestScoped
+ @Named
+ public User getNewUser()
+ {
+ return newUser;
+ }
+
+ public boolean isRegistered()
+ {
+ return registered;
+ }
+
+ public String getConfirmPassword()
+ {
+ return confirmPassword;
+ }
+
+ public void setConfirmPassword(final String password)
+ {
+ this.confirmPassword = password;
+ }
+
+ public UIInput getUsernameInput()
+ {
+ return usernameInput;
+ }
+
+ public void setUsernameInput(final UIInput usernameInput)
+ {
+ this.usernameInput = usernameInput;
+ }
+
+ private boolean verifyUsernameIsAvailable()
+ {
+ User existing = em.find(User.class, newUser.getUsername());
+ if (existing != null)
+ {
+ messages.warn(new BundleKey("messages", "account.usernameTaken")).textDefault("The username '{0}' is already taken. Please choose another username.").targets(usernameInput.getClientId()).textParams(newUser.getUsername());
+ return false;
+ }
+
+ return true;
+ }
+
+}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/RegistrarBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/RegistrarBean.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/RegistrarBean.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,155 +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.account;
-
-import javax.ejb.Stateful;
-import javax.enterprise.context.RequestScoped;
-import javax.enterprise.inject.Produces;
-import javax.faces.component.UIInput;
-import javax.faces.context.FacesContext;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.jboss.seam.examples.booking.Bundles;
-
-import org.jboss.seam.examples.booking.model.User;
-import org.jboss.seam.international.status.Messages;
-import org.jboss.seam.international.status.builder.BundleKey;
-
-/**
- * @author Dan Allen
- */
- at Stateful
- at RequestScoped
- at Named("registrar")
-public class RegistrarBean implements Registrar
-{
- @PersistenceContext
- private EntityManager em;
-
- @Inject
- private Messages messages;
-
- @Inject
- private FacesContext facesContext;
-
- private UIInput usernameInput;
-
- private final User newUser = new User();
-
- private String confirmPassword;
-
- private boolean registered;
-
- private boolean registrationInvalid;
-
- public void register()
- {
- if (verifyUsernameIsAvailable())
- {
- registered = true;
- em.persist(newUser);
-
- messages.info(new BundleKey(Bundles.MESSAGES, "registration.registered"))
- .textDefault("You have been successfully registered as the user {0}! You can now login.")
- .textParams(newUser.getUsername());
- }
- else
- {
- registrationInvalid = true;
- }
- }
-
- public boolean isRegistrationInvalid()
- {
- return registrationInvalid;
- }
-
- /**
- * This method just shows another approach to adding a status message.
- * <p>
- * Invoked by:
- * </p>
- *
- * <pre>
- * <f:event type="preRenderView" listener="#{registrar.notifyIfRegistrationIsInvalid}"/>
- * </pre>
- */
- public void notifyIfRegistrationIsInvalid()
- {
- if (facesContext.isValidationFailed() || registrationInvalid)
- {
- messages.warn(new BundleKey(Bundles.MESSAGES, "registration.invalid"))
- .textDefault("Invalid registration. Please correct the errors and try again.");
- }
- }
-
- @Produces
- @RequestScoped
- @Named
- public User getNewUser()
- {
- return newUser;
- }
-
- public boolean isRegistered()
- {
- return registered;
- }
-
- public String getConfirmPassword()
- {
- return confirmPassword;
- }
-
- public void setConfirmPassword(final String password)
- {
- this.confirmPassword = password;
- }
-
- public UIInput getUsernameInput()
- {
- return usernameInput;
- }
-
- public void setUsernameInput(UIInput usernameInput)
- {
- this.usernameInput = usernameInput;
- }
-
- private boolean verifyUsernameIsAvailable()
- {
- User existing = em.find(User.class, newUser.getUsername());
- if (existing != null)
- {
- messages.warn(new BundleKey("messages", "account.usernameTaken"))
- .textDefault("The username '{0}' is already taken. Please choose another username.")
- .targets(usernameInput.getClientId())
- .textParams(newUser.getUsername());
- return false;
- }
-
- return true;
- }
-
-}
Deleted: 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-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,52 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat Middleware LLC, 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.ejb.Local;
-
-import org.jboss.seam.examples.booking.model.Booking;
-import org.jboss.seam.examples.booking.model.Hotel;
-
-/**
- * @author Dan Allen
- */
- at Local
-public interface BookingAgent
-{
- void selectHotel(Long hotelId);
-
- void bookHotel();
-
- void validate();
-
- void cancel();
-
- void confirm();
-
- void onBookingComplete(Booking booking);
-
- Hotel getSelectedHotel();
-
- Booking getBooking();
-
- boolean isBookingValid();
-}
Copied: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java (from rev 13217, examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java)
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java (rev 0)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -0,0 +1,153 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, 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 static javax.persistence.PersistenceContextType.EXTENDED;
+
+import javax.ejb.Stateful;
+import javax.enterprise.context.ConversationScoped;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.event.Observes;
+import javax.enterprise.event.TransactionPhase;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.seam.examples.booking.Bundles;
+import org.jboss.seam.examples.booking.account.Authenticated;
+import org.jboss.seam.examples.booking.model.Booking;
+import org.jboss.seam.examples.booking.model.Hotel;
+import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.faces.context.conversation.Begin;
+import org.jboss.seam.faces.context.conversation.End;
+import org.jboss.seam.international.status.Messages;
+import org.jboss.seam.international.status.builder.BundleKey;
+import org.jboss.seam.international.status.builder.TemplateMessage;
+import org.slf4j.Logger;
+
+import com.ocpsoft.pretty.time.PrettyTime;
+
+ at Stateful
+ at ConversationScoped
+ at Named
+public class BookingAgent
+{
+ @Inject
+ private Logger log;
+
+ @PersistenceContext(type = EXTENDED)
+ private EntityManager em;
+
+ @Inject
+ private Instance<TemplateMessage> messageBuilder;
+
+ @Inject
+ private Messages messages;
+
+ @Inject
+ @Authenticated
+ private User user;
+
+ @Inject
+ @Confirmed
+ private Event<Booking> bookingConfirmedEventSrc;
+
+ private Hotel hotelSelection;
+
+ private Booking booking;
+
+ private boolean bookingValid;
+
+ @Begin
+ public void selectHotel(final Long id)
+ {
+ // NOTE get a fresh reference that's managed by the extended persistence
+ // context
+ hotelSelection = em.find(Hotel.class, id);
+ if (hotelSelection != null)
+ {
+ log.info(messageBuilder.get().text("Selected the {0} in {1}").textParams(hotelSelection.getName(), hotelSelection.getCity()).build().getText());
+ }
+ }
+
+ public void bookHotel()
+ {
+ booking = new Booking(hotelSelection, user, 7, 2);
+ hotelSelection = null;
+
+ // for demo convenience
+ booking.setCreditCardNumber("1111222233334444");
+
+ messages.info(new BundleKey(Bundles.MESSAGES, "booking.initiated")).textDefault("You've initiated a booking at the {0}.").textParams(booking.getHotel().getName());
+ }
+
+ public void validate()
+ {
+ // if we got here, all validations passed
+ bookingValid = true;
+ }
+
+ @End
+ public void confirm()
+ {
+ em.persist(booking);
+ bookingConfirmedEventSrc.fire(booking);
+ }
+
+ @End
+ public void cancel()
+ {
+ booking = null;
+ hotelSelection = null;
+ }
+
+ public void onBookingComplete(@Observes(during = TransactionPhase.AFTER_SUCCESS) @Confirmed final Booking booking)
+ {
+ log.info(messageBuilder.get().text("New booking at the {0} confirmed for {1}").textParams(booking.getHotel().getName(), booking.getUser().getName()).build().getText());
+ messages.info(new BundleKey(Bundles.MESSAGES, "booking.confirmed")).textDefault("You're booked to stay at the {0} {1}.").textParams(booking.getHotel().getName(), new PrettyTime().format(booking.getCheckinDate()));
+ }
+
+ @Produces
+ @Named
+ @ConversationScoped
+ public Booking getBooking()
+ {
+ return booking;
+ }
+
+ @Produces
+ @Named("hotel")
+ @RequestScoped
+ public Hotel getSelectedHotel()
+ {
+ return booking != null ? booking.getHotel() : hotelSelection;
+ }
+
+ public boolean isBookingValid()
+ {
+ return bookingValid;
+ }
+}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,159 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat Middleware LLC, 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 static javax.persistence.PersistenceContextType.EXTENDED;
-
-
-import javax.ejb.Stateful;
-import javax.enterprise.context.ConversationScoped;
-import javax.enterprise.context.RequestScoped;
-import javax.enterprise.inject.Produces;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-import org.jboss.seam.examples.booking.account.Authenticated;
-import org.jboss.seam.examples.booking.model.Booking;
-import org.jboss.seam.examples.booking.model.Hotel;
-import org.jboss.seam.examples.booking.model.User;
-import org.jboss.seam.faces.context.conversation.Begin;
-import org.jboss.seam.faces.context.conversation.End;
-import org.jboss.seam.international.status.Messages;
-import org.jboss.seam.international.status.builder.BundleKey;
-import org.slf4j.Logger;
-
-import com.ocpsoft.pretty.time.PrettyTime;
-import javax.enterprise.event.Event;
-import javax.enterprise.event.Observes;
-import javax.enterprise.event.TransactionPhase;
-import javax.enterprise.inject.Instance;
-import org.jboss.seam.examples.booking.Bundles;
-import org.jboss.seam.international.status.builder.TemplateMessage;
-
- at Stateful
- at ConversationScoped
- at Named("bookingAgent")
-public class BookingAgentBean implements BookingAgent
-{
- @Inject
- private Logger log;
-
- @PersistenceContext(type = EXTENDED)
- private EntityManager em;
-
- @Inject
- private Instance<TemplateMessage> messageBuilder;
-
- @Inject
- private Messages messages;
-
- @Inject
- @Authenticated
- private User user;
-
- @Inject @Confirmed
- private Event<Booking> bookingConfirmedEventSrc;
-
- private Hotel hotelSelection;
-
- private Booking booking;
-
- private boolean bookingValid;
-
- @Begin
- public void selectHotel(final Long id)
- {
- // NOTE get a fresh reference that's managed by the extended persistence context
- hotelSelection = em.find(Hotel.class, id);
- if (hotelSelection != null)
- {
- log.info(messageBuilder.get().text("Selected the {0} in {1}")
- .textParams(hotelSelection.getName(), hotelSelection.getCity()).build().getText());
- }
- }
-
- public void bookHotel()
- {
- booking = new Booking(hotelSelection, user, 7, 2);
- hotelSelection = null;
-
- // for demo convenience
- booking.setCreditCardNumber("1111222233334444");
-
- messages.info(new BundleKey(Bundles.MESSAGES, "booking.initiated"))
- .textDefault("You've initiated a booking at the {0}.")
- .textParams(booking.getHotel().getName());
- }
-
- public void validate()
- {
- // if we got here, all validations passed
- bookingValid = true;
- }
-
- @End
- public void confirm()
- {
- em.persist(booking);
- bookingConfirmedEventSrc.fire(booking);
- }
-
- @End
- public void cancel()
- {
- booking = null;
- hotelSelection = null;
- }
-
- public void onBookingComplete(@Observes(during = TransactionPhase.AFTER_SUCCESS)
- @Confirmed final Booking booking)
- {
- log.info(messageBuilder.get().text("New booking at the {0} confirmed for {1}")
- .textParams(booking.getHotel().getName(), booking.getUser().getName()).build().getText());
- messages.info(new BundleKey(Bundles.MESSAGES, "booking.confirmed"))
- .textDefault("You're booked to stay at the {0} {1}.")
- .textParams(booking.getHotel().getName(), new PrettyTime().format(booking.getCheckinDate()));
- }
-
- @Produces
- @Named
- @ConversationScoped
- public Booking getBooking()
- {
- return booking;
- }
-
- @Produces
- @Named("hotel")
- @RequestScoped
- public Hotel getSelectedHotel()
- {
- return booking != null ? booking.getHotel() : hotelSelection;
- }
-
- public boolean isBookingValid()
- {
- return bookingValid;
- }
-}
Deleted: 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-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,39 +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 java.util.List;
-import javax.ejb.Local;
-import org.jboss.seam.examples.booking.model.Booking;
-
-/**
- * @author Dan Allen
- */
- at Local
-public interface BookingHistory
-{
- List<Booking> getBookingsForCurrentUser();
-
- void cancelBooking(Booking booking);
-
- void onBookingComplete(Booking booking);
-}
Copied: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java (from rev 13217, examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistoryBean.java)
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java (rev 0)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, 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 java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+import javax.ejb.Stateful;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.event.Reception;
+import javax.enterprise.event.TransactionPhase;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.JoinType;
+import javax.persistence.criteria.Root;
+import org.jboss.seam.examples.booking.Bundles;
+
+import org.jboss.seam.examples.booking.account.Authenticated;
+import org.jboss.seam.examples.booking.model.Booking;
+import org.jboss.seam.examples.booking.model.Booking_;
+import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.examples.booking.model.User_;
+import org.jboss.seam.examples.booking.security.Identity;
+import org.jboss.seam.international.status.Messages;
+import org.jboss.seam.international.status.builder.BundleKey;
+import org.slf4j.Logger;
+
+/**
+ * @author Dan Allen
+ */
+ at Named
+ at Stateful
+ at SessionScoped
+public class BookingHistory
+{
+ @Inject
+ private Logger log;
+
+ @PersistenceContext
+ private EntityManager em;
+
+ @Inject
+ private Messages messages;
+
+ @Inject
+ private Identity identity;
+
+ @Inject @Authenticated
+ private Instance<User> currentUserInstance;
+
+ private List<Booking> bookingsForUser = null;
+
+ @Produces
+ @Authenticated
+ @Named("bookings")
+ public List<Booking> getBookingsForCurrentUser()
+ {
+ if (bookingsForUser == null && identity.isLoggedIn())
+ {
+ fetchBookingsForCurrentUser();
+ }
+ return bookingsForUser;
+ }
+
+ public void onBookingComplete(@Observes(during = TransactionPhase.AFTER_SUCCESS, notifyObserver = Reception.IF_EXISTS)
+ @Confirmed final Booking booking)
+ {
+ // optimization, save the db call
+ if (bookingsForUser != null)
+ {
+ log.info("Adding new booking to user's cached booking history");
+ bookingsForUser.add(booking);
+ }
+ else
+ {
+ log.info("User's booking history not loaded. Skipping cache update.");
+ }
+ }
+
+ 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());
+ if (booking != null)
+ {
+ em.remove(booking);
+ messages.info(new BundleKey(Bundles.MESSAGES, "booking.canceled"))
+ .textDefault("The booking at the {0} on {1} has been canceled.")
+ .textParams(selectedBooking.getHotel().getName(),
+ DateFormat.getDateInstance(SimpleDateFormat.MEDIUM).format(selectedBooking.getCheckinDate()));
+ }
+ else
+ {
+ messages.info(new BundleKey(Bundles.MESSAGES, "booking.doesNotExist"))
+ .textDefault("Our records indicate that the booking you selected has already been canceled.");
+ }
+
+ bookingsForUser.remove(selectedBooking);
+ }
+
+ private void fetchBookingsForCurrentUser()
+ {
+ String username = currentUserInstance.get().getUsername();
+ CriteriaBuilder builder = em.getCriteriaBuilder();
+ CriteriaQuery<Booking> cquery = builder.createQuery(Booking.class);
+ Root<Booking> booking = cquery.from(Booking.class);
+ booking.fetch(Booking_.hotel, JoinType.INNER);
+ cquery.select(booking)
+ .where(builder.equal(booking.get(Booking_.user).get(User_.username), username))
+ .orderBy(builder.asc(booking.get(Booking_.checkinDate)));
+
+ bookingsForUser = em.createQuery(cquery).getResultList();
+ }
+
+}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistoryBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistoryBean.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistoryBean.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,142 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat Middleware LLC, 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 java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.List;
-
-import javax.ejb.Stateful;
-import javax.enterprise.context.SessionScoped;
-import javax.enterprise.event.Observes;
-import javax.enterprise.event.Reception;
-import javax.enterprise.event.TransactionPhase;
-import javax.enterprise.inject.Instance;
-import javax.enterprise.inject.Produces;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.JoinType;
-import javax.persistence.criteria.Root;
-import org.jboss.seam.examples.booking.Bundles;
-
-import org.jboss.seam.examples.booking.account.Authenticated;
-import org.jboss.seam.examples.booking.model.Booking;
-import org.jboss.seam.examples.booking.model.Booking_;
-import org.jboss.seam.examples.booking.model.User;
-import org.jboss.seam.examples.booking.model.User_;
-import org.jboss.seam.examples.booking.security.Identity;
-import org.jboss.seam.international.status.Messages;
-import org.jboss.seam.international.status.builder.BundleKey;
-import org.slf4j.Logger;
-
-/**
- * @author Dan Allen
- */
- at Named("bookingHistory")
- at Stateful
- at SessionScoped
-public class BookingHistoryBean implements BookingHistory
-{
- @Inject
- private Logger log;
-
- @PersistenceContext
- private EntityManager em;
-
- @Inject
- private Messages messages;
-
- @Inject
- private Identity identity;
-
- @Inject @Authenticated
- private Instance<User> currentUserInstance;
-
- private List<Booking> bookingsForUser = null;
-
- @Produces
- @Authenticated
- @Named("bookings")
- public List<Booking> getBookingsForCurrentUser()
- {
- if (bookingsForUser == null && identity.isLoggedIn())
- {
- fetchBookingsForCurrentUser();
- }
- return bookingsForUser;
- }
-
- public void onBookingComplete(@Observes(during = TransactionPhase.AFTER_SUCCESS, notifyObserver = Reception.IF_EXISTS)
- @Confirmed final Booking booking)
- {
- // optimization, save the db call
- if (bookingsForUser != null)
- {
- log.info("Adding new booking to user's cached booking history");
- bookingsForUser.add(booking);
- }
- else
- {
- log.info("User's booking history not loaded. Skipping cache update.");
- }
- }
-
- 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());
- if (booking != null)
- {
- em.remove(booking);
- messages.info(new BundleKey(Bundles.MESSAGES, "booking.canceled"))
- .textDefault("The booking at the {0} on {1} has been canceled.")
- .textParams(selectedBooking.getHotel().getName(),
- DateFormat.getDateInstance(SimpleDateFormat.MEDIUM).format(selectedBooking.getCheckinDate()));
- }
- else
- {
- messages.info(new BundleKey(Bundles.MESSAGES, "booking.doesNotExist"))
- .textDefault("Our records indicate that the booking you selected has already been canceled.");
- }
-
- bookingsForUser.remove(selectedBooking);
- }
-
- private void fetchBookingsForCurrentUser()
- {
- String username = currentUserInstance.get().getUsername();
- CriteriaBuilder builder = em.getCriteriaBuilder();
- CriteriaQuery<Booking> cquery = builder.createQuery(Booking.class);
- Root<Booking> booking = cquery.from(Booking.class);
- booking.fetch(Booking_.hotel, JoinType.INNER);
- cquery.select(booking)
- .where(builder.equal(booking.get(Booking_.user).get(User_.username), username))
- .orderBy(builder.asc(booking.get(Booking_.checkinDate)));
-
- bookingsForUser = em.createQuery(cquery).getResultList();
- }
-
-}
Copied: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationInitializer.java (from rev 13217, examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationSetupBean.java)
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationInitializer.java (rev 0)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationInitializer.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -0,0 +1,126 @@
+/*
+ * 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.bootstrap;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Alternative;
+import javax.faces.event.PostConstructApplicationEvent;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.validation.ConstraintViolation;
+import javax.validation.ConstraintViolationException;
+
+import org.jboss.seam.examples.booking.model.Hotel;
+import org.jboss.seam.examples.booking.model.User;
+import org.slf4j.Logger;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ */
+ at Stateless
+ at Alternative
+public class ApplicationInitializer
+{
+ @PersistenceContext
+ private EntityManager em;
+
+ @Inject
+ Logger log;
+
+ private final List<User> users = new ArrayList<User>();
+ private final List<Hotel> hotels = new ArrayList<Hotel>();
+
+ public ApplicationInitializer()
+ {
+ users.add(new User("Dan Allen", "dan", "dan at example.com", "laurel"));
+ users.add(new User("Pete Muir", "pete", "pete at example.com", "edinburgh"));
+ users.add(new User("Lincoln Baxter III", "lincoln", "lincoln at example.com", "charlotte"));
+ users.add(new User("Shane Bryzak", "shane", "shane at example.com", "brisbane"));
+ users.add(new User("Gavin King", "gavin", "gavin at example.com", "mexico"));
+
+ hotels.add(new Hotel(129, 3, "Marriott Courtyard", "Tower Place, Buckhead", "Atlanta", "GA", "30305", "USA"));
+ hotels.add(new Hotel(84, 4, "Doubletree Atlanta-Buckhead", "3342 Peachtree Road NE", "Atlanta", "GA", "30326", "USA"));
+ hotels.add(new Hotel(289, 4, "W New York - Union Square", "201 Park Avenue South", "New York", "NY", "10003", "USA"));
+ hotels.add(new Hotel(219, 3, "W New York", "541 Lexington Avenue", "New York", "NY", "10022", "USA"));
+ hotels.add(new Hotel(250, 3, "Hotel Rouge", "1315 16th Street NW", "Washington", "DC", "20036", "USA"));
+ hotels.add(new Hotel(159, 4, "70 Park Avenue Hotel", "70 Park Avenue, 38th St", "New York", "NY", "10016", "USA"));
+ hotels.add(new Hotel(198, 4, "Parc 55", "55 Cyril Magnin Street", "San Francisco", "CA", "94102", "USA"));
+ hotels.add(new Hotel(189, 4, "Conrad Miami", "1395 Brickell Ave", "Miami", "FL", "33131", "USA"));
+ hotels.add(new Hotel(111, 4, "Grand Hyatt", "345 Stockton Street", "San Francisco", "CA", "94108", "USA"));
+ hotels.add(new Hotel(54, 1, "Super 8 Eau Claire Campus Area", "1151 W MacArthur Ave", "Eau Claire", "WI", "54701", "USA"));
+ hotels.add(new Hotel(199, 4, "San Francisco Marriott", "55 Fourth Street", "San Francisco", "CA", "94103", "USA"));
+ hotels.add(new Hotel(543, 4, "Hilton Diagonal Mar", "Passeig del Taulat 262-264", "Barcelona", "Catalunya", "08019", "ES"));
+ hotels.add(new Hotel(335, 5, "Hilton Tel Aviv", "Independence Park", "Tel Aviv", null, "63405", "IL"));
+ hotels.add(new Hotel(242, 5, "InterContinental Hotel Tokyo Bay", "1-15-2 Kaigan", "Tokyo", "Minato", "105", "JP"));
+ hotels.add(new Hotel(130, 4, "Hotel Beaulac", " Esplanade Léopold-Robert 2", "Neuchatel", null, "2000", "CH"));
+ hotels.add(new Hotel(266, 5, "Conrad Treasury Place", "130 William Street", "Brisbane", "QL", "4001", "AU"));
+ hotels.add(new Hotel(170, 4, "Ritz-Carlton Montreal", "1228 Sherbrooke St West", "Montreal", "Quebec", "H3G1H6", "CA"));
+ hotels.add(new Hotel(179, 4, "Ritz-Carlton Atlanta", "181 Peachtree St NE", "Atlanta", "GA", "30303", "USA"));
+ hotels.add(new Hotel(145, 4, "Swissotel Sydney", "68 Market Street", "Sydney", "NSW", "2000", "AU"));
+ hotels.add(new Hotel(178, 4, "Meliá White House", "Albany Street Regents Park", "London", null, "NW13UP", "GB"));
+ hotels.add(new Hotel(159, 3, "Hotel Allegro", "171 W Randolph Street", "Chicago", "IL", "60601", "USA"));
+ hotels.add(new Hotel(296, 5, "Caesars Palace", "3570 Las Vegas Blvd S", "Las Vegas", "NV", "89109", "USA"));
+ hotels.add(new Hotel(300, 4, "Mandalay Bay Resort & Casino", "3950 Las Vegas Blvd S", "Las Vegas", "NV", "89119", "USA"));
+ hotels.add(new Hotel(100, 2, "Hotel Cammerpoorte", "Nationalestraat 38-40", "Antwerp", null, "2000", "BE"));
+ }
+
+ public void init(@Observes final PostConstructApplicationEvent event)
+ {
+ try
+ {
+ persist(users);
+ persist(hotels);
+ }
+ catch (Exception e)
+ {
+ log.error("Encountered error seeding the database", e);
+ }
+ }
+
+ private void persist(final List entities)
+ {
+ for (Object e : entities)
+ {
+ persist(e);
+ }
+ }
+
+ private void persist(final Object entity)
+ {
+ try
+ {
+ em.persist(entity);
+ }
+ catch (ConstraintViolationException e)
+ {
+ for (ConstraintViolation v : e.getConstraintViolations())
+ {
+ log.error("Cannot persist entity because it has validation errors " + v.getRootBean() + ": " + v.getPropertyPath() + " " + v.getMessage());
+ }
+ }
+ }
+}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationSetup.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationSetup.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationSetup.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,34 +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.bootstrap;
-
-import javax.ejb.Local;
-import javax.faces.event.PostConstructApplicationEvent;
-
-/**
- * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
- */
- at Local
-public interface ApplicationSetup
-{
- public void init(final PostConstructApplicationEvent event);
-}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationSetupBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationSetupBean.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationSetupBean.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,125 +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.bootstrap;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.ejb.Stateless;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Alternative;
-import javax.faces.event.PostConstructApplicationEvent;
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.validation.ConstraintViolation;
-import javax.validation.ConstraintViolationException;
-
-import org.jboss.seam.examples.booking.model.Hotel;
-import org.jboss.seam.examples.booking.model.User;
-import org.slf4j.Logger;
-
-/**
- * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
- */
- at Stateless
- at Alternative
-public class ApplicationSetupBean implements ApplicationSetup
-{
- @PersistenceContext
- private EntityManager em;
-
- @Inject Logger log;
-
- private final List<User> users = new ArrayList<User>();
- private final List<Hotel> hotels = new ArrayList<Hotel>();
-
- public ApplicationSetupBean()
- {
- users.add(new User("Dan Allen", "dan", "dan at example.com", "laurel"));
- users.add(new User("Pete Muir", "pete", "pete at example.com", "edinburgh"));
- users.add(new User("Lincoln Baxter III", "lincoln", "lincoln at example.com", "charlotte"));
- users.add(new User("Shane Bryzak", "shane", "shane at example.com", "brisbane"));
- users.add(new User("Gavin King", "gavin", "gavin at example.com", "mexico"));
-
- hotels.add(new Hotel(129, 3, "Marriott Courtyard", "Tower Place, Buckhead", "Atlanta", "GA", "30305", "USA"));
- hotels.add(new Hotel(84, 4, "Doubletree Atlanta-Buckhead", "3342 Peachtree Road NE", "Atlanta", "GA", "30326", "USA"));
- hotels.add(new Hotel(289, 4, "W New York - Union Square", "201 Park Avenue South", "New York", "NY", "10003", "USA"));
- hotels.add(new Hotel(219, 3, "W New York", "541 Lexington Avenue", "New York", "NY", "10022", "USA"));
- hotels.add(new Hotel(250, 3, "Hotel Rouge", "1315 16th Street NW", "Washington", "DC", "20036", "USA"));
- hotels.add(new Hotel(159, 4, "70 Park Avenue Hotel", "70 Park Avenue, 38th St", "New York", "NY", "10016", "USA"));
- hotels.add(new Hotel(198, 4, "Parc 55", "55 Cyril Magnin Street", "San Francisco", "CA", "94102", "USA"));
- hotels.add(new Hotel(189, 4, "Conrad Miami", "1395 Brickell Ave", "Miami", "FL", "33131", "USA"));
- hotels.add(new Hotel(111, 4, "Grand Hyatt", "345 Stockton Street", "San Francisco", "CA", "94108", "USA"));
- hotels.add(new Hotel(54, 1, "Super 8 Eau Claire Campus Area", "1151 W MacArthur Ave", "Eau Claire", "WI", "54701", "USA"));
- hotels.add(new Hotel(199, 4, "San Francisco Marriott", "55 Fourth Street", "San Francisco", "CA", "94103", "USA"));
- hotels.add(new Hotel(543, 4, "Hilton Diagonal Mar", "Passeig del Taulat 262-264", "Barcelona", "Catalunya", "08019", "ES"));
- hotels.add(new Hotel(335, 5, "Hilton Tel Aviv", "Independence Park", "Tel Aviv", null, "63405", "IL"));
- hotels.add(new Hotel(242, 5, "InterContinental Hotel Tokyo Bay", "1-15-2 Kaigan", "Tokyo", "Minato", "105", "JP"));
- hotels.add(new Hotel(130, 4, "Hotel Beaulac", " Esplanade Léopold-Robert 2", "Neuchatel", null, "2000", "CH"));
- hotels.add(new Hotel(266, 5, "Conrad Treasury Place", "130 William Street", "Brisbane", "QL", "4001", "AU"));
- hotels.add(new Hotel(170, 4, "Ritz-Carlton Montreal", "1228 Sherbrooke St West", "Montreal", "Quebec", "H3G1H6", "CA"));
- hotels.add(new Hotel(179, 4, "Ritz-Carlton Atlanta", "181 Peachtree St NE", "Atlanta", "GA", "30303", "USA"));
- hotels.add(new Hotel(145, 4, "Swissotel Sydney", "68 Market Street", "Sydney", "NSW", "2000", "AU"));
- hotels.add(new Hotel(178, 4, "Meliá White House", "Albany Street Regents Park", "London", null, "NW13UP", "GB"));
- hotels.add(new Hotel(159, 3, "Hotel Allegro", "171 W Randolph Street", "Chicago", "IL", "60601", "USA"));
- hotels.add(new Hotel(296, 5, "Caesars Palace", "3570 Las Vegas Blvd S", "Las Vegas", "NV", "89109", "USA"));
- hotels.add(new Hotel(300, 4, "Mandalay Bay Resort & Casino", "3950 Las Vegas Blvd S", "Las Vegas", "NV", "89119", "USA"));
- hotels.add(new Hotel(100, 2, "Hotel Cammerpoorte", "Nationalestraat 38-40", "Antwerp", null, "2000", "BE"));
- }
-
- public void init(@Observes final PostConstructApplicationEvent event)
- {
- try {
- persist(users);
- persist(hotels);
- }
- catch (Exception e)
- {
- log.error("Encountered error seeding the database", e);
- }
- }
-
- private void persist(List entities)
- {
- for (Object e : entities)
- {
- persist(e);
- }
- }
-
- private void persist(Object entity)
- {
- try
- {
- em.persist(entity);
- }
- catch (ConstraintViolationException e)
- {
- for (ConstraintViolation v : e.getConstraintViolations())
- {
- log.error("Cannot persist entity because it has validation errors " +
- v.getRootBean() + ": " + v.getPropertyPath() + " " + v.getMessage());
- }
- }
- }
-}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,42 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat Middleware LLC, 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.inventory;
-
-import java.util.List;
-import javax.ejb.Local;
-import org.jboss.seam.examples.booking.model.Hotel;
-
- at Local
-public interface HotelSearch
-{
- void find();
-
- void previousPage();
-
- void nextPage();
-
- List<Hotel> getHotels();
-
- boolean isNextPageAvailable();
-
- boolean isPreviousPageAvailable();
-}
Copied: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java (from rev 13217, examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearchBean.java)
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java (rev 0)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, 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.inventory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Stateful;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
+
+import org.jboss.seam.examples.booking.model.Hotel;
+import org.jboss.seam.examples.booking.model.Hotel_;
+import org.jboss.seam.international.status.builder.TemplateMessage;
+import org.slf4j.Logger;
+
+ at Named
+ at Stateful
+ at SessionScoped
+public class HotelSearch
+{
+ @Inject
+ private Logger log;
+
+ @PersistenceContext
+ private EntityManager em;
+
+ @Inject
+ private SearchCriteria criteria;
+
+ @Inject
+ private Instance<TemplateMessage> messageBuilder;
+
+ private boolean nextPageAvailable = false;
+
+ private List<Hotel> hotels = new ArrayList<Hotel>();
+
+ public void find()
+ {
+ criteria.firstPage();
+ queryHotels(criteria);
+ }
+
+ public void nextPage()
+ {
+ criteria.nextPage();
+ queryHotels(criteria);
+ }
+
+ public void previousPage()
+ {
+ criteria.previousPage();
+ queryHotels(criteria);
+ }
+
+ @Produces
+ @Named
+ public List<Hotel> getHotels()
+ {
+ return hotels;
+ }
+
+ public boolean isNextPageAvailable()
+ {
+ return nextPageAvailable;
+ }
+
+ public boolean isPreviousPageAvailable()
+ {
+ return criteria.getPage() > 0;
+ }
+
+ private void queryHotels(final SearchCriteria criteria)
+ {
+ CriteriaBuilder builder = em.getCriteriaBuilder();
+ CriteriaQuery<Hotel> cquery = builder.createQuery(Hotel.class);
+ Root<Hotel> hotel = cquery.from(Hotel.class);
+ // QUESTION can like create the pattern for us?
+ cquery.select(hotel).where(builder.or(builder.like(builder.lower(hotel.get(Hotel_.name)), criteria.getSearchPattern()), builder.like(builder.lower(hotel.get(Hotel_.city)), criteria.getSearchPattern()), builder.like(builder.lower(hotel.get(Hotel_.zip)), criteria.getSearchPattern()), builder.like(builder.lower(hotel.get(Hotel_.address)), criteria.getSearchPattern())));
+
+ List<Hotel> results = em.createQuery(cquery).setMaxResults(criteria.getFetchSize()).setFirstResult(criteria.getFetchOffset()).getResultList();
+
+ nextPageAvailable = results.size() > criteria.getPageSize();
+ if (nextPageAvailable)
+ {
+ // NOTE create new ArrayList since subList creates unserializable list
+ hotels = new ArrayList<Hotel>(results.subList(0, criteria.getPageSize()));
+ }
+ else
+ {
+ hotels = results;
+ }
+ log.info(messageBuilder.get().text("Found {0} hotel(s) matching search term [ {1} ] (limit {2})").textParams(hotels.size(), criteria.getQuery(), criteria.getPageSize()).build().getText());
+ }
+}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearchBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearchBean.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearchBean.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,131 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat Middleware LLC, 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.inventory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.ejb.Stateful;
-import javax.enterprise.context.SessionScoped;
-import javax.enterprise.inject.Instance;
-import javax.enterprise.inject.Produces;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Root;
-
-import org.jboss.seam.examples.booking.model.Hotel;
-import org.jboss.seam.examples.booking.model.Hotel_;
-import org.jboss.seam.international.status.builder.TemplateMessage;
-import org.slf4j.Logger;
-
- at Stateful
- at SessionScoped
- at Named("hotelSearch")
-public class HotelSearchBean implements HotelSearch
-{
- @Inject
- private Logger log;
-
- @PersistenceContext
- private EntityManager em;
-
- @Inject
- private SearchCriteria criteria;
-
- @Inject
- private Instance<TemplateMessage> messageBuilder;
-
- private boolean nextPageAvailable = false;
-
- private List<Hotel> hotels = new ArrayList<Hotel>();
-
- public void find()
- {
- criteria.firstPage();
- queryHotels(criteria);
- }
-
- public void nextPage()
- {
- criteria.nextPage();
- queryHotels(criteria);
- }
-
- public void previousPage()
- {
- criteria.previousPage();
- queryHotels(criteria);
- }
-
- @Produces
- @Named
- public List<Hotel> getHotels()
- {
- return hotels;
- }
-
- public boolean isNextPageAvailable()
- {
- return nextPageAvailable;
- }
-
- public boolean isPreviousPageAvailable()
- {
- return criteria.getPage() > 0;
- }
-
- private void queryHotels(final SearchCriteria criteria)
- {
- CriteriaBuilder builder = em.getCriteriaBuilder();
- CriteriaQuery<Hotel> cquery = builder.createQuery(Hotel.class);
- Root<Hotel> hotel = cquery.from(Hotel.class);
- // QUESTION can like create the pattern for us?
- cquery.select(hotel)
- .where(builder.or(
- builder.like(builder.lower(hotel.get(Hotel_.name)), criteria.getSearchPattern()),
- builder.like(builder.lower(hotel.get(Hotel_.city)), criteria.getSearchPattern()),
- builder.like(builder.lower(hotel.get(Hotel_.zip)), criteria.getSearchPattern()),
- builder.like(builder.lower(hotel.get(Hotel_.address)), criteria.getSearchPattern())));
-
- List<Hotel> results = em.createQuery(cquery)
- .setMaxResults(criteria.getFetchSize())
- .setFirstResult(criteria.getFetchOffset())
- .getResultList();
-
- nextPageAvailable = results.size() > criteria.getPageSize();
- if (nextPageAvailable)
- {
- // NOTE create new ArrayList since subList creates unserializable list
- hotels = new ArrayList<Hotel>(results.subList(0, criteria.getPageSize()));
- }
- else
- {
- hotels = results;
- }
- log.info(messageBuilder.get().text("Found {0} hotel(s) matching search term [ {1} ] (limit {2})")
- .textParams(hotels.size(), criteria.getQuery(), criteria.getPageSize()).build().getText());
- }
-}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/Authenticator.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/Authenticator.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/Authenticator.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,37 +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.security;
-
-import javax.ejb.Local;
-
-/**
- * <strong>Authenticator</strong> is responsible for authenticating the current
- * user. The sole method of this interface, authenticate(), is invoked as a
- * callback method to Seam's security infrastructure during authentication.
- *
- * @author Dan Allen
- */
- at Local
-public interface Authenticator // extends org.jboss.seam.security.Authenticator
-{
- public boolean authenticate();
-}
Copied: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/Authenticator.java (from rev 13217, examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/AuthenticatorBean.java)
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/Authenticator.java (rev 0)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/Authenticator.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -0,0 +1,85 @@
+/*
+ * 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.security;
+
+import javax.ejb.Stateless;
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.seam.examples.booking.Bundles;
+import org.jboss.seam.examples.booking.account.Authenticated;
+import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.international.status.Messages;
+import org.jboss.seam.international.status.builder.BundleKey;
+import org.slf4j.Logger;
+
+/**
+ * This implementation of <strong>Authenticator</strong> cross references the
+ * values of the user's credentials against the database.
+ *
+ * @author Dan Allen
+ */
+ at Stateless
+public class Authenticator
+{
+ @Inject
+ private Logger log;
+
+ @PersistenceContext
+ private EntityManager em;
+
+ @Inject
+ private Messages messages;
+
+ @Inject
+ private Credentials credentials;
+
+ @Inject
+ @Authenticated
+ private Event<User> loginEventSrc;
+
+ public boolean authenticate()
+ {
+ log.info("Logging in " + credentials.getUsername());
+ if ((credentials.getUsername() == null) || (credentials.getPassword() == null))
+ {
+ messages.info(new BundleKey(Bundles.MESSAGES, "identity.loginFailed"));
+ return false;
+ }
+
+ User user = em.find(User.class, credentials.getUsername());
+ if ((user != null) && user.getPassword().equals(credentials.getPassword()))
+ {
+ loginEventSrc.fire(user);
+ messages.info(new BundleKey(Bundles.MESSAGES, "identity.loggedIn"), user.getName());
+ return true;
+ }
+ else
+ {
+ messages.info(new BundleKey(Bundles.MESSAGES, "identity.loginFailed"));
+ return false;
+ }
+ }
+
+}
Deleted: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/AuthenticatorBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/AuthenticatorBean.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/AuthenticatorBean.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -1,85 +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.security;
-
-import javax.ejb.Stateless;
-import javax.enterprise.event.Event;
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.jboss.seam.examples.booking.Bundles;
-
-import org.jboss.seam.examples.booking.account.Authenticated;
-import org.jboss.seam.examples.booking.model.User;
-import org.jboss.seam.international.status.Messages;
-import org.jboss.seam.international.status.builder.BundleKey;
-import org.slf4j.Logger;
-
-/**
- * This implementation of <strong>Authenticator</strong> cross references the
- * values of the user's credentials against the database.
- *
- * @author Dan Allen
- */
- at Stateless
-public class AuthenticatorBean implements Authenticator
-{
- @Inject
- private Logger log;
-
- @PersistenceContext
- private EntityManager em;
-
- @Inject
- private Messages messages;
-
- @Inject
- private Credentials credentials;
-
- @Inject
- @Authenticated
- private Event<User> loginEventSrc;
-
- public boolean authenticate()
- {
- log.info("Logging in " + credentials.getUsername());
- if ((credentials.getUsername() == null) || (credentials.getPassword() == null))
- {
- messages.info(new BundleKey(Bundles.MESSAGES, "identity.loginFailed"));
- return false;
- }
-
- User user = em.find(User.class, credentials.getUsername());
- if ((user != null) && user.getPassword().equals(credentials.getPassword()))
- {
- loginEventSrc.fire(user);
- messages.info(new BundleKey(Bundles.MESSAGES, "identity.loggedIn"), user.getName());
- return true;
- }
- else
- {
- messages.info(new BundleKey(Bundles.MESSAGES, "identity.loginFailed"));
- return false;
- }
- }
-
-}
Modified: examples/trunk/booking-simplified/src/main/webapp/WEB-INF/beans.xml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/WEB-INF/beans.xml 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/webapp/WEB-INF/beans.xml 2010-06-17 17:41:30 UTC (rev 13218)
@@ -8,6 +8,6 @@
<class>org.jboss.seam.faces.context.conversation.ConversationBoundaryInterceptor</class>
</interceptors>
<alternatives>
- <class>org.jboss.seam.examples.booking.bootstrap.ApplicationSetupBean</class>
+ <class>org.jboss.seam.examples.booking.bootstrap.ApplicationInitializer</class>
</alternatives>
</beans>
Modified: examples/trunk/booking-simplified/src/main/webapp/password.xhtml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/password.xhtml 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/main/webapp/password.xhtml 2010-06-17 17:41:30 UTC (rev 13218)
@@ -25,7 +25,9 @@
<fieldset>
<p:input id="current">
- <h:inputSecret id="password" value="#{currentUser.password}"/>
+ <h:inputSecret id="password" value="#{currentUser.password}">
+ <f:validator validatorId="currentPasswordValidator" />
+ </h:inputSecret>
</p:input>
<p:input id="new">
@@ -44,8 +46,6 @@
</fieldset>
- <s:validateForm validatorId="changePasswordValidator"
- fields="currentPassword=current:password"/>
<s:validateForm validatorId="confirmPasswordValidator"
fields="newPassword=new:password confirmPassword=confirm:password"/>
</h:form>
Modified: examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/booking/BookingAgentTest.java
===================================================================
--- examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/booking/BookingAgentTest.java 2010-06-17 15:15:54 UTC (rev 13217)
+++ examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/booking/BookingAgentTest.java 2010-06-17 17:41:30 UTC (rev 13218)
@@ -38,7 +38,7 @@
{
WebArchive war = ShrinkWrap.create("test.war", WebArchive.class)
.addPackage(Hotel.class.getPackage())
- .addClasses(BookingAgent.class, BookingAgentBean.class, Confirmed.class,
+ .addClasses(BookingAgent.class, BookingAgent.class, Confirmed.class,
Authenticated.class, NoOpLogger.class)
.addLibraries(
MavenArtifactResolver.resolve("joda-time:joda-time:1.6"),
More information about the seam-commits
mailing list