import javax.ejb.EJB;
import javax.ejb.Stateless;
import org.mxchange.addressbook.enterprise.BaseAddressbookEnterpriseBean;
+import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeNotFoundException;
import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
+import org.mxchange.jcontactsbusiness.model.utils.BranchOfficeUtils;
import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jusercore.model.user.User;
/**
* General branch office bean
*/
- @EJB (lookup = "java:global/addressbook-ejb/branchOffice!org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote")
+ @EJB (lookup = "java:global/jfinancials-ejb/branchOffice!org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote")
private BranchOfficeSessionBeanRemote branchOfficeBean;
/**
// Add created timestamp
branchOffice.setBranchEntryCreated(new Date());
+ // Is contact employee set?
+ if (branchOffice.getBranchContactEmployee() instanceof Contact) {
+ // Get managed lead contact
+ final Contact managedContact = this.createManaged(branchOffice.getBranchContactEmployee());
+
+ // Set it back
+ branchOffice.setBranchContactEmployee(managedContact);
+ }
+
+ // Is owner employee set?
+ if (branchOffice.getBranchOwnerEmployee() instanceof Contact) {
+ // Get managed lead contact
+ final Contact managedContact = this.createManaged(branchOffice.getBranchOwnerEmployee());
+
+ // Set it back
+ branchOffice.setBranchOwnerEmployee(managedContact);
+ }
+
// Is user instance set?
if (branchOffice.getBranchCompany() instanceof BasicData) {
// Get managed instance back
final List<OpeningTime> openingTimes = branchOffice.getBranchOpeningTimes();
// Debugging:
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.addBranchOffice(): branchOffice.branchOfficeOpeningTimes={1}", this.getClass().getSimpleName(), openingTimes));
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.addBranchOffice(): branchOffice.branchOfficeOpeningTimes={1}", this.getClass().getSimpleName(), openingTimes)); //NOI18N
// Is opening times set and not empty?
if ((openingTimes instanceof List) && (!openingTimes.isEmpty())) {
return branchOffice;
}
+ @Override
+ public BranchOffice updateBranchOffice (final BranchOffice branchOffice) throws BranchOfficeNotFoundException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateBranchOffice(): branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N
+
+ // Is parameter valid?
+ 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 IAE again
+ throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is invalid", branchOffice.getBranchId())); //NOI18N
+ } else if (!this.isBranchOfficeFound(branchOffice)) {
+ // Not found
+ throw new BranchOfficeNotFoundException(branchOffice.getBranchId());
+ }
+
+ // Merge data
+ final BranchOffice updatedBranchOffice = this.mergeBranchOfficeData(branchOffice);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateBranchOffice(): updatedBranchOffice={1} - EXIT!", this.getClass().getSimpleName(), updatedBranchOffice));
+
+ // Return updated instance
+ return updatedBranchOffice;
+ }
+
/**
* Checks if given branch office's address is already persisted. The whole
* (persisted) list is being loaded and each address is being matched
* @return Whether it has been found
*/
private boolean isBranchOfficeFound (final BranchOffice branchOffice) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isBranchOfficeFound(): branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N
+
// Get whole list
final List<BranchOffice> branchOffices = this.branchOfficeBean.fetchAllBranchOffices();
// Check all single addresses
for (final BranchOffice bo : branchOffices) {
// Is the same address found?
- if (Objects.equals(bo.getBranchId(), branchOffice.getBranchId()) || BranchOffices.isSameAddress(bo, branchOffice)) {
+ if (Objects.equals(bo.getBranchId(), branchOffice.getBranchId()) || BranchOfficeUtils.isSameAddress(bo, branchOffice)) {
// Found one
isFound = true;
break;
}
}
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isBranchOfficeFound(): isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N
+
// Return flag
return isFound;
}