]> git.mxchange.org Git - jjobs-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Thu, 8 Jun 2017 21:10:09 +0000 (23:10 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 9 Jun 2017 19:17:41 +0000 (21:17 +0200)
- added controller for business contacts (non-administrative)
- added converter for business contacts which

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jjobs/beans/businesscontact/JobsBusinessContactWebSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jjobs/beans/businesscontact/JobsBusinessContactWebSessionController.java [new file with mode: 0644]
src/java/org/mxchange/jjobs/converter/businesscontact/JobsBusinessContactConverter.java [new file with mode: 0644]

diff --git a/src/java/org/mxchange/jjobs/beans/businesscontact/JobsBusinessContactWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/businesscontact/JobsBusinessContactWebSessionBean.java
new file mode 100644 (file)
index 0000000..a8dd55b
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.beans.businesscontact;
+
+import java.util.Collections;
+import java.util.List;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.SessionScoped;
+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.jcontactsbusiness.BusinessContact;
+import org.mxchange.jcontactsbusiness.BusinessContactSessionBeanRemote;
+import org.mxchange.jfinancials.beans.BaseFinancialsController;
+import org.mxchange.jfinancials.beans.login.user.FinancialsUserLoginWebSessionController;
+
+/**
+ * A business contact bean (controller)
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("businessContactController")
+@SessionScoped
+public class JobsBusinessContactWebSessionBean extends BaseFinancialsController implements JobsBusinessContactWebSessionController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 56_189_028_928_371L;
+
+       /**
+        * Remote contact bean
+        */
+       private BusinessContactSessionBeanRemote businessContactBean;
+
+       /**
+        * A list of all registered companies (globally)
+        */
+       private List<BusinessContact> registeredCompanies;
+
+       /**
+        * User instance
+        */
+       @Inject
+       private FinancialsUserLoginWebSessionController userLoginController;
+
+       /**
+        * Constructor
+        */
+       public JobsBusinessContactWebSessionBean () {
+               // Call super constructor
+               super();
+       }
+
+       @Override
+       public List<BusinessContact> allRegisteredCompanies () {
+               return Collections.unmodifiableList(this.registeredCompanies);
+       }
+
+       /**
+        * Post-initialization of this class
+        */
+       @PostConstruct
+       public void init () {
+               // Try it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup
+                       this.businessContactBean = (BusinessContactSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/businessContact!org.mxchange.jcontactsbusiness.BusinessContactSessionBeanRemote"); //NOI18N
+
+                       // Init list
+                       this.registeredCompanies = this.businessContactBean.allBusinessContacts();
+               } catch (final NamingException e) {
+                       // Throw again
+                       throw new FaceletException(e);
+               }
+       }
+
+}
diff --git a/src/java/org/mxchange/jjobs/beans/businesscontact/JobsBusinessContactWebSessionController.java b/src/java/org/mxchange/jjobs/beans/businesscontact/JobsBusinessContactWebSessionController.java
new file mode 100644 (file)
index 0000000..ff839ff
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.beans.businesscontact;
+
+import java.io.Serializable;
+import java.util.List;
+import javax.ejb.Local;
+import org.mxchange.jcontactsbusiness.BusinessContact;
+
+/**
+ * An interface for session-scoped financial controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Local
+public interface JobsBusinessContactWebSessionController extends Serializable {
+
+       /**
+        * Returns a list of all registered companies
+        * <p>
+        * @return A list of all registered companies
+        */
+       List<BusinessContact> allRegisteredCompanies ();
+
+}
diff --git a/src/java/org/mxchange/jjobs/converter/businesscontact/JobsBusinessContactConverter.java b/src/java/org/mxchange/jjobs/converter/businesscontact/JobsBusinessContactConverter.java
new file mode 100644 (file)
index 0000000..18175b1
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.converter.businesscontact;
+
+import java.text.MessageFormat;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.convert.FacesConverter;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontactsbusiness.BusinessContact;
+import org.mxchange.jcontactsbusiness.BusinessContactSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.exceptions.BusinessContactNotFoundException;
+
+/**
+ * Converter for contact id <-> valid business contact instance
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesConverter (value = "BusinessContactConverter")
+public class JobsBusinessContactConverter implements Converter {
+
+       /**
+        * Business contact EJB
+        */
+       private BusinessContactSessionBeanRemote businessContactBean;
+
+       /**
+        * Initialization of this converter
+        */
+       public JobsBusinessContactConverter () {
+               // Try to get it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // ... and user controller
+                       this.businessContactBean = (BusinessContactSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/businessContact!org.mxchange.jcontactsbusiness.BusinessContactSessionBeanRemote"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw it
+                       throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+               }
+       }
+
+       @Override
+       public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
+               // Is the value null or empty?
+               if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
+                       // Warning message
+                       // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
+
+                       // Return null
+                       return null;
+               }
+
+               // Init instance
+               BusinessContact businessContact = null;
+
+               try {
+                       // Try to parse the value as long
+                       Long contactId = Long.valueOf(submittedValue);
+
+                       // Try to get user instance from it
+                       businessContact = this.businessContactBean.findBusinessContactById(contactId);
+               } catch (final NumberFormatException ex) {
+                       // Throw again
+                       throw new ConverterException(ex);
+               } catch (final BusinessContactNotFoundException ex) {
+                       // Debug message
+                       // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
+               }
+
+               // Return it
+               return businessContact;
+       }
+
+       @Override
+       public String getAsString (final FacesContext context, final UIComponent component, final Object value) {
+               // Is the object null?
+               if ((null == value) || ((String.valueOf(value)).isEmpty())) {
+                       // Is null
+                       return ""; //NOI18N
+               } else if (!(value instanceof Contact)) {
+                       // Not same interface
+                       throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement Contact.", value)); //NOI18N
+               }
+
+               // Return category id
+               return String.valueOf(((BusinessContact) value).getBusinessContactId());
+       }
+
+}