From 9bb398fd9f3417be93f7b590fb260bb02f570040 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 1 Nov 2017 21:21:18 +0100 Subject: [PATCH] Continued: - removed suffix Data, just Headquarters is okay here, not for basic data entity, of course - renamed exception, only company headquarters will exist - added checked exception which is being thrown when headquarters with same address already exists MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../HeadquartersAlreadyAddedException.java | 43 +++++++++++++++++++ ...ava => HeadquartersNotFoundException.java} | 8 ++-- .../model/basicdata/BasicData.java | 6 +-- .../model/basicdata/BusinessBasicData.java | 12 +++--- .../model/department/BusinessDepartment.java | 12 +++--- .../model/department/Department.java | 6 +-- .../model/employee/BusinessEmployee.java | 12 +++--- .../model/employee/Employable.java | 6 +-- ...ersData.java => BusinessHeadquarters.java} | 4 +- ...eadquartersData.java => Headquarters.java} | 2 +- 10 files changed, 77 insertions(+), 34 deletions(-) create mode 100644 src/org/mxchange/jcontactsbusiness/exceptions/headquarters/HeadquartersAlreadyAddedException.java rename src/org/mxchange/jcontactsbusiness/exceptions/headquarters/{CompanyHeadquartersNotFoundException.java => HeadquartersNotFoundException.java} (85%) rename src/org/mxchange/jcontactsbusiness/model/headquarters/{BusinessHeadquartersData.java => BusinessHeadquarters.java} (98%) rename src/org/mxchange/jcontactsbusiness/model/headquarters/{HeadquartersData.java => Headquarters.java} (99%) diff --git a/src/org/mxchange/jcontactsbusiness/exceptions/headquarters/HeadquartersAlreadyAddedException.java b/src/org/mxchange/jcontactsbusiness/exceptions/headquarters/HeadquartersAlreadyAddedException.java new file mode 100644 index 0000000..d92a414 --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/exceptions/headquarters/HeadquartersAlreadyAddedException.java @@ -0,0 +1,43 @@ +/* + * 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; +import org.mxchange.jcontactsbusiness.model.headquarters.Headquarters; + +/** + * An exception thrown when a headquarters (entity) was already added. + *

+ * @author Roland Häder + */ +public class HeadquartersAlreadyAddedException extends Exception { + + /** + * Serial number + */ + private static final long serialVersionUID = 23_759_801_876_416_573L; + + /** + * Constructor with a headquarters instance + *

+ * @param headquarters Headquarters that is already found + */ + public HeadquartersAlreadyAddedException (final Headquarters headquarters) { + super(MessageFormat.format("Headquarters office with headquartersStreet={0},headquartersHouseNumber={1},headquartersZipCode={2},headquartersCity={3} already created.", headquarters.getHeadquartersStreet(), headquarters.getHeadquartersHouseNumber(), headquarters.getHeadquartersZipCode(), headquarters.getHeadquartersCity())); + } + +} diff --git a/src/org/mxchange/jcontactsbusiness/exceptions/headquarters/CompanyHeadquartersNotFoundException.java b/src/org/mxchange/jcontactsbusiness/exceptions/headquarters/HeadquartersNotFoundException.java similarity index 85% rename from src/org/mxchange/jcontactsbusiness/exceptions/headquarters/CompanyHeadquartersNotFoundException.java rename to src/org/mxchange/jcontactsbusiness/exceptions/headquarters/HeadquartersNotFoundException.java index 738dd6e..514d1fa 100644 --- a/src/org/mxchange/jcontactsbusiness/exceptions/headquarters/CompanyHeadquartersNotFoundException.java +++ b/src/org/mxchange/jcontactsbusiness/exceptions/headquarters/HeadquartersNotFoundException.java @@ -23,7 +23,7 @@ import java.text.MessageFormat; *

* @author Roland Häder */ -public class CompanyHeadquartersNotFoundException extends Exception { +public class HeadquartersNotFoundException extends Exception { /** * Serial number @@ -35,7 +35,7 @@ public class CompanyHeadquartersNotFoundException extends Exception { *

* @param headquartersId Company headquarters id */ - public CompanyHeadquartersNotFoundException (final Long headquartersId) { + public HeadquartersNotFoundException (final Long headquartersId) { // Call super constructor with message and cause super(MessageFormat.format("Company headquarters with id {0} was not found.", headquartersId)); //NOI18N } @@ -46,7 +46,7 @@ public class CompanyHeadquartersNotFoundException extends Exception { * @param headquartersId Company headquarters id * @param cause Causing exception */ - public CompanyHeadquartersNotFoundException (final Long headquartersId, final Throwable cause) { + public HeadquartersNotFoundException (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 } @@ -57,7 +57,7 @@ public class CompanyHeadquartersNotFoundException extends Exception { * @param emailAddress Email address * @param cause Causing exception */ - public CompanyHeadquartersNotFoundException (final String emailAddress, final Throwable cause) { + public HeadquartersNotFoundException (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/model/basicdata/BasicData.java b/src/org/mxchange/jcontactsbusiness/model/basicdata/BasicData.java index 5bb5a5a..1a129dd 100644 --- a/src/org/mxchange/jcontactsbusiness/model/basicdata/BasicData.java +++ b/src/org/mxchange/jcontactsbusiness/model/basicdata/BasicData.java @@ -21,11 +21,11 @@ import java.util.Date; import java.util.List; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.model.employee.Employable; -import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jusercore.model.user.User; import org.mxchange.jcontactsbusiness.model.logo.Logo; +import org.mxchange.jcontactsbusiness.model.headquarters.Headquarters; /** * A POJI for business contact classes @@ -95,14 +95,14 @@ public interface BasicData extends Serializable { *

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

* @param headQuartersData Headquarters data */ - void setCompanyHeadQuartersData (final HeadquartersData headQuartersData); + void setCompanyHeadQuartersData (final Headquarters headQuartersData); /** * Getter for user owner instance diff --git a/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java b/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java index 0a12a28..5cf2bb1 100644 --- a/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java +++ b/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java @@ -38,8 +38,7 @@ import javax.persistence.Transient; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee; import org.mxchange.jcontactsbusiness.model.employee.Employable; -import org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquartersData; -import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData; +import org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquarters; import org.mxchange.jcontactsbusiness.model.logo.BusinessLogo; import org.mxchange.jcontactsbusiness.model.logo.Logo; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; @@ -48,6 +47,7 @@ import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jcontactsbusiness.model.headquarters.Headquarters; /** * A POJO for business basic data @@ -131,8 +131,8 @@ public class BusinessBasicData implements BasicData { * Reference to headquarters data */ @JoinColumn (name = "company_headquarters_data_id") - @OneToOne (targetEntity = BusinessHeadquartersData.class, cascade = CascadeType.ALL) - private HeadquartersData companyHeadQuartersData; + @OneToOne (targetEntity = BusinessHeadquarters.class, cascade = CascadeType.ALL) + private Headquarters companyHeadQuartersData; /** * Company's main phone number: +ccxxxxxxxxxx @@ -309,12 +309,12 @@ public class BusinessBasicData implements BasicData { } @Override - public HeadquartersData getCompanyHeadQuartersData () { + public Headquarters getCompanyHeadQuartersData () { return this.companyHeadQuartersData; } @Override - public void setCompanyHeadQuartersData (final HeadquartersData companyHeadQuartersData) { + public void setCompanyHeadQuartersData (final Headquarters companyHeadQuartersData) { this.companyHeadQuartersData = companyHeadQuartersData; } diff --git a/src/org/mxchange/jcontactsbusiness/model/department/BusinessDepartment.java b/src/org/mxchange/jcontactsbusiness/model/department/BusinessDepartment.java index cf1081b..582b922 100644 --- a/src/org/mxchange/jcontactsbusiness/model/department/BusinessDepartment.java +++ b/src/org/mxchange/jcontactsbusiness/model/department/BusinessDepartment.java @@ -38,12 +38,12 @@ import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice; import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee; -import org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquartersData; -import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData; +import org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquarters; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; +import org.mxchange.jcontactsbusiness.model.headquarters.Headquarters; /** * A POJO for company departments @@ -92,8 +92,8 @@ public class BusinessDepartment implements Department { * Where this department is located */ @JoinColumn (name = "department_headquarters_id") - @OneToOne (targetEntity = BusinessHeadquartersData.class, cascade = CascadeType.REFRESH) - private HeadquartersData departmentHeadquarters; + @OneToOne (targetEntity = BusinessHeadquarters.class, cascade = CascadeType.REFRESH) + private Headquarters departmentHeadquarters; /** * Department i18n key @@ -211,12 +211,12 @@ public class BusinessDepartment implements Department { } @Override - public HeadquartersData getDepartmentHeadquarters () { + public Headquarters getDepartmentHeadquarters () { return this.departmentHeadquarters; } @Override - public void setDepartmentHeadquarters (final HeadquartersData departmentHeadquarters) { + public void setDepartmentHeadquarters (final Headquarters departmentHeadquarters) { this.departmentHeadquarters = departmentHeadquarters; } diff --git a/src/org/mxchange/jcontactsbusiness/model/department/Department.java b/src/org/mxchange/jcontactsbusiness/model/department/Department.java index 7c75dcb..d349513 100644 --- a/src/org/mxchange/jcontactsbusiness/model/department/Department.java +++ b/src/org/mxchange/jcontactsbusiness/model/department/Department.java @@ -19,10 +19,10 @@ package org.mxchange.jcontactsbusiness.model.department; import java.io.Serializable; import java.util.Date; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData; import org.mxchange.jusercore.model.user.User; import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; +import org.mxchange.jcontactsbusiness.model.headquarters.Headquarters; /** * A POJI for company departments @@ -50,14 +50,14 @@ public interface Department extends Serializable { *

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

* @param departmentHeadquarters Connection to company headquarters */ - void setDepartmentHeadquarters (final HeadquartersData departmentHeadquarters); + void setDepartmentHeadquarters (final Headquarters departmentHeadquarters); /** * Getter for connection to company branch office diff --git a/src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java b/src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java index 21953d5..5fbcb64 100644 --- a/src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java +++ b/src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java @@ -40,8 +40,7 @@ import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice; import org.mxchange.jcontactsbusiness.model.department.BusinessDepartment; import org.mxchange.jcontactsbusiness.model.department.Department; -import org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquartersData; -import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData; +import org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquarters; import org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition; import org.mxchange.jcontactsbusiness.model.jobposition.JobPosition; import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; @@ -49,6 +48,7 @@ import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; +import org.mxchange.jcontactsbusiness.model.headquarters.Headquarters; /** * A POJO for company employees (including CEO) @@ -111,8 +111,8 @@ public class BusinessEmployee implements Employable { * Head quarters id number (if the employee works there) */ @JoinColumn (name = "employee_headquarters_id") - @OneToOne (targetEntity = BusinessHeadquartersData.class, cascade = CascadeType.REFRESH) - private HeadquartersData employeeHeadquarter; + @OneToOne (targetEntity = BusinessHeadquarters.class, cascade = CascadeType.REFRESH) + private Headquarters employeeHeadquarter; /** * Id number @@ -263,12 +263,12 @@ public class BusinessEmployee implements Employable { } @Override - public HeadquartersData getEmployeeHeadquarter () { + public Headquarters getEmployeeHeadquarter () { return this.employeeHeadquarter; } @Override - public void setEmployeeHeadquarter (final HeadquartersData employeeHeadquarter) { + public void setEmployeeHeadquarter (final Headquarters employeeHeadquarter) { this.employeeHeadquarter = employeeHeadquarter; } diff --git a/src/org/mxchange/jcontactsbusiness/model/employee/Employable.java b/src/org/mxchange/jcontactsbusiness/model/employee/Employable.java index d4eecde..c724c02 100644 --- a/src/org/mxchange/jcontactsbusiness/model/employee/Employable.java +++ b/src/org/mxchange/jcontactsbusiness/model/employee/Employable.java @@ -21,11 +21,11 @@ import java.util.Date; import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.model.department.Department; -import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData; import org.mxchange.jcontactsbusiness.model.jobposition.JobPosition; import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; import org.mxchange.jusercore.model.user.User; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; +import org.mxchange.jcontactsbusiness.model.headquarters.Headquarters; /** * A POJI for employees @@ -81,14 +81,14 @@ public interface Employable extends Serializable { *

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

* @param employeeHeadquarter Employable's head quarters */ - void setEmployeeHeadquarter (final HeadquartersData employeeHeadquarter); + void setEmployeeHeadquarter (final Headquarters employeeHeadquarter); /** * Getter for employee's email address diff --git a/src/org/mxchange/jcontactsbusiness/model/headquarters/BusinessHeadquartersData.java b/src/org/mxchange/jcontactsbusiness/model/headquarters/BusinessHeadquarters.java similarity index 98% rename from src/org/mxchange/jcontactsbusiness/model/headquarters/BusinessHeadquartersData.java rename to src/org/mxchange/jcontactsbusiness/model/headquarters/BusinessHeadquarters.java index 1ce6048..663ce23 100644 --- a/src/org/mxchange/jcontactsbusiness/model/headquarters/BusinessHeadquartersData.java +++ b/src/org/mxchange/jcontactsbusiness/model/headquarters/BusinessHeadquarters.java @@ -55,7 +55,7 @@ import org.mxchange.jusercore.model.user.User; @Entity (name = "company_headquarters") @Table (name = "company_headquarters") @SuppressWarnings ("PersistenceUnitPresent") -public class BusinessHeadquartersData implements HeadquartersData { +public class BusinessHeadquarters implements Headquarters { /** * Serial number @@ -169,7 +169,7 @@ public class BusinessHeadquartersData implements HeadquartersData { return false; } - final HeadquartersData other = (HeadquartersData) object; + final Headquarters other = (Headquarters) object; if (!Objects.equals(this.getHeadquartersId(), other.getHeadquartersId())) { return false; diff --git a/src/org/mxchange/jcontactsbusiness/model/headquarters/HeadquartersData.java b/src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarters.java similarity index 99% rename from src/org/mxchange/jcontactsbusiness/model/headquarters/HeadquartersData.java rename to src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarters.java index 42fecef..6e14f3d 100644 --- a/src/org/mxchange/jcontactsbusiness/model/headquarters/HeadquartersData.java +++ b/src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarters.java @@ -31,7 +31,7 @@ import org.mxchange.jusercore.model.user.User; *

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