From 224591960fb1dd6d9761b4db080fed0b68a813ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 15 Aug 2016 13:00:00 +0200 Subject: [PATCH] Please cherry-pick: - splitted contact remote interface into general and administrative purposes --- .../contact/JobsContactSessionBean.java | 35 ------ .../LandingAdminContactSessionBean.java | 101 ++++++++++++++++++ 2 files changed, 101 insertions(+), 35 deletions(-) create mode 100644 src/java/org/mxchange/jcontacts/contact/LandingAdminContactSessionBean.java diff --git a/src/java/org/mxchange/jcontacts/contact/JobsContactSessionBean.java b/src/java/org/mxchange/jcontacts/contact/JobsContactSessionBean.java index 8eafc5c..4bb8b9c 100644 --- a/src/java/org/mxchange/jcontacts/contact/JobsContactSessionBean.java +++ b/src/java/org/mxchange/jcontacts/contact/JobsContactSessionBean.java @@ -17,7 +17,6 @@ package org.mxchange.jcontacts.contact; import java.text.MessageFormat; -import java.util.GregorianCalendar; import java.util.Iterator; import java.util.List; import java.util.Objects; @@ -25,7 +24,6 @@ import javax.ejb.Stateless; import javax.persistence.NoResultException; import javax.persistence.Query; import org.mxchange.jcontacts.contact.utils.ContactUtils; -import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jjobs.database.BaseJobsDatabaseBean; @@ -48,39 +46,6 @@ public class JobsContactSessionBean extends BaseJobsDatabaseBean implements Cont public JobsContactSessionBean () { } - @Override - public Contact addContact (final Contact contact) throws ContactAlreadyAddedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addContact: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Is the instance set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() != null) { - // Should be null - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} - is not null", contact.getContactId())); //NOI18N - } - - // Set created timestamp - contact.setContactCreated(new GregorianCalendar()); - - // Set all created timestamps, if instance is there - this.setAllContactPhoneEntriesCreated(contact); - - // Persist it - this.getEntityManager().persist(contact); - - // Flush it to get contactId set - this.getEntityManager().flush(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addContact: contact.contactId={1} after persisting - EXIT!", this.getClass().getSimpleName(), contact.getContactId())); //NOI18N - - // Return it - return contact; - } - @Override public Contact findContactByEmailAddress (final String emailAddress) throws ContactNotFoundException { // Log trace message diff --git a/src/java/org/mxchange/jcontacts/contact/LandingAdminContactSessionBean.java b/src/java/org/mxchange/jcontacts/contact/LandingAdminContactSessionBean.java new file mode 100644 index 0000000..dbbe9f1 --- /dev/null +++ b/src/java/org/mxchange/jcontacts/contact/LandingAdminContactSessionBean.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2016 Cho-Time GmbH + * + * 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 . + */ +package org.mxchange.jcontacts.contact; + +import de.chotime.landingpage.database.BaseLandingDatabaseBean; +import java.text.MessageFormat; +import java.util.GregorianCalendar; +import javax.ejb.Stateless; +import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; + +/** + * An administrative contact EJB + *

+ * @author Roland Haeder + */ +@Stateless (name = "adminContact", description = "An administrative contact EJB") +public class LandingAdminContactSessionBean extends BaseLandingDatabaseBean implements AdminContactSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 542_145_347_916L; + + /** + * Default constructor + */ + public LandingAdminContactSessionBean () { + } + + @Override + public Contact addContact (final Contact contact) throws ContactAlreadyAddedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addContact: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N + + // Is the instance set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() != null) { + // Should be null + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} - is not null", contact.getContactId())); //NOI18N + } + + // Set created timestamp + contact.setContactCreated(new GregorianCalendar()); + + // Set all created timestamps, if instance is there + this.setAllContactPhoneEntriesCreated(contact); + + // Persist it + this.getEntityManager().persist(contact); + + // Flush it to get contactId set + this.getEntityManager().flush(); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addContact: contact.contactId={1} after persisting - EXIT!", this.getClass().getSimpleName(), contact.getContactId())); //NOI18N + + // Return it + return contact; + } + + @Override + public void deleteContactData (Contact contact) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N + + // Is the instance set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() != null) { + // Should be null + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} - is not null", contact.getContactId())); //NOI18N + } + + // Merge it to get a managed entity back + Contact managedContact = this.getEntityManager().getReference(contact.getClass(), contact.getContactId()); + + // Remove it from database + this.getEntityManager().remove(managedContact); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteContactData: EXIT!", this.getClass().getSimpleName())); + } + +} -- 2.39.5