OSGi Events for Communities Components
- Onderwerpen:
- Communities
Gemaakt voor:
- User
Overzicht
Wanneer leden met de eigenschappen van de Gemeenschappen in wisselwerking staan, worden de gebeurtenissen OSGi verzonden die asynchrone luisteraars, zoals berichten of gamificatie (het scoren en het merken) kunnen teweegbrengen.
Een component SocialEvent instantie neemt de gebeurtenissen op als actions
die voor een topic
. De SocialEvent bevat een methode om een verb
aan de handeling is gekoppeld. Er is een n-1 relatie tussen actions
en verbs
.
Voor de onderdelen van Communities die in de release worden geleverd, wordt in de volgende tabellen de verbs
gedefinieerd voor elk topic
beschikbaar voor gebruik.
Onderwerpen en werven
Kalendercomponent
SocialEvent topic
= com/adobe/cq/social/agenda
Verb | Beschrijving |
---|---|
POST | lid maakt een agendagebeurtenis |
TOEVOEGEN | opmerkingen van leden over een agendagebeurtenis |
BIJWERKEN | agendagebeurtenis of commentaar van lid wordt bewerkt |
DELETE | agendagebeurtenis of commentaar van lid wordt verwijderd |
Component Opmerkingen
SocialEvent topic
= com/adobe/cq/social/comment
Verb | Beschrijving |
---|---|
POST | lid maakt een opmerking |
TOEVOEGEN | reactie van lid op opmerking |
BIJWERKEN | commentaar van lid is bewerkt |
DELETE | commentaar van lid is verwijderd |
Bestandsbibliotheekcomponent
SocialEvent topic
= com/adobe/cq/social/fileLibrary
Verb | Beschrijving |
---|---|
POST | lid maakt een map |
ATTACH | lid uploadt een bestand |
BIJWERKEN | lid werkt een map of bestand bij |
DELETE | lid verwijdert een map of bestand |
Forum-component
SocialEvent topic
= com/adobe/cq/social/forum
Verb | Beschrijving |
---|---|
POST | lid maakt forum-onderwerp |
TOEVOEGEN | reacties van leden op forum onderwerp |
BIJWERKEN | onderwerp of antwoord van lid wordt bewerkt |
DELETE | forumonderwerp of antwoord van lid wordt verwijderd |
Journal-component
SocialEvent topic
= com/adobe/cq/social/journaal
Verb | Beschrijving |
---|---|
POST | lid maakt een blogartikel |
TOEVOEGEN | commentaar van leden op blogartikel |
BIJWERKEN | blogartikel of commentaar van lid wordt bewerkt |
DELETE | blogartikel of commentaar van lid is verwijderd |
QnA-component
SocialEvent topic
= com/adobe/cq/social/qna
Verb | Beschrijving |
---|---|
POST | lid maakt een QnA-vraag |
TOEVOEGEN | lid maakt een QnA-antwoord |
BIJWERKEN | Vraag of antwoord van lid wordt bewerkt |
SELECT | het antwoord van lid is geselecteerd |
SELECTEREN OPHEFFEN | het antwoord van het lid is gedeselecteerd |
DELETE | Vraag of antwoord van lid wordt verwijderd |
Component Reviews
SocialEvent topic
= com/adobe/cq/social/review
Verb | Beschrijving |
---|---|
POST | lid maakt beoordeling |
BIJWERKEN | beoordeling door lid wordt bewerkt |
DELETE | beoordeling door lid is verwijderd |
Beoordelingscomponent
SocialEvent topic
= com/adobe/cq/social/tally
Verb | Beschrijving |
---|---|
WAARDERING TOEVOEGEN | de inhoud van het lid is opgegeven |
RATING VERWIJDEREN | de inhoud van het lid is neergezet |
Stemcomponent
SocialEvent topic
= com/adobe/cq/social/tally
Verb | Beschrijving |
---|---|
STEMMING TOEVOEGEN | de inhoud van het lid is in stemming gebracht |
STEMMING VERWIJDEREN | over de inhoud van het lid is gestemd |
Componenten met moderatie
SocialEvent topic
= com/adobe/cq/social/moderation
Verb | Beschrijving |
---|---|
DENKEN | inhoud van lid wordt geweigerd |
VLAG ALS ONJUIST | inhoud van lid is gemarkeerd |
ONGESCHIKTE LAG ALS ONJUIST | inhoud van lid is ongemarkeerd |
ACCEPTEREN | de inhoud van het lid wordt goedgekeurd door moderator |
SLUITEN | lid sluit commentaar op bewerkingen en reacties |
OPENEN | opmerking opnieuw openen lid |
Gebeurtenissen voor aangepaste componenten
Voor een aangepaste component wordt de abstracte klasse van SocialEvent moet d worden uitgebreid om de gebeurtenissen van de component als te registreren actions
die voor een topic
.
De aangepaste gebeurtenis zou de methode overschrijven getVerb()
zodat verb
is geretourneerd voor elk action
. De verb
De geretourneerde waarde voor een handeling kan een veelgebruikte handeling zijn (zoals POST
) of een voor de component gespecialiseerde instantie (zoals ADD RATING
). Er is een n-1 relatie tussen actions
en verbs
.
Pseudo-code voor gebeurtenis Custom Component
org.osgi.service.event.Event;
com.adobe.cq.social.scf.core.SocialEvent;
com.adobe.granite.activitystreams.ObjectTypes;
com.adobe.granite.activity streams.Verbs;
package com.mycompany.recipe;
import org.osgi.service.event.Event;
import com.adobe.cq.social.scf.core.SocialEvent;
import com.adobe.granite.activitystreams.ObjectTypes;
import com.adobe.granite.activitystreams.Verbs;
/*
* The Recipe type, passed to RecipeEvent(), would be a custom Recipe class
* that extends either
* com.adobe.cq.social.scf.SocialComponent
* or
* com.adobe.cq.social.scf.SocialCollectionComponent
* See https://docs.adobe.com/docs/en/aem/6-2/develop/communities/scf/server-customize.html
*/
/**
* Defines events that are triggered on a custom component, "Recipe".
*/
public class RecipeEvent extends SocialEvent<RecipeEvent.RecipeActions> {
private static final long serialVersionUID = 1L;
protected static final String PARENT_PATH = "PARENT_PATH";
/**
* The event topic suffix for Recipe events
*/
public static final String RECIPE_TOPIC = "recipe";
/**
* @param recipe - the recipe resource on which the event was triggered
* @param userId - the user id of the user who triggered the action
* @param action - the recipe action that triggered this event
*/
public RecipeEvent(final Recipe recipe, final String userId, final RecipeEvent.RecipeActions action) {
String recipePath = recipe.getResource().getPath();
String parentPath = (recipe.getParentComponent() != null) ?
recipe.getParentComponent().getResource().getPath() :
recipe.getSourceComponentId();
this(recipePath, userId, parentPath, action);
}
/**
* @param recipePath - the path to the recipe resource (jcr node) on which the event was triggered
* @param userId - the user id of the user who triggered the action
* @param parentPath - the path to the parent node of the recipe resource
* @param action - the recipe action that triggered this event
*/
public RecipeEvent(final String recipePath, final String userId, final String parentPath) {
super(RECIPE_TOPIC, recipePath, userId, action,
new BaseEventObject(recipePath, ObjectTypes.ARTICLE),
new BaseEventObject(parentPath, ObjectTypes.COLLECTION),
new HashMap<String, Object>(1) {
private static final long serialVersionUID = 1L;
{
if (parentPath != null) {
this.put(PARENT_PATH, parentPath);
}
}
});
}
private RecipeEvent (final Event event) {
super(event);
}
/**
* List of available recipe actions that can trigger a recipe event.
*/
public static enum RecipeActions implements SocialEvent.SocialActions {
RecipeAdded,
RecipeModified,
RecipeDeleted;
@Override
public String getVerb() {
switch (this) {
case RecipeAdded:
return Verbs.POST;
case RecipeModified:
return Verbs.UPDATE;
case RecipeDeleted:
return Verbs.DELETE;
default:
throw new IllegalArgumentException("Unsupported action");
}
}
}
}
Voorbeeld van gebeurtenislistener om activiteitsstroomgegevens te filteren
Het is mogelijk naar gebeurtenissen te luisteren om te wijzigen wat er in de activiteitsstroom wordt weergegeven.
In het volgende pseudo-codevoorbeeld worden DELETE-gebeurtenissen voor de component Comments verwijderd uit de activiteitsstroom.
Pseudo-code voor EventListener
Vereisten nieuwste functiepakket.
package my.company.comments;
import java.util.Collections;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;
import com.adobe.cq.social.activitystreams.listener.api.ActivityStreamProviderExtension;
import com.adobe.cq.social.commons.events.CommentEvent.CommentActions;
import com.adobe.cq.social.scf.core.SocialEvent;
@Service
@Component(metatype = true, label = "My Comment Delete Event Filter",
description = "Prevents comment DELETE events from showing up in activity streams")
public class CommentDeleteEventActivityFilter implements ActivityStreamProviderExtension {
@Property(name = "ranking", intValue = 10)
protected int ranking;
@Activate
public void activate(final ComponentContext ctx) {
ranking = PropertiesUtil.toInteger(ctx.getProperties().get("ranking"), 10);
}
@Modified
public void update(final Map<String, Object> props) {
ranking = PropertiesUtil.toInteger(props.get("ranking"), 10);
}
@Override
public boolean evaluate(final SocialEvent<?> evt, final Resource resource) {
if (evt.getAction() != null && evt.getAction() instanceof SocialEvent.SocialActions) {
final SocialEvent.SocialActions action = evt.getAction();
if (StringUtils.equals(action.getVerb(), CommentActions.DELETED.getVerb())) {
return false;
}
}
return true;
}
@Override
public Map<String, ? extends Object> getActivityProperties(final SocialEvent<?> arg0, final Resource arg1) {
return Collections.<String, Object>emptyMap();
}
@Override
public Map<String, ? extends Object> getActorProperties(final SocialEvent<?> arg0, final Resource arg1) {
return Collections.<String, Object>emptyMap();
}
@Override
public String getName() {
return "My Comment Delete Event Filter";
}
@Override
public Map<String, ? extends Object> getObjectProperties(final SocialEvent<?> arg0, final Resource arg1) {
return Collections.<String, Object>emptyMap();
}
/* Ensure a custom extension is registered with a ranking lower than any existing implementation in the product. */
@Override
public int getRanking() {
return this.ranking;
}
@Override
public Map<String, ? extends Object> getTargetProperties(final SocialEvent<?> arg0, final Resource arg1) {
return Collections.<String, Object>emptyMap();
}
@Override
public String[] getStreamProviderPid() {
return new String[]{"*"};
}
}