/**
 * Axelor Business Solutions
 *
 * Copyright (C) 2012-2014 Axelor (<http://axelor.com>).
 *
 * This program is free software: you can redistribute it and/or  modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.axelor.wkf.web;

import java.util.Map;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.axelor.app.AppSettings;
import com.axelor.auth.AuthUtils;
import com.axelor.rpc.ActionRequest;
import com.axelor.rpc.ActionResponse;
import com.axelor.wkf.db.Instance;
import com.axelor.wkf.db.Workflow;
import com.axelor.wkf.service.WorkflowImporter;
import com.google.common.collect.Maps;

public class WorkflowController {

	protected Logger log = LoggerFactory.getLogger( getClass() );
	
	private static final String CONFIG_WKF_BASE = "workflow.editor.base";
	private static final String CONFIG_WKF_LANG = "workflow.editor.lang";

	@Inject
	private WorkflowImporter workflowImporter;

	public void importWorkflow(ActionRequest request, ActionResponse response){

		Workflow workflow = request.getContext().asType( Workflow.class );
		workflowImporter.run( workflow.getBpmn() );
		response.setReload(true);
		
	}

	/**
	 * Open all instances of the wkf.
	 *
	 * @param request
	 * @param response
	 */
	public void openInstances (ActionRequest request, ActionResponse response) {

		Workflow workflow = request.getContext().asType( Workflow.class );
		
		Map<String,Object> view = Maps.newHashMap();
		view.put( "title", workflow.getName() );
		view.put( "resource", Instance.class.getName() );
		view.put( "domain", String.format( "self.workflow.id = %d", workflow.getId() ) );
		
		response.setView( view );

	}

	/**
	 * Open editor
	 * 
	 * @param request
	 * @param response
	 */
	public void openEditor( ActionRequest request, ActionResponse response ) {

		Workflow workflow = request.getContext().asType( Workflow.class );
		
		String resource = String.format(
			"%s/p/editor?id=%s&name=%s&model=%s&url=%s&lang=%s&sessionId=%s}", 
			AppSettings.get().get(CONFIG_WKF_BASE, "http://localhost:8080/axelorbpm"),
			workflow.getId(),
			workflow.getName(),
			workflow.getMetaModel().getFullName(),
			AppSettings.get().getBaseURL(),
			AppSettings.get().get(CONFIG_WKF_LANG, "fr"),
			AuthUtils.getSubject().getSession().getId()
		);			
		
		log.debug("SIGNAVIO URL : {}", resource);

		Map<String,Object> view = Maps.newHashMap();
		view.put( "title", String.format("Editor : %s", workflow.getName()) );
		view.put( "resource", resource );
		view.put( "viewType", "html" );
		
		response.setView( view );
	}
}

@@ -872,16 +872,58 @@
 ttings;%0A
+import com.axelor.app.internal.AppFilter;%0A
 import c
@@ -1355,79 +1355,8 @@
 se%22;
-%0A%09private static final String CONFIG_WKF_LANG = %22workflow.editor.lang%22;
 %0A%0A%09@
@@ -2354,16 +2354,18 @@
 ss );%0A%09%09
+%09%09
 %0A%09%09Strin
@@ -2534,16 +2534,17 @@
 0/axelor
+-
 bpm%22),%0A%09
@@ -2673,48 +2673,39 @@
 %09App
-Settings.get().get(CONFIG_WKF_LANG, %22fr%22
+Filter.getLocale().getLanguage(
 ),%0A%09

Fix default axelor-bpm editor and use user language.