package org.opencps.statisticsmgt.dashboard.template;

import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.opencps.statisticsmgt.model.DossiersStatistics;
import org.opencps.statisticsmgt.service.DossiersStatisticsLocalService;
import org.opencps.statisticsmgt.service.DossiersStatisticsService;
import org.opencps.util.WebKeys;

import com.liferay.portal.kernel.portletdisplaytemplate.BasePortletDisplayTemplateHandler;
import com.liferay.portal.kernel.template.TemplateVariableGroup;
import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplateConstants;

public class DetailDashBoardPortletDisplayTemplateHandler extends
		BasePortletDisplayTemplateHandler {

	@Override
	public String getClassName() {
		// TODO Auto-generated method stub
		return DossiersStatistics.class.getName() + "#DETAIL";
	}

	@Override
	public String getName(Locale arg0) {
		// TODO Auto-generated method stub
		return "Detail DashBoard";
	}

	@Override
	public String getResourceName() {
		return WebKeys.DETAIL_DASHBOARD_PORTLET;
	}

	@Override
	public Map<String, TemplateVariableGroup> getTemplateVariableGroups(
			long classPK, String language, Locale locale) throws Exception {

		Map<String, TemplateVariableGroup> templateVariableGroups = super
				.getTemplateVariableGroups(classPK, language, locale);

		TemplateVariableGroup templateVariableGroup = templateVariableGroups
				.get("fields");

		templateVariableGroup.empty();

		templateVariableGroup.addCollectionVariable("dossiersStatistics",
				List.class, PortletDisplayTemplateConstants.ENTRIES,
				"dossierStatistics", DossiersStatistics.class,
				"curDossierStatistics", "month");

		templateVariableGroup.addCollectionVariable("dossiersStatistics",
				List.class, PortletDisplayTemplateConstants.ENTRIES,
				"dossierStatistics", DossiersStatistics.class,
				"curDossierStatistics", "year");

		/*templateVariableGroup.addVariable("ListDossierStatistics", List.class,
				PortletDisplayTemplateConstants.ENTRIES);*/
		
		templateVariableGroup.addVariable(
			"json-data", String.class, "jsonData");

		templateVariableGroup
				.addVariable("dossierStatistics", List.class,
						PortletDisplayTemplateConstants.ENTRIES,
						"curDossierStatistics");

		String[] restrictedVariables = getRestrictedVariables(language);

		System.out
				.println("#############################################################restrictedVariables");

		System.out.println(restrictedVariables.length);
		
		TemplateVariableGroup statisticsServicesTemplateVariableGroup = new TemplateVariableGroup(
				"statistic-services", restrictedVariables);

		statisticsServicesTemplateVariableGroup.setAutocompleteEnabled(true);

		statisticsServicesTemplateVariableGroup.addServiceLocatorVariables(
				DossiersStatisticsLocalService.class,
				DossiersStatisticsService.class);

		System.out.println(statisticsServicesTemplateVariableGroup.getLabel());

		templateVariableGroups.put(
				statisticsServicesTemplateVariableGroup.getLabel(),
				statisticsServicesTemplateVariableGroup);
		
		
		
		for(Map.Entry<String, TemplateVariableGroup> entry : templateVariableGroups.entrySet()) {
		    String key = entry.getKey();
		    
		    System.out.println("######### " + key);
		   

		    // do what you have to do here
		    // In your case, an other loop.
		}

		return templateVariableGroups;
	}
}

@@ -1891,132 +1891,8 @@
 r%22);
-%0A%0A%09%09/*templateVariableGroup.addVariable(%22ListDossierStatistics%22, List.class,%0A%09%09%09%09PortletDisplayTemplateConstants.ENTRIES);*/
 %0A%09%09%0A
@@ -2195,171 +2195,8 @@
 ge);
-%0A%0A%09%09System.out%0A%09%09%09%09.println(%22#############################################################restrictedVariables%22);%0A%0A%09%09System.out.println(restrictedVariables.length);
 %0A%09%09%0A
@@ -2565,83 +2565,8 @@
 );%0A%0A
-%09%09System.out.println(statisticsServicesTemplateVariableGroup.getLabel());%0A%0A
 %09%09te
@@ -2647,16 +2647,16 @@
 abel(),%0A
+
 %09%09%09%09stat
@@ -2696,283 +2696,8 @@
 up);
-%0A%09%09%0A%09%09%0A%09%09%0A%09%09for(Map.Entry%3CString, TemplateVariableGroup%3E entry : templateVariableGroups.entrySet()) %7B%0A%09%09    String key = entry.getKey();%0A%09%09    %0A%09%09    System.out.println(%22######### %22 + key);%0A%09%09   %0A%0A%09%09    // do what you have to do here%0A%09%09    // In your case, an other loop.%0A%09%09%7D
 %0A%0A%09%09

update Dashboard DetailDashBoardPortletDisplayTemplateHandler