import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper;
import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
import org.mxchange.jphone.utils.PhoneUtils;
import org.mxchange.jusercore.model.user.LoginUser;
import org.mxchange.jusercore.model.user.User;
// Is contact cellphone set?
if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
- // Copy cellphone number
- contact.setContactMobileNumber(this.getDetached(contact.getContactMobileNumber(), contact.getContactMobileNumber()));
+ // Fetch it from entity manager
+ DialableMobileNumber fetchedNumber = this.getEntityManager().getReference(MobileNumber.class, contact.getContactMobileNumber().getPhoneId());
+
+ // Copy mobile number
+ contact.setContactMobileNumber(this.getDetached(contact.getContactMobileNumber(), fetchedNumber));
}
// Debug message
// Is the land-line number set?
if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+ // Fetch it from entity manager
+ DialableLandLineNumber fetchedNumber = this.getEntityManager().getReference(LandLineNumber.class, contact.getContactLandLineNumber().getPhoneId());
+
// Copy land-line number
- contact.setContactLandLineNumber(this.getDetached(contact.getContactLandLineNumber(), contact.getContactLandLineNumber()));
+ contact.setContactLandLineNumber(this.getDetached(contact.getContactLandLineNumber(), fetchedNumber));
}
// Debug message
// Is the fax number set?
if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+ // Fetch it from entity manager
+ DialableFaxNumber fetchedNumber = this.getEntityManager().getReference(FaxNumber.class, contact.getContactFaxNumber().getPhoneId());
+
// Copy fax number
- contact.setContactFaxNumber(this.getDetached(contact.getContactFaxNumber(), contact.getContactFaxNumber()));
+ contact.setContactFaxNumber(this.getDetached(contact.getContactFaxNumber(), fetchedNumber));
}
// Trace message
if (null == mobileNumber) {
// Throw NPE
throw new NullPointerException("mobileNumber is null"); //NOI18N
+ } else if (null == fetchedNumber) {
+ // Throw NPE again
+ throw new NullPointerException("fetchedNumber is null"); //NOI18N
} else if (fetchedNumber.getPhoneId() == null) {
// ..and again
throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
// Debug message
this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
- // Default is null
- DialableMobileNumber detachedNumber = null;
+ // Default is fetched number
+ DialableMobileNumber detachedNumber = fetchedNumber;
// Is there a difference?
if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
// Merge this entry
detachedNumber = this.getEntityManager().merge(foundNumber);
-
- // Copy all
}
// Trace message