/*
 * Axelor Business Solutions
 *
 * Copyright (C) 2018 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.apps.prestashop.web;

import javax.xml.transform.TransformerException;

import com.axelor.apps.base.db.AppPrestashop;
import com.axelor.apps.prestashop.app.AppPrestaShopService;
import com.axelor.apps.prestashop.service.library.PrestaShopWebserviceException;
import com.axelor.rpc.ActionRequest;
import com.axelor.rpc.ActionResponse;
import com.google.inject.Inject;
import com.google.inject.Singleton;

@Singleton
public class AppPrestaShopController {

	@Inject
	private AppPrestaShopService service;

	/**
	 * Test connection with prestashop
	 *
	 * @param request
	 * @param response
	 * @throws PrestaShopWebserviceException
	 * @throws TransformerException
	 */
	public void testConnection(ActionRequest request, ActionResponse response) throws PrestaShopWebserviceException, TransformerException {

		AppPrestashop ps = request.getContext().asType(AppPrestashop.class);
		boolean test = service.connection(ps);

		if(test) {
			response.setAlert("Connection Sucessfully");
		} else {
			response.setAlert("Connection Fail");
		}
	}

	/**
	 * Validate url which are set in configuration
	 *
	 * @param request
	 * @param response
	 */
	public void validUrl(ActionRequest request, ActionResponse response) {

		AppPrestashop ps = request.getContext().asType(AppPrestashop.class);
		if(service.validateUrl(ps) == false) {
			response.setError("URL is invalid, it should not be empty nor contain the trailing slash");
		}
	}
}

@@ -970,16 +970,45 @@
 eption;%0A
+import com.axelor.i18n.I18n;%0A
 import c
@@ -1685,32 +1685,41 @@
 sponse.setAlert(
+I18n.get(
 %22Connection Suce
@@ -1718,20 +1718,24 @@
 ion 
-Su
+was suc
 cessful
-ly
 %22
+)
 );%0A%09
@@ -1765,16 +1765,25 @@
 etAlert(
+I18n.get(
 %22Connect
@@ -1790,13 +1790,16 @@
 ion 
-Fail%22
+failed%22)
 );%0A%09
@@ -2112,16 +2112,25 @@
 etError(
+I18n.get(
 %22URL is 
@@ -2193,16 +2193,17 @@
  slash%22)
+)
 ;%0A%09%09%7D%0A%09%7D

fix connection check messages