Skip to content

Commit

Permalink
fix: use TraitementPhase instead of string for phase
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolife999 committed Oct 8, 2023
1 parent b5f8bef commit ac9f260
Show file tree
Hide file tree
Showing 29 changed files with 100 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void run() {
public void execute() {

this.report = ApiServiceFactory.getService( //
getPhaseName().toString(), //
getPhaseName(), //
mapParam.get(PhaseParameterKeys.KEY_FOR_EXECUTION_ENVIRONMENT), //
mapParam.get(PhaseParameterKeys.KEY_FOR_DIRECTORY_LOCATION), //
Integer.parseInt(mapParam.get(capacityParameterName())), //
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.insee.arc.core.factory;

import fr.insee.arc.core.model.TraitementPhase;
import fr.insee.arc.core.service.global.ApiService;
import fr.insee.arc.core.service.p2chargement.ApiChargementService;

Expand All @@ -14,7 +15,7 @@ public class ApiChargementServiceFactory implements IServiceFactory {
* @param aDirectoryRoot
* @param aNbEnr
*/
public ApiService get(String phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
public ApiService get(TraitementPhase phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
return new ApiChargementService(phaseService, executionSchema, directory, capacityParameter, paramBatch);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.insee.arc.core.factory;

import fr.insee.arc.core.model.TraitementPhase;
import fr.insee.arc.core.service.global.ApiService;
import fr.insee.arc.core.service.p4controle.ApiControleService;

Expand All @@ -14,7 +15,7 @@ public class ApiControleServiceFactory implements IServiceFactory {
* @param aDirectoryRoot
* @param aNbEnr
*/
public ApiService get(String phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
public ApiService get(TraitementPhase phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
return new ApiControleService(phaseService, executionSchema, directory, capacityParameter, paramBatch);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package fr.insee.arc.core.factory;

import fr.insee.arc.core.model.TraitementPhase;
import fr.insee.arc.core.service.global.ApiService;
import fr.insee.arc.core.service.p0initialisation.ApiInitialisationService;

public class ApiInitialisationServiceFactory implements IServiceFactory {

@Override
public ApiService get(String phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
public ApiService get(TraitementPhase phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
return new ApiInitialisationService(phaseService, executionSchema, directory, capacityParameter, paramBatch);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package fr.insee.arc.core.factory;

import fr.insee.arc.core.model.TraitementPhase;
import fr.insee.arc.core.service.global.ApiService;
import fr.insee.arc.core.service.p5mapping.ApiMappingService;

public class ApiMappingServiceFactory implements IServiceFactory {

@Override
public ApiService get(String phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
public ApiService get(TraitementPhase phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
return new ApiMappingService(phaseService, executionSchema, directory, capacityParameter, paramBatch);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.insee.arc.core.factory;

import fr.insee.arc.core.model.TraitementPhase;
import fr.insee.arc.core.service.global.ApiService;
import fr.insee.arc.core.service.p3normage.ApiNormageService;

Expand All @@ -14,7 +15,7 @@ public class ApiNormageServiceFactory implements IServiceFactory {
* @param aDirectoryRoot
* @param aNbEnr
*/
public ApiService get(String phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
public ApiService get(TraitementPhase phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
return new ApiNormageService(phaseService, executionSchema, directory, capacityParameter, paramBatch);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.insee.arc.core.factory;

import fr.insee.arc.core.model.TraitementPhase;
import fr.insee.arc.core.service.global.ApiService;
import fr.insee.arc.core.service.p1reception.ApiReceptionService;

Expand All @@ -14,7 +15,7 @@ public class ApiReceptionServiceFactory implements IServiceFactory {
* @param aDirectoryRoot
* @param aNbEnr
*/
public ApiService get(String phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
public ApiService get(TraitementPhase phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
return new ApiReceptionService(phaseService, executionSchema, directory, capacityParameter, paramBatch);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
public class ApiServiceFactory {


private Map<String, IServiceFactory> map;
private Map<TraitementPhase, IServiceFactory> map;

private static ApiServiceFactory instance = null;

private ApiServiceFactory(Map<String, IServiceFactory> aMap) {
private ApiServiceFactory(Map<TraitementPhase, IServiceFactory> aMap) {
this.map = aMap;
this.map.put(TraitementPhase.INITIALISATION.toString(),
this.map.put(TraitementPhase.INITIALISATION,
ApiInitialisationServiceFactory.getInstance());
this.map.put(TraitementPhase.RECEPTION.toString(),
this.map.put(TraitementPhase.RECEPTION,
ApiReceptionServiceFactory.getInstance());
this.map.put(TraitementPhase.CHARGEMENT.toString(),
this.map.put(TraitementPhase.CHARGEMENT,
ApiChargementServiceFactory.getInstance());
this.map.put(TraitementPhase.NORMAGE.toString(),
this.map.put(TraitementPhase.NORMAGE,
ApiNormageServiceFactory.getInstance());
this.map.put(TraitementPhase.CONTROLE.toString(),
this.map.put(TraitementPhase.CONTROLE,
ApiControleServiceFactory.getInstance());
this.map.put(TraitementPhase.MAPPING.toString(),
this.map.put(TraitementPhase.MAPPING,
ApiMappingServiceFactory.getInstance());
}

Expand All @@ -52,7 +52,7 @@ private static final ApiServiceFactory getInstance() {
* @param paramBatch
* @return
*/
public static final ApiService getService(String phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
public static final ApiService getService(TraitementPhase phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch) {
return getInstance().map.get(phaseService).get(phaseService, executionSchema, directory, capacityParameter, paramBatch);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.insee.arc.core.factory;

import fr.insee.arc.core.model.TraitementPhase;
import fr.insee.arc.core.service.global.ApiService;

public interface IServiceFactory {
Expand All @@ -14,6 +15,6 @@ public interface IServiceFactory {
* @param paramBatch
* @return
*/
public ApiService get(String phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch);
public ApiService get(TraitementPhase phaseService, String executionSchema, String directory, Integer capacityParameter, String paramBatch);

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public abstract class ApiService implements IConstanteNumerique {
protected String envExecution;
protected String tablePrevious;

protected String previousPhase;
protected String currentPhase;
protected TraitementPhase previousPhase;
protected TraitementPhase currentPhase;

protected String tablePil;
protected String tablePilTemp;
Expand All @@ -72,7 +72,7 @@ public ApiService() {
springInit();
}

protected ApiService(String aCurrentPhase, String aEnvExecution, String aDirectoryRoot, Integer aNbEnr,
protected ApiService(TraitementPhase aCurrentPhase, String aEnvExecution, String aDirectoryRoot, Integer aNbEnr,
String paramBatch) {

StaticLoggerDispatcher.info(LOGGER_APISERVICE, "** initialiserVariable **");
Expand All @@ -89,7 +89,7 @@ protected ApiService(String aCurrentPhase, String aEnvExecution, String aDirecto

// current phase and compute the previous phase
this.currentPhase = aCurrentPhase;
this.previousPhase = TraitementPhase.valueOf(this.getCurrentPhase()).previousPhase().toString();
this.previousPhase = this.getCurrentPhase().previousPhase();

// number of object to be proceed
this.nbEnr = aNbEnr;
Expand Down Expand Up @@ -150,11 +150,11 @@ private void springInit() {
* @param phaseAncien
* @return
*/
private boolean checkTodo(String tablePil, String phaseAncien) {
private boolean checkTodo(String tablePil, TraitementPhase phaseAncien) {
ArcPreparedStatementBuilder requete = new ArcPreparedStatementBuilder();
boolean checkTodoResult = false;
requete.append("SELECT 1 FROM " + tablePil + " a ");
requete.append("WHERE phase_traitement=" + requete.quoteText(phaseAncien) + " AND "
requete.append("WHERE phase_traitement=" + requete.quoteText(phaseAncien.toString()) + " AND "
+ requete.quoteText(TraitementEtat.OK.toString()) + "=ANY(etat_traitement) ");
requete.append("and etape=1 ");
requete.append("limit 1 ");
Expand All @@ -180,7 +180,7 @@ private boolean checkTodo(String tablePil, String phaseAncien) {
* @param nbEnr
* @throws ArcException
*/
private void register(Connection connexion, String phaseIn, String phase, String tablePil, String tablePilTemp,
private void register(Connection connexion, TraitementPhase phaseIn, TraitementPhase phase, String tablePil, String tablePilTemp,
Integer nbEnr) {
LoggerHelper.info(LOGGER_APISERVICE, "** register **");
try {
Expand Down Expand Up @@ -264,11 +264,11 @@ public void finaliser() {
* @param etat
* @return
*/
public Map<String, List<String>> pilotageListIdsource(String tablePilotage, String aCurrentPhase, String etat) {
public Map<String, List<String>> pilotageListIdsource(String tablePilotage, TraitementPhase aCurrentPhase, String etat) {
LoggerHelper.info(LOGGER_APISERVICE, "pilotageListIdsource");
ArcPreparedStatementBuilder requete = new ArcPreparedStatementBuilder();
requete.append("SELECT container, " + ColumnEnum.ID_SOURCE.getColumnName() + " FROM " + tablePilotage + " ");
requete.append("WHERE phase_traitement=" + requete.quoteText(aCurrentPhase) + " ");
requete.append("WHERE phase_traitement=" + requete.quoteText(aCurrentPhase.toString()) + " ");
requete.append("AND " + requete.quoteText(etat) + "=ANY(etat_traitement); ");
try {
return new GenericBean(
Expand All @@ -289,7 +289,7 @@ public Map<String, List<String>> pilotageListIdsource(String tablePilotage, Stri
* @param etatNew
* @return
*/
public static StringBuilder pilotageMarkIdsource(String tablePilotage, String idSource, String phaseNew,
public static StringBuilder pilotageMarkIdsource(String tablePilotage, String idSource, TraitementPhase phaseNew,
String etatNew, String rapport, String... jointure) {
StringBuilder requete = new StringBuilder();
requete.append("UPDATE " + tablePilotage + " ");
Expand Down Expand Up @@ -336,8 +336,8 @@ public ServiceReporting invokeApi() {
LoggerHelper.info(LOGGER_APISERVICE, "****** Execution " + this.getCurrentPhase() + " *******");
try {

if (this.getCurrentPhase().equals(TraitementPhase.INITIALISATION.toString())
|| this.getCurrentPhase().equals(TraitementPhase.RECEPTION.toString())) {
if (this.getCurrentPhase().equals(TraitementPhase.INITIALISATION)
|| this.getCurrentPhase().equals(TraitementPhase.RECEPTION)) {
this.todo = true;
} else {
this.todo = checkTodo(this.getTablePil(), this.getPreviousPhase());
Expand All @@ -352,7 +352,7 @@ public ServiceReporting invokeApi() {
ex.logFullException();
try {
this.repriseSurErreur(this.connexion.getCoordinatorConnection(), this.getCurrentPhase(),
this.getTablePil(), ex, "aucuneTableADroper");
this.getTablePil(), ex);
} catch (ArcException ex2) {
LoggerHelper.error(LOGGER_APISERVICE, "Error in ApiService.invokeApi.repriseSurErreur");
ex2.logFullException();
Expand Down Expand Up @@ -388,8 +388,7 @@ public void setTablePilTemp(String tablePilTemp) {
* @param tableDrop
* @throws ArcException
*/
private void repriseSurErreur(Connection connexion, String phase, String tablePil, ArcException exception,
String... tableDrop) throws ArcException {
private void repriseSurErreur(Connection connexion, TraitementPhase phase, String tablePil, ArcException exception) throws ArcException {
// nettoyage de la connexion
// comme on arrive ici à cause d'une erreur, la base de donnée attend une fin de
// la transaction
Expand All @@ -403,11 +402,6 @@ private void repriseSurErreur(Connection connexion, String phase, String tablePi
throw new ArcException(rollbackException, ArcExceptionMessage.DATABASE_ROLLBACK_FAILED);
}
StringBuilder requete = new StringBuilder();

for (int i = 0; i < tableDrop.length; i++) {
requete.append("DROP TABLE IF EXISTS " + tableDrop[i] + ";");
}

requete.append("WITH t0 AS ( ");
requete.append(PilotageOperations.queryUpdatePilotageError(phase, tablePil, exception));
requete.append("\n RETURNING " + ColumnEnum.ID_SOURCE.getColumnName() + ") ");
Expand Down Expand Up @@ -451,11 +445,11 @@ public String getTablePil() {
return tablePil;
}

public String getPreviousPhase() {
public TraitementPhase getPreviousPhase() {
return previousPhase;
}

public String getCurrentPhase() {
public TraitementPhase getCurrentPhase() {
return currentPhase;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public static String queryUpdateNbEnr(String tablePilTemp, String tableTravailTe
* @param nbEnr
* @return
*/
public static String queryCopieTablePilotage(String tablePil, String tablePilTemp, String phaseAncien,
String phaseNouveau, Integer nbEnr) {
public static String queryCopieTablePilotage(String tablePil, String tablePilTemp, TraitementPhase phaseAncien,
TraitementPhase phaseNouveau, Integer nbEnr) {
StringBuilder requete = new StringBuilder();

Date date = new Date();
Expand Down Expand Up @@ -124,7 +124,7 @@ public static String queryCopieTablePilotage(String tablePil, String tablePilTem
* @param exception
* @return
*/
public static StringBuilder queryUpdatePilotageError(String phase, String tablePil, Exception exception) {
public static StringBuilder queryUpdatePilotageError(TraitementPhase phase, String tablePil, Exception exception) {
StringBuilder requete = new StringBuilder();
requete.append("UPDATE " + tablePil + " SET etape=2, etat_traitement= '{" + TraitementEtat.KO + "}', rapport="
+ FormatSQL.quoteText(exception.toString()).replace("\r", "") + " ");
Expand Down Expand Up @@ -201,7 +201,7 @@ public static StringBuilder queryResetPreviousPhaseMark(String tablePil, String
* @param tableDrop
* @throws ArcException
*/
public static void traitementSurErreur(Connection connexion, String phase, String tablePil, String idSource,
public static void traitementSurErreur(Connection connexion, TraitementPhase phase, String tablePil, String idSource,
ArcException exception) throws ArcException {
// nettoyage de la connexion
// comme on arrive ici à cause d'une erreur, la base de donnée attend une fin de
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fr.insee.arc.core.dataobjects.ColumnEnum;
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.utils.dao.SQL;
import fr.insee.arc.utils.utils.FormatSQL;

Expand All @@ -24,11 +25,11 @@ private TableNaming() {
* @param suffix optionnal suffix added to the temporary name
* @return
*/
public static String temporaryTableName(String aEnvExecution, String aCurrentPhase, ViewEnum table) {
public static String temporaryTableName(String aEnvExecution, TraitementPhase aCurrentPhase, ViewEnum table) {
return ViewEnum.getFullName(aEnvExecution, FormatSQL.temporaryTableName(aCurrentPhase + "_" + table));
}

public static String phaseDataTableName(String aEnvExecution, String aPhase, TraitementEtat etat) {
public static String phaseDataTableName(String aEnvExecution, TraitementPhase aPhase, TraitementEtat etat) {
return ViewEnum.getFullName(aEnvExecution, aPhase + "_" + etat.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import org.springframework.stereotype.Component;

import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder;
import fr.insee.arc.core.model.TraitementPhase;
import fr.insee.arc.core.service.global.ApiService;
import fr.insee.arc.core.service.p0initialisation.filesystem.RestoreFileSystem;
import fr.insee.arc.core.service.p0initialisation.metadata.SynchronizeRulesAndMetadataOperation;
import fr.insee.arc.core.service.p0initialisation.pilotage.CleanPilotageOperation;
import fr.insee.arc.core.service.p0initialisation.pilotage.SynchronizeDataByPilotageOperation;
import fr.insee.arc.core.service.p0initialisation.useroperation.ReplayOrDeleteFilesOperation;
import fr.insee.arc.utils.dao.UtilitaireDao;
import fr.insee.arc.utils.exception.ArcException;

/**
Expand All @@ -32,7 +31,7 @@ public ApiInitialisationService() {
super();
}

public ApiInitialisationService(String aCurrentPhase, String aEnvExecution, String aDirectoryRoot, Integer aNbEnr,
public ApiInitialisationService(TraitementPhase aCurrentPhase, String aEnvExecution, String aDirectoryRoot, Integer aNbEnr,
String paramBatch) {
super(aCurrentPhase, aEnvExecution, aDirectoryRoot, aNbEnr, paramBatch);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void backToTargetPhase(TraitementPhase phaseAExecuter, String env,
if (phaseAExecuter.getOrdre() == TraitementPhase.INITIALISATION.getOrdre()) {
resetBAS(env, rootDirectory);
} else {
ApiInitialisationService serv = new ApiInitialisationService(TraitementPhase.INITIALISATION.toString(), env,
ApiInitialisationService serv = new ApiInitialisationService(TraitementPhase.INITIALISATION, env,
rootDirectory, TraitementPhase.INITIALISATION.getNbLigneATraiter(), null);
try {
new ResetEnvironmentOperation(serv.getCoordinatorSandbox()).retourPhasePrecedente(phaseAExecuter, undoFilesSelection);
Expand All @@ -51,7 +51,7 @@ public static void backToTargetPhase(TraitementPhase phaseAExecuter, String env,
*/
public static void resetBAS(String env, String rootDirectory) {

ApiInitialisationService service = new ApiInitialisationService(TraitementPhase.INITIALISATION.toString(), env,
ApiInitialisationService service = new ApiInitialisationService(TraitementPhase.INITIALISATION, env,
rootDirectory, TraitementPhase.INITIALISATION.getNbLigneATraiter(), null);
try {
// delete files and pilotage tables
Expand Down
Loading

0 comments on commit ac9f260

Please sign in to comment.