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

com.adobe.cq.social.tally.client.api.AbstractLiking Maven / Gradle / Ivy

/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2012 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.tally.client.api;

import javax.jcr.RepositoryException;

import org.apache.sling.api.resource.Resource;

import com.adobe.cq.social.scf.ClientUtilities;
import com.adobe.cq.social.tally.Liking;

public class AbstractLiking extends AbstractTally implements LikingSocialComponent {
    private Liking likingComponent;

    public AbstractLiking(final Resource resource) {
        this(resource, null);
    }

    public AbstractLiking(final Resource resource, final ClientUtilities clientUtils) {
        super(resource, clientUtils);
        initComponent();
    }

    private void initComponent() {
        this.likingComponent = this.getResource().adaptTo(Liking.class);
        this.tally = this.likingComponent;
    }

    @Override
    public long getLikeCount() {
        return this.likingComponent.getLikeCount();
    }

    @Override
    public boolean isCurrentUserLike() {
        try {
            if (clientUtils.userIsAnonymous()) {
                return false;
            }

            final Response resp = this.likingComponent.getUserResponse(this.currentUser);
            if (resp == null) {
                return false;
            }
            return Like.LIKE.equals(resp.getResponseValue()) ? true : false;
        } catch (final RepositoryException e) {
            return false;
        } catch (final TallyException e) {
            return false;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy