From: Roland Häder Date: Sun, 10 May 2020 03:28:22 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3158707ad18b88f19e4c61c6e7ebe71da2f23cbf;p=jcontacts-business-core.git Continued: - added utilities method copyDepartmentData() - added AdminUpdatedDepartmentEvent class and interface - renamed DepartmentAddedEvent to AdminDeaprtmentAddedEvent Signed-off-by: Roland Häder --- 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 . + */ +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 + *

+ * @author Roland Häder + */ +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 + *

+ * @param addedDepartment Branch office instance + *

+ * @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/DepartmentAddedEvent.java b/src/org/mxchange/jcontactsbusiness/events/department/added/DepartmentAddedEvent.java deleted file mode 100644 index 97de10d..0000000 --- a/src/org/mxchange/jcontactsbusiness/events/department/added/DepartmentAddedEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 . - */ -package org.mxchange.jcontactsbusiness.events.department.added; - -import java.text.MessageFormat; -import org.mxchange.jcontactsbusiness.model.department.Department; - -/** - * An event being fired when a department has been added - *

- * @author Roland Häder - */ -public class DepartmentAddedEvent implements ObservableDepartmentAddedEvent { - - /** - * Serial number - */ - private static final long serialVersionUID = 572_367_561_659_111L; - - /** - * Branch office instance being added - */ - private final Department department; - - /** - * Constructor with department instance - *

- * @param department Branch office instance - *

- * @throws NullPointerException If the parameter is null - */ - public DepartmentAddedEvent (final Department department) { - // Check parameter - if (null == department) { - // Throw NPE - throw new NullPointerException("department is null"); //NOI18N - } else if (department.getDepartmentId() == null) { - // Throw NPE again - throw new NullPointerException("department.departmentId is null"); //NOI18N - } else if (department.getDepartmentId() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("department.departmentId={0} is not valid", department.getDepartmentId())); //NOI18N - } - - // Set it - this.department = department; - } - - @Override - public Department getDepartment () { - return this.department; - } - -} diff --git a/src/org/mxchange/jcontactsbusiness/events/department/added/ObservableAdminDepartmentAddedEvent.java b/src/org/mxchange/jcontactsbusiness/events/department/added/ObservableAdminDepartmentAddedEvent.java new file mode 100644 index 0000000..80653be --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/events/department/added/ObservableAdminDepartmentAddedEvent.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 . + */ +package org.mxchange.jcontactsbusiness.events.department.added; + +import java.io.Serializable; +import org.mxchange.jcontactsbusiness.model.department.Department; + +/** + * An interface for events being fired when a department has been added by an + * administrator. + *

+ * @author Roland Häder + */ +public interface ObservableAdminDepartmentAddedEvent extends Serializable { + + /** + * Getter for added department instance + *

+ * @return Added department instance + */ + Department getAddedDepartment (); + +} diff --git a/src/org/mxchange/jcontactsbusiness/events/department/added/ObservableDepartmentAddedEvent.java b/src/org/mxchange/jcontactsbusiness/events/department/added/ObservableDepartmentAddedEvent.java deleted file mode 100644 index bbdae8c..0000000 --- a/src/org/mxchange/jcontactsbusiness/events/department/added/ObservableDepartmentAddedEvent.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 . - */ -package org.mxchange.jcontactsbusiness.events.department.added; - -import java.io.Serializable; -import org.mxchange.jcontactsbusiness.model.department.Department; - -/** - * An interface for events being fired when a department has been added. - *

- * @author Roland Häder - */ -public interface ObservableDepartmentAddedEvent extends Serializable { - - /** - * Getter for department instance - *

- * @return Department instance - */ - Department getDepartment (); - -} diff --git a/src/org/mxchange/jcontactsbusiness/events/department/updated/AdminDepartmentUpdatedEvent.java b/src/org/mxchange/jcontactsbusiness/events/department/updated/AdminDepartmentUpdatedEvent.java new file mode 100644 index 0000000..682e3b8 --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/events/department/updated/AdminDepartmentUpdatedEvent.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 . + */ +package org.mxchange.jcontactsbusiness.events.department.updated; + +import java.text.MessageFormat; +import org.mxchange.jcontactsbusiness.model.department.Department; + +/** + * An event being fired when a department has been added + *

+ * @author Roland Häder + */ +public class AdminDepartmentUpdatedEvent implements ObservableAdminDepartmentUpdatedEvent { + + /** + * Serial number + */ + private static final long serialVersionUID = 572_367_561_659_115L; + + /** + * Branch office instance being added + */ + private final Department updatedDepartment; + + /** + * Constructor with department instance + *

+ * @param updatedDepartment Branch office instance + *

+ * @throws NullPointerException If the parameter is null + */ + public AdminDepartmentUpdatedEvent (final Department updatedDepartment) { + // Check parameter + if (null == updatedDepartment) { + // Throw NPE + throw new NullPointerException("department is null"); //NOI18N + } else if (updatedDepartment.getDepartmentId() == null) { + // Throw NPE again + throw new NullPointerException("department.departmentId is null"); //NOI18N + } else if (updatedDepartment.getDepartmentId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("department.departmentId={0} is not valid", updatedDepartment.getDepartmentId())); //NOI18N + } + + // Set it + this.updatedDepartment = updatedDepartment; + } + + @Override + 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 . + */ +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. + *

+ * @author Roland Häder + */ +public interface ObservableAdminDepartmentUpdatedEvent extends Serializable { + + /** + * Getter for updated department instance + *

+ * @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. + *

+ * @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.