커뮤니티 구성 요소에 대한 OSGi 이벤트 osgi-events-for-communities-components
개요 overview
구성원이 커뮤니티 기능과 상호 작용할 때 알림 또는 게임화(점수 및 배지)와 같은 비동기 리스너를 트리거할 수 있는 OSGi 이벤트가 전송됩니다.
구성 요소의 SocialEvent 인스턴스는 actions그것은 topic. SocialEvent에는 verb관련 작업을 수행한 후, 다음 항목이 있습니다 n-1 관계 간 actions및 verbs.
릴리스에서 제공되는 Communities 구성 요소의 경우 다음 표에서는 verbs각 topic사용할 수 있습니다.
항목 및 동사 topics-and-verbs
달력 구성 요소
SocialEvent topic= com/adobe/cq/social/calendar
댓글 구성 요소
SocialEvent topic= com/adobe/cq/social/comment
파일 라이브러리 구성 요소
SocialEvent topic= com/adobe/cq/social/fileLibrary
포럼 구성 요소
SocialEvent topic= com/adobe/cq/social/forum
분개 구성 요소
SocialEvent topic= com/adobe/cq/social/journal
QnA 구성 요소
SocialEvent topic = com/adobe/cq/social/qna
구성 요소 검토
SocialEvent topic= com/adobe/cq/social/review
등급 구성 요소
SocialEvent topic= com/adobe/cq/social/tally
투표 구성 요소
SocialEvent topic= com/adobe/cq/social/tally
중재 사용 구성 요소
SocialEvent topic= com/adobe/cq/social/moderation
사용자 지정 구성 요소에 대한 이벤트 events-for-custom-components
사용자 지정 구성 요소의 경우 SocialEvent 추상 클래스 구성 요소의 이벤트를 actions그것은 topic.
사용자 지정 이벤트는 메서드를 재정의합니다 getVerb() 그래서 적절한 verb에 대해 반환됨 action. 다음 verb 작업에 대해 반환되는 것은 일반적으로 사용되는 것(예: POST) 또는 각 구성 요소의 전문( 예: ADD RATING). 다음 항목이 있습니다 n-1 관계 간 actions및 verbs.
사용자 지정 구성 요소 이벤트에 대한 의사 코드 pseudo-code-for-custom-component-event
org.osgi.service.event.Event;
com.adobe.cq.social.scf.core.SocialEvent;
com.adobe.granite.activitystreams.ObjectTypes;
com.adobe.granite.activitystreams.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");
}
}
}
}
활동 스트림 데이터를 필터링하는 샘플 EventListener sample-eventlistener-to-filter-activity-stream-data
활동 스트림에 표시되는 내용을 수정하기 위해 이벤트를 수신할 수 있습니다.
다음 의사 코드 샘플은 활동 스트림에서 댓글 구성 요소에 대한 DELETE 이벤트를 제거합니다.
EventListener에 대한 의사 코드 pseudo-code-for-eventlistener
필요한 경우 최신 기능 팩.
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[]{"*"};
}
}