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;
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.jjobs.beans.BaseJobsController;
import org.mxchange.jjobs.beans.helper.JobsWebRequestController;
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.mobileprovider.MobileProvider;
+import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
/**
* An administrative user controller (bean)
@Any
private Event<AdminAddedContactEvent> addedContactEvent;
+ /**
+ * Administrative contact EJB
+ */
+ private AdminContactSessionBeanRemote adminContactBean;
+
/**
* Admin helper instance
*/
private String comment;
/**
- * Remote contact bean
+ * General contact EJB
*/
private final ContactSessionBeanRemote contactBean;
*/
private Country country;
+ /**
+ * Event being fired when contact data has been deleted
+ */
+ @Inject
+ @Any
+ private Event<AdminDeletedContactEvent> deletedContactEvent;
+
/**
* Email address
*/
// 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);
// 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);
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
@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));
-
- // Clear bean
- this.clear();
+ this.deletedContactEvent.fire(new AdminContactDeletedEvent(contact));
- // Return it
- return contact;
+ // All fine
+ return "admin_list_contact"; //NOI18N
}
@Override
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;
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
*/
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
contact.setContactZipCode(this.getZipCode());
contact.setContactCity(this.getCity());
contact.setContactCountry(this.getCountry());
+ contact.setContactEmailAddress(this.getEmailAddress());
// Update contact's cellphone number
this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());