diff --git a/booking/pom.xml b/booking/pom.xml index 275a2dc..a6f3b80 100644 --- a/booking/pom.xml +++ b/booking/pom.xml @@ -16,432 +16,432 @@ limitations under the License. --> - 4.0.0 - - org.jboss.seam.examples - seam-examples-parent - 3.0.0-SNAPSHOT - ../pom.xml - - org.jboss.seam.examples - seam-booking - war - Seam Booking Example - The Seam booking example using the simplified Java EE 6 programming model and packaging structure (i.e., web archive) - http://seamframework.org/Seam3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + + org.jboss.seam.examples + seam-examples-parent + 3.0.0-SNAPSHOT + ../pom.xml + + org.jboss.seam.examples + seam-booking + war + Seam Booking Example + The Seam booking example using the simplified Java EE 6 programming model and packaging structure (i.e., web archive) + http://seamframework.org/Seam3 - - src/main/webapp - ${env.JBOSS_HOME} - default - 1.0.0.Alpha3 - 3.1 - 1.1.1.Final - 6.0.0.Final - 1.0.0.Final - 1.0.3.GA - + + src/main/webapp + ${env.JBOSS_HOME} + default + 1.0.0.Alpha3 + 3.1 + 1.1.1.Final + 6.0.0.Final + 1.0.0.Final + 1.0.3.GA + - - - - org.jboss.seam.solder - seam-solder-tooling - 3.0.0-SNAPSHOT - provided - true - + + + + org.jboss.seam.solder + seam-solder-tooling + 3.0.0-SNAPSHOT + provided + true + - - org.jboss.seam.solder - seam-solder - 3.0.0-SNAPSHOT - + + org.jboss.seam.solder + seam-solder + 3.0.0-SNAPSHOT + - - org.hibernate - hibernate-jpamodelgen - ${jpamodelgen.version} - provided - - - - org.hibernate.javax.persistence - hibernate-jpa-2.0-api - - - - - - org.jboss.seam.faces - seam-faces - 3.0.0-SNAPSHOT - - - - org.jboss.seam.international - seam-international - 3.0.0-SNAPSHOT - - - - org.jboss.seam.servlet - seam-servlet - 3.0.0-SNAPSHOT - - - - org.jboss.seam.catch - seam-catch - - - + + + org.hibernate.javax.persistence + hibernate-jpa-2.0-api + + + + + + org.jboss.seam.faces + seam-faces + 3.0.0-SNAPSHOT + + + + org.jboss.seam.international + seam-international + 3.0.0-SNAPSHOT + + + + org.jboss.seam.servlet + seam-servlet + 3.0.0-SNAPSHOT + + + + org.jboss.seam.catch + seam-catch + + + - - - com.ocpsoft - ocpsoft-pretty-time - 1.0.6 - + + org.jboss.seam.mail + seam-mail-impl + 3.0.0-SNAPSHOT + runtime + --> + + + com.ocpsoft + ocpsoft-pretty-time + 1.0.6 + - - com.ocpsoft - prettyfaces-jsf2 - 3.0.1 - - - - commons-digester - commons-digester - 2.1 - - - - - - - org.hibernate. - hibernate-validator - 4.1.0.Final - provided - + + com.ocpsoft + prettyfaces-jsf2 + 3.0.1 + + + + commons-digester + commons-digester + 2.1 + + + + + + + org.hibernate. + hibernate-validator + 4.1.0.Final + provided + - - joda-time - joda-time - + + joda-time + joda-time + - - javax.enterprise - cdi-api - provided - - - - - org.seleniumhq.selenium.client-drivers - selenium-java-client-driver - - - - org.jboss.test - richfaces-selenium - + + javax.enterprise + cdi-api + provided + - - junit - junit - ${junit.version} - test - + + + org.seleniumhq.selenium.client-drivers + selenium-java-client-driver + - - org.jboss.arquillian - arquillian-junit - ${arquillian.version} - test - - - - org.jboss.spec - jboss-javaee-6.0 - ${jboss-javaee6-spec.version} - pom - provided - + + org.jboss.test + richfaces-selenium + - + + junit + junit + ${junit.version} + test + - + + org.jboss.arquillian + arquillian-junit + ${arquillian.version} + test + + + + org.jboss.spec + jboss-javaee-6.0 + ${jboss-javaee6-spec.version} + pom + provided + - - package - ${project.artifactId} - + - - org.apache.maven.plugins - maven-compiler-plugin - - - - - + - + + package + ${project.artifactId} + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + - - maven-eclipse-plugin - 2.8 - - - - - org.jboss.tools.common.verification.verifybuilder - - - - - .settings/org.maven.ide.eclipse.prefs - activeProfiles=jdk6 - eclipse.preferences.version=1 - fullBuildGoals=process-test-resources - includeModules=false - resolveWorkspaceProjects=true - resourceFilterGoals=process-resources - resources\:testResources - skipCompilerPlugin=true - version=1 - - - - 2.0 - - - org.eclipse.wst.jsdt.core.jsNature - org.jboss.tools.jsf.jsfnature - - ${user.home}/.eclipse/workspace - JBossAS - 2.0 - - - - - - - + - - ftest - + + maven-eclipse-plugin + 2.9 + + + + + org.jboss.tools.common.verification.verifybuilder + + + + + .settings/org.maven.ide.eclipse.prefs + activeProfiles=jdk6 + eclipse.preferences.version=1 + fullBuildGoals=process-test-resources + includeModules=false + resolveWorkspaceProjects=true + resourceFilterGoals=process-resources + resources\:testResources + skipCompilerPlugin=true + version=1 + + + + 2.0 + + + org.eclipse.wst.jsdt.core.jsNature + org.jboss.tools.jsf.jsfnature + + ${user.home}/.eclipse/workspace + JBossAS + 2.0 + + + + + + + - - distribution - - - release - - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - - - - - default - - true - - - - - maven-surefire-plugin - - true - - - - org.codehaus.mojo - jboss-maven-plugin - - 1.4.1 - - ${jboss.home} - ${jboss.domain} - - src/main/resources-jbossas/booking-ds.xml - ${project.build.directory}/${project.build.finalName}.war - - - - - - + + distribution + + + release + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + + + + + default + + true + + + + + maven-surefire-plugin + + true + + + + org.codehaus.mojo + jboss-maven-plugin + + 1.4.1 + + ${jboss.home} + ${jboss.domain} + + src/main/resources-jbossas/booking-ds.xml + ${project.build.directory}/${project.build.finalName}.war + + + + + + + + + ftest + - - jbossas-remote-6 - - - org.jboss.arquillian.container - arquillian-jbossas-remote-6 - ${arquillian.version} - test - - - org.jboss.spec - jboss-javaee-6.0 - ${jboss-javaee6-spec.version} - pom - provided - - - - org.jboss.jbossas - jboss-as-client - ${jboss-as-client.version} - pom - test - - - - - - src/test/resources - - - src/test/resources-jbossas - - - - + + jbossas-remote-6 + + + org.jboss.arquillian.container + arquillian-jbossas-remote-6 + ${arquillian.version} + test + + + org.jboss.spec + jboss-javaee-6.0 + ${jboss-javaee6-spec.version} + pom + provided + + + + org.jboss.jbossas + jboss-as-client + ${jboss-as-client.version} + pom + test + + + + + + src/test/resources + + + src/test/resources-jbossas + + + + - - glassfish-embedded-3 - - - org.jboss.arquillian.container - arquillian-glassfish-embedded-3 - ${arquillian.version} - test - - - org.glassfish.extras - glassfish-embedded-all - ${glassfish.version} - provided - - - - - - src/test/resources - - - src/test/resources-glassfish-embedded - - - - - maven-surefire-plugin - - 2.4.3 - - - - - derby.stream.error.file - - target/derby.log - - - - - - - + + glassfish-embedded-3 + + + org.jboss.arquillian.container + arquillian-glassfish-embedded-3 + ${arquillian.version} + test + + + org.glassfish.extras + glassfish-embedded-all + ${glassfish.version} + provided + + + + + + src/test/resources + + + src/test/resources-glassfish-embedded + + + + + maven-surefire-plugin + + 2.4.3 + + + + + derby.stream.error.file + + target/derby.log + + + + + + + - - + + - - scm:git:git://github.com/seam/examples.git - scm:git:git@github.com:seam/examples.git - http://github.com/seam - + + scm:git:git://github.com/seam/examples.git + scm:git:git@github.com:seam/examples.git + http://github.com/seam + diff --git a/booking/src/main/assembly/assembly.xml b/booking/src/main/assembly/assembly.xml index dd97b23..da0b49d 100644 --- a/booking/src/main/assembly/assembly.xml +++ b/booking/src/main/assembly/assembly.xml @@ -1,22 +1,23 @@ + - - zip - - ${project.build.finalName} - - - ${project.basedir} - true - - ${project.build.directory}/** - .classpath - .project - .settings/** - src/main/assembly/** - - - + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> + + zip + + ${project.build.finalName} + + + ${project.basedir} + true + + ${project.build.directory}/** + .classpath + .project + .settings/** + src/main/assembly/** + + + diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/account/Authenticated.java b/booking/src/main/java/org/jboss/seam/examples/booking/account/Authenticated.java index 4fc5df1..f9a7e35 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/account/Authenticated.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/account/Authenticated.java @@ -1,23 +1,18 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.account; @@ -37,10 +32,11 @@ * A qualifier, which indicates that the user has been sucessfully authenticated * * @author pmuir - * + * */ @Target({ TYPE, METHOD, PARAMETER, FIELD }) @Retention(RUNTIME) @Documented @Qualifier -public @interface Authenticated {} +public @interface Authenticated { +} diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/account/ConfirmPasswordValidator.java b/booking/src/main/java/org/jboss/seam/examples/booking/account/ConfirmPasswordValidator.java index d75dffd..cd51862 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/account/ConfirmPasswordValidator.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/account/ConfirmPasswordValidator.java @@ -1,23 +1,18 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.account; @@ -34,42 +29,34 @@ import org.jboss.seam.international.status.builder.BundleTemplateMessage; /** - * Validate that both the password fields contain the same value. Implements the - * classic pasword change validation. + * Validate that both the password fields contain the same value. Implements the classic pasword change validation. * * @author Lincoln Baxter, III */ @FacesValidator("confirmPasswordValidator") -public class ConfirmPasswordValidator implements Validator -{ - @Inject - private BundleTemplateMessage messageBuilder; - - @Inject @InputField - private String newPassword; - - @Inject @InputField - private String confirmPassword; - - - - public void validate(final FacesContext ctx, final UIComponent form, final Object components) - throws ValidatorException{ - - if (newPassword == null || confirmPassword == null) { - throw new ValidatorException(new FacesMessage(messageBuilder.key(new DefaultBundleKey("null_fields")) - .defaults("null fields is forbidden") - .build().getText())); - } - if ((newPassword != null) && !newPassword.equals(confirmPassword)) - { - throw new ValidatorException(new FacesMessage(messageBuilder.key(new DefaultBundleKey("account_passwordsDoNotMatch")) - .defaults("Passwords do not match") - .build().getText())); - } - } - - - +public class ConfirmPasswordValidator implements Validator { + @Inject + private BundleTemplateMessage messageBuilder; + + @Inject + @InputField + private String newPassword; + + @Inject + @InputField + private String confirmPassword; + + public void validate(final FacesContext ctx, final UIComponent form, final Object components) throws ValidatorException { + + if (newPassword == null || confirmPassword == null) { + throw new ValidatorException(new FacesMessage(messageBuilder.key(new DefaultBundleKey("null_fields")) + .defaults("null fields is forbidden").build().getText())); + } + if ((newPassword != null) && !newPassword.equals(confirmPassword)) { + throw new ValidatorException(new FacesMessage(messageBuilder + .key(new DefaultBundleKey("account_passwordsDoNotMatch")).defaults("Passwords do not match").build() + .getText())); + } + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/account/CurrentPasswordValidator.java b/booking/src/main/java/org/jboss/seam/examples/booking/account/CurrentPasswordValidator.java index 0313342..7674b9b 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/account/CurrentPasswordValidator.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/account/CurrentPasswordValidator.java @@ -1,23 +1,18 @@ /* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.account; @@ -35,38 +30,33 @@ import org.jboss.seam.international.status.builder.BundleTemplateMessage; /** - * A JSF Validator, used to check that the password the user submits matches - * that on record. + * A JSF Validator, used to check that the password the user submits matches that on record. * - * @author Dan Allen + * @author Dan Allen */ @FacesValidator("currentPassword") -public class CurrentPasswordValidator implements Validator -{ - @Inject - private BundleTemplateMessage messageBuilder; +public class CurrentPasswordValidator implements Validator { + @Inject + private BundleTemplateMessage messageBuilder; + + @Inject + @Authenticated + private User currentUser; + + @Inject + Messages messages; - @Inject @Authenticated - private User currentUser; - - @Inject - Messages messages; + 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)) { + /* + * FIXME: This is an ugly way to put i18n in FacesMessages: https://jira.jboss.org/browse/SEAMFACES-24 + */ - 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)) - { - /* - * FIXME: - * This is an ugly way to put i18n in FacesMessages: - * https://jira.jboss.org/browse/SEAMFACES-24 - */ - - throw new ValidatorException(new FacesMessage(messageBuilder.key(new DefaultBundleKey("account_passwordsDoNotMatch")) - .defaults("Passwords do not match") - .build().getText())); - } - } + throw new ValidatorException(new FacesMessage(messageBuilder + .key(new DefaultBundleKey("account_passwordsDoNotMatch")).defaults("Passwords do not match").build() + .getText())); + } + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/account/CurrentUserManager.java b/booking/src/main/java/org/jboss/seam/examples/booking/account/CurrentUserManager.java index a6ff025..ebbf9a0 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/account/CurrentUserManager.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/account/CurrentUserManager.java @@ -1,23 +1,18 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.account; @@ -33,25 +28,25 @@ /** * Exposes the currently logged in user * - * @author Dan Allen + * @author Dan Allen */ -@Stateful @SessionScoped -public class CurrentUserManager -{ - private User currentUser; +@Stateful +@SessionScoped +public class CurrentUserManager { + private User currentUser; - @Produces @Authenticated @Named("currentUser") - public User getCurrentAccount() - { - return currentUser; - } + @Produces + @Authenticated + @Named("currentUser") + public User getCurrentAccount() { + return currentUser; + } - // Injecting HttpServletRequest instead of HttpSession as the latter conflicts with a Weld bean on GlassFish 3.0.1 - public void onLogin(@Observes @Authenticated User user, HttpServletRequest request) - { - currentUser = user; - // reward authenticated users with a longer session - // default is kept short to prevent search engines from driving up # of sessions - request.getSession().setMaxInactiveInterval(3600); - } + // Injecting HttpServletRequest instead of HttpSession as the latter conflicts with a Weld bean on GlassFish 3.0.1 + public void onLogin(@Observes @Authenticated User user, HttpServletRequest request) { + currentUser = user; + // reward authenticated users with a longer session + // default is kept short to prevent search engines from driving up # of sessions + request.getSession().setMaxInactiveInterval(3600); + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java b/booking/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java index 2c2778e..41dd105 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/account/PasswordManager.java @@ -1,23 +1,18 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.account; @@ -36,45 +31,43 @@ /** * The view controller for changing the user password * - * @author Dan Allen + * @author Dan Allen */ -@Stateful @Model -public class PasswordManager -{ - @PersistenceContext - private EntityManager em; +@Stateful +@Model +public class PasswordManager { + @PersistenceContext + private EntityManager em; + + @Inject + private Messages messages; - @Inject - private Messages messages; + @Inject + @Authenticated + private User user; - @Inject @Authenticated - private User user; + @NotNull + @Size(min = 5, max = 15) + private String confirmPassword; - @NotNull @Size(min = 5, max = 15) - private String confirmPassword; - - private boolean changed; + private boolean changed; - public void changePassword() - { - em.merge(user); - messages.info(new DefaultBundleKey("account_passwordChanged")).defaults("Password successfully updated."); - changed = true; - } + public void changePassword() { + em.merge(user); + messages.info(new DefaultBundleKey("account_passwordChanged")).defaults("Password successfully updated."); + changed = true; + } - public boolean isChanged() - { - return changed; - } + public boolean isChanged() { + return changed; + } - public void setConfirmPassword(final String password) - { - confirmPassword = password; - } + public void setConfirmPassword(final String password) { + confirmPassword = password; + } - public String getConfirmPassword() - { - return confirmPassword; - } + public String getConfirmPassword() { + return confirmPassword; + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java b/booking/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java index 2ebcdfe..9c0dd1e 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/account/Registrar.java @@ -1,23 +1,18 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.account; @@ -41,127 +36,112 @@ /** * The view controller for registering a new user * - * @author Dan Allen + * @author Dan Allen */ @Stateful @Model -public class Registrar -{ - @PersistenceContext - private EntityManager em; - - @Inject - private Messages messages; - - @Inject - private FacesContext facesContext; - - private UIInput usernameInput; - - private UIInput confirmPasswordInput; - - 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 DefaultBundleKey("registration_registered")) - .defaults("You have been successfully registered as the user {0}! You can now login.").params(newUser.getUsername()); - } - else - { - registrationInvalid = true; - } - } - - public boolean isRegistrationInvalid() - { - return registrationInvalid; - } - - /** - * This method just shows another approach to adding a status message. - *

- * Invoked by: - *

- * - *
-	 * <f:event type="preRenderView" listener="#{registrar.notifyIfRegistrationIsInvalid}"/>
-	 * 
- */ - public void notifyIfRegistrationIsInvalid() - { - if (facesContext.isValidationFailed() || registrationInvalid) - { - messages.warn(new DefaultBundleKey("registration_invalid")).defaults( - "Invalid registration. Please correct the errors and try again."); - } - } - - @Produces - @Named - public User getNewUser() - { - return newUser; - } - - public boolean isRegistered() - { - return registered; - } - - public String getConfirmPassword() - { - return confirmPassword; - } - - public void setConfirmPassword(final String password) - { - confirmPassword = password; - } - - public UIInput getUsernameInput() - { - return usernameInput; - } - - public void setUsernameInput(final UIInput usernameInput) - { - this.usernameInput = usernameInput; - } - - public UIInput getConfirmPasswordInput() { - return confirmPasswordInput; - } - - public void setConfirmPasswordInput(final UIInput confirmPasswordInput) { - this.confirmPasswordInput = confirmPasswordInput; - } - - private boolean verifyUsernameIsAvailable() - { - User existing = em.find(User.class, newUser.getUsername()); - if (existing != null) - { - messages.warn(new BundleKey("messages", "account_usernameTaken")) - .defaults("The username '{0}' is already taken. Please choose another username.").targets(usernameInput.getClientId()) - .params(newUser.getUsername()); - return false; - } - - return true; - } - +public class Registrar { + @PersistenceContext + private EntityManager em; + + @Inject + private Messages messages; + + @Inject + private FacesContext facesContext; + + private UIInput usernameInput; + + private UIInput confirmPasswordInput; + + 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 DefaultBundleKey("registration_registered")) + .defaults("You have been successfully registered as the user {0}! You can now login.") + .params(newUser.getUsername()); + } else { + registrationInvalid = true; + } + } + + public boolean isRegistrationInvalid() { + return registrationInvalid; + } + + /** + * This method just shows another approach to adding a status message. + *

+ * Invoked by: + *

+ * + *
+     * <f:event type="preRenderView" listener="#{registrar.notifyIfRegistrationIsInvalid}"/>
+     * 
+ */ + public void notifyIfRegistrationIsInvalid() { + if (facesContext.isValidationFailed() || registrationInvalid) { + messages.warn(new DefaultBundleKey("registration_invalid")).defaults( + "Invalid registration. Please correct the errors and try again."); + } + } + + @Produces + @Named + public User getNewUser() { + return newUser; + } + + public boolean isRegistered() { + return registered; + } + + public String getConfirmPassword() { + return confirmPassword; + } + + public void setConfirmPassword(final String password) { + confirmPassword = password; + } + + public UIInput getUsernameInput() { + return usernameInput; + } + + public void setUsernameInput(final UIInput usernameInput) { + this.usernameInput = usernameInput; + } + + public UIInput getConfirmPasswordInput() { + return confirmPasswordInput; + } + + public void setConfirmPasswordInput(final UIInput confirmPasswordInput) { + this.confirmPasswordInput = confirmPasswordInput; + } + + private boolean verifyUsernameIsAvailable() { + User existing = em.find(User.class, newUser.getUsername()); + if (existing != null) { + messages.warn(new BundleKey("messages", "account_usernameTaken")) + .defaults("The username '{0}' is already taken. Please choose another username.") + .targets(usernameInput.getClientId()).params(newUser.getUsername()); + return false; + } + + return true; + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java b/booking/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java index 290fbe5..1f8fad8 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java @@ -1,23 +1,18 @@ -/* +/* * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.booking; @@ -53,106 +48,106 @@ import com.ocpsoft.pretty.time.PrettyTime; -@Stateful @ConversationScoped @Named -public class BookingAgent -{ - @Inject @TypedCategory(BookingAgent.class) - private BookingLog log; - - @PersistenceContext(type = EXTENDED) - private EntityManager em; - - @Inject - private Instance messageBuilder; - - @Inject - private Messages messages; - - @Inject @Authenticated - private User user; - - @Inject - private Locale locale; - - @Inject @Confirmed - private Event bookingConfirmedEventSrc; - - private Hotel hotelSelection; - - private Booking booking; - - private boolean bookingValid; - - @Inject - private Conversation conversation; - - @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.hotelSelected(user != null ? user.getName() : "Anonymous", hotelSelection.getName(), hotelSelection.getCity()); - } - } - - public void bookHotel() - { - booking = new Booking(hotelSelection, user, 7, 2); - hotelSelection = null; - - // for demo convenience - booking.setCreditCardNumber("1111222233334444"); - log.bookingInitiated(user.getName(), booking.getHotel().getName()); - - messages.info(new DefaultBundleKey("booking_initiated")).defaults("You've initiated a booking at the {0}.") - .params(booking.getHotel().getName()); - } - - public void validate() - { - log.hotelEntityInPersistenceContext(em.contains(booking.getHotel())); - // 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.bookingConfirmed(booking.getHotel().getName(), booking.getUser().getName()); - messages.info(new DefaultBundleKey("booking_confirmed")) - .defaults("You're booked to stay at the {0} {1}.") - .params(booking.getHotel().getName(), new PrettyTime(locale).format(booking.getCheckinDate())); - } - - @Produces @ConversationScoped @Named - public Booking getBooking() - { - return booking; - } - - @Produces @RequestScoped @Named("hotel") - public Hotel getSelectedHotel() - { - return booking != null ? booking.getHotel() : hotelSelection; - } - - public boolean isBookingValid() - { - return bookingValid; - } +/** + * @author Dan Allen + */ +@Stateful +@ConversationScoped +@Named +public class BookingAgent { + @Inject + @TypedCategory(BookingAgent.class) + private BookingLog log; + + @PersistenceContext(type = EXTENDED) + private EntityManager em; + + @Inject + private Instance messageBuilder; + + @Inject + private Messages messages; + + @Inject + @Authenticated + private User user; + + @Inject + private Locale locale; + + @Inject + @Confirmed + private Event bookingConfirmedEventSrc; + + private Hotel hotelSelection; + + private Booking booking; + + private boolean bookingValid; + + @Inject + private Conversation conversation; + + @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.hotelSelected(user != null ? user.getName() : "Anonymous", hotelSelection.getName(), hotelSelection.getCity()); + } + } + + public void bookHotel() { + booking = new Booking(hotelSelection, user, 7, 2); + hotelSelection = null; + + // for demo convenience + booking.setCreditCardNumber("1111222233334444"); + log.bookingInitiated(user.getName(), booking.getHotel().getName()); + + messages.info(new DefaultBundleKey("booking_initiated")).defaults("You've initiated a booking at the {0}.") + .params(booking.getHotel().getName()); + } + + public void validate() { + log.hotelEntityInPersistenceContext(em.contains(booking.getHotel())); + // 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.bookingConfirmed(booking.getHotel().getName(), booking.getUser().getName()); + messages.info(new DefaultBundleKey("booking_confirmed")).defaults("You're booked to stay at the {0} {1}.") + .params(booking.getHotel().getName(), new PrettyTime(locale).format(booking.getCheckinDate())); + } + + @Produces + @ConversationScoped + @Named + public Booking getBooking() { + return booking; + } + + @Produces + @RequestScoped + @Named("hotel") + public Hotel getSelectedHotel() { + return booking != null ? booking.getHotel() : hotelSelection; + } + + public boolean isBookingValid() { + return bookingValid; + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java b/booking/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java index f9a7076..d06d3a6 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/booking/BookingHistory.java @@ -1,23 +1,18 @@ -/* +/* * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.booking; @@ -54,87 +49,79 @@ /** * The booking history exposes the current users existing bookings * - * @author Dan Allen + * @author Dan Allen */ -@Stateful @SessionScoped @Named -public class BookingHistory -{ - @Inject - private Logger log; - - @PersistenceContext - private EntityManager entityManager; - - @Inject - private Messages messages; - - @Inject - private Identity identity; - - @Inject @Authenticated - private Instance currentUserInstance; - - private List bookingsForUser = null; - - @Produces @Authenticated @Named("bookings") - public List getBookingsForCurrentUser() - { - if (bookingsForUser == null && identity.isLoggedIn()) - { - fetchBookingsForCurrentUser(); - } - return bookingsForUser; - } - - public void onBookingComplete(@Observes(during = TransactionPhase.AFTER_SUCCESS, notifyObserver = Reception.IF_EXISTS) @Confirmed 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.infov("Canceling booking {0} for {1}", selectedBooking.getId(), currentUserInstance.get().getName()); - Booking booking = entityManager.find(Booking.class, selectedBooking.getId()); - if (booking != null) - { - entityManager.remove(booking); - messages.info(new DefaultBundleKey("booking_canceled")) - .defaults("The booking at the {0} on {1} has been canceled.") - .params(selectedBooking.getHotel().getName(), - DateFormat.getDateInstance(SimpleDateFormat.MEDIUM).format(selectedBooking.getCheckinDate())); - } - else - { - messages.info(new DefaultBundleKey("booking_doesNotExist")).defaults( - "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 = entityManager.getCriteriaBuilder(); - CriteriaQuery cquery = builder.createQuery(Booking.class); - Root 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 = entityManager.createQuery(cquery).getResultList(); - } +@Stateful +@SessionScoped +@Named +public class BookingHistory { + @Inject + private Logger log; + + @PersistenceContext + private EntityManager entityManager; + + @Inject + private Messages messages; + + @Inject + private Identity identity; + + @Inject + @Authenticated + private Instance currentUserInstance; + + private List bookingsForUser = null; + + @Produces + @Authenticated + @Named("bookings") + public List getBookingsForCurrentUser() { + if (bookingsForUser == null && identity.isLoggedIn()) { + fetchBookingsForCurrentUser(); + } + return bookingsForUser; + } + + public void onBookingComplete( + @Observes(during = TransactionPhase.AFTER_SUCCESS, notifyObserver = Reception.IF_EXISTS) @Confirmed 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.infov("Canceling booking {0} for {1}", selectedBooking.getId(), currentUserInstance.get().getName()); + Booking booking = entityManager.find(Booking.class, selectedBooking.getId()); + if (booking != null) { + entityManager.remove(booking); + messages.info(new DefaultBundleKey("booking_canceled")) + .defaults("The booking at the {0} on {1} has been canceled.") + .params(selectedBooking.getHotel().getName(), + DateFormat.getDateInstance(SimpleDateFormat.MEDIUM).format(selectedBooking.getCheckinDate())); + } else { + messages.info(new DefaultBundleKey("booking_doesNotExist")).defaults( + "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 = entityManager.getCriteriaBuilder(); + CriteriaQuery cquery = builder.createQuery(Booking.class); + Root 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 = entityManager.createQuery(cquery).getResultList(); + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/booking/Confirmed.java b/booking/src/main/java/org/jboss/seam/examples/booking/booking/Confirmed.java index 742dd03..f8e6faf 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/booking/Confirmed.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/booking/Confirmed.java @@ -1,23 +1,18 @@ -/* +/* * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.booking; @@ -36,10 +31,11 @@ /** * A qualifier, used to differentiate confirmed and unconfirmed bookings * - * @author Dan Allen + * @author Dan Allen */ -@Target( { TYPE, METHOD, PARAMETER, FIELD }) +@Target({ TYPE, METHOD, PARAMETER, FIELD }) @Retention(RUNTIME) @Documented @Qualifier -public @interface Confirmed {} +public @interface Confirmed { +} diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/booking/ReservationDateRangeValidator.java b/booking/src/main/java/org/jboss/seam/examples/booking/booking/ReservationDateRangeValidator.java index 782d86c..0b324f7 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/booking/ReservationDateRangeValidator.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/booking/ReservationDateRangeValidator.java @@ -1,23 +1,18 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.booking; @@ -40,46 +35,39 @@ import org.jboss.seam.international.status.builder.BundleTemplateMessage; /** - * A cross-field validator that validates the start date is in the future and - * before the end date. + * A cross-field validator that validates the start date is in the future and before the end date. * - * @author Dan Allen + * @author Dan Allen */ @FacesValidator("reservationDateRange") -public class ReservationDateRangeValidator implements Validator -{ - @Inject - @InputField - private Date startDate; - - @Inject - @InputField - private Date endDate; +public class ReservationDateRangeValidator implements Validator { + @Inject + @InputField + private Date startDate; - @Inject - private Instance messageBuilder; + @Inject + @InputField + private Date endDate; + @Inject + private Instance messageBuilder; - public void validate(final FacesContext ctx, final UIComponent form, final Object value) throws ValidatorException - { - @SuppressWarnings("unchecked") - Map fieldMap = (Map) value; + public void validate(final FacesContext ctx, final UIComponent form, final Object value) throws ValidatorException { + @SuppressWarnings("unchecked") + Map fieldMap = (Map) value; - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DAY_OF_MONTH, -1); - if (startDate.before(calendar.getTime())) - { - String message = messageBuilder.get().key(new DefaultBundleKey("booking_checkInNotFutureDate")) - // FIXME the component should come through via injection - .targets(fieldMap.get("beginDate").getClientId()).build().getText(); - throw new ValidatorException(new FacesMessage(message)); - } - else if (!startDate.before(endDate)) - { - String message = messageBuilder.get().key(new DefaultBundleKey("booking_checkOutBeforeCheckIn")) - // FIXME the component should come through via injection - .targets(fieldMap.get("endDate").getClientId()).build().getText(); - throw new ValidatorException(new FacesMessage(message)); - } - } + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH, -1); + if (startDate.before(calendar.getTime())) { + String message = messageBuilder.get().key(new DefaultBundleKey("booking_checkInNotFutureDate")) + // FIXME the component should come through via injection + .targets(fieldMap.get("beginDate").getClientId()).build().getText(); + throw new ValidatorException(new FacesMessage(message)); + } else if (!startDate.before(endDate)) { + String message = messageBuilder.get().key(new DefaultBundleKey("booking_checkOutBeforeCheckIn")) + // FIXME the component should come through via injection + .targets(fieldMap.get("endDate").getClientId()).build().getText(); + throw new ValidatorException(new FacesMessage(message)); + } + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/booking/ReservationNotifier.java b/booking/src/main/java/org/jboss/seam/examples/booking/booking/ReservationNotifier.java index 549a55a..679ffd5 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/booking/ReservationNotifier.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/booking/ReservationNotifier.java @@ -1,23 +1,18 @@ /* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.booking; @@ -34,21 +29,18 @@ // @ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/BookingTopic"), // @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic") //}) -public class ReservationNotifier implements MessageListener -{ - @Inject - private Logger log; +public class ReservationNotifier implements MessageListener { + @Inject + private Logger log; - public void onMessage(Message message) - { - try - { - Booking booking = (Booking) ((ObjectMessage) message).getObject(); - log.info("In a real-world application, send e-mail containing reservation information to " + booking.getUser().getEmailWithName()); - } catch (JMSException ex) - { - log.error("Error reading booking from topic"); - } - } + public void onMessage(Message message) { + try { + Booking booking = (Booking) ((ObjectMessage) message).getObject(); + log.info("In a real-world application, send e-mail containing reservation information to " + + booking.getUser().getEmailWithName()); + } catch (JMSException ex) { + log.error("Error reading booking from topic"); + } + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationInitializer.java b/booking/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationInitializer.java index 29a0d8f..0085d58 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationInitializer.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/bootstrap/ApplicationInitializer.java @@ -1,23 +1,18 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.bootstrap; @@ -67,8 +62,7 @@ public ApplicationInitializer() { new User("Shane Bryzak", "shane", "shane@example.com", "brisbane"), new User("Dan Allen", "dan", "dan@example.com", "laurel"), new User("Lincoln Baxter III", "lincoln", "lincoln@example.com", "charlotte"), - new User("Jose Freitas", "jose", "jose.freitas@example.com", "brazil")) - ); + new User("Jose Freitas", "jose", "jose.freitas@example.com", "brazil"))); hotels.addAll(Arrays.asList( new Hotel(129, 3, "Marriott Courtyard", "Tower Place, Buckhead", "Atlanta", "GA", "30305", "USA"), @@ -85,7 +79,7 @@ public ApplicationInitializer() { new Hotel(543, 4, "Hilton Diagonal Mar", "Passeig del Taulat 262-264", "Barcelona", "Catalunya", "08019", "ES"), new Hotel(335, 5, "Hilton Tel Aviv", "Independence Park", "Tel Aviv", null, "63405", "IL"), new Hotel(242, 5, "InterContinental Hotel Tokyo Bay", "1-15-2 Kaigan", "Tokyo", "Minato", "105", "JP"), - new Hotel(130, 4, "Hotel Beaulac", " Esplanade Léopold-Robert 2", "Neuchatel", null, "2000", "CH"), + new Hotel(130, 4, "Hotel Beaulac", "Esplanade Léopold-Robert 2", "Neuchatel", null, "2000", "CH"), new Hotel(266, 5, "Conrad Treasury Place", "130 William Street", "Brisbane", "QL", "4001", "AU"), new Hotel(170, 4, "Ritz-Carlton Montreal", "1228 Sherbrooke St West", "Montreal", "Quebec", "H3G1H6", "CA"), new Hotel(179, 4, "Ritz-Carlton Atlanta", "181 Peachtree St NE", "Atlanta", "GA", "30303", "USA"), @@ -94,8 +88,7 @@ public ApplicationInitializer() { new Hotel(159, 3, "Hotel Allegro", "171 W Randolph Street", "Chicago", "IL", "60601", "USA"), new Hotel(296, 5, "Caesars Palace", "3570 Las Vegas Blvd S", "Las Vegas", "NV", "89109", "USA"), new Hotel(300, 4, "Mandalay Bay Resort & Casino", "3950 Las Vegas Blvd S", "Las Vegas", "NV", "89119", "USA"), - new Hotel(100, 2, "Hotel Cammerpoorte", "Nationalestraat 38-40", "Antwerp", null, "2000", "BE")) - ); + new Hotel(100, 2, "Hotel Cammerpoorte", "Nationalestraat 38-40", "Antwerp", null, "2000", "BE"))); } /** @@ -120,8 +113,8 @@ public void importData(@Observes @Initialized WebApplication webapp) { log.error("Error rolling back transaction", rbe); } } + } catch (Exception se) { } - catch (Exception se) {} } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/exceptioncontrol/GeneralExceptionHandler.java b/booking/src/main/java/org/jboss/seam/examples/booking/exceptioncontrol/GeneralExceptionHandler.java index 229792c..5d0226f 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/exceptioncontrol/GeneralExceptionHandler.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/exceptioncontrol/GeneralExceptionHandler.java @@ -1,3 +1,19 @@ +/* + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jboss.seam.examples.booking.exceptioncontrol; import org.jboss.logging.Logger; @@ -12,10 +28,10 @@ */ @HandlesExceptions public class GeneralExceptionHandler { - - public void printExceptionMessage(@Handles CaughtException event, Logger log) { - log.info("Something bad happened: " + event.getException().getMessage()); - event.rethrow(); - } + + public void printExceptionMessage(@Handles CaughtException event, Logger log) { + log.info("Something bad happened: " + event.getException().getMessage()); + event.rethrow(); + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/i18n/DefaultBundleKey.java b/booking/src/main/java/org/jboss/seam/examples/booking/i18n/DefaultBundleKey.java index 94332ef..122b5a6 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/i18n/DefaultBundleKey.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/i18n/DefaultBundleKey.java @@ -1,37 +1,31 @@ /* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.i18n; import org.jboss.seam.international.status.builder.BundleKey; /** - * @author Dan Allen + * @author Dan Allen */ public class DefaultBundleKey extends BundleKey { - public static final String DEFAULT_BUNDLE_NAME = "messages"; + public static final String DEFAULT_BUNDLE_NAME = "messages"; - public DefaultBundleKey(String key) - { - super(DEFAULT_BUNDLE_NAME, key); - } + public DefaultBundleKey(String key) { + super(DEFAULT_BUNDLE_NAME, key); + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java b/booking/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java index 5ed4550..5d50706 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/inventory/HotelSearch.java @@ -1,23 +1,18 @@ -/* +/* * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.inventory; @@ -41,86 +36,85 @@ import org.jboss.seam.examples.booking.model.Hotel_; import org.jboss.seam.international.status.builder.TemplateMessage; +/** + * @author Dan Allen + */ @Named @Stateful @SessionScoped -public class HotelSearch -{ - - @Inject - private Logger log; - - @PersistenceContext - private EntityManager em; - - @Inject - private SearchCriteria criteria; - - @Inject - private Instance messageBuilder; - - private boolean nextPageAvailable = false; - - private List hotels = new ArrayList(); - - 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 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 cquery = builder.createQuery(Hotel.class); - Root 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 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(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()); - /*System.out.println(messageBuilder.get().text("Found {0} hotel(s) matching search term [ {1} ] (limit {2})") - .textParams(hotels.size(), criteria.getQuery(), criteria.getPageSize()).build().getText());*/ - } +public class HotelSearch { + + @Inject + private Logger log; + + @PersistenceContext + private EntityManager em; + + @Inject + private SearchCriteria criteria; + + @Inject + private Instance messageBuilder; + + private boolean nextPageAvailable = false; + + private List hotels = new ArrayList(); + + 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 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 cquery = builder.createQuery(Hotel.class); + Root 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 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(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()); + /* + * System.out.println(messageBuilder.get().text("Found {0} hotel(s) matching search term [ {1} ] (limit {2})") + * .textParams(hotels.size(), criteria.getQuery(), criteria.getPageSize()).build().getText()); + */ + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/inventory/SearchCriteria.java b/booking/src/main/java/org/jboss/seam/examples/booking/inventory/SearchCriteria.java index 89f81f7..f695c72 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/inventory/SearchCriteria.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/inventory/SearchCriteria.java @@ -1,23 +1,18 @@ -/* +/* * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.inventory; @@ -26,94 +21,81 @@ import javax.enterprise.context.SessionScoped; import javax.inject.Named; +/** + * @author Dan Allen + */ @Named @SessionScoped -public class SearchCriteria implements Serializable -{ - private static final char SQL_WILDCARD_CHAR = '%'; - private static final String SQL_WILDCARD_STR = String.valueOf(SQL_WILDCARD_CHAR); - private static final String REPEAT_SQL_WIDCARD_REGEX = SQL_WILDCARD_STR + "+"; - private static final char HUMAN_WILDCARD_CHAR = '*'; - - private String query = ""; - private int pageSize = 5; - private int page = 0; - - public String getSearchPattern() - { - if (query == null || query.length() == 0) - { - return SQL_WILDCARD_STR; - } - - StringBuilder pattern = new StringBuilder(); - pattern.append(query.toLowerCase().replace(HUMAN_WILDCARD_CHAR, SQL_WILDCARD_CHAR).replaceAll(REPEAT_SQL_WIDCARD_REGEX, SQL_WILDCARD_STR)); - if (pattern.length() == 0 || pattern.charAt(0) != SQL_WILDCARD_CHAR) - { - pattern.insert(0, SQL_WILDCARD_CHAR); - } - if (pattern.length() > 1 && pattern.charAt(pattern.length() - 1) != SQL_WILDCARD_CHAR) - { - pattern.append(SQL_WILDCARD_CHAR); - } - return pattern.toString(); - } - - public int getPage() - { - return page; - } - - public void setPage(int page) - { - this.page = page; - } - - public int getPageSize() - { - return pageSize; - } - - public void setPageSize(int pageSize) - { - this.pageSize = pageSize; - } - - public int getFetchSize() - { - return pageSize + 1; - } - - public int getFetchOffset() - { - return page * pageSize; - } - - public String getQuery() - { - return query; - } - - public void setQuery(String query) - { - this.query = (query != null ? query.trim() : null); - } - - public void nextPage() - { - page++; - } - - public void previousPage() - { - if (page > 0) - { - page--; - } - } - - public void firstPage() - { - page = 0; - } +public class SearchCriteria implements Serializable { + private static final char SQL_WILDCARD_CHAR = '%'; + private static final String SQL_WILDCARD_STR = String.valueOf(SQL_WILDCARD_CHAR); + private static final String REPEAT_SQL_WIDCARD_REGEX = SQL_WILDCARD_STR + "+"; + private static final char HUMAN_WILDCARD_CHAR = '*'; + + private String query = ""; + private int pageSize = 5; + private int page = 0; + + public String getSearchPattern() { + if (query == null || query.length() == 0) { + return SQL_WILDCARD_STR; + } + + StringBuilder pattern = new StringBuilder(); + pattern.append(query.toLowerCase().replace(HUMAN_WILDCARD_CHAR, SQL_WILDCARD_CHAR) + .replaceAll(REPEAT_SQL_WIDCARD_REGEX, SQL_WILDCARD_STR)); + if (pattern.length() == 0 || pattern.charAt(0) != SQL_WILDCARD_CHAR) { + pattern.insert(0, SQL_WILDCARD_CHAR); + } + if (pattern.length() > 1 && pattern.charAt(pattern.length() - 1) != SQL_WILDCARD_CHAR) { + pattern.append(SQL_WILDCARD_CHAR); + } + return pattern.toString(); + } + + public int getPage() { + return page; + } + + public void setPage(int page) { + this.page = page; + } + + public int getPageSize() { + return pageSize; + } + + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + + public int getFetchSize() { + return pageSize + 1; + } + + public int getFetchOffset() { + return page * pageSize; + } + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = (query != null ? query.trim() : null); + } + + public void nextPage() { + page++; + } + + public void previousPage() { + if (page > 0) { + page--; + } + } + + public void firstPage() { + page = 0; + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/log/BookingLog.java b/booking/src/main/java/org/jboss/seam/examples/booking/log/BookingLog.java index 91909da..9bdab2b 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/log/BookingLog.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/log/BookingLog.java @@ -1,3 +1,19 @@ +/* + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jboss.seam.examples.booking.log; import org.jboss.logging.Logger.Level; @@ -5,21 +21,24 @@ import org.jboss.seam.solder.logging.Message; import org.jboss.seam.solder.logging.MessageLogger; +/** + * @author Dan Allen + */ @MessageLogger public interface BookingLog { @LogMessage(level = Level.INFO) @Message("%s selected the %s in %s.") void hotelSelected(String customerName, String hotelName, String city); - + @LogMessage(level = Level.INFO) @Message("%s initiated a booking at the %s.") void bookingInitiated(String customerName, String hotelName); - + // QUESTION can positional parameters be used in message string? @LogMessage(level = Level.INFO) @Message("New booking at the %s confirmed for %s.") void bookingConfirmed(String hotelName, String customerName); - + @LogMessage(level = Level.INFO) @Message("Does the persistence context still contain the hotel instance? %s") void hotelEntityInPersistenceContext(boolean state); diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/model/Booking.java b/booking/src/main/java/org/jboss/seam/examples/booking/model/Booking.java index b07f061..d979720 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/model/Booking.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/model/Booking.java @@ -1,23 +1,18 @@ -/* +/* * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.model; @@ -44,234 +39,199 @@ import org.jboss.seam.solder.core.Veto; /** - *

Booking is the model/entity class that represents a hotel - * booking.

- * + *

+ * Booking is the model/entity class that represents a hotel booking. + *

+ * * @author Gavin King - * @author Dan Allen + * @author Dan Allen */ @Entity @Veto -public class Booking implements Serializable -{ - private Long id; - private User user; - private Hotel hotel; - private Date checkinDate; - private Date checkoutDate; - private String creditCardNumber; - private CreditCardType creditCardType; - private String creditCardName; - private int creditCardExpiryMonth; - private int creditCardExpiryYear; - private boolean smoking; - private int beds; - - public Booking() - { - } - - public Booking(Hotel hotel, User user, int daysFromNow, int nights) - { - this.hotel = hotel; - this.user = user; - creditCardName = user.getName(); - smoking = false; - beds = 1; - setReservationDates(daysFromNow, nights); - creditCardExpiryMonth = Calendar.getInstance().get(Calendar.MONTH) + 1; - } - - @Id - @GeneratedValue - public Long getId() - { - return id; - } - - public void setId(Long id) - { - this.id = id; - } - - @Temporal(TemporalType.DATE) - public Date getCheckinDate() - { - return checkinDate; - } - - public void setCheckinDate(Date datetime) - { - checkinDate = datetime; - } - - @NotNull - @ManyToOne - public Hotel getHotel() - { - return hotel; - } - - public void setHotel(Hotel hotel) - { - this.hotel = hotel; - } - - @NotNull - @ManyToOne - public User getUser() - { - return user; - } - - public void setUser(User user) - { - this.user = user; - } - - @Temporal(TemporalType.DATE) - public Date getCheckoutDate() - { - return checkoutDate; - } - - public void setCheckoutDate(Date checkoutDate) - { - this.checkoutDate = checkoutDate; - } - - public boolean isSmoking() - { - return smoking; - } - - public void setSmoking(boolean smoking) - { - this.smoking = smoking; - } - - //@Size(min = 1, max = 3) - public int getBeds() - { - return beds; - } - - public void setBeds(int beds) - { - this.beds = beds; - } - - @NotNull(message = "Credit card number is required") - @Size(min = 16, max = 16, message = "Credit card number must 16 digits long") - @Digits(fraction = 0, integer = 16) - @CreditCardNumber - public String getCreditCardNumber() - { - return creditCardNumber; - } - - public void setCreditCardNumber(String creditCardNumber) - { - this.creditCardNumber = creditCardNumber; - } - - @NotNull(message = "Credit card type is required") - @Enumerated(EnumType.STRING) - public CreditCardType getCreditCardType() - { - return creditCardType; - } - - public void setCreditCardType(CreditCardType creditCardType) - { - this.creditCardType = creditCardType; - } - - @NotNull(message = "Credit card name is required") - @Size(min = 3, max = 70, message = "Credit card name is required") - public String getCreditCardName() - { - return creditCardName; - } - - public void setCreditCardName(String creditCardName) - { - this.creditCardName = creditCardName; - } - - /** - * The credit card expiration month, represented using a 1-based - * numeric value (i.e., Jan = 1, Feb = 2, ...). - * - * @return 1-based numeric month value - */ - public int getCreditCardExpiryMonth() - { - return creditCardExpiryMonth; - } - - public void setCreditCardExpiryMonth(int creditCardExpiryMonth) - { - this.creditCardExpiryMonth = creditCardExpiryMonth; - } - - /** - * The credit card expiration year. - * - * @return numberic year value - */ - public int getCreditCardExpiryYear() - { - return creditCardExpiryYear; - } - - public void setCreditCardExpiryYear(int creditCardExpiryYear) - { - this.creditCardExpiryYear = creditCardExpiryYear; - } - - @Transient - public String getDescription() - { - DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM); - return hotel == null ? null : hotel.getName() + - ", " + df.format(getCheckinDate()) + - " to " + df.format(getCheckoutDate()); - } - - @Transient - public BigDecimal getTotal() - { - return hotel.getPrice().multiply(new BigDecimal(getNights())); - } - - @Transient - public int getNights() - { - return (int) (checkoutDate.getTime() - checkinDate.getTime()) / 1000 / 60 / 60 / 24; - } - - /** - * Initialize the check-in and check-out dates. - * - * @param daysFromNow Number of days the stay will begin from now - * @param nights Length of the stay in number of nights - */ - public void setReservationDates(int daysFromNow, int nights) - { - Calendar refDate = Calendar.getInstance(); - refDate.set( - refDate.get(Calendar.YEAR), - refDate.get(Calendar.MONTH), - refDate.get(Calendar.DAY_OF_MONTH) + daysFromNow, 0, 0, 0); - setCheckinDate(refDate.getTime()); - refDate.add(Calendar.DAY_OF_MONTH, nights); - setCheckoutDate(refDate.getTime()); - } - - @Override - public String toString() - { - return "Booking(" + user + ", " + hotel + ")"; - } +public class Booking implements Serializable { + private Long id; + private User user; + private Hotel hotel; + private Date checkinDate; + private Date checkoutDate; + private String creditCardNumber; + private CreditCardType creditCardType; + private String creditCardName; + private int creditCardExpiryMonth; + private int creditCardExpiryYear; + private boolean smoking; + private int beds; + + public Booking() { + } + + public Booking(Hotel hotel, User user, int daysFromNow, int nights) { + this.hotel = hotel; + this.user = user; + creditCardName = user.getName(); + smoking = false; + beds = 1; + setReservationDates(daysFromNow, nights); + creditCardExpiryMonth = Calendar.getInstance().get(Calendar.MONTH) + 1; + } + + @Id + @GeneratedValue + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + @Temporal(TemporalType.DATE) + public Date getCheckinDate() { + return checkinDate; + } + + public void setCheckinDate(Date datetime) { + checkinDate = datetime; + } + + @NotNull + @ManyToOne + public Hotel getHotel() { + return hotel; + } + + public void setHotel(Hotel hotel) { + this.hotel = hotel; + } + + @NotNull + @ManyToOne + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + @Temporal(TemporalType.DATE) + public Date getCheckoutDate() { + return checkoutDate; + } + + public void setCheckoutDate(Date checkoutDate) { + this.checkoutDate = checkoutDate; + } + + public boolean isSmoking() { + return smoking; + } + + public void setSmoking(boolean smoking) { + this.smoking = smoking; + } + + // @Size(min = 1, max = 3) + public int getBeds() { + return beds; + } + + public void setBeds(int beds) { + this.beds = beds; + } + + @NotNull(message = "Credit card number is required") + @Size(min = 16, max = 16, message = "Credit card number must 16 digits long") + @Digits(fraction = 0, integer = 16) + @CreditCardNumber + public String getCreditCardNumber() { + return creditCardNumber; + } + + public void setCreditCardNumber(String creditCardNumber) { + this.creditCardNumber = creditCardNumber; + } + + @NotNull(message = "Credit card type is required") + @Enumerated(EnumType.STRING) + public CreditCardType getCreditCardType() { + return creditCardType; + } + + public void setCreditCardType(CreditCardType creditCardType) { + this.creditCardType = creditCardType; + } + + @NotNull(message = "Credit card name is required") + @Size(min = 3, max = 70, message = "Credit card name is required") + public String getCreditCardName() { + return creditCardName; + } + + public void setCreditCardName(String creditCardName) { + this.creditCardName = creditCardName; + } + + /** + * The credit card expiration month, represented using a 1-based numeric value (i.e., Jan = 1, Feb = 2, ...). + * + * @return 1-based numeric month value + */ + public int getCreditCardExpiryMonth() { + return creditCardExpiryMonth; + } + + public void setCreditCardExpiryMonth(int creditCardExpiryMonth) { + this.creditCardExpiryMonth = creditCardExpiryMonth; + } + + /** + * The credit card expiration year. + * + * @return numberic year value + */ + public int getCreditCardExpiryYear() { + return creditCardExpiryYear; + } + + public void setCreditCardExpiryYear(int creditCardExpiryYear) { + this.creditCardExpiryYear = creditCardExpiryYear; + } + + @Transient + public String getDescription() { + DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM); + return hotel == null ? null : hotel.getName() + ", " + df.format(getCheckinDate()) + " to " + + df.format(getCheckoutDate()); + } + + @Transient + public BigDecimal getTotal() { + return hotel.getPrice().multiply(new BigDecimal(getNights())); + } + + @Transient + public int getNights() { + return (int) (checkoutDate.getTime() - checkinDate.getTime()) / 1000 / 60 / 60 / 24; + } + + /** + * Initialize the check-in and check-out dates. + * + * @param daysFromNow Number of days the stay will begin from now + * @param nights Length of the stay in number of nights + */ + public void setReservationDates(int daysFromNow, int nights) { + Calendar refDate = Calendar.getInstance(); + refDate.set(refDate.get(Calendar.YEAR), refDate.get(Calendar.MONTH), refDate.get(Calendar.DAY_OF_MONTH) + daysFromNow, + 0, 0, 0); + setCheckinDate(refDate.getTime()); + refDate.add(Calendar.DAY_OF_MONTH, nights); + setCheckoutDate(refDate.getTime()); + } + + @Override + public String toString() { + return "Booking(" + user + ", " + hotel + ")"; + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/model/Booking_.java b/booking/src/main/java/org/jboss/seam/examples/booking/model/Booking_.java index 445bcbb..1d7adfc 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/model/Booking_.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/model/Booking_.java @@ -1,24 +1,23 @@ package org.jboss.seam.examples.booking.model; -import java.util.Date; -import javax.persistence.metamodel.SingularAttribute; -import javax.persistence.metamodel.StaticMetamodel; +import java.util.Date; +import javax.persistence.metamodel.SingularAttribute; +import javax.persistence.metamodel.StaticMetamodel; @StaticMetamodel(Booking.class) public abstract class Booking_ { - public static volatile SingularAttribute id; - public static volatile SingularAttribute beds; - public static volatile SingularAttribute smoking; - public static volatile SingularAttribute creditCardName; - public static volatile SingularAttribute creditCardNumber; - public static volatile SingularAttribute hotel; - public static volatile SingularAttribute checkinDate; - public static volatile SingularAttribute creditCardExpiryYear; - public static volatile SingularAttribute creditCardExpiryMonth; - public static volatile SingularAttribute checkoutDate; - public static volatile SingularAttribute user; - public static volatile SingularAttribute creditCardType; + public static volatile SingularAttribute id; + public static volatile SingularAttribute beds; + public static volatile SingularAttribute smoking; + public static volatile SingularAttribute creditCardName; + public static volatile SingularAttribute creditCardNumber; + public static volatile SingularAttribute hotel; + public static volatile SingularAttribute checkinDate; + public static volatile SingularAttribute creditCardExpiryYear; + public static volatile SingularAttribute creditCardExpiryMonth; + public static volatile SingularAttribute checkoutDate; + public static volatile SingularAttribute user; + public static volatile SingularAttribute creditCardType; } - diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/model/CreditCardType.java b/booking/src/main/java/org/jboss/seam/examples/booking/model/CreditCardType.java index d826c57..baf901a 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/model/CreditCardType.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/model/CreditCardType.java @@ -1,30 +1,24 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.model; -public enum CreditCardType -{ - VISA, - MasterCard, - AMEX, - Discover +/** + * @author Dan Allen + */ +public enum CreditCardType { + VISA, MasterCard, AMEX, Discover } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/model/Hotel.java b/booking/src/main/java/org/jboss/seam/examples/booking/model/Hotel.java index 5c83109..9077033 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/model/Hotel.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/model/Hotel.java @@ -1,23 +1,18 @@ -/* +/* * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.model; @@ -43,164 +38,142 @@ *

* * @author Gavin King - * @author Dan Allen + * @author Dan Allen */ @Entity @Table(name = "hotel") @Veto -public class Hotel implements Serializable -{ - private Long id; - private String name; - private String address; - private String city; - private String state; - private String zip; - private String country; - private Integer stars; - private BigDecimal price; - - public Hotel() - { - } - - public Hotel(final String name, final String address, final String city, final String state, final String zip, final String country) - { - this.name = name; - this.address = address; - this.city = city; - this.state = state; - this.zip = zip; - this.country = country; - } - - public Hotel(final int price, final int stars, final String name, final String address, final String city, final String state, final String zip, final String country) - { - this.price = new BigDecimal(price); - this.stars = stars; - this.name = name; - this.address = address; - this.city = city; - this.state = state; - this.zip = zip; - this.country = country; - } - - @Id - @GeneratedValue - public Long getId() - { - return id; - } - - public void setId(final Long id) - { - this.id = id; - } - - @Size(max = 50) - @NotNull - public String getName() - { - return name; - } - - public void setName(final String name) - { - this.name = name; - } - - @Size(max = 100) - @NotNull - public String getAddress() - { - return address; - } - - public void setAddress(final String address) - { - this.address = address; - } - - @Size(max = 40) - @NotNull - public String getCity() - { - return city; - } - - public void setCity(final String city) - { - this.city = city; - } - - @Size(min = 3, max = 6) - @NotNull - public String getZip() - { - return zip; - } - - public void setZip(final String zip) - { - this.zip = zip; - } - - @Size(min = 2, max = 10) - public String getState() - { - return state; - } - - public void setState(final String state) - { - this.state = state; - } - - @Size(min = 2, max = 40) - @NotNull - public String getCountry() - { - return country; - } - - public void setCountry(final String country) - { - this.country = country; - } - - @Min(1) - @Max(5) - public Integer getStars() - { - return stars; - } - - public void setStars(final Integer stars) - { - this.stars = stars; - } - - @Column(precision = 6, scale = 2) - public BigDecimal getPrice() - { - return price; - } - - public void setPrice(final BigDecimal price) - { - this.price = price; - } - - @Transient - public String getLocation() - { - return city + ", " + state + ", " + country; - } - - @Override - public String toString() - { - return "Hotel(" + name + "," + address + "," + city + "," + zip + ")"; - } +public class Hotel implements Serializable { + private Long id; + private String name; + private String address; + private String city; + private String state; + private String zip; + private String country; + private Integer stars; + private BigDecimal price; + + public Hotel() { + } + + public Hotel(final String name, final String address, final String city, final String state, final String zip, + final String country) { + this.name = name; + this.address = address; + this.city = city; + this.state = state; + this.zip = zip; + this.country = country; + } + + public Hotel(final int price, final int stars, final String name, final String address, final String city, + final String state, final String zip, final String country) { + this.price = new BigDecimal(price); + this.stars = stars; + this.name = name; + this.address = address; + this.city = city; + this.state = state; + this.zip = zip; + this.country = country; + } + + @Id + @GeneratedValue + public Long getId() { + return id; + } + + public void setId(final Long id) { + this.id = id; + } + + @Size(max = 50) + @NotNull + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + @Size(max = 100) + @NotNull + public String getAddress() { + return address; + } + + public void setAddress(final String address) { + this.address = address; + } + + @Size(max = 40) + @NotNull + public String getCity() { + return city; + } + + public void setCity(final String city) { + this.city = city; + } + + @Size(min = 3, max = 6) + @NotNull + public String getZip() { + return zip; + } + + public void setZip(final String zip) { + this.zip = zip; + } + + @Size(min = 2, max = 10) + public String getState() { + return state; + } + + public void setState(final String state) { + this.state = state; + } + + @Size(min = 2, max = 40) + @NotNull + public String getCountry() { + return country; + } + + public void setCountry(final String country) { + this.country = country; + } + + @Min(1) + @Max(5) + public Integer getStars() { + return stars; + } + + public void setStars(final Integer stars) { + this.stars = stars; + } + + @Column(precision = 6, scale = 2) + public BigDecimal getPrice() { + return price; + } + + public void setPrice(final BigDecimal price) { + this.price = price; + } + + @Transient + public String getLocation() { + return city + ", " + state + ", " + country; + } + + @Override + public String toString() { + return "Hotel(" + name + "," + address + "," + city + "," + zip + ")"; + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/model/Hotel_.java b/booking/src/main/java/org/jboss/seam/examples/booking/model/Hotel_.java index 992ee96..7ebd385 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/model/Hotel_.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/model/Hotel_.java @@ -1,21 +1,20 @@ package org.jboss.seam.examples.booking.model; -import java.math.BigDecimal; -import javax.persistence.metamodel.SingularAttribute; -import javax.persistence.metamodel.StaticMetamodel; +import java.math.BigDecimal; +import javax.persistence.metamodel.SingularAttribute; +import javax.persistence.metamodel.StaticMetamodel; @StaticMetamodel(Hotel.class) public abstract class Hotel_ { - public static volatile SingularAttribute id; - public static volatile SingularAttribute zip; - public static volatile SingularAttribute price; - public static volatile SingularAttribute address; - public static volatile SingularAttribute stars; - public static volatile SingularAttribute name; - public static volatile SingularAttribute state; - public static volatile SingularAttribute country; - public static volatile SingularAttribute city; + public static volatile SingularAttribute id; + public static volatile SingularAttribute zip; + public static volatile SingularAttribute price; + public static volatile SingularAttribute address; + public static volatile SingularAttribute stars; + public static volatile SingularAttribute name; + public static volatile SingularAttribute state; + public static volatile SingularAttribute country; + public static volatile SingularAttribute city; } - diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/model/User.java b/booking/src/main/java/org/jboss/seam/examples/booking/model/User.java index 03c682f..fb399c8 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/model/User.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/model/User.java @@ -1,23 +1,18 @@ -/* +/* * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.model; @@ -36,100 +31,85 @@ /** *

- * User is the model/entity class that represents a customer - * who may book a hotel. + * User is the model/entity class that represents a customer who may book a hotel. *

* * @author Gavin King - * @author Dan Allen + * @author Dan Allen */ @Entity @Table(name = "traveler") @Veto -public class User implements Serializable -{ - private static final long serialVersionUID = -602733026033932730L; - private String username; - private String password; - private String name; - private String email; - - public User() - { - } - - public User(final String name, final String username, final String email) - { - this.name = name; - this.username = username; - this.email = email; - } - - public User(final String name, final String username, final String email, final String password) - { - this(name, username, email); - this.password = password; - } - - @NotNull - @Size(min = 1, max = 100) - public String getName() - { - return name; - } - - public void setName(final String name) - { - this.name = name; - } - - @NotNull - @Size(min = 5, max = 15) - public String getPassword() - { - return password; - } - - public void setPassword(final String password) - { - this.password = password; - } - - @Id - @NotNull - @Size(min = 3, max = 15) - @Pattern(regexp = "^\\w*$", message = "not a valid username") - public String getUsername() - { - return username; - } - - public void setUsername(final String username) - { - this.username = username; - } - - @NotNull - @Email - public String getEmail() - { - return email; - } - - public void setEmail(final String email) - { - this.email = email; - } - - @Transient - public String getEmailWithName() - { - return name + " <" + email + ">"; - } - - @Override - public String toString() - { - return "User(" + username + ")"; - } +public class User implements Serializable { + private static final long serialVersionUID = -602733026033932730L; + private String username; + private String password; + private String name; + private String email; + + public User() { + } + + public User(final String name, final String username, final String email) { + this.name = name; + this.username = username; + this.email = email; + } + + public User(final String name, final String username, final String email, final String password) { + this(name, username, email); + this.password = password; + } + + @NotNull + @Size(min = 1, max = 100) + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + @NotNull + @Size(min = 5, max = 15) + public String getPassword() { + return password; + } + + public void setPassword(final String password) { + this.password = password; + } + + @Id + @NotNull + @Size(min = 3, max = 15) + @Pattern(regexp = "^\\w*$", message = "not a valid username") + public String getUsername() { + return username; + } + + public void setUsername(final String username) { + this.username = username; + } + + @NotNull + @Email + public String getEmail() { + return email; + } + + public void setEmail(final String email) { + this.email = email; + } + + @Transient + public String getEmailWithName() { + return name + " <" + email + ">"; + } + + @Override + public String toString() { + return "User(" + username + ")"; + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/model/User_.java b/booking/src/main/java/org/jboss/seam/examples/booking/model/User_.java index 62f47c2..70bf487 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/model/User_.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/model/User_.java @@ -1,15 +1,14 @@ package org.jboss.seam.examples.booking.model; -import javax.persistence.metamodel.SingularAttribute; -import javax.persistence.metamodel.StaticMetamodel; +import javax.persistence.metamodel.SingularAttribute; +import javax.persistence.metamodel.StaticMetamodel; @StaticMetamodel(User.class) public abstract class User_ { - public static volatile SingularAttribute username; - public static volatile SingularAttribute email; - public static volatile SingularAttribute name; - public static volatile SingularAttribute password; + public static volatile SingularAttribute username; + public static volatile SingularAttribute email; + public static volatile SingularAttribute name; + public static volatile SingularAttribute password; } - diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/reference/CalendarReferenceProducer.java b/booking/src/main/java/org/jboss/seam/examples/booking/reference/CalendarReferenceProducer.java index 6c77eb6..9efb61b 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/reference/CalendarReferenceProducer.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/reference/CalendarReferenceProducer.java @@ -1,23 +1,18 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.reference; @@ -33,29 +28,27 @@ import javax.enterprise.inject.Produces; /** - * Produces calendar-oriented reference data to be used in user-interface forms. - * The user's locale is honored when producing name-based data. - * - * @author Dan Allen + * Produces calendar-oriented reference data to be used in user-interface forms. The user's locale is honored when producing + * name-based data. + * + * @author Dan Allen */ public class CalendarReferenceProducer { - @Produces - @Named - @ConversationScoped - public List getMonths(Locale locale) - { - List months = new ArrayList(12); - DateFormat longNameFormat = new SimpleDateFormat("MMMM", locale); - DateFormat shortNameFormat = new SimpleDateFormat("MMM", locale); - Calendar cal = Calendar.getInstance(); - for (int m = 0; m < 12; m++) - { - cal.set(Calendar.MONTH, m); - months.add(new Month(m, longNameFormat.format(cal.getTime()), shortNameFormat.format(cal.getTime()))); - } + @Produces + @Named + @ConversationScoped + public List getMonths(Locale locale) { + List months = new ArrayList(12); + DateFormat longNameFormat = new SimpleDateFormat("MMMM", locale); + DateFormat shortNameFormat = new SimpleDateFormat("MMM", locale); + Calendar cal = Calendar.getInstance(); + for (int m = 0; m < 12; m++) { + cal.set(Calendar.MONTH, m); + months.add(new Month(m, longNameFormat.format(cal.getTime()), shortNameFormat.format(cal.getTime()))); + } - return months; - } + return months; + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/reference/CreditCardExpiryYears.java b/booking/src/main/java/org/jboss/seam/examples/booking/reference/CreditCardExpiryYears.java index e328331..11ac336 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/reference/CreditCardExpiryYears.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/reference/CreditCardExpiryYears.java @@ -1,23 +1,18 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.reference; @@ -34,16 +29,14 @@ import javax.inject.Qualifier; /** - * A binding type attached to a collection of years - * indicating the set is limited to the possible - * values for a credit card expiry date. - * - * @author Dan Allen + * A binding type attached to a collection of years indicating the set is limited to the possible values for a credit card + * expiry date. + * + * @author Dan Allen */ @Target({ TYPE, METHOD, PARAMETER, FIELD }) @Retention(RUNTIME) @Documented @Qualifier -public @interface CreditCardExpiryYears -{ +public @interface CreditCardExpiryYears { } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/reference/CreditCardReferenceProducer.java b/booking/src/main/java/org/jboss/seam/examples/booking/reference/CreditCardReferenceProducer.java index add3e15..5dfda17 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/reference/CreditCardReferenceProducer.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/reference/CreditCardReferenceProducer.java @@ -1,23 +1,18 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.reference; @@ -33,34 +28,29 @@ import org.jboss.seam.examples.booking.model.CreditCardType; /** - * A bean that produces credit card reference data for - * user-interface forms. + * A bean that produces credit card reference data for user-interface forms. * - * @author Dan Allen + * @author Dan Allen */ -public class CreditCardReferenceProducer -{ - @Produces - @Named - @ConversationScoped - public List getCreditCardTypes() - { - return new ArrayList(Arrays.asList(CreditCardType.values())); - } - - @Produces - @Named - @ConversationScoped - @CreditCardExpiryYears - public List getCreditCardExpiryYears() - { - List years = new ArrayList(8); - int currentYear = Calendar.getInstance().get(Calendar.YEAR); - for (int i = 0; i < 8; i++) - { - years.add(currentYear + i); - } +public class CreditCardReferenceProducer { + @Produces + @Named + @ConversationScoped + public List getCreditCardTypes() { + return new ArrayList(Arrays.asList(CreditCardType.values())); + } + + @Produces + @Named + @ConversationScoped + @CreditCardExpiryYears + public List getCreditCardExpiryYears() { + List years = new ArrayList(8); + int currentYear = Calendar.getInstance().get(Calendar.YEAR); + for (int i = 0; i < 8; i++) { + years.add(currentYear + i); + } - return years; - } + return years; + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/reference/Month.java b/booking/src/main/java/org/jboss/seam/examples/booking/reference/Month.java index ea23baf..99f92c2 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/reference/Month.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/reference/Month.java @@ -1,70 +1,58 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.reference; /** - * A simple Java bean representing a month. This - * bean assumes that the names it is provided - * have already been localized. - * - * @author Dan Allen + * A simple Java bean representing a month. This bean assumes that the names it is provided have already been localized. + * + * @author Dan Allen */ public class Month { - private int index; - private String name; - private String shortName; + private int index; + private String name; + private String shortName; - public Month() {} + public Month() { + } - public Month(int index, String name, String shortName) - { - this.index = index; - this.name = name; - this.shortName = shortName; - } + public Month(int index, String name, String shortName) { + this.index = index; + this.name = name; + this.shortName = shortName; + } - public int getIndex() - { - return index; - } + public int getIndex() { + return index; + } - public int getNumber() - { - return index + 1; - } + public int getNumber() { + return index + 1; + } - public String getLongName() - { - return name; - } + public String getLongName() { + return name; + } - public String getShortName() - { - return shortName; - } + public String getShortName() { + return shortName; + } - public String getName() - { - return name; - } + public String getName() { + return name; + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/security/Authenticator.java b/booking/src/main/java/org/jboss/seam/examples/booking/security/Authenticator.java index dc63cd7..50287ce 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/security/Authenticator.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/security/Authenticator.java @@ -1,23 +1,18 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.security; @@ -34,51 +29,46 @@ import org.jboss.seam.international.status.Messages; /** - * This implementation of Authenticator cross references the - * values of the user's credentials against the database. + * This implementation of Authenticator cross references the values of the user's credentials against the + * database. * - * @author Dan Allen + * @author Dan Allen */ @Stateless -public class Authenticator -{ - @Inject - private Logger log; +public class Authenticator { + @Inject + private Logger log; - @PersistenceContext - private EntityManager em; + @PersistenceContext + private EntityManager em; - @Inject - private Credentials credentials; + @Inject + private Credentials credentials; - @Inject - private Messages messages; + @Inject + private Messages messages; - @Inject - @Authenticated - private Event loginEventSrc; + @Inject + @Authenticated + private Event loginEventSrc; - public boolean authenticate() - { - log.info("Logging in " + credentials.getUsername()); - if ((credentials.getUsername() == null) || (credentials.getPassword() == null)) - { - messages.error(new DefaultBundleKey("identity_loginFailed")).defaults("Invalid username or password"); - return false; - } + public boolean authenticate() { + log.info("Logging in " + credentials.getUsername()); + if ((credentials.getUsername() == null) || (credentials.getPassword() == null)) { + messages.error(new DefaultBundleKey("identity_loginFailed")).defaults("Invalid username or password"); + return false; + } - User user = em.find(User.class, credentials.getUsername()); - if ((user != null) && user.getPassword().equals(credentials.getPassword())) - { - loginEventSrc.fire(user); - messages.info(new DefaultBundleKey("identity_loggedIn"), user.getName()).defaults("You're signed in as {0}").params(user.getName()); - return true; - } - else - { - messages.error(new DefaultBundleKey("identity_loginFailed")).defaults("Invalid username or password"); - return false; - } - } + User user = em.find(User.class, credentials.getUsername()); + if ((user != null) && user.getPassword().equals(credentials.getPassword())) { + loginEventSrc.fire(user); + messages.info(new DefaultBundleKey("identity_loggedIn"), user.getName()).defaults("You're signed in as {0}") + .params(user.getName()); + return true; + } else { + messages.error(new DefaultBundleKey("identity_loginFailed")).defaults("Invalid username or password"); + return false; + } + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/security/Credentials.java b/booking/src/main/java/org/jboss/seam/examples/booking/security/Credentials.java index ed2e95c..36443dc 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/security/Credentials.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/security/Credentials.java @@ -1,23 +1,18 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.security; @@ -31,28 +26,23 @@ */ @Named @SessionScoped -public class Credentials implements Serializable -{ - private String username; - private String password; +public class Credentials implements Serializable { + private String username; + private String password; - public String getUsername() - { - return username; - } + public String getUsername() { + return username; + } - public void setUsername(final String username) - { - this.username = username; - } + public void setUsername(final String username) { + this.username = username; + } - public String getPassword() - { - return password; - } + public String getPassword() { + return password; + } - public void setPassword(final String password) - { - this.password = password; - } + public void setPassword(final String password) { + this.password = password; + } } diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/security/Identity.java b/booking/src/main/java/org/jboss/seam/examples/booking/security/Identity.java index 33fe50d..ce5f80d 100644 --- a/booking/src/main/java/org/jboss/seam/examples/booking/security/Identity.java +++ b/booking/src/main/java/org/jboss/seam/examples/booking/security/Identity.java @@ -1,23 +1,18 @@ -/* +/* * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors + * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jboss.seam.examples.booking.security; @@ -34,46 +29,40 @@ */ @Named @SessionScoped -public class Identity implements Serializable -{ - private static final long serialVersionUID = 4488275906698680752L; +public class Identity implements Serializable { + private static final long serialVersionUID = 4488275906698680752L; - private boolean loggedIn; + private boolean loggedIn; - @Inject - private ExternalContext externalContext; + @Inject + private ExternalContext externalContext; - @Inject - private Authenticator authenticator; + @Inject + private Authenticator authenticator; - @Inject - private Credentials credentials; + @Inject + private Credentials credentials; - public String getUsername() - { - return credentials.getUsername(); - } + public String getUsername() { + return credentials.getUsername(); + } - public boolean isLoggedIn() - { - return loggedIn; - } + public boolean isLoggedIn() { + return loggedIn; + } - public void login() - { - if (authenticator.authenticate()) - { - loggedIn = true; - credentials.setPassword(null); - } - } + public void login() { + if (authenticator.authenticate()) { + loggedIn = true; + credentials.setPassword(null); + } + } - public String logout() - { - loggedIn = false; - HttpSession session = (HttpSession) externalContext.getSession(true); - session.invalidate(); - return "home?faces-redirect=true"; - } + public String logout() { + loggedIn = false; + HttpSession session = (HttpSession) externalContext.getSession(true); + session.invalidate(); + return "home?faces-redirect=true"; + } } diff --git a/booking/src/main/resources-jbossas/booking-ds.xml b/booking/src/main/resources-jbossas/booking-ds.xml index ceb5d0c..efc910b 100644 --- a/booking/src/main/resources-jbossas/booking-ds.xml +++ b/booking/src/main/resources-jbossas/booking-ds.xml @@ -1,16 +1,16 @@ + PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN" + "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd"> - - jdbc/__default - false - jdbc:hsqldb:. - org.hsqldb.jdbcDriver - sa - - 5 - 20 - + + jdbc/__default + false + jdbc:hsqldb:. + org.hsqldb.jdbcDriver + sa + + 5 + 20 + diff --git a/booking/src/main/resources/META-INF/persistence.xml b/booking/src/main/resources/META-INF/persistence.xml index fa0f74f..52cafbc 100644 --- a/booking/src/main/resources/META-INF/persistence.xml +++ b/booking/src/main/resources/META-INF/persistence.xml @@ -1,33 +1,33 @@ - - - jdbc/__default - org.jboss.seam.examples.booking.model.User - org.jboss.seam.examples.booking.model.Hotel - org.jboss.seam.examples.booking.model.Booking - - - - - - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" + version="2.0"> + + + jdbc/__default + org.jboss.seam.examples.booking.model.User + org.jboss.seam.examples.booking.model.Hotel + org.jboss.seam.examples.booking.model.Booking + + + + + + + + + - - - - - + + + + + diff --git a/booking/src/main/resources/META-INF/seam-beans.xml b/booking/src/main/resources/META-INF/seam-beans.xml index 46a002a..c4dd4ba 100644 --- a/booking/src/main/resources/META-INF/seam-beans.xml +++ b/booking/src/main/resources/META-INF/seam-beans.xml @@ -16,15 +16,15 @@ limitations under the License. --> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:s="urn:java:seam:core" + xmlns:i18n="urn:java:org.jboss.seam.international.locale" + xsi:schemaLocation=" + http://java.sun.com/xml/ns/javaee + http://docs.jboss.org/cdi/beans_1_0.xsd"> - - - - + + + + diff --git a/booking/src/main/webapp/WEB-INF/beans.xml b/booking/src/main/webapp/WEB-INF/beans.xml index 351d504..f57c876 100644 --- a/booking/src/main/webapp/WEB-INF/beans.xml +++ b/booking/src/main/webapp/WEB-INF/beans.xml @@ -1,13 +1,13 @@ - - org.jboss.seam.faces.context.conversation.ConversationBoundaryInterceptor - - - org.jboss.seam.examples.booking.bootstrap.ApplicationInitializer - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://java.sun.com/xml/ns/javaee + http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> + + org.jboss.seam.faces.context.conversation.ConversationBoundaryInterceptor + + + org.jboss.seam.examples.booking.bootstrap.ApplicationInitializer + diff --git a/booking/src/main/webapp/WEB-INF/faces-config.xml b/booking/src/main/webapp/WEB-INF/faces-config.xml index 7ebd4f8..b8a1237 100644 --- a/booking/src/main/webapp/WEB-INF/faces-config.xml +++ b/booking/src/main/webapp/WEB-INF/faces-config.xml @@ -1,151 +1,150 @@ - - seam_booking - - - - confirmPassword - org.jboss.seam.examples.booking.account.ConfirmPasswordValidator - - - - currentPassword - org.jboss.seam.examples.booking.account.CurrentPasswordValidator - - - - reservationDateRange - org.jboss.seam.examples.booking.booking.ReservationDateRangeValidator - - - - * - - - #{identity.logout} - #{true} - /home.xhtml - - - - - #{bookingAgent.cancel} - #{true} - /search.xhtml - - - - - - - /home.xhtml - - - #{identity.login} - #{identity.loggedIn} - /search.xhtml - - - - - - - /search.xhtml - - - - - - #{bookingAgent.selectHotel(_hotel)} - #{bookingAgent.hotelSelection != null} - /hotel.xhtml - - - - - - - /hotel.xhtml - - - #{bookingAgent.bookHotel} - #{bookingAgent.booking != null} - /book.xhtml - - - - - - - /book.xhtml - - - #{bookingAgent.validate} - #{bookingAgent.bookingValid} - /confirm.xhtml - - - - - - - /confirm.xhtml - - - #{bookingAgent.confirm} - #{true} - /search.xhtml - - - - - - - /register.xhtml - - - #{registrar.register} - #{registrar.registered} - /home.xhtml - - - - - - - /password.xhtml - - - #{passwordManager.changePassword} - #{passwordManager.changed} - /account.xhtml - - - - - - - - - messages - messages - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" + version="2.0"> + + SeamBooking + + + + confirmPassword + org.jboss.seam.examples.booking.account.ConfirmPasswordValidator + + + + currentPassword + org.jboss.seam.examples.booking.account.CurrentPasswordValidator + + + + reservationDateRange + org.jboss.seam.examples.booking.booking.ReservationDateRangeValidator + + + + * + + + #{identity.logout} + #{true} + /home.xhtml + + + + + #{bookingAgent.cancel} + #{true} + /search.xhtml + + + + + + + /home.xhtml + + + #{identity.login} + #{identity.loggedIn} + /search.xhtml + + + + + + + /search.xhtml + + + + + + #{bookingAgent.selectHotel(_hotel)} + #{bookingAgent.hotelSelection != null} + /hotel.xhtml + + + + + + + /hotel.xhtml + + + #{bookingAgent.bookHotel} + #{bookingAgent.booking != null} + /book.xhtml + + + + + + + /book.xhtml + + + #{bookingAgent.validate} + #{bookingAgent.bookingValid} + /confirm.xhtml + + + + + + + /confirm.xhtml + + + #{bookingAgent.confirm} + #{true} + /search.xhtml + + + + + + + /register.xhtml + + + #{registrar.register} + #{registrar.registered} + /home.xhtml + + + + + + + /password.xhtml + + + #{passwordManager.changePassword} + #{passwordManager.changed} + /account.xhtml + + + + + + + + messages + messages + + diff --git a/booking/src/main/webapp/WEB-INF/layout/template.xhtml b/booking/src/main/webapp/WEB-INF/layout/template.xhtml index aec2520..b3aa6c1 100644 --- a/booking/src/main/webapp/WEB-INF/layout/template.xhtml +++ b/booking/src/main/webapp/WEB-INF/layout/template.xhtml @@ -27,7 +27,7 @@ #{' | '} - #{bundles.messages.template_linkLogin} + #{bundles.messages.template_linkLogin} #{' | '} diff --git a/booking/src/main/webapp/WEB-INF/pretty-config.xml b/booking/src/main/webapp/WEB-INF/pretty-config.xml index 501dba3..3b28dcb 100644 --- a/booking/src/main/webapp/WEB-INF/pretty-config.xml +++ b/booking/src/main/webapp/WEB-INF/pretty-config.xml @@ -1,53 +1,54 @@ - - - - /home.xhtml - - - - - /home.xhtml - #{identity.logout} - - - - - /search.xhtml - - - - - /hotel.xhtml - - - - - /book.xhtml - - - - - /confirm.xhtml - - - - - /register.xhtml - - - - - /account.xhtml - - - - - /password.xhtml - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://ocpsoft.com/prettyfaces/2.0.4 + http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-2.0.4.xsd"> + + + + /home.xhtml + + + + + /home.xhtml + #{identity.logout} + + + + + /search.xhtml + + + + + /hotel.xhtml + + + + + /book.xhtml + + + + + /confirm.xhtml + + + + + /register.xhtml + + + + + /account.xhtml + + + + + /password.xhtml + diff --git a/booking/src/main/webapp/WEB-INF/web.xml b/booking/src/main/webapp/WEB-INF/web.xml index 0817f99..7f1c118 100644 --- a/booking/src/main/webapp/WEB-INF/web.xml +++ b/booking/src/main/webapp/WEB-INF/web.xml @@ -1,51 +1,51 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" + version="3.0"> - Seam Booking Example (Java EE Environment) + Seam Booking Example (Java EE Environment) - - - javax.faces.PROJECT_STAGE - Development - + + + javax.faces.PROJECT_STAGE + Development + - - 10 - + + 10 + - - Faces Servlet - javax.faces.webapp.FacesServlet - 1 - - - + Faces Servlet - *.xhtml - + javax.faces.webapp.FacesServlet + 1 + + + + Faces Servlet + *.xhtml + - - + - + + 500 + /error.xhtml + + --> + diff --git a/booking/src/main/webapp/book.xhtml b/booking/src/main/webapp/book.xhtml index bd723e5..9ae6f53 100644 --- a/booking/src/main/webapp/book.xhtml +++ b/booking/src/main/webapp/book.xhtml @@ -50,16 +50,16 @@ - + - - + + - - - + + + @@ -72,7 +72,7 @@ - +
#{' '} @@ -82,8 +82,8 @@
diff --git a/booking/src/main/webapp/home.xhtml b/booking/src/main/webapp/home.xhtml index b7d3e1b..6bf03eb 100644 --- a/booking/src/main/webapp/home.xhtml +++ b/booking/src/main/webapp/home.xhtml @@ -47,8 +47,8 @@ - - + +
diff --git a/booking/src/main/webapp/hotel.xhtml b/booking/src/main/webapp/hotel.xhtml index 7526754..6693230 100644 --- a/booking/src/main/webapp/hotel.xhtml +++ b/booking/src/main/webapp/hotel.xhtml @@ -40,7 +40,7 @@ -
+

Don't kill your database

Keeping conversational state in memory in the middle tier is a great diff --git a/booking/src/main/webapp/password.xhtml b/booking/src/main/webapp/password.xhtml index a979fd4..090ea04 100644 --- a/booking/src/main/webapp/password.xhtml +++ b/booking/src/main/webapp/password.xhtml @@ -26,7 +26,7 @@ - + @@ -46,14 +46,14 @@ + fields="newPassword=new:input confirmPassword=confirm:input"/>

-
+

Simple things should be easy

(And so should some complex things.) You shouldn't have to write four different classes just to change a @@ -63,7 +63,7 @@ delivering new functionality quicker. Productivity matters. But with Seam, JSF, EJB 3.0 and jBPM, you don't need to sacrifice the ability to handle complex problems just to achieve great productivity.

-
+
diff --git a/booking/src/main/webapp/register.xhtml b/booking/src/main/webapp/register.xhtml index 1c14d21..f6bdc1c 100644 --- a/booking/src/main/webapp/register.xhtml +++ b/booking/src/main/webapp/register.xhtml @@ -47,8 +47,8 @@ - - + + @@ -59,7 +59,7 @@ render="confirmPassword :registrationForm:password"/> - + + + + + + + diff --git a/booking/src/test/resources-glassfish-embedded/test-persistence.xml b/booking/src/test/resources-glassfish-embedded/test-persistence.xml index b8ba02f..85b6bf7 100644 --- a/booking/src/test/resources-glassfish-embedded/test-persistence.xml +++ b/booking/src/test/resources-glassfish-embedded/test-persistence.xml @@ -1,19 +1,19 @@ - - - jdbc/arquillian - org.jboss.seam.examples.booking.model.User - org.jboss.seam.examples.booking.model.Hotel - org.jboss.seam.examples.booking.model.Booking - - - - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" + version="2.0"> + + + jdbc/arquillian + org.jboss.seam.examples.booking.model.User + org.jboss.seam.examples.booking.model.Hotel + org.jboss.seam.examples.booking.model.Booking + + + + + + + diff --git a/booking/src/test/resources-jbossas/test-persistence.xml b/booking/src/test/resources-jbossas/test-persistence.xml index 8fa850a..8d8e001 100644 --- a/booking/src/test/resources-jbossas/test-persistence.xml +++ b/booking/src/test/resources-jbossas/test-persistence.xml @@ -1,16 +1,16 @@ - - java:/DefaultDS - - - - - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" + version="2.0"> + + java:/DefaultDS + + + + + + + +