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

com.adobe.cq.social.enablement.learningpath.endpoints.api.AbstractEnablementLearningPathModelOperation Maven / Gradle / Ivy

There is a newer version: 6.5.21
Show newest version
/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2015 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.enablement.learningpath.endpoints.api;

import javax.jcr.Session;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.jcr.api.SlingRepository;

import com.adobe.cq.social.scf.OperationException;
import com.adobe.cq.social.scf.SocialOperationResult;
import com.adobe.cq.social.scf.core.operations.AbstractSocialOperation;

@Component(metatype = false, componentAbstract = true)
public abstract class AbstractEnablementLearningPathModelOperation
    extends AbstractSocialOperation {

    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY, policy = ReferencePolicy.STATIC)
    protected SlingRepository repository;

    /**
     * Gets session from resource {@link Session}.
     * @param resource the resource for which to retrieve the session
     * @return The Session or null if the session couldn't be created.
     */
    protected Session getSessionFromResource(final Resource resource) {
        return resource.getResourceResolver().adaptTo(Session.class);
    }

    @Override
    protected SocialOperationResult performOperation(final SlingHttpServletRequest request) throws OperationException {
        final Session session = getSessionFromResource(request.getResource());
        return performOperation(request, session);
    }

    /**
     * Perform the operation and send the response using the provided session.
     * @param request the client request.
     * @param session the session to be used to perform the operation
     * @return SocialOperationResult the result of the operation.
     * @throws OperationException if there is an error occurs while performing the operation.
     */
    protected abstract SocialOperationResult performOperation(final SlingHttpServletRequest request,
        final Session session) throws OperationException;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy