import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.util.Hashtable;
import java.util.Map;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.xml.namespace.NamespaceContext;
+import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import fr.gouv.finances.dgfip.utils.Pair;
+import fr.gouv.finances.dgfip.utils.VersionProvider;
import fr.gouv.finances.dgfip.xemelios.auth.UnauthorizedException;
import fr.gouv.finances.dgfip.xemelios.common.config.DocumentModel;
import fr.gouv.finances.dgfip.xemelios.common.config.DocumentsModel;
* @author paul.renier
*
*/
-public class PesControlConnector implements ControlConnector {
-
+public class PesControlConnector implements ControlConnector, VersionProvider {
private static Logger logger = Logger.getLogger(PesControlConnector.class);
+ private static final String CONTROL_VERSION = "Control-Version";
+ private static final String CONTROL_ENGINE_VERSION = "Control-Engine-Version";
+ private static final String CORE_VERSION = "Core-Version";
+
private static final String PES_DOC_ID = "pes-aller";
private static final String PES_CONFIG_PATH = "/pes-config.zip";
private MainControl xemeliosControlEngine;
private ControlProgressListener ctrlPrgListener;
+ protected String controlVersion;
+ protected String controlEngineVersion;
+ protected String coreVersion;
public PesControlConnector() {
OutputStream fOut = new FileOutputStream(f);
try {
- byte[] buffer = new byte[1024];
- int len = 0;
- while ((len = confZipIn.read(buffer)) > 0) {
- fOut.write(buffer, 0, len);
- }
+ IOUtils.copy(confZipIn, fOut);
} finally {
fOut.close();
}
}
}
+ protected void extractVersionInformations() throws IOException {
+ Class<? extends PesControlConnector> myClass = getClass();
+ String myClassName = myClass.getSimpleName() + ".class";
+ String myClassFullName = myClass.getName() + ".class";
+ URL myURL = myClass.getResource(myClassName);
+
+ if ("jar".equalsIgnoreCase(myURL.getProtocol())) {
+ String myUrlStr = myURL.toExternalForm();
+ URL jarManifest = new URL(myUrlStr.substring(0, myUrlStr.length() - myClassFullName.length()) + JarFile.MANIFEST_NAME);
+ InputStream mfIn = jarManifest.openStream();
+
+ try {
+ Manifest manifest = new Manifest(mfIn);
+ Attributes mainAttributes = manifest.getMainAttributes();
+
+ controlEngineVersion = mainAttributes.getValue(CONTROL_ENGINE_VERSION);
+ controlVersion = mainAttributes.getValue(CONTROL_VERSION);
+ coreVersion = mainAttributes.getValue(CORE_VERSION);
+ } finally {
+ mfIn.close();
+ }
+ }
+ }
+
protected DocumentModel loadDocumentModel(File confFolder) throws Exception {
DocumentsModel docModels = Loader.getDocumentsInfos(confFolder.getAbsolutePath());
return docModels.getDocumentById(PES_DOC_ID);
if (tech03 != null) {
schemaLocation = new File(documentModel.getBaseDirectory(), tech03.getParamTechById("schemaLocation").getValue());
}
+
+ extractVersionInformations();
+ logger.debug("Version informations read : Core=" + coreVersion + ", Control-Engine=" + controlEngineVersion + ", Control=" + controlVersion);
} catch (InitializationException e) {
- logger.error(e, e);
throw e;
} catch (Exception e) {
- logger.error(e, e);
throw new InitializationException(e);
}
}
};
+ xemeliosControlEngine.setVersionProvider(this);
+
logger.debug("PesosControlConnector initialization complete");
}
@Override
public ControlResult processControl(File xmlIn, File xmlOut, File reportOut, Map<String, Object> parameters) throws IOException, ParameterNeededException {
+ xemeliosControlEngine.reset();
+
// vérification des paramètres obligatoire
DocumentControlModel dc = xemeliosControlEngine.getDocumentControl();
for (ParamModel pm : dc.getParams()) {
return this.ctrlPrgListener;
}
+ @Override
+ public String getControlEngineVersion() {
+ return controlEngineVersion;
+ }
+
+ @Override
+ public String getControlVersion() {
+ return controlVersion;
+ }
+
+ @Override
+ public String getCoreVersion() {
+ return coreVersion;
+ }
+
private static class ControlContentHandler extends AbstractControlContentHandler {
public ControlContentHandler(String documentId, NamespaceContext nsCtx, DocumentControlModel docCtrlMod, Hashtable<String, Object> parameters, String file, ControlProgressListener cpl) {
super(documentId, nsCtx, docCtrlMod, parameters, file, cpl);
}
}
+ @Override
+ public String getVersion(String moduleId) throws Exception {
+ return getVersion(XemeliosModule.parse(moduleId));
+ }
+
+ @Override
+ public String getVersion(XemeliosModule module) throws Exception {
+ String result = null;
+
+ switch (module) {
+ case CONTROL_CORE:
+ result = getControlEngineVersion();
+ break;
+ case CORE:
+ result = getCoreVersion();
+ break;
+ case PES:
+ result = getControlVersion();
+ break;
+ }
+
+ return result;
+ }
+
}