diff --git a/pom.xml b/pom.xml new file mode 100755 index 0000000..6b0b456 --- /dev/null +++ b/pom.xml @@ -0,0 +1,352 @@ + + + 4.0.0 + + org.prabuckt.application + vegancakes + 8.0 + Vegan Cakes store + war + + + 8.0 + 1.0.4.Final + 2.8.2 + + 4.12 + 1.1.15.2 + 4.0.0.Alpha1 + 1.2.6 + 1.0.0.Alpha4 + 3.1.4.Final + 10.10.1.1 + 1.7.8 + + 11.0.0.Final + + 3.4.1 + 3.6.0 + 10.0.0 + 1.0.10 + 4.7.0 + + 1.5.17 + + 3.3.1 + 3.1 + 2.10 + 2.19.1 + 2.19.1 + 3.1.6 + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + + org.arquillian + arquillian-universe + ${version.arquillian} + pom + import + + + junit + junit + ${version.junit} + test + + + org.apache.logging.log4j + log4j-core + ${version.log4j} + + + org.webjars + bootstrap + ${version.bootstrap} + + + org.webjars + jquery + ${version.jquery} + + + org.primefaces + primefaces + ${version.primefaces} + + + org.primefaces.themes + all-themes + ${version.primefaces-themes} + + + org.webjars.bower + fontawesome + ${version.fontawesome} + + + org.jboss.spec + jboss-javaee-8.0 + ${version.jboss-javaee} + pom + provided + + + org.jboss.resteasy + resteasy-client + ${version.resteasy} + test + + + nl.jqno.equalsverifier + equalsverifier + ${version.equalsverifier} + test + + + + + + + io.swagger + swagger-annotations + ${version.swagger} + + + org.apache.logging.log4j + log4j-core + + + org.webjars + bootstrap + + + org.webjars + jquery + + + org.primefaces + primefaces + + + org.primefaces.themes + all-themes + + + org.webjars.bower + fontawesome + + + org.jboss.spec + jboss-javaee-8.0 + pom + provided + + + + junit + junit + + + nl.jqno.equalsverifier + equalsverifier + + + org.arquillian.universe + arquillian-junit + test + pom + + + org.jboss.shrinkwrap + shrinkwrap-api + ${version.shrinkwrap} + test + + + org.jboss.arquillian.extension + arquillian-rest-client-api + ${version.arquillian.rest} + test + + + org.jboss.arquillian.extension + arquillian-rest-client-impl-3x + ${version.arquillian.rest} + test + + + org.jboss.resteasy + resteasy-jackson-provider + ${version.resteasy} + test + + + + + applicationVegancakes + + + org.apache.maven.plugins + maven-war-plugin + ${version.maven.war.plugin} + + false + + + + com.github.kongchen + swagger-maven-plugin + ${version.swagger.plugin} + + + + false + org.prabuckt.application.vegancakes.rest + http,https + localhost:8080 + /applicationVegancakes/rest + json + + Vegancakes APIs + 1.0.0 + VeganCakes APIs exposed + + prabuckt@uni.coventry.ac.uk + Tomasz Prabucki + https://tprabucki.netlify.com/ + + + ${basedir}/src/main/webapp + true + + + + + + compile + + generate + + + + + + io.swagger + swagger-hibernate-validations + ${version.swagger} + + + + + + + + + arquillian-wildfly-remote + + + + maven-surefire-plugin + ${version.maven.surefire.plugin} + + + arquillian-wildfly-remote + + + + + + + + org.wildfly.arquillian + wildfly-arquillian-container-remote + ${version.arquillian.wildfly} + test + + + + + + arquillian-wildfly-managed + + + + org.apache.maven.plugins + maven-dependency-plugin + ${version.maven.dependency.plugin} + + + unpack + process-test-classes + + unpack + + + + + org.wildfly + wildfly-dist + ${version.wildfly} + zip + false + ${project.build.directory} + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${version.maven.surefire.plugin} + + false + + arquillian-wildfly-managed + + + + + + + + org.wildfly.arquillian + wildfly-arquillian-container-managed + ${version.arquillian.wildfly} + test + + + + + + + + + central + Maven Central + default + https://repo1.maven.org/maven2 + + + jboss + Jboss + default + https://repository.jboss.org/nexus/content/repositories/thirdparty-releases/ + + + primefaces + https://repository.primefaces.org/ + + + + diff --git a/src/main/docker/postgresql.yml b/src/main/docker/postgresql.yml new file mode 100644 index 0000000..03dd9f3 --- /dev/null +++ b/src/main/docker/postgresql.yml @@ -0,0 +1,6 @@ +version: '2' +services: + sponsor-postgresql: + image: postgres:9.6.5 + ports: + - 5432:5432 diff --git a/src/main/forge/generate.fsh b/src/main/forge/generate.fsh new file mode 100644 index 0000000..1da6c05 --- /dev/null +++ b/src/main/forge/generate.fsh @@ -0,0 +1,508 @@ +# ############## # +# Install Addons # +# ############## # +# If the following plugins are not installed +# addon-install-from-git --url https://github.com/forge/addon-arquillian.git --coordinate org.arquillian.forge:arquillian-addon + + + +# ##################### # +# Creates a new project # +# ##################### # + +project-new --named prabuckt-application-vegancakes-ee7 --topLevelPackage org.prabuckt.application.vegancakes --type war --finalName applicationVegancakes --version 7.0 ; + + +# Setup the deployment descriptors to Java EE 7 +# ############ +jpa-setup --persistenceUnitName applicationVegancakesPU --jpaVersion 2.1 ; +cdi-setup --cdiVersion 1.1 ; +ejb-setup --ejbVersion 3.2 ; +faces-setup --facesVersion 2.2 ; +servlet-setup --servletVersion 3.1 ; +rest-setup --jaxrsVersion 2.0 ; + +# Setup Arquillian +# ############ +arquillian-setup --arquillianVersion 1.1.8.Final --testFramework junit --testFrameworkVersion 4.12 --containerAdapter wildfly-remote --containerAdapterVersion 8.2.0.Final ; + + + +# ################### # +# Creates constraints # +# ################### # + +constraint-new-annotation --named Email ; +constraint-new-annotation --named Login ; +constraint-new-annotation --named NotEmpty ; +constraint-new-annotation --named Price ; + + + +# ######################## # +# Creates the domain model # +# ######################## # + +# TODO Command java-new-package-info to create a new package-info.java class [FORGE-2071] +# Package Vetoed +# ############ +java-new-package --named org.prabuckt.application.vegancakes.model --createPackageInfo ; +# java-add-annotation --annotation javax.enterprie.inject.Vetoed --targetClass org.prabuckt.application.vegancakes.model.package-info ; + + +# User role enumeration +# ############ +java-new-enum --named UserRole --targetPackage ~.model ; +java-new-enum-const USER ; +java-new-enum-const ADMIN ; + + +# Country entity +# ############ +jpa-new-entity --named Country ; +jpa-new-field --named isoCode --length 2 --columnName iso_code --not-nullable ; +jpa-new-field --named name --length 80 --not-nullable ; +jpa-new-field --named printableName --length 80 --columnName printable_name --not-nullable ; +jpa-new-field --named iso3 --length 3 ; +jpa-new-field --named numcode --length 3 ; +# Constraints +constraint-add --onProperty isoCode --constraint NotNull ; +constraint-add --onProperty isoCode --constraint Size --min 2 --max 2 ; +constraint-add --onProperty name --constraint NotNull ; +constraint-add --onProperty name --constraint Size --min 2 --max 80 ; +constraint-add --onProperty printableName --constraint NotNull ; +constraint-add --onProperty printableName --constraint Size --min 2 --max 80 ; +constraint-add --onProperty iso3 --constraint NotNull ; +constraint-add --onProperty iso3 --constraint Size --min 3 --max 3 ; +constraint-add --onProperty numcode --constraint NotNull ; +constraint-add --onProperty numcode --constraint Size --min 3 --max 3 ; +# Cache +java-add-annotation --annotation javax.persistence.Cacheable ; + + +# Address embeddable +# ############ +jpa-new-embeddable --named Address ; +jpa-new-field --named street1 --length 50 --not-nullable ; +jpa-new-field --named street2 ; +jpa-new-field --named city --length 50 --not-nullable ; +jpa-new-field --named state ; +jpa-new-field --named postcode --columnName zip_code --length 10 --not-nullable ; +# Relationships +jpa-new-field --named country --type Country --relationshipType Many-to-One --cascadeType PERSIST ; +# Constraints +constraint-add --onProperty street1 --constraint Size --min 5 --max 50 ; +constraint-add --onProperty street1 --constraint NotNull ; +constraint-add --onProperty city --constraint Size --min 2 --max 50 ; +constraint-add --onProperty city --constraint NotNull ; +constraint-add --onProperty postcode --constraint Size --min 1 --max 10 ; +constraint-add --onProperty postcode --constraint NotNull ; + + +# Customer entity +# ############ +jpa-new-entity --named Customer ; +jpa-new-field --named firstName --length 50 --columnName first_name --not-nullable ; +jpa-new-field --named lastName --length 50 --columnName last_name --not-nullable ; +jpa-new-field --named telephone ; +jpa-new-field --named email ; +jpa-new-field --named login --length 10 --not-nullable ; +jpa-new-field --named password --length 256 --not-nullable ; +jpa-new-field --named uuid --length 256 ; +jpa-new-field --named UserRole --type ~.model.UserRole --columnName user_role ; +jpa-new-field --named dateOfBirth --type java.util.Date --temporalType DATE --columnName date_of_birth ; +jpa-new-field --named age --type java.lang.Integer --transient ; +# Address embeddable +jpa-new-field --named street1 --length 50 ; +jpa-new-field --named street2 ; +jpa-new-field --named city --length 50 ; +jpa-new-field --named state ; +jpa-new-field --named postcode --columnName zip_code --length 10 ; +# Relationships +jpa-new-field --named country --type Country --relationshipType Many-to-One ; +# Constraints +# TODO constraint-add --onProperty login --constraint Login ; +constraint-add --onProperty password --constraint NotNull ; +constraint-add --onProperty password --constraint Size --min 1 --max 256 ; +constraint-add --onProperty firstName --constraint NotNull ; +constraint-add --onProperty firstName --constraint Size --min 2 --max 50 ; +constraint-add --onProperty lastName --constraint NotNull ; +constraint-add --onProperty lastName --constraint Size --min 2 --max 50 ; +constraint-add --onProperty dateOfBirth --constraint Past ; + + +# Category entity +# ############ +jpa-new-entity --named Category ; +jpa-new-field --named name --length 30 --not-nullable ; +jpa-new-field --named description --length 3000 --not-nullable ; +# Constraints +constraint-add --onProperty name --constraint NotNull ; +constraint-add --onProperty name --constraint Size --min 1 --max 30 ; +constraint-add --onProperty description --constraint NotNull ; +constraint-add --onProperty description --constraint Size --max 3000 ; +# Cache +java-add-annotation --annotation javax.persistence.Cacheable ; + + +# Product entity +# ############ +jpa-new-entity --named Product ; +jpa-new-field --named name --length 30 --not-nullable ; +jpa-new-field --named description --length 3000 --not-nullable ; +# Relationships +jpa-new-field --named category --type Category --relationshipType Many-to-One --cascadeType PERSIST ; +# Constraints +constraint-add --onProperty name --constraint NotNull ; +constraint-add --onProperty name --constraint Size --min 1 --max 30 ; +constraint-add --onProperty description --constraint NotNull ; +constraint-add --onProperty description --constraint Size --max 3000 ; +# Cache +java-add-annotation --annotation javax.persistence.Cacheable ; + + +# Item entity +# ############ +jpa-new-entity --named Item ; +jpa-new-field --named name --length 30 --not-nullable ; +jpa-new-field --named description --length 3000 --not-nullable ; +jpa-new-field --named imagePath --columnName image_path ; +jpa-new-field --named unitCost --type java.lang.Float --columnName unit_cost --not-nullable ; +# Relationships +jpa-new-field --named product --type Product --relationshipType Many-to-One --cascadeType PERSIST ; +# Constraints +constraint-add --onProperty name --constraint NotNull ; +constraint-add --onProperty name --constraint Size --min 1 --max 30 ; +constraint-add --onProperty description --constraint NotNull ; +constraint-add --onProperty description --constraint Size --max 3000 ; +constraint-add --onProperty unitCost --constraint NotNull ; +# TODO constraint-add --onProperty unitCost --constraint Price ; +# TODO constraint-add --onProperty imagePath --constraint NotEmpty ; +# Cache +java-add-annotation --annotation javax.persistence.Cacheable ; + + +# CreditCardType enumeration +# ############ +java-new-enum --named CreditCardType --targetPackage org.prabuckt.application.vegancakes.model ; +java-new-enum-const VISA ; +java-new-enum-const MASTER_CARD ; +java-new-enum-const AMERICAN_EXPRESS ; + +java-new-class --named CreditCardConverter --targetPackage org.prabuckt.application.vegancakes.model ; + + +# CreditCard embeddable +# ############ +jpa-new-embeddable --named CreditCard ; +jpa-new-field --named creditCardNumber --columnName credit_card_number --length 30 --not-nullable ; +jpa-new-field --named creditCardType --type CreditCardType --columnName credit_card_type ; +jpa-new-field --named creditCardExpDate --columnName credit_card_expiry_date --length 5 --not-nullable ; +# Constraints +constraint-add --onProperty creditCardNumber --constraint NotNull ; +constraint-add --onProperty creditCardNumber --constraint Size --min 1 --max 30 ; +constraint-add --onProperty creditCardType --constraint NotNull ; +constraint-add --onProperty creditCardExpDate --constraint NotNull ; +constraint-add --onProperty creditCardExpDate --constraint Size --min 1 --max 5 ; + + +# OrderLine entity +# ############ +jpa-new-entity --named OrderLine --tableName order_line ; +jpa-new-field --named quantity --type java.lang.Integer --not-nullable; +# Relationships +jpa-new-field --named item --type Item --relationshipType Many-to-One --cascadeType PERSIST ; +# Constraints +constraint-add --onProperty quantity --constraint Min --value 1 ; + + +# PurchaseOrder entity +# ############ +jpa-new-entity --named PurchaseOrder --tableName purchase_order ; +jpa-new-field --named orderDate --type java.util.Date --temporalType DATE --columnName order_date --not-updatable ; +jpa-new-field --named totalWithoutVat --type java.lang.Float ; +jpa-new-field --named vatRate --type java.lang.Float --columnName vat_rate ; +jpa-new-field --named vat --type java.lang.Float ; +jpa-new-field --named totalWithVat --type java.lang.Float ; +jpa-new-field --named discountRate --type java.lang.Float --columnName discount_rate ; +jpa-new-field --named discount --type java.lang.Float ; +jpa-new-field --named total --type java.lang.Float ; +# Address embeddable +jpa-new-field --named street1 --length 50 ; +jpa-new-field --named street2 ; +jpa-new-field --named city --length 50 ; +jpa-new-field --named state ; +jpa-new-field --named postcode --columnName zip_code --length 10 ; +# Relationships +jpa-new-field --named country --type Country --relationshipType Many-to-One ; +# Credit card embeddable +jpa-new-field --named creditCardNumber --columnName credit_card_number ; +jpa-new-field --named creditCardType --type CreditCardType --columnName credit_card_type ; +jpa-new-field --named creditCardExpDate --columnName credit_card_expiry_date ; +# Relationships +jpa-new-field --named customer --type Customer --relationshipType Many-to-One ; +jpa-new-field --named orderLines --type OrderLine --relationshipType One-to-Many ; +# Constraints +constraint-add --constraint NotNull --onProperty street1 ; +constraint-add --constraint Size --min 5 --max 50 --onProperty street1 ; +constraint-add --constraint NotNull --onProperty city ; +constraint-add --constraint Size --min 5 --max 50 --onProperty city ; +constraint-add --constraint NotNull --onProperty postcode ; +constraint-add --constraint Size --min 1 --max 10 --onProperty postcode ; +constraint-add --constraint NotNull --onProperty creditCardNumber ; +constraint-add --constraint Size --min 1 --max 30 --onProperty creditCardNumber ; +constraint-add --constraint NotNull --onProperty creditCardType ; +constraint-add --constraint NotNull --onProperty creditCardExpDate ; +constraint-add --constraint Size --min 5 --max 5 --onProperty creditCardExpDate ; + + + +# ####################### # +# Creates utility classes # +# ####################### # + +java-new-exception --named ValidationException --targetPackage org.prabuckt.application.vegancakes.exceptions ; +java-new-class --named LoginContextProducer --targetPackage org.prabuckt.application.vegancakes.security ; +java-new-class --named SimpleCallbackHandler --targetPackage org.prabuckt.application.vegancakes.security ; +java-new-class --named SimpleLoginModule --targetPackage org.prabuckt.application.vegancakes.security ; + +# Config producer +# ############ +cdi-new-qualifier --named ConfigProperty --targetPackage org.prabuckt.application.vegancakes.util ; +java-new-class --named ConfigPropertyProducer --targetPackage org.prabuckt.application.vegancakes.util ; + +# DatabaseProducer +# ############ +java-new-class --named DatabaseProducer --targetPackage org.prabuckt.application.vegancakes.util ; +java-new-field --named em --type javax.persistence.EntityManager --generateGetter=false --generateSetter=false --updateToString=false ; +java-add-annotation --annotation javax.enterprise.inject.Produces --onProperty em ; +java-add-annotation --annotation javax.persistence.PersistenceContext --onProperty em ; + +# Logging Interceptor +# ############ +cdi-new-interceptor-binding --named Loggable --targetPackage org.prabuckt.application.vegancakes.util ; +cdi-new-interceptor --named LoggingInterceptor --interceptorBinding Loggable --targetPackage org.prabuckt.application.vegancakes.util ; +java-new-field --named logger --type org.apache.logging.log4j.Logger --generateGetter=false --generateSetter=false --updateToString=false --updateToString=false ; +java-add-annotation --annotation javax.inject.Inject --onProperty logger ; + +# Logging Producer +# ############ +java-new-class --named LoggingProducer --targetPackage org.prabuckt.application.vegancakes.util ; + +# Number producer +# ############ +cdi-new-qualifier --named Vat --targetPackage org.prabuckt.application.vegancakes.util ; +cdi-new-qualifier --named Discount --targetPackage org.prabuckt.application.vegancakes.util ; +java-new-class --named NumberProducer --targetPackage org.prabuckt.application.vegancakes.util ; + +java-new-field --named vatRate --type java.lang.Float --generateGetter=false --generateSetter=false --updateToString=false ; +java-add-annotation --annotation javax.enterprise.inject.Produces --onProperty vatRate ; +java-add-annotation --annotation Vat --onProperty vatRate ; +java-add-annotation --annotation javax.inject.Named --onProperty vatRate ; + +java-new-field --named discountRate --type java.lang.Float --generateGetter=false --generateSetter=false --updateToString=false ; +java-add-annotation --annotation javax.enterprise.inject.Produces --onProperty discountRate ; +java-add-annotation --annotation Discount --onProperty discountRate ; +java-add-annotation --annotation javax.inject.Named --onProperty discountRate ; + + + +# ##################### # +# Adding a Service Tier # +# ##################### # + +java-new-class --named AbstractService --targetPackage org.prabuckt.application.vegancakes.service ; +java-add-annotation --annotation Loggable ; +ejb-new-bean --named CountryService ; +java-add-annotation --annotation Loggable ; +ejb-new-bean --named CustomerService ; +java-add-annotation --annotation Loggable ; +ejb-new-bean --named CategoryService ; +java-add-annotation --annotation Loggable ; +ejb-new-bean --named ProductService ; +java-add-annotation --annotation Loggable ; +ejb-new-bean --named ItemService ; +java-add-annotation --annotation Loggable ; +ejb-new-bean --named PurchaseOrderService ; +java-add-annotation --annotation Loggable ; +ejb-new-bean --named OrderLineService ; +java-add-annotation --annotation Loggable ; +java-new-class --named InventoryService --targetPackage org.prabuckt.application.vegancakes.service ; +java-add-annotation --annotation Loggable ; +java-new-class --named ShippingService --targetPackage org.prabuckt.application.vegancakes.service ; +java-add-annotation --annotation Loggable ; +java-new-class --named StatisticService --targetPackage org.prabuckt.application.vegancakes.service ; +java-add-annotation --annotation Loggable ; +java-new-interface --named ComputablePurchaseOrder --targetPackage org.prabuckt.application.vegancakes.service ; +cdi-new-decorator --named PurchaseOrderDecorator --delegate ComputablePurchaseOrder --targetPackage org.prabuckt.application.vegancakes.service ; + + + +# ############################# # +# Generates JSF beans and pages # +# ############################# # + +scaffold-generate --webRoot /admin --targets Category ; +scaffold-generate --webRoot /admin --targets Country ; +scaffold-generate --webRoot /admin --targets Customer ; +scaffold-generate --webRoot /admin --targets Item ; +scaffold-generate --webRoot /admin --targets OrderLine ; +scaffold-generate --webRoot /admin --targets Product ; +scaffold-generate --webRoot /admin --targets PurchaseOrder ; + +java-add-annotation --annotation Loggable --targetClass org.prabuckt.application.vegancakes.view.CategoryBean ; +java-add-annotation --annotation Loggable --targetClass org.prabuckt.application.vegancakes.view.CountryBean ; +java-add-annotation --annotation Loggable --targetClass org.prabuckt.application.vegancakes.view.CustomerBean ; +java-add-annotation --annotation Loggable --targetClass org.prabuckt.application.vegancakes.view.ItemBean ; +java-add-annotation --annotation Loggable --targetClass org.prabuckt.application.vegancakes.view.OrderLineBean ; +java-add-annotation --annotation Loggable --targetClass org.prabuckt.application.vegancakes.view.ProductBean ; +java-add-annotation --annotation Loggable --targetClass org.prabuckt.application.vegancakes.view.PurchaseOrderBean ; + +java-add-annotation --annotation CatchException --targetClass org.prabuckt.application.vegancakes.view.CategoryBean ; +java-add-annotation --annotation CatchException --targetClass org.prabuckt.application.vegancakes.view.CountryBean ; +java-add-annotation --annotation CatchException --targetClass org.prabuckt.application.vegancakes.view.CustomerBean ; +java-add-annotation --annotation CatchException --targetClass org.prabuckt.application.vegancakes.view.ItemBean ; +java-add-annotation --annotation CatchException --targetClass org.prabuckt.application.vegancakes.view.OrderLineBean ; +java-add-annotation --annotation CatchException --targetClass org.prabuckt.application.vegancakes.view.ProductBean ; +java-add-annotation --annotation CatchException --targetClass org.prabuckt.application.vegancakes.view.PurchaseOrderBean ; + +# AbstractBean +# ############ +faces-new-bean --named AbstractBean --targetPackage org.prabuckt.application.vegancakes.view ; + +# Utility beans +# ############ +faces-new-bean --named DebugBean --targetPackage org.prabuckt.application.vegancakes.view.util ; +faces-new-bean --named LocalBean --targetPackage org.prabuckt.application.vegancakes.view.util ; + +# Credentials +# ############ +cdi-new-interceptor-binding --named LoggedIn --targetPackage org.prabuckt.application.vegancakes.view.credentials ; + +faces-new-bean --named AccountBean --targetPackage org.prabuckt.application.vegancakes.view.credentials ; +java-add-annotation --annotation Loggable --targetClass org.prabuckt.application.vegancakes.view.AccountBean ; +java-add-annotation --annotation CatchException --targetClass org.prabuckt.application.vegancakes.view.AccountBean ; + +faces-new-bean --named CredentialsBean --targetPackage org.prabuckt.application.vegancakes.view.credentials ; +java-add-annotation --annotation Loggable --targetClass org.prabuckt.application.vegancakes.view.CredentialsBean ; +java-add-annotation --annotation CatchException --targetClass org.prabuckt.application.vegancakes.view.CredentialsBean ; + +# ShoppingCartBean +# ############ +faces-new-bean --named ShoppingCartBean --targetPackage org.prabuckt.application.vegancakes.view.shopping ; +java-add-annotation --annotation javax.enterprise.context.SessionScoped --targetPackage org.prabuckt.application.vegancakes.view.shopping ; +java-add-annotation --annotation Loggable --targetClass org.prabuckt.application.vegancakes.view.ShoppingCartBean ; +java-add-annotation --annotation CatchException --targetClass org.prabuckt.application.vegancakes.view.ShoppingCartBean ; + +java-new-class --named ShoppingCartItem --targetPackage org.prabuckt.application.vegancakes.view.shopping ; +java-new-field --named item --type Item ; +java-new-field --named quantity --type java.lang.Integer ; +# Constraints +constraint-add --constraint NotNull --onProperty item ; +constraint-add --constraint NotNull --onProperty quantity ; +constraint-add --constraint Min --onProperty quantity --value 1 ; + + + +# ############################ # +# Creates view utility classes # +# ############################ # + +# FacesContext producer +# ############ +java-new-class --named FacesProducer --targetPackage org.prabuckt.application.vegancakes.view.util ; +java-new-field --named facesContext --type javax.faces.context.FacesContext --generateGetter=false --generateSetter=false --updateToString=false ; +java-add-annotation --annotation javax.enterprise.inject.Produces --onProperty facesContext ; + +# Exception +# ############ +cdi-new-interceptor-binding --named CatchException --targetPackage org.prabuckt.application.vegancakes.view.util ; +cdi-new-interceptor --named ExceptionInterceptor --interceptorBinding org.prabuckt.application.vegancakes.view.util.CatchException --targetPackage org.prabuckt.application.vegancakes.view.util ; +java-new-field --named logger --type org.apache.logging.log4j.Logger --generateGetter=false --generateSetter=false --updateToString=false ; +java-add-annotation --annotation javax.inject.Inject --onProperty logger ; + + + +# ######################## # +# Generates REST endpoints # +# ######################## # + +rest-generate-endpoints-from-entities --targets Category --contentType application/xml application/json ; +rest-generate-endpoints-from-entities --targets Country --contentType application/xml application/json ; +rest-generate-endpoints-from-entities --targets Customer --contentType application/xml application/json ; +rest-generate-endpoints-from-entities --targets Item --contentType application/xml application/json ; +rest-generate-endpoints-from-entities --targets Product --contentType application/xml application/json ; + +java-add-annotation --annotation Loggable --targetClass CategoryEndpoint ; +java-add-annotation --annotation Loggable --targetClass CountryEndpoint ; +java-add-annotation --annotation Loggable --targetClass CustomerEndpoint ; +java-add-annotation --annotation Loggable --targetClass ItemEndpoint ; +java-add-annotation --annotation Loggable --targetClass ProductEndpoint ; + + + +# ######################### # +# Generate Arquillian tests +# ######################### # + +# JSF Beacking Beans +# ################## +arquillian-create-test --targets org.prabuckt.application.vegancakes.view.CountryBean --enableJPA ; +arquillian-create-test --targets org.prabuckt.application.vegancakes.view.CustomerBean --enableJPA ; +arquillian-create-test --targets org.prabuckt.application.vegancakes.view.CategoryBean --enableJPA ; +arquillian-create-test --targets org.prabuckt.application.vegancakes.view.ProductBean --enableJPA ; +arquillian-create-test --targets org.prabuckt.application.vegancakes.view.ItemBean --enableJPA ; +arquillian-create-test --targets org.prabuckt.application.vegancakes.view.OrderLineBean --enableJPA ; +arquillian-create-test --targets org.prabuckt.application.vegancakes.view.PurchaseOrderBean --enableJPA ; + +# REST Endpoints +# ############## +arquillian-create-test --targets CountryEndpoint --enableJPA --archiveType WAR ; +arquillian-create-test --targets CustomerEndpoint --enableJPA --archiveType WAR ; +arquillian-create-test --targets CategoryEndpoint --enableJPA --archiveType WAR ; +arquillian-create-test --targets ProductEndpoint --enableJPA --archiveType WAR ; +arquillian-create-test --targets ItemEndpoint --enableJPA --archiveType WAR ; + +# Services +# ############## +arquillian-create-test --targets CountryService --enableJPA ; +arquillian-create-test --targets CustomerService --enableJPA ; +arquillian-create-test --targets CategoryService --enableJPA ; +arquillian-create-test --targets ProductService --enableJPA ; +arquillian-create-test --targets ItemService --enableJPA ; +arquillian-create-test --targets PurchaseOrderService --enableJPA ; +arquillian-create-test --targets OrderLineService --enableJPA ; + + +# ################## # +# Cleans the pom.xml # +# ################## # + +project-remove-dependencies org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:: ; +project-remove-dependencies javax.enterprise:cdi-api:jar:: ; +project-remove-dependencies javax.ejb:javax.ejb-api:jar:: ; +project-remove-dependencies javax.faces:javax.faces-api:jar:: ; +project-remove-dependencies javax.servlet:javax.servlet-api:jar:: ; +project-remove-dependencies org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec:jar:: ; +project-remove-dependencies javax.ws.rs:javax.ws.rs-api:jar:: ; +project-remove-dependencies javax.validation:validation-api:jar:: ; + +project-remove-managed-dependencies org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar::1.0.0.Draft-16 ; +project-remove-managed-dependencies javax.enterprise:cdi-api:jar::1.1 ; +project-remove-managed-dependencies javax.ejb:javax.ejb-api:jar::3.2 ; +project-remove-managed-dependencies javax.faces:javax.faces-api:jar::2.2 ; +project-remove-managed-dependencies javax.servlet:javax.servlet-api:jar::3.1.0 ; +project-remove-managed-dependencies javax.ws.rs:javax.ws.rs-api:jar::2.0 +project-remove-managed-dependencies org.jboss.spec:jboss-javaee-6.0:pom::3.0.2.Final ; + +# Adding Java EE and Web Jars dependencies +# ############################ +project-add-dependencies org.apache.logging.log4j:log4j-core:2.0.2 ; +project-add-dependencies org.webjars:bootstrap:3.4.1 ; +project-add-dependencies org.primefaces:primefaces:10.0.0 ; +project-add-dependencies org.primefaces.themes:all-themes:1.0.10 ; +project-add-dependencies org.jboss.spec:jboss-javaee-7.0:1.0.1.Final:provided:pom ; + +# Adding External repositories +# ############################ +project-add-repository --named primefaces --url http://repository.primefaces.org/ diff --git a/src/main/java/org/prabuckt/application/vegancakes/constraints/Email.java b/src/main/java/org/prabuckt/application/vegancakes/constraints/Email.java new file mode 100644 index 0000000..b5be497 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/constraints/Email.java @@ -0,0 +1,55 @@ +package org.prabuckt.application.vegancakes.constraints; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.ReportAsSingleViolation; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Constraint(validatedBy = {}) +@Size(min = 5) +@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])?") +@ReportAsSingleViolation +@Retention(RetentionPolicy.RUNTIME) +@Target( {ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, + ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR}) +@Documented +public @interface Email +{ + + // ====================================== + // = Attributes = + // ====================================== + + String message() default "{Email.message}"; + + Class[] groups() default {}; + + Class[] payload() default {}; + + // ====================================== + // = Inner Annotation = + // ====================================== + + @Retention(RetentionPolicy.RUNTIME) + @Target( {ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, + ElementType.TYPE, ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR}) + public @interface List + { + Email[] value(); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/constraints/Login.java b/src/main/java/org/prabuckt/application/vegancakes/constraints/Login.java new file mode 100644 index 0000000..36a9c21 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/constraints/Login.java @@ -0,0 +1,53 @@ +package org.prabuckt.application.vegancakes.constraints; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.ReportAsSingleViolation; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Constraint(validatedBy = {}) +@NotNull +@Size(min = 1, max = 10) +@ReportAsSingleViolation +@Retention(RetentionPolicy.RUNTIME) +@Target( {ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, + ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR}) +@Documented +public @interface Login +{ + + // ====================================== + // = Attributes = + // ====================================== + + String message() default "{Login.message}"; + + Class[] groups() default {}; + + Class[] payload() default {}; + + // ====================================== + // = Inner Annotation = + // ====================================== + + @Retention(RetentionPolicy.RUNTIME) + @Target( {ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, + ElementType.TYPE, ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR}) + public @interface List + { + Login[] value(); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/constraints/NotEmpty.java b/src/main/java/org/prabuckt/application/vegancakes/constraints/NotEmpty.java new file mode 100644 index 0000000..8fac7fa --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/constraints/NotEmpty.java @@ -0,0 +1,53 @@ +package org.prabuckt.application.vegancakes.constraints; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.ReportAsSingleViolation; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Constraint(validatedBy = {}) +@NotNull +@Size(min = 1) +@ReportAsSingleViolation +@Retention(RetentionPolicy.RUNTIME) +@Target( {ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, + ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR}) +@Documented +public @interface NotEmpty +{ + + // ====================================== + // = Attributes = + // ====================================== + + String message() default "{NotEmpty.message}"; + + Class[] groups() default {}; + + Class[] payload() default {}; + + // ====================================== + // = Inner Annotation = + // ====================================== + + @Retention(RetentionPolicy.RUNTIME) + @Target( {ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, + ElementType.TYPE, ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR}) + public @interface List + { + NotEmpty[] value(); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/constraints/Price.java b/src/main/java/org/prabuckt/application/vegancakes/constraints/Price.java new file mode 100644 index 0000000..1ee3178 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/constraints/Price.java @@ -0,0 +1,51 @@ +package org.prabuckt.application.vegancakes.constraints; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.ReportAsSingleViolation; +import javax.validation.constraints.DecimalMin; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Constraint(validatedBy = {}) +@DecimalMin("10") +@ReportAsSingleViolation +@Retention(RetentionPolicy.RUNTIME) +@Target( {ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, + ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR}) +@Documented +public @interface Price +{ + + // ====================================== + // = Attributes = + // ====================================== + + String message() default "{Price.message}"; + + Class[] groups() default {}; + + Class[] payload() default {}; + + // ====================================== + // = Inner Annotation = + // ====================================== + + @Retention(RetentionPolicy.RUNTIME) + @Target( {ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, + ElementType.TYPE, ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR}) + public @interface List + { + Price[] value(); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/exceptions/ValidationException.java b/src/main/java/org/prabuckt/application/vegancakes/exceptions/ValidationException.java new file mode 100644 index 0000000..83193d6 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/exceptions/ValidationException.java @@ -0,0 +1,25 @@ +package org.prabuckt.application.vegancakes.exceptions; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + * Thrown when data is not valid + */ + +public class ValidationException extends RuntimeException +{ + // ====================================== + // = Constructors = + // ====================================== + + public ValidationException() + { + super(); + } + + public ValidationException(String message) + { + super(message); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/model/Address.java b/src/main/java/org/prabuckt/application/vegancakes/model/Address.java new file mode 100644 index 0000000..1e74d33 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/model/Address.java @@ -0,0 +1,166 @@ +package org.prabuckt.application.vegancakes.model; + +import java.io.Serializable; +import java.util.Objects; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.ManyToOne; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +/** + * @author Tomasz Prabucki https://tprabucki.netlify.com -- + */ + +@Embeddable +public class Address implements Serializable +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Column(length = 50, nullable = false) + @Size(min = 5, max = 50) + @NotNull + private String street1; + + @Column + private String street2; + + @Column(length = 50, nullable = false) + @Size(min = 2, max = 50) + @NotNull + private String city; + + @Column + private String state; + + @Column(length = 10, name = "zip_code", nullable = false) + @Size(min = 1, max = 10) + @NotNull + private String postcode; + + @ManyToOne(cascade = CascadeType.PERSIST) + private Country country = new Country(); + + // ====================================== + // = Constructors = + // ====================================== + + public Address() + { + } + + public Address(String street1, String city, String postcode, Country country) + { + this.street1 = street1; + this.city = city; + this.postcode = postcode; + this.country = country; + } + + // ====================================== + // = Getters & setters = + // ====================================== + + public String getStreet1() + { + return street1; + } + + public void setStreet1(String street1) + { + this.street1 = street1; + } + + public String getStreet2() + { + return street2; + } + + public void setStreet2(String street2) + { + this.street2 = street2; + } + + public String getCity() + { + return city; + } + + public void setCity(String city) + { + this.city = city; + } + + public String getState() + { + return state; + } + + public void setState(String state) + { + this.state = state; + } + + public String getPostcode() + { + return postcode; + } + + public void setPostcode(String postcode) + { + this.postcode = postcode; + } + + public Country getCountry() + { + return this.country; + } + + public void setCountry(final Country country) + { + this.country = country; + } + + // ====================================== + // = Methods hash, equals, toString = + // ====================================== + + @Override + public final boolean equals(Object o) + { + if (this == o) + return true; + if (!(o instanceof Address)) + return false; + Address address = (Address) o; + return Objects.equals(street1, address.street1) && + Objects.equals(city, address.city) && + Objects.equals(state, address.state) && + Objects.equals(postcode, address.postcode) && + Objects.equals(country, address.country); + } + + @Override + public final int hashCode() + { + return Objects.hash(street1, city, state, postcode, country); + } + + @Override + public String toString() + { + return "Address{" + + "street1='" + street1 + '\'' + + ", street2='" + street2 + '\'' + + ", city='" + city + '\'' + + ", state='" + state + '\'' + + ", postcode='" + postcode + '\'' + + ", country=" + country + + '}'; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/model/Category.java b/src/main/java/org/prabuckt/application/vegancakes/model/Category.java new file mode 100644 index 0000000..2ac5069 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/model/Category.java @@ -0,0 +1,140 @@ +package org.prabuckt.application.vegancakes.model; + +import java.io.Serializable; +import java.util.Objects; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Tomasz Prabucki https://tprabucki.netlify.com -- + */ + +@Entity +@Cacheable +@NamedQueries({ + // TODO fetch doesn't work with GlassFIsh + // @NamedQuery(name = Category.FIND_BY_NAME, query = + // "SELECT c FROM Category c LEFT JOIN FETCH c.products WHERE c.name = :pname"), + @NamedQuery(name = Category.FIND_BY_NAME, query = "SELECT c FROM Category c WHERE c.name = :pname"), + @NamedQuery(name = Category.FIND_ALL, query = "SELECT c FROM Category c") +}) +@XmlRootElement +public class Category implements Serializable +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false) + private Long id; + @Version + @Column(name = "version") + private int version; + + @Column(length = 30, nullable = false) + @NotNull + @Size(min = 1, max = 30) + private String name; + + @Column(length = 3000, nullable = false) + @NotNull + @Size(max = 3000) + private String description; + + // ====================================== + // = Constants = + // ====================================== + + public static final String FIND_BY_NAME = "Category.findByName"; + public static final String FIND_ALL = "Category.findAll"; + + // ====================================== + // = Constructors = + // ====================================== + + public Category() + { + } + + public Category(String name, String description) + { + this.name = name; + this.description = description; + } + + // ====================================== + // = Getters & setters = + // ====================================== + + public Long getId() + { + return this.id; + } + + public void setId(final Long id) + { + this.id = id; + } + + public int getVersion() + { + return this.version; + } + + public void setVersion(final int version) + { + this.version = version; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + // ====================================== + // = Methods hash, equals, toString = + // ====================================== + + @Override + public final boolean equals(Object o) + { + if (this == o) + return true; + if (!(o instanceof Category)) + return false; + Category category = (Category) o; + return Objects.equals(name, category.name); + } + + @Override + public final int hashCode() + { + return Objects.hash(name); + } + + @Override + public String toString() { + return name; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/model/Country.java b/src/main/java/org/prabuckt/application/vegancakes/model/Country.java new file mode 100644 index 0000000..75eb98f --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/model/Country.java @@ -0,0 +1,171 @@ +package org.prabuckt.application.vegancakes.model; + +import java.io.Serializable; +import java.util.Objects; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; + +@Entity +@Cacheable +@XmlRootElement +public class Country implements Serializable +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false) + private Long id; + @Version + @Column(name = "version") + private int version; + + @Column(length = 2, name = "iso_code", nullable = false) + @NotNull + @Size(min = 2, max = 2) + private String isoCode; + + @Column(length = 80, nullable = false) + @NotNull + @Size(min = 2, max = 80) + private String name; + + @Column(length = 80, name = "printable_name", nullable = false) + @NotNull + @Size(min = 2, max = 80) + private String printableName; + + @Column(length = 3) + @NotNull + @Size(min = 3, max = 3) + private String iso3; + + @Column(length = 3) + @NotNull + @Size(min = 3, max = 3) + private String numcode; + + // ====================================== + // = Constructors = + // ====================================== + + public Country() + { + } + + public Country(String isoCode, String name, String printableName, String iso3, String numcode) + { + this.isoCode = isoCode; + this.name = name; + this.printableName = printableName; + this.iso3 = iso3; + this.numcode = numcode; + } + + // ====================================== + // = Getters & setters = + // ====================================== + + public Long getId() + { + return this.id; + } + + public void setId(final Long id) + { + this.id = id; + } + + public int getVersion() + { + return this.version; + } + + public void setVersion(final int version) + { + this.version = version; + } + + public String getIsoCode() + { + return isoCode; + } + + public void setIsoCode(String isoCode) + { + this.isoCode = isoCode; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getPrintableName() + { + return printableName; + } + + public void setPrintableName(String printableName) + { + this.printableName = printableName; + } + + public String getIso3() + { + return iso3; + } + + public void setIso3(String iso3) + { + this.iso3 = iso3; + } + + public String getNumcode() + { + return numcode; + } + + public void setNumcode(String numcode) + { + this.numcode = numcode; + } + + // ====================================== + // = Methods hash, equals, toString = + // ====================================== + + @Override + public final boolean equals(Object o) + { + if (this == o) + return true; + if (!(o instanceof Country)) + return false; + Country country = (Country) o; + return Objects.equals(isoCode, country.isoCode); + } + + @Override + public final int hashCode() + { + return Objects.hash(isoCode); + } + + @Override + public String toString() + { + return name; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/model/CreditCard.java b/src/main/java/org/prabuckt/application/vegancakes/model/CreditCard.java new file mode 100644 index 0000000..2eca4f7 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/model/CreditCard.java @@ -0,0 +1,120 @@ +package org.prabuckt.application.vegancakes.model; + +import java.io.Serializable; +import java.util.Objects; + +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.Enumerated; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +/** + * @author Tomasz Prabucki https://tprabucki.netlify.com -- + */ + +@Embeddable +public class CreditCard implements Serializable +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Column(length = 30, name = "credit_card_number", nullable = false) + @NotNull + @Size(min = 1, max = 30) + private String creditCardNumber; + + @Enumerated + @Column(name = "credit_card_type") + @NotNull + private CreditCardType creditCardType; + + @Column(length = 5, name = "credit_card_expiry_date", nullable = false) + @NotNull + @Size(min = 1, max = 5) + private String creditCardExpDate; + + // ====================================== + // = Constructors = + // ====================================== + + public CreditCard() + { + } + + public CreditCard(String creditCardNumber, CreditCardType creditCardType, String creditCardExpDate) + { + this.creditCardNumber = creditCardNumber; + this.creditCardType = creditCardType; + this.creditCardExpDate = creditCardExpDate; + } + + // ====================================== + // = Getters & setters = + // ====================================== + + public String getCreditCardNumber() + { + return creditCardNumber; + } + + public void setCreditCardNumber(String creditCardNumber) + { + this.creditCardNumber = creditCardNumber; + } + + public CreditCardType getCreditCardType() + { + return creditCardType; + } + + public void setCreditCardType(CreditCardType creditCardType) + { + this.creditCardType = creditCardType; + } + + public String getCreditCardExpDate() + { + return creditCardExpDate; + } + + public void setCreditCardExpDate(String creditCardExpDate) + { + this.creditCardExpDate = creditCardExpDate; + } + + // ====================================== + // = Methods hash, equals, toString = + // ====================================== + + @Override + public final boolean equals(Object o) + { + if (this == o) + return true; + if (!(o instanceof CreditCard)) + return false; + CreditCard that = (CreditCard) o; + return Objects.equals(creditCardNumber, that.creditCardNumber) && + Objects.equals(creditCardType, that.creditCardType) && + Objects.equals(creditCardExpDate, that.creditCardExpDate); + } + + @Override + public final int hashCode() + { + return Objects.hash(creditCardNumber, creditCardType, creditCardExpDate); + } + + @Override + public String toString() + { + return "CreditCard{" + + "creditCardNumber='" + creditCardNumber + '\'' + + ", creditCardType=" + creditCardType + + ", creditCardExpDate='" + creditCardExpDate + '\'' + + '}'; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/model/CreditCardConverter.java b/src/main/java/org/prabuckt/application/vegancakes/model/CreditCardConverter.java new file mode 100644 index 0000000..e62c781 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/model/CreditCardConverter.java @@ -0,0 +1,5 @@ +package org.prabuckt.application.vegancakes.model; + +public class CreditCardConverter +{ +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/model/CreditCardType.java b/src/main/java/org/prabuckt/application/vegancakes/model/CreditCardType.java new file mode 100644 index 0000000..142420b --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/model/CreditCardType.java @@ -0,0 +1,17 @@ +package org.prabuckt.application.vegancakes.model; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +public enum CreditCardType +{ + + // ====================================== + // = Constants = + // ====================================== + + VISA, MASTER_CARD, AMERICAN_EXPRESS +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/model/Customer.java b/src/main/java/org/prabuckt/application/vegancakes/model/Customer.java new file mode 100644 index 0000000..ef329e4 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/model/Customer.java @@ -0,0 +1,344 @@ +package org.prabuckt.application.vegancakes.model; + +import java.io.Serializable; +import java.security.MessageDigest; +import java.util.Base64; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Objects; + +import javax.persistence.*; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Past; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; + +import org.prabuckt.application.vegancakes.constraints.Email; +import org.prabuckt.application.vegancakes.constraints.Login; + +/** + * @author Tomasz Prabucki https://tprabucki.netlify.com -- + */ + +@Entity +@NamedQueries({ + @NamedQuery(name = Customer.FIND_BY_LOGIN, query = "SELECT c FROM Customer c WHERE c.login = :login"), + @NamedQuery(name = Customer.FIND_BY_EMAIL, query = "SELECT c FROM Customer c WHERE c.email = :email"), + @NamedQuery(name = Customer.FIND_BY_LOGIN_PASSWORD, query = "SELECT c FROM Customer c WHERE c.login = :login AND c.password = :password"), + @NamedQuery(name = Customer.FIND_BY_UUID, query = "SELECT c FROM Customer c WHERE c.uuid = :uuid"), + @NamedQuery(name = Customer.FIND_ALL, query = "SELECT c FROM Customer c") +}) +@XmlRootElement +public class Customer implements Serializable +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false) + private Long id; + @Version + @Column(name = "version") + private int version; + + @Column(length = 50, name = "first_name", nullable = false) + @NotNull + @Size(min = 2, max = 50) + private String firstName; + + @Column(length = 50, name = "last_name", nullable = false) + @NotNull + @Size(min = 2, max = 50) + private String lastName; + + @Column + private String telephone; + + @Column + @Email + private String email; + + @Column(length = 10, nullable = false) + @Login + private String login; + + @Column(length = 256, nullable = false) + @NotNull + @Size(min = 1, max = 256) + private String password; + + @Column(length = 256) + @Size(min = 1, max = 256) + private String uuid; + + private UserRole role; + + @Column(name = "date_of_birth") + @Temporal(TemporalType.DATE) + @Past + private Date dateOfBirth; + + @Transient + private Integer age; + + @Embedded + @Valid + private Address homeAddress = new Address(); + + // ====================================== + // = Constants = + // ====================================== + + public static final String FIND_BY_LOGIN = "Customer.findByLogin"; + public static final String FIND_BY_LOGIN_PASSWORD = "Customer.findByLoginAndPassword"; + public static final String FIND_ALL = "Customer.findAll"; + public static final String FIND_BY_EMAIL = "Customer.findByEmail"; + public static final String FIND_BY_UUID = "Customer.findByUUID"; + + // ====================================== + // = Constructors = + // ====================================== + + public Customer() + { + } + + public Customer(String firstName, String lastName, String login, String plainTextPassword, String email, + Address address) + { + this.firstName = firstName; + this.lastName = lastName; + this.login = login; + this.password = digestPassword(plainTextPassword); + this.email = email; + this.homeAddress = address; + this.dateOfBirth = new Date(); + } + + // ====================================== + // = Lifecycle Methods = + // ====================================== + + /** + * This method calculates the age of the customer + */ + @PostLoad + @PostPersist + @PostUpdate + public void calculateAge() + { + if (dateOfBirth == null) + { + age = null; + return; + } + + Calendar birth = new GregorianCalendar(); + birth.setTime(dateOfBirth); + Calendar now = new GregorianCalendar(); + now.setTime(new Date()); + int adjust = 0; + if (now.get(Calendar.DAY_OF_YEAR) - birth.get(Calendar.DAY_OF_YEAR) < 0) + { + adjust = -1; + } + age = now.get(Calendar.YEAR) - birth.get(Calendar.YEAR) + adjust; + } + + @PrePersist + public void digestPassword() + { + password = digestPassword(password); + } + + // ====================================== + // = Business methods = + // ====================================== + + /** + * Digest password with SHA-256 then encode it with Base64. + * + * @param plainTextPassword the password to digest and encode + * @return digested password + */ + public static String digestPassword(String plainTextPassword) + { + try + { + MessageDigest md = MessageDigest.getInstance("SHA-256"); + md.update(plainTextPassword.getBytes("UTF-8")); + byte[] passwordDigest = md.digest(); + return Base64.getEncoder().encodeToString(passwordDigest); + } + catch (Exception e) + { + throw new RuntimeException("Exception encoding password", e); + } + } + + // ====================================== + // = Getters & setters = + // ====================================== + + public Long getId() + { + return this.id; + } + + public void setId(final Long id) + { + this.id = id; + } + + public int getVersion() + { + return this.version; + } + + public void setVersion(final int version) + { + this.version = version; + } + + public String getLogin() + { + return login; + } + + public void setLogin(String login) + { + this.login = login; + } + + public UserRole getRole() + { + return role; + } + + public void setRole(UserRole role) + { + this.role = role; + } + + public String getUuid() + { + return uuid; + } + + public void setUuid(String uuid) + { + this.uuid = uuid; + } + + public String getPassword() + { + return password; + } + + public void setPassword(String password) + { + this.password = password; + } + + public String getFirstName() + { + return firstName; + } + + public void setFirstName(String firstName) + { + this.firstName = firstName; + } + + public String getLastName() + { + return lastName; + } + + public void setLastName(String lastName) + { + this.lastName = lastName; + } + + public String getFullName() + { + return firstName + " " + lastName; + } + + public String getTelephone() + { + return telephone; + } + + public void setTelephone(String telephone) + { + this.telephone = telephone; + } + + public String getEmail() + { + return email; + } + + public void setEmail(String email) + { + this.email = email; + } + + public Date getDateOfBirth() + { + return dateOfBirth; + } + + public void setDateOfBirth(Date dateOfBirth) + { + this.dateOfBirth = dateOfBirth; + } + + public Integer getAge() + { + return age; + } + + public Address getHomeAddress() + { + return homeAddress; + } + + public void setHomeAddress(Address homeAddress) + { + this.homeAddress = homeAddress; + } + + // ====================================== + // = Methods hash, equals, toString = + // ====================================== + + @Override + public final boolean equals(Object o) + { + if (this == o) + return true; + if (!(o instanceof Customer)) + return false; + Customer customer = (Customer) o; + return Objects.equals(login, customer.login); + } + + @Override + public final int hashCode() + { + return Objects.hash(login); + } + + @Override + public String toString() + { + return firstName + ' ' + lastName + " (" + login + ")"; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/model/Item.java b/src/main/java/org/prabuckt/application/vegancakes/model/Item.java new file mode 100644 index 0000000..7244f5d --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/model/Item.java @@ -0,0 +1,200 @@ +package org.prabuckt.application.vegancakes.model; + +import java.io.Serializable; +import java.util.Objects; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; + +import org.prabuckt.application.vegancakes.constraints.NotEmpty; +import org.prabuckt.application.vegancakes.constraints.Price; + +/** + * @author Tomasz Prabucki https://tprabucki.netlify.com -- + */ + +@Entity +@Cacheable +@NamedQueries({ + @NamedQuery(name = Item.FIND_BY_PRODUCT_ID, query = "SELECT i FROM Item i WHERE i.product.id = :productId"), + @NamedQuery(name = Item.SEARCH, query = "SELECT i FROM Item i WHERE UPPER(i.name) LIKE :keyword OR UPPER(i.product.name) LIKE :keyword ORDER BY i.product.category.name, i.product.name"), + @NamedQuery(name = Item.FIND_ALL, query = "SELECT i FROM Item i") +}) +@XmlRootElement +public class Item implements Serializable +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false) + private Long id; + @Version + @Column(name = "version") + private int version; + + @Column(length = 30, nullable = false) + @NotNull + @Size(min = 1, max = 30) + private String name; + + @Column(length = 3000, nullable = false) + @NotNull + @Size(max = 3000) + private String description; + + @Column(name = "image_path") + @NotEmpty + private String imagePath; + + @Column(name = "unit_cost", nullable = false) + @NotNull + @Price + private Float unitCost; + + @ManyToOne(cascade = CascadeType.PERSIST) + @JoinColumn(name = "product_fk", nullable = false) + @XmlTransient + private Product product; + + // ====================================== + // = Constants = + // ====================================== + + public static final String FIND_BY_PRODUCT_ID = "Item.findByProductId"; + public static final String SEARCH = "Item.search"; + public static final String FIND_ALL = "Item.findAll"; + + // ====================================== + // = Constructors = + // ====================================== + + public Item() + { + } + + public Item(String name, Float unitCost, String imagePath, String description, Product product) + { + this.name = name; + this.unitCost = unitCost; + this.imagePath = imagePath; + this.description = description; + this.product = product; + } + + // ====================================== + // = Getters & setters = + // ====================================== + + public Long getId() + { + return this.id; + } + + public void setId(final Long id) + { + this.id = id; + } + + public int getVersion() + { + return this.version; + } + + public void setVersion(final int version) + { + this.version = version; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public String getImagePath() + { + return imagePath; + } + + public void setImagePath(String imagePath) + { + this.imagePath = imagePath; + } + + public Float getUnitCost() + { + return unitCost; + } + + public void setUnitCost(Float unitCost) + { + this.unitCost = unitCost; + } + + public Product getProduct() + { + return this.product; + } + + public void setProduct(final Product product) + { + this.product = product; + } + + // ====================================== + // = Methods hash, equals, toString = + // ====================================== + + @Override + public final boolean equals(Object o) + { + if (this == o) + return true; + if (!(o instanceof Item)) + return false; + Item item = (Item) o; + return Objects.equals(name, item.name) && + Objects.equals(description, item.description); + } + + @Override + public final int hashCode() + { + return Objects.hash(name, description); + } + + @Override + public String toString() + { + return "Item{" + + "id=" + id + + ", version=" + version + + ", name='" + name + '\'' + + ", description='" + description + '\'' + + ", imagePath='" + imagePath + '\'' + + ", unitCost=" + unitCost + + ", product=" + product + + '}'; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/model/OrderLine.java b/src/main/java/org/prabuckt/application/vegancakes/model/OrderLine.java new file mode 100644 index 0000000..0183b08 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/model/OrderLine.java @@ -0,0 +1,133 @@ +package org.prabuckt.application.vegancakes.model; + +import java.io.Serializable; +import java.util.Objects; + +import javax.persistence.*; +import javax.validation.constraints.Min; + +@Entity +@Table(name = "order_line") +public class OrderLine implements Serializable +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false) + private Long id; + @Version + @Column(name = "version") + private int version; + + @Column(nullable = false) + @Min(1) + private Integer quantity; + + @ManyToOne(cascade = CascadeType.PERSIST) + @JoinColumn(name = "item_fk", nullable = false) + private Item item; + + // ====================================== + // = Constructors = + // ====================================== + + public OrderLine() + { + } + + public OrderLine(Integer quantity, Item item) + { + this.quantity = quantity; + this.item = item; + } + + // ====================================== + // = Business methods = + // ====================================== + + public Float getSubTotal() + { + return item.getUnitCost() * quantity; + } + + // ====================================== + // = Getters & setters = + // ====================================== + + public Long getId() + { + return this.id; + } + + public void setId(final Long id) + { + this.id = id; + } + + public int getVersion() + { + return this.version; + } + + public void setVersion(final int version) + { + this.version = version; + } + + public Integer getQuantity() + { + return quantity; + } + + public void setQuantity(Integer quantity) + { + this.quantity = quantity; + } + + public Item getItem() + { + return this.item; + } + + public void setItem(final Item item) + { + this.item = item; + } + + // ====================================== + // = Methods hash, equals, toString = + // ====================================== + + @Override + public final boolean equals(Object o) + { + if (this == o) + return true; + if (!(o instanceof OrderLine)) + return false; + OrderLine orderLine = (OrderLine) o; + return Objects.equals(quantity, orderLine.quantity) && + Objects.equals(item, orderLine.item); + } + + @Override + public final int hashCode() + { + return Objects.hash(quantity, item); + } + + @Override + public String toString() + { + return "OrderLine{" + + "id=" + id + + ", version=" + version + + ", quantity=" + quantity + + ", item=" + item + + '}'; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/model/Product.java b/src/main/java/org/prabuckt/application/vegancakes/model/Product.java new file mode 100644 index 0000000..991377d --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/model/Product.java @@ -0,0 +1,156 @@ +package org.prabuckt.application.vegancakes.model; + +import java.io.Serializable; +import java.util.Objects; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; + +@Entity +@Cacheable +@NamedQueries({ + // TODO fetch doesn't work with GlassFish + // @NamedQuery(name = Product.FIND_BY_CATEGORY_NAME, query = + // "SELECT p FROM Product p LEFT JOIN FETCH p.items LEFT JOIN FETCH p.category WHERE p.category.name = + // :pname"), + @NamedQuery(name = Product.FIND_BY_CATEGORY_NAME, query = "SELECT p FROM Product p WHERE p.category.name = :pname"), + @NamedQuery(name = Product.FIND_ALL, query = "SELECT p FROM Product p") +}) +@XmlRootElement +public class Product implements Serializable +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false) + private Long id; + @Version + @Column(name = "version") + private int version; + + @Column(length = 30, nullable = false) + @NotNull + @Size(min = 1, max = 30) + private String name; + + @Column(length = 3000, nullable = false) + @NotNull + @Size(max = 3000) + private String description; + + @ManyToOne(cascade = CascadeType.PERSIST) + @JoinColumn(name = "category_fk", nullable = false) + @XmlTransient + private Category category; + + // ====================================== + // = Constants = + // ====================================== + + public static final String FIND_BY_CATEGORY_NAME = "Product.findByCategoryName"; + public static final String FIND_ALL = "Product.findAll"; + + // ====================================== + // = Constructors = + // ====================================== + + public Product() + { + } + + public Product(String name, String description, Category category) + { + this.name = name; + this.description = description; + this.category = category; + } + + // ====================================== + // = Getters & setters = + // ====================================== + + public Long getId() + { + return this.id; + } + + public void setId(final Long id) + { + this.id = id; + } + + public int getVersion() + { + return this.version; + } + + public void setVersion(final int version) + { + this.version = version; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public Category getCategory() + { + return this.category; + } + + public void setCategory(final Category category) + { + this.category = category; + } + + // ====================================== + // = Methods hash, equals, toString = + // ====================================== + + @Override + public final boolean equals(Object o) + { + if (this == o) + return true; + if (!(o instanceof Product)) + return false; + Product product = (Product) o; + return Objects.equals(name, product.name) && + Objects.equals(description, product.description); + } + + @Override + public final int hashCode() + { + return Objects.hash(name, description); + } + + @Override + public String toString() + { + return name; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/model/PurchaseOrder.java b/src/main/java/org/prabuckt/application/vegancakes/model/PurchaseOrder.java new file mode 100644 index 0000000..fa92ebe --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/model/PurchaseOrder.java @@ -0,0 +1,293 @@ +package org.prabuckt.application.vegancakes.model; + +import java.io.Serializable; +import java.util.Date; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +import javax.persistence.*; +import javax.validation.Valid; +import javax.xml.bind.annotation.XmlRootElement; + +@Entity +@Table(name = "purchase_order") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = PurchaseOrder.FIND_ALL, query = "SELECT o FROM PurchaseOrder o") +}) +public class PurchaseOrder implements Serializable +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false) + private Long id; + @Version + @Column(name = "version") + private int version; + + @Column(name = "order_date", updatable = false) + @Temporal(TemporalType.DATE) + private Date orderDate; + + @Column + private Float totalWithoutVat; + + @Column(name = "vat_rate") + private Float vatRate; + + @Column + private Float vat; + + @Column + private Float totalWithVat; + + @Column(name = "discount_rate") + private Float discountRate; + + @Column + private Float discount; + + @Column + private Float total; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "customer_fk", nullable = false) + private Customer customer; + + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinTable(name = "t_order_order_line", joinColumns = { @JoinColumn(name = "order_fk") }, inverseJoinColumns = { + @JoinColumn(name = "order_line_fk") }) + private Set orderLines = new HashSet(); + + @Embedded + @Valid + private Address deliveryAddress = new Address(); + + @Embedded + @Valid + private CreditCard creditCard = new CreditCard(); + + // ====================================== + // = Constants = + // ====================================== + + public static final String FIND_ALL = "Order.findAll"; + + // ====================================== + // = Constructors = + // ====================================== + + public PurchaseOrder() + { + } + + public PurchaseOrder(Customer customer, CreditCard creditCard, Address deliveryAddress) + { + this.customer = customer; + this.creditCard = creditCard; + this.deliveryAddress = deliveryAddress; + } + + // ====================================== + // = Lifecycle Methods = + // ====================================== + + @PrePersist + private void setDefaultData() + { + orderDate = new Date(); + } + + // ====================================== + // = Getters & setters = + // ====================================== + + public Long getId() + { + return this.id; + } + + public void setId(final Long id) + { + this.id = id; + } + + public int getVersion() + { + return this.version; + } + + public void setVersion(final int version) + { + this.version = version; + } + + public Date getOrderDate() + { + return orderDate; + } + + public void setOrderDate(Date orderDate) + { + this.orderDate = orderDate; + } + + public Float getTotalWithoutVat() + { + return totalWithoutVat; + } + + public void setTotalWithoutVat(Float totalWithoutVat) + { + this.totalWithoutVat = totalWithoutVat; + } + + public Float getVatRate() + { + return vatRate; + } + + public void setVatRate(Float vatRate) + { + this.vatRate = vatRate; + } + + public Float getVat() + { + return vat; + } + + public void setVat(Float vat) + { + this.vat = vat; + } + + public Float getTotalWithVat() + { + return totalWithVat; + } + + public void setTotalWithVat(Float totalWithVat) + { + this.totalWithVat = totalWithVat; + } + + public Float getDiscountRate() + { + return discountRate; + } + + public void setDiscountRate(Float discountRate) + { + this.discountRate = discountRate; + } + + public Float getDiscount() + { + return discount; + } + + public void setDiscount(Float discount) + { + this.discount = discount; + } + + public Float getTotal() + { + return total; + } + + public void setTotal(Float total) + { + this.total = total; + } + + public Customer getCustomer() + { + return this.customer; + } + + public void setCustomer(final Customer customer) + { + this.customer = customer; + } + + public Set getOrderLines() + { + return this.orderLines; + } + + public void setOrderLines(final Set orderLines) + { + this.orderLines = orderLines; + } + + public Address getDeliveryAddress() + { + return deliveryAddress; + } + + public void setDeliveryAddress(Address deliveryAddress) + { + this.deliveryAddress = deliveryAddress; + } + + public CreditCard getCreditCard() + { + return creditCard; + } + + public void setCreditCard(CreditCard creditCard) + { + this.creditCard = creditCard; + } + + // ====================================== + // = Methods hash, equals, toString = + // ====================================== + + @Override + public final boolean equals(Object o) + { + if (this == o) + return true; + if (!(o instanceof PurchaseOrder)) + return false; + PurchaseOrder that = (PurchaseOrder) o; + return Objects.equals(orderDate, that.orderDate) && + Objects.equals(customer, that.customer); + } + + @Override + public final int hashCode() + { + return Objects.hash(orderDate, customer); + } + + @Override + public String toString() + { + return "PurchaseOrder{" + + "id=" + id + + ", version=" + version + + ", orderDate=" + orderDate + + ", totalWithoutVat=" + totalWithoutVat + + ", vatRate=" + vatRate + + ", vat=" + vat + + ", totalWithVat=" + totalWithVat + + ", discountRate=" + discountRate + + ", discount=" + discount + + ", total=" + total + + ", customer=" + customer + + ", orderLines=" + orderLines + + ", deliveryAddress=" + deliveryAddress + + ", creditCard=" + creditCard + + '}'; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/model/UserRole.java b/src/main/java/org/prabuckt/application/vegancakes/model/UserRole.java new file mode 100644 index 0000000..8f76f10 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/model/UserRole.java @@ -0,0 +1,13 @@ +package org.prabuckt.application.vegancakes.model; + +/** + * @author Tomasz Prabucki - https://tprabucki.netlify.com -- + */ +public enum UserRole +{ + // ====================================== + // = Attributes = + // ====================================== + + USER, ADMIN +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/rest/CategoryEndpoint.java b/src/main/java/org/prabuckt/application/vegancakes/rest/CategoryEndpoint.java new file mode 100644 index 0000000..ae7dbb8 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/rest/CategoryEndpoint.java @@ -0,0 +1,122 @@ +package org.prabuckt.application.vegancakes.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.prabuckt.application.vegancakes.model.Category; +import org.prabuckt.application.vegancakes.util.Loggable; + +import javax.ejb.Stateless; +import javax.persistence.*; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriBuilder; +import java.util.List; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Stateless +@Path("/categories") +@Loggable +@Api("Category") +public class CategoryEndpoint +{ + + // ====================================== + // = Attributes = + // ====================================== + + @PersistenceContext(unitName = "applicationVegancakesPU") + private EntityManager em; + + // ====================================== + // = Business methods = + // ====================================== + + @POST + @Consumes( {"application/xml", "application/json"}) + @ApiOperation("Creates a category") + public Response create(Category entity) + { + em.persist(entity); + return Response.created(UriBuilder.fromResource(CategoryEndpoint.class).path(String.valueOf(entity.getId())).build()).build(); + } + + @DELETE + @Path("/{id:[0-9][0-9]*}") + @ApiOperation("Deletes a category by id") + public Response deleteById(@PathParam("id") Long id) + { + Category entity = em.find(Category.class, id); + if (entity == null) + { + return Response.status(Status.NOT_FOUND).build(); + } + em.remove(entity); + return Response.noContent().build(); + } + + @GET + @Path("/{id:[0-9][0-9]*}") + @Produces( {"application/xml", "application/json"}) + @ApiOperation("Finds a category given an identifier") + public Response findById(@PathParam("id") Long id) + { + TypedQuery findByIdQuery = em.createQuery("SELECT DISTINCT c FROM Category c WHERE c.id = :entityId ORDER BY c.id", Category.class); + findByIdQuery.setParameter("entityId", id); + Category entity; + try + { + entity = findByIdQuery.getSingleResult(); + } + catch (NoResultException nre) + { + entity = null; + } + if (entity == null) + { + return Response.status(Status.NOT_FOUND).build(); + } + return Response.ok(entity).build(); + } + + @GET + @Produces( {"application/xml", "application/json"}) + @ApiOperation("Lists all the categories") + public List listAll(@QueryParam("start") Integer startPosition, @QueryParam("max") Integer maxResult) + { + TypedQuery findAllQuery = em.createQuery("SELECT DISTINCT c FROM Category c ORDER BY c.id", Category.class); + if (startPosition != null) + { + findAllQuery.setFirstResult(startPosition); + } + if (maxResult != null) + { + findAllQuery.setMaxResults(maxResult); + } + final List results = findAllQuery.getResultList(); + return results; + } + + @PUT + @Path("/{id:[0-9][0-9]*}") + @Consumes( {"application/xml", "application/json"}) + @ApiOperation("Updates a category") + public Response update(Category entity) + { + try + { + entity = em.merge(entity); + } + catch (OptimisticLockException e) + { + return Response.status(Response.Status.CONFLICT).entity(e.getEntity()).build(); + } + + return Response.noContent().build(); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/rest/CountryEndpoint.java b/src/main/java/org/prabuckt/application/vegancakes/rest/CountryEndpoint.java new file mode 100644 index 0000000..de1a18c --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/rest/CountryEndpoint.java @@ -0,0 +1,122 @@ +package org.prabuckt.application.vegancakes.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.prabuckt.application.vegancakes.model.Country; +import org.prabuckt.application.vegancakes.util.Loggable; + +import javax.ejb.Stateless; +import javax.persistence.*; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriBuilder; +import java.util.List; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Stateless +@Path("/countries") +@Loggable +@Api("Country") +public class CountryEndpoint +{ + + // ====================================== + // = Attributes = + // ====================================== + + @PersistenceContext(unitName = "applicationVegancakesPU") + private EntityManager em; + + // ====================================== + // = Business methods = + // ====================================== + + @POST + @Consumes( {"application/xml", "application/json"}) + @ApiOperation("Creates a country") + public Response create(Country entity) + { + em.persist(entity); + return Response.created(UriBuilder.fromResource(CountryEndpoint.class).path(String.valueOf(entity.getId())).build()).build(); + } + + @DELETE + @Path("/{id:[0-9][0-9]*}") + @ApiOperation("Deletes a country given an id") + public Response deleteById(@PathParam("id") Long id) + { + Country entity = em.find(Country.class, id); + if (entity == null) + { + return Response.status(Status.NOT_FOUND).build(); + } + em.remove(entity); + return Response.noContent().build(); + } + + @GET + @Path("/{id:[0-9][0-9]*}") + @Produces( {"application/xml", "application/json"}) + @ApiOperation("Retrieves a country by its id") + public Response findById(@PathParam("id") Long id) + { + TypedQuery findByIdQuery = em.createQuery("SELECT DISTINCT c FROM Country c WHERE c.id = :entityId ORDER BY c.id", Country.class); + findByIdQuery.setParameter("entityId", id); + Country entity; + try + { + entity = findByIdQuery.getSingleResult(); + } + catch (NoResultException nre) + { + entity = null; + } + if (entity == null) + { + return Response.status(Status.NOT_FOUND).build(); + } + return Response.ok(entity).build(); + } + + @GET + @Produces( {"application/xml", "application/json"}) + @ApiOperation("Lists all the countries") + public List listAll(@QueryParam("start") Integer startPosition, @QueryParam("max") Integer maxResult) + { + TypedQuery findAllQuery = em.createQuery("SELECT DISTINCT c FROM Country c ORDER BY c.id", Country.class); + if (startPosition != null) + { + findAllQuery.setFirstResult(startPosition); + } + if (maxResult != null) + { + findAllQuery.setMaxResults(maxResult); + } + final List results = findAllQuery.getResultList(); + return results; + } + + @PUT + @Path("/{id:[0-9][0-9]*}") + @Consumes( {"application/xml", "application/json"}) + @ApiOperation("Updates a country") + public Response update(Country entity) + { + try + { + entity = em.merge(entity); + } + catch (OptimisticLockException e) + { + return Response.status(Response.Status.CONFLICT).entity(e.getEntity()).build(); + } + + return Response.noContent().build(); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/rest/CustomerEndpoint.java b/src/main/java/org/prabuckt/application/vegancakes/rest/CustomerEndpoint.java new file mode 100644 index 0000000..e2e3ea5 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/rest/CustomerEndpoint.java @@ -0,0 +1,122 @@ +package org.prabuckt.application.vegancakes.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.prabuckt.application.vegancakes.model.Customer; +import org.prabuckt.application.vegancakes.util.Loggable; + +import javax.ejb.Stateless; +import javax.persistence.*; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriBuilder; +import java.util.List; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Stateless +@Path("/customers") +@Loggable +@Api("Customer") +public class CustomerEndpoint +{ + + // ====================================== + // = Attributes = + // ====================================== + + @PersistenceContext(unitName = "applicationVegancakesPU") + private EntityManager em; + + // ====================================== + // = Business methods = + // ====================================== + + @POST + @Consumes( {"application/xml", "application/json"}) + @ApiOperation("Creates a customer") + public Response create(Customer entity) + { + em.persist(entity); + return Response.created(UriBuilder.fromResource(CustomerEndpoint.class).path(String.valueOf(entity.getId())).build()).build(); + } + + @DELETE + @Path("/{id:[0-9][0-9]*}") + @ApiOperation("Deletes a customer by id") + public Response deleteById(@PathParam("id") Long id) + { + Customer entity = em.find(Customer.class, id); + if (entity == null) + { + return Response.status(Status.NOT_FOUND).build(); + } + em.remove(entity); + return Response.noContent().build(); + } + + @GET + @Path("/{id:[0-9][0-9]*}") + @Produces( {"application/xml", "application/json"}) + @ApiOperation("Finds a customer by it identifier") + public Response findById(@PathParam("id") Long id) + { + TypedQuery findByIdQuery = em.createQuery("SELECT DISTINCT c FROM Customer c LEFT JOIN FETCH c.homeAddress.country WHERE c.id = :entityId ORDER BY c.id", Customer.class); + findByIdQuery.setParameter("entityId", id); + Customer entity; + try + { + entity = findByIdQuery.getSingleResult(); + } + catch (NoResultException nre) + { + entity = null; + } + if (entity == null) + { + return Response.status(Status.NOT_FOUND).build(); + } + return Response.ok(entity).build(); + } + + @GET + @Produces( {"application/xml", "application/json"}) + @ApiOperation("Lists all the customers") + public List listAll(@QueryParam("start") Integer startPosition, @QueryParam("max") Integer maxResult) + { + TypedQuery findAllQuery = em.createQuery("SELECT DISTINCT c FROM Customer c LEFT JOIN FETCH c.homeAddress.country ORDER BY c.id", Customer.class); + if (startPosition != null) + { + findAllQuery.setFirstResult(startPosition); + } + if (maxResult != null) + { + findAllQuery.setMaxResults(maxResult); + } + final List results = findAllQuery.getResultList(); + return results; + } + + @PUT + @Path("/{id:[0-9][0-9]*}") + @Consumes( {"application/xml", "application/json"}) + @ApiOperation("Updates a customer") + public Response update(Customer entity) + { + try + { + entity = em.merge(entity); + } + catch (OptimisticLockException e) + { + return Response.status(Response.Status.CONFLICT).entity(e.getEntity()).build(); + } + + return Response.noContent().build(); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/rest/ItemEndpoint.java b/src/main/java/org/prabuckt/application/vegancakes/rest/ItemEndpoint.java new file mode 100644 index 0000000..3bd9f79 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/rest/ItemEndpoint.java @@ -0,0 +1,122 @@ +package org.prabuckt.application.vegancakes.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.prabuckt.application.vegancakes.model.Item; +import org.prabuckt.application.vegancakes.util.Loggable; + +import javax.ejb.Stateless; +import javax.persistence.*; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriBuilder; +import java.util.List; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Stateless +@Path("/items") +@Loggable +@Api("Item") +public class ItemEndpoint +{ + + // ====================================== + // = Attributes = + // ====================================== + + @PersistenceContext(unitName = "applicationVegancakesPU") + private EntityManager em; + + // ====================================== + // = Business methods = + // ====================================== + + @POST + @Consumes( {"application/xml", "application/json"}) + @ApiOperation("Creates a new item") + public Response create(Item entity) + { + em.persist(entity); + return Response.created(UriBuilder.fromResource(ItemEndpoint.class).path(String.valueOf(entity.getId())).build()).build(); + } + + @DELETE + @Path("/{id:[0-9][0-9]*}") + @ApiOperation("Deletes an item by its id") + public Response deleteById(@PathParam("id") Long id) + { + Item entity = em.find(Item.class, id); + if (entity == null) + { + return Response.status(Status.NOT_FOUND).build(); + } + em.remove(entity); + return Response.noContent().build(); + } + + @GET + @Path("/{id:[0-9][0-9]*}") + @Produces( {"application/xml", "application/json"}) + @ApiOperation("Finds an item by its id") + public Response findById(@PathParam("id") Long id) + { + TypedQuery findByIdQuery = em.createQuery("SELECT DISTINCT i FROM Item i LEFT JOIN FETCH i.product WHERE i.id = :entityId ORDER BY i.id", Item.class); + findByIdQuery.setParameter("entityId", id); + Item entity; + try + { + entity = findByIdQuery.getSingleResult(); + } + catch (NoResultException nre) + { + entity = null; + } + if (entity == null) + { + return Response.status(Status.NOT_FOUND).build(); + } + return Response.ok(entity).build(); + } + + @GET + @Produces( {"application/xml", "application/json"}) + @ApiOperation("Lists all items") + public List listAll(@QueryParam("start") Integer startPosition, @QueryParam("max") Integer maxResult) + { + TypedQuery findAllQuery = em.createQuery("SELECT DISTINCT i FROM Item i LEFT JOIN FETCH i.product ORDER BY i.id", Item.class); + if (startPosition != null) + { + findAllQuery.setFirstResult(startPosition); + } + if (maxResult != null) + { + findAllQuery.setMaxResults(maxResult); + } + final List results = findAllQuery.getResultList(); + return results; + } + + @PUT + @Path("/{id:[0-9][0-9]*}") + @Consumes( {"application/xml", "application/json"}) + @ApiOperation("Updates an item") + public Response update(Item entity) + { + try + { + entity = em.merge(entity); + } + catch (OptimisticLockException e) + { + return Response.status(Response.Status.CONFLICT).entity(e.getEntity()).build(); + } + + return Response.noContent().build(); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/rest/ProductEndpoint.java b/src/main/java/org/prabuckt/application/vegancakes/rest/ProductEndpoint.java new file mode 100644 index 0000000..cb5b1fa --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/rest/ProductEndpoint.java @@ -0,0 +1,122 @@ +package org.prabuckt.application.vegancakes.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.prabuckt.application.vegancakes.model.Product; +import org.prabuckt.application.vegancakes.util.Loggable; + +import javax.ejb.Stateless; +import javax.persistence.*; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriBuilder; +import java.util.List; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Stateless +@Path("/products") +@Loggable +@Api("Product") +public class ProductEndpoint +{ + + // ====================================== + // = Attributes = + // ====================================== + + @PersistenceContext(unitName = "applicationVegancakesPU") + private EntityManager em; + + // ====================================== + // = Business methods = + // ====================================== + + @POST + @Consumes( {"application/xml", "application/json"}) + @ApiOperation("Creates new product") + public Response create(Product entity) + { + em.persist(entity); + return Response.created(UriBuilder.fromResource(ProductEndpoint.class).path(String.valueOf(entity.getId())).build()).build(); + } + + @DELETE + @Path("/{id:[0-9][0-9]*}") + @ApiOperation("Deletes a product by id") + public Response deleteById(@PathParam("id") Long id) + { + Product entity = em.find(Product.class, id); + if (entity == null) + { + return Response.status(Status.NOT_FOUND).build(); + } + em.remove(entity); + return Response.noContent().build(); + } + + @GET + @Path("/{id:[0-9][0-9]*}") + @Produces( {"application/xml", "application/json"}) + @ApiOperation("Finds a product by id") + public Response findById(@PathParam("id") Long id) + { + TypedQuery findByIdQuery = em.createQuery("SELECT DISTINCT p FROM Product p LEFT JOIN FETCH p.category WHERE p.id = :entityId ORDER BY p.id", Product.class); + findByIdQuery.setParameter("entityId", id); + Product entity; + try + { + entity = findByIdQuery.getSingleResult(); + } + catch (NoResultException nre) + { + entity = null; + } + if (entity == null) + { + return Response.status(Status.NOT_FOUND).build(); + } + return Response.ok(entity).build(); + } + + @GET + @Produces( {"application/xml", "application/json"}) + @ApiOperation("Lists all products") + public List listAll(@QueryParam("start") Integer startPosition, @QueryParam("max") Integer maxResult) + { + TypedQuery findAllQuery = em.createQuery("SELECT DISTINCT p FROM Product p LEFT JOIN FETCH p.category ORDER BY p.id", Product.class); + if (startPosition != null) + { + findAllQuery.setFirstResult(startPosition); + } + if (maxResult != null) + { + findAllQuery.setMaxResults(maxResult); + } + final List results = findAllQuery.getResultList(); + return results; + } + + @PUT + @Path("/{id:[0-9][0-9]*}") + @Consumes( {"application/xml", "application/json"}) + @ApiOperation("Updates a product") + public Response update(Product entity) + { + try + { + entity = em.merge(entity); + } + catch (OptimisticLockException e) + { + return Response.status(Response.Status.CONFLICT).entity(e.getEntity()).build(); + } + + return Response.noContent().build(); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/rest/RestApplication.java b/src/main/java/org/prabuckt/application/vegancakes/rest/RestApplication.java new file mode 100644 index 0000000..bfea651 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/rest/RestApplication.java @@ -0,0 +1,33 @@ +package org.prabuckt.application.vegancakes.rest; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; +import java.util.HashSet; +import java.util.Set; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@ApplicationPath("/rest") +public class RestApplication extends Application +{ + // ====================================== + // = Business methods = + // ====================================== + + // TODO Not sure this is still needed for portability in EE 8 +// @Override +// public Set> getClasses() +// { +// Set> classes = new HashSet<>(); +// classes.add(CategoryEndpoint.class); +// classes.add(CountryEndpoint.class); +// classes.add(CustomerEndpoint.class); +// classes.add(ItemEndpoint.class); +// classes.add(ProductEndpoint.class); +// return classes; +// } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/security/LoginContextProducer.java b/src/main/java/org/prabuckt/application/vegancakes/security/LoginContextProducer.java new file mode 100755 index 0000000..a04f9ca --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/security/LoginContextProducer.java @@ -0,0 +1,49 @@ +package org.prabuckt.application.vegancakes.security; + +import org.prabuckt.application.vegancakes.util.ConfigProperty; + +import javax.enterprise.inject.Produces; +import javax.inject.Inject; +import javax.security.auth.login.LoginContext; +import javax.security.auth.login.LoginException; +import java.net.URISyntaxException; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +public class LoginContextProducer +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private SimpleCallbackHandler callbackHandler; + + // ====================================== + // = Business methods = + // ====================================== + + @Produces + public LoginContext produceLoginContext(@ConfigProperty("loginConfigFile") String loginConfigFileName, + @ConfigProperty("loginModuleName") String loginModuleName) throws LoginException, URISyntaxException + { + + //System.setProperty("java.security.auth.login.config", new File(LoginContextProducer.class.getResource(loginConfigFileName).toURI()).getPath()); + + try + { + return new LoginContext(loginModuleName, callbackHandler); + } + catch (Exception e) + { + System.out.println("ouch!!!"); + return null; + } + } + +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/security/SimpleCallbackHandler.java b/src/main/java/org/prabuckt/application/vegancakes/security/SimpleCallbackHandler.java new file mode 100755 index 0000000..8aaaced --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/security/SimpleCallbackHandler.java @@ -0,0 +1,57 @@ +package org.prabuckt.application.vegancakes.security; + +import org.prabuckt.application.vegancakes.view.shopping.CredentialsBean; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.callback.UnsupportedCallbackException; +import java.io.IOException; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Named +public class SimpleCallbackHandler implements CallbackHandler +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + //@RequestScoped + private CredentialsBean credentials; + + // ====================================== + // = Business methods = + // ====================================== + + @Override + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException + { + for (Callback callback : callbacks) + { + if (callback instanceof NameCallback) + { + NameCallback nameCallback = (NameCallback) callback; + nameCallback.setName(credentials.getLogin()); + } + else if (callback instanceof PasswordCallback) + { + PasswordCallback passwordCallback = (PasswordCallback) callback; + passwordCallback.setPassword(credentials.getPassword().toCharArray()); + } + else + { + throw new UnsupportedCallbackException(callback); + } + } + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/security/SimpleLoginModule.java b/src/main/java/org/prabuckt/application/vegancakes/security/SimpleLoginModule.java new file mode 100755 index 0000000..0ea5d83 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/security/SimpleLoginModule.java @@ -0,0 +1,122 @@ +package org.prabuckt.application.vegancakes.security; + +import org.prabuckt.application.vegancakes.model.Customer; +import org.prabuckt.application.vegancakes.service.CustomerService; + +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeanManager; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.security.auth.Subject; +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.login.LoginException; +import javax.security.auth.spi.LoginModule; +import java.util.Map; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +public class SimpleLoginModule implements LoginModule +{ + + // ====================================== + // = Attributes = + // ====================================== + + private CallbackHandler callbackHandler; + + private CustomerService customerService; + + private BeanManager beanManager; + + // ====================================== + // = Business methods = + // ====================================== + + private CustomerService getCustomerService() + { + if (customerService != null) + { + return customerService; + } + try + { + Context context = new InitialContext(); + beanManager = (BeanManager) context.lookup("java:comp/BeanManager"); + Bean bean = beanManager.getBeans(CustomerService.class).iterator().next(); + CreationalContext cc = beanManager.createCreationalContext(bean); + customerService = (CustomerService) beanManager.getReference(bean, CustomerService.class, cc); + + } + catch (NamingException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + + return customerService; + + } + + @Override + public void initialize(Subject subject, CallbackHandler callbackHandler, Map stringMap, Map stringMap1) + { + this.callbackHandler = callbackHandler; + getCustomerService(); + } + + @Override + public boolean login() throws LoginException + { + + NameCallback nameCallback = new NameCallback("Name : "); + PasswordCallback passwordCallback = new PasswordCallback("Password : ", false); + try + { + callbackHandler.handle(new Callback[]{nameCallback, passwordCallback}); + String username = nameCallback.getName(); + String password = new String(passwordCallback.getPassword()); + nameCallback.setName(""); + passwordCallback.clearPassword(); + Customer customer = customerService.findCustomer(username, password); + + if (customer == null) + { + throw new LoginException("Authentication failed"); + } + + return true; + } + catch (Exception e) + { + e.printStackTrace(); + throw new LoginException(e.getMessage()); + } + } + + @Override + public boolean commit() throws LoginException + { + return true; + } + + @Override + public boolean abort() throws LoginException + { + return true; + } + + @Override + public boolean logout() throws LoginException + { + return true; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/AbstractService.java b/src/main/java/org/prabuckt/application/vegancakes/service/AbstractService.java new file mode 100644 index 0000000..dc89182 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/AbstractService.java @@ -0,0 +1,125 @@ +package org.prabuckt.application.vegancakes.service; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import java.util.List; +import org.prabuckt.application.vegancakes.util.Loggable; + +@Loggable +public abstract class AbstractService +{ + + // ====================================== + // = Attributes = + // ====================================== + + @PersistenceContext(unitName = "applicationVegancakesPU") + protected EntityManager entityManager; + + private Class entityClass; + + // ====================================== + // = Constructors = + // ====================================== + + public AbstractService() + { + } + + public AbstractService(Class entityClass) + { + this.entityClass = entityClass; + } + + // ====================================== + // = Business methods = + // ====================================== + + public T persist(T entity) + { + entityManager.persist(entity); + return entity; + } + + public T findById(Long id) + { + return entityManager.find(entityClass, id); + } + + public void remove(T entity) + { + entityManager.remove(entityManager.merge(entity)); + } + + public T merge(T entity) + { + return entityManager.merge(entity); + } + + public List listAll(Integer startPosition, Integer maxResult) + { + TypedQuery findAllQuery = getListAllQuery(); + if (startPosition != null) +{ + findAllQuery.setFirstResult(startPosition); + } + if (maxResult != null) + { + findAllQuery.setMaxResults(maxResult); + } + final List results = findAllQuery.getResultList(); + return results; + } + + public List listAll() + { + return getListAllQuery().getResultList(); + } + + public TypedQuery getListAllQuery() + { + CriteriaQuery criteria = entityManager.getCriteriaBuilder().createQuery(entityClass); + return entityManager.createQuery(criteria.select(criteria.from(entityClass))); + } + + public long count(T example) + { + + CriteriaBuilder builder = entityManager.getCriteriaBuilder(); + + // Populate count + + CriteriaQuery countCriteria = builder.createQuery(Long.class); + Root root = countCriteria.from(entityClass); + countCriteria = countCriteria.select(builder.count(root)).where(getSearchPredicates(root, example)); + long count = entityManager.createQuery(countCriteria).getSingleResult(); + return count; + } + + public List page(T example, int page, int pageSize) + { + + CriteriaBuilder builder = entityManager.getCriteriaBuilder(); + + // Populate pageItems + + CriteriaQuery criteria = builder.createQuery(entityClass); + Root root = criteria.from(entityClass); + TypedQuery query = entityManager.createQuery(criteria.select(root).where(getSearchPredicates(root, example))); + query.setFirstResult(page * pageSize).setMaxResults(pageSize); + List pageItems = query.getResultList(); + return pageItems; + + } + + // ====================================== + // = Protected methods = + // ====================================== + + protected abstract Predicate[] getSearchPredicates(Root root, T example); +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/CatalogService.java b/src/main/java/org/prabuckt/application/vegancakes/service/CatalogService.java new file mode 100755 index 0000000..b5cac9f --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/CatalogService.java @@ -0,0 +1,151 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.model.Category; +import org.prabuckt.application.vegancakes.model.Item; +import org.prabuckt.application.vegancakes.model.Product; +import org.prabuckt.application.vegancakes.util.Loggable; + +import javax.ejb.Stateless; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.TypedQuery; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Stateless +@Loggable +public class CatalogService implements Serializable { + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private EntityManager em; + + // ====================================== + // = Public Methods = + // ====================================== + + public Category findCategory(@NotNull Long categoryId) { + return em.find(Category.class, categoryId); + } + + public Category findCategory(@NotNull String categoryName) { + TypedQuery typedQuery = em.createNamedQuery(Category.FIND_BY_NAME, Category.class); + typedQuery.setParameter("pname", categoryName); + return typedQuery.getSingleResult(); + } + + public List findAllCategories() { + TypedQuery typedQuery = em.createNamedQuery(Category.FIND_ALL, Category.class); + return typedQuery.getResultList(); + } + + public Category createCategory(@NotNull Category category) { + em.persist(category); + return category; + } + + public Category updateCategory(@NotNull Category category) { + return em.merge(category); + } + + public void removeCategory(@NotNull Category category) { + em.remove(em.merge(category)); + } + + public void removeCategory(@NotNull Long categoryId) { + removeCategory(findCategory(categoryId)); + } + + public List findProducts(@NotNull String categoryName) { + TypedQuery typedQuery = em.createNamedQuery(Product.FIND_BY_CATEGORY_NAME, Product.class); + typedQuery.setParameter("pname", categoryName); + return typedQuery.getResultList(); + } + + public Product findProduct(@NotNull Long productId) { + Product product = em.find(Product.class, productId); + return product; + } + + public List findAllProducts() { + TypedQuery typedQuery = em.createNamedQuery(Product.FIND_ALL, Product.class); + return typedQuery.getResultList(); + } + + public Product createProduct(@NotNull Product product) { + if (product.getCategory() != null && product.getCategory().getId() == null) + em.persist(product.getCategory()); + + em.persist(product); + return product; + } + + public Product updateProduct(@NotNull Product product) { + return em.merge(product); + } + + public void removeProduct(@NotNull Product product) { + em.remove(em.merge(product)); + } + + public void removeProduct(@NotNull Long productId) { + removeProduct(findProduct(productId)); + } + + public List findItems(@NotNull Long productId) { + TypedQuery typedQuery = em.createNamedQuery(Item.FIND_BY_PRODUCT_ID, Item.class); + typedQuery.setParameter("productId", productId); + return typedQuery.getResultList(); + } + + public Item findItem(@NotNull Long itemId) { + return em.find(Item.class, itemId); + } + + public List searchItems(String keyword) { + if (keyword == null) + keyword = ""; + + TypedQuery typedQuery = em.createNamedQuery(Item.SEARCH, Item.class); + typedQuery.setParameter("keyword", "%" + keyword.toUpperCase() + "%"); + return typedQuery.getResultList(); + } + + public List findAllItems() { + TypedQuery typedQuery = em.createNamedQuery(Item.FIND_ALL, Item.class); + return typedQuery.getResultList(); + } + + public Item createItem(@NotNull Item item) { + if (item.getProduct() != null && item.getProduct().getId() == null) { + em.persist(item.getProduct()); + if (item.getProduct().getCategory() != null && item.getProduct().getCategory().getId() == null) + em.persist(item.getProduct().getCategory()); + } + + em.persist(item); + return item; + } + + public Item updateItem(@NotNull Item item) { + return em.merge(item); + } + + public void removeItem(@NotNull Item item) { + em.remove(em.merge(item)); + } + + public void removeItem(@NotNull Long itemId) { + removeItem(findItem(itemId)); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/CategoryService.java b/src/main/java/org/prabuckt/application/vegancakes/service/CategoryService.java new file mode 100644 index 0000000..ec33604 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/CategoryService.java @@ -0,0 +1,53 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.model.Category; + +import javax.ejb.Stateless; +import javax.ejb.LocalBean; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import org.prabuckt.application.vegancakes.util.Loggable; + +@Stateless +@LocalBean +@Loggable +public class CategoryService extends AbstractService implements Serializable +{ + + // ====================================== + // = Constructors = + // ====================================== + + public CategoryService() + { + super(Category.class); + } + + // ====================================== + // = Protected methods = + // ====================================== + + @Override + protected Predicate[] getSearchPredicates(Root root, Category example) + { + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + String name = example.getName(); + if (name != null && !"".equals(name)) + { + predicatesList.add(builder.like(builder.lower(root. get("name")), '%' + name.toLowerCase() + '%')); + } + String description = example.getDescription(); + if (description != null && !"".equals(description)) + { + predicatesList.add(builder.like(builder.lower(root. get("description")), '%' + description.toLowerCase() + '%')); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/ComputablePurchaseOrder.java b/src/main/java/org/prabuckt/application/vegancakes/service/ComputablePurchaseOrder.java new file mode 100644 index 0000000..8e24dc8 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/ComputablePurchaseOrder.java @@ -0,0 +1,5 @@ +package org.prabuckt.application.vegancakes.service; + +public interface ComputablePurchaseOrder +{ +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/CountryService.java b/src/main/java/org/prabuckt/application/vegancakes/service/CountryService.java new file mode 100644 index 0000000..c596110 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/CountryService.java @@ -0,0 +1,68 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.model.Country; + +import javax.ejb.Stateless; +import javax.ejb.LocalBean; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import org.prabuckt.application.vegancakes.util.Loggable; + +@Stateless +@LocalBean +@Loggable +public class CountryService extends AbstractService implements Serializable +{ + + // ====================================== + // = Constructors = + // ====================================== + + public CountryService() + { + super(Country.class); + } + + // ====================================== + // = Protected methods = + // ====================================== + + @Override + protected Predicate[] getSearchPredicates(Root root, Country example) + { + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + String isoCode = example.getIsoCode(); + if (isoCode != null && !"".equals(isoCode)) + { + predicatesList.add(builder.like(builder.lower(root. get("isoCode")), '%' + isoCode.toLowerCase() + '%')); + } + String name = example.getName(); + if (name != null && !"".equals(name)) + { + predicatesList.add(builder.like(builder.lower(root. get("name")), '%' + name.toLowerCase() + '%')); + } + String printableName = example.getPrintableName(); + if (printableName != null && !"".equals(printableName)) + { + predicatesList.add(builder.like(builder.lower(root. get("printableName")), '%' + printableName.toLowerCase() + '%')); + } + String iso3 = example.getIso3(); + if (iso3 != null && !"".equals(iso3)) + { + predicatesList.add(builder.like(builder.lower(root. get("iso3")), '%' + iso3.toLowerCase() + '%')); + } + String numcode = example.getNumcode(); + if (numcode != null && !"".equals(numcode)) + { + predicatesList.add(builder.like(builder.lower(root. get("numcode")), '%' + numcode.toLowerCase() + '%')); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/CustomerService.java b/src/main/java/org/prabuckt/application/vegancakes/service/CustomerService.java new file mode 100755 index 0000000..6d270b1 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/CustomerService.java @@ -0,0 +1,168 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.model.Country; +import org.prabuckt.application.vegancakes.model.Customer; +import org.prabuckt.application.vegancakes.util.Loggable; + +import javax.ejb.LocalBean; +import javax.ejb.Stateless; +import javax.persistence.NoResultException; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Stateless +@LocalBean +@Loggable +public class CustomerService extends AbstractService implements Serializable +{ + + // ====================================== + // = Constructors = + // ====================================== + + public CustomerService() + { + super(Customer.class); + } + + // ====================================== + // = Attributes = + // ====================================== + + + // ====================================== + // = Public Methods = + // ====================================== + + public boolean doesLoginAlreadyExist(@NotNull String login) + { + + // Login has to be unique + TypedQuery typedQuery = entityManager.createNamedQuery(Customer.FIND_BY_LOGIN, Customer.class); + typedQuery.setParameter("login", login); + try + { + typedQuery.getSingleResult(); + return true; + } + catch (NoResultException e) + { + return false; + } + } + + public Customer createCustomer(@NotNull Customer customer) + { + Country country = entityManager.find(Country.class, customer.getHomeAddress().getCountry().getId()); + customer.getHomeAddress().setCountry(country); + entityManager.persist(customer); + return customer; + } + + public Customer findCustomer(@NotNull String login) + { + TypedQuery typedQuery = entityManager.createNamedQuery(Customer.FIND_BY_LOGIN, Customer.class); + typedQuery.setParameter("login", login); + + try + { + return typedQuery.getSingleResult(); + } + catch (NoResultException e) + { + return null; + } + } + + public Customer findCustomer(@NotNull String login, @NotNull String password) + { + TypedQuery typedQuery = entityManager.createNamedQuery(Customer.FIND_BY_LOGIN_PASSWORD, Customer.class); + + String hash = Customer.digestPassword(password); + + typedQuery.setParameter("login", login); + typedQuery.setParameter("password", hash); + + try + { + return typedQuery.getSingleResult(); + } + catch (NoResultException e) + { + return null; + } + } + + public List findAllCustomers() + { + TypedQuery typedQuery = entityManager.createNamedQuery(Customer.FIND_ALL, Customer.class); + return typedQuery.getResultList(); + } + + public Customer updateCustomer(@NotNull Customer customer) + { + entityManager.merge(customer); + return customer; + } + + public void removeCustomer(@NotNull Customer customer) + { + entityManager.remove(entityManager.merge(customer)); + } + + public Country findCountry(@NotNull Long countryId) + { + return entityManager.find(Country.class, countryId); + } + + // ====================================== + // = Protected methods = + // ====================================== + + @Override + protected Predicate[] getSearchPredicates(Root root, Customer example) + { + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + String firstName = example.getFirstName(); + if (firstName != null && !"".equals(firstName)) + { + predicatesList.add(builder.like(builder.lower(root.get("firstName")), '%' + firstName.toLowerCase() + '%')); + } + String lastName = example.getLastName(); + if (lastName != null && !"".equals(lastName)) + { + predicatesList.add(builder.like(builder.lower(root.get("lastName")), '%' + lastName.toLowerCase() + '%')); + } + String telephone = example.getTelephone(); + if (telephone != null && !"".equals(telephone)) + { + predicatesList.add(builder.like(builder.lower(root.get("telephone")), '%' + telephone.toLowerCase() + '%')); + } + String email = example.getEmail(); + if (email != null && !"".equals(email)) + { + predicatesList.add(builder.like(builder.lower(root.get("email")), '%' + email.toLowerCase() + '%')); + } + String login = example.getLogin(); + if (login != null && !"".equals(login)) + { + predicatesList.add(builder.like(builder.lower(root.get("login")), '%' + login.toLowerCase() + '%')); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/InventoryService.java b/src/main/java/org/prabuckt/application/vegancakes/service/InventoryService.java new file mode 100644 index 0000000..bf8608a --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/InventoryService.java @@ -0,0 +1,8 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.util.Loggable; + +@Loggable +public class InventoryService +{ +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/ItemService.java b/src/main/java/org/prabuckt/application/vegancakes/service/ItemService.java new file mode 100644 index 0000000..66048d2 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/ItemService.java @@ -0,0 +1,65 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.model.Item; +import org.prabuckt.application.vegancakes.model.Product; + +import javax.ejb.Stateless; +import javax.ejb.LocalBean; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import org.prabuckt.application.vegancakes.util.Loggable; + +@Stateless +@LocalBean +@Loggable +public class ItemService extends AbstractService implements Serializable +{ + + + // ====================================== + // = Constructors = + // ====================================== + + public ItemService() + { + super(Item.class); + } + + // ====================================== + // = Protected methods = + // ====================================== + + @Override + protected Predicate[] getSearchPredicates(Root root, Item example) + { + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + String name = example.getName(); + if (name != null && !"".equals(name)) + { + predicatesList.add(builder.like(builder.lower(root. get("name")), '%' + name.toLowerCase() + '%')); + } + String description = example.getDescription(); + if (description != null && !"".equals(description)) + { + predicatesList.add(builder.like(builder.lower(root. get("description")), '%' + description.toLowerCase() + '%')); + } + String imagePath = example.getImagePath(); + if (imagePath != null && !"".equals(imagePath)) + { + predicatesList.add(builder.like(builder.lower(root. get("imagePath")), '%' + imagePath.toLowerCase() + '%')); + } + Product product = example.getProduct(); + if (product != null) + { + predicatesList.add(builder.equal(root.get("product"), product)); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/OrderLineService.java b/src/main/java/org/prabuckt/application/vegancakes/service/OrderLineService.java new file mode 100644 index 0000000..c2b7760 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/OrderLineService.java @@ -0,0 +1,54 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.model.Item; +import org.prabuckt.application.vegancakes.model.OrderLine; + +import javax.ejb.Stateless; +import javax.ejb.LocalBean; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import org.prabuckt.application.vegancakes.util.Loggable; + +@Stateless +@LocalBean +@Loggable +public class OrderLineService extends AbstractService implements Serializable +{ + + // ====================================== + // = Constructors = + // ====================================== + + public OrderLineService() + { + super(OrderLine.class); + } + + // ====================================== + // = Protected methods = + // ====================================== + + @Override + protected Predicate[] getSearchPredicates(Root root, OrderLine example) + { + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + Integer quantity = example.getQuantity(); + if (quantity != null && quantity.intValue() != 0) + { + predicatesList.add(builder.equal(root.get("quantity"), quantity)); + } + Item item = example.getItem(); + if (item != null) + { + predicatesList.add(builder.equal(root.get("item"), item)); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/ProductService.java b/src/main/java/org/prabuckt/application/vegancakes/service/ProductService.java new file mode 100644 index 0000000..34e2478 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/ProductService.java @@ -0,0 +1,59 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.model.Category; +import org.prabuckt.application.vegancakes.model.Product; + +import javax.ejb.Stateless; +import javax.ejb.LocalBean; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import org.prabuckt.application.vegancakes.util.Loggable; + +@Stateless +@LocalBean +@Loggable +public class ProductService extends AbstractService implements Serializable +{ + + // ====================================== + // = Constructors = + // ====================================== + + public ProductService() + { + super(Product.class); + } + + // ====================================== + // = Protected methods = + // ====================================== + + @Override + protected Predicate[] getSearchPredicates(Root root, Product example) + { + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + String name = example.getName(); + if (name != null && !"".equals(name)) + { + predicatesList.add(builder.like(builder.lower(root. get("name")), '%' + name.toLowerCase() + '%')); + } + String description = example.getDescription(); + if (description != null && !"".equals(description)) + { + predicatesList.add(builder.like(builder.lower(root. get("description")), '%' + description.toLowerCase() + '%')); + } + Category category = example.getCategory(); + if (category != null) + { + predicatesList.add(builder.equal(root.get("category"), category)); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/PurchaseOrderDecorator.java b/src/main/java/org/prabuckt/application/vegancakes/service/PurchaseOrderDecorator.java new file mode 100644 index 0000000..dced7e5 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/PurchaseOrderDecorator.java @@ -0,0 +1,14 @@ +package org.prabuckt.application.vegancakes.service; + +import javax.decorator.Decorator; +import javax.inject.Inject; +import javax.decorator.Delegate; + +@Decorator +public abstract class PurchaseOrderDecorator implements ComputablePurchaseOrder +{ + + @Inject + @Delegate + private ComputablePurchaseOrder delegate; +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/PurchaseOrderService.java b/src/main/java/org/prabuckt/application/vegancakes/service/PurchaseOrderService.java new file mode 100755 index 0000000..4c61e89 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/PurchaseOrderService.java @@ -0,0 +1,124 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.exceptions.ValidationException; +import org.prabuckt.application.vegancakes.model.*; +import org.prabuckt.application.vegancakes.util.Loggable; +import org.prabuckt.application.vegancakes.view.shopping.ShoppingCartItem; + +import javax.ejb.LocalBean; +import javax.ejb.Stateless; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Stateless +@LocalBean +@Loggable +public class PurchaseOrderService extends AbstractServiceimplements Serializable +{ + + // ====================================== + // = Attributes = + // ====================================== + + + // ====================================== + // = Public Methods = + // ====================================== + + public PurchaseOrder createOrder(@NotNull Customer customer, @NotNull CreditCard creditCard, final List cartItems) + { + + // Make sure the object is valid + if (cartItems == null || cartItems.size() == 0) + throw new ValidationException("Shopping cart is empty"); // TODO exception bean validation + + // Creating the order + Address deliveryAddress = customer.getHomeAddress(); + Country country = entityManager.find(Country.class, customer.getHomeAddress().getCountry().getId()); + deliveryAddress.setCountry(country); + PurchaseOrder order = new PurchaseOrder(entityManager.merge(customer), creditCard, deliveryAddress); + + // From the shopping cart we create the order lines + Set orderLines = new HashSet<>(); + + for (ShoppingCartItem cartItem : cartItems) + { + orderLines.add(new OrderLine(cartItem.getQuantity(), entityManager.merge(cartItem.getItem()))); + } + order.setOrderLines(orderLines); + + // Persists the object to the database + entityManager.persist(order); + + return order; + } + + public PurchaseOrder findOrder(@NotNull Long orderId) + { + return entityManager.find(PurchaseOrder.class, orderId); + } + + public List findAllOrders() + { + TypedQuery typedQuery = entityManager.createNamedQuery(PurchaseOrder.FIND_ALL, PurchaseOrder.class); + return typedQuery.getResultList(); + } + + public void removeOrder(@NotNull PurchaseOrder order) + { + entityManager.remove(entityManager.merge(order)); + } + + // ====================================== + // = Protected methods = + // ====================================== + + @Override + protected Predicate[] getSearchPredicates(Root root, PurchaseOrder example) + { + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + String street1 = example.getCustomer().getHomeAddress().getStreet1(); + if (street1 != null && !"".equals(street1)) + { + predicatesList.add(builder.like(builder.lower(root.get("street1")), '%' + street1.toLowerCase() + '%')); + } + String street2 = example.getCustomer().getHomeAddress().getStreet2(); + if (street2 != null && !"".equals(street2)) + { + predicatesList.add(builder.like(builder.lower(root.get("street2")), '%' + street2.toLowerCase() + '%')); + } + String city = example.getCustomer().getHomeAddress().getCity(); + if (city != null && !"".equals(city)) + { + predicatesList.add(builder.like(builder.lower(root.get("city")), '%' + city.toLowerCase() + '%')); + } + String state = example.getCustomer().getHomeAddress().getState(); + if (state != null && !"".equals(state)) + { + predicatesList.add(builder.like(builder.lower(root.get("state")), '%' + state.toLowerCase() + '%')); + } + String postcode = example.getCustomer().getHomeAddress().getPostcode(); + if (postcode != null && !"".equals(postcode)) + { + predicatesList.add(builder.like(builder.lower(root.get("postcode")), '%' + postcode.toLowerCase() + '%')); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/ShippingService.java b/src/main/java/org/prabuckt/application/vegancakes/service/ShippingService.java new file mode 100644 index 0000000..ec0562d --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/ShippingService.java @@ -0,0 +1,8 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.util.Loggable; + +@Loggable +public class ShippingService +{ +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/service/StatisticService.java b/src/main/java/org/prabuckt/application/vegancakes/service/StatisticService.java new file mode 100644 index 0000000..5747aa5 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/service/StatisticService.java @@ -0,0 +1,8 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.util.Loggable; + +@Loggable +public class StatisticService +{ +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/util/ConfigProperty.java b/src/main/java/org/prabuckt/application/vegancakes/util/ConfigProperty.java new file mode 100755 index 0000000..f167c09 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/util/ConfigProperty.java @@ -0,0 +1,18 @@ +package org.prabuckt.application.vegancakes.util; + +import javax.enterprise.util.Nonbinding; +import javax.inject.Qualifier; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Documented; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, + ElementType.TYPE }) +@Documented +public @interface ConfigProperty { + @Nonbinding String value() default ""; +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/util/ConfigPropertyProducer.java b/src/main/java/org/prabuckt/application/vegancakes/util/ConfigPropertyProducer.java new file mode 100755 index 0000000..10e5342 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/util/ConfigPropertyProducer.java @@ -0,0 +1,42 @@ +package org.prabuckt.application.vegancakes.util; + +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.spi.InjectionPoint; +import java.io.IOException; +import java.util.Properties; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +public class ConfigPropertyProducer { + + // ====================================== + // = Attributes = + // ====================================== + + private static Properties props; + + static { + props = new Properties(); + try { + props.load(ConfigPropertyProducer.class.getResourceAsStream("/config.properties")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + // ====================================== + // = Business methods = + // ====================================== + + @Produces + @ConfigProperty + public static String produceConfigProperty(InjectionPoint ip) { + String key = ip.getAnnotated().getAnnotation(ConfigProperty.class).value(); + + return props.getProperty(key); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/util/DatabaseProducer.java b/src/main/java/org/prabuckt/application/vegancakes/util/DatabaseProducer.java new file mode 100755 index 0000000..86f69c4 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/util/DatabaseProducer.java @@ -0,0 +1,23 @@ +package org.prabuckt.application.vegancakes.util; + +import javax.enterprise.inject.Produces; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +public class DatabaseProducer +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Produces + @PersistenceContext(unitName = "applicationVegancakesPU") + private EntityManager em; +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/util/Discount.java b/src/main/java/org/prabuckt/application/vegancakes/util/Discount.java new file mode 100644 index 0000000..c362d91 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/util/Discount.java @@ -0,0 +1,17 @@ +package org.prabuckt.application.vegancakes.util; + +import javax.inject.Qualifier; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Documented; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, + ElementType.TYPE }) +@Documented +public @interface Discount +{ +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/util/Loggable.java b/src/main/java/org/prabuckt/application/vegancakes/util/Loggable.java new file mode 100755 index 0000000..f3c19de --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/util/Loggable.java @@ -0,0 +1,22 @@ +package org.prabuckt.application.vegancakes.util; + +import javax.interceptor.InterceptorBinding; +import java.lang.annotation.*; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@InterceptorBinding +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.TYPE }) +@Documented +public @interface Loggable +{ +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/util/LoggingInterceptor.java b/src/main/java/org/prabuckt/application/vegancakes/util/LoggingInterceptor.java new file mode 100755 index 0000000..88d8276 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/util/LoggingInterceptor.java @@ -0,0 +1,49 @@ +package org.prabuckt.application.vegancakes.util; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; +import java.io.Serializable; +import java.util.logging.Logger; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + * This interceptor implements Serializable because it's used on a Stateful Session Bean who has + * passivation and activation lifecycle. + */ + +@Loggable +@Interceptor +public class LoggingInterceptor implements Serializable +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private transient Logger logger; + + // ====================================== + // = Business methods = + // ====================================== + + @AroundInvoke + private Object intercept(InvocationContext ic) throws Exception + { + logger.entering(ic.getTarget().getClass().getName(), ic.getMethod().getName()); + logger.info(">>> " + ic.getTarget().getClass().getName() + "-" + ic.getMethod().getName()); + try + { + return ic.proceed(); + } + finally + { + logger.exiting(ic.getTarget().getClass().getName(), ic.getMethod().getName()); + logger.info("<<< " + ic.getTarget().getClass().getName() + "-" + ic.getMethod().getName()); + } + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/util/LoggingProducer.java b/src/main/java/org/prabuckt/application/vegancakes/util/LoggingProducer.java new file mode 100755 index 0000000..688db9c --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/util/LoggingProducer.java @@ -0,0 +1,23 @@ +package org.prabuckt.application.vegancakes.util; + +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.spi.InjectionPoint; +import java.util.logging.Logger; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +public class LoggingProducer { + + // ====================================== + // = Business methods = + // ====================================== + + @Produces + public Logger produceLogger(InjectionPoint injectionPoint) { + return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName()); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/util/NumberProducer.java b/src/main/java/org/prabuckt/application/vegancakes/util/NumberProducer.java new file mode 100644 index 0000000..486cb4b --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/util/NumberProducer.java @@ -0,0 +1,17 @@ +package org.prabuckt.application.vegancakes.util; + +import javax.enterprise.inject.Produces; +import javax.inject.Named; + +public class NumberProducer +{ + + @Produces + @Vat + @Named + private Float vatRate; + @Produces + @Discount + @Named + private Float discountRate; +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/util/Vat.java b/src/main/java/org/prabuckt/application/vegancakes/util/Vat.java new file mode 100644 index 0000000..2275caa --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/util/Vat.java @@ -0,0 +1,17 @@ +package org.prabuckt.application.vegancakes.util; + +import javax.inject.Qualifier; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; +import java.lang.annotation.Documented; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, + ElementType.TYPE }) +@Documented +public @interface Vat +{ +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/AbstractBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/AbstractBean.java new file mode 100755 index 0000000..3d3854e --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/AbstractBean.java @@ -0,0 +1,66 @@ +package org.prabuckt.application.vegancakes.view; + +import org.prabuckt.application.vegancakes.util.Loggable; + +import javax.faces.application.FacesMessage; +import javax.faces.context.FacesContext; +import javax.inject.Inject; +import java.text.MessageFormat; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.logging.Logger; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Loggable +public abstract class AbstractBean { + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private transient Logger logger; + + // ====================================== + // = Protected Methods = + // ====================================== + + private String getMessage(FacesContext facesContext, String msgKey, Object... args) { + Locale locale = facesContext.getViewRoot().getLocale(); + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + ResourceBundle bundle = ResourceBundle.getBundle("Messages", locale, classLoader); + String msgValue = bundle.getString(msgKey); + return MessageFormat.format(msgValue, args); + } + + protected void addInformationMessage(String message, Object... args) { + FacesContext context = FacesContext.getCurrentInstance(); + context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, getMessage(context, message, args), null)); + } + + protected void addWarningMessage(String message, Object... args) { + FacesContext context = FacesContext.getCurrentInstance(); + context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, getMessage(context, message, args), null)); + } + + protected void addErrorMessage(String message, Object... args) { + FacesContext context = FacesContext.getCurrentInstance(); + context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, getMessage(context, message, args), null)); + } + + protected String getParam(String param) { + FacesContext context = FacesContext.getCurrentInstance(); + Map map = context.getExternalContext().getRequestParameterMap(); + return map.get(param); + } + + protected Long getParamId(String param) { + return Long.valueOf(getParam(param)); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/CatchException.java b/src/main/java/org/prabuckt/application/vegancakes/view/CatchException.java new file mode 100755 index 0000000..b8e49e8 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/CatchException.java @@ -0,0 +1,22 @@ +package org.prabuckt.application.vegancakes.view; + +import javax.interceptor.InterceptorBinding; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + * Any JSF backing bean using this interceptor binding will catch and display exceptions on the JSF page + */ + +@InterceptorBinding +@Target({METHOD, TYPE}) +@Retention(RUNTIME) +public @interface CatchException { +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/DebugBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/DebugBean.java new file mode 100755 index 0000000..7def147 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/DebugBean.java @@ -0,0 +1,48 @@ +package org.prabuckt.application.vegancakes.view; + +import org.prabuckt.application.vegancakes.util.Loggable; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Named +@RequestScoped +@Loggable +@CatchException +public class DebugBean extends AbstractBean { + + // ====================================== + // = Public Methods = + // ====================================== + + public List getThreadStack() { + StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); + List elements = new ArrayList<>(); + for (StackTraceElement stackTraceElement : stackTraceElements) { + elements.add(stackTraceElement.getClassName() + "." + + stackTraceElement.getMethodName() + + "(" + stackTraceElement.getFileName() + ":" + stackTraceElement.getLineNumber() + ")"); + } + return elements; + } + + public String getWorkingDirectory() { + return new java.io.File(".").getAbsolutePath(); + } + + public String getTotalMemory() { + return String.valueOf(Runtime.getRuntime().totalMemory()); + } + + public String getFreeMemory() { + return String.valueOf(Runtime.getRuntime().freeMemory()); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/ExceptionInterceptor.java b/src/main/java/org/prabuckt/application/vegancakes/view/ExceptionInterceptor.java new file mode 100755 index 0000000..d62d985 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/ExceptionInterceptor.java @@ -0,0 +1,43 @@ +package org.prabuckt.application.vegancakes.view; + +import javax.faces.application.FacesMessage; +import javax.faces.context.FacesContext; +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; +import java.io.Serializable; +import java.util.logging.Logger; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + * This interceptor catches exception and displayes them in a JSF page + */ + +@Interceptor +@CatchException +public class ExceptionInterceptor implements Serializable { + + @Inject + private Logger log; + + @AroundInvoke + public Object catchException(InvocationContext ic) throws Exception { + try { + return ic.proceed(); + } catch (Exception e) { + addErrorMessage(e.getMessage()); + log.severe("/!\\ " + ic.getTarget().getClass().getName() + " - " + ic.getMethod().getName() + " - " + e.getMessage()); + e.printStackTrace(); + } + return null; + } + + // TODO to refactor with Controller methods + protected void addErrorMessage(String message) { + FacesContext context = FacesContext.getCurrentInstance(); + context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, message, null)); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/LocaleBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/LocaleBean.java new file mode 100755 index 0000000..7ce9206 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/LocaleBean.java @@ -0,0 +1,42 @@ +package org.prabuckt.application.vegancakes.view; + +import org.prabuckt.application.vegancakes.util.Loggable; + +import javax.enterprise.context.SessionScoped; +import javax.enterprise.inject.Produces; +import javax.faces.context.FacesContext; +import javax.inject.Named; +import java.io.Serializable; +import java.util.Locale; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Named +@SessionScoped +@Loggable +public class LocaleBean implements Serializable { + + @Produces + private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); + + // ====================================== + // = Business methods = + // ====================================== + + public Locale getLocale() { + return locale; + } + + public String getLanguage() { + return locale.getLanguage(); + } + + public void setLanguage(String language) { + locale = new Locale(language); + FacesContext.getCurrentInstance().getViewRoot().setLocale(locale); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/LoggedIn.java b/src/main/java/org/prabuckt/application/vegancakes/view/LoggedIn.java new file mode 100755 index 0000000..74aebc4 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/LoggedIn.java @@ -0,0 +1,20 @@ +package org.prabuckt.application.vegancakes.view; + +import javax.inject.Qualifier; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Qualifier +@Retention(RUNTIME) +@Target({FIELD, TYPE, METHOD}) +public @interface LoggedIn { +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/ViewUtils.java b/src/main/java/org/prabuckt/application/vegancakes/view/ViewUtils.java new file mode 100644 index 0000000..fb87651 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/ViewUtils.java @@ -0,0 +1,86 @@ +package org.prabuckt.application.vegancakes.view; + +import javax.persistence.Id; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * Utilities for working with Java Server Faces views. + */ + +public final class ViewUtils +{ + + public static List asList(Collection collection) + { + + if (collection == null) + { + return null; + } + + return new ArrayList(collection); + } + + public static String display(Object object) + { + + if (object == null) + { + return null; + } + + try + { + // Invoke toString if declared in the class. If not found, the NoSuchMethodException is caught and handled + object.getClass().getDeclaredMethod("toString"); + return object.toString(); + } + catch (NoSuchMethodException noMethodEx) + { + try + { + for (Field field : object.getClass().getDeclaredFields()) + { + // Find the primary key field and display it + if (field.getAnnotation(Id.class) != null) + { + // Find a matching getter and invoke it to display the key + for (Method method : object.getClass().getDeclaredMethods()) + { + if (method.equals(new PropertyDescriptor(field.getName(), object.getClass()).getReadMethod())) + { + return method.invoke(object).toString(); + } + } + } + } + for (Method method : object.getClass().getDeclaredMethods()) + { + // Find the primary key as a property instead of a field, and display it + if (method.getAnnotation(Id.class) != null) + { + return method.invoke(object).toString(); + } + } + } + catch (Exception ex) + { + // Unlikely, but abort and stop view generation if any exception is thrown + throw new RuntimeException(ex); + } + } + + return null; + } + + private ViewUtils() + { + + // Can never be called + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/admin/CategoryBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/admin/CategoryBean.java new file mode 100644 index 0000000..0750c44 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/admin/CategoryBean.java @@ -0,0 +1,329 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; +import javax.ejb.SessionContext; +import javax.ejb.Stateful; +import javax.enterprise.context.Conversation; +import javax.enterprise.context.ConversationScoped; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +import org.prabuckt.application.vegancakes.model.Category; +import org.prabuckt.application.vegancakes.util.Loggable; + +/** + * Backing bean for Category entities. + *

+ * This class provides CRUD functionality for all Category entities. It focuses + * purely on Java EE 6 standards (e.g. @ConversationScoped for + * state management, PersistenceContext for persistence, + * CriteriaBuilder for searches) rather than introducing a CRUD framework or + * custom base class. + */ + +@Named +@Stateful +@ConversationScoped +@Loggable +public class CategoryBean implements Serializable +{ + + private static final long serialVersionUID = 1L; + + /* + * Support creating and retrieving Category entities + */ + + private Long id; + + public Long getId() + { + return this.id; + } + + public void setId(Long id) + { + this.id = id; + } + + private Category category; + + public Category getCategory() + { + return this.category; + } + + public void setCategory(Category category) + { + this.category = category; + } + + @Inject + private Conversation conversation; + + @PersistenceContext(unitName = "applicationVegancakesPU", type = PersistenceContextType.EXTENDED) + private EntityManager entityManager; + + public String create() + { + + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + return "create?faces-redirect=true"; + } + + public void retrieve() + { + + if (FacesContext.getCurrentInstance().isPostback()) + { + return; + } + + if (this.conversation.isTransient()) + { + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + } + + if (this.id == null) + { + this.category = this.example; + } + else + { + this.category = findById(getId()); + } + } + + public Category findById(Long id) + { + + return this.entityManager.find(Category.class, id); + } + + /* + * Support updating and deleting Category entities + */ + + public String update() + { + this.conversation.end(); + + try + { + if (this.id == null) + { + this.entityManager.persist(this.category); + return "search?faces-redirect=true"; + } + else + { + this.entityManager.merge(this.category); + return "view?faces-redirect=true&id=" + this.category.getId(); + } + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + public String delete() + { + this.conversation.end(); + + try + { + Category deletableEntity = findById(getId()); + + this.entityManager.remove(deletableEntity); + this.entityManager.flush(); + return "search?faces-redirect=true"; + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + /* + * Support searching Category entities with pagination + */ + + private int page; + private long count; + private List pageItems; + + private Category example = new Category(); + + public int getPage() + { + return this.page; + } + + public void setPage(int page) + { + this.page = page; + } + + public int getPageSize() + { + return 10; + } + + public Category getExample() + { + return this.example; + } + + public void setExample(Category example) + { + this.example = example; + } + + public String search() + { + this.page = 0; + return null; + } + + public void paginate() + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + + // Populate this.count + + CriteriaQuery countCriteria = builder.createQuery(Long.class); + Root root = countCriteria.from(Category.class); + countCriteria = countCriteria.select(builder.count(root)).where( + getSearchPredicates(root)); + this.count = this.entityManager.createQuery(countCriteria) + .getSingleResult(); + + // Populate this.pageItems + + CriteriaQuery criteria = builder.createQuery(Category.class); + root = criteria.from(Category.class); + TypedQuery query = this.entityManager.createQuery(criteria + .select(root).where(getSearchPredicates(root))); + query.setFirstResult(this.page * getPageSize()).setMaxResults( + getPageSize()); + this.pageItems = query.getResultList(); + } + + private Predicate[] getSearchPredicates(Root root) + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + String name = this.example.getName(); + if (name != null && !"".equals(name)) + { + predicatesList.add(builder.like(builder.lower(root. get("name")), '%' + name.toLowerCase() + '%')); + } + String description = this.example.getDescription(); + if (description != null && !"".equals(description)) + { + predicatesList.add(builder.like(builder.lower(root. get("description")), '%' + description.toLowerCase() + '%')); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } + + public List getPageItems() + { + return this.pageItems; + } + + public long getCount() + { + return this.count; + } + + /* + * Support listing and POSTing back Category entities (e.g. from inside an + * HtmlSelectOneMenu) + */ + + public List getAll() + { + + CriteriaQuery criteria = this.entityManager + .getCriteriaBuilder().createQuery(Category.class); + return this.entityManager.createQuery( + criteria.select(criteria.from(Category.class))).getResultList(); + } + + @Resource + private SessionContext sessionContext; + + public Converter getConverter() + { + + final CategoryBean ejbProxy = this.sessionContext.getBusinessObject(CategoryBean.class); + + return new Converter() + { + + @Override + public Object getAsObject(FacesContext context, + UIComponent component, String value) + { + + return ejbProxy.findById(Long.valueOf(value)); + } + + @Override + public String getAsString(FacesContext context, + UIComponent component, Object value) + { + + if (value == null) + { + return ""; + } + + return String.valueOf(((Category) value).getId()); + } + }; + } + + /* + * Support adding children to bidirectional, one-to-many tables + */ + + private Category add = new Category(); + + public Category getAdd() + { + return this.add; + } + + public Category getAdded() + { + Category added = this.add; + this.add = new Category(); + return added; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/admin/CountryBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/admin/CountryBean.java new file mode 100644 index 0000000..30f582d --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/admin/CountryBean.java @@ -0,0 +1,344 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; +import javax.ejb.SessionContext; +import javax.ejb.Stateful; +import javax.enterprise.context.Conversation; +import javax.enterprise.context.ConversationScoped; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +import org.prabuckt.application.vegancakes.model.Country; +import org.prabuckt.application.vegancakes.util.Loggable; + +/** + * Backing bean for Country entities. + *

+ * This class provides CRUD functionality for all Country entities. It focuses + * purely on Java EE 6 standards (e.g. @ConversationScoped for + * state management, PersistenceContext for persistence, + * CriteriaBuilder for searches) rather than introducing a CRUD framework or + * custom base class. + */ + +@Named +@Stateful +@ConversationScoped +@Loggable +public class CountryBean implements Serializable +{ + + private static final long serialVersionUID = 1L; + + /* + * Support creating and retrieving Country entities + */ + + private Long id; + + public Long getId() + { + return this.id; + } + + public void setId(Long id) + { + this.id = id; + } + + private Country country; + + public Country getCountry() + { + return this.country; + } + + public void setCountry(Country country) + { + this.country = country; + } + + @Inject + private Conversation conversation; + + @PersistenceContext(unitName = "applicationVegancakesPU", type = PersistenceContextType.EXTENDED) + private EntityManager entityManager; + + public String create() + { + + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + return "create?faces-redirect=true"; + } + + public void retrieve() + { + + if (FacesContext.getCurrentInstance().isPostback()) + { + return; + } + + if (this.conversation.isTransient()) + { + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + } + + if (this.id == null) + { + this.country = this.example; + } + else + { + this.country = findById(getId()); + } + } + + public Country findById(Long id) + { + + return this.entityManager.find(Country.class, id); + } + + /* + * Support updating and deleting Country entities + */ + + public String update() + { + this.conversation.end(); + + try + { + if (this.id == null) + { + this.entityManager.persist(this.country); + return "search?faces-redirect=true"; + } + else + { + this.entityManager.merge(this.country); + return "view?faces-redirect=true&id=" + this.country.getId(); + } + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + public String delete() + { + this.conversation.end(); + + try + { + Country deletableEntity = findById(getId()); + + this.entityManager.remove(deletableEntity); + this.entityManager.flush(); + return "search?faces-redirect=true"; + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + /* + * Support searching Country entities with pagination + */ + + private int page; + private long count; + private List pageItems; + + private Country example = new Country(); + + public int getPage() + { + return this.page; + } + + public void setPage(int page) + { + this.page = page; + } + + public int getPageSize() + { + return 10; + } + + public Country getExample() + { + return this.example; + } + + public void setExample(Country example) + { + this.example = example; + } + + public String search() + { + this.page = 0; + return null; + } + + public void paginate() + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + + // Populate this.count + + CriteriaQuery countCriteria = builder.createQuery(Long.class); + Root root = countCriteria.from(Country.class); + countCriteria = countCriteria.select(builder.count(root)).where( + getSearchPredicates(root)); + this.count = this.entityManager.createQuery(countCriteria) + .getSingleResult(); + + // Populate this.pageItems + + CriteriaQuery criteria = builder.createQuery(Country.class); + root = criteria.from(Country.class); + TypedQuery query = this.entityManager.createQuery(criteria + .select(root).where(getSearchPredicates(root))); + query.setFirstResult(this.page * getPageSize()).setMaxResults( + getPageSize()); + this.pageItems = query.getResultList(); + } + + private Predicate[] getSearchPredicates(Root root) + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + String isoCode = this.example.getIsoCode(); + if (isoCode != null && !"".equals(isoCode)) + { + predicatesList.add(builder.like(builder.lower(root. get("isoCode")), '%' + isoCode.toLowerCase() + '%')); + } + String name = this.example.getName(); + if (name != null && !"".equals(name)) + { + predicatesList.add(builder.like(builder.lower(root. get("name")), '%' + name.toLowerCase() + '%')); + } + String printableName = this.example.getPrintableName(); + if (printableName != null && !"".equals(printableName)) + { + predicatesList.add(builder.like(builder.lower(root. get("printableName")), '%' + printableName.toLowerCase() + '%')); + } + String iso3 = this.example.getIso3(); + if (iso3 != null && !"".equals(iso3)) + { + predicatesList.add(builder.like(builder.lower(root. get("iso3")), '%' + iso3.toLowerCase() + '%')); + } + String numcode = this.example.getNumcode(); + if (numcode != null && !"".equals(numcode)) + { + predicatesList.add(builder.like(builder.lower(root. get("numcode")), '%' + numcode.toLowerCase() + '%')); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } + + public List getPageItems() + { + return this.pageItems; + } + + public long getCount() + { + return this.count; + } + + /* + * Support listing and POSTing back Country entities (e.g. from inside an + * HtmlSelectOneMenu) + */ + + public List getAll() + { + + CriteriaQuery criteria = this.entityManager + .getCriteriaBuilder().createQuery(Country.class); + return this.entityManager.createQuery( + criteria.select(criteria.from(Country.class))).getResultList(); + } + + @Resource + private SessionContext sessionContext; + + public Converter getConverter() + { + + final CountryBean ejbProxy = this.sessionContext.getBusinessObject(CountryBean.class); + + return new Converter() + { + + @Override + public Object getAsObject(FacesContext context, + UIComponent component, String value) + { + + return ejbProxy.findById(Long.valueOf(value)); + } + + @Override + public String getAsString(FacesContext context, + UIComponent component, Object value) + { + + if (value == null) + { + return ""; + } + + return String.valueOf(((Country) value).getId()); + } + }; + } + + /* + * Support adding children to bidirectional, one-to-many tables + */ + + private Country add = new Country(); + + public Country getAdd() + { + return this.add; + } + + public Country getAdded() + { + Country added = this.add; + this.add = new Country(); + return added; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/admin/CustomerBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/admin/CustomerBean.java new file mode 100644 index 0000000..9131985 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/admin/CustomerBean.java @@ -0,0 +1,344 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; +import javax.ejb.SessionContext; +import javax.ejb.Stateful; +import javax.enterprise.context.Conversation; +import javax.enterprise.context.ConversationScoped; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +import org.prabuckt.application.vegancakes.model.Customer; +import org.prabuckt.application.vegancakes.util.Loggable; + +/** + * Backing bean for Customer entities. + *

+ * This class provides CRUD functionality for all Customer entities. It focuses + * purely on Java EE 6 standards (e.g. @ConversationScoped for + * state management, PersistenceContext for persistence, + * CriteriaBuilder for searches) rather than introducing a CRUD framework or + * custom base class. + */ + +@Named +@Stateful +@ConversationScoped +@Loggable +public class CustomerBean implements Serializable +{ + + private static final long serialVersionUID = 1L; + + /* + * Support creating and retrieving Customer entities + */ + + private Long id; + + public Long getId() + { + return this.id; + } + + public void setId(Long id) + { + this.id = id; + } + + private Customer customer; + + public Customer getCustomer() + { + return this.customer; + } + + public void setCustomer(Customer customer) + { + this.customer = customer; + } + + @Inject + private Conversation conversation; + + @PersistenceContext(unitName = "applicationVegancakesPU", type = PersistenceContextType.EXTENDED) + private EntityManager entityManager; + + public String create() + { + + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + return "create?faces-redirect=true"; + } + + public void retrieve() + { + + if (FacesContext.getCurrentInstance().isPostback()) + { + return; + } + + if (this.conversation.isTransient()) + { + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + } + + if (this.id == null) + { + this.customer = this.example; + } + else + { + this.customer = findById(getId()); + } + } + + public Customer findById(Long id) + { + + return this.entityManager.find(Customer.class, id); + } + + /* + * Support updating and deleting Customer entities + */ + + public String update() + { + this.conversation.end(); + + try + { + if (this.id == null) + { + this.entityManager.persist(this.customer); + return "search?faces-redirect=true"; + } + else + { + this.entityManager.merge(this.customer); + return "view?faces-redirect=true&id=" + this.customer.getId(); + } + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + public String delete() + { + this.conversation.end(); + + try + { + Customer deletableEntity = findById(getId()); + + this.entityManager.remove(deletableEntity); + this.entityManager.flush(); + return "search?faces-redirect=true"; + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + /* + * Support searching Customer entities with pagination + */ + + private int page; + private long count; + private List pageItems; + + private Customer example = new Customer(); + + public int getPage() + { + return this.page; + } + + public void setPage(int page) + { + this.page = page; + } + + public int getPageSize() + { + return 10; + } + + public Customer getExample() + { + return this.example; + } + + public void setExample(Customer example) + { + this.example = example; + } + + public String search() + { + this.page = 0; + return null; + } + + public void paginate() + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + + // Populate this.count + + CriteriaQuery countCriteria = builder.createQuery(Long.class); + Root root = countCriteria.from(Customer.class); + countCriteria = countCriteria.select(builder.count(root)).where( + getSearchPredicates(root)); + this.count = this.entityManager.createQuery(countCriteria) + .getSingleResult(); + + // Populate this.pageItems + + CriteriaQuery criteria = builder.createQuery(Customer.class); + root = criteria.from(Customer.class); + TypedQuery query = this.entityManager.createQuery(criteria + .select(root).where(getSearchPredicates(root))); + query.setFirstResult(this.page * getPageSize()).setMaxResults( + getPageSize()); + this.pageItems = query.getResultList(); + } + + private Predicate[] getSearchPredicates(Root root) + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + String firstName = this.example.getFirstName(); + if (firstName != null && !"".equals(firstName)) + { + predicatesList.add(builder.like(builder.lower(root. get("firstName")), '%' + firstName.toLowerCase() + '%')); + } + String lastName = this.example.getLastName(); + if (lastName != null && !"".equals(lastName)) + { + predicatesList.add(builder.like(builder.lower(root. get("lastName")), '%' + lastName.toLowerCase() + '%')); + } + String telephone = this.example.getTelephone(); + if (telephone != null && !"".equals(telephone)) + { + predicatesList.add(builder.like(builder.lower(root. get("telephone")), '%' + telephone.toLowerCase() + '%')); + } + String email = this.example.getEmail(); + if (email != null && !"".equals(email)) + { + predicatesList.add(builder.like(builder.lower(root. get("email")), '%' + email.toLowerCase() + '%')); + } + String login = this.example.getLogin(); + if (login != null && !"".equals(login)) + { + predicatesList.add(builder.like(builder.lower(root. get("login")), '%' + login.toLowerCase() + '%')); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } + + public List getPageItems() + { + return this.pageItems; + } + + public long getCount() + { + return this.count; + } + + /* + * Support listing and POSTing back Customer entities (e.g. from inside an + * HtmlSelectOneMenu) + */ + + public List getAll() + { + + CriteriaQuery criteria = this.entityManager + .getCriteriaBuilder().createQuery(Customer.class); + return this.entityManager.createQuery( + criteria.select(criteria.from(Customer.class))).getResultList(); + } + + @Resource + private SessionContext sessionContext; + + public Converter getConverter() + { + + final CustomerBean ejbProxy = this.sessionContext.getBusinessObject(CustomerBean.class); + + return new Converter() + { + + @Override + public Object getAsObject(FacesContext context, + UIComponent component, String value) + { + + return ejbProxy.findById(Long.valueOf(value)); + } + + @Override + public String getAsString(FacesContext context, + UIComponent component, Object value) + { + + if (value == null) + { + return ""; + } + + return String.valueOf(((Customer) value).getId()); + } + }; + } + + /* + * Support adding children to bidirectional, one-to-many tables + */ + + private Customer add = new Customer(); + + public Customer getAdd() + { + return this.add; + } + + public Customer getAdded() + { + Customer added = this.add; + this.add = new Customer(); + return added; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/admin/ItemBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/admin/ItemBean.java new file mode 100644 index 0000000..4f4ee7e --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/admin/ItemBean.java @@ -0,0 +1,340 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; +import javax.ejb.SessionContext; +import javax.ejb.Stateful; +import javax.enterprise.context.Conversation; +import javax.enterprise.context.ConversationScoped; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +import org.prabuckt.application.vegancakes.model.Item; +import org.prabuckt.application.vegancakes.model.Product; +import org.prabuckt.application.vegancakes.util.Loggable; + +/** + * Backing bean for Item entities. + *

+ * This class provides CRUD functionality for all Item entities. It focuses + * purely on Java EE 6 standards (e.g. @ConversationScoped for + * state management, PersistenceContext for persistence, + * CriteriaBuilder for searches) rather than introducing a CRUD framework or + * custom base class. + */ + +@Named +@Stateful +@ConversationScoped +@Loggable +public class ItemBean implements Serializable +{ + + private static final long serialVersionUID = 1L; + + /* + * Support creating and retrieving Item entities + */ + + private Long id; + + public Long getId() + { + return this.id; + } + + public void setId(Long id) + { + this.id = id; + } + + private Item item; + + public Item getItem() + { + return this.item; + } + + public void setItem(Item item) + { + this.item = item; + } + + @Inject + private Conversation conversation; + + @PersistenceContext(unitName = "applicationVegancakesPU", type = PersistenceContextType.EXTENDED) + private EntityManager entityManager; + + public String create() + { + + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + return "create?faces-redirect=true"; + } + + public void retrieve() + { + + if (FacesContext.getCurrentInstance().isPostback()) + { + return; + } + + if (this.conversation.isTransient()) + { + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + } + + if (this.id == null) + { + this.item = this.example; + } + else + { + this.item = findById(getId()); + } + } + + public Item findById(Long id) + { + + return this.entityManager.find(Item.class, id); + } + + /* + * Support updating and deleting Item entities + */ + + public String update() + { + this.conversation.end(); + + try + { + if (this.id == null) + { + this.entityManager.persist(this.item); + return "search?faces-redirect=true"; + } + else + { + this.entityManager.merge(this.item); + return "view?faces-redirect=true&id=" + this.item.getId(); + } + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + public String delete() + { + this.conversation.end(); + + try + { + Item deletableEntity = findById(getId()); + + this.entityManager.remove(deletableEntity); + this.entityManager.flush(); + return "search?faces-redirect=true"; + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + /* + * Support searching Item entities with pagination + */ + + private int page; + private long count; + private List pageItems; + + private Item example = new Item(); + + public int getPage() + { + return this.page; + } + + public void setPage(int page) + { + this.page = page; + } + + public int getPageSize() + { + return 10; + } + + public Item getExample() + { + return this.example; + } + + public void setExample(Item example) + { + this.example = example; + } + + public String search() + { + this.page = 0; + return null; + } + + public void paginate() + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + + // Populate this.count + + CriteriaQuery countCriteria = builder.createQuery(Long.class); + Root root = countCriteria.from(Item.class); + countCriteria = countCriteria.select(builder.count(root)).where( + getSearchPredicates(root)); + this.count = this.entityManager.createQuery(countCriteria) + .getSingleResult(); + + // Populate this.pageItems + + CriteriaQuery criteria = builder.createQuery(Item.class); + root = criteria.from(Item.class); + TypedQuery query = this.entityManager.createQuery(criteria + .select(root).where(getSearchPredicates(root))); + query.setFirstResult(this.page * getPageSize()).setMaxResults( + getPageSize()); + this.pageItems = query.getResultList(); + } + + private Predicate[] getSearchPredicates(Root root) + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + String name = this.example.getName(); + if (name != null && !"".equals(name)) + { + predicatesList.add(builder.like(builder.lower(root. get("name")), '%' + name.toLowerCase() + '%')); + } + String description = this.example.getDescription(); + if (description != null && !"".equals(description)) + { + predicatesList.add(builder.like(builder.lower(root. get("description")), '%' + description.toLowerCase() + '%')); + } + String imagePath = this.example.getImagePath(); + if (imagePath != null && !"".equals(imagePath)) + { + predicatesList.add(builder.like(builder.lower(root. get("imagePath")), '%' + imagePath.toLowerCase() + '%')); + } + Product product = this.example.getProduct(); + if (product != null) + { + predicatesList.add(builder.equal(root.get("product"), product)); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } + + public List getPageItems() + { + return this.pageItems; + } + + public long getCount() + { + return this.count; + } + + /* + * Support listing and POSTing back Item entities (e.g. from inside an + * HtmlSelectOneMenu) + */ + + public List getAll() + { + + CriteriaQuery criteria = this.entityManager + .getCriteriaBuilder().createQuery(Item.class); + return this.entityManager.createQuery( + criteria.select(criteria.from(Item.class))).getResultList(); + } + + @Resource + private SessionContext sessionContext; + + public Converter getConverter() + { + + final ItemBean ejbProxy = this.sessionContext.getBusinessObject(ItemBean.class); + + return new Converter() + { + + @Override + public Object getAsObject(FacesContext context, + UIComponent component, String value) + { + + return ejbProxy.findById(Long.valueOf(value)); + } + + @Override + public String getAsString(FacesContext context, + UIComponent component, Object value) + { + + if (value == null) + { + return ""; + } + + return String.valueOf(((Item) value).getId()); + } + }; + } + + /* + * Support adding children to bidirectional, one-to-many tables + */ + + private Item add = new Item(); + + public Item getAdd() + { + return this.add; + } + + public Item getAdded() + { + Item added = this.add; + this.add = new Item(); + return added; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/admin/OrderLineBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/admin/OrderLineBean.java new file mode 100644 index 0000000..19cbed6 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/admin/OrderLineBean.java @@ -0,0 +1,330 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; +import javax.ejb.SessionContext; +import javax.ejb.Stateful; +import javax.enterprise.context.Conversation; +import javax.enterprise.context.ConversationScoped; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +import org.prabuckt.application.vegancakes.model.OrderLine; +import org.prabuckt.application.vegancakes.model.Item; +import org.prabuckt.application.vegancakes.util.Loggable; + +/** + * Backing bean for OrderLine entities. + *

+ * This class provides CRUD functionality for all OrderLine entities. It focuses + * purely on Java EE 6 standards (e.g. @ConversationScoped for + * state management, PersistenceContext for persistence, + * CriteriaBuilder for searches) rather than introducing a CRUD framework or + * custom base class. + */ + +@Named +@Stateful +@ConversationScoped +@Loggable +public class OrderLineBean implements Serializable +{ + + private static final long serialVersionUID = 1L; + + /* + * Support creating and retrieving OrderLine entities + */ + + private Long id; + + public Long getId() + { + return this.id; + } + + public void setId(Long id) + { + this.id = id; + } + + private OrderLine orderLine; + + public OrderLine getOrderLine() + { + return this.orderLine; + } + + public void setOrderLine(OrderLine orderLine) + { + this.orderLine = orderLine; + } + + @Inject + private Conversation conversation; + + @PersistenceContext(unitName = "applicationVegancakesPU", type = PersistenceContextType.EXTENDED) + private EntityManager entityManager; + + public String create() + { + + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + return "create?faces-redirect=true"; + } + + public void retrieve() + { + + if (FacesContext.getCurrentInstance().isPostback()) + { + return; + } + + if (this.conversation.isTransient()) + { + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + } + + if (this.id == null) + { + this.orderLine = this.example; + } + else + { + this.orderLine = findById(getId()); + } + } + + public OrderLine findById(Long id) + { + + return this.entityManager.find(OrderLine.class, id); + } + + /* + * Support updating and deleting OrderLine entities + */ + + public String update() + { + this.conversation.end(); + + try + { + if (this.id == null) + { + this.entityManager.persist(this.orderLine); + return "search?faces-redirect=true"; + } + else + { + this.entityManager.merge(this.orderLine); + return "view?faces-redirect=true&id=" + this.orderLine.getId(); + } + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + public String delete() + { + this.conversation.end(); + + try + { + OrderLine deletableEntity = findById(getId()); + + this.entityManager.remove(deletableEntity); + this.entityManager.flush(); + return "search?faces-redirect=true"; + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + /* + * Support searching OrderLine entities with pagination + */ + + private int page; + private long count; + private List pageItems; + + private OrderLine example = new OrderLine(); + + public int getPage() + { + return this.page; + } + + public void setPage(int page) + { + this.page = page; + } + + public int getPageSize() + { + return 10; + } + + public OrderLine getExample() + { + return this.example; + } + + public void setExample(OrderLine example) + { + this.example = example; + } + + public String search() + { + this.page = 0; + return null; + } + + public void paginate() + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + + // Populate this.count + + CriteriaQuery countCriteria = builder.createQuery(Long.class); + Root root = countCriteria.from(OrderLine.class); + countCriteria = countCriteria.select(builder.count(root)).where( + getSearchPredicates(root)); + this.count = this.entityManager.createQuery(countCriteria) + .getSingleResult(); + + // Populate this.pageItems + + CriteriaQuery criteria = builder.createQuery(OrderLine.class); + root = criteria.from(OrderLine.class); + TypedQuery query = this.entityManager.createQuery(criteria + .select(root).where(getSearchPredicates(root))); + query.setFirstResult(this.page * getPageSize()).setMaxResults( + getPageSize()); + this.pageItems = query.getResultList(); + } + + private Predicate[] getSearchPredicates(Root root) + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + Integer quantity = this.example.getQuantity(); + if (quantity != null && quantity.intValue() != 0) + { + predicatesList.add(builder.equal(root.get("quantity"), quantity)); + } + Item item = this.example.getItem(); + if (item != null) + { + predicatesList.add(builder.equal(root.get("item"), item)); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } + + public List getPageItems() + { + return this.pageItems; + } + + public long getCount() + { + return this.count; + } + + /* + * Support listing and POSTing back OrderLine entities (e.g. from inside an + * HtmlSelectOneMenu) + */ + + public List getAll() + { + + CriteriaQuery criteria = this.entityManager + .getCriteriaBuilder().createQuery(OrderLine.class); + return this.entityManager.createQuery( + criteria.select(criteria.from(OrderLine.class))).getResultList(); + } + + @Resource + private SessionContext sessionContext; + + public Converter getConverter() + { + + final OrderLineBean ejbProxy = this.sessionContext.getBusinessObject(OrderLineBean.class); + + return new Converter() + { + + @Override + public Object getAsObject(FacesContext context, + UIComponent component, String value) + { + + return ejbProxy.findById(Long.valueOf(value)); + } + + @Override + public String getAsString(FacesContext context, + UIComponent component, Object value) + { + + if (value == null) + { + return ""; + } + + return String.valueOf(((OrderLine) value).getId()); + } + }; + } + + /* + * Support adding children to bidirectional, one-to-many tables + */ + + private OrderLine add = new OrderLine(); + + public OrderLine getAdd() + { + return this.add; + } + + public OrderLine getAdded() + { + OrderLine added = this.add; + this.add = new OrderLine(); + return added; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/admin/ProductBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/admin/ProductBean.java new file mode 100644 index 0000000..31515d2 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/admin/ProductBean.java @@ -0,0 +1,335 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; +import javax.ejb.SessionContext; +import javax.ejb.Stateful; +import javax.enterprise.context.Conversation; +import javax.enterprise.context.ConversationScoped; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +import org.prabuckt.application.vegancakes.model.Product; +import org.prabuckt.application.vegancakes.model.Category; +import org.prabuckt.application.vegancakes.util.Loggable; + +/** + * Backing bean for Product entities. + *

+ * This class provides CRUD functionality for all Product entities. It focuses + * purely on Java EE 6 standards (e.g. @ConversationScoped for + * state management, PersistenceContext for persistence, + * CriteriaBuilder for searches) rather than introducing a CRUD framework or + * custom base class. + */ + +@Named +@Stateful +@ConversationScoped +@Loggable +public class ProductBean implements Serializable +{ + + private static final long serialVersionUID = 1L; + + /* + * Support creating and retrieving Product entities + */ + + private Long id; + + public Long getId() + { + return this.id; + } + + public void setId(Long id) + { + this.id = id; + } + + private Product product; + + public Product getProduct() + { + return this.product; + } + + public void setProduct(Product product) + { + this.product = product; + } + + @Inject + private Conversation conversation; + + @PersistenceContext(unitName = "applicationVegancakesPU", type = PersistenceContextType.EXTENDED) + private EntityManager entityManager; + + public String create() + { + + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + return "create?faces-redirect=true"; + } + + public void retrieve() + { + + if (FacesContext.getCurrentInstance().isPostback()) + { + return; + } + + if (this.conversation.isTransient()) + { + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + } + + if (this.id == null) + { + this.product = this.example; + } + else + { + this.product = findById(getId()); + } + } + + public Product findById(Long id) + { + + return this.entityManager.find(Product.class, id); + } + + /* + * Support updating and deleting Product entities + */ + + public String update() + { + this.conversation.end(); + + try + { + if (this.id == null) + { + this.entityManager.persist(this.product); + return "search?faces-redirect=true"; + } + else + { + this.entityManager.merge(this.product); + return "view?faces-redirect=true&id=" + this.product.getId(); + } + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + public String delete() + { + this.conversation.end(); + + try + { + Product deletableEntity = findById(getId()); + + this.entityManager.remove(deletableEntity); + this.entityManager.flush(); + return "search?faces-redirect=true"; + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + /* + * Support searching Product entities with pagination + */ + + private int page; + private long count; + private List pageItems; + + private Product example = new Product(); + + public int getPage() + { + return this.page; + } + + public void setPage(int page) + { + this.page = page; + } + + public int getPageSize() + { + return 10; + } + + public Product getExample() + { + return this.example; + } + + public void setExample(Product example) + { + this.example = example; + } + + public String search() + { + this.page = 0; + return null; + } + + public void paginate() + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + + // Populate this.count + + CriteriaQuery countCriteria = builder.createQuery(Long.class); + Root root = countCriteria.from(Product.class); + countCriteria = countCriteria.select(builder.count(root)).where( + getSearchPredicates(root)); + this.count = this.entityManager.createQuery(countCriteria) + .getSingleResult(); + + // Populate this.pageItems + + CriteriaQuery criteria = builder.createQuery(Product.class); + root = criteria.from(Product.class); + TypedQuery query = this.entityManager.createQuery(criteria + .select(root).where(getSearchPredicates(root))); + query.setFirstResult(this.page * getPageSize()).setMaxResults( + getPageSize()); + this.pageItems = query.getResultList(); + } + + private Predicate[] getSearchPredicates(Root root) + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + String name = this.example.getName(); + if (name != null && !"".equals(name)) + { + predicatesList.add(builder.like(builder.lower(root. get("name")), '%' + name.toLowerCase() + '%')); + } + String description = this.example.getDescription(); + if (description != null && !"".equals(description)) + { + predicatesList.add(builder.like(builder.lower(root. get("description")), '%' + description.toLowerCase() + '%')); + } + Category category = this.example.getCategory(); + if (category != null) + { + predicatesList.add(builder.equal(root.get("category"), category)); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } + + public List getPageItems() + { + return this.pageItems; + } + + public long getCount() + { + return this.count; + } + + /* + * Support listing and POSTing back Product entities (e.g. from inside an + * HtmlSelectOneMenu) + */ + + public List getAll() + { + + CriteriaQuery criteria = this.entityManager + .getCriteriaBuilder().createQuery(Product.class); + return this.entityManager.createQuery( + criteria.select(criteria.from(Product.class))).getResultList(); + } + + @Resource + private SessionContext sessionContext; + + public Converter getConverter() + { + + final ProductBean ejbProxy = this.sessionContext.getBusinessObject(ProductBean.class); + + return new Converter() + { + + @Override + public Object getAsObject(FacesContext context, + UIComponent component, String value) + { + + return ejbProxy.findById(Long.valueOf(value)); + } + + @Override + public String getAsString(FacesContext context, + UIComponent component, Object value) + { + + if (value == null) + { + return ""; + } + + return String.valueOf(((Product) value).getId()); + } + }; + } + + /* + * Support adding children to bidirectional, one-to-many tables + */ + + private Product add = new Product(); + + public Product getAdd() + { + return this.add; + } + + public Product getAdded() + { + Product added = this.add; + this.add = new Product(); + return added; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/admin/PurchaseOrderBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/admin/PurchaseOrderBean.java new file mode 100644 index 0000000..8bffb19 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/admin/PurchaseOrderBean.java @@ -0,0 +1,344 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; +import javax.ejb.SessionContext; +import javax.ejb.Stateful; +import javax.enterprise.context.Conversation; +import javax.enterprise.context.ConversationScoped; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +import org.prabuckt.application.vegancakes.model.PurchaseOrder; +import org.prabuckt.application.vegancakes.util.Loggable; + +/** + * Backing bean for PurchaseOrder entities. + *

+ * This class provides CRUD functionality for all PurchaseOrder entities. It focuses + * purely on Java EE 6 standards (e.g. @ConversationScoped for + * state management, PersistenceContext for persistence, + * CriteriaBuilder for searches) rather than introducing a CRUD framework or + * custom base class. + */ + +@Named +@Stateful +@ConversationScoped +@Loggable +public class PurchaseOrderBean implements Serializable +{ + + private static final long serialVersionUID = 1L; + + /* + * Support creating and retrieving PurchaseOrder entities + */ + + private Long id; + + public Long getId() + { + return this.id; + } + + public void setId(Long id) + { + this.id = id; + } + + private PurchaseOrder purchaseOrder; + + public PurchaseOrder getPurchaseOrder() + { + return this.purchaseOrder; + } + + public void setPurchaseOrder(PurchaseOrder purchaseOrder) + { + this.purchaseOrder = purchaseOrder; + } + + @Inject + private Conversation conversation; + + @PersistenceContext(unitName = "applicationVegancakesPU", type = PersistenceContextType.EXTENDED) + private EntityManager entityManager; + + public String create() + { + + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + return "create?faces-redirect=true"; + } + + public void retrieve() + { + + if (FacesContext.getCurrentInstance().isPostback()) + { + return; + } + + if (this.conversation.isTransient()) + { + this.conversation.begin(); + this.conversation.setTimeout(1800000L); + } + + if (this.id == null) + { + this.purchaseOrder = this.example; + } + else + { + this.purchaseOrder = findById(getId()); + } + } + + public PurchaseOrder findById(Long id) + { + + return this.entityManager.find(PurchaseOrder.class, id); + } + + /* + * Support updating and deleting PurchaseOrder entities + */ + + public String update() + { + this.conversation.end(); + + try + { + if (this.id == null) + { + this.entityManager.persist(this.purchaseOrder); + return "search?faces-redirect=true"; + } + else + { + this.entityManager.merge(this.purchaseOrder); + return "view?faces-redirect=true&id=" + this.purchaseOrder.getId(); + } + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + public String delete() + { + this.conversation.end(); + + try + { + PurchaseOrder deletableEntity = findById(getId()); + + this.entityManager.remove(deletableEntity); + this.entityManager.flush(); + return "search?faces-redirect=true"; + } + catch (Exception e) + { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage())); + return null; + } + } + + /* + * Support searching PurchaseOrder entities with pagination + */ + + private int page; + private long count; + private List pageItems; + + private PurchaseOrder example = new PurchaseOrder(); + + public int getPage() + { + return this.page; + } + + public void setPage(int page) + { + this.page = page; + } + + public int getPageSize() + { + return 10; + } + + public PurchaseOrder getExample() + { + return this.example; + } + + public void setExample(PurchaseOrder example) + { + this.example = example; + } + + public String search() + { + this.page = 0; + return null; + } + + public void paginate() + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + + // Populate this.count + + CriteriaQuery countCriteria = builder.createQuery(Long.class); + Root root = countCriteria.from(PurchaseOrder.class); + countCriteria = countCriteria.select(builder.count(root)).where( + getSearchPredicates(root)); + this.count = this.entityManager.createQuery(countCriteria) + .getSingleResult(); + + // Populate this.pageItems + + CriteriaQuery criteria = builder.createQuery(PurchaseOrder.class); + root = criteria.from(PurchaseOrder.class); + TypedQuery query = this.entityManager.createQuery(criteria + .select(root).where(getSearchPredicates(root))); + query.setFirstResult(this.page * getPageSize()).setMaxResults( + getPageSize()); + this.pageItems = query.getResultList(); + } + + private Predicate[] getSearchPredicates(Root root) + { + + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); + List predicatesList = new ArrayList(); + + String street1 = this.example.getDeliveryAddress().getStreet1(); + if (street1 != null && !"".equals(street1)) + { + predicatesList.add(builder.like(builder.lower(root. get("street1")), '%' + street1.toLowerCase() + '%')); + } + String street2 = this.example.getDeliveryAddress().getStreet2(); + if (street2 != null && !"".equals(street2)) + { + predicatesList.add(builder.like(builder.lower(root. get("street2")), '%' + street2.toLowerCase() + '%')); + } + String city = this.example.getDeliveryAddress().getCity(); + if (city != null && !"".equals(city)) + { + predicatesList.add(builder.like(builder.lower(root. get("city")), '%' + city.toLowerCase() + '%')); + } + String state = this.example.getDeliveryAddress().getState(); + if (state != null && !"".equals(state)) + { + predicatesList.add(builder.like(builder.lower(root. get("state")), '%' + state.toLowerCase() + '%')); + } + String postcode = this.example.getDeliveryAddress().getPostcode(); + if (postcode != null && !"".equals(postcode)) + { + predicatesList.add(builder.like(builder.lower(root. get("postcode")), '%' + postcode.toLowerCase() + '%')); + } + + return predicatesList.toArray(new Predicate[predicatesList.size()]); + } + + public List getPageItems() + { + return this.pageItems; + } + + public long getCount() + { + return this.count; + } + + /* + * Support listing and POSTing back PurchaseOrder entities (e.g. from inside an + * HtmlSelectOneMenu) + */ + + public List getAll() + { + + CriteriaQuery criteria = this.entityManager + .getCriteriaBuilder().createQuery(PurchaseOrder.class); + return this.entityManager.createQuery( + criteria.select(criteria.from(PurchaseOrder.class))).getResultList(); + } + + @Resource + private SessionContext sessionContext; + + public Converter getConverter() + { + + final PurchaseOrderBean ejbProxy = this.sessionContext.getBusinessObject(PurchaseOrderBean.class); + + return new Converter() + { + + @Override + public Object getAsObject(FacesContext context, + UIComponent component, String value) + { + + return ejbProxy.findById(Long.valueOf(value)); + } + + @Override + public String getAsString(FacesContext context, + UIComponent component, Object value) + { + + if (value == null) + { + return ""; + } + + return String.valueOf(((PurchaseOrder) value).getId()); + } + }; + } + + /* + * Support adding children to bidirectional, one-to-many tables + */ + + private PurchaseOrder add = new PurchaseOrder(); + + public PurchaseOrder getAdd() + { + return this.add; + } + + public PurchaseOrder getAdded() + { + PurchaseOrder added = this.add; + this.add = new PurchaseOrder(); + return added; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/shopping/AccountBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/shopping/AccountBean.java new file mode 100755 index 0000000..6601e78 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/shopping/AccountBean.java @@ -0,0 +1,135 @@ +package org.prabuckt.application.vegancakes.view.shopping; + +import org.prabuckt.application.vegancakes.model.Customer; +import org.prabuckt.application.vegancakes.service.CustomerService; +import org.prabuckt.application.vegancakes.util.Loggable; +import org.prabuckt.application.vegancakes.view.AbstractBean; +import org.prabuckt.application.vegancakes.view.CatchException; +import org.prabuckt.application.vegancakes.view.LoggedIn; + +import javax.enterprise.context.Conversation; +import javax.enterprise.context.SessionScoped; +import javax.enterprise.inject.Produces; +import javax.inject.Inject; +import javax.inject.Named; +import javax.security.auth.login.LoginContext; +import javax.security.auth.login.LoginException; +import java.io.Serializable; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Named +@SessionScoped +@Loggable +@CatchException +public class AccountBean extends AbstractBean implements Serializable { + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private CustomerService customerService; + + @Inject + private CredentialsBean credentials; + + @Inject + private Conversation conversation; + + @Produces + @LoggedIn + private Customer loggedinCustomer; + + @Inject + @SessionScoped + private transient LoginContext loginContext; + + // ====================================== + // = Public Methods = + // ====================================== + + public String doLogin() throws LoginException { + if (credentials.getLogin() == null || "".equals(credentials.getLogin())) { + addWarningMessage("id_filled"); + return null; + } + if (credentials.getPassword() == null || "".equals(credentials.getPassword())) { + addWarningMessage("pwd_filled"); + return null; + } + + loggedinCustomer = customerService.findCustomer(credentials.getLogin(), credentials.getPassword()); + + if (loggedinCustomer == null) { + addErrorMessage("authentication_failed"); + return null; + } + addInformationMessage("authentication_success"); + return "main.faces"; + } + + public String doCreateNewAccount() { + + // Login has to be unique + if (customerService.doesLoginAlreadyExist(credentials.getLogin())) { + addWarningMessage("login_exists"); + return null; + } + + // Id and password must be filled + if ("".equals(credentials.getLogin()) || "".equals(credentials.getPassword()) || "".equals(credentials.getPassword2())) { + addWarningMessage("id_pwd_filled"); + return null; + } else if (!credentials.getPassword().equals(credentials.getPassword2())) { + addWarningMessage("both_pwd_same"); + return null; + } + + // Login and password are ok + loggedinCustomer = new Customer(); + loggedinCustomer.setLogin(credentials.getLogin()); + loggedinCustomer.setPassword(credentials.getPassword()); + + return "createaccount.faces"; + } + + public String doCreateCustomer() { + loggedinCustomer = customerService.createCustomer(loggedinCustomer); + addInformationMessage("account_creation_success"); + return "main.faces"; + } + + + public String doLogout() { + loggedinCustomer = null; + // Stop conversation + if (!conversation.isTransient()) { + conversation.end(); + } + addInformationMessage("been_loggedout"); + return "main.faces"; + } + + public String doUpdateAccount() { + loggedinCustomer = customerService.updateCustomer(loggedinCustomer); + addInformationMessage("account_updated"); + return "showaccount.faces"; + } + + public boolean isLoggedIn() { + return loggedinCustomer != null; + } + + public Customer getLoggedinCustomer() { + return loggedinCustomer; + } + + public void setLoggedinCustomer(Customer loggedinCustomer) { + this.loggedinCustomer = loggedinCustomer; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/shopping/CatalogBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/shopping/CatalogBean.java new file mode 100755 index 0000000..a02b92c --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/shopping/CatalogBean.java @@ -0,0 +1,136 @@ +package org.prabuckt.application.vegancakes.view.shopping; + +import org.prabuckt.application.vegancakes.model.Item; +import org.prabuckt.application.vegancakes.model.Product; +import org.prabuckt.application.vegancakes.service.CatalogService; +import org.prabuckt.application.vegancakes.util.Loggable; +import org.prabuckt.application.vegancakes.view.AbstractBean; +import org.prabuckt.application.vegancakes.view.CatchException; + +import javax.enterprise.context.SessionScoped; +import javax.inject.Inject; +import javax.inject.Named; +import java.io.Serializable; +import java.util.List; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Named +//@RequestScoped TODO should be request scoped +@SessionScoped +@Loggable +@CatchException +public class CatalogBean extends AbstractBean implements Serializable { + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private CatalogService catalogService; + + private String categoryName; + private Long productId; + private Long itemId; + + private String keyword; + private Product product; + private Item item; + private List products; + private List items; + + // ====================================== + // = Public Methods = + // ====================================== + + public String doFindProducts() { + products = catalogService.findProducts(categoryName); + return "showproducts.faces"; + } + + public String doFindItems() { + product = catalogService.findProduct(productId); + items = catalogService.findItems(productId); + return "showitems.faces"; + } + + public String doFindItem() { + item = catalogService.findItem(itemId); + return "showitem.faces"; + } + + /** + * Can also be invoked in a RESTful way : + * http://localhost:8080/applicationVegancakes/searchresult.xhtml?keyword=tail + */ + public String doSearch() { + items = catalogService.searchItems(keyword); +// return "searchresult"; + return "searchresult.faces&faces-redirect=true"; +// return "searchresult.faces?keyword=" + keyword + "&faces-redirect=true"; + } + + // ====================================== + // = Getters & setters = + // ====================================== + + public Product getProduct() { + return product; + } + + public void setProduct(Product product) { + this.product = product; + } + + public Item getItem() { + return item; + } + + public void setItem(Item item) { + this.item = item; + } + + public List getProducts() { + return products; + } + + public List getItems() { + return items; + } + + public String getKeyword() { + return keyword; + } + + public void setKeyword(String keyword) { + this.keyword = keyword; + } + + public String getCategoryName() { + return categoryName; + } + + public void setCategoryName(String categoryName) { + this.categoryName = categoryName; + } + + public Long getProductId() { + return productId; + } + + public void setProductId(Long productId) { + this.productId = productId; + } + + public Long getItemId() { + return itemId; + } + + public void setItemId(Long itemId) { + this.itemId = itemId; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/shopping/CredentialsBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/shopping/CredentialsBean.java new file mode 100755 index 0000000..f450ce1 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/shopping/CredentialsBean.java @@ -0,0 +1,52 @@ +package org.prabuckt.application.vegancakes.view.shopping; + +import javax.enterprise.context.SessionScoped; +import javax.inject.Named; +import java.io.Serializable; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Named +@SessionScoped +public class CredentialsBean implements Serializable { + + // ====================================== + // = Attributes = + // ====================================== + + private String login; + private String password; + private String password2; + + // ====================================== + // = Getters & setters = + // ====================================== + + public String getLogin() { + return login; + } + + public void setLogin(String login) { + this.login = login; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getPassword2() { + return password2; + } + + public void setPassword2(String password2) { + this.password2 = password2; + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/shopping/ShoppingCartBean.java b/src/main/java/org/prabuckt/application/vegancakes/view/shopping/ShoppingCartBean.java new file mode 100755 index 0000000..7b04e51 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/shopping/ShoppingCartBean.java @@ -0,0 +1,166 @@ +package org.prabuckt.application.vegancakes.view.shopping; + +import org.prabuckt.application.vegancakes.model.*; +import org.prabuckt.application.vegancakes.service.CatalogService; +import org.prabuckt.application.vegancakes.service.PurchaseOrderService; +import org.prabuckt.application.vegancakes.util.Loggable; +import org.prabuckt.application.vegancakes.view.AbstractBean; +import org.prabuckt.application.vegancakes.view.CatchException; +import org.prabuckt.application.vegancakes.view.LoggedIn; + +import javax.enterprise.context.Conversation; +import javax.enterprise.context.ConversationScoped; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; +import javax.inject.Named; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +@Named +@ConversationScoped +@Loggable +@CatchException +public class ShoppingCartBean extends AbstractBean implements Serializable { + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + @LoggedIn + private Instance loggedInCustomer; + @Inject + private CatalogService catalogBean; + @Inject + private PurchaseOrderService orderBean; + @Inject + private Conversation conversation; + + private List cartItems; + private CreditCard creditCard = new CreditCard(); + private PurchaseOrder order; + + // ====================================== + // = Public Methods = + // ====================================== + + public String addItemToCart() { + Item item = catalogBean.findItem(getParamId("itemId")); + + // Start conversation + if (conversation.isTransient()) { + cartItems = new ArrayList<>(); + conversation.begin(); + } + + boolean itemFound = false; + for (ShoppingCartItem cartItem : cartItems) { + // If item already exists in the shopping cart we just change the quantity + if (cartItem.getItem().equals(item)) { + cartItem.setQuantity(cartItem.getQuantity() + 1); + itemFound = true; + } + } + if (!itemFound) + // Otherwise it's added to the shopping cart + cartItems.add(new ShoppingCartItem(item, 1)); + + return "showcart.faces"; + } + + public String removeItemFromCart() { + Item item = catalogBean.findItem(getParamId("itemId")); + + for (ShoppingCartItem cartItem : cartItems) { + if (cartItem.getItem().equals(item)) { + cartItems.remove(cartItem); + return null; + } + } + + return null; + } + + public String updateQuantity() { + return null; + } + + public String checkout() { + return "confirmorder.faces"; + } + + public String confirmOrder() { + order = orderBean.createOrder(getCustomer(), creditCard, getCartItems()); + cartItems.clear(); + + // Stop conversation + if (!conversation.isTransient()) { + conversation.end(); + } + + return "orderconfirmed.faces"; + } + + public List getCartItems() { + return cartItems; + } + + public boolean shoppingCartIsEmpty() { + return getCartItems() == null || getCartItems().size() == 0; + } + + + public Float getTotal() { + + if (cartItems == null || cartItems.isEmpty()) + return 0f; + + Float total = 0f; + + // Sum up the quantities + for (ShoppingCartItem cartItem : cartItems) { + total += (cartItem.getSubTotal()); + } + return total; + } + + // ====================================== + // = Getters & setters = + // ====================================== + + public Customer getCustomer() { + return loggedInCustomer.get(); + } + + + public CreditCard getCreditCard() { + return creditCard; + } + + public void setCreditCard(CreditCard creditCard) { + this.creditCard = creditCard; + } + + public PurchaseOrder getOrder() { + return order; + } + + public void setOrder(PurchaseOrder order) { + this.order = order; + } + + public Conversation getConversation() { + return conversation; + } + + public CreditCardType[] getCreditCardTypes() { + return CreditCardType.values(); + } +} diff --git a/src/main/java/org/prabuckt/application/vegancakes/view/shopping/ShoppingCartItem.java b/src/main/java/org/prabuckt/application/vegancakes/view/shopping/ShoppingCartItem.java new file mode 100755 index 0000000..6081d71 --- /dev/null +++ b/src/main/java/org/prabuckt/application/vegancakes/view/shopping/ShoppingCartItem.java @@ -0,0 +1,106 @@ +package org.prabuckt.application.vegancakes.view.shopping; + +import org.prabuckt.application.vegancakes.model.Item; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +/** + * @author Tomasz Prabucki + * https://tprabucki.netlify.com + * -- + */ + +public class ShoppingCartItem +{ + + // ====================================== + // = Attributes = + // ====================================== + + @NotNull + private Item item; + @NotNull + @Min(1) + private Integer quantity; + + // ====================================== + // = Constructors = + // ====================================== + + public ShoppingCartItem(Item item, Integer quantity) + { + this.item = item; + this.quantity = quantity; + } + + // ====================================== + // = Public Methods = + // ====================================== + + public Float getSubTotal() + { + return item.getUnitCost() * quantity; + } + + // ====================================== + // = Getters & setters = + // ====================================== + + public Item getItem() + { + return item; + } + + public void setItem(Item item) + { + this.item = item; + } + + public Integer getQuantity() + { + return quantity; + } + + public void setQuantity(Integer quantity) + { + this.quantity = quantity; + } + + // ====================================== + // = Methods hash, equals, toString = + // ====================================== + + @Override + public boolean equals(Object o) + { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ShoppingCartItem cartItem = (ShoppingCartItem) o; + + if (!item.equals(cartItem.item)) return false; + if (!quantity.equals(cartItem.quantity)) return false; + + return true; + } + + @Override + public int hashCode() + { + int result = item.hashCode(); + result = 31 * result + quantity.hashCode(); + return result; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append("CartItem"); + sb.append("{item='").append(item).append('\''); + sb.append(", quantity='").append(quantity).append('\''); + sb.append('}'); + return sb.toString(); + } +} diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml new file mode 100755 index 0000000..0766dca --- /dev/null +++ b/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,13 @@ + + + + + java:jboss/datasources/ExampleDS + + + + + + + + diff --git a/src/main/resources/META-INF/validation.xml b/src/main/resources/META-INF/validation.xml new file mode 100644 index 0000000..df91a77 --- /dev/null +++ b/src/main/resources/META-INF/validation.xml @@ -0,0 +1,2 @@ + + diff --git a/src/main/resources/Messages.properties b/src/main/resources/Messages.properties new file mode 100755 index 0000000..e56dded --- /dev/null +++ b/src/main/resources/Messages.properties @@ -0,0 +1,118 @@ +#common +yes=Yes. +no=No. +logIn=Log in +logOut=Log out +again=again +creditCard=Credit Card +noItemsFound=No Items Found +update=Update +remove=Remove +search=Search +submit=Submit +checkout=Checkout + +#signon page +signon_signIn=Sign In +signon_returningCustomer=You are a returning customer +signon_signup=You would like to sign up for an account +signon_passwordRepeate=Password (Repeat): +signon_new=Create new account +login_exists=Login already exists +been_loggedout=You've been logged out +id_filled=User id has to be filled +pwd_filled=User password has to be filled +id_pwd_filled=Id and passwords have to be filled +both_pwd_same=Both entered passwords have to be the same +account_updated=Your account has been updated +authentication_failed=User or password incorrect +authentication_success=You have successfully logged in +account_creation_success=New account successfully created + +#Entities +accounts=Accounts +address=Address +items=Items +products=Products +address_street1=Street1 +address_street2=Street2 +address_city=City +address_state=State +address_postcode=Postcode +address_country=Country +category_id=Id +category_name=Name +category_description=Description +category_products=products +creditCard_creditCardNumber=Credit Card Number +creditCard_creditCardType=Type +creditCard_creditCardExpDate=Expiry date +customer_id=Id +customer_login=Login +customer_password=Password +customer_firstName=Firstname +customer_lastName=Lastname +customer_telephone=Telephone +customer_email=Email +customer_dateOfBirth=Date Of Birth +customer_age=Age +item_id=Id +item_name=Name +item_description=Description +item_unitCost=Unit cost +item_imagePath=Image path +item_product=Product +order_id=Id +order_orderDate=Order Date +order_customer=Customer +order_orderLines=Order lines +order_deliveryAddress=Delivery address +order_creditCard=Credit card +orderLine_id=Id; +orderLine_quantity=Quantity +orderLine_item=Item +product_id=Id +product_description=Description +product_category=Category +product_items=Items +product_noProductFound=No products found + +#Confirm order +confirmorder_confimOrder=Confirm Order +confirmorder_personalInformation=Personal information +confirmorder_firstName=*Firstname : +confirmorder_deliveryAddress=Delivery Address + + +#Create Account +createAccount_createYourAccount=Create Your Account +createAccount_personalInformation=Personal information + +#Order Confirmed +orderConfirmed_yourOrderIsComplete=Your Order is Complete +orderConfirmed_yourOrderIdIs=Your order id is +orderConfirmed_msg1=You will receive shortly an email confirming your order +orderConfirmed_msg2=Thank you for shopping with the Vegan Cakes + +#Search Result +searchResult_searchFor=Search for +searchResult_addToCart=Add to Cart +searchResult_pleaselogin=Please log in to buy + +#Show account +showAccount_edit=Edit Your Account Information + +#Shopping Cart +shoppingCart=Shopping Cart +shoppingCart_empty=The Shopping Cart is empty + +#Show Items +showItems_itemForProduct=Items for product + +#Update account +updateYourAccount=Update your account + + + + + diff --git a/src/main/resources/ValidationMessages.properties b/src/main/resources/ValidationMessages.properties new file mode 100755 index 0000000..5ffb56a --- /dev/null +++ b/src/main/resources/ValidationMessages.properties @@ -0,0 +1,4 @@ +Email.message=Invalid email format +Login.message=Invalid login +NotEmpty.message=Not be empty +Price.message=Invalid price diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties new file mode 100755 index 0000000..bf1a8b4 --- /dev/null +++ b/src/main/resources/config.properties @@ -0,0 +1,2 @@ +loginModuleName=SimpleLoginModule +loginConfigFile=/vegancakes-test.login diff --git a/src/main/resources/init_db.sql b/src/main/resources/init_db.sql new file mode 100644 index 0000000..98ae33d --- /dev/null +++ b/src/main/resources/init_db.sql @@ -0,0 +1,382 @@ +INSERT INTO category(id, name, description, version) VALUES (1000, 'Cakes', '', 1) +INSERT INTO category(id, name, description, version) VALUES (1001, 'Cookies', '', 1) +INSERT INTO category(id, name, description, version) VALUES (1002, 'Pudding', '', 1) +INSERT INTO category(id, name, description, version) VALUES (1003, 'Brownies', '', 1) +INSERT INTO category(id, name, description, version) VALUES (1004, 'Drinks', '', 1) +INSERT INTO category(id, name, description, version) VALUES (1005, 'Other', '', 1) + + +INSERT INTO product(id, name, description, category_fk, version) VALUES (1000, 'Double Chocolate Mug Cake', 'Chocolate cake is one of the most popular, if not the most popular cake flavours that we know of. With this recipe, you can quickly make a delicious single-serving chocolate cake (in a mug), with minimal effort.', 1000, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1001, 'Vegan Blueberry Mug Cake', 'Sometimes you just feel like having a cup of tea with a fluffy, warm, bakery-style blueberry muffin. With this recipe you can make a super quick version at home - it only needs 2 minutes in the microwave!', 1000, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1002, 'Peanut Butter & Jelly Mug Cake', 'The PB & J sandwich is possibly the most classic kids sandwich. So if you feel like re-living a part of your childhood in a mug, as dessert, then this is the place to be.', 1000, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1003, 'Vanilla Birthday Mug Cake', 'Nothing says birthday party quite like a classic funfetti cake. A birthday isnt required to enjoy this treat though - this size is perfect for anyone who just wants to celebrate any day of the week with a piece of cake.', 1000, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1004, 'Vanilla Caramel Cake', 'Hooray, its the 4th birthday of Pick Up Limes! To celebrate, weve made a new incredibly delicious cake recipe - this time a classic vanilla cake, with a caramel twist.', 1000, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1005, 'Raspberry Rose Chocolate Bark', 'This chocolate bark makes for a beautiful handmade gift. The confetti-like toppings on the chocolate make this a delicious and beautiful gift for Valentines Day, an anniversary, or any other special event!', 1000, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1006, 'Easy Vegan Chocolate Cake', 'A good chocolate cake can be enjoyed on just about any special occasion: birthdays, anniversaries, graduations, potluck parties. Its a classic! This chocolate cake is delicious, moist, and fluffy, and no one will even guess its completely plant-based!', 1000, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1007, 'Strawberry Cheesecake Overnight Oats', 'Cheesecake exists in different flavours, shapes, and sizes all over the world, and its definitely a dessert that many love. These overnight oats are inspired by the classic strawberry cheesecake, and it just might be your new breakfast favourite!', 1000, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1008, 'Almond Brownie Cookies', 'Brownies and cookies, two of the most beloved desserts we can think of. Now imagine both of them merged into one. Yupp, a little bit crunchy on the outside, while soft and fudgy on the inside - a real treat!', 1001, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1009, 'Vegan Cowboy Cookies', 'There are many stories on where the name "cowboy cookies" comes from. Some say they were enjoyed by cowboys back in the 1800s when they were working a long day out on the trail. Others claim the cookie recipe was developed in Texas, where a lot of cowboys lived. Both theories sound good, but the cookies taste even better. Filled with chocolate chips, pecans, shredded coconut, oats, and cinnamon, this cookie is sure to be a crowd-pleaser!', 1001, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1010, 'Soft Vegan Chocolate Chip Cookies', 'Sometimes, a good old classic will hit the spot. Nothing fancy, just a simple, wholesome and indulgent chocolate chip cookie.', 1001, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1011, 'Blueberry Almond Breakfast Cookies', 'These cookies make a great grab-and-go snack. Considering all the wholesome ingredients used to make them, several cookies can also be enjoyed as a grab-and-go breakfast option for those hectic mornings.', 1001, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1012, 'Double Chocolate Banana Muffins', 'This is a perfect chocolatey treat to take to potlucks, birthdays, house-warming events or to make in a batch and freeze for later.', 1001, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1013, 'Peanut Butter & Chocolate Oatmeal Cookies', 'These cookies are one of our favourites to make! It calls for only 7-ingredients, comes together in under 20 minutes, is made with whole food ingredients, and makes for an awesome on-the-go snack.', 1001, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1014, 'One-Bowl Chewy Double Chocolate Chip Cookies', 'These soft cookies are so delicious, and perfect for when youre in the mood for something sweet. Weve added espresso powder, which is optional but helps to amp up the rich, chocolatey flavour of the cookies.', 1001, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1015, 'Mousse Au Chocolat', 'This delectable dessert can be eaten on its own by the spoonful, but its even better with some fruit toppings, like apples, bananas and strawberries.', 1002, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1016, 'Tea-Infused Chocolate Mousse', 'Weve added a little twist to the classic chocolate mousse by infusing it with one of our favourite tea flavours. To make it even more unique, were whipping it up using aquafaba, which is the fancy name given to the liquid in a jar or can of chickpeas, or the liquid the chickpeas is cooked in. Topped with some fresh fruits, this chocolate mousse is an easy and tasty dessert that also looks the part!', 1002, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1017, 'Raspberry Chocolate Pudding', 'This rich and luscious chocolate pudding is one of our absolute favourites. The avocado makes the pudding naturally creamy, and the tartness of the frozen raspberries is highly recommended to offset the natural bitterness in the avocado and cocoa powder.', 1002, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1018, 'Chocolate Chia Breakfast Pudding', 'A simple and wholesome breakfast or snack. Sweet enough for a chocolate-lover, but not too heavy for the first meal of the day.', 1002, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1019, 'Vanilla Chia Pudding with Mixed Fruit', 'This is a great no-cook breakfast or snack recipe. Its cool, creamy, sweet and filling.', 1002, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1020, 'Chocolate Fudge Brownie Bites', 'The brownie bites are deliciously fudgy and so wholesome. They make for a lovely snack or dessert and are always a hit when taken to picnics or potlucks. We like to make a big batch to store in the freezer for on-demand snacks when our sweet tooth strikes.', 1003, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1021, 'Ultra Fudgy Sea Salt Caramel Brownies', 'These brownies are the BEST. Not only are they just 6 ingredients, but they are also super fast to make, and are the fudgiest, most delicious chocolate packed squares you might ever put into your mouth! Plus, theyre made with some pretty wholesome ingredients!', 1003, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1022, 'Double Chocolate Brownies', 'Brownies can sometimes be overly sweet or too rich, but this recipe is a perfect balance. It tastes indulgent, with a moist, slightly cake-like texture. Top with some coconut whip or ice cream, and enjoy!', 1003, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1023, 'Peanut Butter Caramel Latte', 'If you reduced a Snickers bar into a drink, this would be it. Its thick, creamy, nutty and sweet. With the peanut butter and cashews, its a decadent warm drink to cozy up to.', 1004, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1024, 'Golden Vegan Hot Chocolate', 'This hot chocolate has all the deliciousness of a regular hot chocolate and is also nutritionally power-packed. Naturally sweetened with dates, and featuring anti-inflammatory properties from turmeric. Its creamy and sweet, perfect for snuggling up and enjoying any time of the year.', 1004, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1025, 'Vegan Gingerbread Latte', 'Cold weather is tolerable because of all things that make it cozy: comfy sweaters, warm blankets, and warm drinks. Oh, the warm drinks! This gingerbread latte - while often enjoyed during the holiday season - can certainly be enjoyed year-round, and feels just like a hug in a mug.', 1004, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1026, 'Apple & Banana Peanut Butter Breakfast Cups', 'Oatmeal is generally a go-to for breakfast, but every once in a while, things need to be shaken up. These cups are fibre-packed and incredibly versatile, perfect for a busy morning, or simply enjoy as a snack.', 1005, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1027, 'Zesty Lemon Cream Cups', 'If you ever find yourself with a bunch of lemons, you could make lemonade, or better yet: these creamy and zesty lemon dessert cups! They make for a great snack or after-dinner treat, and they freeze super well, so batch make and enjoy when desired!', 1005, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1028, 'Vegan Caramel Sauce', 'This caramel sauce is sweet, but not overwhelmingly sweet like some traditional caramel sauces are, making it perfect to add to inherently sweet desserts. You can serve this delicious caramel sauce on coffee with whipped cream, ice cream, apples, popcorn, pancakes, waffles, cake, yogurt, brownies, or simply on a spoon.', 1005, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1029, 'Dark Chocolate Trail Mix Bars', 'Everything to love about a good trail mix is incorporated into these bars - chewy dried cranberries, crunchy almonds, sweet coconut, and filling pumpkin seeds.', 1005, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1030, 'One-Bowl Oatmeal Blueberry Muffins', 'These moist and delicious blueberry muffins are wholesome enough to be eaten for breakfast but are also sweet enough to be enjoyed as a snack.', 1005, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1031, 'Tropical Coconut Popsicles', 'These fruity and refreshing popsicles make for the perfect snack or dessert in the warm spring and summer months. Only 4-ingredients required, and 100% kid approved!', 1005, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1032, 'Coconut Lemon Custard Tart', 'Tofu is the surprise star ingredient in this light and fresh dessert. The lemon adds a nice, refreshing flavour, which is a welcomed change to all the chocolate desserts we keep sharing on the blog!', 1005, 1) +INSERT INTO product(id, name, description, category_fk, version) VALUES (1033, 'Chocolate Coconut Peanut Butter Balls', 'If you love peanut butter and chocolate, then youll love these delicious balls. They dont need any baking, call for only 6 ingredients, and are a real treat!', 1005, 1) + + +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1000 ,'Small', 10.99, '1000.jpg', 1000, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1001 ,'Medium', 15.99, '1000.jpg', 1000, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1002 ,'Large', 20.99, '1000.jpg', 1000, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1003 ,'Small', 8.99, '1001.jpg', 1001, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1004 ,'Medium', 14.99, '1001.jpg', 1001, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1005 ,'Large', 17.99, '1001.jpg', 1001, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1006 ,'Small', 20.99, '1002.jpg', 1002, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1007 ,'Medium', 27.99, '1002.jpg', 1002, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1008 ,'Large', 32.99, '1002.jpg', 1002, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1009 ,'Small', 14.99, '1003.jpg', 1003, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1010 ,'Medium', 18.99, '1003.jpg', 1003, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1011 ,'Large', 23.99, '1003.jpg', 1003, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1012 ,'Small', 13.99, '1004.jpg', 1004, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1013 ,'Medium', 16.99, '1004.jpg', 1004, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1014 ,'Large', 20.99, '1004.jpg', 1004, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1015 ,'Small', 19.99, '1005.jpg', 1005, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1016 ,'Medium', 24.99, '1005.jpg', 1005, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1017 ,'Large', 29.99, '1005.jpg', 1005, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1018 ,'Small', 10.99, '1006.jpg', 1006, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1019 ,'Medium', 15.99, '1006.jpg', 1006, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1020 ,'Large', 20.99, '1006.jpg', 1006, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1021 ,'Small', 8.99, '1007.jpg', 1007, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1022 ,'Medium', 14.99, '1007.jpg', 1007, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1023 ,'Large', 17.99, '1007.jpg', 1007, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1024 ,'Small', 20.99, '1008.jpg', 1008, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1025 ,'Medium', 27.99, '1008.jpg', 1008, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1026 ,'Large', 32.99, '1008.jpg', 1008, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1027 ,'Small', 14.99, '1009.jpg', 1009, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1028 ,'Medium', 18.99, '1009.jpg', 1009, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1029 ,'Large', 23.99, '1009.jpg', 1009, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1030 ,'Small', 13.99, '1010.jpg', 1010, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1031 ,'Medium', 16.99, '1010.jpg', 1010, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1032 ,'Large', 20.99, '1010.jpg', 1010, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1033 ,'Small', 19.99, '1011.jpg', 1011, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1034 ,'Medium', 24.99, '1011.jpg', 1011, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1035 ,'Large', 29.99, '1011.jpg', 1011, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1036 ,'Small', 10.99, '1012.jpg', 1012, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1037 ,'Medium', 15.99, '1012.jpg', 1012, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1038 ,'Large', 20.99, '1012.jpg', 1012, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1039 ,'Small', 8.99, '1013.jpg', 1013, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1040 ,'Medium', 14.99, '1013.jpg', 1013, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1041 ,'Large', 17.99, '1013.jpg', 1013, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1042 ,'Small', 20.99, '1014.jpg', 1014, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1043 ,'Medium', 27.99, '1014.jpg', 1014, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1044 ,'Large', 32.99, '1014.jpg', 1014, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1045 ,'Small', 14.99, '1015.jpg', 1015, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1046 ,'Medium', 18.99, '1015.jpg', 1015, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1047 ,'Large', 23.99, '1015.jpg', 1015, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1048 ,'Small', 13.99, '1016.jpg', 1016, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1049 ,'Medium', 16.99, '1016.jpg', 1016, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1050 ,'Large', 20.99, '1016.jpg', 1016, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1051 ,'Small', 19.99, '1017.jpg', 1017, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1052 ,'Medium', 24.99, '1017.jpg', 1017, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1053 ,'Large', 29.99, '1017.jpg', 1017, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1054 ,'Small', 10.99, '1018.jpg', 1018, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1055 ,'Medium', 15.99, '1018.jpg', 1018, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1056 ,'Large', 20.99, '1018.jpg', 1018, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1057 ,'Small', 8.99, '1019.jpg', 1019, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1058 ,'Medium', 14.99, '1019.jpg', 1019, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1059 ,'Large', 17.99, '1019.jpg', 1019, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1060 ,'Small', 20.99, '1020.jpg', 1020, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1061 ,'Medium', 27.99, '1020.jpg', 1020, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1062 ,'Large', 32.99, '1020.jpg', 1020, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1063 ,'Small', 14.99, '1021.jpg', 1021, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1064 ,'Medium', 18.99, '1021.jpg', 1021, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1065 ,'Large', 23.99, '1021.jpg', 1021, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1066 ,'Small', 13.99, '1022.jpg', 1022, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1067 ,'Medium', 16.99, '1022.jpg', 1022, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1068 ,'Large', 20.99, '1022.jpg', 1022, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1069 ,'Small', 19.99, '1023.jpg', 1023, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1070 ,'Medium', 24.99, '1023.jpg', 1023, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1071 ,'Large', 29.99, '1023.jpg', 1023, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1072 ,'Small', 10.99, '1024.jpg', 1024, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1073 ,'Medium', 15.99, '1024.jpg', 1024, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1074 ,'Large', 20.99, '1024.jpg', 1024, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1075 ,'Small', 8.99, '1025.jpg', 1025, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1076 ,'Medium', 14.99, '1025.jpg', 1025, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1077 ,'Large', 17.99, '1025.jpg', 1025, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1078 ,'Small', 20.99, '1026.jpg', 1026, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1079 ,'Medium', 27.99, '1026.jpg', 1026, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1080 ,'Large', 32.99, '1026.jpg', 1026, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1081 ,'Small', 14.99, '1027.jpg', 1027, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1082 ,'Medium', 18.99, '1027.jpg', 1027, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1083 ,'Large', 23.99, '1027.jpg', 1027, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1084 ,'Small', 13.99, '1028.jpg', 1028, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1085 ,'Medium', 16.99, '1028.jpg', 1028, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1086 ,'Large', 20.99, '1028.jpg', 1028, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1087 ,'Small', 19.99, '1029.jpg', 1029, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1088 ,'Medium', 24.99, '1029.jpg', 1029, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1089 ,'Large', 29.99, '1029.jpg', 1029, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1090 ,'Small', 10.99, '1030.jpg', 1030, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1091 ,'Medium', 15.99, '1030.jpg', 1030, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1092 ,'Large', 20.99, '1030.jpg', 1030, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1093 ,'Small', 8.99, '1031.jpg', 1031, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1094 ,'Medium', 14.99, '1031.jpg', 1031, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1095 ,'Large', 17.99, '1031.jpg', 1031, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1096 ,'Small', 20.99, '1032.jpg', 1032, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1097 ,'Medium', 27.99, '1032.jpg', 1032, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1098 ,'Large', 32.99, '1032.jpg', 1032, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1099 ,'Small', 14.99, '1033.jpg', 1033, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1100 ,'Medium', 18.99, '1033.jpg', 1033, '', 1) +INSERT INTO item(id, name, unit_cost, image_path, product_fk, description, version) VALUES (1101 ,'Large', 23.99, '1033.jpg', 1033, '', 1) + + +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1000, 'AF','AFGHANISTAN','Afghanistan','AFG','004', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1001, 'AL','ALBANIA','Albania','ALB','008', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1002, 'DZ','ALGERIA','Algeria','DZA','012', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1003, 'AS','AMERICAN SAMOA','American Samoa','ASM','016', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1004, 'AD','ANDORRA','Andorra','AND','020', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1005, 'AO','ANGOLA','Angola','AGO','024', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1006, 'AI','ANGUILLA','Anguilla','AIA','660', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1008, 'AG','ANTIGUA AND BARBUDA','Antigua and Barbuda','ATG','028', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1009, 'AR','ARGENTINA','Argentina','ARG','032', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1010, 'AM','ARMENIA','Armenia','ARM','051', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1011, 'AW','ARUBA','Aruba','ABW','533', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1012, 'AU','AUSTRALIA','Australia','AUS','036', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1013, 'AT','AUSTRIA','Austria','AUT','040', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1014, 'AZ','AZERBAIJAN','Azerbaijan','AZE','031', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1015, 'BS','BAHAMAS','Bahamas','BHS','044', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1016, 'BH','BAHRAIN','Bahrain','BHR','048', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1017, 'BD','BANGLADESH','Bangladesh','BGD','050', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1018, 'BB','BARBADOS','Barbados','BRB','052', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1019, 'BY','BELARUS','Belarus','BLR','112', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1020, 'BE','BELGIUM','Belgium','BEL','056', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1021, 'BZ','BELIZE','Belize','BLZ','084', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1022, 'BJ','BENIN','Benin','BEN','204', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1023, 'BM','BERMUDA','Bermuda','BMU','060', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1024, 'BT','BHUTAN','Bhutan','BTN','064', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1025, 'BO','BOLIVIA','Bolivia','BOL','068', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1026, 'BA','BOSNIA AND HERZEGOVINA','Bosnia and Herzegovina','BIH','070', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1027, 'BW','BOTSWANA','Botswana','BWA','072', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1029, 'BR','BRAZIL','Brazil','BRA','076', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1031, 'BN','BRUNEI DARUSSALAM','Brunei Darussalam','BRN','096', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1032, 'BG','BULGARIA','Bulgaria','BGR','100', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1033, 'BF','BURKINA FASO','Burkina Faso','BFA','854', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1034, 'BI','BURUNDI','Burundi','BDI','108', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1035, 'KH','CAMBODIA','Cambodia','KHM','116', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1036, 'CM','CAMEROON','Cameroon','CMR','120', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1037, 'CA','CANADA','Canada','CAN','124', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1038, 'CV','CAPE VERDE','Cape Verde','CPV','132', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1039, 'KY','CAYMAN ISLANDS','Cayman Islands','CYM','136', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1040, 'CF','CENTRAL AFRICAN REPUBLIC','Central African Republic','CAF','140', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1041, 'TD','CHAD','Chad','TCD','148', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1042, 'CL','CHILE','Chile','CHL','152', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1043, 'CN','CHINA','China','CHN','156', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1046, 'CO','COLOMBIA','Colombia','COL','170', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1047, 'KM','COMOROS','Comoros','COM','174', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1048, 'CG','CONGO','Congo','COG','178', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1049, 'CD','CONGO, THE DEMOCRATIC REPUBLIC OF THE','Congo, the Democratic Republic of the','COD','180', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1050, 'CK','COOK ISLANDS','Cook Islands','COK','184', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1051, 'CR','COSTA RICA','Costa Rica','CRI','188', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1052, 'CI','COTE D IVOIRE','Cote d Ivoire','CIV','384', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1053, 'HR','CROATIA','Croatia','HRV','191', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1054, 'CU','CUBA','Cuba','CUB','192', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1055, 'CY','CYPRUS','Cyprus','CYP','196', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1056, 'CZ','CZECH REPUBLIC','Czech Republic','CZE','203', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1057, 'DK','DENMARK','Denmark','DNK','208', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1058, 'DJ','DJIBOUTI','Djibouti','DJI','262', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1059, 'DM','DOMINICA','Dominica','DMA','212', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1060, 'DO','DOMINICAN REPUBLIC','Dominican Republic','DOM','214', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1061, 'EC','ECUADOR','Ecuador','ECU','218', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1062, 'EG','EGYPT','Egypt','EGY','818', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1063, 'SV','EL SALVADOR','El Salvador','SLV','222', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1064, 'GQ','EQUATORIAL GUINEA','Equatorial Guinea','GNQ','226', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1065, 'ER','ERITREA','Eritrea','ERI','232', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1066, 'EE','ESTONIA','Estonia','EST','233', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1067, 'ET','ETHIOPIA','Ethiopia','ETH','231', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1068, 'FK','FALKLAND ISLANDS (MALVINAS)','Falkland Islands (Malvinas)','FLK','238', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1069, 'FO','FAROE ISLANDS','Faroe Islands','FRO','234', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1070, 'FJ','FIJI','Fiji','FJI','242', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1071, 'FI','FINLAND','Finland','FIN','246', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1072, 'FR','FRANCE','France','FRA','250', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1073, 'GF','FRENCH GUIANA','French Guiana','GUF','254', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1074, 'PF','FRENCH POLYNESIA','French Polynesia','PYF','258', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1076, 'GA','GABON','Gabon','GAB','266', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1077, 'GM','GAMBIA','Gambia','GMB','270', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1078, 'GE','GEORGIA','Georgia','GEO','268', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1079, 'DE','GERMANY','Germany','DEU','276', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1080, 'GH','GHANA','Ghana','GHA','288', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1081, 'GI','GIBRALTAR','Gibraltar','GIB','292', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1082, 'GR','GREECE','Greece','GRC','300', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1083, 'GL','GREENLAND','Greenland','GRL','304', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1084, 'GD','GRENADA','Grenada','GRD','308', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1085, 'GP','GUADELOUPE','Guadeloupe','GLP','312', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1086, 'GU','GUAM','Guam','GUM','316', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1087, 'GT','GUATEMALA','Guatemala','GTM','320', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1088, 'GN','GUINEA','Guinea','GIN','324', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1089, 'GW','GUINEA-BISSAU','Guinea-Bissau','GNB','624', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1090, 'GY','GUYANA','Guyana','GUY','328', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1091, 'HT','HAITI','Haiti','HTI','332', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1093, 'VA','HOLY SEE (VATICAN CITY STATE)','Holy See (Vatican City State)','VAT','336', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1094, 'HN','HONDURAS','Honduras','HND','340', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1095, 'HK','HONG KONG','Hong Kong','HKG','344', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1096, 'HU','HUNGARY','Hungary','HUN','348', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1097, 'IS','ICELAND','Iceland','ISL','352', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1098, 'IN','INDIA','India','IND','356', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1099, 'ID','INDONESIA','Indonesia','IDN','360', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1100, 'IR','IRAN, ISLAMIC REPUBLIC OF','Iran, Islamic Republic of','IRN','364', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1101, 'IQ','IRAQ','Iraq','IRQ','368', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1102, 'IE','IRELAND','Ireland','IRL','372', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1103, 'IL','ISRAEL','Israel','ISR','376', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1104, 'IT','ITALY','Italy','ITA','380', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1105, 'JM','JAMAICA','Jamaica','JAM','388', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1106, 'JP','JAPAN','Japan','JPN','392', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1107, 'JO','JORDAN','Jordan','JOR','400', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1108, 'KZ','KAZAKHSTAN','Kazakhstan','KAZ','398', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1109, 'KE','KENYA','Kenya','KEN','404', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1110, 'KI','KIRIBATI','Kiribati','KIR','296', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1111, 'KP','KOREA, DEMOCRATIC PEOPLE S REPUBLIC OF','Korea, Democratic People s Republic of','PRK','408', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1112, 'KR','KOREA, REPUBLIC OF','Korea, Republic of','KOR','410', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1113, 'KW','KUWAIT','Kuwait','KWT','414', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1114, 'KG','KYRGYZSTAN','Kyrgyzstan','KGZ','417', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1115, 'LA','LAO PEOPLE S DEMOCRATIC REPUBLIC','Lao People s Democratic Republic','LAO','418', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1116, 'LV','LATVIA','Latvia','LVA','428', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1117, 'LB','LEBANON','Lebanon','LBN','422', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1118, 'LS','LESOTHO','Lesotho','LSO','426', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1119, 'LR','LIBERIA','Liberia','LBR','430', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1120, 'LY','LIBYAN ARAB JAMAHIRIYA','Libyan Arab Jamahiriya','LBY','434', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1121, 'LI','LIECHTENSTEIN','Liechtenstein','LIE','438', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1122, 'LT','LITHUANIA','Lithuania','LTU','440', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1123, 'LU','LUXEMBOURG','Luxembourg','LUX','442', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1124, 'MO','MACAO','Macao','MAC','446', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1125, 'MK','MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF','Macedonia, the Former Yugoslav Republic of','MKD','807', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1126, 'MG','MADAGASCAR','Madagascar','MDG','450', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1127, 'MW','MALAWI','Malawi','MWI','454', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1128, 'MY','MALAYSIA','Malaysia','MYS','458', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1129, 'MV','MALDIVES','Maldives','MDV','462', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1130, 'ML','MALI','Mali','MLI','466', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1131, 'MT','MALTA','Malta','MLT','470', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1132, 'MH','MARSHALL ISLANDS','Marshall Islands','MHL','584', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1133, 'MQ','MARTINIQUE','Martinique','MTQ','474', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1134, 'MR','MAURITANIA','Mauritania','MRT','478', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1135, 'MU','MAURITIUS','Mauritius','MUS','480', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1137, 'MX','MEXICO','Mexico','MEX','484', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1138, 'FM','MICRONESIA, FEDERATED STATES OF','Micronesia, Federated States of','FSM','583', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1139, 'MD','MOLDOVA, REPUBLIC OF','Moldova, Republic of','MDA','498', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1140, 'MC','MONACO','Monaco','MCO','492', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1141, 'MN','MONGOLIA','Mongolia','MNG','496', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1142, 'MS','MONTSERRAT','Montserrat','MSR','500', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1143, 'MA','MOROCCO','Morocco','MAR','504', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1144, 'MZ','MOZAMBIQUE','Mozambique','MOZ','508', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1145, 'MM','MYANMAR','Myanmar','MMR','104', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1146, 'NA','NAMIBIA','Namibia','NAM','516', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1147, 'NR','NAURU','Nauru','NRU','520', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1148, 'NP','NEPAL','Nepal','NPL','524', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1149, 'NL','NETHERLANDS','Netherlands','NLD','528', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1150, 'AN','NETHERLANDS ANTILLES','Netherlands Antilles','ANT','530', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1151, 'NC','NEW CALEDONIA','New Caledonia','NCL','540', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1152, 'NZ','NEW ZEALAND','New Zealand','NZL','554', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1153, 'NI','NICARAGUA','Nicaragua','NIC','558', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1154, 'NE','NIGER','Niger','NER','562', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1155, 'NG','NIGERIA','Nigeria','NGA','566', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1156, 'NU','NIUE','Niue','NIU','570', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1157, 'NF','NORFOLK ISLAND','Norfolk Island','NFK','574', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1158, 'MP','NORTHERN MARIANA ISLANDS','Northern Mariana Islands','MNP','580', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1159, 'NO','NORWAY','Norway','NOR','578', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1160, 'OM','OMAN','Oman','OMN','512', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1161, 'PK','PAKISTAN','Pakistan','PAK','586', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1162, 'PW','PALAU','Palau','PLW','585', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1164, 'PA','PANAMA','Panama','PAN','591', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1165, 'PG','PAPUA NEW GUINEA','Papua New Guinea','PNG','598', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1166, 'PY','PARAGUAY','Paraguay','PRY','600', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1167, 'PE','PERU','Peru','PER','604', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1168, 'PH','PHILIPPINES','Philippines','PHL','608', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1169, 'PN','PITCAIRN','Pitcairn','PCN','612', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1170, 'PL','POLAND','Poland','POL','616', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1171, 'PT','PORTUGAL','Portugal','PRT','620', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1172, 'PR','PUERTO RICO','Puerto Rico','PRI','630', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1173, 'QA','QATAR','Qatar','QAT','634', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1174, 'RE','REUNION','Reunion','REU','638', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1175, 'RO','ROMANIA','Romania','ROM','642', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1176, 'RU','RUSSIAN FEDERATION','Russian Federation','RUS','643', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1177, 'RW','RWANDA','Rwanda','RWA','646', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1178, 'SH','SAINT HELENA','Saint Helena','SHN','654', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1179, 'KN','SAINT KITTS AND NEVIS','Saint Kitts and Nevis','KNA','659', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1180, 'LC','SAINT LUCIA','Saint Lucia','LCA','662', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1181, 'PM','SAINT PIERRE AND MIQUELON','Saint Pierre and Miquelon','SPM','666', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1182, 'VC','SAINT VINCENT AND THE GRENADINES','Saint Vincent and the Grenadines','VCT','670', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1183, 'WS','SAMOA','Samoa','WSM','882', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1184, 'SM','SAN MARINO','San Marino','SMR','674', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1185, 'ST','SAO TOME AND PRINCIPE','Sao Tome and Principe','STP','678', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1186, 'SA','SAUDI ARABIA','Saudi Arabia','SAU','682', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1187, 'SN','SENEGAL','Senegal','SEN','686', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1189, 'SC','SEYCHELLES','Seychelles','SYC','690', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1190, 'SL','SIERRA LEONE','Sierra Leone','SLE','694', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1191, 'SG','SINGAPORE','Singapore','SGP','702', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1192, 'SK','SLOVAKIA','Slovakia','SVK','703', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1193, 'SI','SLOVENIA','Slovenia','SVN','705', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1194, 'SB','SOLOMON ISLANDS','Solomon Islands','SLB','090', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1195, 'SO','SOMALIA','Somalia','SOM','706', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1196, 'ZA','SOUTH AFRICA','South Africa','ZAF','710', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1198, 'ES','SPAIN','Spain','ESP','724', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1199, 'LK','SRI LANKA','Sri Lanka','LKA','144', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1200, 'SD','SUDAN','Sudan','SDN','736', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1201, 'SR','SURINAME','Suriname','SUR','740', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1202, 'SJ','SVALBARD AND JAN MAYEN','Svalbard and Jan Mayen','SJM','744', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1203, 'SZ','SWAZILAND','Swaziland','SWZ','748', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1204, 'SE','SWEDEN','Sweden','SWE','752', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1205, 'CH','SWITZERLAND','Switzerland','CHE','756', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1206, 'SY','SYRIAN ARAB REPUBLIC','Syrian Arab Republic','SYR','760', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1207, 'TW','TAIWAN, PROVINCE OF CHINA','Taiwan, Province of China','TWN','158', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1208, 'TJ','TAJIKISTAN','Tajikistan','TJK','762', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1209, 'TZ','TANZANIA, UNITED REPUBLIC OF','Tanzania, United Republic of','TZA','834', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1210, 'TH','THAILAND','Thailand','THA','764', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1212, 'TG','TOGO','Togo','TGO','768', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1213, 'TK','TOKELAU','Tokelau','TKL','772', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1214, 'TO','TONGA','Tonga','TON','776', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1215, 'TT','TRINIDAD AND TOBAGO','Trinidad and Tobago','TTO','780', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1216, 'TN','TUNISIA','Tunisia','TUN','788', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1217, 'TR','TURKEY','Turkey','TUR','792', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1218, 'TM','TURKMENISTAN','Turkmenistan','TKM','795', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1219, 'TC','TURKS AND CAICOS ISLANDS','Turks and Caicos Islands','TCA','796', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1220, 'TV','TUVALU','Tuvalu','TUV','798', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1221, 'UG','UGANDA','Uganda','UGA','800', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1222, 'UA','UKRAINE','Ukraine','UKR','804', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1223, 'AE','UNITED ARAB EMIRATES','United Arab Emirates','ARE','784', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1224, 'GB','UNITED KINGDOM','United Kingdom','GBR','826', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1225, 'US','UNITED STATES','United States','USA','840', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1227, 'UY','URUGUAY','Uruguay','URY','858', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1228, 'UZ','UZBEKISTAN','Uzbekistan','UZB','860', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1229, 'VU','VANUATU','Vanuatu','VUT','548', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1230, 'VE','VENEZUELA','Venezuela','VEN','862', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1231, 'VN','VIET NAM','Viet Nam','VNM','704', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1232, 'VG','VIRGIN ISLANDS, BRITISH','Virgin Islands, British','VGB','092', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1233, 'VI','VIRGIN ISLANDS, U.S.','Virgin Islands, U.s.','VIR','850', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1234, 'WF','WALLIS AND FUTUNA','Wallis and Futuna','WLF','876', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1235, 'EH','WESTERN SAHARA','Western Sahara','ESH','732', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1236, 'YE','YEMEN','Yemen','YEM','887', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1237, 'ZM','ZAMBIA','Zambia','ZMB','894', 1) +INSERT INTO country(id, iso_code, name, printable_name, iso3, numcode, version) VALUES (1238, 'ZW','ZIMBABWE','Zimbabwe','ZWE','716', 1) + + +INSERT INTO customer (id, version, login, password, first_name, last_name, telephone, email, date_of_birth, street1, city, zip_code, country_id) VALUES (1000, 1, 'admin', 'jGl25bVBBBW96Qi9Te4V37Fnqchz/Eu4qB9vKrRIqRg=', 'Admin', 'Admin', '+1 123 3564 4567', 'admin@vegancakes.com', '1935-07-01', 'The Admin Alley', 'CA', '87653', 1230) +INSERT INTO customer (id, version, login, password, first_name, last_name, telephone, email, date_of_birth, street1, city, zip_code, country_id) VALUES (1001, 1, 'user', 'BPiZbadjt6lpsQKO4wB1aerzpjVIbdqyEdUSyFud+Ps=', 'User', 'User', '+1 123 3564 4567', 'user@vegancakes.com', '1934-09-02', 'The User Boulevard', 'CA', '87653', 1230) +INSERT INTO customer (id, version, login, password, first_name, last_name, telephone, email, date_of_birth, street1, city, zip_code, country_id) VALUES (1002, 1, 'anakin', 'NwsSbfB4Wa+lac2CWCvEPfss47qAadu8vva3IVt6dsY=', 'Anakin', 'Skywalker', '+1 123 3564 4567', 'anakin@skywalker.com', '1935-07-01', '3 Wars Street', 'Black Star', '9999', 1230) +INSERT INTO customer (id, version, login, password, first_name, last_name, telephone, email, date_of_birth, street1, city, zip_code, country_id) VALUES (1003, 1, 'obiwan', 'tNUFJEkJ96Dgu4quiEbgNxyEKJIaKUA4I7UziEIa6Kc=', 'Obi-Wan', 'Kenobi', '+1 765 897 321', 'obiwan@kenobi.com', '1914-04-02', '14 Star Boulevard', 'Black Star', '9999', 1115) +INSERT INTO customer (id, version, login, password, first_name, last_name, telephone, email, date_of_birth, street1, city, zip_code, country_id) VALUES (1004, 1, 'luke', 'zM9S89A8UHLuZKE290/FayfgTxX/5dHSd9WKsY2Usyc=', 'Luke', 'Skywalker', '+1 786 1212 987', 'luke@skywalker.com', '1951-09-07', '543 Sun Set Boulevard', 'Black Star', '9999', 1200) +INSERT INTO customer (id, version, login, password, first_name, last_name, telephone, email, date_of_birth, street1, city, zip_code, country_id) VALUES (1005, 1, 'han', 'wQaIooUS4VUGRcaf3xPnq2t07YcJS74B8o6IZJC3Ajk=', 'Han', 'Solo', '+1 786 1212 987', 'han@solo.com', '1923-04-12', '543 Sun Set Boulevard', 'Black Star', '9999', 1238) diff --git a/src/main/resources/logging.properties b/src/main/resources/logging.properties new file mode 100755 index 0000000..ba6a871 --- /dev/null +++ b/src/main/resources/logging.properties @@ -0,0 +1,55 @@ +############################################################ +# Default Logging Configuration File +# +# You can use a different file by specifying a filename +# with the java.util.logging.config.file system property. +# For example java -Djava.util.logging.config.file=myfile +############################################################ + +############################################################ +# Global properties +############################################################ + +# "handlers" specifies a comma separated list of log Handler +# classes. These handlers will be installed during VM startup. +# Note that these classes must be on the system classpath. +# By default we only configure a ConsoleHandler, which will only +# show messages at the INFO and above levels. +handlers= java.util.logging.ConsoleHandler, java.util.logging.FileHandler + +# To also add the FileHandler, use the following line instead. +#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler + +# Default global logging level. +# This specifies which kinds of events are logged across +# all loggers. For any given facility this global level +# can be overriden by a facility specific level +# Note that the ConsoleHandler also has a separate level +# setting to limit messages printed to the console. +.level= FINEST + +############################################################ +# Handler specific properties. +# Describes specific configuration info for Handlers. +############################################################ + +# default file output is in customer's home directory. +java.util.logging.FileHandler.pattern = %h/java%u.log +java.util.logging.FileHandler.level = FINEST +java.util.logging.FileHandler.limit = 50000 +java.util.logging.FileHandler.count = 1 +java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter + +# Limit the message that are printed on the console to INFO and above. +java.util.logging.ConsoleHandler.level = FINEST +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + + +############################################################ +# Facility specific properties. +# Provides extra control for each logger. +############################################################ + +# For example, set the com.xyz.foo logger to only log SEVERE +# messages: +org.prabuckt.vegancakes.level = FINEST diff --git a/src/main/resources/vegancakes-test.login b/src/main/resources/vegancakes-test.login new file mode 100755 index 0000000..8884b64 --- /dev/null +++ b/src/main/resources/vegancakes-test.login @@ -0,0 +1,3 @@ +SimpleLoginModule{ + SimpleLoginModule required; +} ; diff --git a/src/main/webapp/WEB-INF/beans.xml b/src/main/webapp/WEB-INF/beans.xml new file mode 100755 index 0000000..a10bc1b --- /dev/null +++ b/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,9 @@ + + + + + org.prabuckt.application.vegancakes.util.LoggingInterceptor + org.prabuckt.application.vegancakes.view.ExceptionInterceptor + + + diff --git a/src/main/webapp/WEB-INF/classes/META-INF/forge.taglib.xml b/src/main/webapp/WEB-INF/classes/META-INF/forge.taglib.xml new file mode 100644 index 0000000..847ca9b --- /dev/null +++ b/src/main/webapp/WEB-INF/classes/META-INF/forge.taglib.xml @@ -0,0 +1,22 @@ + + + + http://jboss.org/forge/view + + + asList + org.prabuckt.application.vegancakes.view.ViewUtils + + java.util.List asList(java.util.Collection) + + + + + display + org.prabuckt.application.vegancakes.view.ViewUtils + + java.lang.String display(java.lang.Object) + + + + diff --git a/src/main/webapp/WEB-INF/faces-config.xml b/src/main/webapp/WEB-INF/faces-config.xml new file mode 100755 index 0000000..fce49d5 --- /dev/null +++ b/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,13 @@ + + + + + + en + + + Messages + i18n + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100755 index 0000000..b77c71e --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,53 @@ + + + + prabuckt-application-vegancakes-ee7 + + 30 + + + ico + image/x-icon + + + javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE + true + + + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + *.xhtml + + + + + primefaces.THEME + bootstrap + + + primefaces.FONT_AWESOME + true + + + + index.html + + + + + + + + + + + diff --git a/src/main/webapp/admin/category/create.xhtml b/src/main/webapp/admin/category/create.xhtml new file mode 100644 index 0000000..0ec8884 --- /dev/null +++ b/src/main/webapp/admin/category/create.xhtml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + Category + + + + + + Edit existing Category + + + Create a new Category + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/admin/category/search.xhtml b/src/main/webapp/admin/category/search.xhtml new file mode 100644 index 0000000..808deb5 --- /dev/null +++ b/src/main/webapp/admin/category/search.xhtml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + Category + + + + Search Category entities + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/admin/category/view.xhtml b/src/main/webapp/admin/category/view.xhtml new file mode 100644 index 0000000..4494ebf --- /dev/null +++ b/src/main/webapp/admin/category/view.xhtml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + Category + + + + View existing Category + + + + + + + + + + + + +

+ + + +
+ + + \ No newline at end of file diff --git a/src/main/webapp/admin/country/create.xhtml b/src/main/webapp/admin/country/create.xhtml new file mode 100644 index 0000000..78117e3 --- /dev/null +++ b/src/main/webapp/admin/country/create.xhtml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + Country + + + + + + Edit existing Country + + + Create a new Country + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/admin/country/search.xhtml b/src/main/webapp/admin/country/search.xhtml new file mode 100644 index 0000000..1069234 --- /dev/null +++ b/src/main/webapp/admin/country/search.xhtml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + Country + + + + Search Country entities + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/admin/country/view.xhtml b/src/main/webapp/admin/country/view.xhtml new file mode 100644 index 0000000..334958b --- /dev/null +++ b/src/main/webapp/admin/country/view.xhtml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + Country + + + + View existing Country + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+ +
\ No newline at end of file diff --git a/src/main/webapp/admin/customer/create.xhtml b/src/main/webapp/admin/customer/create.xhtml new file mode 100644 index 0000000..3bd1c2e --- /dev/null +++ b/src/main/webapp/admin/customer/create.xhtml @@ -0,0 +1,138 @@ + + + + + + + + + + + + + Customer + + + + + + Edit existing Customer + + + Create a new Customer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/admin/customer/search.xhtml b/src/main/webapp/admin/customer/search.xhtml new file mode 100644 index 0000000..7fbc5f4 --- /dev/null +++ b/src/main/webapp/admin/customer/search.xhtml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + Customer + + + + Search Customer entities + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/admin/customer/view.xhtml b/src/main/webapp/admin/customer/view.xhtml new file mode 100644 index 0000000..c072d3e --- /dev/null +++ b/src/main/webapp/admin/customer/view.xhtml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + Customer + + + + View existing Customer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+ +
\ No newline at end of file diff --git a/src/main/webapp/admin/item/create.xhtml b/src/main/webapp/admin/item/create.xhtml new file mode 100644 index 0000000..2873f01 --- /dev/null +++ b/src/main/webapp/admin/item/create.xhtml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + Item + + + + + + Edit existing Item + + + Create a new Item + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/admin/item/search.xhtml b/src/main/webapp/admin/item/search.xhtml new file mode 100644 index 0000000..b48a541 --- /dev/null +++ b/src/main/webapp/admin/item/search.xhtml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + Item + + + + Search Item entities + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/admin/item/view.xhtml b/src/main/webapp/admin/item/view.xhtml new file mode 100644 index 0000000..3b82eff --- /dev/null +++ b/src/main/webapp/admin/item/view.xhtml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + Item + + + + View existing Item + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+ +
\ No newline at end of file diff --git a/src/main/webapp/admin/product/create.xhtml b/src/main/webapp/admin/product/create.xhtml new file mode 100644 index 0000000..64656ff --- /dev/null +++ b/src/main/webapp/admin/product/create.xhtml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + Product + + + + + + Edit existing Product + + + Create a new Product + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/admin/product/search.xhtml b/src/main/webapp/admin/product/search.xhtml new file mode 100644 index 0000000..bbfcdb9 --- /dev/null +++ b/src/main/webapp/admin/product/search.xhtml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + Product + + + + Search Product entities + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/admin/product/view.xhtml b/src/main/webapp/admin/product/view.xhtml new file mode 100644 index 0000000..01f556d --- /dev/null +++ b/src/main/webapp/admin/product/view.xhtml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + Product + + + + View existing Product + + + + + + + + + + + + + + + + + +
+ + + +
+
+ +
\ No newline at end of file diff --git a/src/main/webapp/admin/purchaseOrder/search.xhtml b/src/main/webapp/admin/purchaseOrder/search.xhtml new file mode 100644 index 0000000..36b9b53 --- /dev/null +++ b/src/main/webapp/admin/purchaseOrder/search.xhtml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + Purchase Order + + + + Search Purchase Order entities + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/admin/purchaseOrder/view.xhtml b/src/main/webapp/admin/purchaseOrder/view.xhtml new file mode 100644 index 0000000..3a6a606 --- /dev/null +++ b/src/main/webapp/admin/purchaseOrder/view.xhtml @@ -0,0 +1,115 @@ + + + + + + + + + + + + + Purchase Order + + + + View existing Purchase Order + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+ +
\ No newline at end of file diff --git a/src/main/webapp/debug.xhtml b/src/main/webapp/debug.xhtml new file mode 100644 index 0000000..00938c2 --- /dev/null +++ b/src/main/webapp/debug.xhtml @@ -0,0 +1,167 @@ + + + + + + + + +

Request information

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

Request headers

+ + + + + + + + + +

Request cookies

+ + + + + + + +

Request attributes

+ + + + + + + +

Session information

+ + + + + + + + + +

Session attributes

+ + + + + + + +

Application information

+ + + + + + + + + + + + + + + +

Application attributes

+ + + + + + + +

System information

+ + + + + + + + + +

Memory

+ + + + + + + +

Thread stack

+ + + + + + + +
+
diff --git a/src/main/webapp/error.xhtml b/src/main/webapp/error.xhtml new file mode 100644 index 0000000..41cee2f --- /dev/null +++ b/src/main/webapp/error.xhtml @@ -0,0 +1,27 @@ + + + + + + + + Oops + + + + That's going to leave a mark! + + + +

+ JBoss and JBoss Community +
To replace this page edit 'src/main/webapp/error.xhtml', or + keep Forging! +

+
+ +
diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html new file mode 100755 index 0000000..0e7f732 --- /dev/null +++ b/src/main/webapp/index.html @@ -0,0 +1,11 @@ + + + + + + Redirect... + + + + + \ No newline at end of file diff --git a/src/main/webapp/resources/coventry.png b/src/main/webapp/resources/coventry.png new file mode 100644 index 0000000..e7ba8bf Binary files /dev/null and b/src/main/webapp/resources/coventry.png differ diff --git a/src/main/webapp/resources/css/style.css b/src/main/webapp/resources/css/style.css new file mode 100755 index 0000000..7e30bdf --- /dev/null +++ b/src/main/webapp/resources/css/style.css @@ -0,0 +1,195 @@ +.centered-text { + text-align: center +} + +#myVideo { + object-fit: cover; + width: 100vw; + height: 100vh; + position: fixed; + top: 0; + left: 0; + z-index: -100; + opacity: 0.4; + pointer-events: none; +} + +.navbar { + background: white; + box-shadow: 0 7px 72px 0 rgba(0,0,0,.18); +} + +.well { + border-radius: 5px; + background: rgba(255,255,255,0.8); + box-shadow: 0 7px 72px 0 rgba(0,0,0,.18); +} + +body { + font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji; +} + +a { + color: gray; + font-weight: 200; +} + +.list-image { + max-width: 200px; + box-shadow: 0 2px 1px rgba(0,0,0,.09),0 4px 2px rgba(0,0,0,.09),0 8px 4px rgba(0,0,0,.09),0 1pc 8px rgba(0,0,0,.09),0 2pc 1pc rgba(0,0,0,.09),0 0 58px 14px rgba(0,0,0,.1); +} + +.products-grid tbody { + display: flex; + flex-wrap: wrap; + flex-direction: row; + /*justify-content: space-between;*/ + align-items: auto; + align-content: space-between +} + +.products-grid tr { + flex: 0 0 auto; + margin: 8px; + position: relative; +} + +.products-grid td { + border: none !important; +} + +.products-grid td:first-child { + border-radius: 10px; +} + +.products-grid td:last-child { + position: absolute; + bottom: 0; + left: 0; + background: rgba(255,255,255,0.8); + max-width: 100%; + margin: 8px; + width: calc(100% - 16px); +} + +.products-grid a { + color: black; + font-weight: 500; + font-size: 15px; +} + +.page-header { + border-bottom: none !important; +} + +.navbar .container { + padding-top: 10px; + padding-bottom: 10px; +} + +.navbar-brand > img { + width: 18px; + display: inline-block; + margin-top: -5px; +} + +.details-table img { + max-width: 200px; +} + +#page-container { + position: relative; + min-height: calc(100vh - 50px); +} + +#wrap { + padding-bottom: 6rem; /* Footer height */ +} + +#footer { + position: absolute; + bottom: 0; + width: 100%; + height: 6rem; /* Footer height */ +} + +.coventry-logo { + height: 40px; + opacity: 0.4; +} + +.btn-primary { + margin: 5px; + background: lightcoral; + border-color: deeppink !important; +} + +input, select { + margin-bottom: 10px; +} + +.navbar-form input { + margin-bottom: 0px; +} + +.welcome-img { + max-width: 300px; + display: block; + margin-left: auto; + margin-right: auto; +} + +.main-container { + margin-top: 50px; +} + +.page-header ul { + list-style: none !important; + margin-left: -40px !important; +} + +.alert-info { + /*color: #0c5460;*/ + /*background-color: #d1ecf1;*/ + /*border-color: #bee5eb;*/ + color: #155724; + background-color: #d4edda; + border-color: #c3e6cb; +} + +.alert-warn { + color: #856404; + background-color: #fff3cd; + border-color: #ffeeba; +} + +.alert-error { + color: #721c24; + background-color: #f8d7da; + border-color: #f5c6cb; +} + +.btn-search { + position: absolute; + right: 0; + background: none; + margin-right: 22px; + height: 34px; + border: none; +} + +.navbar-form .fa-search { + position: absolute; + width: 0; + margin-left: -25px; + margin-top: 10px; + pointer-events: none; +} + +.search-table img { + max-width: 30px; +} + +#itemBeanItemImagePath { + max-width: 200px; +} \ No newline at end of file diff --git a/src/main/webapp/resources/favicon.ico b/src/main/webapp/resources/favicon.ico new file mode 100644 index 0000000..95bff0b Binary files /dev/null and b/src/main/webapp/resources/favicon.ico differ diff --git a/src/main/webapp/resources/icon.png b/src/main/webapp/resources/icon.png new file mode 100644 index 0000000..68e195a Binary files /dev/null and b/src/main/webapp/resources/icon.png differ diff --git a/src/main/webapp/resources/images/1000.jpg b/src/main/webapp/resources/images/1000.jpg new file mode 100644 index 0000000..aa5731f Binary files /dev/null and b/src/main/webapp/resources/images/1000.jpg differ diff --git a/src/main/webapp/resources/images/1001.jpg b/src/main/webapp/resources/images/1001.jpg new file mode 100644 index 0000000..43e303b Binary files /dev/null and b/src/main/webapp/resources/images/1001.jpg differ diff --git a/src/main/webapp/resources/images/1002.jpg b/src/main/webapp/resources/images/1002.jpg new file mode 100644 index 0000000..81d9980 Binary files /dev/null and b/src/main/webapp/resources/images/1002.jpg differ diff --git a/src/main/webapp/resources/images/1003.jpg b/src/main/webapp/resources/images/1003.jpg new file mode 100644 index 0000000..6359e8a Binary files /dev/null and b/src/main/webapp/resources/images/1003.jpg differ diff --git a/src/main/webapp/resources/images/1004.jpg b/src/main/webapp/resources/images/1004.jpg new file mode 100644 index 0000000..bc882f8 Binary files /dev/null and b/src/main/webapp/resources/images/1004.jpg differ diff --git a/src/main/webapp/resources/images/1005.jpg b/src/main/webapp/resources/images/1005.jpg new file mode 100644 index 0000000..ef8d483 Binary files /dev/null and b/src/main/webapp/resources/images/1005.jpg differ diff --git a/src/main/webapp/resources/images/1006.jpg b/src/main/webapp/resources/images/1006.jpg new file mode 100644 index 0000000..948001e Binary files /dev/null and b/src/main/webapp/resources/images/1006.jpg differ diff --git a/src/main/webapp/resources/images/1007.jpg b/src/main/webapp/resources/images/1007.jpg new file mode 100644 index 0000000..5277124 Binary files /dev/null and b/src/main/webapp/resources/images/1007.jpg differ diff --git a/src/main/webapp/resources/images/1008.jpg b/src/main/webapp/resources/images/1008.jpg new file mode 100644 index 0000000..77df26b Binary files /dev/null and b/src/main/webapp/resources/images/1008.jpg differ diff --git a/src/main/webapp/resources/images/1009.jpg b/src/main/webapp/resources/images/1009.jpg new file mode 100644 index 0000000..05f5dc9 Binary files /dev/null and b/src/main/webapp/resources/images/1009.jpg differ diff --git a/src/main/webapp/resources/images/1010.jpg b/src/main/webapp/resources/images/1010.jpg new file mode 100644 index 0000000..478589e Binary files /dev/null and b/src/main/webapp/resources/images/1010.jpg differ diff --git a/src/main/webapp/resources/images/1011.jpg b/src/main/webapp/resources/images/1011.jpg new file mode 100644 index 0000000..f427101 Binary files /dev/null and b/src/main/webapp/resources/images/1011.jpg differ diff --git a/src/main/webapp/resources/images/1012.jpg b/src/main/webapp/resources/images/1012.jpg new file mode 100644 index 0000000..854d190 Binary files /dev/null and b/src/main/webapp/resources/images/1012.jpg differ diff --git a/src/main/webapp/resources/images/1013.jpg b/src/main/webapp/resources/images/1013.jpg new file mode 100644 index 0000000..adeaf88 Binary files /dev/null and b/src/main/webapp/resources/images/1013.jpg differ diff --git a/src/main/webapp/resources/images/1014.jpg b/src/main/webapp/resources/images/1014.jpg new file mode 100644 index 0000000..4b272f3 Binary files /dev/null and b/src/main/webapp/resources/images/1014.jpg differ diff --git a/src/main/webapp/resources/images/1015.jpg b/src/main/webapp/resources/images/1015.jpg new file mode 100644 index 0000000..5319127 Binary files /dev/null and b/src/main/webapp/resources/images/1015.jpg differ diff --git a/src/main/webapp/resources/images/1016.jpg b/src/main/webapp/resources/images/1016.jpg new file mode 100644 index 0000000..6a0d964 Binary files /dev/null and b/src/main/webapp/resources/images/1016.jpg differ diff --git a/src/main/webapp/resources/images/1017.jpg b/src/main/webapp/resources/images/1017.jpg new file mode 100644 index 0000000..911dce2 Binary files /dev/null and b/src/main/webapp/resources/images/1017.jpg differ diff --git a/src/main/webapp/resources/images/1018.jpg b/src/main/webapp/resources/images/1018.jpg new file mode 100644 index 0000000..50a0c44 Binary files /dev/null and b/src/main/webapp/resources/images/1018.jpg differ diff --git a/src/main/webapp/resources/images/1019.jpg b/src/main/webapp/resources/images/1019.jpg new file mode 100644 index 0000000..c157417 Binary files /dev/null and b/src/main/webapp/resources/images/1019.jpg differ diff --git a/src/main/webapp/resources/images/1020.jpg b/src/main/webapp/resources/images/1020.jpg new file mode 100644 index 0000000..2df8809 Binary files /dev/null and b/src/main/webapp/resources/images/1020.jpg differ diff --git a/src/main/webapp/resources/images/1021.jpg b/src/main/webapp/resources/images/1021.jpg new file mode 100644 index 0000000..d696cce Binary files /dev/null and b/src/main/webapp/resources/images/1021.jpg differ diff --git a/src/main/webapp/resources/images/1022.jpg b/src/main/webapp/resources/images/1022.jpg new file mode 100644 index 0000000..7315f4d Binary files /dev/null and b/src/main/webapp/resources/images/1022.jpg differ diff --git a/src/main/webapp/resources/images/1023.jpg b/src/main/webapp/resources/images/1023.jpg new file mode 100644 index 0000000..49f576c Binary files /dev/null and b/src/main/webapp/resources/images/1023.jpg differ diff --git a/src/main/webapp/resources/images/1024.jpg b/src/main/webapp/resources/images/1024.jpg new file mode 100644 index 0000000..6622be1 Binary files /dev/null and b/src/main/webapp/resources/images/1024.jpg differ diff --git a/src/main/webapp/resources/images/1025.jpg b/src/main/webapp/resources/images/1025.jpg new file mode 100644 index 0000000..ad7e783 Binary files /dev/null and b/src/main/webapp/resources/images/1025.jpg differ diff --git a/src/main/webapp/resources/images/1026.jpg b/src/main/webapp/resources/images/1026.jpg new file mode 100644 index 0000000..dcd0138 Binary files /dev/null and b/src/main/webapp/resources/images/1026.jpg differ diff --git a/src/main/webapp/resources/images/1027.jpg b/src/main/webapp/resources/images/1027.jpg new file mode 100644 index 0000000..7c2e543 Binary files /dev/null and b/src/main/webapp/resources/images/1027.jpg differ diff --git a/src/main/webapp/resources/images/1028.jpg b/src/main/webapp/resources/images/1028.jpg new file mode 100644 index 0000000..cbedd8b Binary files /dev/null and b/src/main/webapp/resources/images/1028.jpg differ diff --git a/src/main/webapp/resources/images/1029.jpg b/src/main/webapp/resources/images/1029.jpg new file mode 100644 index 0000000..5f33a91 Binary files /dev/null and b/src/main/webapp/resources/images/1029.jpg differ diff --git a/src/main/webapp/resources/images/1030.jpg b/src/main/webapp/resources/images/1030.jpg new file mode 100644 index 0000000..09ce1b4 Binary files /dev/null and b/src/main/webapp/resources/images/1030.jpg differ diff --git a/src/main/webapp/resources/images/1031.jpg b/src/main/webapp/resources/images/1031.jpg new file mode 100644 index 0000000..3314e62 Binary files /dev/null and b/src/main/webapp/resources/images/1031.jpg differ diff --git a/src/main/webapp/resources/images/1032.jpg b/src/main/webapp/resources/images/1032.jpg new file mode 100644 index 0000000..b1222cb Binary files /dev/null and b/src/main/webapp/resources/images/1032.jpg differ diff --git a/src/main/webapp/resources/images/1033.jpg b/src/main/webapp/resources/images/1033.jpg new file mode 100644 index 0000000..68932a7 Binary files /dev/null and b/src/main/webapp/resources/images/1033.jpg differ diff --git a/src/main/webapp/resources/templates/paginator.xhtml b/src/main/webapp/resources/templates/paginator.xhtml new file mode 100644 index 0000000..98d0bc6 --- /dev/null +++ b/src/main/webapp/resources/templates/paginator.xhtml @@ -0,0 +1,22 @@ + + + + + + + + + < Previous + + + + + Next > + + + + diff --git a/src/main/webapp/resources/templates/template.xhtml b/src/main/webapp/resources/templates/template.xhtml new file mode 100755 index 0000000..69839f8 --- /dev/null +++ b/src/main/webapp/resources/templates/template.xhtml @@ -0,0 +1,177 @@ + + + + + + + + + + + + + #{empty pageTitle ? 'Page Title' : pageTitle} + + + + + + + + + + + + + + +
+ + +
+ +
+ + + + + + + + + + + + + + $(document).ready(function () { + myVideo.muted="true" + myVideo.loop="true" + myVideo.play(); + }); + + + + diff --git a/src/main/webapp/resources/templates/templateCRUD.xhtml b/src/main/webapp/resources/templates/templateCRUD.xhtml new file mode 100755 index 0000000..967be94 --- /dev/null +++ b/src/main/webapp/resources/templates/templateCRUD.xhtml @@ -0,0 +1,21 @@ + + + + + +
+ +
+
+
\ No newline at end of file diff --git a/src/main/webapp/resources/templates/templateShopping.xhtml b/src/main/webapp/resources/templates/templateShopping.xhtml new file mode 100755 index 0000000..1c80480 --- /dev/null +++ b/src/main/webapp/resources/templates/templateShopping.xhtml @@ -0,0 +1,46 @@ + + + + + +
+ +
+
+
\ No newline at end of file diff --git a/src/main/webapp/shopping/confirmorder.xhtml b/src/main/webapp/shopping/confirmorder.xhtml new file mode 100755 index 0000000..2360256 --- /dev/null +++ b/src/main/webapp/shopping/confirmorder.xhtml @@ -0,0 +1,110 @@ + + + + + + + + #{i18n.orderConfirmed_yourOrderIsComplete} + + + + + + +
+
+

#{i18n.confirmorder_personalInformation}

+
+
+ + + + + + + + + + + + + + +
+
+ +
+
+

#{i18n.confirmorder_deliveryAddress}

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+

#{i18n.creditCard}

+
+
+ + + + + + + + + + + + + + + +
+
+ +
+ +
+
+ +
+
diff --git a/src/main/webapp/shopping/createaccount.xhtml b/src/main/webapp/shopping/createaccount.xhtml new file mode 100755 index 0000000..b05e116 --- /dev/null +++ b/src/main/webapp/shopping/createaccount.xhtml @@ -0,0 +1,101 @@ + + + + + + + + #{i18n.createAccount_createYourAccount} + + + + + + +
+
+

#{i18n.createAccount_personalInformation}

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+

#{i18n.address}

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+ +
+
diff --git a/src/main/webapp/shopping/main.xhtml b/src/main/webapp/shopping/main.xhtml new file mode 100755 index 0000000..e4d6601 --- /dev/null +++ b/src/main/webapp/shopping/main.xhtml @@ -0,0 +1,17 @@ + + + + + + + +
+ + Looking for the ultimate vegan chocolate cake? Want a classic carrot cake without eggs or dairy? We've taken classic British cakes and made them vegan friendly. Our decadent chocolate cake, moist carrot cake and tangy lemon loaf are just as moist and moreish without the dairy! +
+
+
diff --git a/src/main/webapp/shopping/orderconfirmed.xhtml b/src/main/webapp/shopping/orderconfirmed.xhtml new file mode 100755 index 0000000..969e637 --- /dev/null +++ b/src/main/webapp/shopping/orderconfirmed.xhtml @@ -0,0 +1,50 @@ + + + + + + + + #{i18n.orderConfirmed_yourOrderIsComplete} + + + + + + + + +
+ +
+ + + + + x + £ + + + = + £ + +
+
+ +
+ Total £#{shoppingCartBean.order.total} +
+
+ + #{i18n.orderConfirmed_yourOrderIdIs} : #{shoppingCartBean.order.id} + +

#{i18n.orderConfirmed_msg1}

+ +

#{i18n.orderConfirmed_msg2}

+ +
+
diff --git a/src/main/webapp/shopping/pexels-taryn-elliott-6829215.mp4 b/src/main/webapp/shopping/pexels-taryn-elliott-6829215.mp4 new file mode 100644 index 0000000..87bb1b2 Binary files /dev/null and b/src/main/webapp/shopping/pexels-taryn-elliott-6829215.mp4 differ diff --git a/src/main/webapp/shopping/searchresult.xhtml b/src/main/webapp/shopping/searchresult.xhtml new file mode 100755 index 0000000..2270b5e --- /dev/null +++ b/src/main/webapp/shopping/searchresult.xhtml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + #{i18n.searchResult_searchFor} : #{catalogBean.keyword} + + + + + + + + + + + + + + + + + + + + + + ( + + - + + ) + + + £ + + + + + + + + + + + + + + + diff --git a/src/main/webapp/shopping/showaccount.xhtml b/src/main/webapp/shopping/showaccount.xhtml new file mode 100755 index 0000000..8491703 --- /dev/null +++ b/src/main/webapp/shopping/showaccount.xhtml @@ -0,0 +1,103 @@ + + + + + + + + #{i18n.accounts} + + + + + + +
+
+

#{i18n.confirmorder_personalInformation}

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+

#{i18n.address}

+
+
+ + + + + + + + + + + + + + + + + + + +
+
+ +
+ + + +
+
+ +
+
+ diff --git a/src/main/webapp/shopping/showcart.xhtml b/src/main/webapp/shopping/showcart.xhtml new file mode 100755 index 0000000..67bc810 --- /dev/null +++ b/src/main/webapp/shopping/showcart.xhtml @@ -0,0 +1,72 @@ + + + + + + + + #{i18n.shoppingCart} + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + x + £ + + + = £ + + + + + + + + +
+ +
+ +
+ Total £ + + + + Check Out + +
+
+ +
+
+ diff --git a/src/main/webapp/shopping/showitem.xhtml b/src/main/webapp/shopping/showitem.xhtml new file mode 100755 index 0000000..821c468 --- /dev/null +++ b/src/main/webapp/shopping/showitem.xhtml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + #{catalogBean.item.product.name} - #{catalogBean.item.name} + + + + + + + + + + + + + + + + + £ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/shopping/showitems.xhtml b/src/main/webapp/shopping/showitems.xhtml new file mode 100755 index 0000000..5ef5c77 --- /dev/null +++ b/src/main/webapp/shopping/showitems.xhtml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + #{i18n.showItems_itemForProduct} : #{catalogBean.product.name} + + + + + + + + + + + + + + £ + + + + + diff --git a/src/main/webapp/shopping/showproducts.xhtml b/src/main/webapp/shopping/showproducts.xhtml new file mode 100755 index 0000000..082d555 --- /dev/null +++ b/src/main/webapp/shopping/showproducts.xhtml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + #{catalogBean.categoryName} + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/shopping/signon.xhtml b/src/main/webapp/shopping/signon.xhtml new file mode 100755 index 0000000..74c31b1 --- /dev/null +++ b/src/main/webapp/shopping/signon.xhtml @@ -0,0 +1,57 @@ + + + + + + + + #{i18n.signon_signIn} + + + + +
+
+

#{i18n.signon_returningCustomer}

+
+
+ + + + + + + + + +
+
+ +
+
+

#{i18n.signon_signup}

+
+
+ + + + + + + + + + + +
+
+ +
+
diff --git a/src/main/webapp/shopping/updateaccount.xhtml b/src/main/webapp/shopping/updateaccount.xhtml new file mode 100755 index 0000000..4d3a2e4 --- /dev/null +++ b/src/main/webapp/shopping/updateaccount.xhtml @@ -0,0 +1,110 @@ + + + + + + + + #{i18n.updateYourAccount} + + + + + + +
+
+

#{i18n.createAccount_personalInformation}

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+

#{i18n.address}

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+ +
+
diff --git a/src/main/webapp/shopping/welcome.png b/src/main/webapp/shopping/welcome.png new file mode 100644 index 0000000..8b4dbe4 Binary files /dev/null and b/src/main/webapp/shopping/welcome.png differ diff --git a/src/main/webapp/swagger.json b/src/main/webapp/swagger.json new file mode 100644 index 0000000..ec6bafe --- /dev/null +++ b/src/main/webapp/swagger.json @@ -0,0 +1,736 @@ +{ + "swagger" : "2.0", + "info" : { + "description" : "VeganCakes APIs exposed", + "version" : "1.0.0", + "title" : "Vegancakes APIs", + "contact" : { + "name" : "Tomasz Prabucki", + "url" : "https://tprabucki.netlify.com/", + "email" : "prabuckt@uni.coventry.ac.uk" + } + }, + "host" : "localhost:8080", + "basePath" : "/applicationVegancakes/rest", + "tags" : [ { + "name" : "Category" + }, { + "name" : "Country" + }, { + "name" : "Customer" + }, { + "name" : "Item" + }, { + "name" : "Product" + } ], + "schemes" : [ "http", "https" ], + "paths" : { + "/categories" : { + "get" : { + "tags" : [ "Category" ], + "summary" : "Lists all the categories", + "description" : "", + "operationId" : "listAll", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "start", + "in" : "query", + "required" : false, + "type" : "integer", + "format" : "int32" + }, { + "name" : "max", + "in" : "query", + "required" : false, + "type" : "integer", + "format" : "int32" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Category" + } + } + } + } + }, + "post" : { + "tags" : [ "Category" ], + "summary" : "Creates a category", + "description" : "", + "operationId" : "create", + "consumes" : [ "application/xml", "application/json" ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/categories/{id}" : { + "get" : { + "tags" : [ "Category" ], + "summary" : "Finds a category given an identifier", + "description" : "", + "operationId" : "findById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "id", + "in" : "path", + "required" : true, + "type" : "integer", + "pattern" : "[0-9][0-9]*", + "format" : "int64" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + }, + "put" : { + "tags" : [ "Category" ], + "summary" : "Updates a category", + "description" : "", + "operationId" : "update", + "consumes" : [ "application/xml", "application/json" ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + }, + "delete" : { + "tags" : [ "Category" ], + "summary" : "Deletes a category by id", + "description" : "", + "operationId" : "deleteById", + "parameters" : [ { + "name" : "id", + "in" : "path", + "required" : true, + "type" : "integer", + "pattern" : "[0-9][0-9]*", + "format" : "int64" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/countries" : { + "get" : { + "tags" : [ "Country" ], + "summary" : "Lists all the countries", + "description" : "", + "operationId" : "listAll", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "start", + "in" : "query", + "required" : false, + "type" : "integer", + "format" : "int32" + }, { + "name" : "max", + "in" : "query", + "required" : false, + "type" : "integer", + "format" : "int32" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Country" + } + } + } + } + }, + "post" : { + "tags" : [ "Country" ], + "summary" : "Creates a country", + "description" : "", + "operationId" : "create", + "consumes" : [ "application/xml", "application/json" ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/countries/{id}" : { + "get" : { + "tags" : [ "Country" ], + "summary" : "Retrieves a country by its id", + "description" : "", + "operationId" : "findById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "id", + "in" : "path", + "required" : true, + "type" : "integer", + "pattern" : "[0-9][0-9]*", + "format" : "int64" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + }, + "put" : { + "tags" : [ "Country" ], + "summary" : "Updates a country", + "description" : "", + "operationId" : "update", + "consumes" : [ "application/xml", "application/json" ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + }, + "delete" : { + "tags" : [ "Country" ], + "summary" : "Deletes a country given an id", + "description" : "", + "operationId" : "deleteById", + "parameters" : [ { + "name" : "id", + "in" : "path", + "required" : true, + "type" : "integer", + "pattern" : "[0-9][0-9]*", + "format" : "int64" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/customers" : { + "get" : { + "tags" : [ "Customer" ], + "summary" : "Lists all the customers", + "description" : "", + "operationId" : "listAll", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "start", + "in" : "query", + "required" : false, + "type" : "integer", + "format" : "int32" + }, { + "name" : "max", + "in" : "query", + "required" : false, + "type" : "integer", + "format" : "int32" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Customer" + } + } + } + } + }, + "post" : { + "tags" : [ "Customer" ], + "summary" : "Creates a customer", + "description" : "", + "operationId" : "create", + "consumes" : [ "application/xml", "application/json" ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/customers/{id}" : { + "get" : { + "tags" : [ "Customer" ], + "summary" : "Finds a customer by it identifier", + "description" : "", + "operationId" : "findById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "id", + "in" : "path", + "required" : true, + "type" : "integer", + "pattern" : "[0-9][0-9]*", + "format" : "int64" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + }, + "put" : { + "tags" : [ "Customer" ], + "summary" : "Updates a customer", + "description" : "", + "operationId" : "update", + "consumes" : [ "application/xml", "application/json" ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + }, + "delete" : { + "tags" : [ "Customer" ], + "summary" : "Deletes a customer by id", + "description" : "", + "operationId" : "deleteById", + "parameters" : [ { + "name" : "id", + "in" : "path", + "required" : true, + "type" : "integer", + "pattern" : "[0-9][0-9]*", + "format" : "int64" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/items" : { + "get" : { + "tags" : [ "Item" ], + "summary" : "Lists all items", + "description" : "", + "operationId" : "listAll", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "start", + "in" : "query", + "required" : false, + "type" : "integer", + "format" : "int32" + }, { + "name" : "max", + "in" : "query", + "required" : false, + "type" : "integer", + "format" : "int32" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Item" + } + } + } + } + }, + "post" : { + "tags" : [ "Item" ], + "summary" : "Creates a new item", + "description" : "", + "operationId" : "create", + "consumes" : [ "application/xml", "application/json" ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/items/{id}" : { + "get" : { + "tags" : [ "Item" ], + "summary" : "Finds an item by its id", + "description" : "", + "operationId" : "findById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "id", + "in" : "path", + "required" : true, + "type" : "integer", + "pattern" : "[0-9][0-9]*", + "format" : "int64" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + }, + "put" : { + "tags" : [ "Item" ], + "summary" : "Updates an item", + "description" : "", + "operationId" : "update", + "consumes" : [ "application/xml", "application/json" ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + }, + "delete" : { + "tags" : [ "Item" ], + "summary" : "Deletes an item by its id", + "description" : "", + "operationId" : "deleteById", + "parameters" : [ { + "name" : "id", + "in" : "path", + "required" : true, + "type" : "integer", + "pattern" : "[0-9][0-9]*", + "format" : "int64" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/products" : { + "get" : { + "tags" : [ "Product" ], + "summary" : "Lists all products", + "description" : "", + "operationId" : "listAll", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "start", + "in" : "query", + "required" : false, + "type" : "integer", + "format" : "int32" + }, { + "name" : "max", + "in" : "query", + "required" : false, + "type" : "integer", + "format" : "int32" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Product" + } + } + } + } + }, + "post" : { + "tags" : [ "Product" ], + "summary" : "Creates new product", + "description" : "", + "operationId" : "create", + "consumes" : [ "application/xml", "application/json" ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/products/{id}" : { + "get" : { + "tags" : [ "Product" ], + "summary" : "Finds a product by id", + "description" : "", + "operationId" : "findById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "id", + "in" : "path", + "required" : true, + "type" : "integer", + "pattern" : "[0-9][0-9]*", + "format" : "int64" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + }, + "put" : { + "tags" : [ "Product" ], + "summary" : "Updates a product", + "description" : "", + "operationId" : "update", + "consumes" : [ "application/xml", "application/json" ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + }, + "delete" : { + "tags" : [ "Product" ], + "summary" : "Deletes a product by id", + "description" : "", + "operationId" : "deleteById", + "parameters" : [ { + "name" : "id", + "in" : "path", + "required" : true, + "type" : "integer", + "pattern" : "[0-9][0-9]*", + "format" : "int64" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + } + }, + "definitions" : { + "Address" : { + "type" : "object", + "required" : [ "city", "street1", "postcode" ], + "properties" : { + "street1" : { + "type" : "string", + "minLength" : 5, + "maxLength" : 50 + }, + "street2" : { + "type" : "string" + }, + "city" : { + "type" : "string", + "minLength" : 2, + "maxLength" : 50 + }, + "state" : { + "type" : "string" + }, + "postcode" : { + "type" : "string", + "minLength" : 1, + "maxLength" : 10 + }, + "country" : { + "$ref" : "#/definitions/Country" + } + } + }, + "Category" : { + "type" : "object", + "required" : [ "description", "name" ], + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "version" : { + "type" : "integer", + "format" : "int32" + }, + "name" : { + "type" : "string", + "minLength" : 1, + "maxLength" : 30 + }, + "description" : { + "type" : "string", + "minLength" : 0, + "maxLength" : 3000 + } + } + }, + "Country" : { + "type" : "object", + "required" : [ "iso3", "isoCode", "name", "numcode", "printableName" ], + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "version" : { + "type" : "integer", + "format" : "int32" + }, + "isoCode" : { + "type" : "string", + "minLength" : 2, + "maxLength" : 2 + }, + "name" : { + "type" : "string", + "minLength" : 2, + "maxLength" : 80 + }, + "printableName" : { + "type" : "string", + "minLength" : 2, + "maxLength" : 80 + }, + "iso3" : { + "type" : "string", + "minLength" : 3, + "maxLength" : 3 + }, + "numcode" : { + "type" : "string", + "minLength" : 3, + "maxLength" : 3 + } + } + }, + "Customer" : { + "type" : "object", + "required" : [ "firstName", "lastName", "password" ], + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "version" : { + "type" : "integer", + "format" : "int32" + }, + "firstName" : { + "type" : "string", + "minLength" : 2, + "maxLength" : 50 + }, + "lastName" : { + "type" : "string", + "minLength" : 2, + "maxLength" : 50 + }, + "telephone" : { + "type" : "string" + }, + "email" : { + "type" : "string" + }, + "login" : { + "type" : "string" + }, + "password" : { + "type" : "string", + "minLength" : 1, + "maxLength" : 256 + }, + "uuid" : { + "type" : "string", + "minLength" : 1, + "maxLength" : 256 + }, + "role" : { + "type" : "string", + "enum" : [ "USER", "ADMIN" ] + }, + "dateOfBirth" : { + "type" : "string", + "format" : "date-time" + }, + "age" : { + "type" : "integer", + "format" : "int32" + }, + "homeAddress" : { + "$ref" : "#/definitions/Address" + }, + "fullName" : { + "type" : "string" + } + } + }, + "Item" : { + "type" : "object", + "required" : [ "description", "name", "unitCost" ], + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "version" : { + "type" : "integer", + "format" : "int32" + }, + "name" : { + "type" : "string", + "minLength" : 1, + "maxLength" : 30 + }, + "description" : { + "type" : "string", + "minLength" : 0, + "maxLength" : 3000 + }, + "imagePath" : { + "type" : "string" + }, + "unitCost" : { + "type" : "number", + "format" : "float" + }, + "product" : { + "$ref" : "#/definitions/Product" + } + } + }, + "Product" : { + "type" : "object", + "required" : [ "description", "name" ], + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "version" : { + "type" : "integer", + "format" : "int32" + }, + "name" : { + "type" : "string", + "minLength" : 1, + "maxLength" : 30 + }, + "description" : { + "type" : "string", + "minLength" : 0, + "maxLength" : 3000 + }, + "category" : { + "$ref" : "#/definitions/Category" + } + } + } + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/AddressIT.java b/src/test/java/org/prabuckt/application/vegancakes/model/AddressIT.java new file mode 100755 index 0000000..c04dcb3 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/AddressIT.java @@ -0,0 +1,54 @@ +package org.prabuckt.application.vegancakes.model; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; +import javax.validation.Validator; + +import static org.junit.Assert.assertEquals; + +/** + * @author Tomasz Prabucki + */ +@RunWith(Arquillian.class) +public class AddressIT { + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private Validator validator; + + // ====================================== + // = Lifecycle Methods = + // ====================================== + + @Deployment + public static JavaArchive jar() { + return ShrinkWrap.create(JavaArchive.class) + .addClass(Address.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCreateAValidAddress() { + + // Creates an object + Country country = new Country("DV", "Dummy value", "Dummy value", "DMV", "DMV"); + Address address = new Address("Street1", "City", "Postcode", country); + + // Checks the object is valid + assertEquals("Should have not constraint violation", 0, validator.validate(address).size()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/AddressTest.java b/src/test/java/org/prabuckt/application/vegancakes/model/AddressTest.java new file mode 100755 index 0000000..00b1813 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/AddressTest.java @@ -0,0 +1,22 @@ +package org.prabuckt.application.vegancakes.model; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; +import org.junit.Test; + +/** + * @author Tomasz Prabucki + */ +public class AddressTest { + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCheckEqualsAndHashCode() { + + // Checks equals and hashCode is valid + EqualsVerifier.forClass(Address.class).suppress(Warning.NONFINAL_FIELDS).verify(); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/CategoryIT.java b/src/test/java/org/prabuckt/application/vegancakes/model/CategoryIT.java new file mode 100755 index 0000000..2b25eb2 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/CategoryIT.java @@ -0,0 +1,69 @@ +package org.prabuckt.application.vegancakes.model; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; +import javax.validation.Validator; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import java.io.StringWriter; + +import static org.junit.Assert.assertEquals; + +/** + * @author Tomasz Prabucki + */ +@RunWith(Arquillian.class) +public class CategoryIT { + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private Validator validator; + + // ====================================== + // = Lifecycle Methods = + // ====================================== + + @Deployment + public static JavaArchive jar() { + return ShrinkWrap.create(JavaArchive.class) + .addClass(Category.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCreateAValidCategory() { + + // Creates an object + Category category = new Category("Cakes", ""); + + // Checks the object is valid + assertEquals("Should have not constraint violation", 0, validator.validate(category).size()); + } + + @Test + public void shouldBeAbleToMarshallAndUnmarchallIntoXML() throws Exception { + + // Creates an object + Category category = new Category("Cakes", ""); + + // Marshalls it to XML + StringWriter writer = new StringWriter(); + JAXBContext context = JAXBContext.newInstance(Category.class); + Marshaller m = context.createMarshaller(); + m.marshal(category, writer); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/CategoryTest.java b/src/test/java/org/prabuckt/application/vegancakes/model/CategoryTest.java new file mode 100755 index 0000000..153a6a0 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/CategoryTest.java @@ -0,0 +1,22 @@ +package org.prabuckt.application.vegancakes.model; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; +import org.junit.Test; + +/** + * @author Tomasz Prabucki + */ +public class CategoryTest { + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCheckEqualsAndHashCode() { + + // Checks equals and hashCode is valid + EqualsVerifier.forClass(Category.class).suppress(Warning.NONFINAL_FIELDS).verify(); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/CountryTest.java b/src/test/java/org/prabuckt/application/vegancakes/model/CountryTest.java new file mode 100755 index 0000000..20df0ca --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/CountryTest.java @@ -0,0 +1,22 @@ +package org.prabuckt.application.vegancakes.model; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; +import org.junit.Test; + +/** + * @author Tomasz Prabucki + */ +public class CountryTest { + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCheckEqualsAndHashCode() { + + // Checks equals and hashCode is valid + EqualsVerifier.forClass(Country.class).suppress(Warning.NONFINAL_FIELDS).verify(); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/CreditCardTest.java b/src/test/java/org/prabuckt/application/vegancakes/model/CreditCardTest.java new file mode 100755 index 0000000..d7a3726 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/CreditCardTest.java @@ -0,0 +1,22 @@ +package org.prabuckt.application.vegancakes.model; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; +import org.junit.Test; + +/** + * @author Tomasz Prabucki + */ +public class CreditCardTest { + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCheckEqualsAndHashCode() { + + // Checks equals and hashCode is valid + EqualsVerifier.forClass(CreditCard.class).suppress(Warning.NONFINAL_FIELDS).verify(); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/CustomerIT.java b/src/test/java/org/prabuckt/application/vegancakes/model/CustomerIT.java new file mode 100755 index 0000000..36edc15 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/CustomerIT.java @@ -0,0 +1,55 @@ +package org.prabuckt.application.vegancakes.model; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; +import javax.validation.Validator; + +import static org.junit.Assert.assertEquals; + +/** + * @author Tomasz Prabucki + */ +@RunWith(Arquillian.class) +public class CustomerIT { + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private Validator validator; + + // ====================================== + // = Lifecycle Methods = + // ====================================== + + @Deployment + public static JavaArchive jar() { + return ShrinkWrap.create(JavaArchive.class) + .addClasses(Category.class, Address.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCreateAValidCustomer() { + + // Creates an object + Country country = new Country("DV", "Dummy value", "Dummy value", "DMV", "DMV"); + Address address = new Address("78 Gnu Rd", "Texas", "666", country); + Customer customer = new Customer("Paul", "Mc Cartney", "pmac", "pmac", "paul@beales.com", address); + + // Checks the object is valid + assertEquals("Should have not constraint violation", 0, validator.validate(customer).size()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/CustomerTest.java b/src/test/java/org/prabuckt/application/vegancakes/model/CustomerTest.java new file mode 100755 index 0000000..917f7b5 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/CustomerTest.java @@ -0,0 +1,22 @@ +package org.prabuckt.application.vegancakes.model; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; +import org.junit.Test; + +/** + * @author Tomasz Prabucki + */ +public class CustomerTest { + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCheckEqualsAndHashCode() { + + // Checks equals and hashCode is valid + EqualsVerifier.forClass(Customer.class).suppress(Warning.NONFINAL_FIELDS).verify(); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/ItemIT.java b/src/test/java/org/prabuckt/application/vegancakes/model/ItemIT.java new file mode 100755 index 0000000..57eb290 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/ItemIT.java @@ -0,0 +1,73 @@ +package org.prabuckt.application.vegancakes.model; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; +import javax.validation.Validator; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import java.io.StringWriter; + +import static org.junit.Assert.assertEquals; + +/** + * @author Tomasz Prabucki + */ +@RunWith(Arquillian.class) +public class ItemIT { + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private Validator validator; + + // ====================================== + // = Lifecycle Methods = + // ====================================== + + @Deployment + public static JavaArchive jar() { + return ShrinkWrap.create(JavaArchive.class) + .addClasses(Category.class, Product.class, Item.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCreateAValidItem() { + + // Creates an object + Category category = new Category("Cakes", ""); + Product product = new Product("Double Chocolate Mug Cake", "Chocolate cake is one of the most popular, if not the most popular cake flavours that we know of. With this recipe, you can quickly make a delicious single-serving chocolate cake (in a mug), with minimal effort.", category); + Item item = new Item("Small", 10.99f, "1000.png", "desc", product); + + // Checks the object is valid + assertEquals("Should have not constraint violation", 0, validator.validate(item).size()); + } + + @Test + public void shouldBeAbleToMarshallAndUnmarchallIntoXML() throws Exception { + + // Creates an object + Category category = new Category("Cakes", ""); + Product product = new Product("Double Chocolate Mug Cake", "Chocolate cake is one of the most popular, if not the most popular cake flavours that we know of. With this recipe, you can quickly make a delicious single-serving chocolate cake (in a mug), with minimal effort.", category); + Item item = new Item("Small", 10.99f, "1000.png", "desc", product); + + // Marshalls it to XML + StringWriter writer = new StringWriter(); + JAXBContext context = JAXBContext.newInstance(Item.class); + Marshaller m = context.createMarshaller(); + m.marshal(item, writer); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/ItemTest.java b/src/test/java/org/prabuckt/application/vegancakes/model/ItemTest.java new file mode 100755 index 0000000..eebdef7 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/ItemTest.java @@ -0,0 +1,22 @@ +package org.prabuckt.application.vegancakes.model; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; +import org.junit.Test; + +/** + * @author Tomasz Prabucki + */ +public class ItemTest { + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCheckEqualsAndHashCode() { + + // Checks equals and hashCode is valid + EqualsVerifier.forClass(Item.class).suppress(Warning.NONFINAL_FIELDS).verify(); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/OrderLineTest.java b/src/test/java/org/prabuckt/application/vegancakes/model/OrderLineTest.java new file mode 100755 index 0000000..ced9faa --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/OrderLineTest.java @@ -0,0 +1,22 @@ +package org.prabuckt.application.vegancakes.model; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; +import org.junit.Test; + +/** + * @author Tomasz Prabucki + */ +public class OrderLineTest { + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCheckEqualsAndHashCode() { + + // Checks equals and hashCode is valid + EqualsVerifier.forClass(OrderLine.class).suppress(Warning.NONFINAL_FIELDS).verify(); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/ProductIT.java b/src/test/java/org/prabuckt/application/vegancakes/model/ProductIT.java new file mode 100755 index 0000000..8aa1a60 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/ProductIT.java @@ -0,0 +1,71 @@ +package org.prabuckt.application.vegancakes.model; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; +import javax.validation.Validator; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import java.io.StringWriter; + +import static org.junit.Assert.assertEquals; + +/** + * @author Tomasz Prabucki + */ +@RunWith(Arquillian.class) +public class ProductIT { + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private Validator validator; + + // ====================================== + // = Lifecycle Methods = + // ====================================== + + @Deployment + public static JavaArchive jar() { + return ShrinkWrap.create(JavaArchive.class) + .addClasses(Category.class, Product.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCreateAValidProduct() { + + // Creates an object + Category category = new Category("Cakes", ""); + Product product = new Product("Double Chocolate Mug Cake", "Chocolate cake is one of the most popular, if not the most popular cake flavours that we know of. With this recipe, you can quickly make a delicious single-serving chocolate cake (in a mug), with minimal effort.", category); + + // Checks the object is valid + assertEquals("Should have not constraint violation", 0, validator.validate(product).size()); + } + + @Test + public void shouldBeAbleToMarshallAndUnmarchallIntoXML() throws Exception { + + // Creates an object + Category category = new Category("Cakes", ""); + Product product = new Product("Double Chocolate Mug Cake", "Chocolate cake is one of the most popular, if not the most popular cake flavours that we know of. With this recipe, you can quickly make a delicious single-serving chocolate cake (in a mug), with minimal effort.", category); + + // Marshalls it to XML + StringWriter writer = new StringWriter(); + JAXBContext context = JAXBContext.newInstance(Product.class); + Marshaller m = context.createMarshaller(); + m.marshal(product, writer); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/ProductTest.java b/src/test/java/org/prabuckt/application/vegancakes/model/ProductTest.java new file mode 100755 index 0000000..6bcc941 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/ProductTest.java @@ -0,0 +1,22 @@ +package org.prabuckt.application.vegancakes.model; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; +import org.junit.Test; + +/** + * @author Tomasz Prabucki + */ +public class ProductTest { + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCheckEqualsAndHashCode() { + + // Checks equals and hashCode is valid + EqualsVerifier.forClass(Product.class).suppress(Warning.NONFINAL_FIELDS).verify(); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/PurchaseOrderIT.java b/src/test/java/org/prabuckt/application/vegancakes/model/PurchaseOrderIT.java new file mode 100755 index 0000000..0eb56a3 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/PurchaseOrderIT.java @@ -0,0 +1,57 @@ +package org.prabuckt.application.vegancakes.model; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; +import javax.validation.Validator; + +import static org.junit.Assert.assertEquals; + +/** + * @author Tomasz Prabucki + */ +@RunWith(Arquillian.class) +public class PurchaseOrderIT { + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private Validator validator; + + // ====================================== + // = Lifecycle Methods = + // ====================================== + + @Deployment + public static JavaArchive jar() { + return ShrinkWrap.create(JavaArchive.class) + .addClasses(Address.class, Customer.class, CreditCard.class, PurchaseOrder.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCreateAValidOrder() { + + // Creates an object + Country country = new Country("DV", "Dummy value", "Dummy value", "DMV", "DMV"); + Address address = new Address("78 Gnu Rd", "Texas", "666", country); + Customer customer = new Customer("Paul", "Mc Cartney", "pmac", "pmac", "paul@beales.com", address); + CreditCard creditCard = new CreditCard("123456789", CreditCardType.VISA, "12/45"); + PurchaseOrder order = new PurchaseOrder(customer, creditCard, address); + + // Checks the object is valid + assertEquals("Should have not constraint violation", 0, validator.validate(order).size()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/model/PurchaseOrderTest.java b/src/test/java/org/prabuckt/application/vegancakes/model/PurchaseOrderTest.java new file mode 100755 index 0000000..4933c20 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/model/PurchaseOrderTest.java @@ -0,0 +1,22 @@ +package org.prabuckt.application.vegancakes.model; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; +import org.junit.Test; + +/** + * @author Tomasz Prabucki + */ +public class PurchaseOrderTest { + + // ====================================== + // = Methods = + // ====================================== + + @Test + public void shouldCheckEqualsAndHashCode() { + + // Checks equals and hashCode is valid + EqualsVerifier.forClass(PurchaseOrder.class).suppress(Warning.NONFINAL_FIELDS).verify(); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/rest/CategoryEndpointTest.java b/src/test/java/org/prabuckt/application/vegancakes/rest/CategoryEndpointTest.java new file mode 100644 index 0000000..cc7f449 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/rest/CategoryEndpointTest.java @@ -0,0 +1,77 @@ +package org.prabuckt.application.vegancakes.rest; + +import org.prabuckt.application.vegancakes.model.Category; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.net.URI; + +import static org.junit.Assert.assertEquals; + +@RunWith(Arquillian.class) +@RunAsClient +public class CategoryEndpointTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @ArquillianResource + private URI baseURL; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment(testable = false) + public static WebArchive createDeployment() + { + return ShrinkWrap.create(WebArchive.class) + .addClass(RestApplication.class) + .addClass(CategoryEndpoint.class) + .addClass(Category.class) + .addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("categories"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_XML).get().getStatus()); + } + + @Test + public void should_produce_json() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("categories"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_JSON).get().getStatus()); + } + + @Test + public void should_produce_xml() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("categories"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_XML).get().getStatus()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/rest/CountryEndpointTest.java b/src/test/java/org/prabuckt/application/vegancakes/rest/CountryEndpointTest.java new file mode 100644 index 0000000..1fbcfe8 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/rest/CountryEndpointTest.java @@ -0,0 +1,77 @@ +package org.prabuckt.application.vegancakes.rest; + +import org.prabuckt.application.vegancakes.model.Country; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.net.URI; + +import static org.junit.Assert.assertEquals; + +@RunWith(Arquillian.class) +@RunAsClient +public class CountryEndpointTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @ArquillianResource + private URI baseURL; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment(testable = false) + public static WebArchive createDeployment() + { + return ShrinkWrap.create(WebArchive.class) + .addClass(RestApplication.class) + .addClass(CountryEndpoint.class) + .addClass(Country.class) + .addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("countries"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_XML).get().getStatus()); + } + + @Test + public void should_produce_json() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("countries"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_JSON).get().getStatus()); + } + + @Test + public void should_produce_xml() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("countries"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_XML).get().getStatus()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/rest/CustomerEndpointTest.java b/src/test/java/org/prabuckt/application/vegancakes/rest/CustomerEndpointTest.java new file mode 100644 index 0000000..9684103 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/rest/CustomerEndpointTest.java @@ -0,0 +1,85 @@ +package org.prabuckt.application.vegancakes.rest; + +import org.prabuckt.application.vegancakes.exceptions.ValidationException; +import org.prabuckt.application.vegancakes.model.Address; +import org.prabuckt.application.vegancakes.model.Country; +import org.prabuckt.application.vegancakes.model.Customer; +import org.prabuckt.application.vegancakes.model.UserRole; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.net.URI; + +import static org.junit.Assert.assertEquals; + +@RunWith(Arquillian.class) +@RunAsClient +public class CustomerEndpointTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @ArquillianResource + private URI baseURL; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment(testable = false) + public static WebArchive createDeployment() + { + return ShrinkWrap.create(WebArchive.class) + .addClass(RestApplication.class) + .addClass(CustomerEndpoint.class) + .addClass(Customer.class) + .addClass(Address.class) + .addClass(Country.class) + .addClass(UserRole.class) + .addClass(ValidationException.class) + .addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("customers"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_XML).get().getStatus()); + } + + @Test + public void should_produce_json() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("customers"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_JSON).get().getStatus()); + } + + @Test + public void should_produce_xml() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("customers"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_XML).get().getStatus()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/rest/ItemEndpointTest.java b/src/test/java/org/prabuckt/application/vegancakes/rest/ItemEndpointTest.java new file mode 100644 index 0000000..63d8e4b --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/rest/ItemEndpointTest.java @@ -0,0 +1,79 @@ +package org.prabuckt.application.vegancakes.rest; + +import org.prabuckt.application.vegancakes.model.Category; +import org.prabuckt.application.vegancakes.model.Item; +import org.prabuckt.application.vegancakes.model.Product; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.net.URI; + +import static org.junit.Assert.assertEquals; + +@RunWith(Arquillian.class) +public class ItemEndpointTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @ArquillianResource + private URI baseURL; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment(testable = false) + public static WebArchive createDeployment() + { + return ShrinkWrap.create(WebArchive.class) + .addClass(RestApplication.class) + .addClass(ItemEndpoint.class) + .addClass(Item.class) + .addClass(Product.class) + .addClass(Category.class) + .addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("items"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_XML).get().getStatus()); + } + + @Test + public void should_produce_json() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("items"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_JSON).get().getStatus()); + } + + @Test + public void should_produce_xml() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("items"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_XML).get().getStatus()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/rest/ProductEndpointTest.java b/src/test/java/org/prabuckt/application/vegancakes/rest/ProductEndpointTest.java new file mode 100644 index 0000000..cd5cdfc --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/rest/ProductEndpointTest.java @@ -0,0 +1,79 @@ +package org.prabuckt.application.vegancakes.rest; + +import org.prabuckt.application.vegancakes.model.Category; +import org.prabuckt.application.vegancakes.model.Product; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.net.URI; + +import static org.junit.Assert.assertEquals; + +@RunWith(Arquillian.class) +@RunAsClient +public class ProductEndpointTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @ArquillianResource + private URI baseURL; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment(testable = false) + public static WebArchive createDeployment() + { + return ShrinkWrap.create(WebArchive.class) + .addClass(RestApplication.class) + .addClass(ProductEndpoint.class) + .addClass(Product.class) + .addClass(Category.class) + .addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("products"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_XML).get().getStatus()); + } + + @Test + public void should_produce_json() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("products"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_JSON).get().getStatus()); + } + + @Test + public void should_produce_xml() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseURL).path("rest").path("products"); + assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.APPLICATION_XML).get().getStatus()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/service/CategoryServiceTest.java b/src/test/java/org/prabuckt/application/vegancakes/service/CategoryServiceTest.java new file mode 100644 index 0000000..7803b25 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/service/CategoryServiceTest.java @@ -0,0 +1,86 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.model.Category; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(Arquillian.class) +public class CategoryServiceTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private CategoryService categoryservice; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(AbstractService.class) + .addClass(CategoryService.class) + .addClass(Category.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(categoryservice); + } + + @Test + public void should_crud() + { + // Gets all the objects + int initialSize = categoryservice.listAll().size(); + + // Creates an object + Category category = new Category(); + category.setName("Dummy value"); + category.setDescription("Dummy value"); + + // Inserts the object into the database + category = categoryservice.persist(category); + assertNotNull(category.getId()); + assertEquals(initialSize + 1, categoryservice.listAll().size()); + + // Finds the object from the database and checks it's the right one + category = categoryservice.findById(category.getId()); + assertEquals("Dummy value", category.getName()); + + // Updates the object + category.setName("A new value"); + category = categoryservice.merge(category); + + // Finds the object from the database and checks it has been updated + category = categoryservice.findById(category.getId()); + assertEquals("A new value", category.getName()); + + // Deletes the object from the database and checks it's not there anymore + categoryservice.remove(category); + assertEquals(initialSize, categoryservice.listAll().size()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/service/CountryServiceTest.java b/src/test/java/org/prabuckt/application/vegancakes/service/CountryServiceTest.java new file mode 100644 index 0000000..7a636ef --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/service/CountryServiceTest.java @@ -0,0 +1,82 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.model.Country; +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.junit.Assert.*; + +@RunWith(Arquillian.class) +public class CountryServiceTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private CountryService countryservice; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(AbstractService.class) + .addClass(CountryService.class) + .addClass(Country.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(countryservice); + } + + @Test + public void should_crud() + { + // Gets all the objects + int initialSize = countryservice.listAll().size(); + + // Creates an object + Country country = new Country("DV", "Dummy value", "Dummy value", "DMV", "DMV"); + + // Inserts the object into the database + country = countryservice.persist(country); + assertNotNull(country.getId()); + assertEquals(initialSize + 1, countryservice.listAll().size()); + + // Finds the object from the database and checks it's the right one + country = countryservice.findById(country.getId()); + assertEquals("Dummy value", country.getName()); + + // Updates the object + country.setName("A new value"); + country = countryservice.merge(country); + + // Finds the object from the database and checks it has been updated + country = countryservice.findById(country.getId()); + assertEquals("A new value", country.getName()); + + // Deletes the object from the database and checks it's not there anymore + countryservice.remove(country); + assertEquals(initialSize, countryservice.listAll().size()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/service/CustomerServiceTest.java b/src/test/java/org/prabuckt/application/vegancakes/service/CustomerServiceTest.java new file mode 100644 index 0000000..611aaf7 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/service/CustomerServiceTest.java @@ -0,0 +1,94 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.exceptions.ValidationException; +import org.prabuckt.application.vegancakes.model.Address; +import org.prabuckt.application.vegancakes.model.Country; +import org.prabuckt.application.vegancakes.model.Customer; +import org.prabuckt.application.vegancakes.model.UserRole; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(Arquillian.class) +public class CustomerServiceTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private CustomerService customerservice; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(AbstractService.class) + .addClass(CustomerService.class) + .addClass(Customer.class) + .addClass(Address.class) + .addClass(Country.class) + .addClass(UserRole.class) + .addClass(ValidationException.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(customerservice); + } + + @Test + public void should_crud() + { + // Gets all the objects + int initialSize = customerservice.listAll().size(); + + // Creates an object + Country country = new Country("DV", "Dummy value", "Dummy value", "DMV", "DMV"); + Address address = new Address("Dummy value", "Dummy value", "DV", country); + Customer customer = new Customer("Dummy value", "Dummy value", "Dummy", "Dummy value", "Dummy value", address); + + // Inserts the object into the database + customer = customerservice.persist(customer); + assertNotNull(customer.getId()); + assertEquals(initialSize + 1, customerservice.listAll().size()); + + // Finds the object from the database and checks it's the right one + customer = customerservice.findById(customer.getId()); + assertEquals("Dummy value", customer.getFirstName()); + + // Updates the object + customer.setFirstName("A new value"); + customer = customerservice.merge(customer); + + // Finds the object from the database and checks it has been updated + customer = customerservice.findById(customer.getId()); + assertEquals("A new value", customer.getFirstName()); + + // Deletes the object from the database and checks it's not there anymore + customerservice.remove(customer); + assertEquals(initialSize, customerservice.listAll().size()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/service/ItemServiceTest.java b/src/test/java/org/prabuckt/application/vegancakes/service/ItemServiceTest.java new file mode 100644 index 0000000..9f4bada --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/service/ItemServiceTest.java @@ -0,0 +1,88 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.model.Category; +import org.prabuckt.application.vegancakes.model.Item; +import org.prabuckt.application.vegancakes.model.Product; +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.junit.Assert.*; + +@RunWith(Arquillian.class) +public class ItemServiceTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private ItemService itemservice; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(AbstractService.class) + .addClass(ItemService.class) + .addClass(Item.class) + .addClass(Product.class) + .addClass(Category.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(itemservice); + } + + @Test + public void should_crud() + { + // Gets all the objects + int initialSize = itemservice.listAll().size(); + + // Creates an object + Category category = new Category("Dummy value", "Dummy value"); + Product product = new Product("Dummy value", "Dummy value", category); + Item item = new Item("Dummy value", 10f, "Dummy value", "Dummy value", product); + + // Inserts the object into the database + item = itemservice.persist(item); + assertNotNull(item.getId()); + assertEquals(initialSize + 1, itemservice.listAll().size()); + + // Finds the object from the database and checks it's the right one + item = itemservice.findById(item.getId()); + assertEquals("Dummy value", item.getName()); + + // Updates the object + item.setName("A new value"); + item = itemservice.merge(item); + + // Finds the object from the database and checks it has been updated + item = itemservice.findById(item.getId()); + assertEquals("A new value", item.getName()); + + // Deletes the object from the database and checks it's not there anymore + itemservice.remove(item); + assertEquals(initialSize, itemservice.listAll().size()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/service/OrderLineServiceTest.java b/src/test/java/org/prabuckt/application/vegancakes/service/OrderLineServiceTest.java new file mode 100644 index 0000000..2fd1027 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/service/OrderLineServiceTest.java @@ -0,0 +1,91 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.model.Category; +import org.prabuckt.application.vegancakes.model.Item; +import org.prabuckt.application.vegancakes.model.OrderLine; +import org.prabuckt.application.vegancakes.model.Product; +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.junit.Assert.*; + +@RunWith(Arquillian.class) +public class OrderLineServiceTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private OrderLineService orderlineservice; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(AbstractService.class) + .addClass(OrderLineService.class) + .addClass(OrderLine.class) + .addClass(Category.class) + .addClass(Product.class) + .addClass(Item.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(orderlineservice); + } + + @Test + public void should_crud() + { + // Gets all the objects + int initialSize = orderlineservice.listAll().size(); + + // Creates an object + Category category = new Category("Dummy value", "Dummy value"); + Product product = new Product("Dummy value", "Dummy value", category); + Item item = new Item("Dummy value", 10f, "Dummy value", "Dummy value", product); + OrderLine orderLine = new OrderLine(77, item); + + // Inserts the object into the database + orderLine = orderlineservice.persist(orderLine); + assertNotNull(orderLine.getId()); + assertEquals(initialSize + 1, orderlineservice.listAll().size()); + + // Finds the object from the database and checks it's the right one + orderLine = orderlineservice.findById(orderLine.getId()); + assertEquals(new Integer(77), orderLine.getQuantity()); + + // Updates the object + orderLine.setQuantity(88); + orderLine = orderlineservice.merge(orderLine); + + // Finds the object from the database and checks it has been updated + orderLine = orderlineservice.findById(orderLine.getId()); + assertEquals(new Integer(88), orderLine.getQuantity()); + + // Deletes the object from the database and checks it's not there anymore + orderlineservice.remove(orderLine); + assertEquals(initialSize, orderlineservice.listAll().size()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/service/ProductServiceTest.java b/src/test/java/org/prabuckt/application/vegancakes/service/ProductServiceTest.java new file mode 100644 index 0000000..a8b070b --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/service/ProductServiceTest.java @@ -0,0 +1,85 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.model.Category; +import org.prabuckt.application.vegancakes.model.Product; +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.junit.Assert.*; + +@RunWith(Arquillian.class) +public class ProductServiceTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private ProductService productservice; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(AbstractService.class) + .addClass(ProductService.class) + .addClass(Product.class) + .addClass(Category.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(productservice); + } + + @Test + public void should_crud() + { + // Gets all the objects + int initialSize = productservice.listAll().size(); + + // Creates an object + Category category = new Category("Dummy value", "Dummy value"); + Product product = new Product("Dummy value", "Dummy value", category); + + // Inserts the object into the database + product = productservice.persist(product); + assertNotNull(product.getId()); + assertEquals(initialSize + 1, productservice.listAll().size()); + + // Finds the object from the database and checks it's the right one + product = productservice.findById(product.getId()); + assertEquals("Dummy value", product.getName()); + + // Updates the object + product.setName("A new value"); + product = productservice.merge(product); + + // Finds the object from the database and checks it has been updated + product = productservice.findById(product.getId()); + assertEquals("A new value", product.getName()); + + // Deletes the object from the database and checks it's not there anymore + productservice.remove(product); + assertEquals(initialSize, productservice.listAll().size()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/service/PurchaseOrderServiceTest.java b/src/test/java/org/prabuckt/application/vegancakes/service/PurchaseOrderServiceTest.java new file mode 100644 index 0000000..086b8b6 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/service/PurchaseOrderServiceTest.java @@ -0,0 +1,108 @@ +package org.prabuckt.application.vegancakes.service; + +import org.prabuckt.application.vegancakes.exceptions.ValidationException; +import org.prabuckt.application.vegancakes.model.*; +import org.prabuckt.application.vegancakes.view.shopping.ShoppingCartItem; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(Arquillian.class) +public class PurchaseOrderServiceTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private PurchaseOrderService purchaseorderservice; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(AbstractService.class) + .addClass(PurchaseOrderService.class) + .addClass(PurchaseOrder.class) + .addClass(Country.class) + .addClass(Address.class) + .addClass(Customer.class) + .addClass(CreditCard.class) + .addClass(CreditCardType.class) + .addClass(OrderLine.class) + .addClass(Category.class) + .addClass(Product.class) + .addClass(Item.class) + .addClass(ShoppingCartItem.class) + .addClass(UserRole.class) + .addClass(ValidationException.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(purchaseorderservice); + } + + @Test @Ignore + public void should_crud() + { + // Gets all the objects + int initialSize = purchaseorderservice.listAll().size(); + + // Creates an object + Country country = new Country("DV", "Dummy value", "Dummy value", "DMV", "DMV"); + Address address = new Address("78 Gnu Rd", "Texas", "666", country); + Customer customer = new Customer("Paul", "Mc Cartney", "pmac", "pmac", "paul@beales.com", address); + CreditCard creditCard = new CreditCard("1234", CreditCardType.MASTER_CARD, "10/12"); + Set orderLines = new HashSet<>(); + PurchaseOrder purchaseOrder = new PurchaseOrder(customer, creditCard, address); + purchaseOrder.setOrderLines(orderLines); + purchaseOrder.setDiscount(12.5F); + + // Inserts the object into the database + purchaseOrder = purchaseorderservice.persist(purchaseOrder); + assertNotNull(purchaseOrder.getId()); + assertEquals(initialSize + 1, purchaseorderservice.listAll().size()); + + // Finds the object from the database and checks it's the right one + purchaseOrder = purchaseorderservice.findById(purchaseOrder.getId()); + assertEquals(new Float(12.5F), purchaseOrder.getDiscountRate()); + + // Updates the object + purchaseOrder.setDiscount(43.25F); + purchaseOrder = purchaseorderservice.merge(purchaseOrder); + + // Finds the object from the database and checks it has been updated + purchaseOrder = purchaseorderservice.findById(purchaseOrder.getId()); + assertEquals(new Float(43.25F), purchaseOrder.getDiscountRate()); + + // Deletes the object from the database and checks it's not there anymore + purchaseorderservice.remove(purchaseOrder); + assertEquals(initialSize, purchaseorderservice.listAll().size()); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/view/admin/CategoryBeanTest.java b/src/test/java/org/prabuckt/application/vegancakes/view/admin/CategoryBeanTest.java new file mode 100644 index 0000000..38338a9 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/view/admin/CategoryBeanTest.java @@ -0,0 +1,89 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import org.prabuckt.application.vegancakes.model.Category; +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.junit.Assert.*; + +@RunWith(Arquillian.class) +public class CategoryBeanTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private CategoryBean categorybean; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(CategoryBean.class) + .addClass(Category.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(categorybean); + } + + @Test + public void should_crud() + { + // Creates an object + Category category = new Category(); + category.setName("Dummy value"); + category.setDescription("Dummy value"); + + // Inserts the object into the database + categorybean.setCategory(category); + categorybean.create(); + categorybean.update(); + category = categorybean.getCategory(); + assertNotNull(category.getId()); + + // Finds the object from the database and checks it's the right one + category = categorybean.findById(category.getId()); + assertEquals("Dummy value", category.getName()); + + // Deletes the object from the database and checks it's not there anymore + categorybean.setId(category.getId()); + categorybean.create(); + categorybean.delete(); + category = categorybean.findById(category.getId()); + assertNull(category); + } + + @Test + public void should_paginate() + { + // Creates an empty example + Category example = new Category(); + + // Paginates through the example + categorybean.setExample(example); + categorybean.paginate(); + assertTrue((categorybean.getPageItems().size() == categorybean.getPageSize()) || (categorybean.getPageItems().size() == categorybean.getCount())); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/view/admin/CountryBeanTest.java b/src/test/java/org/prabuckt/application/vegancakes/view/admin/CountryBeanTest.java new file mode 100644 index 0000000..c2a42de --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/view/admin/CountryBeanTest.java @@ -0,0 +1,87 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import org.prabuckt.application.vegancakes.model.Country; +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.junit.Assert.*; + +@RunWith(Arquillian.class) +public class CountryBeanTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private CountryBean countrybean; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(CountryBean.class) + .addClass(Country.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(countrybean); + } + + @Test + public void should_crud() + { + // Creates an object + Country country = new Country("DV", "Dummy value", "Dummy value", "DMV", "DMV"); + + // Inserts the object into the database + countrybean.setCountry(country); + countrybean.create(); + countrybean.update(); + country = countrybean.getCountry(); + assertNotNull(country.getId()); + + // Finds the object from the database and checks it's the right one + country = countrybean.findById(country.getId()); + assertEquals("Dummy value", country.getName()); + + // Deletes the object from the database and checks it's not there anymore + countrybean.setId(country.getId()); + countrybean.create(); + countrybean.delete(); + country = countrybean.findById(country.getId()); + assertNull(country); + } + + @Test + public void should_paginate() + { + // Creates an empty example + Country example = new Country(); + + // Paginates through the example + countrybean.setExample(example); + countrybean.paginate(); + assertTrue((countrybean.getPageItems().size() == countrybean.getPageSize()) || (countrybean.getPageItems().size() == countrybean.getCount())); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/view/admin/CustomerBeanTest.java b/src/test/java/org/prabuckt/application/vegancakes/view/admin/CustomerBeanTest.java new file mode 100644 index 0000000..b88fd4f --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/view/admin/CustomerBeanTest.java @@ -0,0 +1,99 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import org.prabuckt.application.vegancakes.exceptions.ValidationException; +import org.prabuckt.application.vegancakes.model.Address; +import org.prabuckt.application.vegancakes.model.Country; +import org.prabuckt.application.vegancakes.model.Customer; +import org.prabuckt.application.vegancakes.model.UserRole; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +import static org.junit.Assert.*; + +@RunWith(Arquillian.class) +public class CustomerBeanTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private CustomerBean customerbean; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(CustomerBean.class) + .addClass(Customer.class) + .addClass(Address.class) + .addClass(Country.class) + .addClass(UserRole.class) + .addClass(ValidationException.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(customerbean); + } + + @Test + public void should_crud() + { + // Creates an object + Country country = new Country("DV", "Dummy value", "Dummy value", "DMV", "DMV"); + Address address = new Address("Dummy value", "Dummy value", "DV", country); + Customer customer = new Customer("Dummy value", "Dummy value", "Dummy", "Dummy value", "Dummy value", address); + + // Inserts the object into the database + customerbean.setCustomer(customer); + customerbean.create(); + customerbean.update(); + customer = customerbean.getCustomer(); + assertNotNull(customer.getId()); + + // Finds the object from the database and checks it's the right one + customer = customerbean.findById(customer.getId()); + assertEquals("Dummy value", customer.getFirstName()); + + + // Deletes the object from the database and checks it's not there anymore + customerbean.setId(customer.getId()); + customerbean.create(); + customerbean.delete(); + customer = customerbean.findById(customer.getId()); + assertNull(customer); + } + + @Test + public void should_paginate() + { + // Creates an empty example + Customer example = new Customer(); + + // Paginates through the example + customerbean.setExample(example); + customerbean.paginate(); + assertTrue((customerbean.getPageItems().size() == customerbean.getPageSize()) || (customerbean.getPageItems().size() == customerbean.getCount())); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/view/admin/ItemBeanTest.java b/src/test/java/org/prabuckt/application/vegancakes/view/admin/ItemBeanTest.java new file mode 100644 index 0000000..16f9710 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/view/admin/ItemBeanTest.java @@ -0,0 +1,93 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import org.prabuckt.application.vegancakes.model.Category; +import org.prabuckt.application.vegancakes.model.Item; +import org.prabuckt.application.vegancakes.model.Product; +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.junit.Assert.*; + +@RunWith(Arquillian.class) +public class ItemBeanTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private ItemBean itembean; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(ItemBean.class) + .addClass(Item.class) + .addClass(Product.class) + .addClass(Category.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(itembean); + } + + @Test + public void should_crud() + { + // Creates an object + Category category = new Category("Dummy value", "Dummy value"); + Product product = new Product("Dummy value", "Dummy value", category); + Item item = new Item("Dummy value", 10f, "Dummy value", "Dummy value", product); + + // Inserts the object into the database + itembean.setItem(item); + itembean.create(); + itembean.update(); + item = itembean.getItem(); + assertNotNull(item.getId()); + + // Finds the object from the database and checks it's the right one + item = itembean.findById(item.getId()); + assertEquals("Dummy value", item.getName()); + + // Deletes the object from the database and checks it's not there anymore + itembean.setId(item.getId()); + itembean.create(); + itembean.delete(); + item = itembean.findById(item.getId()); + assertNull(item); + } + + @Test + public void should_paginate() + { + // Creates an empty example + Item example = new Item(); + + // Paginates through the example + itembean.setExample(example); + itembean.paginate(); + assertTrue((itembean.getPageItems().size() == itembean.getPageSize()) || (itembean.getPageItems().size() == itembean.getCount())); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/view/admin/OrderLineBeanTest.java b/src/test/java/org/prabuckt/application/vegancakes/view/admin/OrderLineBeanTest.java new file mode 100644 index 0000000..04832d4 --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/view/admin/OrderLineBeanTest.java @@ -0,0 +1,96 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import org.prabuckt.application.vegancakes.model.Category; +import org.prabuckt.application.vegancakes.model.Item; +import org.prabuckt.application.vegancakes.model.OrderLine; +import org.prabuckt.application.vegancakes.model.Product; +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.junit.Assert.*; + +@RunWith(Arquillian.class) +public class OrderLineBeanTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private OrderLineBean orderlinebean; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(OrderLineBean.class) + .addClass(OrderLine.class) + .addClass(Category.class) + .addClass(Product.class) + .addClass(Item.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(orderlinebean); + } + + @Test + public void should_crud() + { + // Creates an object + Category category = new Category("Dummy value", "Dummy value"); + Product product = new Product("Dummy value", "Dummy value", category); + Item item = new Item("Dummy value", 10f, "Dummy value", "Dummy value", product); + OrderLine orderLine = new OrderLine(77, item); + + // Inserts the object into the database + orderlinebean.setOrderLine(orderLine); + orderlinebean.create(); + orderlinebean.update(); + orderLine = orderlinebean.getOrderLine(); + assertNotNull(orderLine.getId()); + + // Finds the object from the database and checks it's the right one + orderLine = orderlinebean.findById(orderLine.getId()); + assertEquals(new Integer(77), orderLine.getQuantity()); + + // Deletes the object from the database and checks it's not there anymore + orderlinebean.setId(orderLine.getId()); + orderlinebean.create(); + orderlinebean.delete(); + orderLine = orderlinebean.findById(orderLine.getId()); + assertNull(orderLine); + } + + @Test + public void should_paginate() + { + // Creates an empty example + OrderLine example = new OrderLine(); + + // Paginates through the example + orderlinebean.setExample(example); + orderlinebean.paginate(); + assertTrue((orderlinebean.getPageItems().size() == orderlinebean.getPageSize()) || (orderlinebean.getPageItems().size() == orderlinebean.getCount())); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/view/admin/ProductBeanTest.java b/src/test/java/org/prabuckt/application/vegancakes/view/admin/ProductBeanTest.java new file mode 100644 index 0000000..05a617d --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/view/admin/ProductBeanTest.java @@ -0,0 +1,90 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import org.prabuckt.application.vegancakes.model.Category; +import org.prabuckt.application.vegancakes.model.Product; +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.junit.Assert.*; + +@RunWith(Arquillian.class) +public class ProductBeanTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private ProductBean productbean; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(ProductBean.class) + .addClass(Product.class) + .addClass(Category.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(productbean); + } + + @Test + public void should_crud() + { + // Creates an object + Category category = new Category("Dummy value", "Dummy value"); + Product product = new Product("Dummy value", "Dummy value", category); + + // Inserts the object into the database + productbean.setProduct(product); + productbean.create(); + productbean.update(); + product = productbean.getProduct(); + assertNotNull(product.getId()); + + // Finds the object from the database and checks it's the right one + product = productbean.findById(product.getId()); + assertEquals("Dummy value", product.getName()); + + // Deletes the object from the database and checks it's not there anymore + productbean.setId(product.getId()); + productbean.create(); + productbean.delete(); + product = productbean.findById(product.getId()); + assertNull(product); + } + + @Test + public void should_paginate() + { + // Creates an empty example + Product example = new Product(); + + // Paginates through the example + productbean.setExample(example); + productbean.paginate(); + assertTrue((productbean.getPageItems().size() == productbean.getPageSize()) || (productbean.getPageItems().size() == productbean.getCount())); + } +} diff --git a/src/test/java/org/prabuckt/application/vegancakes/view/admin/PurchaseOrderBeanTest.java b/src/test/java/org/prabuckt/application/vegancakes/view/admin/PurchaseOrderBeanTest.java new file mode 100644 index 0000000..660c64a --- /dev/null +++ b/src/test/java/org/prabuckt/application/vegancakes/view/admin/PurchaseOrderBeanTest.java @@ -0,0 +1,112 @@ +package org.prabuckt.application.vegancakes.view.admin; + +import org.prabuckt.application.vegancakes.exceptions.ValidationException; +import org.prabuckt.application.vegancakes.model.*; +import org.prabuckt.application.vegancakes.view.shopping.ShoppingCartItem; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.*; + +@RunWith(Arquillian.class) +public class PurchaseOrderBeanTest +{ + + // ====================================== + // = Attributes = + // ====================================== + + @Inject + private PurchaseOrderBean purchaseorderbean; + + // ====================================== + // = Deployment = + // ====================================== + + @Deployment + public static JavaArchive createDeployment() + { + return ShrinkWrap.create(JavaArchive.class) + .addClass(PurchaseOrderBean.class) + .addClass(PurchaseOrder.class) + .addClass(Country.class) + .addClass(Address.class) + .addClass(Customer.class) + .addClass(CreditCard.class) + .addClass(CreditCardType.class) + .addClass(OrderLine.class) + .addClass(Category.class) + .addClass(Product.class) + .addClass(Item.class) + .addClass(ShoppingCartItem.class) + .addClass(UserRole.class) + .addClass(ValidationException.class) + .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + // ====================================== + // = Test Cases = + // ====================================== + + @Test + public void should_be_deployed() + { + Assert.assertNotNull(purchaseorderbean); + } + + @Test @Ignore + public void should_crud() + { + // Creates an object + Country country = new Country("DV", "Dummy value", "Dummy value", "DMV", "DMV"); + Address address = new Address("78 Gnu Rd", "Texas", "666", country); + Customer customer = new Customer("Paul", "Mc Cartney", "pmac", "pmac", "paul@beales.com", address); + CreditCard creditCard = new CreditCard("1234", CreditCardType.MASTER_CARD, "10/12"); + Set orderLines = new HashSet<>(); + PurchaseOrder purchaseOrder = new PurchaseOrder(customer, creditCard, address); + purchaseOrder.setOrderLines(orderLines); + purchaseOrder.setDiscount(12.5F); + + // Inserts the object into the database + purchaseorderbean.setPurchaseOrder(purchaseOrder); + purchaseorderbean.create(); + purchaseorderbean.update(); + purchaseOrder = purchaseorderbean.getPurchaseOrder(); + assertNotNull(purchaseOrder.getId()); + + // Finds the object from the database and checks it's the right one + purchaseOrder = purchaseorderbean.findById(purchaseOrder.getId()); + assertEquals(new Float(12.5F), purchaseOrder.getDiscountRate()); + + // Deletes the object from the database and checks it's not there anymore + purchaseorderbean.setId(purchaseOrder.getId()); + purchaseorderbean.create(); + purchaseorderbean.delete(); + purchaseOrder = purchaseorderbean.findById(purchaseOrder.getId()); + assertNull(purchaseOrder); + } + + @Test + public void should_paginate() + { + // Creates an empty example + PurchaseOrder example = new PurchaseOrder(); + + // Paginates through the example + purchaseorderbean.setExample(example); + purchaseorderbean.paginate(); + assertTrue((purchaseorderbean.getPageItems().size() == purchaseorderbean.getPageSize()) || (purchaseorderbean.getPageItems().size() == purchaseorderbean.getCount())); + } +} diff --git a/src/test/resources/arquillian.xml b/src/test/resources/arquillian.xml new file mode 100644 index 0000000..8f6777a --- /dev/null +++ b/src/test/resources/arquillian.xml @@ -0,0 +1,15 @@ + + + + + + + target/wildfly-11.0.0.Final + -Xmx1024m -Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 + + true + + + +