Skip to content

Commit

Permalink
feat: remove deprecated autowired
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolife999 committed Nov 16, 2024
1 parent e55f51d commit 8bb8d61
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

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

import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder;
import fr.insee.arc.core.dataobjects.ColumnEnum;
Expand All @@ -27,14 +26,12 @@
import fr.insee.arc.utils.database.ArcDatabase;
import fr.insee.arc.utils.exception.ArcException;
import fr.insee.arc.utils.exception.ArcExceptionMessage;
import fr.insee.arc.utils.ressourceUtils.SpringApplicationContext;
import fr.insee.arc.utils.security.SqlInjectionChecked;
import fr.insee.arc.utils.structure.GenericBean;
import fr.insee.arc.utils.textUtils.IConstanteNumerique;
import fr.insee.arc.utils.utils.FormatSQL;
import fr.insee.arc.utils.utils.LoggerHelper;

@Component
public abstract class ApiService implements IConstanteNumerique {

protected static final Logger LOGGER_APISERVICE = LogManager.getLogger(ApiService.class);
Expand Down Expand Up @@ -71,7 +68,6 @@ public abstract class ApiService implements IConstanteNumerique {

public ApiService() {
super();
springInit();
}

protected ApiService(TraitementPhase aCurrentPhase, String aEnvExecution, Integer aNbEnr,
Expand Down Expand Up @@ -135,15 +131,6 @@ private boolean initialiser() {
return this.todo;
}

/** Manually autowire the factory-produced instance. */
private void springInit() {
try {
SpringApplicationContext.autowire(this);
} catch (Exception e) {
//
}
}

/**
* Vérifier si y'a des fichiers à traiter on teste dans la phase précédente si
* on trouve des fichiers OK avec etape=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import fr.insee.arc.utils.utils.LoggerHelper;

/** Transition class. Try to use a LoggerDispatcher as an @Autowired attribute instead. */
@Component
public class StaticLoggerDispatcher {

Expand All @@ -16,7 +15,6 @@ public static void custom(Logger logger, Object message) {
}


/** Transition class. Use a LoggerDispatcher as an @Autowired attribute instead. */
public static void error(Logger logger, Exception e) {
LoggerHelper.error(logger,ExceptionUtils.getStackTrace(e));
}
Expand All @@ -25,48 +23,39 @@ public static void error(Logger logger, Object message) {
LoggerHelper.error(logger,message);
}

/** Transition class. Use a LoggerDispatcher as an @Autowired attribute instead. */
public static void error(Logger logger, Object message, Exception ex) {
LoggerHelper.error(logger,message,ExceptionUtils.getStackTrace(ex));
}

/** Transition class. Use a LoggerDispatcher as an @Autowired attribute instead. */
public static void warn(Logger logger, Object message) {
LoggerHelper.warn(logger,message);
}

/** Transition class. Use a LoggerDispatcher as an @Autowired attribute instead. */
public static void warn(Logger logger, Object message, Exception ex) {
LoggerHelper.warn(logger,message,ex);
}

/** Transition class. Use a LoggerDispatcher as an @Autowired attribute instead. */
public static void info(Logger logger, Object message) {
LoggerHelper.info(logger,message);

}

/** Transition class. Use a LoggerDispatcher as an @Autowired attribute instead. */
public static void info(Logger logger, Object message, Exception ex) {
LoggerHelper.info(logger,message,ex);
}

/** Transition class. Use a LoggerDispatcher as an @Autowired attribute instead. */
public static void debug(Logger logger, Object message) {
LoggerHelper.debug(logger,message);
}

/** Transition class. Use a LoggerDispatcher as an @Autowired attribute instead. */
public static void debug(Logger logger, Object message, Exception ex) {
LoggerHelper.debug(logger,message,ex);
}

/** Transition class. Use a LoggerDispatcher as an @Autowired attribute instead. */
public static void trace(Logger logger, Object message) {
LoggerHelper.trace(logger,message);
}

/** Transition class. Use a LoggerDispatcher as an @Autowired attribute instead. */
public static void trace(Logger logger, Object message, Exception ex) {
LoggerHelper.trace(logger,message,ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
Expand All @@ -36,7 +35,6 @@
import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder;
import fr.insee.arc.core.dataobjects.ColumnEnum;
import fr.insee.arc.core.service.global.dao.FileSystemManagement;
import fr.insee.arc.core.util.LoggerDispatcher;
import fr.insee.arc.utils.dao.ModeRequeteImpl;
import fr.insee.arc.utils.dao.UtilitaireDao;
import fr.insee.arc.utils.database.ArcDatabase;
Expand Down Expand Up @@ -66,6 +64,11 @@
@Scope(scopeName = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
public class VObjectService {

public VObjectService(Session session)
{
this.session=session;
}

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

// filter constants
Expand All @@ -85,12 +88,8 @@ public class VObjectService {

public static final String DEFAULT_FILTER_FUNCTION = "upper";

@Autowired
private Session session;

@Autowired
private LoggerDispatcher loggerDispatcher;

// default database target for query is META_DATA
private Integer connectionIndex = ArcDatabase.COORDINATOR.getIndex();

Expand Down Expand Up @@ -1432,15 +1431,15 @@ public void upload(VObject data, String repertoireCible) throws ArcException {
temporaryFolder = Files.createTempDirectory("tmp_" + System.currentTimeMillis()).toFile();

Path locationTmp = Paths.get(temporaryFolder.getAbsolutePath(), fileName);
loggerDispatcher.info("Upload >> " + locationTmp, LOGGER);
LoggerHelper.info(LOGGER, "Upload >> " + locationTmp);

File newFileTmp = locationTmp.toFile();

// security fix : transferTo not allowed on non temporary directory
uploadedFile.transferTo(newFileTmp);

Path location = Paths.get(repertoireCible, fileName);
loggerDispatcher.info("Transfering uploaded file to >> " + location, LOGGER);
LoggerHelper.info(LOGGER, "Transfering uploaded file to >> " + location);
Files.copy(locationTmp, location, StandardCopyOption.REPLACE_EXISTING);

} catch (IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

Expand All @@ -30,8 +32,8 @@ public void setup() {

@Test
public void indexOk() throws Exception {
// mockMvc.perform(MockMvcRequestBuilders.get("/healthcheck"))
// .andExpect(MockMvcResultMatchers.status().isInternalServerError());
mockMvc.perform(MockMvcRequestBuilders.get("/healthcheck"))
.andExpect(MockMvcResultMatchers.status().is(200));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ public class VObjectServiceTest extends InitializeQueryTest {

@BeforeClass
public static void setup() throws ArcException {

BddPatcherTest.createDatabase();
vObjectService = new VObjectService();
vObjectService.setConnection(c);

Session session = new Session();
HttpSessionTemplate z = new HttpSessionTemplate();
session.setHttpSession(z);
vObjectService.setSession(session);

vObjectService = new VObjectService(session);
vObjectService.setConnection(c);

}

@Rule
Expand All @@ -49,6 +51,8 @@ public void download() throws ArcException, IOException, SQLException {

File root = testFolder.newFolder("root");
String repertoire = root.getAbsolutePath();

buildPropertiesWithoutScalability(repertoire);

String testSandbox1 = "arc_bas1";
VObject viewFichierBAS = new ViewFichierBAS();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ public class EntrepotDaoTest extends InitializeQueryTest {

@BeforeClass
public static void setup() throws ArcException {

BddPatcherTest.createDatabase();
vObjectService = new VObjectService();

vObjectService = new VObjectService(new Session());
vObjectService.setConnection(c);
vObjectService.setSession(new Session());

dao = new DataObjectService();
dao.setSandboxSchema(BddPatcherTest.testSandbox1);
pdao = new EntrepotDao();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ public class ExportDaoTest extends InitializeQueryTest {

@BeforeClass
public static void setup() throws ArcException {

BddPatcherTest.createDatabase();
BddPatcherTest.insertTestDataExport();
vObjectService = new VObjectService();

vObjectService = new VObjectService(new Session());
vObjectService.setConnection(c);
vObjectService.setSession(new Session());

dao = new DataObjectService();
dao.setSandboxSchema(BddPatcherTest.testSandbox1);
pdao = new ExportDao();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ public class GererFamilleNormeDaoTest extends InitializeQueryTest {

@BeforeClass
public static void setup() throws ArcException {

BddPatcherTest.createDatabase();
BddPatcherTest.insertTestDataFamilleNorme();
vObjectService = new VObjectService();

vObjectService = new VObjectService(new Session());
vObjectService.setConnection(c);
vObjectService.setSession(new Session());

dao = new DataObjectService();
dao.setSandboxSchema(BddPatcherTest.testSandbox1);
pdao = new GererFamilleNormeDao();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public class IndexDaoTest extends InitializeQueryTest {
@BeforeClass
public static void setup() throws ArcException {
BddPatcherTest.createDatabase();
vObjectService = new VObjectService();

vObjectService = new VObjectService(new Session());
vObjectService.setConnection(c);
vObjectService.setSession(new Session());

dao = new DataObjectService();
dao.setSandboxSchema(BddPatcherTest.testSandbox1);
pdao = new IndexDao();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ public class MaintenanceParametreDaoTest extends InitializeQueryTest {

@BeforeClass
public static void setup() throws ArcException {

BddPatcherTest.createDatabase();
vObjectService = new VObjectService();

vObjectService = new VObjectService(new Session());
vObjectService.setConnection(c);
vObjectService.setSession(new Session());

dao = new DataObjectService();
dao.setSandboxSchema(BddPatcherTest.testSandbox1);
pdao = new MaintenanceParametreDao();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ public class GererNomenclatureDaoTest extends InitializeQueryTest {

@BeforeClass
public static void setup() throws ArcException {

BddPatcherTest.createDatabase();
BddPatcherTest.insertTestDataLight();
vObjectService = new VObjectService();

vObjectService = new VObjectService(new Session());
vObjectService.setConnection(c);
vObjectService.setSession(new Session());

dao = new DataObjectService();
dao.setSandboxSchema(BddPatcherTest.testSandbox1);
pdao = new GererNomenclatureDao();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ public static void setup() throws ArcException, SQLException {

BddPatcherTest.createDatabase();
BddPatcherTest.insertTestDataSiera();
vObjectService = new VObjectService();

vObjectService = new VObjectService(new Session());
vObjectService.setConnection(c);
vObjectService.setSession(new Session());

dao = new DataObjectService();
dao.setSandboxSchema(BddPatcherTest.testSandbox1);
pdao = new GererNormeDao();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public class PilotageDaoTest extends InitializeQueryTest {

@BeforeClass
public static void setup() throws ArcException {

BddPatcherTest.createDatabase();
vObjectService = new VObjectService();
vObjectService.setConnection(c);

Session session = new Session();
HttpSessionTemplate z = new HttpSessionTemplate();
session.setHttpSession(z);
vObjectService.setSession(session);

vObjectService = new VObjectService(session);
vObjectService.setConnection(c);

dao = new DataObjectService();
dao.setSandboxSchema(BddPatcherTest.testSandbox1);
pdao = new PilotageDao();
Expand Down

0 comments on commit 8bb8d61

Please sign in to comment.