Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #8896 #1016

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
import java.io.Serializable;

/**
* Abstract listener of deletion events to remove all subscriptions on the deleted resource.
* Abstract listener of events to remove all the subscriptions on a deleted resource or on a
* resource for which the subscription feature is disabled.
* It does really the unsubscription and delegates the getting of the subscription resource to the
* concrete implementors.
* @author mmoquillon
Expand All @@ -49,7 +50,18 @@ public void onDeletion(final T event) throws Exception {
subscriptionService.unsubscribeByResource(resource);
}

@Override
public void onUpdate(final T event) throws Exception {
final R object = event.getTransition().getAfter();
final boolean isEnabled = isSubscriptionEnabled(object);
if (!isEnabled) {
final SubscriptionResource resource = getSubscriptionResource(object);
subscriptionService.unsubscribeByResource(resource);
}
}

protected abstract SubscriptionResource getSubscriptionResource(final R resource);

protected abstract boolean isSubscriptionEnabled(final R resource);
}

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@
*/
public interface ResourceSubscriptionService {

/**
* Some predefined constants to use by Silverpeas components to support identical behaviours.
*/
class Constants {

private Constants() {
}

/**
* Configuration parameter to enable or not the subscription on the resource on which the
* parameter is applied. Usually it is used in some component instances' configuration. Any
* change in the value of this parameter is listened by the subscription transverse service to
* update all the actual subscriptions on the concerned resource.
*/
public static final String SUBSCRIPTION_PARAMETER = "useSubscription";
}

/**
* Gets all subscribers registered on a component.<br>
* This service does not look at resources handled by the component but just explicit component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@
package org.silverpeas.core.subscription;

import org.silverpeas.core.admin.component.model.ComponentInst;
import org.silverpeas.core.admin.component.model.Parameter;
import org.silverpeas.core.admin.component.notification.ComponentInstanceEvent;
import org.silverpeas.core.subscription.service.ComponentSubscriptionResource;
import org.silverpeas.core.util.StringUtil;

import javax.inject.Singleton;

/**
* Listener of the events on the deletion of a component instance to delete all the subscriptions
* on that component instance (and hence on its resources).
* Listener of the events on the deletion or on an update of a component instance. If the component
* instance is deleted or if the subscription on the component instance is disabled, then remove all
* the subscriptions on that component instance (and hence on its resources).
* @author mmoquillon
*/
@Singleton
Expand All @@ -43,5 +46,12 @@ public class SubscriptionComponentInstEventListener
protected SubscriptionResource getSubscriptionResource(final ComponentInst resource) {
return ComponentSubscriptionResource.from(resource.getId());
}

@Override
protected boolean isSubscriptionEnabled(final ComponentInst resource) {
final Parameter parameter =
resource.getParameter(ResourceSubscriptionService.Constants.SUBSCRIPTION_PARAMETER);
return parameter == null || StringUtil.getBooleanValue(parameter.getValue());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ public class SubscriptionNodeEventListener
protected SubscriptionResource getSubscriptionResource(final NodeDetail resource) {
return NodeSubscriptionResource.from(resource.getNodePK());
}

@Override
protected boolean isSubscriptionEnabled(final NodeDetail resource) {
return true;
}
}