From: Roland Haeder Date: Mon, 25 Apr 2016 20:29:03 +0000 (+0200) Subject: initialized project X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7db053598c51c787763031653584de452cf952db;p=jjobs-core.git initialized project --- 7db053598c51c787763031653584de452cf952db diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..17cdcd5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Use Linux/Uni* line-feed for new lines (prevents converting) +* text=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..51ac39e --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +/nbproject/private/ +/nbproject/*~ +/manifest.mf +/build/ +/dist/ +/data/* +/*.properties +/*-ejb/nbproject/private/ +/*-ejb/nbproject/*~ +/*-ejb/build/ +/*-ejb/dist/ diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..a6e9b6a --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project pizzaservice-core. + + + diff --git a/dist.sh b/dist.sh new file mode 100755 index 0000000..7c4e148 --- /dev/null +++ b/dist.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +# Name of this project, detected by it's base path +NAME="${PWD##*/}" + +# Generated JAR file +DIST="dist/${NAME}.jar" + +# WildFly module base path +WILDFLY_MODULE_BASE_PATH="${HOME}/wildfly_domain/modules/org/mxchange" + +# And for this "module" (as WildFly calls it) +WILDFLY_MODULE_PATH="${WILDFLY_MODULE_BASE_PATH}/${NAME}/main" + +# module.xml +WILDFLY_MODULE_XML_FILE="wildfly/module.xml" + +# Glassfish base path (domain) +GLASSFISH_BASE_PATH="${HOME}/gf_domain/domain/lib" + +# Remote Glassfish path +GLASSFISH_SSH_PATH="/var/payara/domains/domain1/lib" + +# Remote SSH server (password-less access) +GLASSFISH_SSH_SERVER="www.mxchange.org" + +# Windows personal domain +PERSONAL_DOMAIN_PATH="${HOME}/personal_domain/lib" + +# Generate list +LIST=`find ../*/lib/${NAME}.jar` +LIST="${LIST} `find ../*/*-ejb/lib/${NAME}.jar`" +LIST="${LIST} ${WILDFLY_MODULE_PATH}" + +if [ -d "${GLASSFISH_BASE_PATH}" ] +then + echo "$0: Glassfish personal domain found, adding to LIST ..." + LIST="${LIST} ${GLASSFISH_BASE_PATH}" +fi + +if [ -d "${PERSONAL_DOMAIN_PATH}" ] +then + echo "$0: Personal domain found, adding to LIST ..." + LIST="${LIST} ${PERSONAL_DOMAIN_PATH}" +fi + +if [ ! -f "${DIST}" ] +then + echo "$0: '${DIST}' not found." + exit 1 +elif [ ! -d "${WILDFLY_MODULE_BASE_PATH}" ] +then + echo "$0: WildFly base path '${WILDFLY_MODULE_BASE_PATH}' not created." +elif [ ! -d "${WILDFLY_MODULE_PATH}" ] +then + mkdir -vp "${WILDFLY_MODULE_PATH}" +fi + +for project in ${LIST}; +do + if [ -d "${project}" ] + then + cp -v "${DIST}" "${project}" + elif [ -f "${project}" ] + then + cp -v "${DIST}" "${project}" + else + echo "$0: Project '${project}' not found." + fi + +done + +if [ "$1" != "r" -a -n "${GLASSFISH_SSH_PATH}" -a -n "${GLASSFISH_SSH_SERVER}" ] +then + echo "$0: Copying to remote '${GLASSFISH_SSH_SERVER}' ..." + scp "${DIST}" "${GLASSFISH_SSH_SERVER}:${GLASSFISH_SSH_PATH}" +fi + +# Copy module.xml ... +if [ -f "${WILDFLY_MODULE_XML_FILE}" ] +then + echo "$0: Generating module.xml ..." + XML_CONTENT=`cat "${WILDFLY_MODULE_XML_FILE}"` + XML_CONTENT="${XML_CONTENT//NAME/$NAME}" + echo "${XML_CONTENT}" > "${WILDFLY_MODULE_PATH}/module.xml" +fi + +echo "$0: All done." +exit 0 diff --git a/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..60c2f42 Binary files /dev/null and b/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/lib/jcontacts-business-core.jar b/lib/jcontacts-business-core.jar new file mode 100644 index 0000000..d0e5887 Binary files /dev/null and b/lib/jcontacts-business-core.jar differ diff --git a/lib/jcontacts-core.jar b/lib/jcontacts-core.jar new file mode 100644 index 0000000..bd2dd6f Binary files /dev/null and b/lib/jcontacts-core.jar differ diff --git a/lib/jcore-logger-lib.jar b/lib/jcore-logger-lib.jar new file mode 100644 index 0000000..687b0da Binary files /dev/null and b/lib/jcore-logger-lib.jar differ diff --git a/lib/jcore.jar b/lib/jcore.jar new file mode 100644 index 0000000..c50cd35 Binary files /dev/null and b/lib/jcore.jar differ diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar new file mode 100644 index 0000000..bf510f6 Binary files /dev/null and b/lib/jcoreee.jar differ diff --git a/lib/jcountry-core.jar b/lib/jcountry-core.jar new file mode 100644 index 0000000..85fa016 Binary files /dev/null and b/lib/jcountry-core.jar differ diff --git a/lib/jcustomer-core.jar b/lib/jcustomer-core.jar new file mode 100644 index 0000000..92d262a Binary files /dev/null and b/lib/jcustomer-core.jar differ diff --git a/lib/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar b/lib/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar new file mode 100644 index 0000000..841d2e1 Binary files /dev/null and b/lib/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar differ diff --git a/lib/jphone-core.jar b/lib/jphone-core.jar new file mode 100644 index 0000000..f89b2e9 Binary files /dev/null and b/lib/jphone-core.jar differ diff --git a/lib/juser-core.jar b/lib/juser-core.jar new file mode 100644 index 0000000..94a1002 Binary files /dev/null and b/lib/juser-core.jar differ diff --git a/lib/nblibraries.properties b/lib/nblibraries.properties new file mode 100644 index 0000000..0d47c47 --- /dev/null +++ b/lib/nblibraries.properties @@ -0,0 +1,8 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.CopyLibs.displayName=CopyLibs Task +libs.CopyLibs.prop-version=2.0 +libs.jpa20-persistence.classpath=\ + ${base}/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar +libs.jpa20-persistence.displayName=Persistence (JPA 2.1) +libs.jpa20-persistence.prop-maven-dependencies=org.eclipse.persistence:javax.persistence:2.1.0:jar diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..8d94110 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1444 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..ffaad87 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=b1744a3a +build.xml.script.CRC32=f71628c3 +build.xml.stylesheet.CRC32=8064a381@1.79.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=b1744a3a +nbproject/build-impl.xml.script.CRC32=2d7ae9d3 +nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..82dd2ed --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,124 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=pizzaservice-core +application.vendor=Cho-Time GmbH +auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/pizzaservice-core.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +file.reference.jcontacts-business-core.jar=lib/jcontacts-business-core.jar +file.reference.jcontacts-core.jar=lib/jcontacts-core.jar +file.reference.jcore-logger-lib.jar=lib/jcore-logger-lib.jar +file.reference.jcore.jar=lib/jcore.jar +file.reference.jcoreee.jar=lib/jcoreee.jar +file.reference.jcountry-core.jar=lib/jcountry-core.jar +file.reference.jcustomer-core.jar=lib/jcustomer-core.jar +file.reference.jphone-core.jar=lib/jphone-core.jar +file.reference.juser-core.jar=lib/juser-core.jar +includes=** +jar.archive.disabled=${jnlp.enabled} +jar.compress=false +jar.index=${jnlp.enabled} +javac.classpath=\ + ${file.reference.jcore.jar}:\ + ${file.reference.jcoreee.jar}:\ + ${file.reference.jcore-logger-lib.jar}:\ + ${file.reference.jcountry-core.jar}:\ + ${file.reference.jphone-core.jar}:\ + ${file.reference.juser-core.jar}:\ + ${file.reference.jcontacts-core.jar}:\ + ${file.reference.jcontacts-business-core.jar}:\ + ${file.reference.jcustomer-core.jar}:\ + ${libs.jpa20-persistence.classpath} +# Space-separated list of extra javac options +javac.compilerargs=-Xlint:unchecked -Xlint:deprecation +javac.deprecation=true +javac.external.vm=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=true +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=true +javadoc.splitindex=true +javadoc.use=true +javadoc.version=true +javadoc.windowtitle=RateCalc Core Library +jnlp.codebase.type=no.codebase +jnlp.descriptor=application +jnlp.enabled=false +jnlp.mixed.code=default +jnlp.offline-allowed=false +jnlp.signed=false +jnlp.signing= +jnlp.signing.alias= +jnlp.signing.keystore= +# Optional override of default Application-Library-Allowable-Codebase attribute identifying the locations where your signed RIA is expected to be found. +manifest.custom.application.library.allowable.codebase= +# Optional override of default Caller-Allowable-Codebase attribute identifying the domains from which JavaScript code can make calls to your RIA without security prompts. +manifest.custom.caller.allowable.codebase= +# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed +manifest.custom.codebase= +# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions) +manifest.custom.permissions= +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=true +platform.active=default_platform +project.license=default +project.licensePath=./nbproject/licenseheader.txt +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +source.reference.jcontacts-business-core.jar=../jcore-business-core/src/ +source.reference.jcontacts-core.jar=../jcontacts-core/src/ +source.reference.jcore-logger-lib.jar=../jcore-logger-lib/src/ +source.reference.jcore.jar=../jcore/src/ +source.reference.jcoreee.jar=../jcoreee/src/ +source.reference.jcountry-core.jar=../jcountry-core/src/ +source.reference.jcustomer-core.jar=../jcustomer-core/src/ +source.reference.jphone-core.jar=../jphone-core/src/ +source.reference.juser-core.jar=../juser-core/src/ +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..ba9f799 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,18 @@ + + + org.netbeans.modules.java.j2seproject + + + pizzaservice-core + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/src/org/mxchange/pizzaaplication/database/BasePizzaDatabaseBean.java b/src/org/mxchange/pizzaaplication/database/BasePizzaDatabaseBean.java new file mode 100644 index 0000000..c3dcea8 --- /dev/null +++ b/src/org/mxchange/pizzaaplication/database/BasePizzaDatabaseBean.java @@ -0,0 +1,242 @@ +/* + * Copyright (C) 2016 Cho-Time GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaaplication.database; + +import java.text.MessageFormat; +import java.util.GregorianCalendar; +import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcoreee.database.BaseDatabaseBean; +import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; + +/** + * A helper class for beans that access the database. + *

+ * @author Roland Haeder + */ +public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean { + + /** + * Serial number + */ + private static final long serialVersionUID = 12_895_410_275_811_963L; + + /** + * Protected constructor + */ + protected BasePizzaDatabaseBean () { + // Call super constructor + super(); + } + + /** + * Merges given contact's data + *

+ * @param contact Contact instance to merge + *

+ * @return Detached contact instance + */ + protected Contact mergeContactData (final Contact contact) { + // The contact instance must be valid + if (null == contact) { + // Throw NPE again + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw NPE again + throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N + } else if (contact.getContactId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } + + // Get contact from it and find it + Contact foundContact = this.getEntityManager().find(contact.getClass(), contact.getContactId()); + + // Should be found + assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", contact.getContactId()); //NOI18N + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: contact.contactId={0}", foundContact.getContactId())); //NOI18N + + // Merge contact instance + Contact detachedContact = this.getEntityManager().merge(foundContact); + + // Copy all + detachedContact.copyAll(contact); + + // Return detached contact + return detachedContact; + } + + /** + * Merges given (detached) contact's cellphone, land-line and fax numbers + *

+ * @param detachedContact Detached contact instance + */ + protected void mergeContactsCellphoneLandLineFaxNumbers (final Contact detachedContact) { + // The contact instance must be valid + if (null == detachedContact) { + // Throw NPE again + throw new NullPointerException("detachedContact is null"); //NOI18N + } else if (detachedContact.getContactId() == null) { + // Throw NPE again + throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N + } else if (detachedContact.getContactId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("detachedContact.contactId={0} is not valid.", detachedContact.getContactId())); //NOI18N + } + + // Get all instances + DialableCellphoneNumber cellphone = detachedContact.getContactCellphoneNumber(); + DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber(); + DialableFaxNumber fax = detachedContact.getContactFaxNumber(); + + // Is there a cellphone instance set? + if (cellphone instanceof DialableCellphoneNumber) { + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N + + // Then find it, too + DialableCellphoneNumber foundCellphone = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId()); + + // Should be there + assert (foundCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", foundCellphone.getPhoneId()); //NOI18N + + // Then merge it, too + DialableCellphoneNumber detachedCellphone = this.getEntityManager().merge(foundCellphone); + + // Should be there + assert (detachedCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", detachedCellphone.getPhoneId()); //NOI18N + + // Copy all + detachedCellphone.copyAll(detachedContact.getContactCellphoneNumber()); + + // Set it back + detachedContact.setContactCellphoneNumber(detachedCellphone); + } + + // Is there a fax instance set? + if (fax instanceof DialableFaxNumber) { + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N + + // Then find it, too + DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId()); + + // Should be there + assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N + + // Then merge it, too + DialableFaxNumber detachedFax = this.getEntityManager().merge(foundFax); + + // Should be there + assert (detachedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", detachedFax.getPhoneId()); //NOI18N + + // Copy all + detachedFax.copyAll(detachedContact.getContactFaxNumber()); + + // Set it back + detachedContact.setContactFaxNumber(detachedFax); + } + + // Is there a fax instance set? + if (landLine instanceof DialableLandLineNumber) { + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N + + // Then find it, too + DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId()); + + // Should be there + assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N + + // Then merge it, too + DialableLandLineNumber detachedLandLine = this.getEntityManager().merge(foundLandLine); + + // Should be there + assert (detachedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", detachedLandLine.getPhoneId()); //NOI18N + + // Copy all + detachedLandLine.copyAll(detachedContact.getContactLandLineNumber()); + + // Set it back + detachedContact.setContactLandLineNumber(detachedLandLine); + } + } + + /** + * Updates all contacts's phone entry's updated timestamps + *

+ * @param contact Contact instance to update + * @param isCellphoneUnlinked Whether a cellphone entry has been unlinked in + * contact instance + * @param isLandlineUnlinked Whether a land-line entry has been unlinked in + * contact instance + * @param isFaxUnlinked Whether a fax entry has been unlinked in contact + * instance + */ + protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isCellphoneUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) { + // The contact instance must be valid + if (null == contact) { + // Throw NPE again + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw NPE again + throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N + } else if (contact.getContactId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } + + // Get all phone instances + DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber(); + DialableFaxNumber faxNumber = contact.getContactFaxNumber(); + DialableCellphoneNumber cellphoneNumber = contact.getContactCellphoneNumber(); + + // Flags and instances must be constistent + if (isCellphoneUnlinked && cellphoneNumber instanceof DialableCellphoneNumber) { + // Bad state + throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but cellphoneNumber is set."); + } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) { + // Bad state + throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); + } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) { + // Bad state + throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); + } + + // Is a phone number instance set? + if (landLineNumber instanceof DialableLandLineNumber) { + // Set updated timestamp + landLineNumber.setPhoneEntryUpdated(new GregorianCalendar()); + } + + // Is a fax number instance set? + if (faxNumber instanceof DialableFaxNumber) { + // Set updated timestamp + faxNumber.setPhoneEntryUpdated(new GregorianCalendar()); + } + + // Is a mobile number instance set? + if (cellphoneNumber instanceof DialableCellphoneNumber) { + // Set updated timestamp + cellphoneNumber.setPhoneEntryUpdated(new GregorianCalendar()); + } + } + +} diff --git a/src/org/mxchange/pizzaaplication/model/customer/PizzaCustomer.java b/src/org/mxchange/pizzaaplication/model/customer/PizzaCustomer.java new file mode 100644 index 0000000..1969920 --- /dev/null +++ b/src/org/mxchange/pizzaaplication/model/customer/PizzaCustomer.java @@ -0,0 +1,262 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.model.customer; + +import java.util.Calendar; +import java.util.Objects; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.contact.UserContact; +import org.mxchange.jcustomercore.model.customer.Customer; +import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus; + +/** + * A customer entity + *

+ * @author Roland Haeder + */ +@Entity (name = "customer") +@Table ( + name = "customer", + indexes = { + @Index (columnList = "customer_number", unique = true) + } +) +@NamedQueries ( + { + @NamedQuery (name = "AllCustomers", query = "SELECT c FROM customer AS c ORDER BY c.customerId ASC") + } +) +@SuppressWarnings ("PersistenceUnitPresent") +public class PizzaCustomer implements Customer { + + /** + * Serial number + */ + private static final long serialVersionUID = 14_857_923_178_504_617L; + + /** + * Account status for this customer + */ + @Basic (optional = false) + @Enumerated (EnumType.STRING) + @Column (name = "customer_status", nullable = false) + private CustomerAccountStatus customerAccountStatus; + + /** + * Contact instance (personal data) + */ + @JoinColumn (name = "customer_contact_id", nullable = false, updatable = false, unique = true) + @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false) + private Contact customerContact; + + /** + * When this customer has been created + */ + @Basic (optional = false) + @Column (name = "customer_created", nullable = false, updatable = false) + @Temporal (TemporalType.TIMESTAMP) + private Calendar customerCreated; + + /** + * Id number for this entry + */ + @Id + @GeneratedValue (strategy = GenerationType.IDENTITY) + @Column (name = "customer_id", nullable = false, updatable = false) + private Long customerId; + + /** + * When this customer has been locked (last timestamp) + */ + @Column (name = "customer_last_locked") + @Temporal (TemporalType.TIMESTAMP) + private Calendar customerLocked; + + /** + * Customer number + */ + @Basic (optional = false) + @Column (name = "customer_number", nullable = false, updatable = false) + private String customerNumber; + + /** + * Default constructor + */ + public PizzaCustomer () { + } + + /** + * Constructor with account status, contact instance and customer number + *

+ * @param customerAccountStatus Account status (Call-agents may only call + * unlocked accounts) + * @param customerContact Contact instance + * @param customerNumber Customer number + */ + public PizzaCustomer (final CustomerAccountStatus customerAccountStatus, final Contact customerContact, final String customerNumber) { + // Call other constructor + this(); + + // Set all parameter + this.customerAccountStatus = customerAccountStatus; + this.customerContact = customerContact; + this.customerNumber = customerNumber; + } + + @Override + public void copyAll (final Customer customer) { + // Copy all supported fields + this.setCustomerAccountStatus(customer.getCustomerAccountStatus()); + this.setCustomerContact(customer.getCustomerContact()); + this.setCustomerCreated(customer.getCustomerCreated()); + this.setCustomerId(customer.getCustomerId()); + this.setCustomerLocked(customer.getCustomerLocked()); + this.setCustomerNumber(customer.getCustomerNumber()); + } + + @Override + public boolean equals (final Object object) { + if (this == object) { + return true; + } else if (null == object) { + return false; + } else if (this.getClass() != object.getClass()) { + return false; + } + + final Customer other = (Customer) object; + + if (!Objects.equals(this.getCustomerNumber(), other.getCustomerNumber())) { + return false; + } else if (!Objects.equals(this.getCustomerContact(), other.getCustomerContact())) { + return false; + } else if (!Objects.equals(this.getCustomerId(), other.getCustomerId())) { + return false; + } + + return true; + } + + @Override + public int hashCode () { + int hash = 7; + + hash = 53 * hash + Objects.hashCode(this.getCustomerContact()); + hash = 53 * hash + Objects.hashCode(this.getCustomerId()); + hash = 53 * hash + Objects.hashCode(this.getCustomerNumber()); + + return hash; + } + + @Override + public CustomerAccountStatus getCustomerAccountStatus () { + return this.customerAccountStatus; + } + + @Override + public void setCustomerAccountStatus (final CustomerAccountStatus customerStatus) { + this.customerAccountStatus = customerStatus; + } + + @Override + public String getCustomerConfirmKey () { + throw new UnsupportedOperationException("Not supported yet."); //NOI18N + } + + @Override + public void setCustomerConfirmKey (final String customerConfirmKey) { + throw new UnsupportedOperationException("Not supported yet."); //NOI18N + } + + @Override + public Contact getCustomerContact () { + return this.customerContact; + } + + @Override + public void setCustomerContact (final Contact customerContact) { + this.customerContact = customerContact; + } + + @Override + public Calendar getCustomerCreated () { + return this.customerCreated; + } + + @Override + public void setCustomerCreated (final Calendar customerCreated) { + this.customerCreated = customerCreated; + } + + @Override + public Long getCustomerId () { + return this.customerId; + } + + @Override + public void setCustomerId (final Long customerId) { + this.customerId = customerId; + } + + @Override + public Calendar getCustomerLocked () { + return this.customerLocked; + } + + @Override + public void setCustomerLocked (final Calendar customerLocked) { + this.customerLocked = customerLocked; + } + + @Override + public String getCustomerNumber () { + return this.customerNumber; + } + + @Override + public void setCustomerNumber (final String customerNumber) { + this.customerNumber = customerNumber; + } + + @Override + public String getCustomerPasswordHash () { + throw new UnsupportedOperationException("Unfinished"); //NOI18N + } + + @Override + public void setCustomerPasswordHash (final String customerPasswordHash) { + throw new UnsupportedOperationException("Unfinished"); //NOI18N + } + +}