import java.text.MessageFormat;
import java.util.Date;
+import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
import org.mxchange.jcontacts.contact.utils.ContactUtils;
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.helper.JobsAdminWebRequestController;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
}
@Override
- public String changeContactData () {
- // Get contact instance
- Contact contact = this.adminHelper.getContact();
+ public String addContact () {
+ // Create new contact instance
+ Contact contact = this.createContactInstance();
- // Check if contact instance is in helper and valid
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("adminHelper.contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw NPE again
- throw new NullPointerException("adminHelper.contact.contactId is null"); //NOI18N //NOI18N
- } else if (contact.getContactId() < 1) {
- // Invalid id
- throw new IllegalStateException(MessageFormat.format("adminHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
+ // Default is not same contact
+ if (this.isSameContactFound(contact)) {
+ // Already registered
+ throw new FaceletException(new ContactAlreadyAddedException(contact));
}
- // Update all data in contact
- this.updateContactData(contact);
+ // Init contact
+ Contact updatedContact;
- // Call EJB for updating contact data
- Contact updatedContact = this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+ // Try to call EJB
+ try {
+ // Call EJB
+ updatedContact = this.contactBean.addContact(contact);
+ } catch (final ContactAlreadyAddedException ex) {
+ // Throw again
+ throw new FaceletException(ex);
+ }
// Fire event
- this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact));
+ this.addedContactEvent.fire(new AdminContactAddedEvent(updatedContact));
- // Return to contact list (for now)
+ // Clear this bean
+ this.clear();
+
+ // Return outcome
return "admin_list_contact"; //NOI18N
}
+ @Override
+ public List<Contact> allContacts () {
+ return this.contactController.allContacts();
+ }
+
@Override
public void copyContactToController (final Contact contact) {
// The contact instance must be valid
}
@Override
+ public String editContactData () {
+ // Get contact instance
+ Contact contact = this.adminHelper.getContact();
+
+ // Check if contact instance is in helper and valid
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("adminHelper.contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("adminHelper.contact.contactId is null"); //NOI18N //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Invalid id
+ throw new IllegalStateException(MessageFormat.format("adminHelper.contact.contactId={0} is invalid", 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);
+
+ // Fire event
+ this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact));
+
+ // Clear bean
+ this.clear();
+
+ // Return to contact list (for now)
+ return "admin_list_contact"; //NOI18N
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
public Date getBirthday () {
return this.birthday;
}
@Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
public void setBirthday (final Date birthday) {
this.birthday = birthday;
}
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUpdatedContact()== null) {
+ } else if (event.getUpdatedContact() == null) {
// Throw NPE again
throw new NullPointerException("event.user is null"); //NOI18N
} else if (event.getUpdatedContact().getContactId() == null) {
System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
}
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<Contact> allContacts () {
+ return this.contactList;
+ }
+
/**
* Clears this bean
*/
// Trace message
//this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact));
-
// Return it
return localContact;
}
}
@Override
+ @SuppressWarnings ("ReturnOfDateField")
public Date getBirthday () {
return this.birthday;
}
@Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
public void setBirthday (final Date birthday) {
this.birthday = birthday;
}