Evolution de la gestion des logs des adapteurs

Bonjour,
j’ai un fichier contenant plus de 9000 lignes.
Lors du traitement de chaque ligne, je logge du texte.
Si je rencontre un soucis fonctionnel, je logge l’information dans le getErrorWriter et set un boolean à true.
A la fin de mon traitement si mon boolean est à true, je lance une exception afin de mettre mon import en KO.
A partir de là :

  • Ce que j’ai logé via le errorWriter n’apparait nul part. Ai-je loupé quelque chose ? J’ai essayé avec et sans le lancement de l’exception pensant que le message de l’exception écrasait peut-être l’errorWriter. ==> Evolution : que les logs soient tracés dans le fichier de log “Rejet”

  • Lorsqu’une exception est lancée, aucun log n’est écrit dans le fichier Log. ==> Evolution : ce que je souhaiterai c’est que même si une exception est lancée, les logs soient quand même écrits. Ils permettraient de savoir exactement quelles lignes du fichiers posent problèmes.

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());
								this.getErrorWriter().println("Impossible to update  BCSIDeployment " + deployment.getRowId() + " with lot " + lot);
								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
			this.getErrorWriter().println("The given file is wrongly formatted.");
			setStatus(SystemXML.SUPERVISOR_STATUS_IMPORT_ERROR);
			throw new InterruptedException("Failure during the update.");
		}
	}
}

Exemple de logs :
Cas 1 : lorsque l’on commente le throw new InterruptedException

:
image
Dans notre code, la ValidateException est loggé à la fois dans les logs classiques et dans les logs error. ==> où est le fichier contenant uniquement le résultat du ErrorWriter ? Je m’attendais à ce qu’il soit dans le fichier de rejet.

Cas 2 : lorsque l’on throw new InterruptedException


Le statut est bien marqué en erreur et il y a un fichier de rejet.

  • Malheureusement le fichier de rejet ne contient que le message de l’exception :
    image
  • Le fichier de log ne contient pas les messages loggués avant le lancement de l’exception. ==> Demande d’évolution pour que les logs soient quand même imprimés en cas d’exception.
    image
  • Un fichier xml est partiellement généré, ce qui proque une exception. ==> je ne comprends pas pourquoi les balises de fin sont manquantes, sachant que je ne travaille pas du tout avec le output stream

Merci beaucoup pour votre support et je me tiens à disposition si vous avez d’autres questions.

Cordialement
AMandine T.