use of ch.interlis.iox_j.plugins.IoxPlugin in project gretl by sogis.
the class IliValidator method validate.
@TaskAction
public void validate() {
log = LogEnvironment.getLogger(IliValidator.class);
if (dataFiles == null) {
return;
}
FileCollection dataFilesCollection = null;
if (dataFiles instanceof FileCollection) {
dataFilesCollection = (FileCollection) dataFiles;
} else {
dataFilesCollection = getProject().files(dataFiles);
}
if (dataFilesCollection == null || dataFilesCollection.isEmpty()) {
return;
}
List<String> files = new ArrayList<String>();
for (java.io.File fileObj : dataFilesCollection) {
String fileName = fileObj.getPath();
files.add(fileName);
}
Settings settings = new Settings();
initSettings(settings);
List<String> userFunctionList = new ArrayList<String>();
userFunctionList.add("ch.so.agi.ilivalidator.ext.IsHttpResourceIoxPlugin");
userFunctionList.add("ch.so.agi.ilivalidator.ext.AreaIoxPlugin");
userFunctionList.add("ch.so.agi.ilivalidator.ext.LengthIoxPlugin");
userFunctionList.add("ch.so.agi.ilivalidator.ext.IsValidDocumentsCycleIoxPlugin");
userFunctionList.add("ch.so.agi.ilivalidator.ext.RingSelfIntersectionIoxPlugin");
userFunctionList.add("ch.so.agi.ilivalidator.ext.TooFewPointsPolylineIoxPlugin");
// userFunctionList.add("ch.so.agi.ilivalidator.ext.IsHttpResourceFromOerebMultilingualUriIoxPlugin");
Map<String, Class> userFunctions = new HashMap<String, Class>();
try {
for (String userFunction : userFunctionList) {
Class clazz = Class.forName(userFunction);
IoxPlugin plugin = (IoxPlugin) clazz.newInstance();
userFunctions.put(((InterlisFunction) plugin).getQualifiedIliName(), clazz);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
log.info("Class not found");
} catch (InstantiationException e) {
e.printStackTrace();
log.error("cannot instantiate class", e);
} catch (IllegalAccessException e) {
e.printStackTrace();
log.error("Class not accessible", e);
}
settings.setTransientObject(ch.interlis.iox_j.validator.Validator.CONFIG_CUSTOM_FUNCTIONS, userFunctions);
validationOk = new Validator().validate(files.toArray(new String[files.size()]), settings);
if (!validationOk && failOnError) {
throw new TaskExecutionException(this, new Exception("validation failed"));
}
}
Aggregations