*/
package org.mxchange.jjobs.beans.business.basicdata;
-import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
-import javax.faces.view.facelets.FaceletException;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
+import javax.faces.FacesException;
+import javax.inject.Inject;
import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jcountry.data.Country;
-import org.mxchange.jjobs.beans.BaseJobsController;
import org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData;
+import org.mxchange.jcontactsbusiness.basicdata.CompanyBasicData;
import org.mxchange.jcontactsbusiness.employee.Employee;
-import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData;
+import org.mxchange.jcontactsbusiness.events.basicdata.added.AdminAddedBusinessBasicDataEvent;
+import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
+import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.headquarters.HeadquartersData;
+import org.mxchange.jcountry.data.Country;
+import org.mxchange.jjobs.beans.BaseJobsController;
+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.jusercore.model.user.User;
/**
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-@Named ("adminBusinessDataController")
+@Named ("adminCompanyDataController")
@RequestScoped
public class JobsAdminBusinessDataWebRequestBean extends BaseJobsController implements JobsAdminBusinessDataWebRequestController {
private static final long serialVersionUID = 56_189_028_928_374L;
/**
- * Remote contact bean
+ * EJB for administrative purposes
*/
+ @EJB (lookup = "java:global/jjobs-ejb/adminBusinessData!org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote")
private AdminBusinessDataSessionBeanRemote adminBusinessDataBean;
+ /**
+ * An event being fired when basic business data has been added
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminAddedBusinessBasicDataEvent> businessDataAddedEvent;
+
/**
* Comments for this company
*/
*/
private String companyEmailAddress;
+ /**
+ * Company founder
+ */
+ private Employee companyFounder;
+
/**
* Head quarter data for this company
*/
- private HeadQuartersData companyHeadQuarters;
+ private HeadquartersData companyHeadQuarters;
/**
* Company name
private String companyTaxNumber;
/**
- * Web site URL
+ * Owning user instance (which this company is assigned to)
*/
- private String companyWebsiteUrl;
+ private User companyUserOwner;
/**
- * Owning user instance (which this company is assigned to)
+ * Web site URL
*/
- private User contactCompanyUserOwner;
+ private String companyWebsiteUrl;
/**
* Area code for fax number
private Long landLineNumber;
/**
- * Constructor
+ * Default constructor
*/
public JobsAdminBusinessDataWebRequestBean () {
// Call super constructor
super();
}
+ /**
+ * Adds a basic business data entry, if not yet found.
+ * <p>
+ * @return Redirect outcome
+ */
+ public String addBusinessBasicData () {
+ // First, validate all parameter
+ if (this.getCompanyName() == null) {
+ // Is null
+ throw new NullPointerException("this.companyName is null"); //NOI18N
+ } else if (this.getCompanyName().isEmpty()) {
+ // Is null
+ throw new IllegalArgumentException("this.companyName is empty"); //NOI18N
+ }
+
+ // Prepare entity
+ BusinessBasicData basicData = new CompanyBasicData(this.getCompanyName());
+
+ // Set all opther remaining data
+ basicData.setCompanyComments(this.getCompanyComments());
+ basicData.setCompanyContactEmployee(this.getCompanyContactEmployee());
+ basicData.setCompanyEmailAddress(this.getCompanyEmailAddress());
+ basicData.setCompanyFounder(this.getCompanyFounder());
+ basicData.setCompanyHeadQuartersData(this.getCompanyHeadQuarters());
+ basicData.setCompanyTaxNumber(this.getCompanyTaxNumber());
+ basicData.setCompanyUserOwner(this.getCompanyUserOwner());
+ basicData.setCompanyWebsiteUrl(this.getCompanyWebsiteUrl());
+
+ // Set logo instance
+ // @TODO basicData.setCompanyLogo();
+ // Generate phone number
+ DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+ DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+
+ // Don't set null or wrong references
+ if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
+ // Now the number must be given
+ if (landLine.getPhoneAreaCode() == null) {
+ // Is null
+ throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
+ } else if (landLine.getPhoneAreaCode() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
+ } else if (landLine.getPhoneNumber() == null) {
+ // Is null
+ throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
+ } else if (landLine.getPhoneNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
+ }
+
+ // Set phone number
+ basicData.setCompanyLandLineNumber(landLine);
+ }
+
+ // Don't set null or wrong references
+ if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
+ // Now the number must be given
+ if (fax.getPhoneAreaCode() == null) {
+ // Is null
+ throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
+ } else if (fax.getPhoneAreaCode() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
+ } else if (fax.getPhoneNumber() == null) {
+ // Is null
+ throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
+ } else if (fax.getPhoneNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
+ }
+
+ // Set fax number
+ basicData.setCompanyFaxNumber(fax);
+ }
+
+ // Now try to send to EJB and get an updated version back
+ try {
+ // Try it
+ BusinessBasicData updatedBasicData = this.adminBusinessDataBean.addCompanyBasicData(basicData);
+
+ // Fire event
+ this.businessDataAddedEvent.fire(new AdminAddedBusinessBasicDataEvent(updatedBasicData));
+ } catch (final BusinessDataAlreadyAddedException e) {
+ // Does already exist
+ throw new FacesException(e);
+ }
+
+ // Continue to list again
+ return "admin_list_business_contacts"; //NOI18N
+ }
+
/**
* Getter for comments
* <p>
this.companyEmailAddress = companyEmailAddress;
}
+ /**
+ * Getter for company founder
+ * <p>
+ * @return Company founder
+ */
+ public Employee getCompanyFounder () {
+ return this.companyFounder;
+ }
+
+ /**
+ * Setter for company founder
+ * <p>
+ * @param companyFounder Company founder
+ */
+ public void setCompanyFounder (final Employee companyFounder) {
+ this.companyFounder = companyFounder;
+ }
+
/**
* Getter for headquarters data
* <p>
* @return Headquarters data
*/
- public HeadQuartersData getCompanyHeadQuarters () {
+ public HeadquartersData getCompanyHeadQuarters () {
return this.companyHeadQuarters;
}
* <p>
* @param companyHeadQuarters Headquarters data
*/
- public void setCompanyHeadQuarters (final HeadQuartersData companyHeadQuarters) {
+ public void setCompanyHeadQuarters (final HeadquartersData companyHeadQuarters) {
this.companyHeadQuarters = companyHeadQuarters;
}
}
/**
- * Getter for company web site URL
+ * Getter for owning user instance
* <p>
- * @return Company web site URL
+ * @return Owning user instance
*/
- public String getCompanyWebsiteUrl () {
- return this.companyWebsiteUrl;
+ public User getCompanyUserOwner () {
+ return this.companyUserOwner;
}
/**
- * Getter for company web site URL
+ * Setter for owning user instance
* <p>
- * @param companyWebsiteUrl Company web site URL
+ * @param companyUserOwner Owning user instance
*/
- public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
- this.companyWebsiteUrl = companyWebsiteUrl;
+ public void setCompanyUserOwner (final User companyUserOwner) {
+ this.companyUserOwner = companyUserOwner;
}
/**
- * Getter for owning user instance
+ * Getter for company web site URL
* <p>
- * @return Owning user instance
+ * @return Company web site URL
*/
- public User getContactCompanyUserOwner () {
- return this.contactCompanyUserOwner;
+ public String getCompanyWebsiteUrl () {
+ return this.companyWebsiteUrl;
}
/**
- * Setter for owning user instance
+ * Getter for company web site URL
* <p>
- * @param contactCompanyUserOwner Owning user instance
+ * @param companyWebsiteUrl Company web site URL
*/
- public void setContactCompanyUserOwner (final User contactCompanyUserOwner) {
- this.contactCompanyUserOwner = contactCompanyUserOwner;
+ public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
+ this.companyWebsiteUrl = companyWebsiteUrl;
}
/**
this.landLineNumber = landLineNumber;
}
- /**
- * Post-initialization of this class
- */
- @PostConstruct
- public void init () {
- // Try it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Try to lookup
- this.adminBusinessDataBean = (AdminBusinessDataSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminBusinessData!org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote"); //NOI18N
- } catch (final NamingException e) {
- // Throw again
- throw new FaceletException(e);
- }
- }
-
}