# Adapteur XSLX en erreur

**URL:** <https://community.simplicite.io/t/adapteur-xslx-en-erreur/2957>\
**Category:** Support\
**Tags:** v4-0\
**Created:** [February 18, 2021, 8:19pm UTC](https://community.simplicite.io/t/adapteur-xslx-en-erreur/2957 "2021-02-18T20:19:40Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Amandine](https://community.simplicite.io/letter_avatar_proxy/v4/letter/a/8baadc/32.png) [@Amandine](https://community.simplicite.io/u/Amandine)\
**Post date:** [February 19, 2021, 3:34pm UTC](https://community.simplicite.io/t/adapteur-xslx-en-erreur/2957/5 "2021-02-19T15:34:23Z")

</div>

Merci @david il me manquait bien le boolean.  
Autre question liée aussi au ticket [Changement du statut d’un adapteur non fonctionnel](https://community.simplicite.io/t/changement-du-statut-dun-adapteur-non-fonctionnel/2685)  
Voici le code de mon adapteur :

```auto
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”

 ![image](https://community.simplicite.io/uploads/default/original/2X/4/4ec4379f1a1303c784d215a82b30d1d693870e9c.png)  
 ![image](https://community.simplicite.io/uploads/default/original/2X/5/5a4e10e0a2359de96aa9a244b393d9ecf1ee2113.png)

L’évolution faite dans le ticket [Changement du statut d’un adapteur non fonctionnel](https://community.simplicite.io/t/changement-du-statut-dun-adapteur-non-fonctionnel/2685) n’a été faite que pour les adapteurs JSON ?

Cordialement.  
Amandine T.

---

_[View the full topic](https://community.simplicite.io/t/adapteur-xslx-en-erreur/2957)._
