diff --git a/arc-core/src/main/java/fr/insee/arc/core/dataobjects/ColumnEnum.java b/arc-core/src/main/java/fr/insee/arc/core/dataobjects/ColumnEnum.java index f78901262..8dad30f2b 100644 --- a/arc-core/src/main/java/fr/insee/arc/core/dataobjects/ColumnEnum.java +++ b/arc-core/src/main/java/fr/insee/arc/core/dataobjects/ColumnEnum.java @@ -132,6 +132,7 @@ public enum ColumnEnum { , POS("pos", TypeEnum.BIGINT, "ordinal position") // export , MAXP("maxp", TypeEnum.BIGINT, "highest position") // export , I("i", TypeEnum.BIGINT, "row number index") // maintenanceparametre + , NB("nb", TypeEnum.BIGINT, "count") // pilotage , TEST1(PgColumnEnum.TEST1) , TEST2(PgColumnEnum.TEST2) diff --git a/arc-core/src/main/java/fr/insee/arc/core/dataobjects/ViewEnum.java b/arc-core/src/main/java/fr/insee/arc/core/dataobjects/ViewEnum.java index 4133ce363..afc214b5d 100644 --- a/arc-core/src/main/java/fr/insee/arc/core/dataobjects/ViewEnum.java +++ b/arc-core/src/main/java/fr/insee/arc/core/dataobjects/ViewEnum.java @@ -90,7 +90,8 @@ public enum ViewEnum { // tables représentant le contenu des vobject (utilisées pour les tests) , VIEW_PILOTAGE_FICHIER("pilotage_fichier", SchemaEnum.SANDBOX, ColumnEnum.DATE_ENTREE) // - + , VIEW_RAPPORT_FICHIER("pilotage_fichier", SchemaEnum.SANDBOX, ColumnEnum.DATE_ENTREE, + ColumnEnum.PHASE_TRAITEMENT, ColumnEnum.ETAT_TRAITEMENT, ColumnEnum.RAPPORT, ColumnEnum.NB) // // tables de pilotage , PILOTAGE_FICHIER("pilotage_fichier", SchemaEnum.SANDBOX, ColumnEnum.ID_SOURCE, ColumnEnum.ID_NORME, ColumnEnum.VALIDITE, ColumnEnum.PERIODICITE, ColumnEnum.PHASE_TRAITEMENT, ColumnEnum.ETAT_TRAITEMENT, diff --git a/arc-utils/src/main/java/fr/insee/arc/utils/dao/SQL.java b/arc-utils/src/main/java/fr/insee/arc/utils/dao/SQL.java index 2c90de172..1a41ab3ef 100644 --- a/arc-utils/src/main/java/fr/insee/arc/utils/dao/SQL.java +++ b/arc-utils/src/main/java/fr/insee/arc/utils/dao/SQL.java @@ -23,6 +23,8 @@ public enum SQL { LIKE("LIKE"), + IS_NULL("IS NULL"), IS_NOT_NULL("IS NOT NULL"), + GROUP_BY("GROUP BY"), TRUE("TRUE"), FALSE("FALSE"), diff --git a/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/dao/PilotageDao.java b/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/dao/PilotageDao.java index 11bca1ac8..cf2ce1dbe 100644 --- a/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/dao/PilotageDao.java +++ b/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/dao/PilotageDao.java @@ -1,6 +1,5 @@ package fr.insee.arc.web.gui.pilotage.dao; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -15,9 +14,12 @@ import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder; import fr.insee.arc.core.dataobjects.ColumnEnum; +import fr.insee.arc.core.dataobjects.DataObjectService; import fr.insee.arc.core.dataobjects.ViewEnum; import fr.insee.arc.core.model.TraitementEtat; import fr.insee.arc.core.model.TraitementPhase; +import fr.insee.arc.core.service.global.dao.HashFileNameConversion; +import fr.insee.arc.utils.dao.SQL; import fr.insee.arc.utils.dao.UtilitaireDao; import fr.insee.arc.utils.dataobjects.TypeEnum; import fr.insee.arc.utils.exception.ArcException; @@ -27,7 +29,7 @@ import fr.insee.arc.utils.utils.ManipString; import fr.insee.arc.web.gui.all.util.VObject; import fr.insee.arc.web.gui.all.util.VObjectHelperDao; -import fr.insee.arc.web.gui.pilotage.service.ServiceViewArchiveBAS; +import fr.insee.arc.web.gui.all.util.VObjectService; @Component public class PilotageDao extends VObjectHelperDao { @@ -81,6 +83,20 @@ public void initializePilotageBAS(VObject viewPilotageBAS) { this.vObjectService.initialize(viewPilotageBAS, requete, null, defaultInputFields); } + + /** + * dao call to get sandbox description + * @throws ArcException + */ + public String getSandboxDescription(String bacASable) throws ArcException { + ViewEnum dataEtatJeuderegle = ViewEnum.EXT_ETAT_JEUDEREGLE; + // query + ArcPreparedStatementBuilder query = new ArcPreparedStatementBuilder(); + query.build(SQL.SELECT, ColumnEnum.ENV_DESCRIPTION, SQL.FROM, dataEtatJeuderegle.getFullName()); + query.build(SQL.WHERE, "replace(id,'.','_') = ", query.quoteText(bacASable)); + // return list + return UtilitaireDao.get(0).getString(null, query); + } public void initializeRapportBAS(VObject viewRapportBAS) { ViewEnum dataModelRapportBAS = ViewEnum.PILOTAGE_FICHIER; @@ -119,7 +135,8 @@ public void initializeEntrepotBAS(VObject viewEntrepotBAS) throws ArcException { ViewEnum dataModelEntrepotBAS = ViewEnum.IHM_ENTREPOT; // view query ArcPreparedStatementBuilder requete = new ArcPreparedStatementBuilder(); - if (Boolean.TRUE.equals(UtilitaireDao.get(0).hasResults(null, FormatSQL.tableExists("arc.ihm_entrepot")))) { + boolean existsEntrepot = UtilitaireDao.get(0).hasResults(null, FormatSQL.tableExists(dataModelEntrepotBAS.getFullName())); + if (existsEntrepot) { requete.append("select id_entrepot from "); requete.append(dataObjectService.getView(dataModelEntrepotBAS)); } else { @@ -218,5 +235,227 @@ public void execQueryDownloadArchive(HttpServletResponse response, VObject viewA listRepertoire); } + + public void downloadFichierBAS(VObject viewFichierBAS, HttpServletResponse response, + String repertoire, String bacASable) { + // récupération de la liste des id_source + Map> selection = viewFichierBAS.mapContentSelected(); + ArcPreparedStatementBuilder query = vObjectService.queryView(viewFichierBAS); + // si la selection de fichiers n'est pas vide, on se restreint aux fichiers + // sélectionner + // + if (!selection.isEmpty()) { + query.build(SQL.AND, ColumnEnum.ID_SOURCE, SQL.IN, "(", query.sqlListeOfValues(selection.get("id_source")), ") "); + } + + // optimisation pour avoir des bloc successifs sur la même archive + query.build(SQL.ORDER_BY, ColumnEnum.CONTAINER); + + vObjectService.downloadXML(viewFichierBAS, response, query, repertoire, bacASable, TraitementPhase.RECEPTION.toString()); + } + + public ArcPreparedStatementBuilder queryUpdateToDelete(VObject viewFichierBAS, String code) { + Map> selection = viewFichierBAS.mapContentSelected(); + ArcPreparedStatementBuilder querySelection = requestSelectToMark(viewFichierBAS, selection); + return requeteUpdateToMark(querySelection, code); + } + + public void execQueryUpdateToDelete(ArcPreparedStatementBuilder updateToDelete) throws ArcException { + UtilitaireDao.get(0).executeRequest(null, updateToDelete); + } + + public void downloadBdBAS(VObject viewFichierBAS, HttpServletResponse response, + ArrayList tableDownload, String phase, String etatBdd, String date) throws ArcException { + + // List of queries that will be executed to download + List tableauRequete = new ArrayList<>(); + // Name of the file containing the data download + List fileNames = new ArrayList<>(); + ArcPreparedStatementBuilder requete; + + for (String t : tableDownload) { + + // Check if the table to download got children + requete = new ArcPreparedStatementBuilder(); + requete.append(FormatSQL.getAllInheritedTables(ManipString.substringBeforeFirst(t, "."), + ManipString.substringAfterFirst(t, "."))); + requete.append(" LIMIT 1"); + + if (Boolean.TRUE.equals(UtilitaireDao.get(0).hasResults(null, requete))) { + + // Get the files to download + requete = new ArcPreparedStatementBuilder(); + requete.append("SELECT id_source FROM " + dataObjectService.getView(ViewEnum.PILOTAGE_FICHIER)); + requete.append("\n WHERE phase_traitement=" + requete.quoteText(phase) + " "); + requete.append("\n AND etat_traitement=" + requete.quoteText(etatBdd) + "::text[] "); + requete.append("\n AND date_entree=" + requete.quoteText(date) + " "); + + // Si des fichiers ont été selectionnés, on ajoute a la requete la liste des + // fichiers + if (!viewFichierBAS.mapContentSelected().isEmpty()) { + ArrayList filesSelected = viewFichierBAS.mapContentSelected().get("id_source"); + requete.append("AND id_source IN ("); + for (int i = 0; i < filesSelected.size(); i++) { + if (i > 0) { + requete.append(","); + } + requete.append("'" + filesSelected.get(i) + "'"); + } + requete.append(")"); + } + + ArrayList idSources = new GenericBean(UtilitaireDao.get(0).executeRequest(null, requete)) + .mapContent().get("id_source"); + + // for each files, generate the download query + for (String idSource : idSources) { + tableauRequete.add(new ArcPreparedStatementBuilder( + "SELECT * FROM " + HashFileNameConversion.tableOfIdSource(t, idSource))); + fileNames.add(t + "_" + idSource); + } + + } + // if no children + else { + + requete = new ArcPreparedStatementBuilder(); + requete.append("WITH prep as ( "); + requete.append("SELECT id_source FROM " + dataObjectService.getView(ViewEnum.PILOTAGE_FICHIER)); + requete.append("\n WHERE phase_traitement=" + requete.quoteText(phase) + " "); + requete.append("\n AND etat_traitement=" + requete.quoteText(etatBdd) + "::text[] "); + requete.append("\n AND date_entree=" + requete.quoteText(date) + " "); + + // Si des fichiers ont été selectionnés, on ajoute a la requete la liste des + // fichiers + if (!viewFichierBAS.mapContentSelected().isEmpty()) { + requete.append("\n AND id_source IN ("); + requete.append( + requete.sqlListeOfValues(viewFichierBAS.mapContentSelected().get("id_source"))); + requete.append(")"); + } + requete.append(" ) "); + requete.append("\n SELECT * from " + t + + " a where exists (select 1 from prep b where a.id_source=b.id_source) "); + tableauRequete.add(requete); + fileNames.add(t); + } + + } + + this.vObjectService.download(viewFichierBAS, response, fileNames, tableauRequete); + } + + public void downloadEnvelopeBAS(VObject viewFichierBAS, HttpServletResponse response, + String chemin, ArrayList listRepertoire) { + // récupération de la liste des noms d'enloppe + Map> selection = viewFichierBAS.mapContentSelected(); + ArcPreparedStatementBuilder query = new ArcPreparedStatementBuilder(); + query.append("select distinct alias_de_table.container as nom_fichier from ("); + query.append(viewFichierBAS.getMainQuery()); + query.append(") alias_de_table "); + query.append(vObjectService.buildFilter(viewFichierBAS.getFilterFields(), viewFichierBAS.getHeadersDLabel())); + if (!selection.isEmpty()) { + query.append(" AND container IN (" + query.sqlListeOfValues(selection.get("container")) + ") "); + } + vObjectService.downloadEnveloppe(viewFichierBAS, response, query, chemin, listRepertoire); + } + + + + /** + * Prepare a request selecting the line to change when marking files for + * deletion/replay. + */ + private ArcPreparedStatementBuilder requestSelectToMark(VObject viewFichierBAS, Map> selection) { + ArcPreparedStatementBuilder querySelection = new ArcPreparedStatementBuilder(); + querySelection.append("select distinct container, id_source from ("); + querySelection.append(viewFichierBAS.getMainQuery()); + querySelection.append(") alias_de_table "); + querySelection.append(this.vObjectService.buildFilter(viewFichierBAS.getFilterFields(), + viewFichierBAS.getHeadersDLabel())); + // si la selection de fichiers n'est pas vide, on se restreint aux fichiers + // sélectionné + if (!selection.isEmpty()) { + // concaténation des informations + ArrayList infoConcatenee = new ArrayList<>(); + ArrayList listContainer = selection.get("container"); + ArrayList listIdSource = selection.get("id_source"); + + for (int i = 0; i < selection.get("id_source").size(); i++) { + infoConcatenee.add(listContainer.get(i) + "+" + listIdSource.get(i)); + } + querySelection.append(" AND container||'+'||id_source IN " + Format.sqlListe(infoConcatenee) + " "); + } + return querySelection; + } + + /** + * Mark the line selected by querySelection for deletion/replay (depending on + * value). + */ + private ArcPreparedStatementBuilder requeteUpdateToMark(ArcPreparedStatementBuilder querySelection, String value) { + ArcPreparedStatementBuilder updateToDelete = new ArcPreparedStatementBuilder(); + updateToDelete.append("WITH "); + updateToDelete.append("prep AS ( "); + updateToDelete.append(querySelection); + updateToDelete.append(" ) "); + updateToDelete.append("UPDATE " + dataObjectService.getView(ViewEnum.PILOTAGE_FICHIER) + " a "); + updateToDelete.append("SET to_delete=" + value + " "); + updateToDelete.append( + "WHERE EXISTS (SELECT 1 FROM prep WHERE a.container=prep.container AND a.id_source=prep.id_source); "); + return updateToDelete; + } + + public void execQueryUpdateEnvDescription(VObject viewPilotageBAS, String envDescription, String bacASable) throws ArcException { + ArcPreparedStatementBuilder envQuery = new ArcPreparedStatementBuilder(); + envQuery.append("update arc.ext_etat_jeuderegle set env_description = "); + envQuery.append(envQuery.quoteText(viewPilotageBAS.getCustomValue(envDescription))); + envQuery.append("where replace(id,'.','_') = "); + envQuery.append(envQuery.quoteText(bacASable)); + UtilitaireDao.get(0).executeRequest(null, envQuery); + } + + public String execQueryTime() throws ArcException { + return UtilitaireDao.get(0).getString(null, new ArcPreparedStatementBuilder("SELECT last_init from arc.pilotage_batch")); + } + + public String execQueryState() throws ArcException { + return UtilitaireDao.get(0).getString(null, new ArcPreparedStatementBuilder("SELECT case when operation='O' then 'active' else 'inactive' end from arc.pilotage_batch;")); + } + + public void execQueryDelayBatchTime() throws ArcException { + UtilitaireDao.get(0).executeRequest(null, + new ArcPreparedStatementBuilder("UPDATE arc.pilotage_batch set last_init=to_char(current_date + interval '7 days','yyyy-mm-dd')||':22';")); + } + + public void execQueryForwardBatchTime() throws ArcException { + UtilitaireDao.get(0).executeRequest(null, + new ArcPreparedStatementBuilder("UPDATE arc.pilotage_batch set last_init=to_char(current_date-interval '1 days','yyyy-mm-dd')||':22';")); + } + + public void execQueryToggleOn() throws ArcException { + UtilitaireDao.get(0).executeRequest(null, new ArcPreparedStatementBuilder("UPDATE arc.pilotage_batch set operation='O'; ")); + } + + public void execQueryToggleOff() throws ArcException { + UtilitaireDao.get(0).executeRequest(null, new ArcPreparedStatementBuilder("UPDATE arc.pilotage_batch set operation='N'; ")); + } + + + public VObjectService getvObjectService() { + return vObjectService; + } + + public void setvObjectService(VObjectService vObjectService) { + this.vObjectService = vObjectService; + } + + public DataObjectService getDataObjectService() { + return dataObjectService; + } + + public void setDataObjectService(DataObjectService dataObjectService) { + this.dataObjectService = dataObjectService; + } } diff --git a/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/InteractorPilotage.java b/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/InteractorPilotage.java index c12eb0da0..65e4005f0 100644 --- a/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/InteractorPilotage.java +++ b/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/InteractorPilotage.java @@ -16,16 +16,14 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.context.WebApplicationContext; -import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder; import fr.insee.arc.core.model.TraitementPhase; -import fr.insee.arc.utils.dao.UtilitaireDao; import fr.insee.arc.utils.exception.ArcException; import fr.insee.arc.utils.utils.LoggerHelper; import fr.insee.arc.utils.utils.ManipString; import fr.insee.arc.web.gui.all.service.ArcWebGenericService; +import fr.insee.arc.web.gui.all.util.ConstantVObject.ColumnRendering; import fr.insee.arc.web.gui.all.util.LineObject; import fr.insee.arc.web.gui.all.util.VObject; -import fr.insee.arc.web.gui.all.util.ConstantVObject.ColumnRendering; import fr.insee.arc.web.gui.pilotage.dao.PilotageDao; import fr.insee.arc.web.gui.pilotage.model.ModelPilotage; @@ -124,12 +122,8 @@ public void initializePilotageBAS(VObject viewPilotageBAS) { this.vObjectService.applyColumnRendering(viewPilotageBAS, columns); // display comment for the sandbox - ArcPreparedStatementBuilder envQuery = new ArcPreparedStatementBuilder(); - envQuery.append("select env_description from arc.ext_etat_jeuderegle where replace(id,'.','_') = "); - envQuery.append(envQuery.quoteText(getBacASable())); - try { - String envDescription = UtilitaireDao.get(0).getString(null, envQuery); + String envDescription = dao.getSandboxDescription(getBacASable()); viewPilotageBAS.setCustomValue(ENV_DESCRIPTION, envDescription); } catch (ArcException e) { loggerDispatcher.error("Error in initializePilotageBAS", e, LOGGER); diff --git a/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/ServiceViewFichierBAS.java b/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/ServiceViewFichierBAS.java index 98965ab42..7a03e502f 100644 --- a/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/ServiceViewFichierBAS.java +++ b/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/ServiceViewFichierBAS.java @@ -13,17 +13,11 @@ import org.springframework.ui.Model; import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder; -import fr.insee.arc.core.dataobjects.ViewEnum; import fr.insee.arc.core.factory.ApiServiceFactory; import fr.insee.arc.core.model.TraitementEtat; import fr.insee.arc.core.model.TraitementPhase; -import fr.insee.arc.core.service.global.dao.HashFileNameConversion; import fr.insee.arc.core.service.global.dao.PhaseOperations; -import fr.insee.arc.utils.dao.UtilitaireDao; import fr.insee.arc.utils.exception.ArcException; -import fr.insee.arc.utils.format.Format; -import fr.insee.arc.utils.structure.GenericBean; -import fr.insee.arc.utils.utils.FormatSQL; import fr.insee.arc.utils.utils.ManipString; @Service @@ -44,26 +38,8 @@ public String sortFichierBAS(Model model) { } public void downloadFichierBAS(HttpServletResponse response) { - loggerDispatcher.trace("*** Téléchargement des fichiers ***", LOGGER); - // récupération de la liste des id_source - - Map> selection = views.getViewFichierBAS().mapContentSelected(); - ArcPreparedStatementBuilder querySelection = this.vObjectService.queryView(views.getViewFichierBAS()); - // si la selection de fichiers n'est pas vide, on se restreint aux fichiers - // sélectionner - // - if (!selection.isEmpty()) { - querySelection - .append(" AND id_source IN (" + querySelection.sqlListeOfValues(selection.get("id_source")) + ") "); - } - - // optimisation pour avoir des bloc successifs sur la même archive - querySelection.append(" ORDER by container "); - - this.vObjectService.downloadXML(views.getViewFichierBAS(), response, querySelection, this.repertoire, - getBacASable(), TraitementPhase.RECEPTION.toString()); - + dao.downloadFichierBAS(this.views.getViewFichierBAS(), response, this.repertoire, getBacASable()); loggerDispatcher.trace("*** Fin du téléchargement des fichiers XML ***", LOGGER); } @@ -87,15 +63,10 @@ public String toRestoreArchiveBAS(Model model) { private String restore(Model model, String code, String messageOk) { loggerDispatcher.trace("*** Marquage de fichier à rejouer ***", LOGGER); - Map> selection = views.getViewFichierBAS().mapContentSelected(); - - ArcPreparedStatementBuilder querySelection = requestSelectToMark(selection); - - ArcPreparedStatementBuilder updateToDelete = requeteUpdateToMark(querySelection, code); + ArcPreparedStatementBuilder updateToDelete = dao.queryUpdateToDelete(views.getViewFichierBAS(), code); String message; try { - - UtilitaireDao.get(0).executeRequest(null, updateToDelete); + dao.execQueryUpdateToDelete(updateToDelete); message = messageOk; } catch (ArcException e) { loggerDispatcher.error("Error in PilotageBASAction.restore", LOGGER); @@ -157,116 +128,22 @@ public void downloadBdBAS(HttpServletResponse response) throws ArcException { } catch (ArcException e) { loggerDispatcher.error(e, LOGGER); } + + dao.downloadBdBAS(this.views.getViewFichierBAS(), response, tableDownload, phase, etatBdd, date); - // List of queries that will be executed to download - List tableauRequete = new ArrayList<>(); - // Name of the file containing the data download - List fileNames = new ArrayList<>(); - - ArcPreparedStatementBuilder requete; - - for (String t : tableDownload) { - - // Check if the table to download got children - requete = new ArcPreparedStatementBuilder(); - requete.append(FormatSQL.getAllInheritedTables(ManipString.substringBeforeFirst(t, "."), - ManipString.substringAfterFirst(t, "."))); - requete.append(" LIMIT 1"); - - if (Boolean.TRUE.equals(UtilitaireDao.get(0).hasResults(null, requete))) { - - // Get the files to download - requete = new ArcPreparedStatementBuilder(); - requete.append("SELECT id_source FROM " + dataObjectService.getView(ViewEnum.PILOTAGE_FICHIER)); - requete.append("\n WHERE phase_traitement=" + requete.quoteText(phase) + " "); - requete.append("\n AND etat_traitement=" + requete.quoteText(etatBdd) + "::text[] "); - requete.append("\n AND date_entree=" + requete.quoteText(date) + " "); - - // Si des fichiers ont été selectionnés, on ajoute a la requete la liste des - // fichiers - if (!views.getViewFichierBAS().mapContentSelected().isEmpty()) { - ArrayList filesSelected = views.getViewFichierBAS().mapContentSelected().get("id_source"); - requete.append("AND id_source IN ("); - for (int i = 0; i < filesSelected.size(); i++) { - if (i > 0) { - requete.append(","); - } - requete.append("'" + filesSelected.get(i) + "'"); - } - requete.append(")"); - } - - ArrayList idSources = new GenericBean(UtilitaireDao.get(0).executeRequest(null, requete)) - .mapContent().get("id_source"); - - // for each files, generate the download query - for (String idSource : idSources) { - tableauRequete.add(new ArcPreparedStatementBuilder( - "SELECT * FROM " + HashFileNameConversion.tableOfIdSource(t, idSource))); - fileNames.add(t + "_" + idSource); - } - - } - // if no children - else { - - requete = new ArcPreparedStatementBuilder(); - requete.append("WITH prep as ( "); - requete.append("SELECT id_source FROM " + dataObjectService.getView(ViewEnum.PILOTAGE_FICHIER)); - requete.append("\n WHERE phase_traitement=" + requete.quoteText(phase) + " "); - requete.append("\n AND etat_traitement=" + requete.quoteText(etatBdd) + "::text[] "); - requete.append("\n AND date_entree=" + requete.quoteText(date) + " "); - - // Si des fichiers ont été selectionnés, on ajoute a la requete la liste des - // fichiers - if (!views.getViewFichierBAS().mapContentSelected().isEmpty()) { - requete.append("\n AND id_source IN ("); - requete.append( - requete.sqlListeOfValues(views.getViewFichierBAS().mapContentSelected().get("id_source"))); - requete.append(")"); - } - requete.append(" ) "); - requete.append("\n SELECT * from " + t - + " a where exists (select 1 from prep b where a.id_source=b.id_source) "); - tableauRequete.add(requete); - fileNames.add(t); - } - - } - - this.vObjectService.download(views.getViewFichierBAS(), response, fileNames, tableauRequete); } public String downloadEnveloppeBAS(HttpServletResponse response) { loggerDispatcher.trace("*** Téléchargement des enveloppes ***", LOGGER); - // récupération de la liste des noms d'enloppe - Map> selection = views.getViewFichierBAS().mapContentSelected(); - + initializeFichierBAS(views.getViewFichierBAS(), views.getViewPilotageBAS(), views.getViewRapportBAS()); - ArcPreparedStatementBuilder querySelection = new ArcPreparedStatementBuilder(); - - querySelection.append("select distinct alias_de_table.container as nom_fichier from ("); - querySelection.append(this.views.getViewFichierBAS().getMainQuery()); - querySelection.append(") alias_de_table "); - querySelection.append(this.vObjectService.buildFilter(this.views.getViewFichierBAS().getFilterFields(), - this.views.getViewFichierBAS().getHeadersDLabel())); - - if (!selection.isEmpty()) { - querySelection - .append(" AND container IN (" + querySelection.sqlListeOfValues(selection.get("container")) + ") "); - } - - loggerDispatcher.info("Ma requete pour récupérer la liste des enveloppes : " + querySelection.toString(), - LOGGER); - ArrayList listRepertoire = new ArrayList<>(); listRepertoire.add(TraitementPhase.RECEPTION + "_" + TraitementEtat.OK); listRepertoire.add(TraitementPhase.RECEPTION + "_" + TraitementEtat.KO); String chemin = Paths.get(this.repertoire, getBacASable().toUpperCase()).toString(); - this.vObjectService.downloadEnveloppe(views.getViewFichierBAS(), response, querySelection, chemin, - listRepertoire); + dao.downloadEnvelopeBAS(this.views.getViewFichierBAS(), response, chemin, listRepertoire); loggerDispatcher.trace("*** Fin du téléchargement des enveloppes ***", LOGGER); return "none"; @@ -280,14 +157,10 @@ public String downloadEnveloppeBAS(HttpServletResponse response) { public String toDeleteBAS(Model model) { loggerDispatcher.trace("*** Marquage de fichier à supprimer ***", LOGGER); - Map> selection = views.getViewFichierBAS().mapContentSelected(); - - ArcPreparedStatementBuilder querySelection = requestSelectToMark(selection); - - ArcPreparedStatementBuilder updateToDelete = requeteUpdateToMark(querySelection, "'1'"); + ArcPreparedStatementBuilder updateToDelete = dao.queryUpdateToDelete(views.getViewFichierBAS(), "'1'"); String message; try { - UtilitaireDao.get(0).executeRequest(null, updateToDelete); + dao.execQueryUpdateToDelete(updateToDelete); message = "managementSandbox.batch.delete.ok"; } catch (ArcException e) { loggerDispatcher.error("Error in PilotageBASAction.toDeleteBAS", LOGGER); @@ -318,12 +191,9 @@ public String toDeleteBAS(Model model) { public String undoActionBAS(Model model) { loggerDispatcher.trace("*** Suppression du marquage de fichier à supprimer ***", LOGGER); - Map> selection = views.getViewFichierBAS().mapContentSelected(); - ArcPreparedStatementBuilder querySelection = requestSelectToMark(selection); - ArcPreparedStatementBuilder updateToDelete = requeteUpdateToMark(querySelection, "null"); + ArcPreparedStatementBuilder updateToDelete = dao.queryUpdateToDelete(views.getViewFichierBAS(), "null"); try { - - UtilitaireDao.get(0).executeRequest(null, updateToDelete); + dao.execQueryUpdateToDelete(updateToDelete); } catch (ArcException e) { loggerDispatcher .info("Problème lors de la mise à jour de to_delete dans la table pilotage_fichier, requete : " @@ -333,48 +203,6 @@ public String undoActionBAS(Model model) { return generateDisplay(model, RESULT_SUCCESS); } - /** - * Prepare a request selecting the line to change when marking files for - * deletion/replay. - */ - private ArcPreparedStatementBuilder requestSelectToMark(Map> selection) { - ArcPreparedStatementBuilder querySelection = new ArcPreparedStatementBuilder(); - querySelection.append("select distinct container, id_source from ("); - querySelection.append(this.views.getViewFichierBAS().getMainQuery()); - querySelection.append(") alias_de_table "); - querySelection.append(this.vObjectService.buildFilter(this.views.getViewFichierBAS().getFilterFields(), - this.views.getViewFichierBAS().getHeadersDLabel())); - // si la selection de fichiers n'est pas vide, on se restreint aux fichiers - // sélectionné - if (!selection.isEmpty()) { - // concaténation des informations - ArrayList infoConcatenee = new ArrayList<>(); - ArrayList listContainer = selection.get("container"); - ArrayList listIdSource = selection.get("id_source"); - - for (int i = 0; i < selection.get("id_source").size(); i++) { - infoConcatenee.add(listContainer.get(i) + "+" + listIdSource.get(i)); - } - querySelection.append(" AND container||'+'||id_source IN " + Format.sqlListe(infoConcatenee) + " "); - } - return querySelection; - } - - /** - * Mark the line selected by querySelection for deletion/replay (depending on - * value). - */ - private ArcPreparedStatementBuilder requeteUpdateToMark(ArcPreparedStatementBuilder querySelection, String value) { - ArcPreparedStatementBuilder updateToDelete = new ArcPreparedStatementBuilder(); - updateToDelete.append("WITH "); - updateToDelete.append("prep AS ( "); - updateToDelete.append(querySelection); - updateToDelete.append(" ) "); - updateToDelete.append("UPDATE " + dataObjectService.getView(ViewEnum.PILOTAGE_FICHIER) + " a "); - updateToDelete.append("SET to_delete=" + value + " "); - updateToDelete.append( - "WHERE EXISTS (SELECT 1 FROM prep WHERE a.container=prep.container AND a.id_source=prep.id_source); "); - return updateToDelete; - } + } diff --git a/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/ServiceViewPilotageBAS.java b/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/ServiceViewPilotageBAS.java index 04babdf26..012fe1f2e 100644 --- a/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/ServiceViewPilotageBAS.java +++ b/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/ServiceViewPilotageBAS.java @@ -11,7 +11,6 @@ import org.springframework.ui.Model; import fr.insee.arc.core.dataobjects.ArcDatabase; -import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder; import fr.insee.arc.core.dataobjects.ColumnEnum; import fr.insee.arc.core.factory.ApiServiceFactory; import fr.insee.arc.core.model.TraitementPhase; @@ -20,7 +19,6 @@ import fr.insee.arc.core.service.p0initialisation.dbmaintenance.BddPatcher; import fr.insee.arc.core.service.p0initialisation.metadata.SynchronizeRulesAndMetadataOperation; import fr.insee.arc.core.util.BDParameters; -import fr.insee.arc.utils.dao.UtilitaireDao; import fr.insee.arc.utils.exception.ArcException; import fr.insee.arc.utils.utils.LoggerHelper; @@ -46,13 +44,8 @@ public String selectPilotageBAS(Model model) { } public String updateEnvDescription(Model model) { - ArcPreparedStatementBuilder envQuery = new ArcPreparedStatementBuilder(); - envQuery.append("update arc.ext_etat_jeuderegle set env_description = "); - envQuery.append(envQuery.quoteText(views.getViewPilotageBAS().getCustomValue(ENV_DESCRIPTION))); - envQuery.append("where replace(id,'.','_') = "); - envQuery.append(envQuery.quoteText(getBacASable())); try { - UtilitaireDao.get(0).executeRequest(null, envQuery); + dao.execQueryUpdateEnvDescription(views.getViewPilotageBAS(), ENV_DESCRIPTION, getBacASable()); } catch (ArcException e) { loggerDispatcher.error("Error in updateEnvDescription", e, LOGGER); } diff --git a/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/ServiceViewPilotageProd.java b/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/ServiceViewPilotageProd.java index 1bb10fbd4..0ee1f8558 100644 --- a/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/ServiceViewPilotageProd.java +++ b/arc-web/src/main/java/fr/insee/arc/web/gui/pilotage/service/ServiceViewPilotageProd.java @@ -7,10 +7,8 @@ import org.springframework.stereotype.Service; import org.springframework.ui.Model; -import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder; import fr.insee.arc.core.service.global.bo.Sandbox; import fr.insee.arc.core.service.p0initialisation.metadata.SynchronizeRulesAndMetadataOperation; -import fr.insee.arc.utils.dao.UtilitaireDao; import fr.insee.arc.utils.exception.ArcException; @Service @@ -27,8 +25,8 @@ public class ServiceViewPilotageProd extends InteractorPilotage { */ public String informationInitialisationPROD(Model model, HttpServletRequest request) { try { - String time = UtilitaireDao.get(0).getString(null, new ArcPreparedStatementBuilder("SELECT last_init from arc.pilotage_batch")); - String state = UtilitaireDao.get(0).getString(null, new ArcPreparedStatementBuilder("SELECT case when operation='O' then 'active' else 'inactive' end from arc.pilotage_batch;")); + String time = dao.execQueryTime(); + String state = dao.execQueryState(); state = messageSource.getMessage("managementSandbox.batch.status." + state, null, request.getLocale()); this.views.getViewPilotageBAS().setMessage("managementSandbox.batch.status"); this.views.getViewPilotageBAS().setMessageArgs(state, time); @@ -46,10 +44,8 @@ public String informationInitialisationPROD(Model model, HttpServletRequest requ */ public String retarderBatchInitialisationPROD(Model model) { try { - UtilitaireDao.get(0).executeRequest(null, - new ArcPreparedStatementBuilder("UPDATE arc.pilotage_batch set last_init=to_char(current_date + interval '7 days','yyyy-mm-dd')||':22';")); - - String time = UtilitaireDao.get(0).getString(null, new ArcPreparedStatementBuilder("SELECT last_init from arc.pilotage_batch")); + dao.execQueryDelayBatchTime(); + String time = dao.execQueryTime(); this.views.getViewPilotageBAS().setMessage("managementSandbox.batch.init.time"); this.views.getViewPilotageBAS().setMessageArgs(time); @@ -70,9 +66,8 @@ public String demanderBatchInitialisationPROD(Model model) { // demande l'initialisation : met au jour -1 à 22h try { - UtilitaireDao.get(0).executeRequest(null, new ArcPreparedStatementBuilder("UPDATE arc.pilotage_batch set last_init=to_char(current_date-interval '1 days','yyyy-mm-dd')||':22';")); - - String time = UtilitaireDao.get(0).getString(null, new ArcPreparedStatementBuilder("SELECT last_init from arc.pilotage_batch")); + dao.execQueryForwardBatchTime(); + String time = dao.execQueryTime(); this.views.getViewPilotageBAS().setMessage("managementSandbox.batch.init.time"); this.views.getViewPilotageBAS().setMessageArgs(time); @@ -91,7 +86,7 @@ public String demanderBatchInitialisationPROD(Model model) { */ public String toggleOnPROD(Model model) { try { - UtilitaireDao.get(0).executeRequest(null, new ArcPreparedStatementBuilder("UPDATE arc.pilotage_batch set operation='O'; ")); + dao.execQueryToggleOn(); this.views.getViewPilotageBAS().setMessage("managementSandbox.batch.status.switch.on"); } catch (ArcException e) { loggerDispatcher.error("Error in toggleOnPROD", e, LOGGER); @@ -107,7 +102,7 @@ public String toggleOnPROD(Model model) { */ public String toggleOffPROD(Model model) { try { - UtilitaireDao.get(0).executeRequest(null, new ArcPreparedStatementBuilder("UPDATE arc.pilotage_batch set operation='N'; ")); + dao.execQueryToggleOff(); this.views.getViewPilotageBAS().setMessage("managementSandbox.batch.status.switch.off"); } catch (ArcException e) { loggerDispatcher.error("Error in toggleOffPROD", e, LOGGER); diff --git a/arc-web/src/test/java/fr/insee/arc/web/gui/pilotage/dao/PilotageDaoTest.java b/arc-web/src/test/java/fr/insee/arc/web/gui/pilotage/dao/PilotageDaoTest.java index 05ec1b946..e8ca484fb 100644 --- a/arc-web/src/test/java/fr/insee/arc/web/gui/pilotage/dao/PilotageDaoTest.java +++ b/arc-web/src/test/java/fr/insee/arc/web/gui/pilotage/dao/PilotageDaoTest.java @@ -16,7 +16,10 @@ import fr.insee.arc.web.gui.all.util.Session; import fr.insee.arc.web.gui.all.util.VObject; import fr.insee.arc.web.gui.all.util.VObjectService; +import fr.insee.arc.web.gui.pilotage.model.ViewArchiveBAS; +import fr.insee.arc.web.gui.pilotage.model.ViewEntrepotBAS; import fr.insee.arc.web.gui.pilotage.model.ViewPilotageBAS; +import fr.insee.arc.web.gui.pilotage.model.ViewRapportBAS; public class PilotageDaoTest extends InitializeQueryTest { @@ -53,5 +56,45 @@ public void initializePilotageBAS() { assertTrue(viewPilotageBAS.getHeadersDLabel().containsAll(viewColumns)); } + + @Test + public void initializeRapportBAS() { + + VObject viewRapportBAS = new ViewRapportBAS(); + + // execute query + pdao.initializeRapportBAS(viewRapportBAS); + + System.out.println(viewRapportBAS.getHeadersDLabel()); + + // test the content of the view + List viewColumns = ColumnEnum + .listColumnEnumByName(ViewEnum.VIEW_RAPPORT_FICHIER.getColumns().keySet()); + + assertTrue(viewRapportBAS.getHeadersDLabel().containsAll(viewColumns)); + + } + + @Test + public void initializeArchiveBAS() throws ArcException { + + VObject viewArchiveBAS = new ViewArchiveBAS(); + VObject viewEntrepotBAS = new ViewEntrepotBAS(); + + // select entrepot + viewEntrepotBAS.setCustomValue("entrepotLecture", "DEFAULT"); + + // execute query + pdao.initializeArchiveBAS(viewArchiveBAS, viewEntrepotBAS); + + System.out.println(viewArchiveBAS.getHeadersDLabel()); + + // test the content of the view + List viewColumns = ColumnEnum + .listColumnEnumByName(ViewEnum.PILOTAGE_ARCHIVE.getColumns().keySet()); + + assertTrue(viewArchiveBAS.getHeadersDLabel().containsAll(viewColumns)); + + } }