From 1d1f03149234ba91668464420fc9333fa926ff4e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 9 Aug 2016 15:44:15 +0200 Subject: [PATCH] Continued: (please cherry-pick) - implemented updateCellphoneData() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../JobsAdminContactPhoneSessionBean.java | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/java/org/mxchange/jcontacts/phone/JobsAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/phone/JobsAdminContactPhoneSessionBean.java index 42daebc..fcd6d02 100644 --- a/src/java/org/mxchange/jcontacts/phone/JobsAdminContactPhoneSessionBean.java +++ b/src/java/org/mxchange/jcontacts/phone/JobsAdminContactPhoneSessionBean.java @@ -16,9 +16,11 @@ */ package org.mxchange.jcontacts.phone; +import java.text.MessageFormat; +import java.util.GregorianCalendar; import javax.ejb.Stateless; -import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote; import org.mxchange.jjobs.database.BaseJobsDatabaseBean; +import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; /** * A session EJB for administrative contact's phone number purposes @@ -33,4 +35,58 @@ public class JobsAdminContactPhoneSessionBean extends BaseJobsDatabaseBean imple */ private static final long serialVersionUID = 189_217_561_460_237_108L; + @Override + public DialableCellphoneNumber updateCellphoneData (final DialableCellphoneNumber cellPhoneNumber) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateCellphoneData: cellPhoneNumber={1} - CALLED!", this.getClass().getSimpleName(), cellPhoneNumber)); + + // Is all data set + if (null == cellPhoneNumber) { + // Not set, throw NPE + throw new NullPointerException("cellphoneNumber is null"); //NOI18N + } else if (cellPhoneNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("cellphoneNumber.phoneId is null"); //NOI18N + } else if (cellPhoneNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.phoneId={0} is not valid", cellPhoneNumber.getPhoneId())); //NOI18N + } else if (cellPhoneNumber.getCellphoneProvider() == null) { + // Throw NPE + throw new NullPointerException("cellphoneNumber.cellphoneProvider is null"); //NOI18N + } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() == null) { + // ... throw again + throw new NullPointerException("cellphoneNumber.cellphoneProvider.providerId is null"); //NOI18N + } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.cellphoneProvider.providerId={0} is not valid.", cellPhoneNumber.getCellphoneProvider().getProviderId())); //NOI18N + } else if (cellPhoneNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("cellphoneNumber.phoneNumber is null"); //NOI18N + } else if (cellPhoneNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("cellphoneNumber.phoneNumber={0} is not valid.", cellPhoneNumber.getPhoneNumber())); //NOI18N + } + + // Set updated timestamp + cellPhoneNumber.setPhoneEntryUpdated(new GregorianCalendar()); + + // Get contact from it and find it + DialableCellphoneNumber foundNumber = this.getEntityManager().find(cellPhoneNumber.getClass(), cellPhoneNumber.getPhoneId()); + + // Should be found + assert (foundNumber instanceof DialableCellphoneNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", cellPhoneNumber.getPhoneId()); //NOI18N + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateCellphoneData: foundNumber.phoneId={0}", foundNumber.getPhoneId())); //NOI18N + + // Merge contact instance + DialableCellphoneNumber detachedNumber = this.getEntityManager().merge(foundNumber); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateCellphoneData: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N + + // Return it + return detachedNumber; + } + } -- 2.39.5