// Path: src/main/java/com/liferay/support/tools/utils/ProgressManager.java
// public class ProgressManager {
// 
// 	private double _loader = 1;
// 	private ProgressTracker _progressTracker;
// 	private int _threshold = 100;
// 	private ActionRequest _request;
// 	private long _sleep = 1500;
// 
// 	/**
// 	 * Start Progress
// 	 * 
// 	 * @param request    ActionRequest
// 	 * @param loaderInit
// 	 */
// 	public void start(ActionRequest request) {
// 		_request = request;
// 
// 		String commonProgressId = ParamUtil.getString(request, LDFPortletKeys.COMMON_PROGRESS_ID,
// 				LDFPortletKeys.COMMON_PROGRESS_ID);
// 
// 		// Tracking progress start
// 		_progressTracker = new ProgressTracker(commonProgressId);
// 		ProgressTrackerThreadLocal.setProgressTracker(_progressTracker);
// 		_progressTracker.start(request);
// 
// 	}
// 
// 	public int getThreshold() {
// 		return _threshold;
// 	}
// 
// 	public void setThreshold(int threshold) {
// 		_threshold = threshold;
// 	}
// 
// 	/**
// 	 * Calcluate the percentage of prgress
// 	 * 
// 	 * @param index
// 	 * @param numberOfTotal
// 	 * @return percentage of progress by int
// 	 */
// 	public int percentageCalcluation(long index, long numberOfTotal) {
// 		
// 		if(numberOfTotal <= 0) {
// 			return 0;
// 		}
// 		
// 		double dIndex  = (double)index;
// 		double dNumberOfTotal = (double)numberOfTotal;
// 		
// 		int result = (int)(dIndex / dNumberOfTotal * 100.00);
// 		
// 		return (_threshold <= result) ? _threshold : result;
// 	}
// 	
// 	/**
// 	 * Tracking progress
// 	 * 
// 	 * @param index         Index of loop
// 	 * @param numberOfTotal Total number
// 	 */
// 	public void trackProgress(long index, long numberOfTotal) {
// 		if(null != _progressTracker ) {
// 			_loader = percentageCalcluation(index, numberOfTotal);
// 			System.out.println("Creating..." + (int) _loader + "% done");
// 			_progressTracker.setPercent((int)_loader);
// 		}
// 	}
// 
// 	/**
// 	 * Finish progress bar
// 	 */
// 	public void finish() {
// 		try {
// 			// Progress bar doesn't hit if finish right away.
// 			Thread.sleep(_sleep);
// 		} catch (InterruptedException e) {
// 			e.printStackTrace();
// 		}
// 		_progressTracker.finish(_request);
// 	}
// 
// }


import com.liferay.dynamic.data.mapping.model.DDMStructure;
import com.liferay.dynamic.data.mapping.service.DDMStructureLocalService;
import com.liferay.dynamic.data.mapping.service.DDMTemplateLocalService;
import com.liferay.journal.model.JournalArticle;
import com.liferay.journal.service.JournalArticleLocalService;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.service.GroupLocalService;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.support.tools.utils.ProgressManager;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.portlet.ActionRequest;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
package com.liferay.support.tools.journal;





/**
 * Structure / Template selected Journal Articles Generator
 * 
 * @author Yasuyuki Takeo
 *
 */
@Component(immediate = true, service = JournalStructureTemplateDummyGenerator.class)
public class JournalStructureTemplateDummyGenerator extends JournalStructureBaseDummyGenerator {

	@Override
	protected JournalContext getContext(ActionRequest request) throws PortalException {
		
		return new JournalContext(request);
	}

	@Override
	protected void exec(ActionRequest request, JournalContext paramContext) throws Exception {

		// Structure Key
		DDMStructure ddmStructure = 
			_DDMStructureLocalService.getStructure(
				paramContext.getDdmStructureId()
			);

		String structureKey =
			ddmStructure.getStructureKey();
		
		// Template key
		String templateKey = 
			_DDMTemplateLocalService.getTemplate(
				paramContext.getDdmTemplateId()
			).getTemplateKey();
		
		// Tracking progress start
// Path: src/main/java/com/liferay/support/tools/utils/ProgressManager.java
// public class ProgressManager {
// 
// 	private double _loader = 1;
// 	private ProgressTracker _progressTracker;
// 	private int _threshold = 100;
// 	private ActionRequest _request;
// 	private long _sleep = 1500;
// 
// 	/**
// 	 * Start Progress
// 	 * 
// 	 * @param request    ActionRequest
// 	 * @param loaderInit
// 	 */
// 	public void start(ActionRequest request) {
// 		_request = request;
// 
// 		String commonProgressId = ParamUtil.getString(request, LDFPortletKeys.COMMON_PROGRESS_ID,
// 				LDFPortletKeys.COMMON_PROGRESS_ID);
// 
// 		// Tracking progress start
// 		_progressTracker = new ProgressTracker(commonProgressId);
// 		ProgressTrackerThreadLocal.setProgressTracker(_progressTracker);
// 		_progressTracker.start(request);
// 
// 	}
// 
// 	public int getThreshold() {
// 		return _threshold;
// 	}
// 
// 	public void setThreshold(int threshold) {
// 		_threshold = threshold;
// 	}
// 
// 	/**
// 	 * Calcluate the percentage of prgress
// 	 * 
// 	 * @param index
// 	 * @param numberOfTotal
// 	 * @return percentage of progress by int
// 	 */
// 	public int percentageCalcluation(long index, long numberOfTotal) {
// 		
// 		if(numberOfTotal <= 0) {
// 			return 0;
// 		}
// 		
// 		double dIndex  = (double)index;
// 		double dNumberOfTotal = (double)numberOfTotal;
// 		
// 		int result = (int)(dIndex / dNumberOfTotal * 100.00);
// 		
// 		return (_threshold <= result) ? _threshold : result;
// 	}
// 	
// 	/**
// 	 * Tracking progress
// 	 * 
// 	 * @param index         Index of loop
// 	 * @param numberOfTotal Total number
// 	 */
// 	public void trackProgress(long index, long numberOfTotal) {
// 		if(null != _progressTracker ) {
// 			_loader = percentageCalcluation(index, numberOfTotal);
// 			System.out.println("Creating..." + (int) _loader + "% done");
// 			_progressTracker.setPercent((int)_loader);
// 		}
// 	}
// 
// 	/**
// 	 * Finish progress bar
// 	 */
// 	public void finish() {
// 		try {
// 			// Progress bar doesn't hit if finish right away.
// 			Thread.sleep(_sleep);
// 		} catch (InterruptedException e) {
// 			e.printStackTrace();
// 		}
// 		_progressTracker.finish(_request);
// 	}
// 
// }


// Path: src/main/java/com/liferay/support/tools/journal/JournalStructureTemplateDummyGenerator.java
import com.liferay.dynamic.data.mapping.model.DDMStructure;
import com.liferay.dynamic.data.mapping.service.DDMStructureLocalService;
import com.liferay.dynamic.data.mapping.service.DDMTemplateLocalService;
import com.liferay.journal.model.JournalArticle;
import com.liferay.journal.service.JournalArticleLocalService;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.service.GroupLocalService;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.support.tools.utils.ProgressManager;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.portlet.ActionRequest;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

package com.liferay.support.tools.journal;





/**
 * Structure / Template selected Journal Articles Generator
 * 
 * @author Yasuyuki Takeo
 *
 */
@Component(immediate = true, service = JournalStructureTemplateDummyGenerator.class)
public class JournalStructureTemplateDummyGenerator extends JournalStructureBaseDummyGenerator {

	@Override
	protected JournalContext getContext(ActionRequest request) throws PortalException {
		
		return new JournalContext(request);
	}

	@Override
	protected void exec(ActionRequest request, JournalContext paramContext) throws Exception {

		// Structure Key
		DDMStructure ddmStructure = 
			_DDMStructureLocalService.getStructure(
				paramContext.getDdmStructureId()
			);

		String structureKey =
			ddmStructure.getStructureKey();
		
		// Template key
		String templateKey = 
			_DDMTemplateLocalService.getTemplate(
				paramContext.getDdmTemplateId()
			).getTemplateKey();
		
		// Tracking progress start
		ProgressManager progressManager = new ProgressManager();