Commit 043e8ff9 authored by marceteau's avatar marceteau
Browse files

création d'une liste de résultat et écriture dans formats.json

parent 784a9aed
......@@ -8,7 +8,11 @@ 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;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -46,6 +50,21 @@ public class FormatValidatorPlugin extends ActionHandler {
ItemStatus itemStatus = new ItemStatus(FORMAT_VALIDATOR_PLUGIN);
List <ValidatorResult> validatorResultList = new ArrayList<ValidatorResult>();
ProcessingUri uri = handlerIO.getOutput(0);
String filename = uri.getPath();
File file = handlerIO.getNewLocalFile(filename);
if (file.exists() && file.length()!=0 ) {
try {
validatorResultList = mapper.readValue(file, new TypeReference <List <ValidatorResult>>() {});
} catch (JsonParseException e) {
LOGGER.error("impossible d'analyser le fichier json {}.", file.getAbsolutePath());
} catch (JsonMappingException e) {
LOGGER.error("impossible de mapper le fichier json {} sur la classe ValidatorResult.", file.getAbsolutePath());
} catch (IOException e) {
LOGGER.error("impossible d'accéder au fichier {}.", file.getAbsolutePath());
}
}
try {
final JsonNode jsonOG = (JsonNode) handlerIO.getInput(0);
......@@ -59,11 +78,11 @@ public class FormatValidatorPlugin extends ActionHandler {
for (final JsonNode versionsArray : versions) {
for (final JsonNode version : versionsArray) {
if (version.get(SedaConstants.TAG_PHYSICAL_ID) == null) {
File file = null;
File fileToValidate = null;
try {
final String objectId = version.get(SedaConstants.PREFIX_ID).asText();
file = loadFileFromWorkspace(handlerIO, objectIdToUri.get(objectId));
Format format = this.validateFormat(file);
fileToValidate = loadFileFromWorkspace(handlerIO, objectIdToUri.get(objectId));
Format format = this.validateFormat(fileToValidate);
ValidatorResult vr = new ValidatorResult();
vr.setFilename(objectIdToUri.get(objectId));
vr.setFormatId(format.getName() + "/" + format.getEncoding() + "/" + format.getVersion());
......@@ -76,19 +95,15 @@ public class FormatValidatorPlugin extends ActionHandler {
}
}
}
ProcessingUri uri = handlerIO.getOutput(0);
String filename = uri.getPath();
// Write your own file
File newFile = handlerIO.getNewLocalFile(filename);
// write it
mapper.writeValue(newFile, validatorResultList);
mapper.writeValue(file, validatorResultList);
// add it to the handler IO
handlerIO.addOutputResult(0, newFile);
handlerIO.addOutputResult(0, file);
}
} catch (Exception e) {
// TODO: handle exception
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));
......
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