From 3158707ad18b88f19e4c61c6e7ebe71da2f23cbf Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Sun, 10 May 2020 05:28:22 +0200
Subject: [PATCH] Continued: - added utilities method copyDepartmentData() -
 added AdminUpdatedDepartmentEvent class and interface - renamed
 DepartmentAddedEvent to AdminDeaprtmentAddedEvent
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder <roland@mxchange.org>
---
 .../added/AdminDepartmentAddedEvent.java      | 68 +++++++++++++++++++
 ... ObservableAdminDepartmentAddedEvent.java} | 11 +--
 .../AdminDepartmentUpdatedEvent.java}         | 26 +++----
 ...ObservableAdminDepartmentUpdatedEvent.java | 37 ++++++++++
 .../model/department/Departments.java         | 29 ++++++++
 5 files changed, 153 insertions(+), 18 deletions(-)
 create mode 100644 src/org/mxchange/jcontactsbusiness/events/department/added/AdminDepartmentAddedEvent.java
 rename src/org/mxchange/jcontactsbusiness/events/department/added/{ObservableDepartmentAddedEvent.java => ObservableAdminDepartmentAddedEvent.java} (82%)
 rename src/org/mxchange/jcontactsbusiness/events/department/{added/DepartmentAddedEvent.java => updated/AdminDepartmentUpdatedEvent.java} (68%)
 create mode 100644 src/org/mxchange/jcontactsbusiness/events/department/updated/ObservableAdminDepartmentUpdatedEvent.java

diff --git a/src/org/mxchange/jcontactsbusiness/events/department/added/AdminDepartmentAddedEvent.java b/src/org/mxchange/jcontactsbusiness/events/department/added/AdminDepartmentAddedEvent.java
new file mode 100644
index 0000000..1e29963
--- /dev/null
+++ b/src/org/mxchange/jcontactsbusiness/events/department/added/AdminDepartmentAddedEvent.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2017 - 2020 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.events.department.added;
+
+import java.text.MessageFormat;
+import org.mxchange.jcontactsbusiness.model.department.Department;
+
+/**
+ * An event being fired when a addedDepartment has been added
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class AdminDepartmentAddedEvent implements ObservableAdminDepartmentAddedEvent {
+
+	/**
+	 * Serial number
+	 */
+	private static final long serialVersionUID = 572_367_561_659_111L;
+
+	/**
+	 * Branch office instance being added
+	 */
+	private final Department addedDepartment;
+
+	/**
+	 * Constructor with addedDepartment instance
+	 * <p>
+	 * @param addedDepartment Branch office instance
+	 * <p>
+	 * @throws NullPointerException If the parameter is null
+	 */
+	public AdminDepartmentAddedEvent (final Department addedDepartment) {
+		// Check parameter
+		if (null == addedDepartment) {
+			// Throw NPE
+			throw new NullPointerException("addedDepartment is null"); //NOI18N
+		} else if (addedDepartment.getDepartmentId() == null) {
+			// Throw NPE again
+			throw new NullPointerException("addedDepartment.departmentId is null"); //NOI18N
+		} else if (addedDepartment.getDepartmentId() < 1) {
+			// Throw NPE again
+			throw new NullPointerException(MessageFormat.format("addedDepartment.departmentId={0} is not valid", addedDepartment.getDepartmentId())); //NOI18N
+		}
+
+		// Set it
+		this.addedDepartment = addedDepartment;
+	}
+
+	@Override
+	public Department getAddedDepartment () {
+		return this.addedDepartment;
+	}
+
+}
diff --git a/src/org/mxchange/jcontactsbusiness/events/department/added/ObservableDepartmentAddedEvent.java b/src/org/mxchange/jcontactsbusiness/events/department/added/ObservableAdminDepartmentAddedEvent.java
similarity index 82%
rename from src/org/mxchange/jcontactsbusiness/events/department/added/ObservableDepartmentAddedEvent.java
rename to src/org/mxchange/jcontactsbusiness/events/department/added/ObservableAdminDepartmentAddedEvent.java
index bbdae8c..80653be 100644
--- a/src/org/mxchange/jcontactsbusiness/events/department/added/ObservableDepartmentAddedEvent.java
+++ b/src/org/mxchange/jcontactsbusiness/events/department/added/ObservableAdminDepartmentAddedEvent.java
@@ -20,17 +20,18 @@ import java.io.Serializable;
 import org.mxchange.jcontactsbusiness.model.department.Department;
 
 /**
- * An interface for events being fired when a department has been added.
+ * An interface for events being fired when a department has been added by an
+ * administrator.
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface ObservableDepartmentAddedEvent extends Serializable {
+public interface ObservableAdminDepartmentAddedEvent extends Serializable {
 
 	/**
-	 * Getter for department instance
+	 * Getter for added department instance
 	 * <p>
-	 * @return Department instance
+	 * @return Added department instance
 	 */
-	Department getDepartment ();
+	Department getAddedDepartment ();
 
 }
diff --git a/src/org/mxchange/jcontactsbusiness/events/department/added/DepartmentAddedEvent.java b/src/org/mxchange/jcontactsbusiness/events/department/updated/AdminDepartmentUpdatedEvent.java
similarity index 68%
rename from src/org/mxchange/jcontactsbusiness/events/department/added/DepartmentAddedEvent.java
rename to src/org/mxchange/jcontactsbusiness/events/department/updated/AdminDepartmentUpdatedEvent.java
index 97de10d..682e3b8 100644
--- a/src/org/mxchange/jcontactsbusiness/events/department/added/DepartmentAddedEvent.java
+++ b/src/org/mxchange/jcontactsbusiness/events/department/updated/AdminDepartmentUpdatedEvent.java
@@ -14,7 +14,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-package org.mxchange.jcontactsbusiness.events.department.added;
+package org.mxchange.jcontactsbusiness.events.department.updated;
 
 import java.text.MessageFormat;
 import org.mxchange.jcontactsbusiness.model.department.Department;
@@ -24,45 +24,45 @@ import org.mxchange.jcontactsbusiness.model.department.Department;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public class DepartmentAddedEvent implements ObservableDepartmentAddedEvent {
+public class AdminDepartmentUpdatedEvent implements ObservableAdminDepartmentUpdatedEvent {
 
 	/**
 	 * Serial number
 	 */
-	private static final long serialVersionUID = 572_367_561_659_111L;
+	private static final long serialVersionUID = 572_367_561_659_115L;
 
 	/**
 	 * Branch office instance being added
 	 */
-	private final Department department;
+	private final Department updatedDepartment;
 
 	/**
 	 * Constructor with department instance
 	 * <p>
-	 * @param department Branch office instance
+	 * @param updatedDepartment Branch office instance
 	 * <p>
 	 * @throws NullPointerException If the parameter is null
 	 */
-	public DepartmentAddedEvent (final Department department) {
+	public AdminDepartmentUpdatedEvent (final Department updatedDepartment) {
 		// Check parameter
-		if (null == department) {
+		if (null == updatedDepartment) {
 			// Throw NPE
 			throw new NullPointerException("department is null"); //NOI18N
-		} else if (department.getDepartmentId() == null) {
+		} else if (updatedDepartment.getDepartmentId() == null) {
 			// Throw NPE again
 			throw new NullPointerException("department.departmentId is null"); //NOI18N
-		} else if (department.getDepartmentId() < 1) {
+		} else if (updatedDepartment.getDepartmentId() < 1) {
 			// Throw NPE again
-			throw new NullPointerException(MessageFormat.format("department.departmentId={0} is not valid", department.getDepartmentId())); //NOI18N
+			throw new NullPointerException(MessageFormat.format("department.departmentId={0} is not valid", updatedDepartment.getDepartmentId())); //NOI18N
 		}
 
 		// Set it
-		this.department = department;
+		this.updatedDepartment = updatedDepartment;
 	}
 
 	@Override
-	public Department getDepartment () {
-		return this.department;
+	public Department getUpdatedDepartment () {
+		return this.updatedDepartment;
 	}
 
 }
diff --git a/src/org/mxchange/jcontactsbusiness/events/department/updated/ObservableAdminDepartmentUpdatedEvent.java b/src/org/mxchange/jcontactsbusiness/events/department/updated/ObservableAdminDepartmentUpdatedEvent.java
new file mode 100644
index 0000000..60f95bd
--- /dev/null
+++ b/src/org/mxchange/jcontactsbusiness/events/department/updated/ObservableAdminDepartmentUpdatedEvent.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 - 2020 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.events.department.updated;
+
+import java.io.Serializable;
+import org.mxchange.jcontactsbusiness.model.department.Department;
+
+/**
+ * An interface for events being fired when a department has been updated by an
+ * administrator.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface ObservableAdminDepartmentUpdatedEvent extends Serializable {
+
+	/**
+	 * Getter for updated department instance
+	 * <p>
+	 * @return Updated department instance
+	 */
+	Department getUpdatedDepartment ();
+
+}
diff --git a/src/org/mxchange/jcontactsbusiness/model/department/Departments.java b/src/org/mxchange/jcontactsbusiness/model/department/Departments.java
index d0b955d..6eae842 100644
--- a/src/org/mxchange/jcontactsbusiness/model/department/Departments.java
+++ b/src/org/mxchange/jcontactsbusiness/model/department/Departments.java
@@ -60,6 +60,35 @@ public class Departments implements Serializable {
 		return department1.compareTo(department2);
 	}
 
+	/**
+	 * Copies all data from source department to target department.
+	 * <p>
+	 * @param sourceDepartment Source department
+	 * @param targetDepartment Target department
+	 */
+	public static void copyDepartmentData (final Department sourceDepartment, final Department targetDepartment) {
+		// Check that both parameters are not null
+		if (null == sourceDepartment) {
+			// Throw NPE
+			throw new NullPointerException("sourceDepartment is null"); //NOI18N
+		} else if (null == targetDepartment) {
+			// Throw NPE
+			throw new NullPointerException("targetDepartment is null"); //NOI18N
+		} else if (Objects.equals(sourceDepartment, targetDepartment)) {
+			// Throw IAE
+			throw new IllegalArgumentException("sourceDepartment and targetDepartment are the same"); //NOI18N
+		}
+
+		// Copy all fields
+		targetDepartment.setDepartmentBranchOffice(sourceDepartment.getDepartmentBranchOffice());
+		targetDepartment.setDepartmentCompany(sourceDepartment.getDepartmentCompany());
+		targetDepartment.setDepartmentHeadquarter(sourceDepartment.getDepartmentHeadquarter());
+		targetDepartment.setDepartmentI18nKey(sourceDepartment.getDepartmentI18nKey());
+		targetDepartment.setDepartmentId(sourceDepartment.getDepartmentId());
+		targetDepartment.setDepartmentLead(sourceDepartment.getDepartmentLead());
+		targetDepartment.setDepartmentUserOwner(sourceDepartment.getDepartmentUserOwner());
+	}
+
 	/**
 	 * Checks if both departments are the same (entity) or if at least basic
 	 * company data and department name are matching.
-- 
2.39.5