<class>org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice</class>
<class>org.mxchange.jcontactsbusiness.model.department.BusinessDepartment</class>
<class>org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee</class>
- <class>org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquartersData</class>
+ <class>org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquarters</class>
<class>org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition</class>
<class>org.mxchange.jcontactsbusiness.model.logo.BusinessLogo</class>
<class>org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime</class>
import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jcontacts.model.contact.ContactUtils;
import org.mxchange.jcontacts.model.contact.UserContact;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
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.employee.Employable;
+import org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquarters;
+import org.mxchange.jcontactsbusiness.model.headquarters.Headquarter;
import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
import org.mxchange.jcoreee.database.BaseDatabaseBean;
import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jusercore.model.user.LoginUser;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.UserUtils;
-import org.mxchange.jcontactsbusiness.model.employee.Employable;
-import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
/**
* A helper class for beans that access the database.
/**
* Get back a managed instance from given branch office
* <p>
- * @param branchOffice Unmanaged/detached branch office instance
+ * @param headquarter Unmanaged/detached branch office instance
* <p>
* @return Managed basic data instance
*/
- protected BranchOffice createManaged (final BranchOffice branchOffice) {
+ protected BranchOffice createManaged (final BranchOffice headquarter) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N
// user should not be null
- if (null == branchOffice) {
+ if (null == headquarter) {
// Abort here
- throw new NullPointerException("branchOffice is null"); //NOI18N
- } else if (branchOffice.getBranchId() == null) {
+ throw new NullPointerException("headquarter is null"); //NOI18N
+ } else if (headquarter.getBranchId() == null) {
// Id is set
- throw new NullPointerException("branchOffice.branchOfficeId is null"); //NOI18N
- } else if (branchOffice.getBranchId() < 1) {
+ throw new NullPointerException("headquarter.headquarterId is null"); //NOI18N
+ } else if (headquarter.getBranchId() < 1) {
// Id is set
- throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchOfficeId={0} is invalid", branchOffice.getBranchId())); //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is invalid", headquarter.getBranchId())); //NOI18N
}
// Try to find it (should be there)
- final BranchOffice managedBranchOffice = this.getEntityManager().find(BusinessBranchOffice.class, branchOffice.getBranchId());
+ final BranchOffice managedBranchOffice = this.getEntityManager().find(BusinessBranchOffice.class, headquarter.getBranchId());
// Should be there
assert (managedBranchOffice instanceof BasicData) : "managedBranchOffice is null"; //NOI18N
* <p>
* @return Managed basic data instance
*/
- protected HeadquartersData createManaged (final HeadquartersData headquarters) {
+ protected Headquarter createManaged (final Headquarter headquarters) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: branchOffice={1} - CALLED!", this.getClass().getSimpleName(), headquarters)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarters)); //NOI18N
// user should not be null
if (null == headquarters) {
// Abort here
- throw new NullPointerException("branchOffice is null"); //NOI18N
+ throw new NullPointerException("headquarter is null"); //NOI18N
} else if (headquarters.getHeadquartersId() == null) {
// Id is set
- throw new NullPointerException("branchOffice.headquartersId is null"); //NOI18N
+ throw new NullPointerException("headquarter.headquartersId is null"); //NOI18N
} else if (headquarters.getHeadquartersId() < 1) {
// Id is set
- throw new IllegalArgumentException(MessageFormat.format("branchOffice.headquartersId={0} is invalid", headquarters.getHeadquartersId())); //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("headquarter.headquartersId={0} is invalid", headquarters.getHeadquartersId())); //NOI18N
}
// Try to find it (should be there)
- final HeadquartersData managedHeadquarters = this.getEntityManager().find(BusinessHeadquartersData.class, headquarters.getHeadquartersId());
+ final Headquarter managedHeadquarters = this.getEntityManager().find(BusinessHeadquarters.class, headquarters.getHeadquartersId());
// Should be there
assert (managedHeadquarters instanceof BasicData) : "managedHeadquarters is null"; //NOI18N
this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
}
+ /**
+ * Updates all branch office's phone entry's created timestamps
+ * <p>
+ * @param headquarter Headquarters instance to update
+ */
+ protected void setAllPhoneEntriesCreated (final Headquarter headquarter) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: headquarter={0} - CALLED!", headquarter)); //NOI18N
+
+ // The contact instance must be valid
+ if (null == headquarter) {
+ // Throw NPE again
+ throw new NullPointerException("headquarter is null"); //NOI18N
+ } else if (headquarter.getHeadquartersId() != null) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("headquarter.branchId={0} is unexpected.", headquarter.getHeadquartersId()));
+ }
+
+ // Get all phone instances
+ final DialableLandLineNumber landLineNumber = headquarter.getHeadquartersLandLineNumber();
+ final DialableFaxNumber faxNumber = headquarter.getHeadquartersFaxNumber();
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N
+
+ // Is a phone number instance set?
+ if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
+
+ // Set updated timestamp
+ landLineNumber.setPhoneEntryCreated(new Date());
+ }
+
+ // Is a fax number instance set?
+ if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug("setAllPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
+
+ // Set updated timestamp
+ faxNumber.setPhoneEntryCreated(new Date());
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("setAllPhoneEntriesCreated: EXIT!"); //NOI18N
+ }
+
/**
* Updates all company's phone entry's created timestamps
* <p>
import javax.ejb.Stateless;
import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentAlreadyAddedException;
import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
-import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
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.Headquarter;
/**
* A stateless session bean for administrative department purposes
}
// Is headquarters set?
- if (department.getDepartmentHeadquarters() instanceof HeadquartersData) {
+ if (department.getDepartmentHeadquarters() instanceof Headquarter) {
// Get managed headquarters
- final HeadquartersData managedHeadquarters = this.createManaged(department.getDepartmentHeadquarters());
+ final Headquarter managedHeadquarters = this.createManaged(department.getDepartmentHeadquarters());
// Set it back
department.setDepartmentHeadquarters(managedHeadquarters);
--- /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 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.headquarters;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.List;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import org.mxchange.jcontactsbusiness.exceptions.headquarters.HeadquartersAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A stateless session bean for administrative branch office purposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "adminHeadquarter", description = "An administrative statless bean for handling branch office data (all)")
+public class AddressbookAdminHeadquartersSessionBean extends BaseAddressbookDatabaseBean implements AdminHeadquartersSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 58_467_386_571_701L;
+
+ /**
+ * General branch office bean
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/headquarters!org.mxchange.jcontactsbusiness.model.headquarters.HeadquarterSessionBeanRemote")
+ private HeadquartersSessionBeanRemote headquartersBean;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookAdminHeadquartersSessionBean () {
+ // Call super constructor
+ super();
+ }
+
+ @Override
+ public Headquarter addHeadquarters (final Headquarter headquarter) throws HeadquartersAlreadyAddedException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addHeadquarters(): headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N
+
+ // Validate parameter
+ if (null == headquarter) {
+ // Throw NPE
+ throw new NullPointerException("headquarter is null"); //NOI18N
+ } else if (headquarter.getHeadquartersId() instanceof Long) {
+ // Should not happen
+ throw new IllegalArgumentException("headquarter.branchId should not be set."); //NOI18N
+ } else if (this.isHeadquarterFound(headquarter)) {
+ // Already added, abort here
+ throw new HeadquartersAlreadyAddedException(headquarter);
+ }
+
+ // Add created timestamp
+ headquarter.setHeadquartersCreated(new Date());
+
+ // Is user instance set?
+ if (headquarter.getHeadquartersUserOwner() instanceof User) {
+ // Get managed instance back
+ final User managedUser = this.createManaged(headquarter.getHeadquartersUserOwner());
+
+ // Set it back in branch office
+ headquarter.setHeadquartersUserOwner(managedUser);
+ }
+
+ // Is user instance set?
+ if (headquarter.getHeadquartersCountry() instanceof Country) {
+ // Get managed instance back
+ final Country managedCountry = this.createManaged(headquarter.getHeadquartersCountry());
+
+ // Set it back in branch office
+ headquarter.setHeadquartersCountry(managedCountry);
+ }
+
+ // Set "created" timestamp on any number assigned
+ this.setAllPhoneEntriesCreated(headquarter);
+
+ // Get opening times
+ final List<OpeningTime> openingTimes = headquarter.getHeadquartersOpeningTimes();
+
+ // Debugging:
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.addHeadquarters(): headquarter.headquarterOpeningTimes={1}", this.getClass().getSimpleName(), openingTimes));
+
+ // Is opening times set and not empty?
+ if ((openingTimes instanceof List) && (!openingTimes.isEmpty())) {
+ // Add created timestamp for all times
+ this.setAllOpeningTimesCreated(openingTimes);
+ } else {
+ // Set all to null
+ headquarter.setHeadquartersOpeningTimes(null);
+ }
+
+ // Persist it
+ this.getEntityManager().persist(headquarter);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addHeadquarters(): headquarter.branchId={1} - EXIT!", this.getClass().getSimpleName(), headquarter.getHeadquartersId())); //NOI18N
+
+ // Return updated instance
+ return headquarter;
+ }
+
+ /**
+ * Checks if given branch office's address is already persisted. The whole
+ * (persisted) list is being loaded and each address is being matched
+ * against the given branch office's address.
+ * <p>
+ * @param headquarter Headquarters office being checked
+ * <p>
+ * @return Whether it has been found
+ */
+ private boolean isHeadquarterFound (final Headquarter headquarter) {
+ // Get whole list
+ final List<Headquarter> headquarters = this.headquartersBean.allHeadquarters();
+
+ // Default is not found
+ boolean isFound = false;
+
+ // Check all single addresses
+ for (final Headquarter hq : headquarters) {
+ // Is the same address found?
+ if (Headquarters.isSameAddress(hq, headquarter)) {
+ // Found one
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
+}
--- /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 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.headquarters;
+
+import java.text.MessageFormat;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.Query;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+
+/**
+ * A stateless session bean for general headquarters purposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "headquarters", description = "A general statless bean for handling headquarters data (all)")
+public class AddressbookHeadquartersSessionBean extends BaseAddressbookDatabaseBean implements HeadquartersSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 58_467_386_571_701L;
+
+ @Override
+ @SuppressWarnings ("unchecked")
+ public List<Headquarter> allHeadquarters () {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allHeadquarters: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
+ // Get query
+ final Query query = this.getEntityManager().createNamedQuery("AllHeadquarters"); //NOI18N
+
+ // Get list from it
+ final List<Headquarter> list = query.getResultList();
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allHeadquarters: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
+
+ // Return it
+ return list;
+ }
+
+}