X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fjjobs%2Fbeans%2Fcontact%2FJobsAdminContactWebRequestBean.java;h=f5f168a94f6a491b8565bf6be4915de5852e6627;hb=09d2137f89da9234cd2fed7af9021b24c3934662;hp=8b93305b84cb560aba769bbfb3658fb2e838f2b2;hpb=451e34d2a064a7b3831094f44f61ba631530b171;p=jjobs-war.git
diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java
index 8b93305b..f5f168a9 100644
--- a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java
+++ b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java
@@ -22,14 +22,15 @@ import java.util.Iterator;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
+import javax.enterprise.event.Observes;
import javax.enterprise.inject.Any;
-import javax.faces.context.FacesContext;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote;
import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
import org.mxchange.jcontacts.contact.UserContact;
@@ -37,23 +38,23 @@ import org.mxchange.jcontacts.contact.gender.Gender;
import org.mxchange.jcontacts.contact.utils.ContactUtils;
import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
import org.mxchange.jcontacts.events.contact.add.AdminContactAddedEvent;
+import org.mxchange.jcontacts.events.contact.deleted.AdminContactDeletedEvent;
+import org.mxchange.jcontacts.events.contact.deleted.AdminDeletedContactEvent;
import org.mxchange.jcontacts.events.contact.update.AdminContactUpdatedEvent;
import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
import org.mxchange.jcountry.data.Country;
import org.mxchange.jjobs.beans.BaseJobsController;
-import org.mxchange.jjobs.beans.helper.JobsWebRequestController;
+import org.mxchange.jjobs.beans.helper.JobsWebViewHelperController;
import org.mxchange.jphone.phonenumbers.DialableNumber;
-import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
-import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
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.mobileprovider.MobileProvider;
+import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
/**
- * An administrative user bean (controller)
+ * An administrative user controller (bean)
*
* @author Roland Haeder
*/
@@ -74,30 +75,20 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
private Event addedContactEvent;
/**
- * Admin helper instance
+ * Administrative contact EJB
*/
- @Inject
- private JobsWebRequestController beanHelper;
-
- /**
- * Birth day
- */
- private Date birthday;
-
- /**
- * Cellphone number's carrier
- */
- private MobileProvider cellphoneCarrier;
+ private AdminContactSessionBeanRemote adminContactBean;
/**
- * Cellphone id number
+ * Bean helper
*/
- private Long cellphoneId;
+ @Inject
+ private JobsWebViewHelperController beanHelper;
/**
- * Cellphone number
+ * Birth day
*/
- private Long cellphoneNumber;
+ private Date birthday;
/**
* City
@@ -110,7 +101,7 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
private String comment;
/**
- * Remote contact bean
+ * General contact EJB
*/
private final ContactSessionBeanRemote contactBean;
@@ -130,6 +121,13 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
*/
private Country country;
+ /**
+ * Event being fired when contact data has been deleted
+ */
+ @Inject
+ @Any
+ private Event deletedContactEvent;
+
/**
* Email address
*/
@@ -151,14 +149,14 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
private Country faxCountry;
/**
- * Fax id number
+ * Fax number
*/
- private Long faxId;
+ private Long faxNumber;
/**
- * Fax number
+ * Fax id number
*/
- private Long faxNumber;
+ private Long faxNumberId;
/**
* First name
@@ -180,11 +178,6 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
*/
private String houseNumberExtension;
- /**
- * Whether a cellphone entry has been unlinked
- */
- private boolean isCellphoneUnlinked;
-
/**
* Whether a fax entry has been unlinked
*/
@@ -195,25 +188,45 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
*/
private boolean isLandLineUnlinked;
+ /**
+ * Whether a mobile entry has been unlinked
+ */
+ private boolean isMobileUnlinked;
+
+ /**
+ * Land-line number area code
+ */
+ private Integer landLineAreaCode;
+
+ /**
+ * Country instance for land-line number
+ */
+ private Country landLineCountry;
+
/**
* Land-line id number
*/
private Long landLineId;
/**
- * Phone number area code
+ * Land-line number
*/
- private Integer phoneAreaCode;
+ private Long landLineNumber;
/**
- * Country instance for phone number
+ * Mobile number
*/
- private Country phoneCountry;
+ private Long mobileNumber;
/**
- * Phone number
+ * Mobile id number
*/
- private Long phoneNumber;
+ private Long mobileNumberId;
+
+ /**
+ * Mobile provider
+ */
+ private MobileProvider mobileProvider;
/**
* Street
@@ -246,8 +259,11 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
// Get initial context
Context context = new InitialContext();
- // Try to lookup
- this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
+ // Try to lookup (general)
+ this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
+
+ // Try to lookup (administative)
+ this.adminContactBean = (AdminContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminContact!org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote"); //NOI18N
} catch (final NamingException e) {
// Throw again
throw new FaceletException(e);
@@ -289,7 +305,7 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
// Try to call EJB
try {
// Call EJB
- updatedContact = this.contactBean.addContact(contact);
+ updatedContact = this.adminContactBean.addContact(contact);
} catch (final ContactAlreadyAddedException ex) {
// Throw again
throw new FaceletException(ex);
@@ -305,6 +321,27 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
return "admin_list_contact"; //NOI18N
}
+ @Override
+ public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getAddedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.addedUser is null"); //NOI18N
+ } else if (event.getAddedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
+ } else if (event.getAddedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
+ }
+
+ // Clear all data
+ this.clear();
+ }
+
@Override
public void copyContactToController (final Contact contact) {
// The contact instance must be valid
@@ -313,7 +350,7 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
throw new NullPointerException("contact is null"); //NOI18N
} else if (contact.getContactId() == null) {
// Throw NPE again
- throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
} else if (contact.getContactId() < 1) {
// Not valid
throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
@@ -335,16 +372,16 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
this.setStreet(contact.getContactStreet());
this.setZipCode(contact.getContactZipCode());
- // ... cellphone data
- if (contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) {
- this.setCellphoneId(contact.getContactCellphoneNumber().getPhoneId());
- this.setCellphoneCarrier(contact.getContactCellphoneNumber().getCellphoneProvider());
- this.setCellphoneNumber(contact.getContactCellphoneNumber().getPhoneNumber());
+ // ... mobile data
+ if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
+ this.setMobileNumberId(contact.getContactMobileNumber().getPhoneId());
+ this.setMobileProvider(contact.getContactMobileNumber().getMobileProvider());
+ this.setMobileNumber(contact.getContactMobileNumber().getPhoneNumber());
}
// ... fax data
if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
- this.setFaxId(contact.getContactFaxNumber().getPhoneId());
+ this.setFaxNumberId(contact.getContactFaxNumber().getPhoneId());
this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
@@ -353,48 +390,46 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
// .. land-line data
if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
- this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
- this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry());
- this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber());
+ this.setLandLineAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
+ this.setLandLineCountry(contact.getContactLandLineNumber().getPhoneCountry());
+ this.setLandLineNumber(contact.getContactLandLineNumber().getPhoneNumber());
}
}
@Override
public Contact createContactInstance () {
- // Generate phone number
- DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
- DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
- DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
-
// Create new instance
Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
- // Check if contact instance is in helper and valid
+ // Update all data in contact
+ this.updateContactData(contact);
+
+ // Return it
+ return contact;
+ }
+
+ @Override
+ public String deleteContactData (final Contact contact) {
+ // The instance must be valid
if (null == contact) {
// Throw NPE
- throw new NullPointerException("beanHelper.contact is null"); //NOI18N
+ throw new NullPointerException("contact is null"); //NOI18N
} else if (contact.getContactId() == null) {
- // Throw NPE again
- throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
+ // Throw it again
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
} else if (contact.getContactId() < 1) {
- // Invalid id
- throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
}
- // Update all data in contact
- this.updateContactData(contact);
-
- // Call EJB for updating contact data
- Contact updatedContact = this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+ // Call EJB
+ this.adminContactBean.deleteContactData(contact);
// Fire event
- this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact));
+ this.deletedContactEvent.fire(new AdminContactDeletedEvent(contact));
- // Clear bean
- this.clear();
-
- // Return it
- return contact;
+ // All fine
+ return "admin_list_contact"; //NOI18N
}
@Override
@@ -408,7 +443,7 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
throw new NullPointerException("beanHelper.contact is null"); //NOI18N
} else if (contact.getContactId() == null) {
// Throw NPE again
- throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
+ throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N
} else if (contact.getContactId() < 1) {
// Invalid id
throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
@@ -418,7 +453,7 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
this.updateContactData(contact);
// Call EJB for updating contact data
- Contact updatedContact = this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+ Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
// Fire event
this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact));
@@ -431,9 +466,9 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
}
@Override
- public String generateCellphoneNumber (final DialableCellphoneNumber cellphoneNumber) {
+ public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
// Is it null?
- if (null == cellphoneNumber) {
+ if (null == mobileNumber) {
// Return null
return null;
}
@@ -441,9 +476,9 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
// Get all data
String number = String.format(
"%s%d%d", //NOI18N
- cellphoneNumber.getCellphoneProvider().getProviderCountry().getCountryExternalDialPrefix(),
- cellphoneNumber.getCellphoneProvider().getProviderDialPrefix(),
- cellphoneNumber.getPhoneNumber()
+ mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
+ mobileNumber.getMobileProvider().getProviderDialPrefix(),
+ mobileNumber.getPhoneNumber()
);
// Return it
@@ -482,36 +517,6 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
this.birthday = birthday;
}
- @Override
- public MobileProvider getCellphoneCarrier () {
- return this.cellphoneCarrier;
- }
-
- @Override
- public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
- this.cellphoneCarrier = cellphoneCarrier;
- }
-
- @Override
- public Long getCellphoneId () {
- return this.cellphoneId;
- }
-
- @Override
- public void setCellphoneId (final Long cellphoneId) {
- this.cellphoneId = cellphoneId;
- }
-
- @Override
- public Long getCellphoneNumber () {
- return this.cellphoneNumber;
- }
-
- @Override
- public void setCellphoneNumber (Long cellphoneNumber) {
- this.cellphoneNumber = cellphoneNumber;
- }
-
@Override
public String getCity () {
return this.city;
@@ -542,6 +547,17 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
this.contactId = contactId;
}
+ @Override
+ public String getControllerType () {
+ return "admin"; //NOI18N
+ }
+
+ @Override
+ @Deprecated
+ public void setControllerType (final String controllerType) {
+ throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
+ }
+
@Override
public Country getCountry () {
return this.country;
@@ -593,23 +609,23 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
}
@Override
- public Long getFaxId () {
- return this.faxId;
+ public Long getFaxNumber () {
+ return this.faxNumber;
}
@Override
- public void setFaxId (final Long faxId) {
- this.faxId = faxId;
+ public void setFaxNumber (final Long faxNumber) {
+ this.faxNumber = faxNumber;
}
@Override
- public Long getFaxNumber () {
- return this.faxNumber;
+ public Long getFaxNumberId () {
+ return this.faxNumberId;
}
@Override
- public void setFaxNumber (final Long faxNumber) {
- this.faxNumber = faxNumber;
+ public void setFaxNumberId (final Long faxNumberId) {
+ this.faxNumberId = faxNumberId;
}
@Override
@@ -652,6 +668,26 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
this.houseNumberExtension = houseNumberExtension;
}
+ @Override
+ public Integer getLandLineAreaCode () {
+ return this.landLineAreaCode;
+ }
+
+ @Override
+ public void setLandLineAreaCode (final Integer landLineAreaCode) {
+ this.landLineAreaCode = landLineAreaCode;
+ }
+
+ @Override
+ public Country getLandLineCountry () {
+ return this.landLineCountry;
+ }
+
+ @Override
+ public void setLandLineCountry (final Country landLineCountry) {
+ this.landLineCountry = landLineCountry;
+ }
+
@Override
public Long getLandLineId () {
return this.landLineId;
@@ -663,33 +699,43 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
}
@Override
- public Integer getPhoneAreaCode () {
- return this.phoneAreaCode;
+ public Long getLandLineNumber () {
+ return this.landLineNumber;
+ }
+
+ @Override
+ public void setLandLineNumber (final Long landLineNumber) {
+ this.landLineNumber = landLineNumber;
}
@Override
- public void setPhoneAreaCode (final Integer phoneAreaCode) {
- this.phoneAreaCode = phoneAreaCode;
+ public Long getMobileNumber () {
+ return this.mobileNumber;
}
@Override
- public Country getPhoneCountry () {
- return this.phoneCountry;
+ public void setMobileNumber (Long mobileNumber) {
+ this.mobileNumber = mobileNumber;
}
@Override
- public void setPhoneCountry (final Country phoneCountry) {
- this.phoneCountry = phoneCountry;
+ public Long getMobileNumberId () {
+ return this.mobileNumberId;
}
@Override
- public Long getPhoneNumber () {
- return this.phoneNumber;
+ public void setMobileNumberId (final Long mobileNumberId) {
+ this.mobileNumberId = mobileNumberId;
}
@Override
- public void setPhoneNumber (final Long phoneNumber) {
- this.phoneNumber = phoneNumber;
+ public MobileProvider getMobileProvider () {
+ return this.mobileProvider;
+ }
+
+ @Override
+ public void setMobileProvider (final MobileProvider mobileProvider) {
+ this.mobileProvider = mobileProvider;
}
@Override
@@ -729,18 +775,6 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
public void init () {
}
- @Override
- public boolean isGenderRequired () {
- // Get context parameter
- String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_admin_gender_enabled"); //NOI18N
-
- // Is it set?
- boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
-
- // Return value
- return isRequired;
- }
-
/**
* Clears this bean
*/
@@ -760,11 +794,11 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
// - contact data
this.setEmailAddress(null);
- this.setPhoneCountry(null);
- this.setPhoneAreaCode(null);
- this.setPhoneNumber(null);
- this.setCellphoneCarrier(null);
- this.setCellphoneNumber(null);
+ this.setLandLineCountry(null);
+ this.setLandLineAreaCode(null);
+ this.setLandLineNumber(null);
+ this.setMobileProvider(null);
+ this.setMobileNumber(null);
this.setFaxCountry(null);
this.setFaxAreaCode(null);
this.setFaxNumber(null);
@@ -815,12 +849,6 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
if (null == contact) {
// Throw NPE
throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw NPE again
- throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
- } else if (contact.getContactId() < 1) {
- // Invalid id
- throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
}
// Update all fields
@@ -834,12 +862,15 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement
contact.setContactZipCode(this.getZipCode());
contact.setContactCity(this.getCity());
contact.setContactCountry(this.getCountry());
+ contact.setContactEmailAddress(this.getEmailAddress());
+ contact.setContactBirthday(this.getBirthday());
+ contact.setContactComment(this.getComment());
- // Update contact's cellphone number
- this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
+ // Update contact's mobile number
+ this.isMobileUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getMobileProvider(), this.getMobileNumber());
// Update contact's land-line number
- this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
+ this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
// Update contact's fax number
this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());