Commit b88b5ec5 authored by marceteau's avatar marceteau
Browse files

mise en place du retour en format ko

parent 043e8ff9
......@@ -8,7 +8,6 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.xerces.impl.dv.dtd.ListDatatypeValidator;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
......@@ -17,9 +16,9 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.cines.Format;
import fr.cines.format.validator.FormatErrorException;
import fr.cines.format.validator.UnknownFormatException;
import fr.cines.format.validator.ValidatorBean;
import fr.cines.format.validator.model.ValidableFormat;
import fr.gouv.vitam.common.SedaConstants;
import fr.gouv.vitam.common.logging.VitamLogger;
import fr.gouv.vitam.common.logging.VitamLoggerFactory;
......@@ -44,9 +43,9 @@ public class FormatValidatorPlugin extends ActionHandler {
private final ObjectMapper mapper = new ObjectMapper();
public ItemStatus execute(WorkerParameters workerParameters, HandlerIO handlerIO) {
LOGGER.warn("===========================================================");
LOGGER.warn("================= FORMAT_VALIDATOR_PLUGIN ============== ");
LOGGER.warn("===========================================================");
LOGGER.info("===========================================================");
LOGGER.info("================= FORMAT_VALIDATOR_PLUGIN ============== ");
LOGGER.info("===========================================================");
ItemStatus itemStatus = new ItemStatus(FORMAT_VALIDATOR_PLUGIN);
List <ValidatorResult> validatorResultList = new ArrayList<ValidatorResult>();
......@@ -82,12 +81,18 @@ public class FormatValidatorPlugin extends ActionHandler {
try {
final String objectId = version.get(SedaConstants.PREFIX_ID).asText();
fileToValidate = loadFileFromWorkspace(handlerIO, objectIdToUri.get(objectId));
LOGGER.warn("Validation du fichier :{}", fileToValidate);
Format format = this.validateFormat(fileToValidate);
ValidatorResult vr = new ValidatorResult();
vr.setFilename(objectIdToUri.get(objectId));
vr.setFormatId(format.getName() + "/" + format.getEncoding() + "/" + format.getVersion());
validatorResultList.add(vr);
} catch (Exception e) {
} catch (FormatErrorException fe) {
itemStatus.increment(StatusCode.KO);
itemStatus.setMessage(fe.getMessage());
LOGGER.warn("Erreur lors de le validation : {}, {}", fileToValidate, fe.getMessage());
return new ItemStatus(FORMAT_VALIDATOR_PLUGIN).setItemsStatus(itemStatus.getItemId(), itemStatus);
} catch (Exception e) {
LOGGER.warn("erreur lors de la validation du format" + e.getMessage());
}
}
......@@ -106,7 +111,8 @@ public class FormatValidatorPlugin extends ActionHandler {
LOGGER.error("erreur du plugin lors de la validation de format " + e.getMessage());
}
return new ItemStatus(FORMAT_VALIDATOR_PLUGIN).setItemsStatus(FORMAT_VALIDATOR_PLUGIN, itemStatus.increment(StatusCode.OK));
itemStatus.increment(StatusCode.OK);
return itemStatus;
}
private Map<String, String> getMapOfObjectsIdsAndUris(JsonNode jsonOG) {
......@@ -155,7 +161,7 @@ public class FormatValidatorPlugin extends ActionHandler {
}
}
protected Format validateFormat(/*final DataObject dataObject,*/ final File file) {
protected Format validateFormat(/*final DataObject dataObject,*/ final File file) throws FormatErrorException {
final ValidatorBean validator = new ValidatorBean();
try {
......@@ -174,12 +180,15 @@ public class FormatValidatorPlugin extends ActionHandler {
}
*/
validator.setFile(file);
} catch (final IOException | UnknownFormatException e) {
} catch (final IOException e) {
// throw new ValidateFormatException(depositId, e);
}
}catch (UnknownFormatException e) {
// TODO: handle exception
}
if (!validator.isValid()) {
// throw new InvalidFormatException(depositId, dataObject.getPath(), validator.getMessage());
throw new FormatErrorException(new Exception(validator.getMessage()));
}
final Format format = validator.getIdentifiedFormat();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment