├── AcmePools ├── README.md ├── pom.xml ├── sql │ ├── create_database-no-netbeans.sql │ └── create_database.sql └── src │ └── main │ ├── java │ └── com │ │ └── acme │ │ └── acmepools │ │ ├── bean │ │ ├── ColumnBean.java │ │ ├── Owner.java │ │ ├── PickListBean.java │ │ └── UserBean.java │ │ ├── converter │ │ ├── CreditLimitConverter.java │ │ ├── DiscountCodeConverter.java │ │ ├── LocalDatePersistenceConverter.java │ │ ├── LocalToZonedConverter.java │ │ └── ZipCodeConverter.java │ │ ├── entity │ │ ├── ColumnModel.java │ │ ├── Customer.java │ │ ├── DiscountCode.java │ │ ├── Job.java │ │ ├── MicroMarket.java │ │ ├── Pool.java │ │ ├── PoolCustomer.java │ │ └── util │ │ │ └── JsfUtil.java │ │ ├── event │ │ └── JobEvent.java │ │ ├── jsf │ │ ├── ColumnModelController.java │ │ ├── ConfigurationBean.java │ │ ├── CustomerController.java │ │ ├── DiscountCodeController.java │ │ ├── JobController.java │ │ ├── MicroMarketController.java │ │ ├── PoolController.java │ │ └── PoolCustomerController.java │ │ ├── rest │ │ ├── ApplicationConfig.java │ │ └── SSEResource.java │ │ ├── servlet │ │ ├── DukeServlet.java │ │ └── SSETestServlet.java │ │ ├── session │ │ ├── AbstractFacade.java │ │ ├── ColumnModelFacade.java │ │ ├── CustomerFacade.java │ │ ├── DiscountCodeFacade.java │ │ ├── JobFacade.java │ │ ├── MicroMarketFacade.java │ │ ├── PoolCustomerFacade.java │ │ └── PoolFacade.java │ │ └── utility │ │ └── CreditLimitEncryptor.java │ ├── resources │ ├── Bundle.properties │ ├── META-INF │ │ └── persistence.xml │ └── log4j2.xml │ └── webapp │ ├── WEB-INF │ ├── beans.xml │ ├── faces-config.xml │ └── web.xml │ ├── customer │ ├── Create.xhtml │ ├── Edit.xhtml │ ├── List.xhtml │ └── View.xhtml │ ├── customersJson.xhtml │ ├── index.html │ ├── index.xhtml │ ├── job │ ├── Create.xhtml │ ├── Edit.xhtml │ ├── JobsByShape.xhtml │ ├── List.xhtml │ └── View.xhtml │ ├── pool │ ├── Create.xhtml │ ├── Edit.xhtml │ ├── List.xhtml │ └── View.xhtml │ ├── poolCustomer │ ├── Create.xhtml │ ├── CustomerExport.xhtml │ ├── Edit.xhtml │ ├── List.xhtml │ └── View.xhtml │ ├── resources │ ├── css │ │ └── jsfcrud.css │ ├── images │ │ ├── dukewaving.gif │ │ └── excel.png │ └── js │ │ └── jsfcrud.js │ └── template.xhtml ├── LICENSE ├── README.md └── environment-aware-configuration ├── .gitignore ├── README.md ├── buildAndRun.sh ├── docker ├── Dockerfile ├── dev_env_properties ├── local_env_properties ├── prod_env_properties └── stage_env_properties ├── pom.xml └── src └── main ├── java └── br │ └── com │ └── fmoraes │ └── environmentawareconfiguration │ ├── JAXRSConfiguration.java │ ├── model │ └── Person.java │ └── resources │ └── PersonResource.java ├── resources ├── META-INF │ └── persistence.xml └── liquibase │ ├── changelog │ └── db.changelog-master.xml │ ├── liquibase-dev.properties │ ├── liquibase-local.properties │ ├── liquibase-prod.properties │ └── liquibase-stage.properties └── webapp └── WEB-INF ├── beans.xml └── web.xml /AcmePools/README.md: -------------------------------------------------------------------------------- 1 | # JavaEE8-Playground 2 | Test project for playing with Java EE 8 APIs. Includes support for all Java EE 8 specifications, utilizing the official Java EE 8 maven coordinates. 3 | 4 | This project has been tested and verified to work on Payara-5 branch. 5 | 6 | I will update the project occasionally to add new demos. Stay tuned. Please send feedback to my twitter handle at @javajuneau. 7 | 8 | Thanks 9 | -------------------------------------------------------------------------------- /AcmePools/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.javaee8recipes 6 | AcmePools 7 | 2.0 8 | war 9 | 10 | AcmePools 11 | 12 | 13 | ${project.build.directory}/endorsed 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.primefaces 21 | primefaces 22 | 6.0 23 | 24 | 25 | 26 | javax 27 | javaee-api 28 | 8.0 29 | provided 30 | 31 | 32 | 33 | 34 | org.projectlombok 35 | lombok 36 | 1.16.8 37 | 38 | 39 | 40 | 41 | org.apache.poi 42 | poi 43 | 3.15 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-compiler-plugin 53 | 3.1 54 | 55 | 1.8 56 | 1.8 57 | 58 | ${endorsed.dir} 59 | 60 | 61 | 62 | 63 | org.apache.maven.plugins 64 | maven-war-plugin 65 | 2.3 66 | 67 | false 68 | 69 | 70 | 71 | org.apache.maven.plugins 72 | maven-dependency-plugin 73 | 2.6 74 | 75 | 76 | validate 77 | 78 | copy 79 | 80 | 81 | ${endorsed.dir} 82 | true 83 | 84 | 85 | javax 86 | javaee-endorsed-api 87 | 7.0 88 | jar 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /AcmePools/sql/create_database.sql: -------------------------------------------------------------------------------- 1 | -- ***************************************************** 2 | -- * Simple database model for AcmePools application. 3 | -- * 4 | -- * Author: J. Juneau 5 | -- * Description: Ready for summer! Run this SQL in 6 | -- * your favorite Apache derby schema 7 | -- ***************************************************** 8 | 9 | create table pool_customer( 10 | id int primary key, 11 | pool_id int, 12 | customer_id int); 13 | 14 | 15 | create table job ( 16 | id int primary key, 17 | customer_id int, 18 | description clob, 19 | est_hours float, 20 | cost numeric, 21 | work_date date); 22 | 23 | 24 | create table pool ( 25 | id int primary key, 26 | style varchar(10), 27 | shape varchar(10), 28 | length float, 29 | width float, 30 | radius float, 31 | gallons float); 32 | 33 | 34 | -- Add support for data export 35 | create table column_model( 36 | id int primary key, 37 | column_name varchar(30), 38 | column_label varchar(150)); 39 | 40 | 41 | insert into column_model values( 42 | 1, 43 | 'addressline1', 44 | 'Address Line 1'); 45 | 46 | insert into column_model values( 47 | 2, 48 | 'addressline2', 49 | 'Address Line 2'); 50 | 51 | insert into column_model values( 52 | 3, 53 | 'city', 54 | 'City'); 55 | 56 | insert into column_model values( 57 | 4, 58 | 'creditLimit', 59 | 'Credit Limit'); 60 | 61 | insert into column_model values( 62 | 5, 63 | 'customerId', 64 | 'Customer Id'); 65 | 66 | insert into column_model values( 67 | 6, 68 | 'discountCode', 69 | 'Discount Code'); 70 | 71 | insert into column_model values( 72 | 7, 73 | 'email', 74 | 'Email'); 75 | 76 | insert into column_model values( 77 | 8, 78 | 'fax', 79 | 'Fax'); 80 | 81 | insert into column_model values( 82 | 9, 83 | 'name', 84 | 'Name'); 85 | 86 | insert into column_model values( 87 | 10, 88 | 'phone', 89 | 'Phone'); 90 | 91 | insert into column_model values( 92 | 11, 93 | 'state', 94 | 'State'); 95 | 96 | insert into column_model values( 97 | 12, 98 | 'zip', 99 | 'Zip'); 100 | 101 | alter table pool_customer 102 | add constraint pool_customer_fk 103 | foreign key (pool_id) references pool(id); 104 | 105 | alter table pool_customer 106 | add constraint pool_customer_fk2 107 | foreign key (customer_id) references customer(customer_id); 108 | 109 | alter table job 110 | add constraint job_fk 111 | foreign key (customer_id) references pool_customer(id); 112 | 113 | insert into pool values( 114 | 1, 115 | 'ABOVE', 116 | 'ROUND', 117 | 0, 118 | 0, 119 | 24, 120 | 61072.56); 121 | 122 | insert into pool values( 123 | 2, 124 | 'INGROUND', 125 | 'ROUND', 126 | 32, 127 | 16, 128 | 0, 129 | 23040); 130 | 131 | insert into pool_customer values( 132 | 1, 133 | 1, 134 | 1); 135 | 136 | insert into pool_customer values( 137 | 2, 138 | 2, 139 | 2); 140 | 141 | -- Uncomment the following to create database sequences if using Apache Derby 10.6+ 142 | -- create sequence pool_cust_s 143 | -- start with 100; 144 | -- 145 | -- create sequence job_s 146 | -- start with 100; 147 | -- 148 | -- 149 | -- create sequence pool_s 150 | -- start with 100; 151 | -- 152 | -- create sequence column_model_s 153 | -- start with 100; 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/bean/ColumnBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.acme.acmepools.bean; 7 | 8 | import java.math.BigDecimal; 9 | import javax.validation.constraints.NotNull; 10 | 11 | 12 | /** 13 | * 14 | * @author juneau 15 | */ 16 | 17 | public class ColumnBean { 18 | 19 | private BigDecimal id; 20 | private String columnName; 21 | private String columnLabel; 22 | 23 | public ColumnBean(BigDecimal id, 24 | String columnName, 25 | String columnLabel){ 26 | this.id = id; 27 | this.columnName = columnName; 28 | this.columnLabel = columnLabel; 29 | } 30 | 31 | 32 | /** 33 | * @return the id 34 | */ 35 | public BigDecimal getId() { 36 | return id; 37 | } 38 | 39 | /** 40 | * @param id the id to set 41 | */ 42 | public void setId(BigDecimal id) { 43 | this.id = id; 44 | } 45 | 46 | /** 47 | * @return the columnName 48 | */ 49 | public String getColumnName() { 50 | return columnName; 51 | } 52 | 53 | /** 54 | * @param columnName the columnName to set 55 | */ 56 | public void setColumnName(String columnName) { 57 | this.columnName = columnName; 58 | } 59 | 60 | /** 61 | * @return the columnLabel 62 | */ 63 | public String getColumnLabel() { 64 | return columnLabel; 65 | } 66 | 67 | /** 68 | * @param columnLabel the columnLabel to set 69 | */ 70 | public void setColumnLabel(String columnLabel) { 71 | this.columnLabel = columnLabel; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/bean/Owner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.bean; 7 | 8 | import java.util.Collection; 9 | import java.util.List; 10 | 11 | /** 12 | * 13 | * @author Juneau 14 | */ 15 | 16 | public class Owner { 17 | 18 | private String firstName; 19 | private String lastName; 20 | private String address1; 21 | private String address2; 22 | private String city; 23 | private String state; 24 | private String zip; 25 | private Collection phoneNumbers; 26 | /** 27 | * @return the firstName 28 | */ 29 | public String getFirstName() { 30 | return firstName; 31 | } 32 | 33 | /** 34 | * @param firstName the firstName to set 35 | */ 36 | public void setFirstName(String firstName) { 37 | this.firstName = firstName; 38 | } 39 | 40 | /** 41 | * @return the lastName 42 | */ 43 | public String getLastName() { 44 | return lastName; 45 | } 46 | 47 | /** 48 | * @param lastName the lastName to set 49 | */ 50 | public void setLastName(String lastName) { 51 | this.lastName = lastName; 52 | } 53 | 54 | /** 55 | * @return the address1 56 | */ 57 | public String getAddress1() { 58 | return address1; 59 | } 60 | 61 | /** 62 | * @param address1 the address1 to set 63 | */ 64 | public void setAddress1(String address1) { 65 | this.address1 = address1; 66 | } 67 | 68 | /** 69 | * @return the address2 70 | */ 71 | public String getAddress2() { 72 | return address2; 73 | } 74 | 75 | /** 76 | * @param address2 the address2 to set 77 | */ 78 | public void setAddress2(String address2) { 79 | this.address2 = address2; 80 | } 81 | 82 | /** 83 | * @return the city 84 | */ 85 | public String getCity() { 86 | return city; 87 | } 88 | 89 | /** 90 | * @param city the city to set 91 | */ 92 | public void setCity(String city) { 93 | this.city = city; 94 | } 95 | 96 | /** 97 | * @return the state 98 | */ 99 | public String getState() { 100 | return state; 101 | } 102 | 103 | /** 104 | * @param state the state to set 105 | */ 106 | public void setState(String state) { 107 | this.state = state; 108 | } 109 | 110 | /** 111 | * @return the zip 112 | */ 113 | public String getZip() { 114 | return zip; 115 | } 116 | 117 | /** 118 | * @param zip the zip to set 119 | */ 120 | public void setZip(String zip) { 121 | this.zip = zip; 122 | } 123 | 124 | /** 125 | * @return the phoneNumbers 126 | */ 127 | public Collection getPhoneNumbers() { 128 | return phoneNumbers; 129 | } 130 | 131 | /** 132 | * @param phoneNumbers the phoneNumbers to set 133 | */ 134 | public void setPhoneNumbers(Collection phoneNumbers) { 135 | this.phoneNumbers = phoneNumbers; 136 | } 137 | 138 | 139 | } 140 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/bean/PickListBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package com.acme.acmepools.bean; 6 | 7 | /** 8 | * 9 | * @author juneau 10 | */ 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | import com.acme.acmepools.entity.ColumnModel; 15 | 16 | import org.primefaces.model.DualListModel; 17 | 18 | public class PickListBean { 19 | 20 | private DualListModel columns; 21 | 22 | private List source = null; 23 | private List target = null; 24 | 25 | 26 | public PickListBean(List columnModelList) { 27 | //Columns 28 | source = new ArrayList(); 29 | target = new ArrayList(); 30 | 31 | for(ColumnModel column:columnModelList){ 32 | System.out.println(column.getColumnLabel()); 33 | ColumnBean bean = new ColumnBean(column.getId(), column.getColumnName(), column.getColumnLabel()); 34 | source.add(bean); 35 | } 36 | 37 | 38 | columns = new DualListModel(source, target); 39 | 40 | } 41 | 42 | /** 43 | * @return the columns 44 | */ 45 | public DualListModel getColumns() { 46 | return columns; 47 | } 48 | 49 | /** 50 | * @param columns the columns to set 51 | */ 52 | public void setColumns(DualListModel columns) { 53 | this.columns = columns; 54 | } 55 | 56 | 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/bean/UserBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Rudy De Busscher (www.c4j.be) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.acme.acmepools.bean; 18 | 19 | import java.io.Serializable; 20 | import java.security.Principal; 21 | import javax.annotation.PostConstruct; 22 | import javax.enterprise.context.RequestScoped; 23 | import javax.faces.context.FacesContext; 24 | import javax.inject.Inject; 25 | import javax.inject.Named; 26 | import javax.servlet.http.HttpServletRequest; 27 | 28 | /** 29 | * 30 | */ 31 | @RequestScoped 32 | @Named 33 | public class UserBean implements Serializable { 34 | 35 | @Inject 36 | private Principal principal; 37 | 38 | private String userName; 39 | 40 | @PostConstruct 41 | public void init() { 42 | HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); 43 | if (request.getUserPrincipal() != null) { 44 | userName = request.getUserPrincipal().getName(); 45 | } 46 | } 47 | 48 | public String getUserName() { 49 | return userName; 50 | } 51 | 52 | public String getPrincipalName() { 53 | return principal.getName(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/converter/CreditLimitConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.converter; 7 | 8 | import com.acme.acmepools.utility.CreditLimitEncryptor; 9 | import java.math.BigDecimal; 10 | import java.time.Instant; 11 | import java.time.LocalDateTime; 12 | import java.time.LocalTime; 13 | import java.time.ZoneId; 14 | import java.util.Date; 15 | import javax.inject.Inject; 16 | import javax.persistence.AttributeConverter; 17 | import javax.persistence.Converter; 18 | 19 | /** 20 | * 21 | * @author Juneau 22 | */ 23 | @Converter 24 | public class CreditLimitConverter implements AttributeConverter { 25 | 26 | @Inject 27 | CreditLimitEncryptor encryptor; 28 | 29 | @Override 30 | public BigDecimal convertToDatabaseColumn(BigDecimal entityValue) { 31 | String encryptedFormat = encryptor.base64encode(entityValue.toString()); 32 | return BigDecimal.valueOf(Long.valueOf(encryptedFormat)); 33 | } 34 | 35 | @Override 36 | public BigDecimal convertToEntityAttribute(BigDecimal databaseValue) { 37 | String decryptedFormat = encryptor.base64decode(databaseValue.toString()); 38 | return BigDecimal.valueOf(Long.valueOf(decryptedFormat)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/converter/DiscountCodeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.converter; 7 | 8 | import com.acme.acmepools.entity.DiscountCode; 9 | import com.acme.acmepools.jsf.DiscountCodeController; 10 | import javax.enterprise.context.ApplicationScoped; 11 | import javax.faces.component.UIComponent; 12 | import javax.faces.context.FacesContext; 13 | import javax.faces.convert.Converter; 14 | import javax.inject.Inject; 15 | import javax.inject.Named; 16 | 17 | @Named 18 | @ApplicationScoped 19 | public class DiscountCodeConverter implements Converter 20 | { 21 | @Inject 22 | DiscountCodeController discountCodeController; 23 | 24 | @Override 25 | public DiscountCode getAsObject(FacesContext context, UIComponent component, String value) 26 | { 27 | System.out.println(value); 28 | DiscountCode dc = null; 29 | try { 30 | dc = discountCodeController.obtainByCode(value); 31 | } catch (NullPointerException ex){ 32 | System.out.println(ex); 33 | } 34 | 35 | return dc; 36 | } 37 | 38 | @Override 39 | public String getAsString(FacesContext context, UIComponent component, Object value) 40 | { 41 | return value.toString(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/converter/LocalDatePersistenceConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.converter; 7 | 8 | import java.time.Instant; 9 | import java.time.LocalDate; 10 | import java.time.LocalDateTime; 11 | import java.time.LocalTime; 12 | import java.time.ZoneId; 13 | import java.util.Date; 14 | import javax.persistence.AttributeConverter; 15 | import javax.persistence.Converter; 16 | 17 | /** 18 | * 19 | * @author Juneau 20 | */ 21 | // Uncomment if using JPA 2.1- 22 | //@Converter(autoApply = true) 23 | public class LocalDatePersistenceConverter implements AttributeConverter { 24 | @Override 25 | public Date convertToDatabaseColumn(LocalDate entityValue) { 26 | LocalTime time = LocalTime.now(); 27 | Instant instant = time.atDate(entityValue).atZone(ZoneId.systemDefault()).toInstant(); 28 | return Date.from(instant); 29 | } 30 | 31 | @Override 32 | public LocalDate convertToEntityAttribute(Date databaseValue) { 33 | Instant instant = Instant.ofEpochMilli(databaseValue.getTime()); 34 | return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/converter/LocalToZonedConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.converter; 7 | 8 | import java.time.Instant; 9 | import java.time.LocalDate; 10 | import java.time.LocalDateTime; 11 | import java.time.LocalTime; 12 | import java.time.ZoneId; 13 | import java.time.ZonedDateTime; 14 | import java.util.Date; 15 | import javax.persistence.AttributeConverter; 16 | import javax.persistence.Converter; 17 | 18 | /** 19 | * 20 | * @author Juneau 21 | */ 22 | @Converter 23 | public class LocalToZonedConverter implements AttributeConverter { 24 | @Override 25 | public LocalDateTime convertToDatabaseColumn(ZonedDateTime entityValue) { 26 | return entityValue.toLocalDateTime(); 27 | } 28 | 29 | @Override 30 | public ZonedDateTime convertToEntityAttribute(LocalDateTime databaseValue) { 31 | return ZonedDateTime.of(databaseValue, ZoneId.systemDefault()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/converter/ZipCodeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.converter; 7 | 8 | import com.acme.acmepools.entity.DiscountCode; 9 | import com.acme.acmepools.entity.MicroMarket; 10 | import com.acme.acmepools.jsf.MicroMarketController; 11 | import javax.enterprise.context.ApplicationScoped; 12 | import javax.faces.component.UIComponent; 13 | import javax.faces.context.FacesContext; 14 | import javax.faces.convert.Converter; 15 | import javax.inject.Inject; 16 | import javax.inject.Named; 17 | 18 | @Named 19 | @ApplicationScoped 20 | public class ZipCodeConverter implements Converter 21 | { 22 | @Inject 23 | MicroMarketController microMarketController; 24 | 25 | @Override 26 | public MicroMarket getAsObject(FacesContext context, UIComponent component, String value) 27 | { 28 | System.out.println(value); 29 | MicroMarket mm = null; 30 | try { 31 | mm = microMarketController.obtainByZipCode(value); 32 | } catch (NullPointerException ex){ 33 | System.out.println(ex); 34 | } 35 | 36 | return mm; 37 | } 38 | 39 | @Override 40 | public String getAsString(FacesContext context, UIComponent component, Object value) 41 | { 42 | return value.toString(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/entity/ColumnModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.entity; 7 | 8 | import java.io.Serializable; 9 | import java.math.BigDecimal; 10 | import javax.persistence.Basic; 11 | import javax.persistence.Column; 12 | import javax.persistence.Entity; 13 | import javax.persistence.Id; 14 | import javax.persistence.NamedQuery; 15 | import javax.persistence.Table; 16 | import javax.validation.constraints.NotNull; 17 | import javax.validation.constraints.Size; 18 | import javax.xml.bind.annotation.XmlRootElement; 19 | 20 | /** 21 | * 22 | * @author Juneau 23 | */ 24 | @Entity 25 | @Table(name = "COLUMN_MODEL") 26 | @XmlRootElement 27 | 28 | @NamedQuery(name = "ColumnModel.findAll", query = "SELECT c FROM ColumnModel c") 29 | @NamedQuery(name = "ColumnModel.findById", query = "SELECT c FROM ColumnModel c WHERE c.id = :id") 30 | @NamedQuery(name = "ColumnModel.findByColumnName", query = "SELECT c FROM ColumnModel c WHERE c.columnName = :columnName") 31 | @NamedQuery(name = "ColumnModel.findByColumnLabel", query = "SELECT c FROM ColumnModel c WHERE c.columnLabel = :columnLabel") 32 | public class ColumnModel implements Serializable { 33 | 34 | private static final long serialVersionUID = 1L; 35 | @Id 36 | // Uncomment if using Apache Derby 10.6+ 37 | // @GeneratedValue(strategy=GenerationType.SEQUENCE, 38 | // generator="column_model_s_generator") 39 | // @SequenceGenerator(name="column_model_s_generator",sequenceName="column_model_s", allocationSize=1) 40 | @Basic(optional = false) 41 | @Column(name = "ID") 42 | private BigDecimal id; 43 | @Size(max = 30) 44 | @Column(name = "COLUMN_NAME") 45 | private String columnName; 46 | @Size(max = 150) 47 | @Column(name = "COLUMN_LABEL") 48 | private String columnLabel; 49 | 50 | public ColumnModel() { 51 | 52 | } 53 | 54 | /** 55 | * @return the id 56 | */ 57 | public BigDecimal getId() { 58 | return id; 59 | } 60 | 61 | /** 62 | * @param id the id to set 63 | */ 64 | public void setId(BigDecimal id) { 65 | this.id = id; 66 | } 67 | 68 | /** 69 | * @return the columnName 70 | */ 71 | public String getColumnName() { 72 | return columnName; 73 | } 74 | 75 | /** 76 | * @param columnName the columnName to set 77 | */ 78 | public void setColumnName(String columnName) { 79 | this.columnName = columnName; 80 | } 81 | 82 | /** 83 | * @return the columnLabel 84 | */ 85 | public String getColumnLabel() { 86 | return columnLabel; 87 | } 88 | 89 | /** 90 | * @param columnLabel the columnLabel to set 91 | */ 92 | public void setColumnLabel(String columnLabel) { 93 | this.columnLabel = columnLabel; 94 | } 95 | 96 | @Override 97 | public int hashCode() { 98 | int hash = 0; 99 | hash += (id != null ? id.hashCode() : 0); 100 | return hash; 101 | } 102 | 103 | @Override 104 | public boolean equals(Object object) { 105 | // TODO: Warning - this method won't work in the case the id fields are not set 106 | if (!(object instanceof ColumnModel)) { 107 | return false; 108 | } 109 | ColumnModel other = (ColumnModel) object; 110 | if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { 111 | return false; 112 | } 113 | return true; 114 | } 115 | 116 | @Override 117 | public String toString() { 118 | return "com.acme.acmepools.entity.ColumnModel[ id=" + id + " ]"; 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/entity/Customer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.entity; 7 | 8 | import java.io.Serializable; 9 | import java.math.BigDecimal; 10 | import java.util.Collection; 11 | import javax.json.bind.annotation.JsonbTransient; 12 | import javax.persistence.Basic; 13 | import javax.persistence.Column; 14 | import javax.persistence.Entity; 15 | import javax.persistence.Id; 16 | import javax.persistence.JoinColumn; 17 | import javax.persistence.ManyToOne; 18 | import javax.persistence.NamedQuery; 19 | import javax.persistence.OneToMany; 20 | import javax.persistence.Table; 21 | import javax.validation.constraints.Size; 22 | import javax.xml.bind.annotation.XmlRootElement; 23 | import javax.xml.bind.annotation.XmlTransient; 24 | 25 | /** 26 | * 27 | * @author Juneau 28 | */ 29 | @Entity 30 | @Table(name = "CUSTOMER") 31 | @XmlRootElement 32 | 33 | @NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Customer c") 34 | @NamedQuery(name = "Customer.findByCustomerId", query = "SELECT c FROM Customer c WHERE c.customerId = :customerId") 35 | @NamedQuery(name = "Customer.findByName", query = "SELECT c FROM Customer c WHERE c.name = :name") 36 | @NamedQuery(name = "Customer.findByAddressline1", query = "SELECT c FROM Customer c WHERE c.addressline1 = :addressline1") 37 | @NamedQuery(name = "Customer.findByAddressline2", query = "SELECT c FROM Customer c WHERE c.addressline2 = :addressline2") 38 | @NamedQuery(name = "Customer.findByCity", query = "SELECT c FROM Customer c WHERE c.city = :city") 39 | @NamedQuery(name = "Customer.findByState", query = "SELECT c FROM Customer c WHERE c.state = :state") 40 | @NamedQuery(name = "Customer.findByPhone", query = "SELECT c FROM Customer c WHERE c.phone = :phone") 41 | @NamedQuery(name = "Customer.findByFax", query = "SELECT c FROM Customer c WHERE c.fax = :fax") 42 | @NamedQuery(name = "Customer.findByEmail", query = "SELECT c FROM Customer c WHERE c.email = :email") 43 | @NamedQuery(name = "Customer.findByCreditLimit", query = "SELECT c FROM Customer c WHERE c.creditLimit = :creditLimit") 44 | public class Customer implements Serializable { 45 | 46 | private static final long serialVersionUID = 1L; 47 | @Id 48 | @Basic(optional = false) 49 | @Column(name = "CUSTOMER_ID") 50 | private Integer customerId; 51 | @Size(max = 30) 52 | @Column(name = "NAME") 53 | private String name; 54 | @Size(max = 30) 55 | @Column(name = "ADDRESSLINE1") 56 | private String addressline1; 57 | @Size(max = 30) 58 | @Column(name = "ADDRESSLINE2") 59 | private String addressline2; 60 | @Size(max = 25) 61 | @Column(name = "CITY") 62 | private String city; 63 | @Size(max = 2) 64 | @Column(name = "STATE") 65 | private String state; 66 | // @Pattern(regexp="^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", message="Invalid phone/fax format, should be as xxx-xxx-xxxx")//if the field contains phone or fax number consider using this annotation to enforce field validation 67 | @Size(max = 12) 68 | @Column(name = "PHONE") 69 | private String phone; 70 | // @Pattern(regexp="^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", message="Invalid phone/fax format, should be as xxx-xxx-xxxx")//if the field contains phone or fax number consider using this annotation to enforce field validation 71 | @Size(max = 12) 72 | @Column(name = "FAX") 73 | private String fax; 74 | // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation 75 | @Size(max = 40) 76 | @Column(name = "EMAIL") 77 | private String email; 78 | @Column(name = "CREDIT_LIMIT") 79 | private BigDecimal creditLimit; 80 | @JsonbTransient 81 | @OneToMany(mappedBy = "customerId") 82 | private Collection poolCustomerCollection; 83 | 84 | @JsonbTransient 85 | @JoinColumn(name = "DISCOUNT_CODE", referencedColumnName = "DISCOUNT_CODE") 86 | @ManyToOne(optional = false) 87 | private DiscountCode discountCode; 88 | 89 | @JsonbTransient 90 | @JoinColumn(name = "ZIP", referencedColumnName = "ZIP_CODE") 91 | @ManyToOne(optional = false) 92 | private MicroMarket zip; 93 | 94 | public Customer() { 95 | } 96 | 97 | public Customer(Integer customerId) { 98 | this.customerId = customerId; 99 | } 100 | 101 | public Integer getCustomerId() { 102 | return customerId; 103 | } 104 | 105 | public void setCustomerId(Integer customerId) { 106 | this.customerId = customerId; 107 | } 108 | 109 | public String getName() { 110 | return name; 111 | } 112 | 113 | public void setName(String name) { 114 | this.name = name; 115 | } 116 | 117 | public String getAddressline1() { 118 | return addressline1; 119 | } 120 | 121 | public void setAddressline1(String addressline1) { 122 | this.addressline1 = addressline1; 123 | } 124 | 125 | public String getAddressline2() { 126 | return addressline2; 127 | } 128 | 129 | public void setAddressline2(String addressline2) { 130 | this.addressline2 = addressline2; 131 | } 132 | 133 | public String getCity() { 134 | return city; 135 | } 136 | 137 | public void setCity(String city) { 138 | this.city = city; 139 | } 140 | 141 | public String getState() { 142 | return state; 143 | } 144 | 145 | public void setState(String state) { 146 | this.state = state; 147 | } 148 | 149 | public String getPhone() { 150 | return phone; 151 | } 152 | 153 | public void setPhone(String phone) { 154 | this.phone = phone; 155 | } 156 | 157 | public String getFax() { 158 | return fax; 159 | } 160 | 161 | public void setFax(String fax) { 162 | this.fax = fax; 163 | } 164 | 165 | public String getEmail() { 166 | return email; 167 | } 168 | 169 | public void setEmail(String email) { 170 | this.email = email; 171 | } 172 | 173 | public BigDecimal getCreditLimit() { 174 | return creditLimit; 175 | } 176 | 177 | public void setCreditLimit(BigDecimal creditLimit) { 178 | this.creditLimit = creditLimit; 179 | } 180 | 181 | /** 182 | * @return the discountCode 183 | */ 184 | public DiscountCode getDiscountCode() { 185 | return discountCode; 186 | } 187 | 188 | /** 189 | * @param discountCode the discountCode to set 190 | */ 191 | public void setDiscountCode(DiscountCode discountCode) { 192 | this.discountCode = discountCode; 193 | } 194 | 195 | /** 196 | * @return the zip 197 | */ 198 | public MicroMarket getZip() { 199 | return zip; 200 | } 201 | 202 | /** 203 | * @param zip the zip to set 204 | */ 205 | public void setZip(MicroMarket zip) { 206 | this.zip = zip; 207 | } 208 | 209 | @XmlTransient 210 | public Collection getPoolCustomerCollection() { 211 | return poolCustomerCollection; 212 | } 213 | 214 | public void setPoolCustomerCollection(Collection poolCustomerCollection) { 215 | this.poolCustomerCollection = poolCustomerCollection; 216 | } 217 | 218 | @Override 219 | public int hashCode() { 220 | int hash = 0; 221 | hash += (customerId != null ? customerId.hashCode() : 0); 222 | return hash; 223 | } 224 | 225 | @Override 226 | public boolean equals(Object object) { 227 | // TODO: Warning - this method won't work in the case the id fields are not set 228 | if (!(object instanceof Customer)) { 229 | return false; 230 | } 231 | Customer other = (Customer) object; 232 | if ((this.customerId == null && other.customerId != null) || (this.customerId != null && !this.customerId.equals(other.customerId))) { 233 | return false; 234 | } 235 | return true; 236 | } 237 | 238 | @Override 239 | public String toString() { 240 | return "com.acme.acmepools.entity.Customer[ customerId=" + customerId + " ]"; 241 | } 242 | 243 | } 244 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/entity/DiscountCode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.entity; 7 | 8 | import java.io.Serializable; 9 | import java.math.BigDecimal; 10 | import java.util.Collection; 11 | import javax.persistence.Basic; 12 | import javax.persistence.CascadeType; 13 | import javax.persistence.Column; 14 | import javax.persistence.Entity; 15 | import javax.persistence.Id; 16 | import javax.persistence.NamedQueries; 17 | import javax.persistence.NamedQuery; 18 | import javax.persistence.OneToMany; 19 | import javax.persistence.Table; 20 | import javax.validation.constraints.NotNull; 21 | import javax.validation.constraints.Size; 22 | import javax.xml.bind.annotation.XmlRootElement; 23 | import javax.xml.bind.annotation.XmlTransient; 24 | import lombok.Data; 25 | 26 | /** 27 | * 28 | * @author Juneau 29 | */ 30 | @Entity 31 | @Table(name = "DISCOUNT_CODE") 32 | @XmlRootElement 33 | 34 | @NamedQuery(name = "DiscountCode.findAll", query = "SELECT d FROM DiscountCode d") 35 | @NamedQuery(name = "DiscountCode.findByDiscountCode", query = "SELECT d FROM DiscountCode d WHERE d.discountCode = :discountCode") 36 | @NamedQuery(name = "DiscountCode.findByRate", query = "SELECT d FROM DiscountCode d WHERE d.rate = :rate") 37 | public class DiscountCode implements Serializable { 38 | 39 | private static final long serialVersionUID = 1L; 40 | @Id 41 | @Basic(optional = false) 42 | @Column(name = "DISCOUNT_CODE") 43 | private String discountCode; 44 | // @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation 45 | @Column(name = "RATE") 46 | private BigDecimal rate; 47 | @OneToMany(cascade = CascadeType.ALL, mappedBy = "discountCode") 48 | private Collection customerCollection; 49 | 50 | public DiscountCode() { 51 | } 52 | 53 | public DiscountCode(String discountCode) { 54 | this.discountCode = discountCode; 55 | } 56 | 57 | /** 58 | * @return the discountCode 59 | */ 60 | public String getDiscountCode() { 61 | return discountCode; 62 | } 63 | 64 | /** 65 | * @param discountCode the discountCode to set 66 | */ 67 | public void setDiscountCode(String discountCode) { 68 | this.discountCode = discountCode; 69 | } 70 | 71 | /** 72 | * @return the rate 73 | */ 74 | public BigDecimal getRate() { 75 | return rate; 76 | } 77 | 78 | /** 79 | * @param rate the rate to set 80 | */ 81 | public void setRate(BigDecimal rate) { 82 | this.rate = rate; 83 | } 84 | 85 | @XmlTransient 86 | public Collection getCustomerCollection() { 87 | return customerCollection; 88 | } 89 | 90 | @Override 91 | public int hashCode() { 92 | int hash = 0; 93 | hash += (discountCode != null ? discountCode.hashCode() : 0); 94 | return hash; 95 | } 96 | 97 | @Override 98 | public boolean equals(Object object) { 99 | // TODO: Warning - this method won't work in the case the id fields are not set 100 | if (!(object instanceof DiscountCode)) { 101 | return false; 102 | } 103 | DiscountCode other = (DiscountCode) object; 104 | if ((this.discountCode == null && other.discountCode != null) || (this.discountCode != null && !this.discountCode.equals(other.discountCode))) { 105 | return false; 106 | } 107 | return true; 108 | } 109 | 110 | @Override 111 | public String toString() { 112 | return "com.acme.acmepools.entity.DiscountCode[ discountCode=" + discountCode + " ]"; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/entity/Job.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package com.acme.acmepools.entity; 8 | 9 | import java.io.Serializable; 10 | import java.math.BigDecimal; 11 | import java.time.LocalDate; 12 | import javax.persistence.Basic; 13 | import javax.persistence.Column; 14 | import javax.persistence.Entity; 15 | import javax.persistence.Id; 16 | import javax.persistence.JoinColumn; 17 | import javax.persistence.Lob; 18 | import javax.persistence.ManyToOne; 19 | import javax.persistence.NamedQueries; 20 | import javax.persistence.NamedQuery; 21 | import javax.persistence.Table; 22 | import javax.validation.constraints.Future; 23 | import javax.validation.constraints.NotNull; 24 | import javax.xml.bind.annotation.XmlRootElement; 25 | import lombok.Data; 26 | 27 | /** 28 | * 29 | * @author Juneau 30 | */ 31 | @Entity 32 | @Table(name = "JOB") 33 | @XmlRootElement 34 | @NamedQueries({ 35 | @NamedQuery(name = "Job.findAll", query = "SELECT j FROM Job j"), 36 | @NamedQuery(name = "Job.findById", query = "SELECT j FROM Job j WHERE j.id = :id"), 37 | @NamedQuery(name = "Job.findByEstHours", query = "SELECT j FROM Job j WHERE j.estHours = :estHours"), 38 | @NamedQuery(name = "Job.findByCost", query = "SELECT j FROM Job j WHERE j.cost = :cost")}) 39 | public class Job implements Serializable { 40 | 41 | private static final long serialVersionUID = 1L; 42 | @Id 43 | // Uncomment if using Apache Derby 10.6+ 44 | // @GeneratedValue(strategy=GenerationType.SEQUENCE, 45 | // generator="job_s_generator") 46 | // @SequenceGenerator(name="job_s_generator",sequenceName="job_s", allocationSize=1) 47 | @Basic(optional = false) 48 | @Column(name = "ID") 49 | private BigDecimal id; 50 | @Lob 51 | @Column(name = "DESCRIPTION") 52 | private String description; 53 | @Column(name = "EST_HOURS") 54 | private Double estHours; 55 | @Column(name = "COST") 56 | private BigDecimal cost; 57 | @Future (message="Please ensure you are entering a work date in the future.") 58 | @Column(name = "WORK_DATE") 59 | private LocalDate workDate; 60 | @JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "ID") 61 | @ManyToOne 62 | private PoolCustomer customerId; 63 | 64 | public Job() { 65 | } 66 | 67 | public Job(BigDecimal id) { 68 | this.id = id; 69 | } 70 | 71 | 72 | /** 73 | * @return the id 74 | */ 75 | public BigDecimal getId() { 76 | return id; 77 | } 78 | 79 | /** 80 | * @param id the id to set 81 | */ 82 | public void setId(BigDecimal id) { 83 | this.id = id; 84 | } 85 | 86 | /** 87 | * @return the description 88 | */ 89 | public String getDescription() { 90 | return description; 91 | } 92 | 93 | /** 94 | * @param description the description to set 95 | */ 96 | public void setDescription(String description) { 97 | this.description = description; 98 | } 99 | 100 | /** 101 | * @return the estHours 102 | */ 103 | public Double getEstHours() { 104 | return estHours; 105 | } 106 | 107 | /** 108 | * @param estHours the estHours to set 109 | */ 110 | public void setEstHours(Double estHours) { 111 | this.estHours = estHours; 112 | } 113 | 114 | /** 115 | * @return the cost 116 | */ 117 | public BigDecimal getCost() { 118 | return cost; 119 | } 120 | 121 | /** 122 | * @param cost the cost to set 123 | */ 124 | public void setCost(BigDecimal cost) { 125 | this.cost = cost; 126 | } 127 | 128 | /** 129 | * @return the workDate 130 | */ 131 | public LocalDate getWorkDate() { 132 | return workDate; 133 | } 134 | 135 | /** 136 | * @param workDate the workDate to set 137 | */ 138 | public void setWorkDate(LocalDate workDate) { 139 | this.workDate = workDate; 140 | } 141 | 142 | /** 143 | * @return the customerId 144 | */ 145 | public PoolCustomer getCustomerId() { 146 | return customerId; 147 | } 148 | 149 | /** 150 | * @param customerId the customerId to set 151 | */ 152 | public void setCustomerId(PoolCustomer customerId) { 153 | this.customerId = customerId; 154 | } 155 | 156 | @Override 157 | public int hashCode() { 158 | int hash = 0; 159 | hash += (id != null ? id.hashCode() : 0); 160 | return hash; 161 | } 162 | 163 | @Override 164 | public boolean equals(Object object) { 165 | // TODO: Warning - this method won't work in the case the id fields are not set 166 | if (!(object instanceof Job)) { 167 | return false; 168 | } 169 | Job other = (Job) object; 170 | if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { 171 | return false; 172 | } 173 | return true; 174 | } 175 | 176 | @Override 177 | public String toString() { 178 | return "com.acme.acmepools.entity.Job[ id=" + id + " ]"; 179 | } 180 | 181 | } 182 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/entity/MicroMarket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.entity; 7 | 8 | import java.io.Serializable; 9 | import java.util.Collection; 10 | import javax.persistence.Basic; 11 | import javax.persistence.CascadeType; 12 | import javax.persistence.Column; 13 | import javax.persistence.Entity; 14 | import javax.persistence.Id; 15 | import javax.persistence.NamedQueries; 16 | import javax.persistence.NamedQuery; 17 | import javax.persistence.OneToMany; 18 | import javax.persistence.Table; 19 | import javax.validation.constraints.NotNull; 20 | import javax.validation.constraints.Size; 21 | import javax.xml.bind.annotation.XmlRootElement; 22 | import javax.xml.bind.annotation.XmlTransient; 23 | import lombok.Data; 24 | 25 | /** 26 | * 27 | * @author Juneau 28 | */ 29 | @Entity 30 | @Table(name = "MICRO_MARKET") 31 | @XmlRootElement 32 | @NamedQuery(name = "MicroMarket.findAll", query = "SELECT m FROM MicroMarket m") 33 | @NamedQuery(name = "MicroMarket.findByZipCode", query = "SELECT m FROM MicroMarket m WHERE m.zipCode = :zipCode") 34 | @NamedQuery(name = "MicroMarket.findByRadius", query = "SELECT m FROM MicroMarket m WHERE m.radius = :radius") 35 | @NamedQuery(name = "MicroMarket.findByAreaLength", query = "SELECT m FROM MicroMarket m WHERE m.areaLength = :areaLength") 36 | @NamedQuery(name = "MicroMarket.findByAreaWidth", query = "SELECT m FROM MicroMarket m WHERE m.areaWidth = :areaWidth") 37 | public class MicroMarket implements Serializable { 38 | 39 | private static final long serialVersionUID = 1L; 40 | @Id 41 | @Basic(optional = false) 42 | @Column(name = "ZIP_CODE") 43 | private String zipCode; 44 | // @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation 45 | @Column(name = "RADIUS") 46 | private Double radius; 47 | @Column(name = "AREA_LENGTH") 48 | private Double areaLength; 49 | @Column(name = "AREA_WIDTH") 50 | private Double areaWidth; 51 | @OneToMany(cascade = CascadeType.ALL, mappedBy = "zip") 52 | private Collection customerCollection; 53 | 54 | public MicroMarket() { 55 | } 56 | 57 | public MicroMarket(String zipCode) { 58 | this.zipCode = zipCode; 59 | } 60 | 61 | /** 62 | * @return the zipCode 63 | */ 64 | public String getZipCode() { 65 | return zipCode; 66 | } 67 | 68 | /** 69 | * @param zipCode the zipCode to set 70 | */ 71 | public void setZipCode(String zipCode) { 72 | this.zipCode = zipCode; 73 | } 74 | 75 | /** 76 | * @return the radius 77 | */ 78 | public Double getRadius() { 79 | return radius; 80 | } 81 | 82 | /** 83 | * @param radius the radius to set 84 | */ 85 | public void setRadius(Double radius) { 86 | this.radius = radius; 87 | } 88 | 89 | /** 90 | * @return the areaLength 91 | */ 92 | public Double getAreaLength() { 93 | return areaLength; 94 | } 95 | 96 | /** 97 | * @param areaLength the areaLength to set 98 | */ 99 | public void setAreaLength(Double areaLength) { 100 | this.areaLength = areaLength; 101 | } 102 | 103 | /** 104 | * @return the areaWidth 105 | */ 106 | public Double getAreaWidth() { 107 | return areaWidth; 108 | } 109 | 110 | /** 111 | * @param areaWidth the areaWidth to set 112 | */ 113 | public void setAreaWidth(Double areaWidth) { 114 | this.areaWidth = areaWidth; 115 | } 116 | 117 | /** 118 | * @param customerCollection the customerCollection to set 119 | */ 120 | public void setCustomerCollection(Collection customerCollection) { 121 | this.customerCollection = customerCollection; 122 | } 123 | 124 | @XmlTransient 125 | public Collection getCustomerCollection() { 126 | return customerCollection; 127 | } 128 | 129 | @Override 130 | public int hashCode() { 131 | int hash = 0; 132 | hash += (zipCode != null ? zipCode.hashCode() : 0); 133 | return hash; 134 | } 135 | 136 | @Override 137 | public boolean equals(Object object) { 138 | // TODO: Warning - this method won't work in the case the id fields are not set 139 | if (!(object instanceof MicroMarket)) { 140 | return false; 141 | } 142 | MicroMarket other = (MicroMarket) object; 143 | if ((this.zipCode == null && other.zipCode != null) || (this.zipCode != null && !this.zipCode.equals(other.zipCode))) { 144 | return false; 145 | } 146 | return true; 147 | } 148 | 149 | @Override 150 | public String toString() { 151 | return "com.acme.acmepools.entity.MicroMarket[ zipCode=" + zipCode + " ]"; 152 | } 153 | 154 | } 155 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/entity/Pool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.entity; 7 | 8 | import java.io.Serializable; 9 | import java.util.Collection; 10 | import javax.persistence.Basic; 11 | import javax.persistence.Column; 12 | import javax.persistence.Entity; 13 | import javax.persistence.Id; 14 | import javax.persistence.NamedQueries; 15 | import javax.persistence.NamedQuery; 16 | import javax.persistence.OneToMany; 17 | import javax.persistence.Table; 18 | import javax.validation.constraints.NotNull; 19 | import javax.validation.constraints.Size; 20 | import javax.xml.bind.annotation.XmlRootElement; 21 | import javax.xml.bind.annotation.XmlTransient; 22 | 23 | /** 24 | * 25 | * @author Juneau 26 | */ 27 | @Entity 28 | @Table(name = "POOL") 29 | @XmlRootElement 30 | @NamedQuery(name = "Pool.findAll", query = "SELECT p FROM Pool p") 31 | @NamedQuery(name = "Pool.findById", query = "SELECT p FROM Pool p WHERE p.id = :id") 32 | @NamedQuery(name = "Pool.findByStyle", query = "SELECT p FROM Pool p WHERE p.style = :style") 33 | @NamedQuery(name = "Pool.findByShape", query = "SELECT p FROM Pool p WHERE p.shape = :shape") 34 | @NamedQuery(name = "Pool.findByLength", query = "SELECT p FROM Pool p WHERE p.length = :length") 35 | @NamedQuery(name = "Pool.findByWidth", query = "SELECT p FROM Pool p WHERE p.width = :width") 36 | @NamedQuery(name = "Pool.findByRadius", query = "SELECT p FROM Pool p WHERE p.radius = :radius") 37 | @NamedQuery(name = "Pool.findByGallons", query = "SELECT p FROM Pool p WHERE p.gallons = :gallons") 38 | public class Pool implements Serializable { 39 | 40 | private static final long serialVersionUID = 1L; 41 | @Id 42 | // Uncomment if using Apache Derby 10.6+ 43 | // @GeneratedValue(strategy=GenerationType.SEQUENCE, 44 | // generator="pool_s_generator") 45 | // @SequenceGenerator(name="pool_s_generator",sequenceName="pool_s", allocationSize=1) 46 | @Basic(optional = false) 47 | @Column(name = "ID") 48 | private Integer id; 49 | @Size(max = 10) 50 | @Column(name = "STYLE") 51 | private String style; 52 | @Size(max = 10) 53 | @Column(name = "SHAPE") 54 | private String shape; 55 | // @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation 56 | @Column(name = "LENGTH") 57 | private Double length; 58 | @Column(name = "WIDTH") 59 | private Double width; 60 | @Column(name = "RADIUS") 61 | private Double radius; 62 | @Column(name = "GALLONS") 63 | private Double gallons; 64 | @OneToMany(mappedBy = "poolId") 65 | private Collection poolCustomerCollection; 66 | 67 | public Pool() { 68 | } 69 | 70 | public Pool(Integer id) { 71 | this.id = id; 72 | } 73 | 74 | /** 75 | * @return the id 76 | */ 77 | public Integer getId() { 78 | return id; 79 | } 80 | 81 | /** 82 | * @param id the id to set 83 | */ 84 | public void setId(Integer id) { 85 | this.id = id; 86 | } 87 | 88 | /** 89 | * @return the style 90 | */ 91 | public String getStyle() { 92 | return style; 93 | } 94 | 95 | /** 96 | * @param style the style to set 97 | */ 98 | public void setStyle(String style) { 99 | this.style = style; 100 | } 101 | 102 | /** 103 | * @return the shape 104 | */ 105 | public String getShape() { 106 | return shape; 107 | } 108 | 109 | /** 110 | * @param shape the shape to set 111 | */ 112 | public void setShape(String shape) { 113 | this.shape = shape; 114 | } 115 | 116 | /** 117 | * @return the length 118 | */ 119 | public Double getLength() { 120 | return length; 121 | } 122 | 123 | /** 124 | * @param length the length to set 125 | */ 126 | public void setLength(Double length) { 127 | this.length = length; 128 | } 129 | 130 | /** 131 | * @return the width 132 | */ 133 | public Double getWidth() { 134 | return width; 135 | } 136 | 137 | /** 138 | * @param width the width to set 139 | */ 140 | public void setWidth(Double width) { 141 | this.width = width; 142 | } 143 | 144 | /** 145 | * @return the radius 146 | */ 147 | public Double getRadius() { 148 | return radius; 149 | } 150 | 151 | /** 152 | * @param radius the radius to set 153 | */ 154 | public void setRadius(Double radius) { 155 | this.radius = radius; 156 | } 157 | 158 | /** 159 | * @return the gallons 160 | */ 161 | public Double getGallons() { 162 | return gallons; 163 | } 164 | 165 | /** 166 | * @param gallons the gallons to set 167 | */ 168 | public void setGallons(Double gallons) { 169 | this.gallons = gallons; 170 | } 171 | 172 | @XmlTransient 173 | public Collection getPoolCustomerCollection() { 174 | return poolCustomerCollection; 175 | } 176 | 177 | public void setPoolCustomerCollection(Collection poolCustomerCollection) { 178 | this.poolCustomerCollection = poolCustomerCollection; 179 | } 180 | 181 | @Override 182 | public int hashCode() { 183 | int hash = 0; 184 | hash += (id != null ? id.hashCode() : 0); 185 | return hash; 186 | } 187 | 188 | @Override 189 | public boolean equals(Object object) { 190 | // TODO: Warning - this method won't work in the case the id fields are not set 191 | if (!(object instanceof Pool)) { 192 | return false; 193 | } 194 | Pool other = (Pool) object; 195 | if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { 196 | return false; 197 | } 198 | return true; 199 | } 200 | 201 | @Override 202 | public String toString() { 203 | return "com.acme.acmepools.entity.Pool[ id=" + id + " ]"; 204 | } 205 | 206 | } 207 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/entity/PoolCustomer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.entity; 7 | 8 | import java.io.Serializable; 9 | import java.util.Collection; 10 | import javax.persistence.Basic; 11 | import javax.persistence.Column; 12 | import javax.persistence.Entity; 13 | import javax.persistence.GeneratedValue; 14 | import javax.persistence.GenerationType; 15 | import javax.persistence.Id; 16 | import javax.persistence.JoinColumn; 17 | import javax.persistence.ManyToOne; 18 | import javax.persistence.NamedQueries; 19 | import javax.persistence.NamedQuery; 20 | import javax.persistence.OneToMany; 21 | import javax.persistence.SequenceGenerator; 22 | import javax.persistence.Table; 23 | import javax.validation.constraints.NotNull; 24 | import javax.xml.bind.annotation.XmlRootElement; 25 | 26 | /** 27 | * 28 | * @author Juneau 29 | */ 30 | @Entity 31 | @Table(name = "POOL_CUSTOMER") 32 | @XmlRootElement 33 | @NamedQuery(name = "PoolCustomer.findAll", query = "SELECT p FROM PoolCustomer p") 34 | @NamedQuery(name = "PoolCustomer.findById", query = "SELECT p FROM PoolCustomer p WHERE p.id = :id") 35 | public class PoolCustomer implements Serializable { 36 | 37 | private static final long serialVersionUID = 1L; 38 | @Id 39 | // Uncomment if using Apache Derby 10.6+ 40 | // @GeneratedValue(strategy=GenerationType.SEQUENCE, 41 | // generator="pool_cust_s_generator") 42 | // @SequenceGenerator(name="pool_cust_s_generator",sequenceName="pool_cust_s", allocationSize=1) 43 | @Basic(optional = false) 44 | @Column(name = "ID") 45 | private Integer id; 46 | @JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "CUSTOMER_ID") 47 | @ManyToOne 48 | private Customer customerId; 49 | @JoinColumn(name = "POOL_ID", referencedColumnName = "ID") 50 | @ManyToOne 51 | private Pool poolId; 52 | @OneToMany(mappedBy = "customerId") 53 | private Collection jobCollection; 54 | 55 | public PoolCustomer() { 56 | } 57 | 58 | public PoolCustomer(Integer id) { 59 | this.id = id; 60 | } 61 | 62 | public Integer getId() { 63 | return id; 64 | } 65 | 66 | public void setId(Integer id) { 67 | this.id = id; 68 | } 69 | 70 | public Customer getCustomerId() { 71 | return customerId; 72 | } 73 | 74 | public void setCustomerId(Customer customerId) { 75 | this.customerId = customerId; 76 | } 77 | 78 | /** 79 | * @return the poolId 80 | */ 81 | public Pool getPoolId() { 82 | return poolId; 83 | } 84 | 85 | /** 86 | * @param poolId the poolId to set 87 | */ 88 | public void setPoolId(Pool poolId) { 89 | this.poolId = poolId; 90 | } 91 | 92 | /** 93 | * @return the jobCollection 94 | */ 95 | public Collection getJobCollection() { 96 | return jobCollection; 97 | } 98 | 99 | /** 100 | * @param jobCollection the jobCollection to set 101 | */ 102 | public void setJobCollection(Collection jobCollection) { 103 | this.jobCollection = jobCollection; 104 | } 105 | 106 | @Override 107 | public int hashCode() { 108 | int hash = 0; 109 | hash += (id != null ? id.hashCode() : 0); 110 | return hash; 111 | } 112 | 113 | @Override 114 | public boolean equals(Object object) { 115 | // TODO: Warning - this method won't work in the case the id fields are not set 116 | if (!(object instanceof PoolCustomer)) { 117 | return false; 118 | } 119 | PoolCustomer other = (PoolCustomer) object; 120 | if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { 121 | return false; 122 | } 123 | return true; 124 | } 125 | 126 | @Override 127 | public String toString() { 128 | return "com.acme.acmepools.entity.PoolCustomer[ id=" + id + " ]"; 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/entity/util/JsfUtil.java: -------------------------------------------------------------------------------- 1 | package com.acme.acmepools.entity.util; 2 | 3 | import java.util.List; 4 | import javax.faces.annotation.RequestParameterMap; 5 | import javax.faces.application.FacesMessage; 6 | import javax.faces.component.UIComponent; 7 | import javax.faces.context.FacesContext; 8 | import javax.faces.convert.Converter; 9 | import javax.faces.model.SelectItem; 10 | import javax.inject.Inject; 11 | 12 | public class JsfUtil { 13 | 14 | 15 | 16 | public static SelectItem[] getSelectItems(List entities, boolean selectOne) { 17 | int size = selectOne ? entities.size() + 1 : entities.size(); 18 | SelectItem[] items = new SelectItem[size]; 19 | int i = 0; 20 | if (selectOne) { 21 | items[0] = new SelectItem("", "---"); 22 | i++; 23 | } 24 | for (Object x : entities) { 25 | items[i++] = new SelectItem(x, x.toString()); 26 | } 27 | return items; 28 | } 29 | 30 | public static boolean isValidationFailed() { 31 | return FacesContext.getCurrentInstance().isValidationFailed(); 32 | } 33 | 34 | public static void addErrorMessage(Exception ex, String defaultMsg) { 35 | String msg = ex.getLocalizedMessage(); 36 | if (msg != null && msg.length() > 0) { 37 | addErrorMessage(msg); 38 | } else { 39 | addErrorMessage(defaultMsg); 40 | } 41 | } 42 | 43 | public static void addErrorMessages(List messages) { 44 | for (String message : messages) { 45 | addErrorMessage(message); 46 | } 47 | } 48 | 49 | public static void addErrorMessage(String msg) { 50 | FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg); 51 | FacesContext.getCurrentInstance().addMessage(null, facesMsg); 52 | } 53 | 54 | public static void addSuccessMessage(String msg) { 55 | FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg); 56 | FacesContext.getCurrentInstance().addMessage("successInfo", facesMsg); 57 | } 58 | 59 | public static String getRequestParameter(String key) { 60 | return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key); 61 | } 62 | 63 | public static Object getObjectFromRequestParameter(String requestParameterName, Converter converter, UIComponent component) { 64 | String theId = JsfUtil.getRequestParameter(requestParameterName); 65 | return converter.getAsObject(FacesContext.getCurrentInstance(), component, theId); 66 | } 67 | 68 | public static enum PersistAction { 69 | 70 | CREATE, 71 | DELETE, 72 | UPDATE 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/event/JobEvent.java: -------------------------------------------------------------------------------- 1 | 2 | package com.acme.acmepools.event; 3 | 4 | import com.acme.acmepools.entity.Job; 5 | import javax.inject.Named; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Getter; 8 | import lombok.NoArgsConstructor; 9 | import lombok.Setter; 10 | 11 | /** 12 | * Utilized to indicate when a job is created. 13 | * 14 | * @author Juneau 15 | */ 16 | @Getter @Setter 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | @Named 20 | public class JobEvent { 21 | private String message; 22 | private Job job; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/jsf/ColumnModelController.java: -------------------------------------------------------------------------------- 1 | package com.acme.acmepools.jsf; 2 | 3 | import com.acme.acmepools.bean.ColumnBean; 4 | import com.acme.acmepools.bean.PickListBean; 5 | import com.acme.acmepools.session.ColumnModelFacade; 6 | import java.io.Serializable; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import javax.ejb.EJB; 10 | import javax.enterprise.context.SessionScoped; 11 | import javax.faces.component.UIComponent; 12 | import javax.faces.context.FacesContext; 13 | import javax.inject.Named; 14 | import org.primefaces.model.DualListModel; 15 | 16 | /** 17 | * 18 | * @author Juneau 19 | */ 20 | @Named 21 | @SessionScoped 22 | public class ColumnModelController implements Serializable { 23 | 24 | @EJB 25 | ColumnModelFacade ejbFacade; 26 | 27 | private PickListBean pickListBean; 28 | private List columns; 29 | 30 | public DualListModel getColumns() { 31 | pickListBean = new PickListBean(ejbFacade.findAll()); 32 | return pickListBean.getColumns(); 33 | } 34 | 35 | public void setColumns(DualListModel columns) { 36 | pickListBean.setColumns(columns); 37 | } 38 | 39 | public List getDynamicColumns() { 40 | return columns; 41 | } 42 | 43 | public void preProcess(Object document) { 44 | System.out.println("starting preprocess"); 45 | updateColumns(); 46 | } 47 | 48 | /** 49 | * Called as preprocessor to export (after clicking Excel icon) to capture 50 | * the table component and call upon createDynamicColumns() 51 | * 52 | * @since 2.7.5 53 | */ 54 | public void updateColumns() { 55 | //reset table state 56 | UIComponent table = FacesContext.getCurrentInstance().getViewRoot().findComponent(":customerExportForm:customerTable"); 57 | table.setValueExpression("sortBy", null); 58 | 59 | //update columns 60 | createDynamicColumns(); 61 | } 62 | 63 | /** 64 | * Creates column list dynamically based upon chosen selections from the 65 | * picklist on the CustomerExport.xhtml view 66 | * 67 | */ 68 | private void createDynamicColumns() { 69 | String[] columnKeys = this.getIncludedColumnsByName().split(","); 70 | columns = new ArrayList<>(); 71 | for (String columnKey : columnKeys) { 72 | String key = columnKey.trim(); 73 | columns.add(new ColumnModel(getColumnLabel(key), key)); 74 | 75 | } 76 | } 77 | 78 | /** 79 | * Returns a column label, given a specified columnName identifier 80 | * 81 | * @param columnName 82 | * @return 83 | */ 84 | public String getColumnLabel(String columnName) { 85 | 86 | com.acme.acmepools.entity.ColumnModel model = ejbFacade.findId(columnName); 87 | return model.getColumnLabel(); 88 | } 89 | 90 | /** 91 | * @return the included columns 92 | */ 93 | public String getIncludedColumnsByName() { 94 | String tempIncludedColString = null; 95 | 96 | System.out.println("Number of included columns:" + pickListBean.getColumns().getTarget().size()); 97 | List localSource = pickListBean.getColumns().getTarget(); 98 | for (int x = 0; x <= localSource.size() - 1; x++) { 99 | String tempModel = (String) localSource.get(x); 100 | if (tempIncludedColString == null) { 101 | tempIncludedColString = tempModel; 102 | } else { 103 | tempIncludedColString = tempIncludedColString + "," + tempModel; 104 | } 105 | } 106 | 107 | return tempIncludedColString; 108 | } 109 | 110 | static public class ColumnModel implements Serializable { 111 | 112 | private String header; 113 | private String property; 114 | 115 | public ColumnModel(String header, String property) { 116 | this.header = header; 117 | this.property = property; 118 | } 119 | 120 | public String getHeader() { 121 | return header; 122 | } 123 | 124 | public String getProperty() { 125 | return property; 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/jsf/ConfigurationBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.jsf; 7 | 8 | import static javax.faces.annotation.FacesConfig.Version.JSF_2_3; 9 | 10 | import javax.faces.annotation.FacesConfig; 11 | 12 | @FacesConfig( 13 | // Activates CDI build-in beans 14 | version = JSF_2_3 15 | ) 16 | public class ConfigurationBean { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/jsf/CustomerController.java: -------------------------------------------------------------------------------- 1 | package com.acme.acmepools.jsf; 2 | 3 | import com.acme.acmepools.entity.Customer; 4 | import com.acme.acmepools.entity.util.JsfUtil; 5 | import com.acme.acmepools.entity.util.JsfUtil.PersistAction; 6 | import com.acme.acmepools.session.CustomerFacade; 7 | import java.io.Serializable; 8 | import java.util.List; 9 | import java.util.Map; 10 | import java.util.ResourceBundle; 11 | import javax.ejb.EJB; 12 | import javax.ejb.EJBException; 13 | import javax.enterprise.context.SessionScoped; 14 | import javax.faces.application.FacesMessage; 15 | import javax.faces.component.UIComponent; 16 | import javax.faces.context.FacesContext; 17 | import javax.faces.convert.Converter; 18 | import javax.faces.convert.FacesConverter; 19 | import javax.inject.Named; 20 | import javax.json.Json; 21 | import javax.json.JsonArray; 22 | import javax.json.JsonObject; 23 | import javax.json.JsonPointer; 24 | import javax.json.JsonValue; 25 | import javax.json.bind.Jsonb; 26 | import javax.json.bind.JsonbBuilder; 27 | import lombok.Getter; 28 | import lombok.Setter; 29 | import org.primefaces.component.datatable.DataTable; 30 | import org.primefaces.event.CellEditEvent; 31 | 32 | @Named("customerController") 33 | @SessionScoped 34 | public class CustomerController implements Serializable { 35 | 36 | @EJB 37 | private com.acme.acmepools.session.CustomerFacade ejbFacade; 38 | private List customers = null; 39 | @Getter 40 | @Setter 41 | private Customer selected; 42 | 43 | @Getter 44 | @Setter 45 | private String addressSearchText; 46 | 47 | @Getter 48 | @Setter 49 | private String searchResult; 50 | 51 | public CustomerController() { 52 | } 53 | 54 | protected void setEmbeddableKeys() { 55 | } 56 | 57 | protected void initializeEmbeddableKey() { 58 | } 59 | 60 | private CustomerFacade getFacade() { 61 | return ejbFacade; 62 | } 63 | 64 | public Customer prepareCreate() { 65 | selected = new Customer(); 66 | initializeEmbeddableKey(); 67 | return selected; 68 | } 69 | 70 | public void create() { 71 | persist(PersistAction.CREATE, ResourceBundle.getBundle("/Bundle").getString("CustomerCreated")); 72 | if (!JsfUtil.isValidationFailed()) { 73 | customers = null; // Invalidate list of items to trigger re-query. 74 | } 75 | } 76 | 77 | public void update() { 78 | persist(PersistAction.UPDATE, ResourceBundle.getBundle("/Bundle").getString("CustomerUpdated")); 79 | } 80 | 81 | public void destroy() { 82 | persist(PersistAction.DELETE, ResourceBundle.getBundle("/Bundle").getString("CustomerDeleted")); 83 | if (!JsfUtil.isValidationFailed()) { 84 | selected = null; // Remove selection 85 | customers = null; // Invalidate list of items to trigger re-query. 86 | } 87 | } 88 | 89 | public List getItems() { 90 | if (customers == null) { 91 | customers = getFacade().findAll(); 92 | } 93 | return customers; 94 | } 95 | 96 | private void persist(PersistAction persistAction, String successMessage) { 97 | if (selected != null) { 98 | setEmbeddableKeys(); 99 | try { 100 | if (persistAction != PersistAction.DELETE) { 101 | getFacade().edit(selected); 102 | } else { 103 | getFacade().remove(selected); 104 | } 105 | JsfUtil.addSuccessMessage(successMessage); 106 | } catch (EJBException ex) { 107 | String msg = ""; 108 | Throwable cause = ex.getCause(); 109 | if (cause != null) { 110 | msg = cause.getLocalizedMessage(); 111 | } 112 | if (msg.length() > 0) { 113 | JsfUtil.addErrorMessage(msg); 114 | } else { 115 | JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured")); 116 | } 117 | } catch (Exception ex) { 118 | System.out.println(ex); 119 | JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured")); 120 | } 121 | } 122 | } 123 | 124 | public Customer getCustomer(java.lang.Integer id) { 125 | return getFacade().find(id); 126 | } 127 | 128 | public List getItemsAvailableSelectMany() { 129 | return getFacade().findAll(); 130 | } 131 | 132 | public List getItemsAvailableSelectOne() { 133 | return getFacade().findAll(); 134 | } 135 | 136 | @FacesConverter(forClass = Customer.class) 137 | public static class CustomerControllerConverter implements Converter { 138 | 139 | @Override 140 | public Object getAsObject(FacesContext facesContext, UIComponent component, String value) { 141 | if (value == null || value.length() == 0) { 142 | return null; 143 | } 144 | CustomerController controller = (CustomerController) facesContext.getApplication().getELResolver(). 145 | getValue(facesContext.getELContext(), null, "customerController"); 146 | return controller.getCustomer(getKey(value)); 147 | } 148 | 149 | java.lang.Integer getKey(String value) { 150 | java.lang.Integer key; 151 | key = Integer.valueOf(value); 152 | return key; 153 | } 154 | 155 | String getStringKey(java.lang.Integer value) { 156 | StringBuilder sb = new StringBuilder(); 157 | sb.append(value); 158 | return sb.toString(); 159 | } 160 | 161 | @Override 162 | public String getAsString(FacesContext facesContext, UIComponent component, Object object) { 163 | if (object == null) { 164 | return null; 165 | } 166 | if (object instanceof Customer) { 167 | Customer o = (Customer) object; 168 | return getStringKey(o.getCustomerId()); 169 | } else { 170 | 171 | return null; 172 | } 173 | } 174 | 175 | } 176 | 177 | public void onCellEdit(CellEditEvent event) { 178 | Object oldValue = event.getOldValue(); 179 | Object newValue = event.getNewValue(); 180 | if (!oldValue.equals(newValue)) { 181 | // Save to the database 182 | DataTable table = (DataTable) event.getSource(); 183 | Customer customer = (Customer) table.getRowData(); 184 | ejbFacade.edit(customer); 185 | FacesContext.getCurrentInstance().addMessage(null, 186 | new FacesMessage(FacesMessage.SEVERITY_INFO, "Successfully Updated", "Updated value to " + newValue)); 187 | } 188 | } 189 | 190 | public String loadCustomer() { 191 | Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); 192 | String customer = (String) requestMap.get("customer"); 193 | selected = ejbFacade.find(Integer.valueOf(customer)); 194 | return "customerInfo"; 195 | } 196 | 197 | /** 198 | * Utilizes the JSON-B API to create a JSON representation from a collection 199 | * of data and serializes. 200 | * 201 | * @return 202 | */ 203 | public String fetchJson() { 204 | System.out.println("Items: " + customers); 205 | Jsonb jsonb = JsonbBuilder.create(); 206 | String result = null; 207 | 208 | result = jsonb.toJson(customers); 209 | 210 | return result; 211 | } 212 | 213 | public void findCustomerByAddress() { 214 | searchResult = null; 215 | String text = "/" + this.addressSearchText; 216 | JsonObject json = Json.createObjectBuilder().build(); 217 | JsonValue object = json.getJsonObject(fetchJson()); 218 | if (addressSearchText != null) { 219 | JsonPointer pointer = Json.createPointer(text); 220 | JsonValue result = pointer.getValue(object.asJsonArray()); 221 | 222 | // Replace a value 223 | JsonArray array = (JsonArray) pointer.replace(object.asJsonArray(), Json.createValue("1000 JsonP Drive")); 224 | searchResult = array.toString(); 225 | //searchResult = result.toString(); 226 | } 227 | 228 | } 229 | 230 | public Customer findById(Integer customerId) { 231 | return ejbFacade.findByCustomerId(customerId); 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/jsf/DiscountCodeController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.jsf; 7 | 8 | import com.acme.acmepools.entity.DiscountCode; 9 | import com.acme.acmepools.session.DiscountCodeFacade; 10 | import java.util.List; 11 | import javax.annotation.PostConstruct; 12 | import javax.ejb.EJB; 13 | import javax.enterprise.context.RequestScoped; 14 | import javax.inject.Named; 15 | import lombok.Getter; 16 | import lombok.NoArgsConstructor; 17 | import lombok.Setter; 18 | 19 | /** 20 | * 21 | * @author Juneau 22 | */ 23 | @Named 24 | @RequestScoped 25 | @NoArgsConstructor 26 | public class DiscountCodeController { 27 | 28 | @EJB 29 | private DiscountCodeFacade discountCodeFacade; 30 | 31 | @Setter 32 | private List itemsAvailableSelectOne; 33 | 34 | public List getItemsAvailableSelectOne(){ 35 | itemsAvailableSelectOne = discountCodeFacade.findAll(); 36 | return itemsAvailableSelectOne; 37 | } 38 | 39 | public DiscountCode obtainById(DiscountCode code){ 40 | return discountCodeFacade.findByCode(code.getDiscountCode()); 41 | } 42 | 43 | public DiscountCode obtainByCode(String code) { 44 | return discountCodeFacade.findByCode(code); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/jsf/JobController.java: -------------------------------------------------------------------------------- 1 | package com.acme.acmepools.jsf; 2 | 3 | import com.acme.acmepools.entity.Customer; 4 | import com.acme.acmepools.entity.Job; 5 | import com.acme.acmepools.entity.PoolCustomer; 6 | import com.acme.acmepools.session.JobFacade; 7 | import com.acme.acmepools.entity.util.JsfUtil; 8 | import com.acme.acmepools.entity.util.JsfUtil.PersistAction; 9 | import com.acme.acmepools.event.JobEvent; 10 | 11 | import java.io.Serializable; 12 | import java.math.BigDecimal; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.ResourceBundle; 16 | import java.util.logging.Level; 17 | import java.util.logging.Logger; 18 | import javax.ejb.EJB; 19 | import javax.ejb.EJBException; 20 | import javax.inject.Named; 21 | import javax.enterprise.context.SessionScoped; 22 | import javax.enterprise.event.Event; 23 | import javax.faces.component.UIComponent; 24 | import javax.faces.context.FacesContext; 25 | import javax.faces.convert.Converter; 26 | import javax.faces.convert.FacesConverter; 27 | import javax.inject.Inject; 28 | 29 | @Named("jobController") 30 | @SessionScoped 31 | public class JobController implements Serializable { 32 | 33 | @EJB 34 | private com.acme.acmepools.session.JobFacade ejbFacade; 35 | @EJB 36 | private com.acme.acmepools.session.PoolCustomerFacade poolCustomerFacade; 37 | 38 | private List items = null; 39 | private List jobsByCustomer = null; 40 | private List jobsByPool = null; 41 | private Job selected; 42 | 43 | @Inject 44 | private Event jobEvent; 45 | 46 | public JobController() { 47 | } 48 | 49 | public Job getSelected() { 50 | return selected; 51 | } 52 | 53 | public void populateRoundJobs(){ 54 | this.jobsByPool = ejbFacade.findByCustPoolShape("ROUND"); 55 | System.out.println("There are " + jobsByPool.size() + " round pool jobs"); 56 | } 57 | 58 | public void findByCustomer(Customer customer){ 59 | List poolCustomerObjects = poolCustomerFacade.findByCustomerId(customer); 60 | jobsByCustomer = new ArrayList(); 61 | for(PoolCustomer pCust:poolCustomerObjects){ 62 | List customerJobs = ejbFacade.findByCustomer(pCust); 63 | jobsByCustomer.addAll(customerJobs); 64 | } 65 | } 66 | 67 | public void setSelected(Job selected) { 68 | this.selected = selected; 69 | } 70 | 71 | protected void setEmbeddableKeys() { 72 | } 73 | 74 | protected void initializeEmbeddableKey() { 75 | } 76 | 77 | private JobFacade getFacade() { 78 | return ejbFacade; 79 | } 80 | 81 | public Job prepareCreate() { 82 | selected = new Job(); 83 | initializeEmbeddableKey(); 84 | return selected; 85 | } 86 | 87 | public void create() { 88 | persist(PersistAction.CREATE, ResourceBundle.getBundle("/Bundle").getString("JobCreated")); 89 | if (!JsfUtil.isValidationFailed()) { 90 | items = null; // Invalidate list of items to trigger re-query. 91 | } 92 | } 93 | 94 | public void update() { 95 | persist(PersistAction.UPDATE, ResourceBundle.getBundle("/Bundle").getString("JobUpdated")); 96 | } 97 | 98 | public void destroy() { 99 | persist(PersistAction.DELETE, ResourceBundle.getBundle("/Bundle").getString("JobDeleted")); 100 | if (!JsfUtil.isValidationFailed()) { 101 | selected = null; // Remove selection 102 | items = null; // Invalidate list of items to trigger re-query. 103 | } 104 | } 105 | 106 | public List getItems() { 107 | if (items == null) { 108 | items = getFacade().findAll(); 109 | } 110 | return items; 111 | } 112 | 113 | public List getJobsByCustomer(){ 114 | return jobsByCustomer; 115 | } 116 | 117 | public void setJobsByCustomer(List jobs){ 118 | this.jobsByCustomer = jobs; 119 | } 120 | 121 | public List getJobsByPool(){ 122 | if(this.jobsByPool == null){ 123 | populateRoundJobs(); 124 | } 125 | return jobsByPool; 126 | } 127 | 128 | public void setJobsByPool(List jobs){ 129 | this.jobsByPool = jobs; 130 | } 131 | 132 | private void persist(PersistAction persistAction, String successMessage) { 133 | if (selected != null) { 134 | setEmbeddableKeys(); 135 | try { 136 | if (persistAction != PersistAction.DELETE) { 137 | getFacade().edit(selected); 138 | if (persistAction == PersistAction.CREATE) { 139 | jobEvent.fireAsync(new JobEvent("New job added", selected)) 140 | .whenComplete((event, throwable) -> { 141 | if (throwable != null) { 142 | System.out.println("Error has occurred: " + throwable.getMessage()); 143 | } else { 144 | System.out.println("Successful Job Processing..."); 145 | } 146 | }); 147 | } 148 | } else { 149 | getFacade().remove(selected); 150 | } 151 | JsfUtil.addSuccessMessage(successMessage); 152 | } catch (EJBException ex) { 153 | String msg = ""; 154 | Throwable cause = ex.getCause(); 155 | if (cause != null) { 156 | msg = cause.getLocalizedMessage(); 157 | } 158 | if (msg.length() > 0) { 159 | JsfUtil.addErrorMessage(msg); 160 | } else { 161 | JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured")); 162 | } 163 | } catch (Exception ex) { 164 | Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); 165 | JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured")); 166 | } 167 | } 168 | } 169 | 170 | public Job getJob(java.lang.Integer id) { 171 | return getFacade().find(id); 172 | } 173 | 174 | public List getItemsAvailableSelectMany() { 175 | return getFacade().findAll(); 176 | } 177 | 178 | public List getItemsAvailableSelectOne() { 179 | return getFacade().findAll(); 180 | } 181 | 182 | @FacesConverter(forClass = Job.class) 183 | public static class JobControllerConverter implements Converter { 184 | 185 | @Override 186 | public Object getAsObject(FacesContext facesContext, UIComponent component, String value) { 187 | if (value == null || value.length() == 0) { 188 | return null; 189 | } 190 | JobController controller = (JobController) facesContext.getApplication().getELResolver(). 191 | getValue(facesContext.getELContext(), null, "jobController"); 192 | return controller.getJob(getKey(value)); 193 | } 194 | 195 | java.lang.Integer getKey(String value) { 196 | java.lang.Integer key; 197 | key = Integer.valueOf(value); 198 | return key; 199 | } 200 | 201 | String getStringKey(BigDecimal value) { 202 | StringBuilder sb = new StringBuilder(); 203 | sb.append(value); 204 | return sb.toString(); 205 | } 206 | 207 | @Override 208 | public String getAsString(FacesContext facesContext, UIComponent component, Object object) { 209 | if (object == null) { 210 | return null; 211 | } 212 | if (object instanceof Job) { 213 | Job o = (Job) object; 214 | return getStringKey(o.getId()); 215 | } else { 216 | Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "object {0} is of type {1}; expected type: {2}", new Object[]{object, object.getClass().getName(), Job.class.getName()}); 217 | return null; 218 | } 219 | } 220 | 221 | } 222 | 223 | } 224 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/jsf/MicroMarketController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.jsf; 7 | 8 | import com.acme.acmepools.entity.MicroMarket; 9 | import com.acme.acmepools.session.MicroMarketFacade; 10 | import java.util.List; 11 | import javax.annotation.PostConstruct; 12 | import javax.ejb.EJB; 13 | import javax.enterprise.context.RequestScoped; 14 | import javax.inject.Named; 15 | import lombok.Getter; 16 | import lombok.NoArgsConstructor; 17 | import lombok.Setter; 18 | 19 | /** 20 | * 21 | * @author Juneau 22 | */ 23 | @Named 24 | @RequestScoped 25 | @NoArgsConstructor 26 | public class MicroMarketController { 27 | 28 | @EJB 29 | private MicroMarketFacade microMarketFacade; 30 | 31 | @Setter 32 | private List itemsAvailableSelectOne; 33 | 34 | 35 | public List getItemsAvailableSelectOne(){ 36 | itemsAvailableSelectOne = microMarketFacade.findAll(); 37 | return itemsAvailableSelectOne; 38 | } 39 | 40 | public MicroMarket obtainById(MicroMarket microMarket){ 41 | return microMarketFacade.find(microMarket); 42 | } 43 | 44 | public MicroMarket obtainByZipCode(String zip){ 45 | return microMarketFacade.findByZipCode(zip); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/jsf/PoolController.java: -------------------------------------------------------------------------------- 1 | package com.acme.acmepools.jsf; 2 | 3 | import com.acme.acmepools.entity.Pool; 4 | import com.acme.acmepools.session.PoolFacade; 5 | import com.acme.acmepools.entity.util.JsfUtil; 6 | import com.acme.acmepools.entity.util.JsfUtil.PersistAction; 7 | 8 | import java.io.Serializable; 9 | import java.util.List; 10 | import java.util.ResourceBundle; 11 | import java.util.logging.Level; 12 | import java.util.logging.Logger; 13 | import javax.ejb.EJB; 14 | import javax.ejb.EJBException; 15 | import javax.inject.Named; 16 | import javax.enterprise.context.SessionScoped; 17 | import javax.faces.component.UIComponent; 18 | import javax.faces.context.FacesContext; 19 | import javax.faces.convert.Converter; 20 | import javax.faces.convert.FacesConverter; 21 | 22 | @Named("poolController") 23 | @SessionScoped 24 | public class PoolController implements Serializable { 25 | 26 | @EJB 27 | private com.acme.acmepools.session.PoolFacade ejbFacade; 28 | private List items = null; 29 | private List filteredPools; 30 | private Pool selected; 31 | 32 | public PoolController() { 33 | } 34 | 35 | public Pool getSelected() { 36 | return selected; 37 | } 38 | 39 | public void setSelected(Pool selected) { 40 | this.selected = selected; 41 | } 42 | 43 | protected void setEmbeddableKeys() { 44 | } 45 | 46 | protected void initializeEmbeddableKey() { 47 | } 48 | 49 | private PoolFacade getFacade() { 50 | return ejbFacade; 51 | } 52 | 53 | public Pool prepareCreate() { 54 | selected = new Pool(); 55 | initializeEmbeddableKey(); 56 | return selected; 57 | } 58 | 59 | public void create() { 60 | persist(PersistAction.CREATE, ResourceBundle.getBundle("/Bundle").getString("PoolCreated")); 61 | if (!JsfUtil.isValidationFailed()) { 62 | items = null; // Invalidate list of items to trigger re-query. 63 | } 64 | } 65 | 66 | public void update() { 67 | persist(PersistAction.UPDATE, ResourceBundle.getBundle("/Bundle").getString("PoolUpdated")); 68 | } 69 | 70 | public void destroy() { 71 | persist(PersistAction.DELETE, ResourceBundle.getBundle("/Bundle").getString("PoolDeleted")); 72 | if (!JsfUtil.isValidationFailed()) { 73 | selected = null; // Remove selection 74 | items = null; // Invalidate list of items to trigger re-query. 75 | } 76 | } 77 | 78 | public List getItems() { 79 | if (items == null) { 80 | items = getFacade().findAll(); 81 | } 82 | return items; 83 | } 84 | 85 | private void persist(PersistAction persistAction, String successMessage) { 86 | if (selected != null) { 87 | setEmbeddableKeys(); 88 | try { 89 | if (persistAction != PersistAction.DELETE) { 90 | getFacade().edit(selected); 91 | } else { 92 | getFacade().remove(selected); 93 | } 94 | JsfUtil.addSuccessMessage(successMessage); 95 | } catch (EJBException ex) { 96 | String msg = ""; 97 | Throwable cause = ex.getCause(); 98 | if (cause != null) { 99 | msg = cause.getLocalizedMessage(); 100 | } 101 | if (msg.length() > 0) { 102 | JsfUtil.addErrorMessage(msg); 103 | } else { 104 | JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured")); 105 | } 106 | } catch (Exception ex) { 107 | Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); 108 | JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured")); 109 | } 110 | } 111 | } 112 | 113 | public Pool getPool(java.lang.Integer id) { 114 | return getFacade().find(id); 115 | } 116 | 117 | public List getItemsAvailableSelectMany() { 118 | return getFacade().findAll(); 119 | } 120 | 121 | public List getItemsAvailableSelectOne() { 122 | return getFacade().findAll(); 123 | } 124 | 125 | /** 126 | * @return the filteredPools 127 | */ 128 | public List getFilteredPools() { 129 | return filteredPools; 130 | } 131 | 132 | /** 133 | * @param filteredPools the filteredPools to set 134 | */ 135 | public void setFilteredPools(List filteredPools) { 136 | this.filteredPools = filteredPools; 137 | } 138 | 139 | @FacesConverter(forClass = Pool.class) 140 | public static class PoolControllerConverter implements Converter { 141 | 142 | @Override 143 | public Object getAsObject(FacesContext facesContext, UIComponent component, String value) { 144 | if (value == null || value.length() == 0) { 145 | return null; 146 | } 147 | PoolController controller = (PoolController) facesContext.getApplication().getELResolver(). 148 | getValue(facesContext.getELContext(), null, "poolController"); 149 | return controller.getPool(getKey(value)); 150 | } 151 | 152 | java.lang.Integer getKey(String value) { 153 | java.lang.Integer key; 154 | key = Integer.valueOf(value); 155 | return key; 156 | } 157 | 158 | String getStringKey(java.lang.Integer value) { 159 | StringBuilder sb = new StringBuilder(); 160 | sb.append(value); 161 | return sb.toString(); 162 | } 163 | 164 | @Override 165 | public String getAsString(FacesContext facesContext, UIComponent component, Object object) { 166 | if (object == null) { 167 | return null; 168 | } 169 | if (object instanceof Pool) { 170 | Pool o = (Pool) object; 171 | return getStringKey(o.getId()); 172 | } else { 173 | Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "object {0} is of type {1}; expected type: {2}", new Object[]{object, object.getClass().getName(), Pool.class.getName()}); 174 | return null; 175 | } 176 | } 177 | 178 | } 179 | 180 | public Pool findByPool(Pool pool){ 181 | Pool returnPool = null; 182 | try { 183 | returnPool = ejbFacade.findByPool(pool.getId()); 184 | } catch (NullPointerException ex){ 185 | System.out.println(ex); 186 | } 187 | return returnPool; 188 | } 189 | 190 | } 191 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/jsf/PoolCustomerController.java: -------------------------------------------------------------------------------- 1 | package com.acme.acmepools.jsf; 2 | 3 | import com.acme.acmepools.entity.PoolCustomer; 4 | import com.acme.acmepools.session.PoolCustomerFacade; 5 | import com.acme.acmepools.entity.util.JsfUtil; 6 | import com.acme.acmepools.entity.util.JsfUtil.PersistAction; 7 | 8 | import java.io.Serializable; 9 | import java.util.List; 10 | import java.util.ResourceBundle; 11 | import java.util.logging.Level; 12 | import java.util.logging.Logger; 13 | import javax.ejb.EJB; 14 | import javax.ejb.EJBException; 15 | import javax.inject.Named; 16 | import javax.enterprise.context.SessionScoped; 17 | import javax.faces.component.UIComponent; 18 | import javax.faces.context.FacesContext; 19 | import javax.faces.convert.Converter; 20 | import javax.faces.convert.FacesConverter; 21 | 22 | @Named("poolCustomerController") 23 | @SessionScoped 24 | public class PoolCustomerController implements Serializable { 25 | 26 | @EJB 27 | private com.acme.acmepools.session.PoolCustomerFacade ejbFacade; 28 | private List items = null; 29 | private PoolCustomer selected; 30 | 31 | public PoolCustomerController() { 32 | } 33 | 34 | public PoolCustomer getSelected() { 35 | return selected; 36 | } 37 | 38 | public void setSelected(PoolCustomer selected) { 39 | this.selected = selected; 40 | } 41 | 42 | protected void setEmbeddableKeys() { 43 | } 44 | 45 | protected void initializeEmbeddableKey() { 46 | } 47 | 48 | private PoolCustomerFacade getFacade() { 49 | return ejbFacade; 50 | } 51 | 52 | public PoolCustomer prepareCreate() { 53 | selected = new PoolCustomer(); 54 | initializeEmbeddableKey(); 55 | return selected; 56 | } 57 | 58 | public void create() { 59 | persist(PersistAction.CREATE, ResourceBundle.getBundle("/Bundle").getString("PoolCustomerCreated")); 60 | if (!JsfUtil.isValidationFailed()) { 61 | items = null; // Invalidate list of items to trigger re-query. 62 | } 63 | } 64 | 65 | public void update() { 66 | persist(PersistAction.UPDATE, ResourceBundle.getBundle("/Bundle").getString("PoolCustomerUpdated")); 67 | } 68 | 69 | public void destroy() { 70 | persist(PersistAction.DELETE, ResourceBundle.getBundle("/Bundle").getString("PoolCustomerDeleted")); 71 | if (!JsfUtil.isValidationFailed()) { 72 | selected = null; // Remove selection 73 | items = null; // Invalidate list of items to trigger re-query. 74 | } 75 | } 76 | 77 | public List getItems() { 78 | if (items == null) { 79 | items = getFacade().findAll(); 80 | } 81 | return items; 82 | } 83 | 84 | private void persist(PersistAction persistAction, String successMessage) { 85 | if (selected != null) { 86 | setEmbeddableKeys(); 87 | try { 88 | if (persistAction != PersistAction.DELETE) { 89 | getFacade().edit(selected); 90 | } else { 91 | getFacade().remove(selected); 92 | } 93 | JsfUtil.addSuccessMessage(successMessage); 94 | } catch (EJBException ex) { 95 | String msg = ""; 96 | Throwable cause = ex.getCause(); 97 | if (cause != null) { 98 | msg = cause.getLocalizedMessage(); 99 | } 100 | if (msg.length() > 0) { 101 | JsfUtil.addErrorMessage(msg); 102 | } else { 103 | JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured")); 104 | } 105 | } catch (Exception ex) { 106 | Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); 107 | JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured")); 108 | } 109 | } 110 | } 111 | 112 | public PoolCustomer getPoolCustomer(java.lang.Integer id) { 113 | return getFacade().find(id); 114 | } 115 | 116 | public List getItemsAvailableSelectMany() { 117 | return getFacade().findAll(); 118 | } 119 | 120 | public List getItemsAvailableSelectOne() { 121 | return getFacade().findAll(); 122 | } 123 | 124 | @FacesConverter(forClass = PoolCustomer.class) 125 | public static class PoolCustomerControllerConverter implements Converter { 126 | 127 | @Override 128 | public Object getAsObject(FacesContext facesContext, UIComponent component, String value) { 129 | if (value == null || value.length() == 0) { 130 | return null; 131 | } 132 | PoolCustomerController controller = (PoolCustomerController) facesContext.getApplication().getELResolver(). 133 | getValue(facesContext.getELContext(), null, "poolCustomerController"); 134 | return controller.getPoolCustomer(getKey(value)); 135 | } 136 | 137 | java.lang.Integer getKey(String value) { 138 | java.lang.Integer key; 139 | key = Integer.valueOf(value); 140 | return key; 141 | } 142 | 143 | String getStringKey(java.lang.Integer value) { 144 | StringBuilder sb = new StringBuilder(); 145 | sb.append(value); 146 | return sb.toString(); 147 | } 148 | 149 | @Override 150 | public String getAsString(FacesContext facesContext, UIComponent component, Object object) { 151 | if (object == null) { 152 | return null; 153 | } 154 | if (object instanceof PoolCustomer) { 155 | PoolCustomer o = (PoolCustomer) object; 156 | return getStringKey(o.getId()); 157 | } else { 158 | Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "object {0} is of type {1}; expected type: {2}", new Object[]{object, object.getClass().getName(), PoolCustomer.class.getName()}); 159 | return null; 160 | } 161 | } 162 | 163 | } 164 | 165 | } 166 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/rest/ApplicationConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.rest; 7 | 8 | import javax.ws.rs.core.Application; 9 | 10 | /** 11 | * 12 | * @author Juneau 13 | */ 14 | @javax.ws.rs.ApplicationPath("rest") 15 | public class ApplicationConfig extends Application { 16 | } 17 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/rest/SSEResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.rest; 7 | 8 | import javax.inject.Singleton; 9 | import javax.ws.rs.Consumes; 10 | import javax.ws.rs.FormParam; 11 | import javax.ws.rs.GET; 12 | import javax.ws.rs.POST; 13 | import javax.ws.rs.Path; 14 | import javax.ws.rs.Produces; 15 | import javax.ws.rs.core.Context; 16 | import javax.ws.rs.core.MediaType; 17 | import javax.ws.rs.sse.Sse; 18 | import javax.ws.rs.sse.SseBroadcaster; 19 | import javax.ws.rs.sse.SseEventSink; 20 | 21 | /** 22 | * 23 | * @author Juneau 24 | */ 25 | @Path("sse") 26 | public class SSEResource { 27 | 28 | public SSEResource(){ 29 | 30 | } 31 | 32 | @GET 33 | @Path("subscribe") 34 | @Produces(MediaType.SERVER_SENT_EVENTS) 35 | public void subscribe(@Context SseEventSink eventSink, 36 | @Context Sse sse){ 37 | eventSink.send(sse.newEvent("Welcome to the List!")); 38 | eventSink.send(sse.newEvent("Message One!")); 39 | eventSink.send(sse.newEvent("SERVER-NOTIFICATION", "Message Two!")); 40 | eventSink.send(sse.newEventBuilder() 41 | .comment("Nice Test") 42 | .name("SERVER-TEST") 43 | .data("Some data...could be an object") 44 | .build()); 45 | eventSink.close(); 46 | } 47 | 48 | } 49 | 50 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/servlet/DukeServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.servlet; 7 | 8 | import java.io.IOException; 9 | import java.io.PrintWriter; 10 | import javax.servlet.annotation.WebServlet; 11 | import javax.servlet.http.HttpServlet; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import javax.servlet.http.PushBuilder; 15 | 16 | /** 17 | * 18 | * @author Juneau 19 | */ 20 | @WebServlet(value = {"/DukeServlet"}) 21 | public class DukeServlet extends HttpServlet { 22 | 23 | @Override 24 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) { 25 | 26 | PushBuilder pushBuilder = req.newPushBuilder(); 27 | if (pushBuilder != null) { 28 | pushBuilder 29 | .path("resources/images/dukewaving.gif") 30 | .addHeader("content-type", "image/gif") 31 | .push(); 32 | // Push more than one resource 33 | // pushBuilder 34 | // .path("resources/images/dukewaving.gif") 35 | // .addHeader("content-type", "image/gif") 36 | // .push(); 37 | } 38 | try (PrintWriter respWriter = resp.getWriter();) { 39 | respWriter.write("" 40 | + "" 41 | + ""); 42 | } catch (IOException ex) { 43 | System.out.println(ex); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/servlet/SSETestServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.servlet; 7 | 8 | import java.io.IOException; 9 | import java.io.PrintWriter; 10 | import java.util.concurrent.TimeUnit; 11 | import javax.servlet.ServletException; 12 | import javax.servlet.annotation.WebServlet; 13 | import javax.servlet.http.HttpServlet; 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpServletResponse; 16 | import javax.ws.rs.client.ClientBuilder; 17 | import javax.ws.rs.client.Entity; 18 | import javax.ws.rs.client.WebTarget; 19 | import javax.ws.rs.sse.SseEventSource; 20 | 21 | /** 22 | * 23 | * @author Juneau 24 | */ 25 | @WebServlet("/SSETestServlet") 26 | public class SSETestServlet extends HttpServlet { 27 | 28 | private static final String SSE_SVC = "http://localhost:8080/AcmePools/rest/sse/subscribe"; 29 | 30 | @Override 31 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 32 | WebTarget target = ClientBuilder.newClient().target(SSE_SVC); 33 | try ( 34 | final SseEventSource eventSource 35 | = SseEventSource.target(target) 36 | .reconnectingEvery(5, TimeUnit.SECONDS) 37 | .build()) { 38 | eventSource.register(System.out::println); // InboundSseEvent consumer 39 | eventSource.open(); 40 | for(int counter = 0; counter < 3; counter ++){ 41 | target.request().post(Entity.text("message: " + counter)); 42 | } 43 | } catch (Exception e){ 44 | System.out.println("exception: " + e); 45 | } 46 | 47 | resp.setContentType("text/html"); 48 | PrintWriter out = resp.getWriter(); 49 | out.println(""); 50 | out.println("" 51 | + "Check server log..."); 52 | 53 | out.println(""); 54 | out.println(""); 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/session/AbstractFacade.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package com.acme.acmepools.session; 8 | 9 | import java.util.List; 10 | import javax.persistence.EntityManager; 11 | 12 | /** 13 | * 14 | * @author Juneau 15 | */ 16 | public abstract class AbstractFacade { 17 | private Class entityClass; 18 | 19 | public AbstractFacade(Class entityClass) { 20 | this.entityClass = entityClass; 21 | } 22 | 23 | protected abstract EntityManager getEntityManager(); 24 | 25 | public void create(T entity) { 26 | getEntityManager().persist(entity); 27 | } 28 | 29 | public void edit(T entity) { 30 | getEntityManager().merge(entity); 31 | } 32 | 33 | public void remove(T entity) { 34 | getEntityManager().remove(getEntityManager().merge(entity)); 35 | } 36 | 37 | public T find(Object id) { 38 | return getEntityManager().find(entityClass, id); 39 | } 40 | 41 | public List findAll() { 42 | javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); 43 | cq.select(cq.from(entityClass)); 44 | return getEntityManager().createQuery(cq).getResultList(); 45 | } 46 | 47 | public List findRange(int[] range) { 48 | javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); 49 | cq.select(cq.from(entityClass)); 50 | javax.persistence.Query q = getEntityManager().createQuery(cq); 51 | q.setMaxResults(range[1] - range[0] + 1); 52 | q.setFirstResult(range[0]); 53 | return q.getResultList(); 54 | } 55 | 56 | public int count() { 57 | javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); 58 | javax.persistence.criteria.Root rt = cq.from(entityClass); 59 | cq.select(getEntityManager().getCriteriaBuilder().count(rt)); 60 | javax.persistence.Query q = getEntityManager().createQuery(cq); 61 | return ((Long) q.getSingleResult()).intValue(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/session/ColumnModelFacade.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package com.acme.acmepools.session; 8 | 9 | import com.acme.acmepools.entity.ColumnModel; 10 | import javax.ejb.Stateless; 11 | import javax.persistence.EntityManager; 12 | import javax.persistence.PersistenceContext; 13 | 14 | /** 15 | * 16 | * @author Juneau 17 | */ 18 | @Stateless 19 | public class ColumnModelFacade extends AbstractFacade { 20 | @PersistenceContext(unitName = "AcmePools_2.0PU") 21 | private EntityManager em; 22 | 23 | @Override 24 | protected EntityManager getEntityManager() { 25 | return em; 26 | } 27 | 28 | public ColumnModelFacade() { 29 | super(ColumnModel.class); 30 | } 31 | 32 | public ColumnModel findId(String columnName){ 33 | return (ColumnModel) em.createQuery("select object(o) from ColumnModel as o " + 34 | "where o.columnName = :columnName") 35 | .setParameter("columnName", columnName) 36 | .getSingleResult(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/session/CustomerFacade.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package com.acme.acmepools.session; 8 | 9 | import com.acme.acmepools.entity.Customer; 10 | import javax.ejb.Stateless; 11 | import javax.persistence.EntityManager; 12 | import javax.persistence.PersistenceContext; 13 | 14 | /** 15 | * 16 | * @author Juneau 17 | */ 18 | @Stateless 19 | public class CustomerFacade extends AbstractFacade { 20 | @PersistenceContext(unitName = "AcmePools_2.0PU") 21 | private EntityManager em; 22 | 23 | @Override 24 | protected EntityManager getEntityManager() { 25 | return em; 26 | } 27 | 28 | public CustomerFacade() { 29 | super(Customer.class); 30 | } 31 | 32 | /** 33 | * Returns a Customer object for a given customerId 34 | * @param customerId 35 | * @return 36 | */ 37 | public Customer findByCustomerId(Integer customerId){ 38 | return (Customer) em.createNamedQuery("Customer.findByCustomerId") 39 | .setParameter("customerId", customerId) 40 | .getSingleResult(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/session/DiscountCodeFacade.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.session; 7 | 8 | import com.acme.acmepools.entity.DiscountCode; 9 | import javax.ejb.Stateless; 10 | import javax.persistence.EntityManager; 11 | import javax.persistence.PersistenceContext; 12 | 13 | /** 14 | * 15 | * @author Juneau 16 | */ 17 | @Stateless 18 | public class DiscountCodeFacade extends AbstractFacade { 19 | 20 | @PersistenceContext(unitName = "AcmePools_2.0PU") 21 | private EntityManager em; 22 | 23 | @Override 24 | protected EntityManager getEntityManager() { 25 | return em; 26 | } 27 | 28 | public DiscountCodeFacade() { 29 | super(DiscountCode.class); 30 | } 31 | 32 | /** 33 | * Return a DiscountCode object, given a specified discount code string. 34 | * @param discountCode 35 | * @return 36 | */ 37 | public DiscountCode findByCode(String discountCode){ 38 | return (DiscountCode) em.createQuery("select object(o) from DiscountCode o " + 39 | "where o.discountCode = :discountCode") 40 | .setParameter("discountCode", discountCode) 41 | .getSingleResult(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/session/JobFacade.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package com.acme.acmepools.session; 8 | 9 | import com.acme.acmepools.entity.Customer; 10 | import com.acme.acmepools.entity.Job; 11 | import com.acme.acmepools.entity.PoolCustomer; 12 | import java.util.List; 13 | import java.util.stream.Collectors; 14 | import java.util.stream.Stream; 15 | import javax.ejb.Stateless; 16 | import javax.persistence.EntityManager; 17 | import javax.persistence.PersistenceContext; 18 | 19 | /** 20 | * 21 | * @author Juneau 22 | */ 23 | @Stateless 24 | public class JobFacade extends AbstractFacade { 25 | 26 | @PersistenceContext(unitName = "AcmePools_2.0PU") 27 | private EntityManager em; 28 | 29 | @Override 30 | protected EntityManager getEntityManager() { 31 | return em; 32 | } 33 | 34 | public JobFacade() { 35 | super(Job.class); 36 | } 37 | 38 | public List findByCustomer(PoolCustomer customer){ 39 | Stream jobList = em.createQuery("select object(o) from Job o " + 40 | "where o.customerId = :customer") 41 | .setParameter("customer", customer).getResultStream(); 42 | // Log the retrieved jobs for some other processing. Commented out because it is only possible to perform 43 | // one opertation on the stream. 44 | // 45 | // jobList.map(j -> j.getCustomerId().getCustomerId().getCustomerId() + " ordered job " + j.getId() + " - Starting " + j.getWorkDate()) 46 | // .forEach(jm -> System.out.println(jm)); 47 | return jobList.collect(Collectors.toList()); 48 | } 49 | 50 | /** 51 | * Returns a List of customers by specified pool shape 52 | * @param poolShape 53 | * @return 54 | */ 55 | public List findByCustPoolShape(String poolShape){ 56 | System.out.println("Finding " + poolShape + " shaped pools..."); 57 | Stream jobstream = em.createQuery("select object(o) from Job o").getResultStream(); 58 | 59 | return jobstream.filter( 60 | c -> poolShape.equals(c.getCustomerId().getPoolId().getShape())) 61 | .collect(Collectors.toList()); 62 | 63 | } 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/session/MicroMarketFacade.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.session; 7 | 8 | import com.acme.acmepools.entity.MicroMarket; 9 | import javax.ejb.Stateless; 10 | import javax.persistence.EntityManager; 11 | import javax.persistence.PersistenceContext; 12 | 13 | /** 14 | * 15 | * @author Juneau 16 | */ 17 | @Stateless 18 | public class MicroMarketFacade extends AbstractFacade { 19 | 20 | @PersistenceContext(unitName = "AcmePools_2.0PU") 21 | private EntityManager em; 22 | 23 | @Override 24 | protected EntityManager getEntityManager() { 25 | return em; 26 | } 27 | 28 | public MicroMarketFacade() { 29 | super(MicroMarket.class); 30 | } 31 | 32 | /** 33 | * Returns MicroMarket for the specified zipCode. 34 | * @param zipCode 35 | * @return 36 | */ 37 | public MicroMarket findByZipCode(String zipCode){ 38 | return (MicroMarket) em.createQuery("select object(o) from MicroMarket o " + 39 | "where o.zipCode = :zipCode") 40 | .setParameter("zipCode", zipCode) 41 | .getSingleResult(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/session/PoolCustomerFacade.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package com.acme.acmepools.session; 8 | 9 | import com.acme.acmepools.entity.Customer; 10 | import com.acme.acmepools.entity.PoolCustomer; 11 | import java.util.List; 12 | import javax.ejb.Stateless; 13 | import javax.persistence.EntityManager; 14 | import javax.persistence.PersistenceContext; 15 | 16 | /** 17 | * 18 | * @author Juneau 19 | */ 20 | @Stateless 21 | public class PoolCustomerFacade extends AbstractFacade { 22 | @PersistenceContext(unitName = "AcmePools_2.0PU") 23 | private EntityManager em; 24 | 25 | @Override 26 | protected EntityManager getEntityManager() { 27 | return em; 28 | } 29 | 30 | public PoolCustomerFacade() { 31 | super(PoolCustomer.class); 32 | } 33 | 34 | /** 35 | * Returns a List object for a given Customer 36 | * @param customer 37 | * @return 38 | */ 39 | public List findByCustomerId(Customer customer){ 40 | return em.createQuery("select object(o) from PoolCustomer o " + 41 | "where o.customerId = :customerId") 42 | .setParameter("customerId", customer) 43 | .getResultList(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/session/PoolFacade.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package com.acme.acmepools.session; 8 | 9 | import com.acme.acmepools.entity.Pool; 10 | import com.acme.acmepools.session.AbstractFacade; 11 | import javax.ejb.Stateless; 12 | import javax.persistence.EntityManager; 13 | import javax.persistence.PersistenceContext; 14 | 15 | /** 16 | * 17 | * @author Juneau 18 | */ 19 | @Stateless 20 | public class PoolFacade extends AbstractFacade { 21 | @PersistenceContext(unitName = "AcmePools_2.0PU") 22 | private EntityManager em; 23 | 24 | @Override 25 | protected EntityManager getEntityManager() { 26 | return em; 27 | } 28 | 29 | public PoolFacade() { 30 | super(Pool.class); 31 | } 32 | 33 | /** 34 | * Returns a Pool for a given poolId. 35 | * @param pool 36 | * @return 37 | */ 38 | public Pool findByPool(Integer poolId){ 39 | return (Pool) em.createQuery("select object(o) from Pool o " + 40 | "where o.id = :id") 41 | .setParameter("id", poolId).getSingleResult(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /AcmePools/src/main/java/com/acme/acmepools/utility/CreditLimitEncryptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package com.acme.acmepools.utility; 7 | 8 | import java.io.IOException; 9 | import java.io.UnsupportedEncodingException; 10 | import javax.enterprise.context.RequestScoped; 11 | import javax.inject.Named; 12 | import sun.misc.BASE64Decoder; 13 | import sun.misc.BASE64Encoder; 14 | 15 | /** 16 | * 17 | * @author Juneau 18 | */ 19 | @Named 20 | @RequestScoped 21 | public class CreditLimitEncryptor { 22 | public static final String DEFAULT_ENCODING = "UTF-8"; 23 | static BASE64Encoder enc = new BASE64Encoder(); 24 | static BASE64Decoder dec = new BASE64Decoder(); 25 | 26 | public String base64encode(String text) { 27 | try { 28 | return enc.encode(text.getBytes(DEFAULT_ENCODING)); 29 | } catch (UnsupportedEncodingException e) { 30 | return null; 31 | } 32 | } 33 | 34 | public String base64decode(String text) { 35 | try { 36 | return new String(dec.decodeBuffer(text), DEFAULT_ENCODING); 37 | } catch (IOException e) { 38 | return null; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /AcmePools/src/main/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | jdbc/sample 5 | false 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /AcmePools/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/WEB-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/WEB-INF/faces-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | /Bundle 9 | bundle 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | javax.faces.PROJECT_STAGE 7 | Development 8 | 9 | 10 | javax.faces.ENABLE_CDI_RESOLVER_CHAIN 11 | true 12 | 13 | 14 | javax.faces.validator.ENABLE_VALIDATE_WHOLE_BEAN 15 | true 16 | 17 | 18 | javax.faces.ENABLE_WEBSOCKET_ENDPOINT 19 | true 20 | 21 | 22 | Faces Servlet 23 | javax.faces.webapp.FacesServlet 24 | 1 25 | 26 | 27 | Faces Servlet 28 | /faces/* 29 | 30 | 31 | 32 | 33 | 30 34 | 35 | 36 | 37 | faces/index.xhtml 38 | 39 | 40 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/customer/Create.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/customer/Edit.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/customer/List.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 |
150 | 151 | 152 | 153 | 154 |
155 |
156 | 157 | 158 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/customer/View.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/customersJson.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Start Page 5 | 6 | 7 | 8 |

Hello World!

9 | 10 | 11 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/index.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
57 | 58 | 59 | 60 |

61 | 63 |
64 |
65 | 66 | 67 |
68 |
69 |
70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/job/Create.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/job/Edit.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/job/JobsByShape.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/job/List.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/job/View.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/pool/Create.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/pool/Edit.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/pool/List.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/pool/View.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/poolCustomer/Create.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 23 | 24 | 25 | 26 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/poolCustomer/CustomerExport.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 29 | Columns 30 | Selected 31 | 32 | 33 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |
43 | 44 | 45 | 46 | 47 | 48 | 51 | 52 |
53 |
54 |
55 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/poolCustomer/Edit.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/poolCustomer/List.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/poolCustomer/View.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/resources/css/jsfcrud.css: -------------------------------------------------------------------------------- 1 | .ui-widget { 2 | font-size: 12px !important; 3 | } 4 | .ui-layout-north { 5 | z-index: 20 !important; 6 | overflow: visible !important;; 7 | } 8 | .ui-layout-north .ui-layout-unit-content { 9 | overflow: visible !important; 10 | } 11 | .ui-widget-header { 12 | text-align: center; 13 | text-transform: uppercase; 14 | } 15 | .ui-datatable-footer .ui-button { 16 | float: left; 17 | margin-top: 25px !important; 18 | } 19 | 20 | .ui-button { 21 | margin-top: 10px !important; 22 | } 23 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/resources/images/dukewaving.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaee-samples/javaee8-applications/b46a28d0c48023cdd270fe9224a39ab633e2094d/AcmePools/src/main/webapp/resources/images/dukewaving.gif -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/resources/images/excel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaee-samples/javaee8-applications/b46a28d0c48023cdd270fe9224a39ab633e2094d/AcmePools/src/main/webapp/resources/images/excel.png -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/resources/js/jsfcrud.js: -------------------------------------------------------------------------------- 1 | function handleSubmit(args, dialog) { 2 | var jqDialog = jQuery('#' + dialog); 3 | if (args.validationFailed) { 4 | jqDialog.effect('shake', {times: 3}, 100); 5 | } else { 6 | PF(dialog).hide(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /AcmePools/src/main/webapp/template.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | <ui:insert name="title">Default Title</ui:insert> 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 JavaEE Samples 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # javaee8-applications 2 | Java EE 8 example applications 3 | -------------------------------------------------------------------------------- /environment-aware-configuration/.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # Default excludes 3 | # 4 | 5 | # Binaries 6 | *.7z 7 | *.dmg 8 | *.gz 9 | *.iso 10 | *.jar 11 | *.rar 12 | *.tar 13 | *.zip 14 | *.war 15 | *.ear 16 | *.sar 17 | *.class 18 | 19 | # Maven 20 | target/ 21 | 22 | # IntelliJ project files 23 | *.iml 24 | *.iws 25 | *.ipr 26 | .idea/ 27 | 28 | # eclipse project file 29 | .settings/ 30 | .classpath 31 | .project 32 | 33 | # NetBeans specific 34 | nbproject/private/ 35 | build/ 36 | nbbuild/ 37 | dist/ 38 | nbdist/ 39 | nbactions.xml 40 | nb-configuration.xml 41 | 42 | 43 | # OS 44 | .DS_Store 45 | 46 | # Misc 47 | *.swp 48 | release.properties 49 | pom.xml.releaseBackup 50 | pom.xml.tag 51 | /backend/derby.log 52 | 53 | -------------------------------------------------------------------------------- /environment-aware-configuration/README.md: -------------------------------------------------------------------------------- 1 | # Environment Aware 2 | 3 | This project was made using this archetype that I created: [javaee8-archetype](https://github.com/felipe-alves-moraes/javaee8-archetype) 4 | 5 | With this approach I set my datasource configuration based on the environment that I was building my project. 6 | 7 | The idea here is that you application should only have references of the environment around it through known variables. 8 | 9 | To do this I've used [payara variable substitution](https://docs.payara.fish/documentation/payara-server/server-configuration/var-substitution/types-of-variables.html) feature. 10 | 11 | This way I was able to let the environment handle infrastructure configuration. 12 | 13 | You can check the configuration inside the `web.xml` file and in each of the docker env-files inside the docker folder. 14 | 15 | ## Cons of this approach 16 | When in development process you will have to set the environment variables in your machine or in you IDE. (This is not hard to achieve but some people may find this annoying) 17 | 18 | Vendor dependent configuration. 19 | 20 | ## Pros 21 | Simple configuration of resources. 22 | 23 | Don't need to do any magical trick in you app to handle configuration. 24 | 25 | CI/CD ready configuration. 26 | 27 | # Build 28 | `mvn clean package && docker build -f ./docker/Dockerfile -t br.com.fmoraes/environment-aware-configuration .` 29 | 30 | # RUN 31 | 32 | `docker rm -f environment-aware-configuration || true && docker run --env-file=./docker/local_env_properties -d -p 8080:8080 -p 4848:4848 --name environment-aware-configuration br.com.fmoraes/environment-aware-configuration` 33 | 34 | You can also run the application using the script `buildAndRun.sh` by default it will pick the `local_env_properties` file to run docker, you can change it passing one of the following envs as argument: `dev`, `stage` and `prod`. 35 | 36 | To run it locally in you IDE you have to configure these Environment Variables: 37 | 38 | ``` 39 | DATASOURCE_CLASS=org.apache.derby.jdbc.ClientDriver 40 | DB_ENGINE=derby 41 | DB_URL=//host.docker.internal:1527/environment-aware-configuration 42 | DB_USER=app 43 | DB_PASSWORD=app 44 | ``` 45 | 46 | OBS. You need to have a local instance of Apache Derby(Java DB) running in you local machine to this project to work, or configure any DB that you want changing the configuration files. 47 | -------------------------------------------------------------------------------- /environment-aware-configuration/buildAndRun.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ENV=$1 3 | 4 | if [ -z "$ENV" ] 5 | then 6 | ENV='local' 7 | fi 8 | ENV_FILE="$ENV"_"env_properties" 9 | 10 | mvn clean package && docker build -f ./docker/Dockerfile -t br.com.fmoraes/environment-aware-configuration . 11 | docker rm -f environment-aware-configuration || true && docker run --env-file=./docker/$ENV_FILE -d -p 8080:8080 -p 4848:4848 --name environment-aware-configuration br.com.fmoraes/environment-aware-configuration 12 | -------------------------------------------------------------------------------- /environment-aware-configuration/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM payara/micro:5.182 2 | 3 | ADD ./target/libs /opt/libs 4 | 5 | COPY ./target/environment-aware-configuration.war ${DEPLOY_DIR} 6 | 7 | ENTRYPOINT ["java", "-jar", "/opt/payara/payara-micro.jar", \ 8 | "--addLibs", "/opt/libs/", \ 9 | "--deploy", "/opt/payara/deployments/environment-aware-configuration.war"] 10 | -------------------------------------------------------------------------------- /environment-aware-configuration/docker/dev_env_properties: -------------------------------------------------------------------------------- 1 | DATASOURCE_CLASS=org.apache.derby.jdbc.ClientDriver 2 | DB_ENGINE=derby 3 | DB_URL=//host.docker.internal:1527/environment-aware-configuration 4 | DB_USER=app 5 | DB_PASSWORD=app -------------------------------------------------------------------------------- /environment-aware-configuration/docker/local_env_properties: -------------------------------------------------------------------------------- 1 | DATASOURCE_CLASS=org.apache.derby.jdbc.ClientDriver 2 | DB_ENGINE=derby 3 | DB_URL=//host.docker.internal:1527/environment-aware-configuration 4 | DB_USER=app 5 | DB_PASSWORD=app -------------------------------------------------------------------------------- /environment-aware-configuration/docker/prod_env_properties: -------------------------------------------------------------------------------- 1 | DATASOURCE_CLASS=org.apache.derby.jdbc.ClientDriver 2 | DB_ENGINE=derby 3 | DB_URL=//host.docker.internal:1527/environment-aware-configuration 4 | DB_USER=app 5 | DB_PASSWORD=app -------------------------------------------------------------------------------- /environment-aware-configuration/docker/stage_env_properties: -------------------------------------------------------------------------------- 1 | DATASOURCE_CLASS=org.apache.derby.jdbc.ClientDriver 2 | DB_ENGINE=derby 3 | DB_URL=//host.docker.internal:1527/environment-aware-configuration 4 | DB_USER=app 5 | DB_PASSWORD=app -------------------------------------------------------------------------------- /environment-aware-configuration/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | br.com.fmoraes 5 | environment-aware-configuration 6 | 1.0-SNAPSHOT 7 | war 8 | 9 | 10 | javax 11 | javaee-api 12 | 8.0 13 | provided 14 | 15 | 16 | org.eclipse.microprofile 17 | microprofile 18 | 1.3 19 | pom 20 | provided 21 | 22 | 23 | junit 24 | junit 25 | 4.12 26 | test 27 | 28 | 29 | org.apache.derby 30 | derbyclient 31 | 10.14.2.0 32 | 33 | 34 | 35 | 36 | environment-aware-configuration 37 | 38 | 39 | fish.payara.maven.plugins 40 | payara-micro-maven-plugin 41 | ${payaramicro.maven.plugin.version} 42 | 43 | true 44 | 45 | 48 | 52 | 53 | 54 | 58 | 59 | 60 | 61 | 62 | maven-war-plugin 63 | 3.2.2 64 | 65 | WEB-INF/lib/*.jar 66 | 67 | 68 | 69 | org.apache.maven.plugins 70 | maven-dependency-plugin 71 | 3.1.1 72 | 73 | 74 | copy-dependencies 75 | package 76 | 77 | copy-dependencies 78 | 79 | 80 | ${project.build.directory}/libs 81 | runtime 82 | provided 83 | 84 | 85 | 86 | 87 | 88 | org.liquibase 89 | liquibase-maven-plugin 90 | 3.6.1 91 | 92 | src/main/resources/liquibase/liquibase-${liquibase.env}.properties 93 | 94 | 95 | 96 | org.apache.derby 97 | derbyclient 98 | 10.14.2.0 99 | 100 | 101 | 102 | 103 | 104 | 105 | 1.8 106 | 1.8 107 | false 108 | 1.0.1 109 | local 110 | 111 | environment-aware-configuration 112 | 113 | -------------------------------------------------------------------------------- /environment-aware-configuration/src/main/java/br/com/fmoraes/environmentawareconfiguration/JAXRSConfiguration.java: -------------------------------------------------------------------------------- 1 | package br.com.fmoraes.environmentawareconfiguration; 2 | 3 | import javax.ws.rs.ApplicationPath; 4 | import javax.ws.rs.core.Application; 5 | 6 | @ApplicationPath("resources") 7 | public class JAXRSConfiguration extends Application { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /environment-aware-configuration/src/main/java/br/com/fmoraes/environmentawareconfiguration/model/Person.java: -------------------------------------------------------------------------------- 1 | package br.com.fmoraes.environmentawareconfiguration.model; 2 | 3 | import java.io.Serializable; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.GenerationType; 7 | import javax.persistence.Id; 8 | 9 | /** 10 | * 11 | * @author fmoraes 12 | */ 13 | @Entity 14 | public class Person implements Serializable { 15 | 16 | @Id 17 | @GeneratedValue(strategy = GenerationType.AUTO) 18 | private Long id; 19 | private String name; 20 | 21 | protected Person() { 22 | 23 | } 24 | 25 | public Person(String name) { 26 | this.name = name; 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /environment-aware-configuration/src/main/java/br/com/fmoraes/environmentawareconfiguration/resources/PersonResource.java: -------------------------------------------------------------------------------- 1 | package br.com.fmoraes.environmentawareconfiguration.resources; 2 | 3 | import br.com.fmoraes.environmentawareconfiguration.model.Person; 4 | import javax.ejb.Stateless; 5 | import javax.persistence.EntityManager; 6 | import javax.persistence.PersistenceContext; 7 | import javax.ws.rs.POST; 8 | import javax.ws.rs.Path; 9 | 10 | /** 11 | * 12 | * @author fmoraes 13 | */ 14 | @Path("person") 15 | @Stateless 16 | public class PersonResource { 17 | 18 | @PersistenceContext 19 | private EntityManager em; 20 | 21 | @POST 22 | public void create() { 23 | em.persist(new Person("Felipe")); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /environment-aware-configuration/src/main/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | java:app/datasources/environment-aware-configurationDS 5 | false 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /environment-aware-configuration/src/main/resources/liquibase/changelog/db.changelog-master.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /environment-aware-configuration/src/main/resources/liquibase/liquibase-dev.properties: -------------------------------------------------------------------------------- 1 | changeLogFile: liquibase/changelog/db.changelog-master.xml 2 | driver: org.apache.derby.jdbc.ClientDriver 3 | url: jdbc:derby://localhost:1527/environment-aware-configuration_dev 4 | username: app 5 | password: app 6 | verbose: true -------------------------------------------------------------------------------- /environment-aware-configuration/src/main/resources/liquibase/liquibase-local.properties: -------------------------------------------------------------------------------- 1 | changeLogFile: liquibase/changelog/db.changelog-master.xml 2 | driver: org.apache.derby.jdbc.ClientDriver 3 | url: jdbc:derby://localhost:1527/environment-aware-configuration 4 | username: app 5 | password: app 6 | verbose: true -------------------------------------------------------------------------------- /environment-aware-configuration/src/main/resources/liquibase/liquibase-prod.properties: -------------------------------------------------------------------------------- 1 | changeLogFile: liquibase/changelog/db.changelog-master.xml 2 | driver: org.apache.derby.jdbc.ClientDriver 3 | url: jdbc:derby://localhost:1527/environment-aware-configuration_prod 4 | username: app 5 | password: app 6 | verbose: true -------------------------------------------------------------------------------- /environment-aware-configuration/src/main/resources/liquibase/liquibase-stage.properties: -------------------------------------------------------------------------------- 1 | changeLogFile: liquibase/changelog/db.changelog-master.xml 2 | driver: org.apache.derby.jdbc.ClientDriver 3 | url: jdbc:derby://localhost:1527/environment-aware-configuration_stage 4 | username: app 5 | password: app 6 | verbose: true -------------------------------------------------------------------------------- /environment-aware-configuration/src/main/webapp/WEB-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /environment-aware-configuration/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | java:app/datasources/environment-aware-configurationDS 10 | ${ENV=DATASOURCE_CLASS} 11 | jdbc:${ENV=DB_ENGINE}:${ENV=DB_URL} 12 | ${ENV=DB_USER} 13 | ${ENV=DB_PASSWORD} 14 | 30 15 | 10 16 | 17 | 18 | 19 | --------------------------------------------------------------------------------