* <p>
* @return Business contact id
*/
- Long getCompanyDataId ();
+ Long getBasicDataId ();
/**
* Setter for business contact id
* <p>
* @param businessContactId Business contact id
*/
- void setCompanyDataId (final Long businessContactId);
+ void setBasicDataId (final Long businessContactId);
/**
* Getter for company founder
@Table (name = "company_basic_data")
@NamedQueries (
{
- @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")
+ @NamedQuery (name = "AllBusinessData", query = "SELECT b FROM company_basic_data AS b ORDER BY b.basicDataId"),
+ @NamedQuery (name = "SearchBusinessDataById", query = "SELECT b FROM company_basic_data AS b WHERE b.basicDataId = :basicDataId")
}
)
@SuppressWarnings ("PersistenceUnitPresent")
@Transient
private static final long serialVersionUID = 470_375_172_748_691L;
+ /**
+ * Id number
+ */
+ @Id
+ @Column (name = "company_data_id", nullable = false, updatable = false)
+ @GeneratedValue (strategy = GenerationType.IDENTITY)
+ private Long basicDataId;
+
/**
* Reference to company branch offices
*/
@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)
*/
final BusinessBasicData other = (BusinessBasicData) object;
- if (!Objects.equals(this.getCompanyDataId(), other.getCompanyDataId())) {
+ if (!Objects.equals(this.getBasicDataId(), other.getBasicDataId())) {
return false;
} else if (!Objects.equals(this.getCompanyName(), other.getCompanyName())) {
return false;
return true;
}
+ @Override
+ public Long getBasicDataId () {
+ return this.basicDataId;
+ }
+
+ @Override
+ public void setBasicDataId (final Long basicDataId) {
+ this.basicDataId = basicDataId;
+ }
+
@Override
@SuppressWarnings ("ReturnOfCollectionOrArrayField")
public List<BranchOffice> getBrancheOffices () {
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;
public int hashCode () {
int hash = 3;
- hash = 37 * hash + Objects.hashCode(this.getCompanyDataId());
+ hash = 37 * hash + Objects.hashCode(this.getBasicDataId());
hash = 37 * hash + Objects.hashCode(this.getCompanyName());
hash = 37 * hash + Objects.hashCode(this.getCompanyHeadQuartersData());
hash = 37 * hash + Objects.hashCode(this.getCompanyContactEmployee());
* <p>
* @return Branch office's phone number
*/
- DialableLandLineNumber getBranchPhoneNumber ();
+ DialableLandLineNumber getBranchLandLineNumber ();
/**
* Setter for branch office's phone number
* <p>
* @param branchPhoneNumber Branch office's phone number
*/
- void setBranchPhoneNumber (final DialableLandLineNumber branchPhoneNumber);
+ void setBranchLandLineNumber (final DialableLandLineNumber branchPhoneNumber);
/**
* Getter for branch office's store
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.branchoffice;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * An utilities class for branch offices
+ *
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class BranchOfficeUtils implements Serializable {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 69_537_867_224_651L;
+
+ /**
+ * Checks if both branch offices have same address. This method will throw
+ * an {@code NullPointerException} if one of the instances is null.
+ * <p>
+ * @param branchOffice1 Branch office 1
+ * @param branchOffice2 Branch office 2
+ * <p>
+ * @return Whether both branch office addresses are the same
+ * <p>
+ * @throws NullPointerException If one of the instances is null
+ */
+ public static boolean isSameAddress (final BranchOffice branchOffice1, final BranchOffice branchOffice2) {
+ // Check that both parameters are not null
+ if (null == branchOffice1) {
+ // Throw NPE
+ throw new NullPointerException("branchOffice1 is null"); //NOI18N
+ } else if (null == branchOffice2) {
+ // Throw NPE
+ throw new NullPointerException("branchOffice2 is null"); //NOI18N
+ }
+
+ // Default is the same
+ boolean isSameAddress = true;
+
+ // Compare both addresses
+ if (!Objects.equals(branchOffice1.getBranchCompany(), branchOffice2.getBranchCompany())) {
+ // Not the same
+ isSameAddress = false;
+ } else if (!Objects.equals(branchOffice1.getBranchCountry(), branchOffice2.getBranchCountry())) {
+ // Not the same
+ isSameAddress = false;
+ } else if (!Objects.equals(branchOffice1.getBranchCity(), branchOffice2.getBranchCity())) {
+ // Not the same
+ isSameAddress = false;
+ } else if (!Objects.equals(branchOffice1.getBranchZipCode(), branchOffice2.getBranchZipCode())) {
+ // Not the same
+ isSameAddress = false;
+ } else if (!Objects.equals(branchOffice1.getBranchStreet(), branchOffice2.getBranchStreet())) {
+ // Not the same
+ isSameAddress = false;
+ } else if (!Objects.equals(branchOffice1.getBranchHouseNumber(), branchOffice2.getBranchHouseNumber())) {
+ // Not the same
+ isSameAddress = false;
+ } else if (!Objects.equals(branchOffice1.getBranchStore(), branchOffice2.getBranchStore())) {
+ // Not the same
+ isSameAddress = false;
+ } else if (!Objects.equals(branchOffice1.getBranchSuiteNumber(), branchOffice2.getBranchSuiteNumber())) {
+ // Not the same
+ isSameAddress = false;
+ }
+
+ // Return flag
+ return isSameAddress;
+ }
+
+ /**
+ * Private default constructor
+ */
+ private BranchOfficeUtils () {
+ // Utilities don't have instances
+ }
+
+}
*/
package org.mxchange.jcontactsbusiness.branchoffice;
+import java.text.MessageFormat;
import java.util.Calendar;
import java.util.Objects;
import javax.persistence.Basic;
* Company that has this branch office
*/
@JoinColumn (name = "branch_company_id", nullable = false, updatable = false)
- @OneToOne (targetEntity = CompanyBasicData.class, optional = false, cascade = CascadeType.ALL)
+ @OneToOne (targetEntity = CompanyBasicData.class, optional = false, cascade = CascadeType.REFRESH)
private BusinessBasicData branchCompany;
+ /**
+ * Reference to contact person
+ */
+ @JoinColumn (name = "branch_contact_employee_id")
+ @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.REFRESH)
+ private Employee branchContactEmployee;
+
/**
* Branch office's country code
*/
@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
*/
private Long branchId;
/**
- * Branch office's main phone number: +ccxxxxxxxxxx
+ * Branch office's main land-line number: +ccxxxxxxxxxx
*/
- @JoinColumn (name = "branch_phone_number_id")
+ @JoinColumn (name = "branch_landline_number_id")
@OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
- private DialableLandLineNumber branchPhoneNumber;
+ private DialableLandLineNumber branchLandLineNumber;
/**
* Branch office's store (if multiple-store building)
@Column (name = "branch_zip_code", length = 6, nullable = false)
private Integer branchZipCode;
+ /**
+ * Default constructor for JPA
+ */
+ public CompanyBranchOffice () {
+ }
+
+ /**
+ * Constructor with all required fields. This constructor may throw
+ * exceptions when one parameter is not valid or NULL.
+ * <p>
+ * @param branchCity Branch office's city
+ * @param branchCompany Branch office's assigned company
+ * @param branchCountry Branch office's country
+ * @param branchStreet Branch office's street
+ * @param branchZipCode Branch office's ZIP code
+ * @param branchHouseNumber Branch office's house number
+ */
+ public CompanyBranchOffice (final String branchCity, final BusinessBasicData branchCompany, final Country branchCountry, final String branchStreet, final Integer branchZipCode, final Short branchHouseNumber) {
+ // Call other constructor
+ this();
+
+ // Check all parameter
+ if (null == branchCity) {
+ // Throw NPE
+ throw new NullPointerException("branchCity is null"); //NOI18N
+ } else if (branchCity.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("branchCity is empty"); //NOI18N
+ } else if (null == branchCompany) {
+ // Throw NPE
+ throw new NullPointerException("branchCompany is null"); //NOI18N
+ } else if (branchCompany.getBasicDataId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("branchCompany.basicDataId is null"); //NOI18N
+ } else if (branchCompany.getBasicDataId() < 1) {
+ // Throw IAE again
+ throw new IllegalArgumentException(MessageFormat.format("branchCompany.basicDataId={0} is invalid", branchCompany.getBasicDataId())); //NOI18N
+ } else if (null == branchCountry) {
+ // Throw NPE again
+ throw new NullPointerException("branchCountry is null"); //NOI18N
+ } else if (branchCountry.getCountryId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("branchCountry.countryId is null"); //NOI18N
+ } else if (branchCountry.getCountryId() < 1) {
+ // Throw IAE again
+ throw new IllegalArgumentException(MessageFormat.format("branchCountry.countryId={0} is invalid", branchCountry.getCountryId())); //NOI18N
+ } else if (null == branchStreet) {
+ // Throw NPE
+ throw new NullPointerException("branchStreet is null"); //NOI18N
+ } else if (branchStreet.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("branchStreet is empty"); //NOI18N
+ } else if (null == branchZipCode) {
+ // Throw NPE
+ throw new NullPointerException("branchZipCode is null"); //NOI18N
+ } else if (branchZipCode < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("branchZipCode={0} is out of range.", branchZipCode)); //NOI18N
+ } else if (null == branchHouseNumber) {
+ // Throw NPE
+ throw new NullPointerException("branchHouseNumber is null"); //NOI18N
+ } else if (branchHouseNumber < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("branchHouseNumber={0} is out of range.", branchHouseNumber)); //NOI18N
+ }
+
+ // Set all fields
+ this.branchCity = branchCity;
+ this.branchCompany = branchCompany;
+ this.branchCountry = branchCountry;
+ this.branchStreet = branchStreet;
+ this.branchZipCode = branchZipCode;
+ this.branchHouseNumber = branchHouseNumber;
+ }
+
@Override
public boolean equals (final Object object) {
if (null == object) {
this.branchCompany = branchCompany;
}
+ @Override
+ public Employee getBranchContactEmployee () {
+ return this.branchContactEmployee;
+ }
+
+ @Override
+ public void setBranchContactEmployee (final Employee branchContactEmployee) {
+ this.branchContactEmployee = branchContactEmployee;
+ }
+
@Override
public Country getBranchCountry () {
return this.branchCountry;
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;
}
@Override
- public DialableLandLineNumber getBranchPhoneNumber () {
- return this.branchPhoneNumber;
+ public DialableLandLineNumber getBranchLandLineNumber () {
+ return this.branchLandLineNumber;
}
@Override
- public void setBranchPhoneNumber (final DialableLandLineNumber branchPhoneNumber) {
- this.branchPhoneNumber = branchPhoneNumber;
+ public void setBranchLandLineNumber (final DialableLandLineNumber branchLandLineNumber) {
+ this.branchLandLineNumber = branchLandLineNumber;
}
@Override
} else if (basicData.getCompanyName().isEmpty()) {
// Throw NPE again
throw new IllegalArgumentException("basicData.companyName is empty"); //NOI18N
- } else if (basicData.getCompanyDataId() == null) {
+ } else if (basicData.getBasicDataId() == null) {
// Throw NPE again
- throw new NullPointerException("basicData.companyDataId is null"); //NOI18N
- } else if (basicData.getCompanyDataId() < 1) {
+ throw new NullPointerException("basicData.basicDataId is null"); //NOI18N
+ } else if (basicData.getBasicDataId() < 1) {
// Throw NPE again
- throw new IllegalArgumentException(MessageFormat.format("basicData.companyDataId={0} is not valid.", basicData.getCompanyDataId())); //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is not valid.", basicData.getBasicDataId())); //NOI18N
}
// Set it here
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.events.branchoffice.added;
+
+import java.text.MessageFormat;
+import org.mxchange.jcontactsbusiness.branchoffice.BranchOffice;
+
+/**
+ * An event being fired when a branch office has been added
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class BranchOfficeAddedEvent implements ObservableBranchOfficeAddedEvent {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 572_367_561_659_109L;
+
+ /**
+ * Branch office instance being added
+ */
+ private final BranchOffice branchOffice;
+
+ /**
+ * Constructor with branch office instance
+ * <p>
+ * @param branchOffice Branch office instance
+ * @throws NullPointerException If the parameter is null
+ */
+ public BranchOfficeAddedEvent (final BranchOffice branchOffice) {
+ // Check parameter
+ if (null == branchOffice) {
+ // Throw NPE
+ throw new NullPointerException("branchOffice is null"); //NOI18N
+ } else if (branchOffice.getBranchId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("branchOffice.branchId is null"); //NOI18N
+ } else if (branchOffice.getBranchId() < 1) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("branchOffice.branchId={0} is not valid", branchOffice.getBranchId())); //NOI18N
+ }
+
+ // Set it
+ this.branchOffice = branchOffice;
+ }
+
+ @Override
+ public BranchOffice getBranchOffice () {
+ return this.branchOffice;
+ }
+
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.events.branchoffice.added;
+
+import java.io.Serializable;
+import org.mxchange.jcontactsbusiness.branchoffice.BranchOffice;
+
+/**
+ * An interface for events being triggered when a branch office has been added.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface ObservableBranchOfficeAddedEvent extends Serializable {
+
+ /**
+ * Getter for branch office instance
+ * <p>
+ * @return Branch office instance
+ */
+ BranchOffice getBranchOffice ();
+
+}
private static final long serialVersionUID = 75_844_851_467L;
/**
- * Constructor with a Contact instance
+ * Constructor with a basic data instance
* <p>
* @param businessContact Business contact that is already added
*/
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.exceptions.branchoffice;
+
+import java.text.MessageFormat;
+import org.mxchange.jcontactsbusiness.branchoffice.BranchOffice;
+
+/**
+ * Thrown if the given BusinessBasicData instance is already added
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class BranchOfficeAlreadyAddedException extends Exception {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 75_844_851_467L;
+
+ /**
+ * Constructor with a branch office instance
+ * <p>
+ * @param branchOffice Branch office that is already found
+ */
+ public BranchOfficeAlreadyAddedException (final BranchOffice branchOffice) {
+ super(MessageFormat.format("Branch office with branchStreet={0},branchHouseNumber={1},branchZipCode={2},branchCity={3} already created.", branchOffice.getBranchStreet(), branchOffice.getBranchHouseNumber(), branchOffice.getBranchZipCode(), branchOffice.getBranchCity()));
+ }
+
+ /**
+ * Default constructor, may be used if no contact instance is available
+ */
+ public BranchOfficeAlreadyAddedException () {
+ super("Branch office already added"); //NOI18N
+ }
+
+}