From 9456d01890f421b44d6f776c8230a43dc9b7e787 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 4 Sep 2017 00:54:42 +0200 Subject: [PATCH] Continued: - renamed branchCompanyContact -> branchCompany - added new entity field/property "branchContactEmployee", an employee may act as a contact person in this branch office - added first named query for branch office entity: "AllBranchOffices" - renamed package "branch" -> "branchoffice" - added event for when an administrator has added basic company data MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../basicdata/BusinessBasicData.java | 24 +-- .../basicdata/CompanyBasicData.java | 201 ++++++++++-------- .../BranchOffice.java | 25 ++- .../CompanyBranchOffice.java | 36 +++- .../department/CompanyDepartment.java | 16 +- .../department/Department.java | 8 +- .../employee/CompanyEmployee.java | 24 ++- .../jcontactsbusiness/employee/Employee.java | 8 +- .../AdminAddedBusinessBasicDataEvent.java | 73 +++++++ ...vableAdminAddedBusinessBasicDataEvent.java | 37 ++++ .../BusinessDataAlreadyAddedException.java | 4 +- .../CompanyEmployeeNotFoundException.java | 2 +- .../CompanyHeadquartersNotFoundException.java | 65 ++++++ ...Data.java => CompanyHeadquartersData.java} | 4 +- ...uartersData.java => HeadquartersData.java} | 2 +- 15 files changed, 388 insertions(+), 141 deletions(-) rename src/org/mxchange/jcontactsbusiness/{branch => branchoffice}/BranchOffice.java (90%) rename src/org/mxchange/jcontactsbusiness/{branch => branchoffice}/CompanyBranchOffice.java (89%) create mode 100644 src/org/mxchange/jcontactsbusiness/events/basicdata/added/AdminAddedBusinessBasicDataEvent.java create mode 100644 src/org/mxchange/jcontactsbusiness/events/basicdata/added/ObservableAdminAddedBusinessBasicDataEvent.java create mode 100644 src/org/mxchange/jcontactsbusiness/exceptions/headquarters/CompanyHeadquartersNotFoundException.java rename src/org/mxchange/jcontactsbusiness/headquarters/{CompanyHeadQuartersData.java => CompanyHeadquartersData.java} (98%) rename src/org/mxchange/jcontactsbusiness/headquarters/{HeadQuartersData.java => HeadquartersData.java} (98%) diff --git a/src/org/mxchange/jcontactsbusiness/basicdata/BusinessBasicData.java b/src/org/mxchange/jcontactsbusiness/basicdata/BusinessBasicData.java index 399b178..0314b60 100644 --- a/src/org/mxchange/jcontactsbusiness/basicdata/BusinessBasicData.java +++ b/src/org/mxchange/jcontactsbusiness/basicdata/BusinessBasicData.java @@ -19,9 +19,9 @@ package org.mxchange.jcontactsbusiness.basicdata; import java.io.Serializable; import java.util.Calendar; import java.util.List; -import org.mxchange.jcontactsbusiness.branch.BranchOffice; +import org.mxchange.jcontactsbusiness.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.employee.Employee; -import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData; +import org.mxchange.jcontactsbusiness.headquarters.HeadquartersData; import org.mxchange.jcontactsbusiness.logo.BusinessLogo; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; @@ -67,14 +67,14 @@ public interface BusinessBasicData extends Serializable { *

* @return Business contact id */ - Long getBusinessDataId (); + Long getCompanyDataId (); /** * Setter for business contact id *

* @param businessContactId Business contact id */ - void setBusinessDataId (final Long businessContactId); + void setCompanyDataId (final Long businessContactId); /** * Getter for company founder @@ -95,42 +95,42 @@ public interface BusinessBasicData extends Serializable { *

* @return Headquarters data */ - HeadQuartersData getCompanyHeadQuartersData (); + HeadquartersData getCompanyHeadQuartersData (); /** * Setter for headquarters data *

* @param headQuartersData Headquarters data */ - void setCompanyHeadQuartersData (final HeadQuartersData headQuartersData); + void setCompanyHeadQuartersData (final HeadquartersData headQuartersData); /** * Getter for user owner instance *

* @return User owner instance */ - User getContactCompanyUserOwner (); + User getCompanyUserOwner (); /** * Setter for user owner instance *

* @param contactUserOwner User owner instance */ - void setContactCompanyUserOwner (final User contactUserOwner); + void setCompanyUserOwner (final User contactUserOwner); /** * Getter for timestamp when this entry has been created *

* @return Timestamp when this entry has been created */ - Calendar getContactCreated (); + Calendar getCompanyCreated (); /** * Setter for timestamp when this entry has been created *

* @param contactCreated Timestamp when this entry has been created */ - void setContactCreated (final Calendar contactCreated); + void setCompanyCreated (final Calendar contactCreated); /** * Getter for comments @@ -207,14 +207,14 @@ public interface BusinessBasicData extends Serializable { *

* @return Phone numbers */ - DialableLandLineNumber getCompanyPhoneNumber (); + DialableLandLineNumber getCompanyLandLineNumber (); /** * Setter for list of phone number *

* @param companyPhoneNumber Phone numbers */ - void setCompanyPhoneNumber (final DialableLandLineNumber companyPhoneNumber); + void setCompanyLandLineNumber (final DialableLandLineNumber companyPhoneNumber); /** * Getter for tax number diff --git a/src/org/mxchange/jcontactsbusiness/basicdata/CompanyBasicData.java b/src/org/mxchange/jcontactsbusiness/basicdata/CompanyBasicData.java index a5ebc01..171abd2 100644 --- a/src/org/mxchange/jcontactsbusiness/basicdata/CompanyBasicData.java +++ b/src/org/mxchange/jcontactsbusiness/basicdata/CompanyBasicData.java @@ -35,11 +35,11 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; -import org.mxchange.jcontactsbusiness.branch.BranchOffice; +import org.mxchange.jcontactsbusiness.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.employee.CompanyEmployee; import org.mxchange.jcontactsbusiness.employee.Employee; -import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadQuartersData; -import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData; +import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadquartersData; +import org.mxchange.jcontactsbusiness.headquarters.HeadquartersData; import org.mxchange.jcontactsbusiness.logo.BusinessLogo; import org.mxchange.jcontactsbusiness.logo.CompanyLogo; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; @@ -58,8 +58,8 @@ import org.mxchange.jusercore.model.user.User; @Table (name = "company_basic_data") @NamedQueries ( { - @NamedQuery (name = "AllBusinessData", query = "SELECT b FROM company_basic_data AS b ORDER BY b.businessDataId"), - @NamedQuery (name = "SearchBusinessDataById", query = "SELECT b FROM company_basic_data AS b WHERE b.businessDataId = :businessDataId") + @NamedQuery (name = "AllBusinessData", query = "SELECT b FROM company_basic_data AS b ORDER BY b.companyDataId"), + @NamedQuery (name = "SearchBusinessDataById", query = "SELECT b FROM company_basic_data AS b WHERE b.companyDataId = :companyDataId") } ) @SuppressWarnings ("PersistenceUnitPresent") @@ -77,14 +77,6 @@ public class CompanyBasicData implements BusinessBasicData { @Transient private List brancheOffices; - /** - * Id number - */ - @Id - @Column (name = "business_data_id", nullable = false, updatable = false) - @GeneratedValue (strategy = GenerationType.IDENTITY) - private Long businessDataId; - /** * Comments (any) */ @@ -99,6 +91,22 @@ public class CompanyBasicData implements BusinessBasicData { @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL) private Employee companyContactEmployee; + /** + * Timestamp when this entry has been created + */ + @Basic (optional = false) + @Temporal (TemporalType.TIMESTAMP) + @Column (name = "company_entry_created", nullable = false, updatable = false) + private Calendar companyCreated; + + /** + * Id number + */ + @Id + @Column (name = "company_data_id", nullable = false, updatable = false) + @GeneratedValue (strategy = GenerationType.IDENTITY) + private Long companyDataId; + /** * Company's main email address (example: info@company.com) */ @@ -119,6 +127,20 @@ public class CompanyBasicData implements BusinessBasicData { @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL) private Employee companyFounder; + /** + * Reference to headquarters data + */ + @JoinColumn (name = "company_headquarters_data_id") + @OneToOne (targetEntity = CompanyHeadquartersData.class, cascade = CascadeType.ALL) + private HeadquartersData companyHeadQuartersData; + + /** + * Company's main phone number: +ccxxxxxxxxxx + */ + @JoinColumn (name = "company_landline_number_id") + @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL) + private DialableLandLineNumber companyLandLineNumber; + /** * Id number of company logo */ @@ -130,22 +152,22 @@ public class CompanyBasicData implements BusinessBasicData { * Company name */ @Basic (optional = false) - @Column (name = "company_name", length = 100, nullable = false) + @Column (name = "company_name", length = 100, nullable = false, unique = true) private String companyName; - /** - * Company's main phone number: +ccxxxxxxxxxx - */ - @JoinColumn (name = "company_phone_number_id") - @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL) - private DialableLandLineNumber companyPhoneNumber; - /** * Tax number */ @Column (name = "company_tax_number", length = 30) private String companyTaxNumber; + /** + * User owner instance + */ + @JoinColumn (name = "company_owner_user_id") + @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH) + private User companyUserOwner; + /** * URL for company website */ @@ -153,26 +175,29 @@ public class CompanyBasicData implements BusinessBasicData { private String companyWebsiteUrl; /** - * User owner instance + * Default constructor, required for JPA */ - @JoinColumn (name = "company_owner_user_id") - @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH) - private User contactCompanyUserOwner; + public CompanyBasicData () { + } /** - * Timestamp when this entry has been created + * Constructor with company name + *

+ * @param companyName Company name */ - @Basic (optional = false) - @Temporal (TemporalType.TIMESTAMP) - @Column (name = "company_entry_created", nullable = false, updatable = false) - private Calendar contactCreated; + public CompanyBasicData (final String companyName) { + // First, validate all parameter + if (companyName == null) { + // Is null + throw new NullPointerException("companyName is null"); //NOI18N + } else if (companyName.isEmpty()) { + // Is null + throw new IllegalArgumentException("companyName is empty"); //NOI18N + } - /** - * Reference to headquarters data - */ - @JoinColumn (name = "company_headquarters_data_id") - @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL) - private HeadQuartersData companyHeadQuartersData; + // Set company name + this.companyName = companyName; + } @Override public boolean equals (final Object object) { @@ -184,7 +209,7 @@ public class CompanyBasicData implements BusinessBasicData { final BusinessBasicData other = (BusinessBasicData) object; - if (!Objects.equals(this.getBusinessDataId(), other.getBusinessDataId())) { + if (!Objects.equals(this.getCompanyDataId(), other.getCompanyDataId())) { return false; } else if (!Objects.equals(this.getCompanyName(), other.getCompanyName())) { return false; @@ -211,16 +236,6 @@ public class CompanyBasicData implements BusinessBasicData { this.brancheOffices = brancheOffices; } - @Override - public Long getBusinessDataId () { - return this.businessDataId; - } - - @Override - public void setBusinessDataId (final Long businessDataId) { - this.businessDataId = businessDataId; - } - @Override public String getCompanyComments () { return this.companyComments; @@ -241,6 +256,28 @@ public class CompanyBasicData implements BusinessBasicData { this.companyContactEmployee = companyContactEmployee; } + @Override + @SuppressWarnings ("ReturnOfDateField") + public Calendar getCompanyCreated () { + return this.companyCreated; + } + + @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setCompanyCreated (final Calendar companyCreated) { + this.companyCreated = companyCreated; + } + + @Override + public Long getCompanyDataId () { + return this.companyDataId; + } + + @Override + public void setCompanyDataId (final Long companyDataId) { + this.companyDataId = companyDataId; + } + @Override public String getCompanyEmailAddress () { return this.companyEmailAddress; @@ -272,92 +309,80 @@ public class CompanyBasicData implements BusinessBasicData { } @Override - public BusinessLogo getCompanyLogo () { - return this.companyLogo; - } - - @Override - public void setCompanyLogo (final BusinessLogo companyLogoId) { - this.companyLogo = companyLogoId; - } - - @Override - public String getCompanyName () { - return this.companyName; + public HeadquartersData getCompanyHeadQuartersData () { + return this.companyHeadQuartersData; } @Override - public void setCompanyName (final String companyName) { - this.companyName = companyName; + public void setCompanyHeadQuartersData (final HeadquartersData companyHeadQuartersData) { + this.companyHeadQuartersData = companyHeadQuartersData; } @Override - public DialableLandLineNumber getCompanyPhoneNumber () { - return this.companyPhoneNumber; + public DialableLandLineNumber getCompanyLandLineNumber () { + return this.companyLandLineNumber; } @Override - public void setCompanyPhoneNumber (final DialableLandLineNumber companyPhoneNumber) { - this.companyPhoneNumber = companyPhoneNumber; + public void setCompanyLandLineNumber (final DialableLandLineNumber companyLandLineNumber) { + this.companyLandLineNumber = companyLandLineNumber; } @Override - public String getCompanyTaxNumber () { - return this.companyTaxNumber; + public BusinessLogo getCompanyLogo () { + return this.companyLogo; } @Override - public void setCompanyTaxNumber (final String companyTaxNumber) { - this.companyTaxNumber = companyTaxNumber; + public void setCompanyLogo (final BusinessLogo companyLogoId) { + this.companyLogo = companyLogoId; } @Override - public String getCompanyWebsiteUrl () { - return this.companyWebsiteUrl; + public String getCompanyName () { + return this.companyName; } @Override - public void setCompanyWebsiteUrl (final String companyWebsiteUrl) { - this.companyWebsiteUrl = companyWebsiteUrl; + public void setCompanyName (final String companyName) { + this.companyName = companyName; } @Override - public User getContactCompanyUserOwner () { - return this.contactCompanyUserOwner; + public String getCompanyTaxNumber () { + return this.companyTaxNumber; } @Override - public void setContactCompanyUserOwner (final User contactCompanyUserOwner) { - this.contactCompanyUserOwner = contactCompanyUserOwner; + public void setCompanyTaxNumber (final String companyTaxNumber) { + this.companyTaxNumber = companyTaxNumber; } @Override - @SuppressWarnings ("ReturnOfDateField") - public Calendar getContactCreated () { - return this.contactCreated; + public User getCompanyUserOwner () { + return this.companyUserOwner; } @Override - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setContactCreated (final Calendar contactCreated) { - this.contactCreated = contactCreated; + public void setCompanyUserOwner (final User companyUserOwner) { + this.companyUserOwner = companyUserOwner; } @Override - public HeadQuartersData getCompanyHeadQuartersData () { - return this.companyHeadQuartersData; + public String getCompanyWebsiteUrl () { + return this.companyWebsiteUrl; } @Override - public void setCompanyHeadQuartersData (final HeadQuartersData companyHeadQuartersData) { - this.companyHeadQuartersData = companyHeadQuartersData; + public void setCompanyWebsiteUrl (final String companyWebsiteUrl) { + this.companyWebsiteUrl = companyWebsiteUrl; } @Override public int hashCode () { int hash = 3; - hash = 37 * hash + Objects.hashCode(this.getBusinessDataId()); + hash = 37 * hash + Objects.hashCode(this.getCompanyDataId()); hash = 37 * hash + Objects.hashCode(this.getCompanyName()); hash = 37 * hash + Objects.hashCode(this.getCompanyHeadQuartersData()); hash = 37 * hash + Objects.hashCode(this.getCompanyContactEmployee()); diff --git a/src/org/mxchange/jcontactsbusiness/branch/BranchOffice.java b/src/org/mxchange/jcontactsbusiness/branchoffice/BranchOffice.java similarity index 90% rename from src/org/mxchange/jcontactsbusiness/branch/BranchOffice.java rename to src/org/mxchange/jcontactsbusiness/branchoffice/BranchOffice.java index be2c01f..5690040 100644 --- a/src/org/mxchange/jcontactsbusiness/branch/BranchOffice.java +++ b/src/org/mxchange/jcontactsbusiness/branchoffice/BranchOffice.java @@ -14,15 +14,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mxchange.jcontactsbusiness.branch; +package org.mxchange.jcontactsbusiness.branchoffice; import java.io.Serializable; import java.util.Calendar; +import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData; +import org.mxchange.jcontactsbusiness.employee.Employee; import org.mxchange.jcountry.data.Country; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jusercore.model.user.User; -import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData; /** * A POJI for branch offices @@ -190,14 +191,28 @@ public interface BranchOffice extends Serializable { *

* @return Branch office's company */ - BusinessBasicData getBranchCompanyContact (); + BusinessBasicData getBranchCompany (); /** * Setter for branch office's company *

- * @param branchCompanyContact Branch office's company + * @param branchCompany Branch office's company + */ + void setBranchCompany (final BusinessBasicData branchCompany); + + /** + * Getter branch office's contact person + *

+ * @return Branch office's contact person + */ + Employee getBranchContactEmployee (); + + /** + * Setter branch office's contact person + *

+ * @param branchEmployee Branch office's contact person */ - void setBranchCompanyContact (final BusinessBasicData branchCompanyContact); + void setBranchContactEmployee (final Employee branchEmployee); /** * Getter for user owner instance diff --git a/src/org/mxchange/jcontactsbusiness/branch/CompanyBranchOffice.java b/src/org/mxchange/jcontactsbusiness/branchoffice/CompanyBranchOffice.java similarity index 89% rename from src/org/mxchange/jcontactsbusiness/branch/CompanyBranchOffice.java rename to src/org/mxchange/jcontactsbusiness/branchoffice/CompanyBranchOffice.java index 4446eb2..691b699 100644 --- a/src/org/mxchange/jcontactsbusiness/branch/CompanyBranchOffice.java +++ b/src/org/mxchange/jcontactsbusiness/branchoffice/CompanyBranchOffice.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mxchange.jcontactsbusiness.branch; +package org.mxchange.jcontactsbusiness.branchoffice; import java.util.Calendar; import java.util.Objects; @@ -26,6 +26,8 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Temporal; @@ -33,6 +35,8 @@ import javax.persistence.TemporalType; import javax.persistence.Transient; import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.basicdata.CompanyBasicData; +import org.mxchange.jcontactsbusiness.employee.CompanyEmployee; +import org.mxchange.jcontactsbusiness.employee.Employee; import org.mxchange.jcountry.data.Country; import org.mxchange.jcountry.data.CountryData; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; @@ -49,6 +53,9 @@ import org.mxchange.jusercore.model.user.User; */ @Entity (name = "company_branch_offices") @Table (name = "company_branch_offices") +@NamedQueries ({ + @NamedQuery (name = "AllBranchOffices", query = "SELECT bo FROM company_branch_offices AS bo ORDER BY bo.branchId ASC") +}) @SuppressWarnings ("PersistenceUnitPresent") public class CompanyBranchOffice implements BranchOffice { @@ -70,7 +77,7 @@ public class CompanyBranchOffice implements BranchOffice { */ @JoinColumn (name = "branch_company_id", nullable = false, updatable = false) @OneToOne (targetEntity = CompanyBasicData.class, optional = false, cascade = CascadeType.ALL) - private BusinessBasicData branchCompanyContact; + private BusinessBasicData branchCompany; /** * Branch office's country code @@ -93,6 +100,13 @@ public class CompanyBranchOffice implements BranchOffice { @Column (name = "branch_email_address", length = 100) private String branchEmailAddress; + /** + * Reference to contact person + */ + @JoinColumn (name = "branch_contact_employee_id") + @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL) + private Employee branchContactEmployee; + /** * Branch office's main fax number: +ccxxxxxxxxxx */ @@ -197,13 +211,13 @@ public class CompanyBranchOffice implements BranchOffice { } @Override - public BusinessBasicData getBranchCompanyContact () { - return this.branchCompanyContact; + public BusinessBasicData getBranchCompany () { + return this.branchCompany; } @Override - public void setBranchCompanyContact (final BusinessBasicData branchCompanyContact) { - this.branchCompanyContact = branchCompanyContact; + public void setBranchCompany (final BusinessBasicData branchCompany) { + this.branchCompany = branchCompany; } @Override @@ -238,6 +252,16 @@ public class CompanyBranchOffice implements BranchOffice { this.branchEmailAddress = branchEmailAddress; } + @Override + public Employee getBranchContactEmployee () { + return this.branchContactEmployee; + } + + @Override + public void setBranchContactEmployee (final Employee branchContactEmployee) { + this.branchContactEmployee = branchContactEmployee; + } + @Override public DialableFaxNumber getBranchFaxNumber () { return this.branchFaxNumber; diff --git a/src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java b/src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java index 3e74a6e..e49a2ce 100644 --- a/src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java +++ b/src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java @@ -33,15 +33,15 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; import org.mxchange.jcontactsbusiness.basicdata.CompanyBasicData; -import org.mxchange.jcontactsbusiness.branch.BranchOffice; -import org.mxchange.jcontactsbusiness.branch.CompanyBranchOffice; +import org.mxchange.jcontactsbusiness.branchoffice.BranchOffice; +import org.mxchange.jcontactsbusiness.branchoffice.CompanyBranchOffice; import org.mxchange.jcontactsbusiness.employee.CompanyEmployee; import org.mxchange.jcontactsbusiness.employee.Employee; -import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadQuartersData; -import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData; +import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadquartersData; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData; +import org.mxchange.jcontactsbusiness.headquarters.HeadquartersData; /** * A POJO for company departments @@ -63,8 +63,8 @@ public class CompanyDepartment implements Department { * Where this department is located */ @JoinColumn (name = "department_headquarters_id") - @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL) - private HeadQuartersData departentHeadquarters; + @OneToOne (targetEntity = CompanyHeadquartersData.class, cascade = CascadeType.ALL) + private HeadquartersData departentHeadquarters; /** * Where this department is located @@ -139,12 +139,12 @@ public class CompanyDepartment implements Department { } @Override - public HeadQuartersData getDepartentHeadquarters () { + public HeadquartersData getDepartentHeadquarters () { return this.departentHeadquarters; } @Override - public void setDepartentHeadquarters (final HeadQuartersData departentHeadquarters) { + public void setDepartentHeadquarters (final HeadquartersData departentHeadquarters) { this.departentHeadquarters = departentHeadquarters; } diff --git a/src/org/mxchange/jcontactsbusiness/department/Department.java b/src/org/mxchange/jcontactsbusiness/department/Department.java index 1615f98..433b1f4 100644 --- a/src/org/mxchange/jcontactsbusiness/department/Department.java +++ b/src/org/mxchange/jcontactsbusiness/department/Department.java @@ -18,11 +18,11 @@ package org.mxchange.jcontactsbusiness.department; import java.io.Serializable; import java.util.Calendar; -import org.mxchange.jcontactsbusiness.branch.BranchOffice; +import org.mxchange.jcontactsbusiness.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.employee.Employee; -import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData; import org.mxchange.jusercore.model.user.User; import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData; +import org.mxchange.jcontactsbusiness.headquarters.HeadquartersData; /** * A POJI for company departments @@ -50,14 +50,14 @@ public interface Department extends Serializable { *

* @return Connection to company headquarters */ - HeadQuartersData getDepartentHeadquarters (); + HeadquartersData getDepartentHeadquarters (); /** * Setter for connection to company headquarters *

* @param departentHeadquarters Connection to company headquarters */ - void setDepartentHeadquarters (final HeadQuartersData departentHeadquarters); + void setDepartentHeadquarters (final HeadquartersData departentHeadquarters); /** * Getter for connection to company branch office diff --git a/src/org/mxchange/jcontactsbusiness/employee/CompanyEmployee.java b/src/org/mxchange/jcontactsbusiness/employee/CompanyEmployee.java index e702921..0e8fe24 100644 --- a/src/org/mxchange/jcontactsbusiness/employee/CompanyEmployee.java +++ b/src/org/mxchange/jcontactsbusiness/employee/CompanyEmployee.java @@ -26,6 +26,8 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Temporal; @@ -35,12 +37,12 @@ import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.contact.UserContact; import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.basicdata.CompanyBasicData; -import org.mxchange.jcontactsbusiness.branch.BranchOffice; -import org.mxchange.jcontactsbusiness.branch.CompanyBranchOffice; +import org.mxchange.jcontactsbusiness.branchoffice.BranchOffice; +import org.mxchange.jcontactsbusiness.branchoffice.CompanyBranchOffice; import org.mxchange.jcontactsbusiness.department.CompanyDepartment; import org.mxchange.jcontactsbusiness.department.Department; -import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadQuartersData; -import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData; +import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadquartersData; +import org.mxchange.jcontactsbusiness.headquarters.HeadquartersData; import org.mxchange.jcontactsbusiness.jobposition.EmployeePosition; import org.mxchange.jcontactsbusiness.jobposition.JobPosition; import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; @@ -55,6 +57,12 @@ import org.mxchange.jusercore.model.user.User; */ @Entity (name = "company_employees") @Table (name = "company_employees") +@NamedQueries ( + { + @NamedQuery (name = "AllCompanyEmployees", query = "SELECT e FROM company_employees AS e ORDER BY e.employeeId ASC"), + @NamedQuery (name = "SearchCompanyEmployeeById", query = "SELECT e FROM company_employees AS e WHERE e.employeeId = :employeeId") + } +) @SuppressWarnings ("PersistenceUnitPresent") public class CompanyEmployee implements Employee { @@ -103,8 +111,8 @@ public class CompanyEmployee implements Employee { * Head quarters id number (if the employee works there) */ @JoinColumn (name = "employee_headquarters_id") - @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL) - private HeadQuartersData employeeHeadquarter; + @OneToOne (targetEntity = CompanyHeadquartersData.class, cascade = CascadeType.ALL) + private HeadquartersData employeeHeadquarter; /** * Id number @@ -230,12 +238,12 @@ public class CompanyEmployee implements Employee { } @Override - public HeadQuartersData getEmployeeHeadquarter () { + public HeadquartersData getEmployeeHeadquarter () { return this.employeeHeadquarter; } @Override - public void setEmployeeHeadquarter (final HeadQuartersData employeeHeadquarter) { + public void setEmployeeHeadquarter (final HeadquartersData employeeHeadquarter) { this.employeeHeadquarter = employeeHeadquarter; } diff --git a/src/org/mxchange/jcontactsbusiness/employee/Employee.java b/src/org/mxchange/jcontactsbusiness/employee/Employee.java index 2bf18ec..5da72e1 100644 --- a/src/org/mxchange/jcontactsbusiness/employee/Employee.java +++ b/src/org/mxchange/jcontactsbusiness/employee/Employee.java @@ -20,12 +20,12 @@ import java.io.Serializable; import java.util.Calendar; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData; -import org.mxchange.jcontactsbusiness.branch.BranchOffice; +import org.mxchange.jcontactsbusiness.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.department.Department; -import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData; import org.mxchange.jcontactsbusiness.jobposition.JobPosition; import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jcontactsbusiness.headquarters.HeadquartersData; /** * A POJI for employees @@ -81,14 +81,14 @@ public interface Employee extends Serializable { *

* @return Employee's head quarters */ - HeadQuartersData getEmployeeHeadquarter (); + HeadquartersData getEmployeeHeadquarter (); /** * Getter for employee's head quarters *

* @param employeeHeadquarter Employee's head quarters */ - void setEmployeeHeadquarter (final HeadQuartersData employeeHeadquarter); + void setEmployeeHeadquarter (final HeadquartersData employeeHeadquarter); /** * Getter for employee's email address diff --git a/src/org/mxchange/jcontactsbusiness/events/basicdata/added/AdminAddedBusinessBasicDataEvent.java b/src/org/mxchange/jcontactsbusiness/events/basicdata/added/AdminAddedBusinessBasicDataEvent.java new file mode 100644 index 0000000..6726d65 --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/events/basicdata/added/AdminAddedBusinessBasicDataEvent.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * 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.jcontactsbusiness.events.basicdata.added; + +import java.text.MessageFormat; +import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData; + +/** + * An event being thrown when new basic business data has been added. + *

+ * @author Roland Häder + */ +public class AdminAddedBusinessBasicDataEvent implements ObservableAdminAddedBusinessBasicDataEvent { + + /** + * Serial number + */ + private static final long serialVersionUID = 41_908_266_873_657_271L; + + /** + * Basic data instance just being created. It must bear aside company name + * also a primary key. + */ + private final BusinessBasicData basicData; + + /** + * Constructor with basic data + *

+ * @param basicData Basic data with at least company name and primary key + */ + public AdminAddedBusinessBasicDataEvent (final BusinessBasicData basicData) { + // Is company name and primary key set? + if (null == basicData) { + // Throw NPE + throw new NullPointerException("basicData is null"); //NOI18N + } else if (basicData.getCompanyName() == null) { + // Throw NPE again + throw new NullPointerException("basicData.companyName is null"); //NOI18N + } else if (basicData.getCompanyName().isEmpty()) { + // Throw NPE again + throw new IllegalArgumentException("basicData.companyName is empty"); //NOI18N + } else if (basicData.getCompanyDataId() == null) { + // Throw NPE again + throw new NullPointerException("basicData.companyDataId is null"); //NOI18N + } else if (basicData.getCompanyDataId() < 1) { + // Throw NPE again + throw new IllegalArgumentException(MessageFormat.format("basicData.companyDataId={0} is not valid.", basicData.getCompanyDataId())); //NOI18N + } + + // Set it here + this.basicData = basicData; + } + + @Override + public BusinessBasicData getBasicData () { + return this.basicData; + } + +} diff --git a/src/org/mxchange/jcontactsbusiness/events/basicdata/added/ObservableAdminAddedBusinessBasicDataEvent.java b/src/org/mxchange/jcontactsbusiness/events/basicdata/added/ObservableAdminAddedBusinessBasicDataEvent.java new file mode 100644 index 0000000..9bec912 --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/events/basicdata/added/ObservableAdminAddedBusinessBasicDataEvent.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * 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.jcontactsbusiness.events.basicdata.added; + +import java.io.Serializable; +import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData; + +/** + * An interface for events being fired when new basic business data has been + * added. + *

+ * @author Roland Häder + */ +public interface ObservableAdminAddedBusinessBasicDataEvent extends Serializable { + + /** + * Getter for basic business data entity + *

+ * @return Basic business data entity + */ + BusinessBasicData getBasicData (); + +} diff --git a/src/org/mxchange/jcontactsbusiness/exceptions/basicdata/BusinessDataAlreadyAddedException.java b/src/org/mxchange/jcontactsbusiness/exceptions/basicdata/BusinessDataAlreadyAddedException.java index a60459c..4137059 100644 --- a/src/org/mxchange/jcontactsbusiness/exceptions/basicdata/BusinessDataAlreadyAddedException.java +++ b/src/org/mxchange/jcontactsbusiness/exceptions/basicdata/BusinessDataAlreadyAddedException.java @@ -37,14 +37,14 @@ public class BusinessDataAlreadyAddedException extends Exception { * @param businessContact Business contact that is already added */ public BusinessDataAlreadyAddedException (final BusinessBasicData businessContact) { - super(MessageFormat.format("Business contact with businessContactId={0} not found.", businessContact.getBusinessDataId())); //NOI18N + super(MessageFormat.format("Business contact with comanyName={0} already added.", businessContact.getCompanyName())); //NOI18N } /** * Default constructor, may be used if no contact instance is available */ public BusinessDataAlreadyAddedException () { - super("BusinessContact already added"); //NOI18N + super("Business contact already added"); //NOI18N } } diff --git a/src/org/mxchange/jcontactsbusiness/exceptions/employee/CompanyEmployeeNotFoundException.java b/src/org/mxchange/jcontactsbusiness/exceptions/employee/CompanyEmployeeNotFoundException.java index 40ac5a4..6e44956 100644 --- a/src/org/mxchange/jcontactsbusiness/exceptions/employee/CompanyEmployeeNotFoundException.java +++ b/src/org/mxchange/jcontactsbusiness/exceptions/employee/CompanyEmployeeNotFoundException.java @@ -19,7 +19,7 @@ package org.mxchange.jcontactsbusiness.exceptions.employee; import java.text.MessageFormat; /** - * An exception thrown when a contact (entity) has not found. + * An exception thrown when a company employee (entity) has not found. *

* @author Roland Häder */ diff --git a/src/org/mxchange/jcontactsbusiness/exceptions/headquarters/CompanyHeadquartersNotFoundException.java b/src/org/mxchange/jcontactsbusiness/exceptions/headquarters/CompanyHeadquartersNotFoundException.java new file mode 100644 index 0000000..ce1799c --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/exceptions/headquarters/CompanyHeadquartersNotFoundException.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * 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.jcontactsbusiness.exceptions.headquarters; + +import java.text.MessageFormat; + +/** + * An exception thrown when a headquarters (entity) has not found. + *

+ * @author Roland Häder + */ +public class CompanyHeadquartersNotFoundException extends Exception { + + /** + * Serial number + */ + private static final long serialVersionUID = 23_759_801_876_416_568L; + + /** + * Constructor with company headquarters id + *

+ * @param headquartersId Company headquarters id + */ + public CompanyHeadquartersNotFoundException (final Long headquartersId) { + // Call super constructor with message and cause + super(MessageFormat.format("Company headquarters with id {0} was not found.", headquartersId)); //NOI18N + } + + /** + * Constructor with company headquarters id and causing exception + *

+ * @param headquartersId Company headquarters id + * @param cause Causing exception + */ + public CompanyHeadquartersNotFoundException (final Long headquartersId, final Throwable cause) { + // Call super constructor with message and cause + super(MessageFormat.format("Company headquarters with id {0} was not found.", headquartersId), cause); //NOI18N + } + + /** + * Constructor with email address and causing exception + *

+ * @param emailAddress Email address + * @param cause Causing exception + */ + public CompanyHeadquartersNotFoundException (final String emailAddress, final Throwable cause) { + // Call super constructor with message and cause + super(MessageFormat.format("Company headquarters with email address {0} was not found.", emailAddress), cause); //NOI18N + } + +} diff --git a/src/org/mxchange/jcontactsbusiness/headquarters/CompanyHeadQuartersData.java b/src/org/mxchange/jcontactsbusiness/headquarters/CompanyHeadquartersData.java similarity index 98% rename from src/org/mxchange/jcontactsbusiness/headquarters/CompanyHeadQuartersData.java rename to src/org/mxchange/jcontactsbusiness/headquarters/CompanyHeadquartersData.java index 0349a23..0bafa1f 100644 --- a/src/org/mxchange/jcontactsbusiness/headquarters/CompanyHeadQuartersData.java +++ b/src/org/mxchange/jcontactsbusiness/headquarters/CompanyHeadquartersData.java @@ -48,7 +48,7 @@ import org.mxchange.jusercore.model.user.User; @Entity (name = "company_headquarters") @Table (name = "company_headquarters") @SuppressWarnings ("PersistenceUnitPresent") -public class CompanyHeadQuartersData implements HeadQuartersData { +public class CompanyHeadquartersData implements HeadquartersData { /** * Serial number @@ -148,7 +148,7 @@ public class CompanyHeadQuartersData implements HeadQuartersData { return false; } - final HeadQuartersData other = (HeadQuartersData) object; + final HeadquartersData other = (HeadquartersData) object; if (!Objects.equals(this.getHeadquartersId(), other.getHeadquartersId())) { return false; diff --git a/src/org/mxchange/jcontactsbusiness/headquarters/HeadQuartersData.java b/src/org/mxchange/jcontactsbusiness/headquarters/HeadquartersData.java similarity index 98% rename from src/org/mxchange/jcontactsbusiness/headquarters/HeadQuartersData.java rename to src/org/mxchange/jcontactsbusiness/headquarters/HeadquartersData.java index 3ca4eaf..598fe3d 100644 --- a/src/org/mxchange/jcontactsbusiness/headquarters/HeadQuartersData.java +++ b/src/org/mxchange/jcontactsbusiness/headquarters/HeadquartersData.java @@ -28,7 +28,7 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -public interface HeadQuartersData extends Serializable { +public interface HeadquartersData extends Serializable { /** * Getter for headquarters' city name -- 2.39.5