private static Object instance = null;
private static final Object locker = new Object();
- private Traitement traitement;
+ private final Traitement traitement;
private File dataDirectory;
private FileFilter fileFilter;
private AbstractImportPatcherImpl patch;
/**
* @param args
*/
- public AutoPatcher(String[] args) {
+ public AutoPatcher(final String[] args) {
super(args);
- traitement = new Traitement(AutoPatcher.class, BATCH_NAME);
+ this.traitement = new Traitement(AutoPatcher.class, BATCH_NAME);
}
@Override
protected void initialize() throws Exception {
logger.debug("Initialisation du batch : AutoPatcher");
- String dataDirProps = getProps().getProperty(DATA_DIR_PROPNAME);
- String patchClass = getProps().getProperty(PATCH_CLASS_PROPNAME);
- String filePattern = getProps().getProperty(FILE_PATTERN_PROPNAME);
+ final String dataDirProps = this.getProps().getProperty(DATA_DIR_PROPNAME);
+ final String patchClass = this.getProps().getProperty(PATCH_CLASS_PROPNAME);
+ final String filePattern = this.getProps().getProperty(FILE_PATTERN_PROPNAME);
if (!StringUtils.isEmpty(dataDirProps)) {
logger.debug("Initialisation du répertoire de donnée : " + dataDirProps);
- dataDirectory = new File(dataDirProps);
+ this.dataDirectory = new File(dataDirProps);
try {
- if (!dataDirectory.exists()) {
+ if (!this.dataDirectory.exists()) {
throw new Exception("'" + dataDirProps + "' n'existe pas");
}
- if (!dataDirectory.isDirectory()) {
+ if (!this.dataDirectory.isDirectory()) {
throw new Exception("'" + dataDirProps + "' n'est pas un réperoire");
}
- if (!dataDirectory.canWrite()) {
+ if (!this.dataDirectory.canWrite()) {
throw new Exception("'" + dataDirProps + "' n'a pas le droit d'écriture");
}
- if (!dataDirectory.canRead()) {
+ if (!this.dataDirectory.canRead()) {
throw new Exception("'" + dataDirProps + "' n'a pas le droit de lecture");
}
- } catch (Exception e) {
+ } catch (final Exception e) {
logger.error("Erreur lors de l'initialisation du répertoire de données: " + dataDirProps);
throw e;
}
logger.debug("Initialisation du filtre : " + filePattern);
final Pattern ffRegexep = Pattern.compile(StringUtils.isEmpty(filePattern) ? ".*" : filePattern);
- fileFilter = new FileFilter() {
+ this.fileFilter = new FileFilter() {
@Override
- public boolean accept(File f) {
- String absolutePath = f.getAbsolutePath();
- String path = f.getPath();
- String name = f.getName();
+ public boolean accept(final File f) {
+ final String absolutePath = f.getAbsolutePath();
+ final String path = f.getPath();
+ final String name = f.getName();
return ffRegexep.matcher(absolutePath).matches() || ffRegexep.matcher(path).matches() || ffRegexep.matcher(name).matches();
}
};
- } catch (Exception e) {
+ } catch (final Exception e) {
logger.error("Erreur lors de l'initialisation du filtre (regex): " + filePattern);
throw e;
}
} else {
- dataDirectory = null;
+ this.dataDirectory = null;
}
logger.debug("Initialisation du patch : " + patchClass);
try {
- patch = (AbstractImportPatcherImpl) Class.forName(patchClass).newInstance();
- patch.setImportServiceProvider(new ImportServiceBatchProvider(null, null, null));
- } catch (Exception e) {
+ this.patch = (AbstractImportPatcherImpl) Class.forName(patchClass).newInstance();
+ this.patch.setImportServiceProvider(new ImportServiceBatchProvider(null, null, null));
+ } catch (final Exception e) {
logger.error("Impossible d'initialiser le patch : " + patchClass);
throw e;
}
@Override
protected void doProcess() throws Exception {
- if (checkNotRunning()) {
+ if (this.checkNotRunning()) {
FileInfo patchResult;
try {
- if (dataDirectory != null) {
- File[] listFiles = dataDirectory.listFiles(fileFilter);
+ if (this.dataDirectory != null) {
+ final File[] listFiles = this.dataDirectory.listFiles(this.fileFilter);
- for (File patchData : listFiles) {
+ for (final File patchData : listFiles) {
try {
- logger.debug("Application de '" + patch.getClass() + "' avec '" + patchData.getName() + "'");
- patch.setParameter("index.file", patchData);
- patchResult = patch.run();
-
- if(!patchData.delete()){
+ logger.debug("Application de '" + this.patch.getClass() + "' avec '" + patchData.getName() + "'");
+ this.patch.setParameter("index.file", patchData);
+ patchResult = this.patch.run();
+
+ if (!patchData.delete()) {
logger.warn("Impossible de supprimer '" + patchData.getName() + "'");
}
- traitement.addMessage(Traitement.SEVERITY_INFO, patchResult.getMessage());
- } catch (Exception e) {
- logger.error("Lors de l'application de '" + patch.getClass() + "' avec '" + patchData.getName() + "'", e);
- traitement.addMessage(Traitement.SEVERITY_ERROR, "Lors de l'application de '" + patch.getClass() + "' avec '" + patchData.getName() + "' : " + e.getMessage());
+ this.traitement.addMessage(Traitement.SEVERITY_INFO, patchResult.getMessage());
+ } catch (final Exception e) {
+ logger.error("Lors de l'application de '" + this.patch.getClass() + "' avec '" + patchData.getName() + "'", e);
+ this.traitement.addMessage(Traitement.SEVERITY_ERROR, "Lors de l'application de '" + this.patch.getClass() + "' avec '" + patchData.getName() + "' : " + e.getMessage());
}
}
} else {
try {
- logger.debug("Application de '" + patch.getClass() + "'");
- patchResult = patch.run();
- } catch (Exception e) {
- logger.error("Lors de l'application de '" + patch.getClass() + "'", e);
- traitement.addMessage(Traitement.SEVERITY_ERROR, "Lors de l'application de '" + patch.getClass() + "' : " + e.getMessage());
+ logger.debug("Application de '" + this.patch.getClass() + "'");
+ patchResult = this.patch.run();
+ } catch (final Exception e) {
+ logger.error("Lors de l'application de '" + this.patch.getClass() + "'", e);
+ this.traitement.addMessage(Traitement.SEVERITY_ERROR, "Lors de l'application de '" + this.patch.getClass() + "' : " + e.getMessage());
}
}
} finally {
- logger.debug("Fin de '" + patch.getClass() + "'");
- clearLock();
+ logger.debug("Fin de '" + this.patch.getClass() + "'");
+ this.clearLock();
}
} else {
- traitement.setResume("Dejà en cours d'execution");
+ this.traitement.setResume("Dejà en cours d'execution");
}
- traitement.setEnd(System.currentTimeMillis());
+ this.traitement.setEnd(System.currentTimeMillis());
}
@Override