--- /dev/null
+/*
+ * Copyright © FYLAB and the Conseil Régional d'Île-de-France, 2009
+ * This file is part of L'Interface Libre et Interactive de l'Enseignement (Lilie).
+ *
+ * Lilie is free software. You can redistribute it and/or modify since
+ * you respect the terms of either (at least one of the both license) :
+ * - under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ * - the CeCILL-C as published by CeCILL-C; either version 1 of the
+ * License, or any later version
+ *
+ * There are special exceptions to the terms and conditions of the
+ * licenses as they are applied to this software. View the full text of
+ * the exception in file LICENSE.txt in the directory of this software
+ * distribution.
+ *
+ * Lilie 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
+ * Licenses for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the CeCILL-C along with Lilie. If not, see :
+ * <http://www.gnu.org/licenses/> and
+ * <http://www.cecill.info/licences.fr.html>.
+ */
+
+package org.lilie.services.eliot.api.backoffice
+
+import org.codehaus.groovy.grails.web.json.JSONArray
+
+import org.lilie.services.eliot.backoffice.BackofficeService
+import org.codehaus.groovy.grails.commons.GrailsApplication
+import org.lilie.services.eliot.api.backoffice.erreur.BackofficeConfigSaveErreur
+import org.lilie.services.eliot.api.RestErreur
+import org.lilie.services.eliot.api.RestUtil
+
+class RestBackofficeConfigController {
+
+ BackofficeService backofficeService
+ GrailsApplication grailsApplication
+ /*
+ * WebService de création d'une Config Backoffice (paramètres d'un établissement
+ * pour les applications Marketing et Backoffice)
+ */
+ def save = {
+
+ response.characterEncoding = "utf-8"
+ def configs = params.configs
+
+ if (!isSaveBodyValide()){
+ String message = "Le corps de la requête est incorrect."
+
+ log.error(message)
+ render(
+ status: 400,
+ text: "<error>$message</error>"
+ )
+ return
+ }
+
+ List<RestErreur> allErreur = []
+ configs.each { def jsonConfig ->
+ BackofficeConfigSaveParam backofficeConfigSaveParam =
+ new BackofficeConfigSaveParam(jsonConfig)
+
+ try{
+
+ if (!backofficeConfigSaveParam.validate()) {
+ throw new IllegalStateException(
+ "La description de la config est incorrecte : " +
+ "(${backofficeConfigSaveParam.errors})"
+ )
+ }
+ backofficeService.insertUpdateBackofficeConfig(jsonConfig)
+
+ }
+ catch (Exception e) {
+ log.error("Erreur durant la sauvegarde d'une config", e)
+
+ allErreur << new BackofficeConfigSaveErreur(
+ configUai: jsonConfig.uai,
+ message: e.message
+ )
+ }
+
+ if (allErreur) {
+ render(RestUtil.encodeAllErreur(allErreur))
+ }
+ else {
+ render message(code: 'eliot.RestSmsFournisseur.response.success') //TOREFACT : code du message à changer
+ }
+
+ }
+ }
+
+ private boolean isSaveBodyValide() {
+ def configs = params?.configs
+ return configs instanceof JSONArray && !configs.isEmpty()
+ }
+
+ def showEtablissements = {
+ def uais = params.uais
+ Map mapARetourner = [:]
+ if(uais){
+
+ try{
+ backofficeService.listerConfigBackoffice(uais)
+ mapARetourner.status = 200
+ mapARetourner.text = 'ok'
+
+ }
+ catch(Exception e){
+ mapARetourner.status = 404
+ mapARetourner.text = 'Une erreur c\'est produite'
+
+ }
+
+ render(
+ status : mapARetourner.status,
+ text : mapARetourner.text )
+
+ }
+ }
+
+
+ def showEtablissementsFiltres = {
+
+ def uais = params.uais
+ def baseEleve = params.baseEleve
+ def lvs = params.lvs
+ def udt = params.udt
+
+ try{
+ backofficeService.listerConfigBackoffice(uais, baseEleve, lvs, udt)
+ mapARetourner.status = 200
+ mapARetourner.text = 'ok'
+ }
+ catch(Exception e){
+ mapARetourner.status = 404
+ mapARetourner.text = 'Une erreur c\'est produite'
+ }
+
+ render(
+ status : mapARetourner.status,
+ text : mapARetourner.text )
+
+
+ }
+
+ def showUtilisateursFiltres = {
+ // TODO
+ }
+
+
+// try{
+// def providers = params.infos.fournisseurs.toString()
+// if (providers) {
+// def providerLst = JSON.parse(providers)
+// smsFournisseurService.ajouterSmsFournisseurs(providerLst)
+//
+// render message(code: 'bo.smsProvider.ws.response.success')
+// }
+// else{
+// render message(code: 'bo.smsProvider.ws.response.error.noInfos')
+// }
+// }
+// catch(Exception e){
+// log.error("Les paramètres passés au webService ne semblent pas corrects", e)
+// render(
+// status : 404,
+// text : "Les paramètres passés au webService ne semblent pas corrects" )
+// }
+ }