Skip to content

Commit

Permalink
recuperation des headers et url dans WSUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
khergalant committed Sep 4, 2024
1 parent b799f34 commit 7fc5857
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 141 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<!-- WS Apogee -->
<apo.ws.version>6.50.01</apo.ws.version>
<apo.ws.prod.version>6.50.01</apo.ws.prod.version>
<apo.ws-utils.version>1.0.4</apo.ws-utils.version>
<apo.ws-utils.version>1.0.3</apo.ws-utils.version>

<!-- Outils -->
<commons.beanutils.version>1.9.4</commons.beanutils.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.List;

import javax.annotation.Resource;
import javax.persistence.Column;
Expand Down Expand Up @@ -83,6 +84,12 @@ public class LaunchAppConfig implements ApplicationListener<ContextRefreshedEven
@Value("${limesurvey.path:}")
private transient String urlLS;

@Value("#{'${ws.apogee.header.etudiantMetier}'.split('" + ConstanteUtils.WS_APOGEE_HEADER_DELIMITER + "')}")
private List<String> wsApogeeHeaderEtudiantMetier;

@Value("#{'${ws.apogee.header.pj}'.split('" + ConstanteUtils.WS_APOGEE_HEADER_DELIMITER + "')}")
private List<String> wsApogeeHeaderPj;

@Override
public void onApplicationEvent(final ContextRefreshedEvent event) {
preprocessLimesurvey();
Expand Down Expand Up @@ -198,11 +205,12 @@ private void changeAnnotationAdresse(final String fieldName, final int size) thr
}

/**
* Charge éventuellement un fichier de config externe pour les fichiers SiScol --> util dans WSutil
* Charge les évenuelles infos pour les WS Apogée --> localisation du repertoire des fichiers SiScol et headers du fichier properties
*/
private void preprocessConfigUrlServicesLocation() {
try {
if (StringUtils.isNotBlank(externalRessource)) {
/* Localisation des fichiers d'url */
final String path = externalRessource + ConstanteUtils.EXTERNAL_RESSOURCE_SISCOL_FOLDER + File.separator;
logger.info("Definition repertoire des fichiers d'URL Siscol : " + path);
WSUtils.setPropertyFilePath(path);
Expand All @@ -213,7 +221,24 @@ private void preprocessConfigUrlServicesLocation() {
// System.setProperty(WSUtils.PROPERTY_FILE_PATH, path);
// }
}
/* On tente d'ajouter les headers de services eventuellement contenus dans le fichier de properties
* (on peut aussi les ajouter directement dans le fichierconfigUrlServices) */
addWsApoHeader(ConstanteUtils.WS_APOGEE_SERVICE_ETUDIANT_METIER, wsApogeeHeaderEtudiantMetier);

addWsApoHeader(ConstanteUtils.WS_APOGEE_SERVICE_PJ, wsApogeeHeaderPj);
} catch (final Exception e) {
}
}

/**
* AJoute les header apogee
* @param serviceName
* @param wsApogeeHeader
*/
private void addWsApoHeader(final String serviceName, final List<String> wsApogeeHeader) {
wsApogeeHeader.forEach(e -> {
final String[] header = e.split(ConstanteUtils.WS_APOGEE_HEADER_SEPARATOR);
WSUtils.addHeader(serviceName + "." + header[0], header[1]);
});
}
}
25 changes: 0 additions & 25 deletions src/main/java/fr/univlorraine/ecandidat/config/SpringConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@

import fr.univlorraine.ecandidat.Initializer;
import fr.univlorraine.ecandidat.utils.ConstanteUtils;
import fr.univlorraine.ecandidat.utils.KeyValue;
import fr.univlorraine.ecandidat.utils.MethodUtils;

/**
Expand Down Expand Up @@ -166,30 +165,6 @@ public static DateTimeFormatter formatterDateTimeApoWsPj() {
return DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
}

/** @return l'url du WS des PJ Apogée */
@Bean
static String urlWsPjApogee() {
return MethodUtils.getUrlWSApogee(ConstanteUtils.WS_APOGEE_PJ_URL_SERVICE);
}

/** @return l'url du WS des PJ Apogée */
@Bean
static KeyValue headerWsPjApogee() {
return MethodUtils.getHeaderWSApogee(ConstanteUtils.WS_APOGEE_PJ_URL_SERVICE);
}

/** @return l'url du WS de verification de l'INES */
@Bean
static String urlWsCheckInes() {
return MethodUtils.getUrlWSApogee(ConstanteUtils.WS_INES_CHECK_URL_SERVICE);
}

/** @return l'url du WS des PJ Apogée */
@Bean
static KeyValue headerWsCheckInes() {
return MethodUtils.getHeaderWSApogee(ConstanteUtils.WS_INES_CHECK_URL_SERVICE);
}

/**
* @return le rest template pegase avec message converter (permet de renvoyernull sur les string vides
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ public class CandidatPieceController {
@Resource(name = "${siscol.implementation}")
private SiScolGenericService siScolService;

@Resource
private transient String urlWsPjApogee;

@Resource
private transient DateTimeFormatter formatterDateTimeApoWsPj;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.vaadin.ui.Notification.Type;
import com.vaadin.ui.UI;

import fr.univlorraine.apowsutils.WSUtils;
import fr.univlorraine.ecandidat.entities.ecandidat.BatchHisto;
import fr.univlorraine.ecandidat.entities.ecandidat.SiScolAnneeUni;
import fr.univlorraine.ecandidat.entities.ecandidat.SiScolBacOptBac;
Expand Down Expand Up @@ -102,9 +103,6 @@ public class SiScolController {
@Resource(name = "${siscol.implementation}")
private SiScolGenericService siScolService;

@Resource
private transient String urlWsPjApogee;

@Resource
private transient ApplicationContext applicationContext;

Expand Down Expand Up @@ -721,8 +719,9 @@ public void testWSSiScolConnnexion() {
*/
public void testWSPJSiScolInfo(final String codEtu, final String codTpj) {
try {
final String urlWsPjApogee = WSUtils.getUrlWS(ConstanteUtils.WS_APOGEE_SERVICE_PJ);
if (urlWsPjApogee == null || urlWsPjApogee.equals("")) {
Notification.show(applicationContext.getMessage("version.ws.pj.noparam", new Object[] { ConstanteUtils.WS_APOGEE_PJ_URL_SERVICE + ConstanteUtils.WS_APOGEE_SERVICE_SUFFIXE }, UI.getCurrent().getLocale()),
Notification.show(applicationContext.getMessage("version.ws.pj.noparam", new Object[] { ConstanteUtils.WS_APOGEE_SERVICE_PJ + ConstanteUtils.WS_APOGEE_SERVICE_SUFFIXE }, UI.getCurrent().getLocale()),
Type.WARNING_MESSAGE);
return;
}
Expand All @@ -746,8 +745,9 @@ public void testWSPJSiScolInfo(final String codEtu, final String codTpj) {
*/
public OnDemandFile testWSPJSiScolFile(final String codEtu, final String codTpj) {
try {
final String urlWsPjApogee = WSUtils.getUrlWS(ConstanteUtils.WS_APOGEE_SERVICE_PJ);
if (urlWsPjApogee == null || urlWsPjApogee.equals("")) {
Notification.show(applicationContext.getMessage("version.ws.pj.noparam", new Object[] { ConstanteUtils.WS_APOGEE_PJ_URL_SERVICE + ConstanteUtils.WS_APOGEE_SERVICE_SUFFIXE }, UI.getCurrent().getLocale()),
Notification.show(applicationContext.getMessage("version.ws.pj.noparam", new Object[] { ConstanteUtils.WS_APOGEE_SERVICE_PJ + ConstanteUtils.WS_APOGEE_SERVICE_SUFFIXE }, UI.getCurrent().getLocale()),
Type.WARNING_MESSAGE);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,6 @@ public void testWsPegase() {
try {
final String codApprenant = bundle.getString("pegase.apprenant.codApprenant");
final WSIndividu ind = siScolService.getIndividu(codApprenant, null, null);
// System.out.println(ind);
// System.out.println(ind.getBac());
// System.out.println(ind.getAdresse());
// ind.getListCursusInterne().forEach(e -> {
// System.out.println(e);
// });
checkString(bundle, String.valueOf(ind.getListCursusInterne().size()), "pegase.apprenant.cursus.size");
} catch (final Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
import fr.univlorraine.ecandidat.entities.siscol.apogee.VoeuxIns;
import fr.univlorraine.ecandidat.services.siscol.SiScolRestUtils.SiScolRestException;
import fr.univlorraine.ecandidat.utils.ConstanteUtils;
import fr.univlorraine.ecandidat.utils.KeyValue;
import fr.univlorraine.ecandidat.utils.MethodUtils;
import fr.univlorraine.ecandidat.utils.NomenclatureUtils;
import gouv.education.apogee.commun.client.ws.EtudiantMetier.AdresseDTO2;
Expand Down Expand Up @@ -192,18 +191,6 @@ public class SiScolApogeeWSServiceImpl implements SiScolGenericService, Serializ
@Resource
private transient DateTimeFormatter formatterDateTimeApo;

@Resource
private transient String urlWsPjApogee;

@Resource
private transient KeyValue headerWsPjApogee;

@Resource
private transient String urlWsCheckInes;

@Resource
private transient KeyValue headerWsCheckInes;

@Resource
private transient BatchController batchController;

Expand Down Expand Up @@ -1684,6 +1671,7 @@ private String getDefaultBacAnneeObt() {
*/
@Override
public WSPjInfo getPjInfoFromApogee(final String codAnu, final String codEtu, final String codPj) throws SiScolException {
final String urlWsPjApogee = WSUtils.getUrlWS(ConstanteUtils.WS_APOGEE_SERVICE_PJ);
// select * from APOGEE.TELEM_IAA_TPJ where COD_ANU = 2016;
if (urlWsPjApogee == null || urlWsPjApogee.equals("")) {
return null;
Expand All @@ -1696,7 +1684,7 @@ public WSPjInfo getPjInfoFromApogee(final String codAnu, final String codEtu, fi
}
params.add("codEtu", codEtu);
params.add("codTpj", codPj);
final List<WSPjInfo> liste = siScolRestServiceInterface.getList(urlWsPjApogee, ConstanteUtils.WS_APOGEE_PJ_INFO, WSPjInfo[].class, params, headerWsPjApogee);
final List<WSPjInfo> liste = siScolRestServiceInterface.getList(urlWsPjApogee, ConstanteUtils.WS_APOGEE_PJ_INFO, WSPjInfo[].class, params, WSUtils.getServiceHeaders(ConstanteUtils.WS_APOGEE_SERVICE_PJ));
if (liste == null) {
return null;
}
Expand Down Expand Up @@ -1738,6 +1726,7 @@ public WSPjInfo getPjInfoFromApogee(final String codAnu, final String codEtu, fi
@Override
public InputStream getPjFichierFromApogee(final String codAnu, final String codEtu, final String codPj) throws SiScolException {
// http://apogee-ws-test.univ-lorraine.fr/apo-ws/services/PJ/fichier?codAnu=2016&codEtu=xxx&codTpj=xxx
final String urlWsPjApogee = WSUtils.getUrlWS(ConstanteUtils.WS_APOGEE_SERVICE_PJ);
if (urlWsPjApogee == null || urlWsPjApogee.equals("")) {
return null;
}
Expand All @@ -1746,7 +1735,7 @@ public InputStream getPjFichierFromApogee(final String codAnu, final String codE
params.add("codAnu", codAnu);
params.add("codEtu", codEtu);
params.add("codTpj", codPj);
return siScolRestServiceInterface.getFile(urlWsPjApogee, ConstanteUtils.WS_APOGEE_PJ_FILE, params, headerWsPjApogee);
return siScolRestServiceInterface.getFile(urlWsPjApogee, ConstanteUtils.WS_APOGEE_PJ_FILE, params, WSUtils.getServiceHeaders(ConstanteUtils.WS_APOGEE_SERVICE_PJ));
} catch (final SiScolRestException e) {
if (e.getErreurType().equals("nullretrieve.etudiantinexistant")) {
return null;
Expand Down Expand Up @@ -1816,7 +1805,7 @@ public void creerOpiPjViaWS(final PjOpi pjOpi, final Fichier file, final InputSt
@Override
public Boolean checkStudentINES(final String ine, final String cle) throws SiScolException {
try {

final String urlWsCheckInes = WSUtils.getUrlWS(ConstanteUtils.WS_APOGEE_SERVICE_CHECKINES);
if (urlWsCheckInes == null || urlWsCheckInes.equals("")) {
return true;
}
Expand All @@ -1829,9 +1818,7 @@ public Boolean checkStudentINES(final String ine, final String cle) throws SiSco
mapPostParameter.put(ConstanteUtils.WS_INES_PARAM_KEY, cle);

final HttpHeaders headers = new HttpHeaders();
if (headerWsCheckInes != null && headerWsCheckInes.isNotEmpty()) {
headers.set(headerWsCheckInes.getKey(), headerWsCheckInes.getValue());
}
WSUtils.getServiceHeaders(ConstanteUtils.WS_APOGEE_SERVICE_CHECKINES).forEach((k, v) -> headers.addAll(k, v));

final HttpEntity<Map<String, String>> request = new HttpEntity<>(mapPostParameter, headers);

Expand All @@ -1848,15 +1835,14 @@ public Boolean checkStudentINES(final String ine, final String cle) throws SiSco
@Override
public String getVersionWSCheckIne() {
try {
final String urlWsCheckInes = WSUtils.getUrlWS(ConstanteUtils.WS_APOGEE_SERVICE_CHECKINES);
if (urlWsCheckInes == null || urlWsCheckInes.equals("")) {
return NomenclatureUtils.VERSION_NO_VERSION_VAL;
}
/* Definition de l'uri */
final URI uri = SiScolRestUtils.getURIForService(urlWsCheckInes, ConstanteUtils.WS_INES_VERSION);
final HttpHeaders headers = new HttpHeaders();
if (headerWsCheckInes != null && headerWsCheckInes.isNotEmpty()) {
headers.set(headerWsCheckInes.getKey(), headerWsCheckInes.getValue());
}
WSUtils.getServiceHeaders(ConstanteUtils.WS_APOGEE_SERVICE_CHECKINES).forEach((k, v) -> headers.addAll(k, v));

final ResponseEntity<String> response = new RestTemplate().exchange(uri, HttpMethod.GET, new HttpEntity<String>(headers), String.class);
if (response == null || response.getBody() == null) {
Expand Down Expand Up @@ -1894,6 +1880,7 @@ public Boolean hasSyncEtudiant() {

@Override
public Boolean hasSyncEtudiantPJ() {
final String urlWsPjApogee = WSUtils.getUrlWS(ConstanteUtils.WS_APOGEE_SERVICE_PJ);
return urlWsPjApogee != null && !urlWsPjApogee.equals("") && parametreController.getIsGetSiScolPJ();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.core.io.Resource;
import org.springframework.http.HttpEntity;
Expand All @@ -34,7 +35,6 @@

import fr.univlorraine.ecandidat.services.siscol.SiScolRestUtils.SiScolResponseErrorHandler;
import fr.univlorraine.ecandidat.services.siscol.SiScolRestUtils.SiScolRestException;
import fr.univlorraine.ecandidat.utils.KeyValue;

/**
* Class utilitaire des services rest de l'AMUE
Expand All @@ -51,17 +51,15 @@ public class SiScolRestServiceInterface {
* @return une liste d'objets pour un service donné
* @throws SiScolException
*/
public <T> List<T> getList(final String url, final String service, final Class<T[]> klass, final MultiValueMap<String, String> mapGetParameter, final KeyValue header) throws SiScolRestException, SiScolException {
public <T> List<T> getList(final String url, final String service, final Class<T[]> klass, final MultiValueMap<String, String> mapGetParameter, final Map<String, List<String>> header)
throws SiScolRestException, SiScolException {
try {
final URI targetUrl = SiScolRestUtils.getURIForService(url, service, mapGetParameter);
final RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new SiScolResponseErrorHandler());

final HttpHeaders headers = new HttpHeaders();
if (header != null && header.isNotEmpty()) {
headers.set(header.getKey(), header.getValue());
}

header.forEach((k, v) -> headers.addAll(k, v));
final ResponseEntity<T[]> response = restTemplate.exchange(targetUrl, HttpMethod.GET, new HttpEntity<T[]>(headers), klass);

final List<T> liste = Arrays.asList(response.getBody());
Expand All @@ -81,17 +79,15 @@ public <T> List<T> getList(final String url, final String service, final Class<T
* @throws SiScolRestException
* @throws SiScolException
*/
public InputStream getFile(final String url, final String service, final MultiValueMap<String, String> mapGetParameter, final KeyValue header) throws SiScolRestException, SiScolException {
public InputStream getFile(final String url, final String service, final MultiValueMap<String, String> mapGetParameter, final Map<String, List<String>> header) throws SiScolRestException, SiScolException {
try {
final URI targetUrl = SiScolRestUtils.getURIForService(url, service, mapGetParameter);
final RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new SiScolResponseErrorHandler());
restTemplate.getMessageConverters().add(new ResourceHttpMessageConverter());
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM));
if (header != null && header.isNotEmpty()) {
headers.set(header.getKey(), header.getValue());
}
header.forEach((k, v) -> headers.addAll(k, v));

final HttpEntity<String> entity = new HttpEntity<>(headers);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public class SiScolRestUtils {
* @return l'uri du service demandé
*/
public static URI getURIForService(final String path, final String service, final MultiValueMap<String, String> mapGetParameter) {
return UriComponentsBuilder.fromUriString(path).path(service).queryParams(mapGetParameter).build().encode().toUri();
String finalPath = path;
if (!finalPath.endsWith("/")) {
finalPath = finalPath + "/";
}
return UriComponentsBuilder.fromUriString(finalPath).path(service).queryParams(mapGetParameter).build().encode().toUri();
}

/**
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/fr/univlorraine/ecandidat/utils/ConstanteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -492,21 +492,28 @@ public class ConstanteUtils {
public static final String SECURITY_SWITCH_BACK_PATH = "/logout/impersonate";
public static final String SECURITY_ROLE_PREFIXE = "ROLE_";

/* WS Apogée */
public static final String WS_APOGEE_SERVICE_ETUDIANT_METIER = "etudiantMetier";
public static final String WS_APOGEE_SERVICE_PEDAGOGIQUE_METIER = "pedagogiqueMetier";
public static final String WS_APOGEE_SERVICE_OPI_METIER = "opiMetier";
public static final String WS_APOGEE_SERVICE_PJ_OPI_METIER = "pjOpiMetier";
public static final String WS_APOGEE_SERVICE_PJ = "pj";
public static final String WS_APOGEE_SERVICE_CHECKINES = "checkInes";
public static final String WS_APOGEE_HEADER_DELIMITER = ",";
public static final String WS_APOGEE_HEADER_SEPARATOR = "\\|\\|";

/* Constantes Webservice Apo */
public static final String WS_APOGEE_SERVICE_SUFFIXE = ".urlService";
public static final String WS_APOGEE_HEADER_PREFIXE = "api.header.";

/* Charset Rest ApoWS */
public static final String WS_APOGEE_PROP_FILE = "configUrlServices";
public final static String WS_APOGEE_PROP_EXTENSION = ".properties";
public static final String WS_APOGEE_DEFAULT_CHARSET = "UTF-8";
public static final String WS_APOGEE_PJ_URL_SERVICE = "pj";

/* WS PJ */
public static final String WS_APOGEE_PJ_INFO = "info";
public static final String WS_APOGEE_PJ_FILE = "fichier";
public static final String WS_APOGEE_PJ_TEM_VALID_CODE = "V";

/* WS INES */
public static final String WS_INES_CHECK_URL_SERVICE = "checkInes";
public static final String WS_INES_CHECK_SERVICE = "/v1/check-ine";
public static final String WS_INES_VERSION = "/version";
public static final String WS_INES_PARAM_INE = "ine";
Expand Down
Loading

0 comments on commit 7fc5857

Please sign in to comment.