diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/Activatable.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/Activatable.java new file mode 100644 index 00000000..2eb27d91 --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/Activatable.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.gbl.model; + +public interface Activatable { + + boolean isActive(); + +} diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/activation/EntityActivationEvent.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/activation/EntityActivationEvent.java new file mode 100644 index 00000000..3cd03ac3 --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/activation/EntityActivationEvent.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.webservice.servicelayer.activation; + +import org.springframework.context.ApplicationEvent; + +import ch.ethz.seb.sebserver.gbl.model.Entity; + +public final class EntityActivationEvent extends ApplicationEvent { + + private static final long serialVersionUID = -6712364320755441148L; + + public final boolean activated; + public final Entity entity; + + public EntityActivationEvent(final Entity source, final boolean activated) { + super(source); + this.entity = source; + this.activated = activated; + } + +} diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ActivatableEntityDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ActivatableEntityDAO.java new file mode 100644 index 00000000..1f50b0c3 --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ActivatableEntityDAO.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.webservice.servicelayer.dao; + +import java.util.Collection; + +import ch.ethz.seb.sebserver.gbl.model.Entity; +import ch.ethz.seb.sebserver.gbl.util.Result; + +/** Interface of a DAO for an Entity that has activation feature. + * + * @param the concrete Entity type */ +public interface ActivatableEntityDAO { + + /** Get a Collection of all active Entity instances for a concrete entity-domain. + * + * @return A Result refer to a Collection of all active Entity instances for a concrete entity-domain + * or refer to an error if happened */ + Result> allActive(); + + /** Set the entity with specified identifier active / inactive + * + * @param entityId The Entity identifier + * @param active The active flag + * @return A Result refer to the Entity instance or refer to an error if happened */ + Result setActive(String entityId, boolean active); + + /** Get notified if some Entity instance has been activated + * This can be used to take action in dependency of an activation of an Entity of different type. + * For example a user-account DAO want to react on a Institution activation to also activate all user + * accounts for this institution. + * + * @param source The source Entity that has been activated */ + void notifyActivation(Entity source); + + /** Get notified if some Entity instance has been deactivated + * This can be used to take action in dependency of an deactivation of an Entity of different type. + * For example a user-account DAO want to react on a Institution deactivation to also deactivate all user + * accounts for this institution. + * + * @param source The source Entity that has been deactivated */ + void notifyDeactivation(Entity source); + +}