<commit_before>/*
 * This is part of the Ktunaxa referral system.
 *
 * Copyright 2011 Ktunaxa Nation Council, http://www.ktunaxa.org/, Canada.
 */

package org.ktunaxa.referral.server.command.bpm;

import org.activiti.engine.RuntimeService;
import org.geomajas.command.Command;
import org.geomajas.global.ExceptionCode;
import org.geomajas.global.GeomajasException;
import org.ktunaxa.bpm.KtunaxaBpmConstant;
import org.ktunaxa.bpm.KtunaxaConfiguration;
import org.ktunaxa.referral.server.command.request.CreateProcessRequest;
import org.ktunaxa.referral.server.command.request.UrlResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * Create a referral handling process.
 *
 * @author <NAME>
 */
@Component
public class CreateProcessCommand implements Command<CreateProcessRequest, UrlResponse> {

	@Autowired
	private RuntimeService runtimeService;

	@Autowired
	private KtunaxaConfiguration ktunaxaConfiguration;
	
	private static DateFormat YYYYMMDD = new SimpleDateFormat("yyyy-MM-dd");

	public UrlResponse getEmptyCommandResponse() {
		return new UrlResponse();
	}

	public void execute(CreateProcessRequest request, UrlResponse response) throws Exception {
		String referralId = request.getReferralId();
		if (null == referralId) {
			throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "referralId");
		}
		String email = request.getEmail();
		if (null == email) {
			throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "email");
		}
		Map<String, Object> context = new HashMap<String, Object>();
		context.put(KtunaxaBpmConstant.REFERRAL_CONTEXT_REFERRAL_ID, referralId);
		String description = request.getDescription();
		if (null == description) {
			description = "";
		}
		context.put(KtunaxaBpmConstant.REFERRAL_CONTEXT_DESCRIPTION, description);
		context.put(KtunaxaBpmConstant.REFERRAL_CONTEXT_EMAIL, email);
		context.put(KtunaxaBpmConstant.REFERRAL_CONTEXT_ENGAGEMENT_LEVEL, request.getEngagementLevel());
		context.put(KtunaxaBpmConstant.REFERRAL_CONTEXT_COMPLETION_DEADLINE,
				YYYYMMDD.format(request.getCompletionDeadline()));
		runtimeService.startProcessInstanceByKey(KtunaxaBpmConstant.REFERRAL_PROCESS_ID, context);
		response.setUrl(ktunaxaConfiguration.getBpmDashboardBaseUrl());
	}
}<commit_msg>KTU-48: don't use static formatter !<commit_after>/*
 * This is part of the Ktunaxa referral system.
 *
 * Copyright 2011 Ktunaxa Nation Council, http://www.ktunaxa.org/, Canada.
 */

package org.ktunaxa.referral.server.command.bpm;

import org.activiti.engine.RuntimeService;
import org.geomajas.command.Command;
import org.geomajas.global.ExceptionCode;
import org.geomajas.global.GeomajasException;
import org.ktunaxa.bpm.KtunaxaBpmConstant;
import org.ktunaxa.bpm.KtunaxaConfiguration;
import org.ktunaxa.referral.server.command.request.CreateProcessRequest;
import org.ktunaxa.referral.server.command.request.UrlResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * Create a referral handling process.
 *
 * @author Joachim <NAME>
 */
@Component
public class CreateProcessCommand implements Command<CreateProcessRequest, UrlResponse> {

	@Autowired
	private RuntimeService runtimeService;

	@Autowired
	private KtunaxaConfiguration ktunaxaConfiguration;

	public UrlResponse getEmptyCommandResponse() {
		return new UrlResponse();
	}

	public void execute(CreateProcessRequest request, UrlResponse response) throws Exception {
		String referralId = request.getReferralId();
		if (null == referralId) {
			throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "referralId");
		}
		String email = request.getEmail();
		if (null == email) {
			throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "email");
		}
		Map<String, Object> context = new HashMap<String, Object>();
		context.put(KtunaxaBpmConstant.REFERRAL_CONTEXT_REFERRAL_ID, referralId);
		String description = request.getDescription();
		if (null == description) {
			description = "";
		}
		DateFormat yyyymmdd = new SimpleDateFormat("yyyy-MM-dd");
		context.put(KtunaxaBpmConstant.REFERRAL_CONTEXT_DESCRIPTION, description);
		context.put(KtunaxaBpmConstant.REFERRAL_CONTEXT_EMAIL, email);
		context.put(KtunaxaBpmConstant.REFERRAL_CONTEXT_ENGAGEMENT_LEVEL, request.getEngagementLevel());
		context.put(KtunaxaBpmConstant.REFERRAL_CONTEXT_COMPLETION_DEADLINE,
				yyyymmdd.format(request.getCompletionDeadline()));
		runtimeService.startProcessInstanceByKey(KtunaxaBpmConstant.REFERRAL_PROCESS_ID, context);
		response.setUrl(ktunaxaConfiguration.getBpmDashboardBaseUrl());
	}
}
{'fraction_non_alphanumeric': 0.09952897808724145, 'fraction_numerical': 0.0020479213598197828, 'mean_word_length': 6.4112291350531105, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5632241', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1573, 'n_words': 272}