From 6686900bfe645826f12a53ef95acd6bc95628842 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 25 Apr 2020 20:10:15 +0200 Subject: [PATCH] Continued: - renamed event for added categories as admin <-> user should be distinguished - added administrative event which can be fired when an administrator has updated a product category MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- ...vent.java => AdminAddedCategoryEvent.java} | 6 +- ...=> ObservableAdminAddedCategoryEvent.java} | 5 +- .../updated/AdminUpdatedCategoryEvent.java | 72 +++++++++++++++++++ .../ObservableAdminUpdatedCategoryEvent.java | 36 ++++++++++ 4 files changed, 114 insertions(+), 5 deletions(-) rename src/org/mxchange/jproduct/events/category/added/{CategoryAddedEvent.java => AdminAddedCategoryEvent.java} (91%) rename src/org/mxchange/jproduct/events/category/added/{AddedCategoryEvent.java => ObservableAdminAddedCategoryEvent.java} (86%) create mode 100644 src/org/mxchange/jproduct/events/category/updated/AdminUpdatedCategoryEvent.java create mode 100644 src/org/mxchange/jproduct/events/category/updated/ObservableAdminUpdatedCategoryEvent.java diff --git a/src/org/mxchange/jproduct/events/category/added/CategoryAddedEvent.java b/src/org/mxchange/jproduct/events/category/added/AdminAddedCategoryEvent.java similarity index 91% rename from src/org/mxchange/jproduct/events/category/added/CategoryAddedEvent.java rename to src/org/mxchange/jproduct/events/category/added/AdminAddedCategoryEvent.java index 3aa4113..2470d76 100644 --- a/src/org/mxchange/jproduct/events/category/added/CategoryAddedEvent.java +++ b/src/org/mxchange/jproduct/events/category/added/AdminAddedCategoryEvent.java @@ -20,11 +20,11 @@ import java.text.MessageFormat; import org.mxchange.jproduct.model.category.Category; /** - * An event fired when a new shop category has been added. + * An event fired when an administrator has added a new category. *

* @author Roland Häder */ -public class CategoryAddedEvent implements AddedCategoryEvent { +public class AdminAddedCategoryEvent implements ObservableAdminAddedCategoryEvent { /** * Serial number @@ -41,7 +41,7 @@ public class CategoryAddedEvent implements AddedCategoryEvent { *

* @param addedCategory Added category */ - public CategoryAddedEvent (final Category addedCategory) { + public AdminAddedCategoryEvent (final Category addedCategory) { // The category should be valid if (null == addedCategory) { // Is NULL, throw NPE diff --git a/src/org/mxchange/jproduct/events/category/added/AddedCategoryEvent.java b/src/org/mxchange/jproduct/events/category/added/ObservableAdminAddedCategoryEvent.java similarity index 86% rename from src/org/mxchange/jproduct/events/category/added/AddedCategoryEvent.java rename to src/org/mxchange/jproduct/events/category/added/ObservableAdminAddedCategoryEvent.java index ec41d01..b22c31f 100644 --- a/src/org/mxchange/jproduct/events/category/added/AddedCategoryEvent.java +++ b/src/org/mxchange/jproduct/events/category/added/ObservableAdminAddedCategoryEvent.java @@ -20,11 +20,12 @@ import java.io.Serializable; import org.mxchange.jproduct.model.category.Category; /** - * An interface for added category events + * An interface for events being fired when an administrator has added a + * category. *

* @author Roland Häder */ -public interface AddedCategoryEvent extends Serializable { +public interface ObservableAdminAddedCategoryEvent extends Serializable { /** * Getter for added category instance diff --git a/src/org/mxchange/jproduct/events/category/updated/AdminUpdatedCategoryEvent.java b/src/org/mxchange/jproduct/events/category/updated/AdminUpdatedCategoryEvent.java new file mode 100644 index 0000000..f497b7e --- /dev/null +++ b/src/org/mxchange/jproduct/events/category/updated/AdminUpdatedCategoryEvent.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2016 - 2020 Free Software Foundation + * + * 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.jproduct.events.category.updated; + +import java.text.MessageFormat; +import org.mxchange.jproduct.model.category.Category; + +/** + * An event fired when an administrator has updated a new category. + *

+ * @author Roland Häder + */ +public class AdminUpdatedCategoryEvent implements ObservableAdminUpdatedCategoryEvent { + + /** + * Serial number + */ + private static final long serialVersionUID = 83_275_471_765_091_761L; + + /** + * Category instance that has been added + */ + private final Category addedCategory; + + /** + * Constructor with added category instance + *

+ * @param addedCategory Added category + */ + public AdminUpdatedCategoryEvent (final Category addedCategory) { + // The category should be valid + if (null == addedCategory) { + // Is NULL, throw NPE + throw new NullPointerException("addedCategory is null"); //NOI18N + } else if (addedCategory.getCategoryI18nKey() == null) { + // Is NULL, throw NPE again + throw new NullPointerException("addedCategory.categoryI18nKey is null"); //NOI18N + } else if (addedCategory.getCategoryI18nKey().isEmpty()) { + // Empty title + throw new IllegalArgumentException("addedCategory.categoryI18nKey is empty"); //NOI18N + } else if (addedCategory.getCategoryId() == null) { + // Id is NULL + throw new NullPointerException("addedCategory.categoryId is null"); //NOI18N + } else if (addedCategory.getCategoryId() <= 0) { + // Not valid id + throw new IllegalArgumentException(MessageFormat.format("addedCategory.categoryId={0} is not valid.", addedCategory.getCategoryId())); //NOI18N + } + + // Set it here + this.addedCategory = addedCategory; + } + + @Override + public Category getAddedCategory () { + return this.addedCategory; + } + +} diff --git a/src/org/mxchange/jproduct/events/category/updated/ObservableAdminUpdatedCategoryEvent.java b/src/org/mxchange/jproduct/events/category/updated/ObservableAdminUpdatedCategoryEvent.java new file mode 100644 index 0000000..ae4a79b --- /dev/null +++ b/src/org/mxchange/jproduct/events/category/updated/ObservableAdminUpdatedCategoryEvent.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2016 - 2020 Free Software Foundation + * + * 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.jproduct.events.category.updated; + +import java.io.Serializable; +import org.mxchange.jproduct.model.category.Category; + +/** + * An interface for events when an administrator has updated a category. + *

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

+ * @return Added category instance + */ + public Category getAddedCategory (); + +} -- 2.39.5