Skip to content

Commit

Permalink
fix: execQueryDownloadArchive isolation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolife999 committed Oct 3, 2023
1 parent 9c66a28 commit 2e207ec
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

public class ContainerName {



private ContainerName() {
throw new IllegalStateException("Utility class");
}

public static String buildContainerName(String container) {
String newContainerName = "";
newContainerName = "";
Expand All @@ -25,6 +27,5 @@ public static String buildContainerName(String container) {
private static String normalizeContainerName(String container, String extension) {
return ManipString.substringBeforeLast(container, extension) + extension;
}



}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
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;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;

import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder;
Expand All @@ -15,14 +21,20 @@
import fr.insee.arc.utils.dao.UtilitaireDao;
import fr.insee.arc.utils.dataobjects.TypeEnum;
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;
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;

@Component
public class PilotageDao extends VObjectHelperDao {

private static final Logger LOGGER = LogManager.getLogger(PilotageDao.class);


public void initializePilotageBAS(VObject viewPilotageBAS) {

// the most recent files processed must be shown first by default
Expand Down Expand Up @@ -167,4 +179,44 @@ public void initializeFichierBAS(VObject viewFichierBAS, VObject viewPilotageBAS
}
}


/**
* build query to return download stream
* @param response
* @param viewArchiveBAS
* @param selection
* @param sandboxRootDirectory
* @throws ArcException
*/
public void execQueryDownloadArchive(HttpServletResponse response, VObject viewArchiveBAS, List<String> selection, String sandboxRootDirectory) throws ArcException {

ArcPreparedStatementBuilder querySelection = new ArcPreparedStatementBuilder();

querySelection.append("select distinct alias_de_table.nom_archive as nom_fichier from (");
querySelection.append(viewArchiveBAS.getMainQuery());
querySelection.append(") alias_de_table ");
querySelection.append(this.vObjectService.buildFilter(viewArchiveBAS.getFilterFields(),
viewArchiveBAS.getHeadersDLabel()));

if (selection!=null) {
querySelection.append(" AND nom_archive IN " + Format.sqlListe(selection) + " ");
}

ArrayList<String> listRepertoire = new ArrayList<>();

ArcPreparedStatementBuilder requete = new ArcPreparedStatementBuilder();
requete.append("SELECT DISTINCT entrepot FROM (");
requete.append(viewArchiveBAS.getMainQuery());
requete.append(") alias_de_table ");

GenericBean g = new GenericBean(UtilitaireDao.get(0).executeRequest(null, requete));
String entrepot = g.mapContent().get("entrepot").get(0);
listRepertoire.add(TraitementPhase.RECEPTION + "_" + entrepot + "_ARCHIVE");


this.vObjectService.downloadEnveloppe(viewArchiveBAS, response, querySelection, sandboxRootDirectory,
listRepertoire);

}

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
package fr.insee.arc.web.gui.pilotage.service;

import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Map;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

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.format.Format;
import fr.insee.arc.utils.structure.GenericBean;

@Service
public class ServiceViewArchiveBAS extends InteractorPilotage {
Expand All @@ -30,43 +24,20 @@ public class ServiceViewArchiveBAS extends InteractorPilotage {
public void downloadEnveloppeFromArchiveBAS(HttpServletResponse response) {

loggerDispatcher.trace("*** Téléchargement des enveloppes à partir de l'archive ***", LOGGER);

// récupération de la liste des noms d'enveloppe
Map<String, ArrayList<String>> selection = views.getViewArchiveBAS().mapContentSelected();
List<String> selection = views.getViewArchiveBAS().mapContentSelected().get("nom_archive");

initializeArchiveBAS(views.getViewArchiveBAS(), views.getViewEntrepotBAS());

ArcPreparedStatementBuilder querySelection = new ArcPreparedStatementBuilder();

querySelection.append("select distinct alias_de_table.nom_archive as nom_fichier from (");
querySelection.append(this.views.getViewArchiveBAS().getMainQuery());
querySelection.append(") alias_de_table ");
querySelection.append(this.vObjectService.buildFilter(this.views.getViewArchiveBAS().getFilterFields(),
this.views.getViewArchiveBAS().getHeadersDLabel()));

if (!selection.isEmpty()) {
querySelection.append(" AND nom_archive IN " + Format.sqlListe(selection.get("nom_archive")) + " ");
}

ArrayList<String> listRepertoire = new ArrayList<>();
GenericBean g;
String entrepot = "";
String sandboxRootDirectory = Paths.get(this.repertoire, getBacASable().toUpperCase()).toString();

try {

ArcPreparedStatementBuilder requete = new ArcPreparedStatementBuilder();
requete.append("SELECT DISTINCT entrepot FROM (");
requete.append(this.views.getViewArchiveBAS().getMainQuery());
requete.append(") alias_de_table ");

g = new GenericBean(UtilitaireDao.get(0).executeRequest(null, requete));
entrepot = g.mapContent().get("entrepot").get(0);
this.dao.execQueryDownloadArchive(response, views.getViewArchiveBAS(), selection, sandboxRootDirectory);
} catch (ArcException e) {
loggerDispatcher.error("Error in PilotageBasAction.downloadEnveloppeFromArchiveBAS()", LOGGER);
this.views.getViewArchiveBAS().setMessage("familyManagement.table.error.invalidname");
}
listRepertoire.add(TraitementPhase.RECEPTION + "_" + entrepot + "_ARCHIVE");
String chemin = Paths.get(this.repertoire, getBacASable().toUpperCase()).toString();

this.vObjectService.downloadEnveloppe(views.getViewArchiveBAS(), response, querySelection, chemin,
listRepertoire);
}

}

0 comments on commit 2e207ec

Please sign in to comment.