<commit_before>package org.opencps.statistic.rest.facade;

import com.liferay.portal.kernel.util.Validator;

import java.time.LocalDate;
import java.util.HashMap;

import org.opencps.statistic.rest.dto.GetVotingResultRequest;
import org.opencps.statistic.rest.dto.GetVotingResultResponse;
import org.opencps.statistic.rest.util.DossierStatisticConfig;
import org.opencps.statistic.rest.util.DossierStatisticConstants;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import opencps.statistic.common.webservice.exception.UpstreamServiceFailedException;
import opencps.statistic.common.webservice.exception.UpstreamServiceTimedOutException;
import opencps.statistic.common.webservice.facade.OpencpsRestFacade;

public class OpencpsCallVotingRestFacadeImpl extends OpencpsRestFacade<GetVotingResultRequest, GetVotingResultResponse>
		implements OpencpsCallRestFacade<GetVotingResultRequest, GetVotingResultResponse> {

	//private final static Log _log = LogFactoryUtil.getLog(OpencpsCallDossierRestFacadeImpl.class);

	@Override
	public GetVotingResultResponse callRestService(GetVotingResultRequest payload)
			throws UpstreamServiceTimedOutException, UpstreamServiceFailedException {
		return makeServiceCall(payload);
	}

	protected GetVotingResultResponse makeServiceCall(GetVotingResultRequest payload)
			throws UpstreamServiceTimedOutException, UpstreamServiceFailedException {
		
		MultiValueMap<String, String> urlQueryParams = new LinkedMultiValueMap<>();
		System.out.println("payload.isCalculate(): "+payload.isCalculate());
		if (payload.isCalculate()) {
			if (payload.getMonth() != null) {
				urlQueryParams.add("month", payload.getMonth());
				//urlQueryParams.add("month", "10");
			}
			else {
				urlQueryParams.add("month", Integer.toString(LocalDate.now().getMonthValue()));
			}
			if (payload.getYear() != null) {
				urlQueryParams.add("year", payload.getYear());
			}
			else {
				urlQueryParams.add("year", Integer.toString(LocalDate.now().getYear()));
			}
		} else {
//			if (Validator.isNotNull(payload.getGovAgencyCode())) {
//				urlQueryParams.add("agency", payload.getGovAgencyCode());
//			}
			if (Validator.isNotNull(payload.getFromVotingDate())) {
				urlQueryParams.add("fromVotingDate", payload.getFromVotingDate());
			}
			if (Validator.isNotNull(payload.getToVotingDate())) {
				urlQueryParams.add("toVotingDate", payload.getToVotingDate());
			}
		}

		urlQueryParams.add("className", "dossier");

		String endPoint = DossierStatisticConfig.get(DossierStatisticConstants.VOTING_ENDPOINT);
		System.out.println("endPoint: "+endPoint);
		HashMap<String, String> urlPathSegments = new HashMap<>();
		String url = buildUrl(endPoint, urlPathSegments, urlQueryParams);
		System.out.println("url: "+url);
		// LOG.info(url);
		HttpHeaders httpHeaders = new HttpHeaders();
		
		//DossierStatisticUtils.logAsFormattedJson(LOG, httpHeaders);
		
		httpHeaders.add("groupId", Long.toString(payload.getGroupId()));<commit_msg>clear log<commit_after>package org.opencps.statistic.rest.facade;

import com.liferay.portal.kernel.util.Validator;

import java.time.LocalDate;
import java.util.HashMap;

import org.opencps.statistic.rest.dto.GetVotingResultRequest;
import org.opencps.statistic.rest.dto.GetVotingResultResponse;
import org.opencps.statistic.rest.util.DossierStatisticConfig;
import org.opencps.statistic.rest.util.DossierStatisticConstants;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import opencps.statistic.common.webservice.exception.UpstreamServiceFailedException;
import opencps.statistic.common.webservice.exception.UpstreamServiceTimedOutException;
import opencps.statistic.common.webservice.facade.OpencpsRestFacade;

public class OpencpsCallVotingRestFacadeImpl extends OpencpsRestFacade<GetVotingResultRequest, GetVotingResultResponse>
		implements OpencpsCallRestFacade<GetVotingResultRequest, GetVotingResultResponse> {

	//private final static Log _log = LogFactoryUtil.getLog(OpencpsCallDossierRestFacadeImpl.class);

	@Override
	public GetVotingResultResponse callRestService(GetVotingResultRequest payload)
			throws UpstreamServiceTimedOutException, UpstreamServiceFailedException {
		return makeServiceCall(payload);
	}

	protected GetVotingResultResponse makeServiceCall(GetVotingResultRequest payload)
			throws UpstreamServiceTimedOutException, UpstreamServiceFailedException {
		
		MultiValueMap<String, String> urlQueryParams = new LinkedMultiValueMap<>();
		//System.out.println("payload.isCalculate(): "+payload.isCalculate());
		if (payload.isCalculate()) {
			if (payload.getMonth() != null) {
				urlQueryParams.add("month", payload.getMonth());
				//urlQueryParams.add("month", "10");
			}
			else {
				urlQueryParams.add("month", Integer.toString(LocalDate.now().getMonthValue()));
			}
			if (payload.getYear() != null) {
				urlQueryParams.add("year", payload.getYear());
			}
			else {
				urlQueryParams.add("year", Integer.toString(LocalDate.now().getYear()));
			}
		} else {
//			if (Validator.isNotNull(payload.getGovAgencyCode())) {
//				urlQueryParams.add("agency", payload.getGovAgencyCode());
//			}
			if (Validator.isNotNull(payload.getFromVotingDate())) {
				urlQueryParams.add("fromVotingDate", payload.getFromVotingDate());
			}
			if (Validator.isNotNull(payload.getToVotingDate())) {
				urlQueryParams.add("toVotingDate", payload.getToVotingDate());
			}
		}

		urlQueryParams.add("className", "dossier");

		String endPoint = DossierStatisticConfig.get(DossierStatisticConstants.VOTING_ENDPOINT);
		//System.out.println("endPoint: "+endPoint);
		HashMap<String, String> urlPathSegments = new HashMap<>();
		String url = buildUrl(endPoint, urlPathSegments, urlQueryParams);
		//System.out.println("url: "+url);
		// LOG.info(url);
		HttpHeaders httpHeaders = new HttpHeaders();
		
		//DossierStatisticUtils.logAsFormattedJson(LOG, httpHeaders);
		
		httpHeaders.add("groupId", Long.toString(payload.getGroupId()));
{'fraction_non_alphanumeric': 0.11971603743142949, 'fraction_numerical': 0.0006453694740238787, 'mean_word_length': 6.3447867298578196, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '23952', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1864, 'n_words': 260}