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

com.adobe.aem.formsndocuments.rnc.RnCPublishPreprocessor Maven / Gradle / Ivy

/***************************************************************************
 * ADOBE CONFIDENTIAL
 * ___________________
 *
 *  Copyright 2014 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 may be covered by U.S. and Foreign Patents,
 * patents in process, 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.aem.formsndocuments.rnc;

import java.util.Map;

import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import com.adobe.aem.formsndocuments.util.FMUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.jcr.api.SlingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.aem.formsndocuments.publish.PublishPreprocessor;
import com.adobe.aem.formsndocuments.util.RnCUtil;
import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;

/**
 * Service for the Pre publish logic to clean up any undergoing review on the
 * asset.
 * 
 * @author sakarora
 * 
 */
@Component(immediate = true)
@Service(value = PublishPreprocessor.class)
public class RnCPublishPreprocessor implements PublishPreprocessor {

	private static final String METADATA_PATH = "/jcr:content/metadata";

	private static Logger logger = LoggerFactory
			.getLogger(RnCPublishPreprocessor.class);

	@Reference(referenceInterface = SlingRepository.class)
	SlingRepository slingRepository;

	@Reference(referenceInterface = ResourceResolverFactory.class)
	ResourceResolverFactory resourceResolverFactory;

	@Reference(referenceInterface = ReviewManagementService.class)
	ReviewManagementService reviewManagementService;

	/**
	 * Closes any undergoing review on asset, before publishing.
	 */
	@Override
	public void preprocess(Session userSession, String assetPath, Map params) {
		logger.trace("Entering preprocess.");

		try {
			ResourceResolver resourceResolver = FMUtils.getResourceResolver(resourceResolverFactory, userSession);
			Node asset = RnCUtil.checkNodeExistance(assetPath + METADATA_PATH,
					resourceResolver);
			if (asset.hasProperty(RnCUtil.UNDER_REVIEW)
					&& asset.getProperty(RnCUtil.UNDER_REVIEW).getBoolean()) {
				
				reviewManagementService.cleanReview(assetPath, userSession, true);
			}
		} catch (Exception e) {
			// If the review cleanup fails, it may be not be an error. Log as a
			// warning.
			logger.warn("Failed to cleanup the review: " , e);
		}
		logger.trace("Exiting preprocess.");
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy