Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*************************************************************************
*
* 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 java.util.Map;
import javax.jcr.Session;
import javax.servlet.http.HttpServletResponse;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.cq.social.enablement.learningpath.model.api.EnablementLearningPathModel;
import com.adobe.cq.social.scf.Operation;
import com.adobe.cq.social.scf.OperationException;
import com.adobe.cq.social.scf.OperationExtension;
import com.adobe.cq.social.scf.SocialComponent;
import com.adobe.cq.social.scf.core.operations.AbstractOperationService;
/**
* Provides abstract implementation of the EnablementLearningPathModel operation..
* @param is a {@link OperationExtension} that will be used as hooks by the extending class.
* @param is a {@link Operation} that is being provided by the extending class.
*/
@SuppressWarnings("rawtypes")
@Component(metatype = false, componentAbstract = true)
@Properties({@Property(name = AbstractEnablementLearningPathModelOperationService.PROPERTY_FIELD_WHITELIST,
value = {}, description = "List of allowed whitelisted custom properties", cardinality = 100)})
public abstract class AbstractEnablementLearningPathModelOperationService
extends AbstractOperationService implements
EnablementLearningPathModelOperations {
/**
* Logger.
*/
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
@Reference
private EnablementLearningPathModelServiceCreate enablementLearningPathModelOperationServiceCreate;
@Reference
private EnablementLearningPathModelServiceUpdate enablementLearningPathModelOperationServiceUpdate;
@Reference
private EnablementLearningPathModelServicePublish enablementLearningPathModelOperationServicePublish;
/**
* Custom white list of input parameters
*/
protected String[] fieldWhitelist;
protected static final String PROPERTY_FIELD_WHITELIST = "fieldWhitelist";
/**
* Activate this component. Open the session and register event listeners.
* @param context The component context
*/
@Activate
protected void activate(final ComponentContext context) {
Object whitelist = context.getProperties().get(PROPERTY_FIELD_WHITELIST);
fieldWhitelist = PropertiesUtil.toStringArray(whitelist);
}
// /
// / Create operation
// /
@Override
public SocialComponent create(final SlingHttpServletRequest request) throws OperationException {
try {
LOGGER.debug("Enablement Learning Path Model Create operation.");
Map properties =
enablementLearningPathModelOperationServiceCreate.getOperationProperties(request, fieldWhitelist);
final U createOperation = getCreateOperation();
final Resource parentResource = request.getResource();
final ResourceResolver resolver = parentResource.getResourceResolver();
final Session session = resolver.adaptTo(Session.class);
performBeforeActions(createOperation, session, parentResource, properties);
EnablementLearningPathModel enablementLearningPathModel =
enablementLearningPathModelOperationServiceCreate.create(request, properties, fieldWhitelist);
if (enablementLearningPathModel != null) {
performAfterActions(createOperation, session, enablementLearningPathModel, properties);
return enablementLearningPathModel;
}
} catch (final Exception e) {
throw new OperationException("Internal error creating enablementLearningPathModel.", e,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
// Get here if we are not able to perform the request
throw new OperationException("Unable to obtain EnablementLearningPathModel component.",
HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
// /
// / Update operation
// /
@Override
public SocialComponent update(final SlingHttpServletRequest request) throws OperationException {
try {
LOGGER.debug("Enablement Learning Path Model Update operation.");
Map properties =
enablementLearningPathModelOperationServiceUpdate.getOperationProperties(request, fieldWhitelist);
final U reportOperation = getUpdateOperation();
final Resource parentResource = request.getResource();
final ResourceResolver resolver = parentResource.getResourceResolver();
final Session session = resolver.adaptTo(Session.class);
performBeforeActions(reportOperation, session, parentResource, properties);
EnablementLearningPathModel enablementLearningPathModel =
enablementLearningPathModelOperationServiceUpdate.update(request, properties, fieldWhitelist);
if (enablementLearningPathModel != null) {
performAfterActions(reportOperation, session, enablementLearningPathModel, properties);
return enablementLearningPathModel;
}
} catch (final Exception e) {
throw new OperationException("Internal error updating enablementLearningPathModel.", e,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
// Get here if we are not able to perform the request
throw new OperationException("Unable to obtain EnablementLearningPathModel component.",
HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
// /
// / Publish operation
// /
@Override
public SocialComponent publish(final SlingHttpServletRequest request) throws OperationException {
try {
LOGGER.debug("Enablement Learning Path Model Report operation.");
Map properties =
enablementLearningPathModelOperationServicePublish.getOperationProperties(request, fieldWhitelist);
final U reportOperation = getPublishOperation();
final Resource parentResource = request.getResource();
final ResourceResolver resolver = parentResource.getResourceResolver();
final Session session = resolver.adaptTo(Session.class);
performBeforeActions(reportOperation, session, parentResource, properties);
EnablementLearningPathModel enablementLearningPathModel =
enablementLearningPathModelOperationServicePublish.publish(request, properties);
if (enablementLearningPathModel != null) {
performAfterActions(reportOperation, session, enablementLearningPathModel, properties);
return enablementLearningPathModel;
}
} catch (final Exception e) {
throw new OperationException("Internal error creating enablementLearningPathModel.", e,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
// Get here if we are not able to perform the request
throw new OperationException("Unable to obtain EnablementLearningPathModel component.",
HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
protected String getResourceType() {
return EnablementLearningPathModel.RESOURCE_TYPE;
}
protected abstract U getCreateOperation();
protected abstract U getPublishOperation();
protected abstract U getUpdateOperation();
protected abstract U getReportOperation();
}