import javax.ejb.EJB;
import javax.ejb.Stateless;
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.jcountry.model.data.Country;
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();
}
}
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isBranchOfficeFound(): isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N
+
// Return flag
return isFound;
}
/**
* Serial number
*/
- private static final long serialVersionUID = 58_467_386_571_701L;
+ private static final long serialVersionUID = 58_467_386_571_702L;
@Override
@SuppressWarnings ("unchecked")
/**
* Serial number
*/
- private static final long serialVersionUID = 58_467_386_571_701L;
+ private static final long serialVersionUID = 58_467_386_571_703L;
/**
* General department bean
}
// Is lead employee set?
- if (department.getDepartmentLead()instanceof Employable) {
+ if (department.getDepartmentLead() instanceof Employable) {
// Get managed lead employee
final Employable managedEmployee = this.createManaged(department.getDepartmentLead());
}
// Is "owning" user set?
- if (department.getDepartmentUserOwner()instanceof User) {
+ if (department.getDepartmentUserOwner() instanceof User) {
// Get managed user
final User managedUser = this.createManaged(department.getDepartmentUserOwner());
/**
* Serial number
*/
- private static final long serialVersionUID = 58_467_386_571_701L;
+ private static final long serialVersionUID = 58_467_386_571_704L;
@Override
@SuppressWarnings ("unchecked")
/**
* Serial number
*/
- private static final long serialVersionUID = 58_467_386_571_701L;
+ private static final long serialVersionUID = 58_467_386_571_706L;
/**
* General branch office bean
*/
package org.mxchange.jcontactsbusiness.model.headquarter;
-import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
import java.text.MessageFormat;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;
import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean;
-import org.mxchange.jcontactsbusiness.model.headquarter.HeadquarterSessionBeanRemote;
/**
* A stateless session bean for general headquarter purposes
/**
* Serial number
*/
- private static final long serialVersionUID = 58_467_386_571_701L;
+ private static final long serialVersionUID = 58_467_386_571_707L;
@Override
@SuppressWarnings ("unchecked")
/**
* Serial number
*/
- private static final long serialVersionUID = 58_467_386_571_701L;
+ private static final long serialVersionUID = 58_467_386_571_709L;
/**
* Default constructor
} else if (openingTime.getOpeningTimeId() instanceof Long) {
// Should not happen
throw new IllegalArgumentException("openingTime.openingId should not be set."); //NOI18N
- } else if (openingTime.getOpeningStartDay()== null) {
+ } else if (openingTime.getOpeningStartDay() == null) {
// Throw NPE
throw new NullPointerException("openingTime.openingStartDay is null"); //NOI18N
- } else if (openingTime.getOpeningStartTime()== null) {
+ } else if (openingTime.getOpeningStartTime() == null) {
// Throw NPE
throw new NullPointerException("openingTime.openingStartTime is null"); //NOI18N
- } else if (openingTime.getOpeningEndDay()== null) {
+ } else if (openingTime.getOpeningEndDay() == null) {
// Throw NPE
throw new NullPointerException("openingTime.openingEndDay is null"); //NOI18N
- } else if (openingTime.getOpeningEndTime()== null) {
+ } else if (openingTime.getOpeningEndTime() == null) {
// Throw NPE
throw new NullPointerException("openingTime.openingEndTime is null"); //NOI18N
}
/**
* Serial number
*/
- private static final long serialVersionUID = 58_467_386_571_701L;
+ private static final long serialVersionUID = 58_467_386_571_710L;
@Override
@SuppressWarnings ("unchecked")
import org.mxchange.jcontacts.model.contact.Contacts;
import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices;
import org.mxchange.jcontactsbusiness.model.department.Department;
import org.mxchange.jcontactsbusiness.model.employee.Employable;
import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
return detachedNumber;
}
+ /**
+ * Merges given branch office's data
+ * <p>
+ * @param detachedBranchOffice Branch office instance to merge
+ * <p>
+ * @return Detached contact instance
+ */
+ protected BranchOffice mergeBranchOfficeData (final BranchOffice detachedBranchOffice) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeBranchOfficeData: detachedBranchOffice={0} - CALLED!", detachedBranchOffice)); //NOI18N
+
+ // The contact instance must be valid
+ if (null == detachedBranchOffice) {
+ // Throw NPE again
+ throw new NullPointerException("detachedBranchOffice is null"); //NOI18N
+ } else if (detachedBranchOffice.getBranchId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("detachedBranchOffice.branchId is null"); //NOI18N //NOI18N
+ } else if (detachedBranchOffice.getBranchId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("detachedBranchOffice.branchId ={0} is not valid.", detachedBranchOffice.getBranchId())); //NOI18N
+ }
+
+ // Set updated timestamp
+ detachedBranchOffice.setBranchEntryUpdated(new Date());
+
+ // Get contact from it and find it
+ final BranchOffice foundBranchOffice = this.getEntityManager().find(detachedBranchOffice.getClass(), detachedBranchOffice.getBranchId());
+
+ // Should be found
+ assert (foundBranchOffice instanceof BranchOffice) : MessageFormat.format("Branch office with id {0} not found, but should be.", detachedBranchOffice.getBranchId()); //NOI18N
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeBranchOfficeData: foundContact.contactId={0}", foundBranchOffice.getBranchId())); //NOI18N
+
+ // Copy all
+ BranchOffices.copyBranchOfficeData(detachedBranchOffice, foundBranchOffice);
+
+ // Merge contact instance
+ final BranchOffice managedBranchOffice = this.getEntityManager().merge(foundBranchOffice);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeBranchOfficeData: managedBranchOffice={0} - EXIT!", managedBranchOffice)); //NOI18N
+
+ // Return detached contact
+ return managedBranchOffice;
+ }
+
/**
* Merges given contact's data
* <p>