All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.cq.social.ideation.client.api.IdeationEvent Maven / Gradle / Ivy

/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2013 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 **************************************************************************/

package com.adobe.cq.social.ideation.client.api;

import java.util.HashMap;

import org.apache.commons.lang3.StringUtils;

import com.adobe.cq.social.commons.events.CommentEvent;
import com.adobe.cq.social.scf.SocialComponent;
import com.adobe.cq.social.scf.core.SocialEvent;
import com.adobe.granite.activitystreams.ObjectTypes;
import com.adobe.granite.activitystreams.Verbs;

/**
 * Defines events that are triggered in ideations.
 */
public class IdeationEvent extends SocialEvent {

    private static final long serialVersionUID = 1L;
    /**
     * The event topic suffix for ideation events.
     */
    public static final String IDEATION_TOPIC = "ideation";
    protected static final String IDEATION_PATH = "IDEATION_PATH";

    /**
     * @param ideationEntry - the ideation entry page on which the event was triggered.
     * @param userId - the user id of the user who triggered the event.
     * @param action - the ideation action that triggered this event.
     */

    public IdeationEvent(final IdeaComment ideationEntry, final String userId,
        final IdeationEvent.IdeationActions action) {
        super(IDEATION_TOPIC, ideationEntry.getResource().getPath(), userId, action, new BaseEventObject(
            getDisplayName(ideationEntry, action), ideationEntry.getResource().getPath(), ideationEntry.isTopic()
                ? ObjectTypes.COLLECTION : ObjectTypes.COMMENT), new BaseEventObject(getDisplayName(
            ideationEntry.getParentComponent(), action), ideationEntry.getParentComponent().getId()
            .getResourceIdentifier(), ideationEntry.isTopic() ? ObjectTypes.COLLECTION : ObjectTypes.COMMENT),
            new HashMap(0));

    }

    private static String getDisplayName(final SocialComponent ideationEntry,
        final IdeationEvent.IdeationActions action) {
        if (ideationEntry instanceof IdeaComment) {

            final String name =
                (action.getVerb().equals(Verbs.DELETE)) ? "" : ((IdeaComment) ideationEntry).getSubject();
            if (StringUtils.isNotEmpty(name)) {
                return name;
            } else {
                return ((IdeaComment) ideationEntry).isTopic() ? "an idea" : "a comment";
            }
        } else {
            if (ideationEntry instanceof Ideation) {
                return ((Ideation) ideationEntry).getTitle();
            } else {
                return null;
            }
        }
    }

    /**
     * List of available ideation actions that can trigger a ideation event.
     */
    public static enum IdeationActions implements SocialEvent.SocialActions {
        CREATED, EDITED, DELETED, REPLY_CREATED, REPLY_EDITED, REPLY_DELETED, CHANGESTATE, REPLY_CHANGESTATE;

        @Override
        public String getVerb() {
            switch (this) {
                case CREATED:
                    return Verbs.POST;
                case REPLY_CREATED:
                    return Verbs.ADD;
                case EDITED:
                case REPLY_EDITED:
                    return Verbs.UPDATE;
                case DELETED:
                case REPLY_DELETED:
                    return Verbs.DELETE;
                case CHANGESTATE:
                case REPLY_CHANGESTATE:
                    return CommentEvent.VERBS_CHANGESTATE;
                default:
                    throw new IllegalArgumentException();
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy