Skip to content

Commit

Permalink
ITEM-328 Modif Statut Item
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelQuetin committed Oct 31, 2024
1 parent 654c693 commit 393966e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 68 deletions.
60 changes: 0 additions & 60 deletions core/src/main/java/fr/abes/item/core/service/StatusService.java
Original file line number Diff line number Diff line change
@@ -1,77 +1,17 @@
package fr.abes.item.core.service;

import fr.abes.cbs.exception.CBSException;
import fr.abes.cbs.process.ProcessCBS;
import fr.abes.item.core.constant.Constant;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.stereotype.Service;

import javax.sql.DataSource;
import java.io.IOException;

@Slf4j
@Service
public class StatusService {
@Getter
private ProcessCBS cbs;

@Value("${sudoc.login}")
private String login;

@Value("${sudoc.serveur}")
private String serveurSudoc;

@Value("${sudoc.port}")
private String portSudoc;

@Autowired
private DataSource baseXmlDataSource;

@Autowired
private JdbcTemplate itemJdbcTemplate;

public StatusService() {
this.cbs = new ProcessCBS();
}
/**
* Service sondant le status de la connexion au CBS
* @return true si le client CBS repond, false dans le cas contraire
*/
public Boolean getCbsConnectionStatus() throws CBSException {
try {
cbs.authenticate(serveurSudoc, portSudoc, login, Constant.PASSSUDOC);
return true;
} catch (CBSException | IOException e) {
log.error("serveur " + serveurSudoc + " : " + e.getMessage());
return false;
} finally {
cbs.disconnect();
}
}

/**
* @return true si la requete SQL a fonctionné, ce qui signifie que la base XML est opérationnelle
* false si la connection à la base XML à échoué
*/
public Boolean getXmlConnectionStatus(){
JdbcTemplate jdbcTemplateBaseXml;
jdbcTemplateBaseXml = new JdbcTemplate(baseXmlDataSource);

try {
SqlRowSet objectTest = jdbcTemplateBaseXml.queryForRowSet("select current_date");
return objectTest.first();
} catch (DataAccessException e){
log.error(e.getMessage());
return false;
}
}

/**
* @return true si la requete SQL a fonctionné, ce qui signifie que la base ITEM est opérationnelle
* false si la connection à la base ITEM à échoué
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,16 @@ public InformationApplicationService(StatusService statusService) {
this.statusService = statusService;
}

@Operation(description = "Connaître : Version du front, back, quel application-localhost.properties est actuellement utilisé, url des serveurs sudoc, item, base xml branchés")
@Operation(description = "Connaître : Version du back")
@GetMapping(value = "/applicationDetails")
public String getApplicationDetails() {
return this.applicationVersionBack;
}

@SneakyThrows
@Operation(summary = "Connaitre : Statut base xml, Statut base item, Statut CBS")
@Operation(summary = "Connaitre : Statut base item")
@GetMapping(value = "/applicationStatutServices")
public Map<String, Boolean> getStatutServices() {
Map<String, Boolean> map = new HashMap<>();
map.put("STATUT CBS", statusService.getCbsConnectionStatus());
map.put("STATUT BASE_XML", statusService.getXmlConnectionStatus());
map.put("STATUT BASE_ITEM", statusService.getItemDataBaseStatus());
return map;
public Boolean getStatutServices() {
return statusService.getItemDataBaseStatus();
}
}

0 comments on commit 393966e

Please sign in to comment.