/*
- * Copyright (C) 2016 Cho-Time GmbH
+ * Copyright (C) 2016 Roland Haeder
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
import java.text.MessageFormat;
import java.util.Date;
import java.util.Iterator;
-import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
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.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;
*/
@Named ("adminContactController")
@RequestScoped
-public class JobsAdminContactWebRequestBean implements JobsAdminContactWebRequestController {
+public class JobsAdminContactWebRequestBean extends BaseJobsController implements JobsAdminContactWebRequestController {
/**
* Serial number
* Admin helper instance
*/
@Inject
- private JobsAdminWebRequestController adminHelper;
+ private JobsWebRequestController beanHelper;
/**
* Birth day
*/
private String street;
+ /**
+ * Title
+ */
+ private String title;
+
/**
* An event fired when the administrator has updated contact data
*/
* Default constructor
*/
public JobsAdminContactWebRequestBean () {
- // Set gender to UNKNOWN
- this.gender = Gender.UNKNOWN;
-
// Try it
try {
// Get initial context
// Fire event
this.addedContactEvent.fire(new AdminContactAddedEvent(updatedContact));
+ // 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
// Set all fields: contact
this.setContactId(contact.getContactId());
+ this.setTitle(contact.getContactTitle());
this.setBirthday(contact.getContactBirthday());
this.setCity(contact.getContactCity());
this.setComment(contact.getContactComment());
this.setFirstName(contact.getContactFirstName());
this.setGender(contact.getContactGender());
this.setHouseNumber(contact.getContactHouseNumber());
+ this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
this.setStreet(contact.getContactStreet());
this.setZipCode(contact.getContactZipCode());
// ... cellphone data
- this.setCellphoneId(contact.getContactCellphoneNumber().getPhoneId());
- this.setCellphoneCarrier(contact.getContactCellphoneNumber().getCellphoneProvider());
- this.setCellphoneNumber(contact.getContactCellphoneNumber().getPhoneNumber());
+ if (contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) {
+ this.setCellphoneId(contact.getContactCellphoneNumber().getPhoneId());
+ this.setCellphoneCarrier(contact.getContactCellphoneNumber().getCellphoneProvider());
+ this.setCellphoneNumber(contact.getContactCellphoneNumber().getPhoneNumber());
+ }
// ... fax data
- this.setFaxId(contact.getContactFaxNumber().getPhoneId());
- this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
- this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
- this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
+ if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+ this.setFaxId(contact.getContactFaxNumber().getPhoneId());
+ this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
+ this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
+ this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
+ }
// .. land-line data
- this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
- this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
- this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry());
- this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber());
+ 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());
+ }
}
@Override
// Check if contact instance is in helper and valid
if (null == contact) {
// Throw NPE
- throw new NullPointerException("adminHelper.contact is null"); //NOI18N
+ throw new NullPointerException("beanHelper.contact is null"); //NOI18N
} else if (contact.getContactId() == null) {
// Throw NPE again
- throw new NullPointerException("adminHelper.contact.contactId is null"); //NOI18N //NOI18N
+ throw new NullPointerException("beanHelper.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
+ throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
}
// Update all data in contact
@Override
public String editContactData () {
// Get contact instance
- Contact contact = this.adminHelper.getContact();
+ Contact contact = this.beanHelper.getContact();
// Check if contact instance is in helper and valid
if (null == contact) {
// Throw NPE
- throw new NullPointerException("adminHelper.contact is null"); //NOI18N
+ throw new NullPointerException("beanHelper.contact is null"); //NOI18N
} else if (contact.getContactId() == null) {
// Throw NPE again
- throw new NullPointerException("adminHelper.contact.contactId is null"); //NOI18N //NOI18N
+ throw new NullPointerException("beanHelper.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
+ throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
}
// Update all data in contact
return "admin_list_contact"; //NOI18N
}
+ @Override
+ public String generateCellphoneNumber (final DialableCellphoneNumber cellphoneNumber) {
+ // Is it null?
+ if (null == cellphoneNumber) {
+ // Return null
+ return null;
+ }
+
+ // Get all data
+ String number = String.format(
+ "%s%d%d", //NOI18N
+ cellphoneNumber.getCellphoneProvider().getProviderCountry().getCountryExternalDialPrefix(),
+ cellphoneNumber.getCellphoneProvider().getProviderDialPrefix(),
+ cellphoneNumber.getPhoneNumber()
+ );
+
+ // Return it
+ return number;
+ }
+
+ @Override
+ public String generatePhoneNumber (final DialableNumber phoneNumber) {
+ // Is it null?
+ if (null == phoneNumber) {
+ // Return null
+ return null;
+ }
+
+ // Generate it
+ String number = String.format(
+ "%s%d%d", //NOI18N
+ phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
+ phoneNumber.getPhoneAreaCode(),
+ phoneNumber.getPhoneNumber()
+ );
+
+ // Return it
+ return number;
+ }
+
@Override
@SuppressWarnings ("ReturnOfDateField")
public Date getBirthday () {
this.street = street;
}
+ @Override
+ public String getTitle () {
+ return this.title;
+ }
+
+ @Override
+ public void setTitle (final String title) {
+ this.title = title;
+ }
+
@Override
public Integer getZipCode () {
return this.zipCode;
this.zipCode = zipCode;
}
- @Override
- public boolean hasContacts () {
- return (!this.allContacts().isEmpty());
- }
-
/**
* Post-initialization of this class
*/
private void clear () {
// Clear all data
// - personal data
- this.setGender(Gender.UNKNOWN);
+ this.setGender(null);
+ this.setTitle(null);
this.setFirstName(null);
this.setFamilyName(null);
this.setStreet(null);
this.setHouseNumber(null);
+ this.setHouseNumberExtension(null);
this.setZipCode(null);
this.setCity(null);
this.setCountry(null);
boolean IsFound = false;
// Get iterator
- Iterator<Contact> iterator = this.allContacts().iterator();
+ Iterator<Contact> iterator = this.contactController.allContacts().iterator();
// Loop through all
while (iterator.hasNext()) {
// Update all fields
contact.setContactGender(this.getGender());
+ contact.setContactTitle(this.getTitle());
contact.setContactFirstName(this.getFirstName());
contact.setContactFamilyName(this.getFamilyName());
contact.setContactStreet(this.getStreet());