Merci @david il me manquait bien le boolean.
Autre question liée aussi au ticket Changement du statut d’un adapteur non fonctionnel
Voici le code de mon adapteur :
package com.simplicite.adapters.BCSIModule_Meta;
import java.util.*;
import com.simplicite.util.*;
import com.simplicite.util.exceptions.*;
import com.simplicite.util.integration.*;
import com.simplicite.util.tools.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* Adapter SHAREPOINT_BCSIDeployment
*/
public class SHAREPOINT_BCSIDeployment extends SimpleXLSXAdapter {
private static final long serialVersionUID = 1L;
private List<XSSFSheet> sheetToProcessList = new ArrayList();
private boolean hasError = false;
public void log(String text) {
this.getLogWriter().println(text);
}
@Override
public void startProcessWorkbook(XSSFWorkbook workbook) throws InterruptedException {}
@Override
public void startProcessSheet(XSSFSheet sheet) throws InterruptedException {
log("Processing sheet " + sheet.getSheetName());
XSSFRow firstRow = sheet.getRow(sheet.getFirstRowNum());
if (firstRow != null) {
int firstCellNum = firstRow.getFirstCellNum();
XSSFCell cell = firstRow.getCell(firstCellNum);
if (firstRow.getCell(firstCellNum) != null && "ASSET_ID".equals(firstRow.getCell(firstCellNum).getStringCellValue())
&& firstRow.getCell(firstCellNum + 1) != null && "UPDATE Scope".equals(firstRow.getCell(firstCellNum + 1).getStringCellValue())
&& firstRow.getCell(firstCellNum + 2) != null && "Lot migration".equals(firstRow.getCell(firstCellNum + 2 ).getStringCellValue())
) {
sheetToProcessList.add(sheet);
}
}
if (sheetToProcessList.contains(sheet)) {
log("Number of rows to process : " + sheet.getLastRowNum());
} else {
log("Ignoring sheet : it doesn't contain informations");
}
}
@Override
public void startProcessRow(XSSFRow row) throws InterruptedException {
if (sheetToProcessList.contains(row.getSheet()) && row.getRowNum() > row.getSheet().getFirstRowNum()) {
int indexColServerName = row.getSheet().getRow(row.getSheet().getFirstRowNum()).getFirstCellNum();
XSSFCell cell = row.getCell(indexColServerName);
String cellValue = getCellValue(cell);
if (StringUtils.isNotBlank(cellValue)) {
ObjectDB deployment = this.getGrant().getTmpObject("BCSIDeployment");
deployment.getField("DepServId.ServId").setFilter(cell.getStringCellValue());
List<String[]> recordList = deployment.search();
if (recordList != null) {
cell = row.getCell(indexColServerName + 2);
String lot = getCellValue(cell);
if (cell != null && StringUtils.isNotBlank(cell.getStringCellValue())) {
lot = cell.getStringCellValue();
}
int nbUpdated = 0;
for (int i = 0; i < recordList.size(); i++) {
deployment.setValues(recordList.get(i), true);
if (!lot.equals(deployment.getFieldValue("DepMigLot"))) {
deployment.getField("DepMigLot").setValue(lot);
try {
new BusinessObjectTool(deployment).validateAndSave();
nbUpdated++;
} catch (ValidateException | SaveException e) {
log("Impossible to update BCSIDeployment " + deployment.getRowId() + " with lot " + lot);
log(e.toString());
hasError = true;
}
}
}
log("Processing row " + row.getRowNum() + " : server id " + deployment.getField("DepServId.ServId").getFilter() + " " + nbUpdated + " app-server updated");
} else {
log("Ignoring row " + row.getRowNum() + " : unknown server id " + cell.getStringCellValue());
}
} else {
log("Ignoring row " + row.getRowNum() + " : it doesn't contain server id");
}
}
}
private String getCellValue(XSSFCell cell) {
String cellValue = "";
if (cell != null) {
if (CellType.STRING.equals(cell.getCellType())) {
cellValue = cell.getStringCellValue();
} else if (CellType.STRING.equals(cell.getCellType())) {
cellValue = String.valueOf(cell.getNumericCellValue());
}
}
return cellValue;
}
@Override
public String processCell(XSSFCell cell) throws InterruptedException { return ""; }
@Override
public void endProcessRow(XSSFRow row) throws InterruptedException {}
@Override
public void endProcessSheet(XSSFSheet sheet) throws InterruptedException {}
@Override
public void endProcessWorkbook(XSSFWorkbook workbook) throws InterruptedException {
if (hasError) {
// Doesn't work
setStatus(SystemXML.SUPERVISOR_STATUS_IMPORT_ERROR);
// throw new InterruptedException("Failure during the update.");
}
}
}
Dans la méthode endProcessWorkbook, je détecte s’il y a eu des erreurs fonctionnelles et souhaite que le statut passe à “Traité en erreur”.
Dans les logs, j’obtiens bien le statut E. Par contre le statut reste “Traitée sans erreur”
L’évolution faite dans le ticket Changement du statut d’un adapteur non fonctionnel n’a été faite que pour les adapteurs JSON ?
Cordialement.
Amandine T.