</requires>
<configurator>fr.gouv.finances.cp.xemelios.ui.patches.Log4JPatch</configurator>
<release-notes>
+ <note visibility="public">IHM pour les imports partiels, y compris boite de suppression</note>
<note visibility="dev">compatibilité core imports-partiels</note>
<note visibility="public">Modification du log4j.xml pour le rendre compatible avec ToTEM</note>
<note visibility="editeur">Déplacement de commons-codec et commons-logging vers core</note>
@Override
public void setEtatImporter(EtatImporteur ei) {
this.ei = ei;
- try{
-//displayProgress(ei.getFilesToImport().length);
- } catch (Exception e) {
- logger.debug("Problèmes dans setEtatImporter(EtatImporteur ei) : Pb de displayProgress()",e);
- }
- /*ei.addPropertyChangeListener(new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- String propName = evt.getPropertyName();
- logger.debug("property " + propName + " changed");
- if ("FILE_NAME".equals(propName)) {
- pg.setCurrentFile((String) evt.getNewValue());
- } else if ("progress".equals(propName)) {
- Integer progress = (Integer) evt.getNewValue();
- pg.pushCurrentProgress(progress.intValue());
- } else if ("terminated".equals(propName)) {
- pg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
- pg.setVisible(false);
- }
- }
- });*/
}
@Override
Runnable code = new Runnable() {
@Override
- public void run() {
- logger.debug(this.getClass().getName());
+ public synchronized void run() {
if (pg == null) {
pg = new ProgressDlg(owner, nbFiles, ei);
}
if (ei != null) {
- ei.addPropertyChangeListener(new PropertyChangeListener() {
+ ei.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
String propName = evt.getPropertyName();
-// logger.debug("property "+propName+" changed");
if ("FILE_NAME".equals(propName)) {
pg.setCurrentFile((String) evt.getNewValue());
} else if ("progress".equals(propName)) {
super(owner, "Import en cours...");
this.nbFilesToImport = nbFilesToImport;
this.ei = ei;
- initComponents(nbFilesToImport);
+ initComponents();
}
- protected void initComponents(int nbFilesToImport) {
+ protected void initComponents() {
IhmFactory iF = IhmFactory.newInstance();
FormLayout fl = null;
if (SHOW_CANCEL_BUTTON) {
*/
package fr.gouv.finances.cp.xemelios.ui;
+import fr.gouv.finances.cp.utils.PropertiesExpansion;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.util.HashMap;
import org.apache.log4j.Logger;
import org.jdesktop.swingworker.SwingWorker;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
import fr.gouv.finances.cp.utils.ui.DisplayExceptionDlg;
+import fr.gouv.finances.dgfip.utils.DateUtils;
import fr.gouv.finances.dgfip.utils.Pair;
import fr.gouv.finances.dgfip.utils.xml.FactoryProvider;
import fr.gouv.finances.dgfip.xemelios.auth.UnauthorizedException;
import fr.gouv.finances.dgfip.xemelios.auth.XemeliosUser;
+import fr.gouv.finances.dgfip.xemelios.common.Constants;
+import fr.gouv.finances.dgfip.xemelios.common.FileInfo;
import fr.gouv.finances.dgfip.xemelios.common.config.DocumentModel;
import fr.gouv.finances.dgfip.xemelios.common.config.DocumentsModel;
import fr.gouv.finances.dgfip.xemelios.data.DataAccessException;
import fr.gouv.finances.dgfip.xemelios.data.ExportableData;
import fr.gouv.finances.dgfip.xemelios.data.WaitableUI;
import fr.gouv.finances.dgfip.xemelios.importers.AbstractImportPatcherImpl;
-import fr.gouv.finances.dgfip.xemelios.utils.XmlUtils;
+import fr.gouv.finances.dgfip.xemelios.importers.EtatImporteur;
+import fr.gouv.finances.dgfip.xemelios.importers.ImportServiceProvider;
+import fr.gouv.finances.dgfip.xemelios.importers.NullImportServiceProvider;
+import fr.gouv.finances.dgfip.xemelios.importers.archives.ArchiveImporter;
+import fr.gouv.finances.dgfip.xemelios.utils.FileUtils;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.lang.reflect.Constructor;
+import java.nio.charset.Charset;
+import java.util.Date;
+import nu.xom.Attribute;
+import nu.xom.Element;
+import nu.xom.Nodes;
@SuppressWarnings("serial")
public class DlgCleanDatabase extends DlgChooseDocuments implements WaitableUI {
private static Logger logger = Logger.getLogger(DlgCleanDatabase.class);
private XemeliosUser user;
+ private PropertiesExpansion applicationProperties;
- public DlgCleanDatabase(java.awt.Frame parent, boolean modal, DocumentsModel _dm, DlgChooseDocuments.DIALOG_TYPE dialogType, XemeliosUser user) {
+ public DlgCleanDatabase(java.awt.Frame parent, boolean modal, DocumentsModel _dm, DlgChooseDocuments.DIALOG_TYPE dialogType, XemeliosUser user, PropertiesExpansion applicationProperties) {
super(parent, modal, _dm, true, dialogType, user, MainWindow.getInstance().getEnvProperties());
this.user = user;
+ this.applicationProperties = applicationProperties;
setTitle("Suppression");
setBActionLibelle("Supprimer");
setVisible(true);
@Override
public void run() {
try {
- Document manifeste = DataLayerManager.getImplementation().getManifesteFromArchive(((Pair)node.getData()).libelle, user);
+ nu.xom.Document manifeste = DataLayerManager.getImplementation().getManifesteFromArchive(((Pair)node.getData()).libelle, user);
if (manifeste != null) {
XPathFactory xpf = FactoryProvider.getXPathFactory();
XPath xp = xpf.newXPath();
xp.setNamespaceContext(MainWindow.getInstance().getDocModels().getDocumentById("manifeste").getNamespaces());
- NodeList documentIds = (NodeList) xp.evaluate("//n:document/@type", manifeste.getDocumentElement(), XPathConstants.NODESET);
+ Nodes documentIds = manifeste.query("//m:document/@type", ArchiveImporter.getNamespaceCtx());
HashMap<String, DocumentModel> docsModel = new HashMap<String, DocumentModel>();
- for (int i = 0; i < documentIds.getLength(); i++) {
- String docId = documentIds.item(i).getNodeValue();
- if ("CGE".equals(docId)) {
- docId = "cg-colloc";
- } else if ("CGETAT".equals(docId)) {
- docId = "cg-etat";
- } else if ("PES".equals(docId)) {
- docId = "pes-aller";
- } else if ("EDMN".equals(docId)) {
- docId = "edmn";
- } else if ("ERTN".equals(docId)) {
- docId = "ertn";
- } else if ("PJ".equals(docId)) {
- docId = null;
- }
+ for (int i = 0; i < documentIds.size(); i++) {
+ String docId = documentIds.get(i).getValue();
+ docId = ArchiveImporter.normalizeDocumentType(docId);
+ if("PJ".equals(docId)) docId=null;
if ( docId!=null && !docsModel.containsKey(docId)) {
try {
docsModel.put(docId, MainWindow.getInstance().getDocModels().getDocumentById(docId));
}
}
DataLayerManager.getImplementation().removeArchive(docsModel, ((Pair)node.getData()).libelle, user);
-
+logger.debug("ici, node.getData().libelle = "+((Pair)node.getData()).libelle);
// Mise à jour du manifeste de l'archive
- DataLayerManager.getImplementation().updateManifeste(((Pair)node.getData()).libelle, user);
+// DataLayerManager.getImplementation().updateManifeste(((Pair)node.getData()).libelle, user);
+ Nodes documents = manifeste.query("/m:manifeste/m:documents/m:document", ArchiveImporter.getNamespaceCtx());
+ for(int i=0;i<documents.size();i++) {
+ nu.xom.Element doc = (nu.xom.Element)documents.get(i);
+ nu.xom.Element resultImport = ArchiveImporter.getElement(doc.query("m:resultatimport | resultatimport", ArchiveImporter.getNamespaceCtx()));
+ if(resultImport!=null) doc.removeChild(resultImport);
+ doc.addAttribute(new Attribute("imported","Non"));
+ }
+ nu.xom.Element evt = new Element("evenement");
+ evt.addAttribute(new Attribute("date", DateUtils.formatXsDateTime(new Date())));
+ evt.addAttribute(new Attribute("section", "Suppression complète"));
+ Element evts = ArchiveImporter.getElement(manifeste.query("/m:manifeste/m:evenements", ArchiveImporter.getNamespaceCtx()));
+ evts.insertChild(evt, 0);
+ manifeste.getRootElement().addAttribute(new Attribute("imported", "Non"));
+ manifeste.getRootElement().addAttribute(new Attribute("added:archive", Constants.ADDED_NS_URI,"Non"));
+ Element resultImport = ArchiveImporter.getElement(manifeste.query("/m:manifeste/m:resultatimport", ArchiveImporter.getNamespaceCtx()));
+ if(resultImport!=null) resultImport.getParent().removeChild(resultImport);
+ Element section = ArchiveImporter.getElement(manifeste.query("/m:manifeste/m:section", ArchiveImporter.getNamespaceCtx()));
+ if(section!=null) section.getParent().removeChild(section);
+ // le /manifeste/fakes sera créé par l'importeur, il faut le supprimer
+ Element fakes = ArchiveImporter.getElement(manifeste.query("/m:manifeste/m:fakes", ArchiveImporter.getNamespaceCtx()));
+ if(fakes!=null) fakes.getParent().removeChild(fakes);
+
// Suppression dans le referentiel collectivite
- XmlUtils.showDomInConsole(manifeste, "Manifeste de la base");
- NodeList actionsOnDelete = (NodeList) xp.evaluate("//n:on-delete/n:action", manifeste.getDocumentElement(), XPathConstants.NODESET);
- for (int compteurAction = 0; compteurAction < actionsOnDelete.getLength(); compteurAction++) {
- Element action = (Element) actionsOnDelete.item(compteurAction);
- String className = action.getAttribute("class");
+// XmlUtils.showDomInConsole(manifeste, "Manifeste de la base");
+ Nodes actionsOnDelete = manifeste.query("//m:on-delete/m:action", ArchiveImporter.getNamespaceCtx());
+ for (int compteurAction = 0; compteurAction < actionsOnDelete.size(); compteurAction++) {
+ nu.xom.Element action = (nu.xom.Element) actionsOnDelete.get(compteurAction);
+ String className = action.getAttributeValue("class");
Class clazz = Class.forName(className);
Object instance = clazz.newInstance();
if (!(instance instanceof AbstractImportPatcherImpl)) {
}
AbstractImportPatcherImpl patcher = (AbstractImportPatcherImpl) instance;
- Object o = xp.evaluate("n:parameter", action, XPathConstants.NODESET);
- if (o instanceof NodeList) {
- NodeList nl = (NodeList) o;
- for (int i = 0; i < nl.getLength(); i++) {
- Element param = (Element) nl.item(i);
- String paramName = param.getAttribute("name");
- String type = param.getAttribute("type");
- if ("java.lang.String".equals(type)) {
- String value = param.getAttribute("value");
- if (value == null) {
- value = (String) xp.evaluate("./text()", param, XPathConstants.STRING);
- }
- patcher.setParameter(paramName, value);
- } else if ("java.lang.Integer".equals(type)) {
- String value = param.getAttribute("value");
- if (value == null) {
- value = (String) xp.evaluate("./text()", param, XPathConstants.STRING);
- }
- patcher.setParameter(paramName, Integer.valueOf(value));
+ Nodes parameters = action.query("m:parameter", ArchiveImporter.getNamespaceCtx());
+ for (int i = 0; i < parameters.size(); i++) {
+ nu.xom.Element param = (nu.xom.Element) parameters.get(i);
+ String paramName = param.getAttributeValue("name");
+ String type = param.getAttributeValue("type");
+ if ("java.lang.String".equals(type)) {
+ String value = param.getAttributeValue("value");
+ if (value == null) {
+ value = (String) xp.evaluate("./text()", param, XPathConstants.STRING);
+ }
+ patcher.setParameter(paramName, value);
+ } else if ("java.lang.Integer".equals(type)) {
+ String value = param.getAttributeValue("value");
+ if (value == null) {
+ value = (String) xp.evaluate("./text()", param, XPathConstants.STRING);
}
+ patcher.setParameter(paramName, Integer.valueOf(value));
}
}
patcher.run();
}
+ doImportManifeste(manifeste, manifeste.getRootElement().getAttributeValue("archive-name"));
} else {
JOptionPane.showMessageDialog(getParent(), "La base de donnée ne contient rien provennat de cette archive.", "Aucune donnée n'a été supprimée", JOptionPane.WARNING_MESSAGE);
}
deleter.execute();
}
}
+ protected void doImportManifeste(nu.xom.Document manif, String archiveName) throws IOException {
+ DocumentModel dm = getDm().getDocumentById("manifeste2");
+ String idColl = "0000";
+ String libColl = "Traçabilité";
+ String idBudg = "00";
+ String libBudg = "--";
+
+ Pair collectivite = new Pair(idColl, libColl);
+ Pair budget = new Pair(idBudg, libBudg);
+ try {
+ DataLayerManager.getImplementation().removeDocument(dm, budget, collectivite, archiveName+".xml", user);
+ } catch(Exception ex) {
+ logger.error("while dropping previous manifeste", ex);
+ }
+
+ File outputFile = null;
+ try {
+ outputFile = new File(FileUtils.getTempDir(), archiveName+".xml");
+ Charset cs = Charset.forName("UTF-8");
+ OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(outputFile),cs);
+ osw.write(manif.toXML());
+ osw.flush();
+ osw.close();
+ Class clazz = Class.forName(dm.getImportClass());
+ Constructor cc = clazz.getConstructor(XemeliosUser.class, PropertiesExpansion.class);
+ Object obj = cc.newInstance(user, applicationProperties);
+ if (!(obj instanceof EtatImporteur)) {
+ throw new DataConfigurationException("Cette classe n'est pas un importeur.\nLe fichier de configuration qui vous a été livré est certainement invalide.\nVeuillez contacter votre fournisseur.");
+ }
+ EtatImporteur ei = (EtatImporteur) obj;
+ ImportServiceProvider importServiceProvider = new NullImportServiceProvider();
+ ei.setArchiveName(archiveName);
+ ei.setImpSvcProvider(importServiceProvider);
+ ei.setOverwriteRule("never");
+ ei.setApplicationConfiguration(applicationProperties);
+
+ ei.setDocument(dm);
+ File[] fichiers = new File[]{outputFile};
+ ei.setFilesToImport(fichiers);
+
+ importServiceProvider.setCollectivite(collectivite);
+ importServiceProvider.setBudget(budget);
+ ei.setCollectivite(collectivite);
+ ei.setBudget(budget);
+ importServiceProvider.setEtatImporter(ei);
+
+ ei.run();
+ FileInfo fInfo = ei.getFileInfo();
+ if(ei.getWarningCount()>0)
+ fInfo.setWarningCount(ei.getWarningCount());
+ return;
+ } catch (Exception ex) {
+ logger.error("importer", ex);
+ return;
+ } finally {
+ if (outputFile.exists()) {
+ outputFile.delete();
+ }
+ }
+ }
private class Deleter extends SwingWorker {
dlg.enableButtons(true);
}
}
+
}
import fr.gouv.finances.cp.xemelios.ui.firststart.PnlFirstAbo;
import fr.gouv.finances.cp.xemelios.ui.firststart.PnlFirstConfigProxy;
import fr.gouv.finances.cp.xemelios.ui.firststart.PnlPresentation;
+import fr.gouv.finances.cp.xemelios.ui.importArchive.ArchiveWizardDisplayer;
import fr.gouv.finances.cp.xemelios.ui.importDialog.ImportDialog;
import fr.gouv.finances.cp.xemelios.ui.importDialog.ImportFile;
import fr.gouv.finances.cp.xemelios.ui.navigate.Navigable;
import fr.gouv.finances.dgfip.xemelios.auth.UnauthorizedException;
import fr.gouv.finances.dgfip.xemelios.data.impl.pool.Pool;
import fr.gouv.finances.dgfip.xemelios.data.impl.pool.PoolManager;
-import fr.gouv.finances.dgfip.xemelios.importers.XemeliosArchiveImporter;
+import fr.gouv.finances.dgfip.xemelios.importers.archives.ArchiveImporter;
import fr.gouv.finances.dgfip.xemelios.tools.MenuTitle;
import fr.gouv.finances.dgfip.xemelios.tools.ToolConstants;
import fr.gouv.finances.dgfip.xemelios.ui.ImageResources;
@Override
public void actionPerformed(ActionEvent evt) {
- new DlgCleanDatabase(MainWindow.this, true, docModels, DlgChooseDocuments.DIALOG_TYPE.BOTH, getConnectedUser());
+ new DlgCleanDatabase(MainWindow.this, true, docModels, DlgChooseDocuments.DIALOG_TYPE.BOTH, getConnectedUser(), getEnvProperties());
}
});
fc.setFileFilter(defaultFileFilter);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false);
- fc.setDialogTitle("Choisissez le premier fichier d'une archive XeMeLios");
+ fc.setDialogTitle("Choisissez une archive XeMeLios");
fc.setApproveButtonText("Importer");
if(fc.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) {
File firstArchive = fc.getSelectedFile();
lastInputDirectory = firstArchive.getParentFile();
- ImportServiceSwingProvider isp = new ImportServiceSwingProvider(this, null, 0);
- isp.setDisplayFeedback(false);
- XemeliosArchiveImporter xai = new XemeliosArchiveImporter(docModels, firstArchive, isp, getEnvProperties());
- xai.setUser(connectedUser);
- XemeliosArchiveImporterWorker worker = new XemeliosArchiveImporterWorker(xai);
- worker.execute();
+ ArchiveWizardDisplayer awd = new ArchiveWizardDisplayer(this, firstArchive);
}
}
public static class XemeliosArchiveImporterWorker extends SwingWorker< Errors, String> {
- private XemeliosArchiveImporter importer;
+ private ArchiveImporter importer;
private Errors errors;
- public XemeliosArchiveImporterWorker(XemeliosArchiveImporter importer) {
+ public XemeliosArchiveImporterWorker(ArchiveImporter importer) {
super();
this.importer = importer;
}
logger.warn(sb2.toString());
}
try {
- sb.append(importer.getFileInfo().toString(Loader.getDocumentsInfos(null)));
+ sb.append(importer.getFileInfo().toString(importer.getDocumentsModel()));
} catch(Exception ex) {}
if (sb.length() > 0) {
JOptionPane.showMessageDialog(MainWindow.getInstance(), sb.toString());
--- /dev/null
+/*
+ * Copyright
+ * 2012 axYus - http://www.axyus.com
+ * 2012 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS_NB.
+ *
+ * XEMELIOS_NB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS_NB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with XEMELIOS_NB; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+package fr.gouv.finances.cp.xemelios.ui.importArchive;
+
+import fr.gouv.finances.cp.utils.ui.DisplayExceptionDlg;
+import fr.gouv.finances.cp.xemelios.importers.ImportServiceSwingProvider;
+import fr.gouv.finances.cp.xemelios.ui.MainWindow;
+import fr.gouv.finances.dgfip.xemelios.common.config.DocumentModel;
+import fr.gouv.finances.dgfip.xemelios.data.DataLayerManager;
+import fr.gouv.finances.dgfip.xemelios.importers.EtatImporteur;
+import fr.gouv.finances.dgfip.xemelios.importers.archives.ArchiveImporter;
+import fr.gouv.finances.dgfip.xemelios.importers.archives.rules.ActionsModel;
+import fr.gouv.finances.dgfip.xemelios.importers.archives.rules.AttributeModel;
+import fr.gouv.finances.dgfip.xemelios.importers.archives.rules.FilterModel;
+import fr.gouv.finances.dgfip.xemelios.importers.archives.rules.ImportModel;
+import fr.gouv.finances.dgfip.xemelios.importers.archives.rules.PredicatModel;
+import fr.gouv.finances.dgfip.xemelios.importers.archives.rules.RulesModel;
+import fr.gouv.finances.dgfip.xemelios.importers.archives.rules.SectionModel;
+import fr.gouv.finances.dgfip.xemelios.importers.archives.rules.DeleteModel;
+import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+import javax.swing.JComponent;
+import nu.xom.Builder;
+import nu.xom.Document;
+import org.apache.log4j.Logger;
+import org.netbeans.api.wizard.WizardDisplayer;
+import org.netbeans.spi.wizard.Wizard;
+import org.netbeans.spi.wizard.WizardBranchController;
+import org.netbeans.spi.wizard.WizardController;
+import org.netbeans.spi.wizard.WizardPanelProvider;
+
+/**
+ *
+ * @author cmarchand
+ */
+public class ArchiveWizardDisplayer {
+ private static final Logger logger = Logger.getLogger(ArchiveWizardDisplayer.class);
+ private File archiveFile;
+ private MainWindow parent;
+
+ public ArchiveWizardDisplayer(MainWindow parent, File archiveFile) {
+ super();
+ this.parent = parent;
+ this.archiveFile = archiveFile;
+ HashMap<Object,Object> wizardProperties = null;
+ try {
+ wizardProperties = loadInitialProperties();
+ WizardBranchController wbc = new MyWizardBranchController(new WizardPanelProvider("Choix de l'action", "initial", "Choix de l'action à effectuer") {
+ @Override
+ protected JComponent createPanel(WizardController wc, String string, Map map) {
+ return new PnlChooseAction();
+ }
+ });
+ Wizard wizard = wbc.createWizard();
+ Map response = (Map)WizardDisplayer.showWizard(wizard, null, null, wizardProperties);
+ if(response==null) {
+ logger.info("import abandonné");
+ } else {
+ logger.info("response is "+response.getClass().getName()+" -> "+response);
+ RulesModel rules = new RulesModel(RulesModel.QN);
+ rules.setId("IHM-generated");
+ if(Boolean.TRUE.equals(response.get("choose.action.full.import")) ||
+ Boolean.TRUE.equals(response.get("choose.action.missing.import"))) {
+ SectionModel sm = new SectionModel(SectionModel.QN);
+ if(Boolean.TRUE.equals(response.get("choose.action.full.import"))) {
+ sm.setName("Import complet");
+ sm.setOverwriteRule(EtatImporteur.OVERWRITE_RULE_ALWAYS);
+ } else {
+ sm.setName("Complément import");
+ sm.setOverwriteRule(EtatImporteur.OVERWRITE_RULE_NEVER);
+ }
+ PredicatModel pm = new PredicatModel(PredicatModel.QN);
+ sm.addChild(pm, pm.getQName());
+ pm.addCharacterData("true"); // on passera toujours dedans, comme ça...
+ ActionsModel am = new ActionsModel(ActionsModel.QN);
+ ImportModel im = new ImportModel(ImportModel.QN);
+ im.setMode(ImportModel.MODE_FULL);
+ am.addChild(im, im.getQName());
+ sm.addChild(am, am.getQName());
+ rules.addChild(sm, sm.getQName());
+ } else if(Boolean.TRUE.equals(response.get("choose.action.re.import"))) {
+ SectionModel sm = new SectionModel(SectionModel.QN);
+ sm.setName("Réimport à l'identique");
+ PredicatModel pm = new PredicatModel(PredicatModel.QN);
+ pm.addCharacterData("true"); // on passera toujours dedans, comme ça...
+ sm.addChild(pm, pm.getQName());
+ ActionsModel am = new ActionsModel(ActionsModel.QN);
+ // on dit juste qu'on réutilise la section du précédent import, et cela
+ // va supprimer les données existantes, puis réappliquer la précédente
+ // session. Tout est fait dans le ArchiveImporter
+ am.setUsePreviousSection(true);
+ sm.addChild(am, am.getQName());
+ rules.addChild(sm, sm.getQName());
+ } else {
+ SectionModel sm = new SectionModel(SectionModel.QN);
+ sm.setName("Import partiel");
+ PredicatModel pm = new PredicatModel(PredicatModel.QN);
+ pm.addCharacterData("true"); // on passera toujours dedans, comme ça...
+ sm.addChild(pm, pm.getQName());
+ ActionsModel am = new ActionsModel(ActionsModel.QN);
+ // traiter le cas de l'arbre
+ sm.addChild(am, am.getQName());
+ if(Boolean.TRUE.equals(response.get("tree.drop.data"))) {
+ DeleteModel dm = new DeleteModel(DeleteModel.QN);
+ dm.setArchive("archiveName");
+ am.addChild(dm, dm.getQName());
+ }
+ ImportModel im = new ImportModel(ImportModel.QN);
+ im.setMode(ImportModel.MODE_PARTIAL);
+ TreeSet<String> documentTypes = (TreeSet<String>)response.get("archive.document.types");
+ for(String docType:documentTypes) {
+ if(Boolean.TRUE.equals(response.get("partial."+docType))) {
+ FilterModel includeModel = new FilterModel(FilterModel.QN_INCLUDE);
+ includeModel.setTypeDoc(docType);
+ DocumentModel dm = parent.getDocModels().getDocumentById(docType);
+ if(dm!=null && dm.getArchiveVentilationAttrName()!=null) {
+ TreeSet<String> allAttrValues = (TreeSet<String>)response.get("partial."+docType+".allAttrValues");
+ ArrayList<String> selectedAttributes = (ArrayList<String>)response.get("partial."+docType+".attrs");
+ for(String attr:allAttrValues) {
+ AttributeModel atm = new AttributeModel(AttributeModel.QN);
+ atm.setName(dm.getArchiveVentilationAttrName());
+ atm.setValue(attr);
+ if(!selectedAttributes.contains(attr)) {
+ atm.setDiffers(true);
+ }
+ includeModel.addChild(atm, atm.getQName());
+ }
+ }
+ im.addChild(includeModel, includeModel.getQName());
+ } else {
+ FilterModel includeModel = new FilterModel(FilterModel.QN_EXCLUDE);
+ includeModel.setTypeDoc(docType);
+ im.addChild(includeModel, includeModel.getQName());
+ }
+ }
+ am.addChild(im, im.getQName());
+ rules.addChild(sm, sm.getQName());
+ }
+ for(SectionModel sm:rules.getSections()) {
+ logger.debug(sm.getXomDefinition().toXML());
+ }
+ ImportServiceSwingProvider isp = new ImportServiceSwingProvider(parent, null, 0);
+ isp.setDisplayFeedback(false);
+ ArchiveImporter ai = new ArchiveImporter(parent.getDocModels(), archiveFile, isp, parent.getEnvProperties(), rules);
+ ai.setUser(parent.getConnectedUser());
+ MainWindow.XemeliosArchiveImporterWorker worker = new MainWindow.XemeliosArchiveImporterWorker(ai);
+ worker.execute();
+ }
+ } catch(Exception ex) {
+ // a l'initialisation, on a rencontré une erreur
+ new DisplayExceptionDlg(parent,ex);
+ }
+ }
+
+ private HashMap<Object,Object> loadInitialProperties() throws Exception {
+ HashMap<Object, Object> properties = new HashMap<Object, Object>();
+ try {
+ ZipFile zf = new ZipFile(archiveFile);
+ ZipEntry ze = zf.getEntry(ArchiveImporter.MANIFESTE_FILE_NAME);
+ InputStream is = zf.getInputStream(ze);
+ Builder builder = new Builder();
+ Document doc = builder.build(is);
+ properties.put("archive.manifeste", doc);
+ Document importedManifesteArchive = DataLayerManager.getImplementation().getManifesteFromArchive(ArchiveImporter.getArchiveName(archiveFile), parent.getConnectedUser());
+ properties.put("imported.archive.manifeste", importedManifesteArchive);
+ } catch(ZipException zEx) {
+ throw new Exception(archiveFile.getName()+" n'est pas une archive ZIP valide",zEx);
+ } finally {
+ return properties;
+ }
+ }
+
+ public class MyWizardBranchController extends WizardBranchController {
+ private WizardPanelProvider _wpp;
+ public MyWizardBranchController(WizardPanelProvider wpp) {
+ super(wpp);
+ _wpp = new WizardPanelProvider("Choix de l'élément", "tree", "Choix de l'élément") {
+ @Override
+ protected JComponent createPanel(WizardController wc, String string, Map map) {
+ return new PnlTree(parent.getDocModels());
+ }
+ };
+ }
+ @Override
+ protected WizardPanelProvider getPanelProviderForStep(String step, Map settings) {
+ if(Boolean.TRUE.equals(settings.get("choose.action.partial.import")))
+ return _wpp;
+ else return null;
+ }
+
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
+ <NonVisualComponents>
+ <Component class="javax.swing.ButtonGroup" name="bGroup">
+ </Component>
+ </NonVisualComponents>
+ <AuxValues>
+ <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
+ <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
+ <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+ </AuxValues>
+
+ <Layout>
+ <DimensionLayout dim="0">
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Group type="102" attributes="0">
+ <EmptySpace max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Component id="lblQuestion" alignment="0" min="-2" max="-2" attributes="0"/>
+ <Component id="rbFullImport" alignment="0" min="-2" max="-2" attributes="0"/>
+ <Component id="rbPartialImport" alignment="0" min="-2" max="-2" attributes="0"/>
+ <Component id="rbCompleteImport" alignment="0" min="-2" max="-2" attributes="0"/>
+ <Component id="rbReImport" alignment="0" min="-2" max="-2" attributes="0"/>
+ </Group>
+ <EmptySpace pref="209" max="32767" attributes="0"/>
+ </Group>
+ </Group>
+ </DimensionLayout>
+ <DimensionLayout dim="1">
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Group type="102" alignment="0" attributes="0">
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="lblQuestion" min="-2" max="-2" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="rbFullImport" min="-2" max="-2" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="rbPartialImport" min="-2" max="-2" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="rbCompleteImport" min="-2" max="-2" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="rbReImport" min="-2" max="-2" attributes="0"/>
+ <EmptySpace pref="149" max="32767" attributes="0"/>
+ </Group>
+ </Group>
+ </DimensionLayout>
+ </Layout>
+ <SubComponents>
+ <Component class="javax.swing.JLabel" name="lblQuestion">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Que souhaitez-vous faire avec cette action ?"/>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JRadioButton" name="rbFullImport">
+ <Properties>
+ <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
+ <ComponentRef name="bGroup"/>
+ </Property>
+ <Property name="text" type="java.lang.String" value="Tout importer"/>
+ <Property name="name" type="java.lang.String" value="choose.action.full.import" noResource="true"/>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JRadioButton" name="rbPartialImport">
+ <Properties>
+ <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
+ <ComponentRef name="bGroup"/>
+ </Property>
+ <Property name="text" type="java.lang.String" value="Importer une partie de l'archive"/>
+ <Property name="name" type="java.lang.String" value="choose.action.partial.import" noResource="true"/>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JRadioButton" name="rbCompleteImport">
+ <Properties>
+ <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
+ <ComponentRef name="bGroup"/>
+ </Property>
+ <Property name="text" type="java.lang.String" value="Importer les données manquantes"/>
+ <Property name="name" type="java.lang.String" value="choose.action.missing.import" noResource="true"/>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JRadioButton" name="rbReImport">
+ <Properties>
+ <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
+ <ComponentRef name="bGroup"/>
+ </Property>
+ <Property name="text" type="java.lang.String" value="Réimporter à l'identique"/>
+ <Property name="name" type="java.lang.String" value="choose.action.re.import" noResource="true"/>
+ </Properties>
+ </Component>
+ </SubComponents>
+</Form>
--- /dev/null
+/*
+ * Copyright
+ * 2012 axYus - http://www.axyus.com
+ * 2012 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS_NB.
+ *
+ * XEMELIOS_NB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS_NB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with XEMELIOS_NB; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+package fr.gouv.finances.cp.xemelios.ui.importArchive;
+
+import fr.gouv.finances.dgfip.xemelios.importers.archives.ArchiveImporter;
+import java.awt.Component;
+import java.util.Map;
+import nu.xom.Document;
+import org.apache.log4j.Logger;
+import org.netbeans.spi.wizard.Wizard;
+import org.netbeans.spi.wizard.WizardController;
+import org.netbeans.spi.wizard.WizardPage;
+import org.netbeans.spi.wizard.WizardPanelNavResult;
+
+/**
+ *
+ * @author cmarchand
+ */
+public class PnlChooseAction extends WizardPage {
+ private static final Logger logger = Logger.getLogger(PnlChooseAction.class);
+
+ /** Creates new form PnlChooseAction */
+ public PnlChooseAction() {
+ super("Choix de l'action");
+ initComponents();
+ setLongDescription("Choix de l'action");
+ }
+
+ @Override
+ public WizardPanelNavResult allowNext(String stepName, Map settings, Wizard wizard) {
+ if(rbPartialImport.isSelected()) {
+ return WizardPanelNavResult.PROCEED;
+ } else return WizardPanelNavResult.REMAIN_ON_PAGE;
+ }
+
+ @Override
+ public WizardPanelNavResult allowFinish(String stepName, Map settings, Wizard wizard) {
+ if(rbCompleteImport.isSelected() || rbFullImport.isSelected() || rbPartialImport.isSelected() || rbReImport.isSelected()) {
+ return WizardPanelNavResult.PROCEED;
+ } else return WizardPanelNavResult.REMAIN_ON_PAGE;
+ }
+
+ @Override
+ public WizardPanelNavResult allowBack(String stepName, Map settings, Wizard wizard) {
+ return WizardPanelNavResult.REMAIN_ON_PAGE;
+ }
+
+ @Override
+ protected String validateContents(Component component, Object event) {
+ if(rbPartialImport.isSelected()) {
+ setForwardNavigationMode(WizardController.MODE_CAN_CONTINUE);
+ } else {
+ setForwardNavigationMode(WizardController.MODE_CAN_FINISH);
+ }
+ return null;
+ }
+
+
+
+ @Override
+ protected void renderingPage() {
+ Document archiveManifeste = (Document)getWizardData("archive.manifeste");
+ Document importedArchiveManifeste = (Document)getWizardData("imported.archive.manifeste");
+ boolean isArchiveAlreadyImported = importedArchiveManifeste!=null;
+ if(isArchiveAlreadyImported) {
+ String archiveVersion = archiveManifeste.getRootElement().getAttributeValue("version");
+ String importedArchiveVersion = importedArchiveManifeste.getRootElement().getAttributeValue("version");
+ if(importedArchiveManifeste.query("/m:manifeste/m:documents/m:document[@imported='"+ArchiveImporter.NON+"' or @imported='"+ArchiveImporter.NON_DISPONIBLE+"']", ArchiveImporter.getNamespaceCtx()).size()>0) {
+ if(archiveVersion.equals(importedArchiveVersion)) {
+ rbCompleteImport.setEnabled(true);
+ rbCompleteImport.setSelected(true);
+ } else
+ rbCompleteImport.setEnabled(false);
+ rbReImport.setEnabled(true);
+ } else {
+ rbCompleteImport.setEnabled(true);
+ rbReImport.setEnabled(true);
+ rbReImport.setSelected(true);
+ }
+ } else {
+ rbCompleteImport.setEnabled(false);
+ rbReImport.setEnabled(false);
+ rbFullImport.setSelected(true);
+ }
+ }
+
+ /** This method is called from within the constructor to
+ * initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is
+ * always regenerated by the Form Editor.
+ */
+ @SuppressWarnings("unchecked")
+ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ bGroup = new javax.swing.ButtonGroup();
+ lblQuestion = new javax.swing.JLabel();
+ rbFullImport = new javax.swing.JRadioButton();
+ rbPartialImport = new javax.swing.JRadioButton();
+ rbCompleteImport = new javax.swing.JRadioButton();
+ rbReImport = new javax.swing.JRadioButton();
+
+ lblQuestion.setText("Que souhaitez-vous faire avec cette action ?");
+
+ bGroup.add(rbFullImport);
+ rbFullImport.setText("Tout importer");
+ rbFullImport.setName("choose.action.full.import"); // NOI18N
+
+ bGroup.add(rbPartialImport);
+ rbPartialImport.setText("Importer une partie de l'archive");
+ rbPartialImport.setName("choose.action.partial.import"); // NOI18N
+
+ bGroup.add(rbCompleteImport);
+ rbCompleteImport.setText("Importer les données manquantes");
+ rbCompleteImport.setName("choose.action.missing.import"); // NOI18N
+
+ bGroup.add(rbReImport);
+ rbReImport.setText("Réimporter à l'identique");
+ rbReImport.setName("choose.action.re.import"); // NOI18N
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(lblQuestion)
+ .addComponent(rbFullImport)
+ .addComponent(rbPartialImport)
+ .addComponent(rbCompleteImport)
+ .addComponent(rbReImport))
+ .addContainerGap(209, Short.MAX_VALUE))
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addComponent(lblQuestion)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(rbFullImport)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(rbPartialImport)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(rbCompleteImport)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(rbReImport)
+ .addContainerGap(149, Short.MAX_VALUE))
+ );
+ }// </editor-fold>//GEN-END:initComponents
+
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.ButtonGroup bGroup;
+ private javax.swing.JLabel lblQuestion;
+ private javax.swing.JRadioButton rbCompleteImport;
+ private javax.swing.JRadioButton rbFullImport;
+ private javax.swing.JRadioButton rbPartialImport;
+ private javax.swing.JRadioButton rbReImport;
+ // End of variables declaration//GEN-END:variables
+
+ public static String getDescription() { return "Choix de l'action"; }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
+ <AuxValues>
+ <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
+ <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
+ <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+ </AuxValues>
+
+ <Layout>
+ <DimensionLayout dim="0">
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Group type="102" alignment="0" attributes="0">
+ <EmptySpace max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Component id="jScrollPane1" alignment="0" pref="376" max="32767" attributes="0"/>
+ <Component id="chkDropDataBefore" alignment="0" min="-2" max="-2" attributes="0"/>
+ </Group>
+ <EmptySpace max="-2" attributes="0"/>
+ </Group>
+ </Group>
+ </DimensionLayout>
+ <DimensionLayout dim="1">
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Group type="102" alignment="0" attributes="0">
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="chkDropDataBefore" min="-2" max="-2" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="jScrollPane1" min="-2" pref="275" max="-2" attributes="0"/>
+ <EmptySpace max="32767" attributes="0"/>
+ </Group>
+ </Group>
+ </DimensionLayout>
+ </Layout>
+ <SubComponents>
+ <Component class="javax.swing.JCheckBox" name="chkDropDataBefore">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Supprimer les données déjà importées"/>
+ <Property name="name" type="java.lang.String" value="tree.drop.data" noResource="true"/>
+ </Properties>
+ </Component>
+ <Container class="javax.swing.JScrollPane" name="jScrollPane1">
+ <AuxValues>
+ <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
+ </AuxValues>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
+ <SubComponents>
+ <Component class="org.jdesktop.swingx.JXTreeTable" name="tree">
+ </Component>
+ </SubComponents>
+ </Container>
+ </SubComponents>
+</Form>
--- /dev/null
+/*
+ * Copyright
+ * 2012 axYus - http://www.axyus.com
+ * 2012 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS_NB.
+ *
+ * XEMELIOS_NB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS_NB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with XEMELIOS_NB; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+package fr.gouv.finances.cp.xemelios.ui.importArchive;
+
+import fr.gouv.finances.dgfip.utils.Pair;
+import fr.gouv.finances.dgfip.xemelios.common.config.DocumentModel;
+import fr.gouv.finances.dgfip.xemelios.common.config.DocumentsModel;
+import fr.gouv.finances.dgfip.xemelios.importers.archives.ArchiveImporter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeSet;
+import javax.swing.event.TableModelEvent;
+import javax.swing.tree.TreePath;
+import nu.xom.Document;
+import nu.xom.Nodes;
+import org.apache.log4j.Logger;
+import org.jdesktop.swingx.treetable.AbstractMutableTreeTableNode;
+import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
+import org.jdesktop.swingx.treetable.MutableTreeTableNode;
+import org.jdesktop.swingx.treetable.TreeTableNode;
+import org.netbeans.spi.wizard.Wizard;
+import org.netbeans.spi.wizard.WizardPage;
+import org.netbeans.spi.wizard.WizardPanelNavResult;
+
+/**
+ *
+ * @author cmarchand
+ */
+public class PnlTree extends WizardPage {
+ private static final int LEVEL_ROOT = 0;
+ private static final int LEVEL_TYPE_DOC = 1;
+ private static final int LEVEL_ATTR = 2;
+
+ private static final Logger logger = Logger.getLogger(PnlTree.class);
+
+ private DocumentsModel documentsModel;
+
+ /** Creates new form PnlTree */
+ public PnlTree(DocumentsModel documentsModels) {
+ super();
+ this.documentsModel = documentsModels;
+ initComponents();
+ tree.setRootVisible(true);
+ }
+
+ @Override
+ public WizardPanelNavResult allowFinish(String stepName, Map settings, Wizard wizard) {
+ prepareExit();
+ return WizardPanelNavResult.PROCEED;
+ }
+
+ @Override
+ public WizardPanelNavResult allowBack(String stepName, Map settings, Wizard wizard) {
+ return WizardPanelNavResult.PROCEED;
+ }
+
+ @Override
+ protected void renderingPage() {
+ Document doc = (Document)getWizardData("archive.manifeste");
+ MyTreeTableNode root = new MyTreeTableNode(null, LEVEL_ROOT);
+ Nodes typeDocs = doc.query("/manifeste/documents/document/@type");
+ TreeSet<String> ts = new TreeSet<String>();
+ for(int i=0;i<typeDocs.size();i++) {
+ ts.add(ArchiveImporter.normalizeDocumentType(typeDocs.get(i).getValue()));
+ }
+ // on a la liste des types de documents
+ putWizardData("archive.document.types", ts);
+ for(String typeDoc:ts) {
+ DocumentModel dm = documentsModel.getDocumentById(typeDoc);
+ if(dm==null) {
+ // c'est un type de document qu'on ne connait pas, il faut un traitement d'exception
+ Pair p = new Pair(typeDoc,typeDoc);
+ MyTreeTableNode ttn = new MyTreeTableNode(p, LEVEL_TYPE_DOC);
+ if(!"PJ".equals(typeDoc)) {
+ // c'est un type de document non disponible
+ ttn.selectionable = false;
+ }
+ root.add(ttn);
+ } else {
+ Pair p = new Pair(typeDoc, dm.getTitre());
+ MyTreeTableNode ttn = new MyTreeTableNode(p, LEVEL_TYPE_DOC);
+ // on va chercher maintenant chercher les valeurs des attributs fils
+ if(dm.getArchiveVentilationAttrName()!=null) {
+ Nodes valuesNodes = doc.query("/manifeste/documents/document[@type='"+p.key+"']/@"+dm.getArchiveVentilationAttrName());
+ TreeSet<String> values = new TreeSet<String>();
+ for(int j=0;j<valuesNodes.size();j++) {
+ values.add(valuesNodes.get(j).getValue());
+ }
+ putWizardData("partial."+typeDoc+".allAttrValues", values);
+ for(String value:values) {
+ MyTreeTableNode child = new MyTreeTableNode(value, LEVEL_ATTR);
+ ttn.add(child);
+ }
+ }
+ root.add(ttn);
+ }
+ }
+ List<String> columnNames = new ArrayList<String>();
+ columnNames.add("Element");
+ columnNames.add("Importer");
+ MyTreeTableModel treeModel = new MyTreeTableModel(root, columnNames);
+ tree.setTreeTableModel(treeModel);
+ tree.expandAll();
+ tree.sizeColumnsToFit(0);
+ }
+
+ protected void prepareExit() {
+ DefaultTreeTableModel dttm = (DefaultTreeTableModel)tree.getTreeTableModel();
+ MyTreeTableNode mttn = (MyTreeTableNode)dttm.getRoot();
+ if(mttn==null) return;
+ for(int docCount = 0 ; docCount < mttn.getChildCount(); docCount++) {
+ MyTreeTableNode doc = (MyTreeTableNode)mttn.getChildAt(docCount);
+ if(doc.selected) {
+ logger.debug("setting partial."+doc.code+"="+Boolean.TRUE);
+ putWizardData("partial."+doc.code, Boolean.TRUE);
+ boolean full = true;
+ ArrayList<String> attrs = new ArrayList<String>();
+ for(int attrCount=0 ; attrCount < doc.getChildCount(); attrCount++) {
+ MyTreeTableNode attr = (MyTreeTableNode)doc.getChildAt(attrCount);
+ if(attr.selected) {
+ full = false;
+ attrs.add(attr.code);
+ }
+ }
+
+ putWizardData("partial."+doc.code+".full", Boolean.valueOf(full));
+ if(!full) {
+ if(attrs.size()>0)
+ putWizardData("partial."+doc.code+".attrs", attrs);
+ else
+ putWizardData("partial."+doc.code+".attrs", null);
+ }
+ } else {
+ logger.debug("setting partial."+doc.code+"="+Boolean.FALSE);
+ putWizardData("partial."+doc.code, Boolean.FALSE);
+ }
+ }
+ }
+
+
+
+ /** This method is called from within the constructor to
+ * initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is
+ * always regenerated by the Form Editor.
+ */
+ @SuppressWarnings("unchecked")
+ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ chkDropDataBefore = new javax.swing.JCheckBox();
+ jScrollPane1 = new javax.swing.JScrollPane();
+ tree = new org.jdesktop.swingx.JXTreeTable();
+
+ chkDropDataBefore.setText("Supprimer les données déjà importées");
+ chkDropDataBefore.setName("tree.drop.data"); // NOI18N
+
+ jScrollPane1.setViewportView(tree);
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
+ .addComponent(chkDropDataBefore))
+ .addContainerGap())
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addComponent(chkDropDataBefore)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ );
+ }// </editor-fold>//GEN-END:initComponents
+
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JCheckBox chkDropDataBefore;
+ private javax.swing.JScrollPane jScrollPane1;
+ private org.jdesktop.swingx.JXTreeTable tree;
+ // End of variables declaration//GEN-END:variables
+
+ class MyTreeTableModel extends DefaultTreeTableModel {
+ public MyTreeTableModel(TreeTableNode rootNode, List<String> columnNames) {
+ super(rootNode, columnNames);
+ }
+
+ @Override
+ public Class<?> getColumnClass(int column) {
+ if(column==1) return Boolean.class;
+ else return super.getColumnClass(column);
+ }
+
+ }
+
+ class MyTreeTableNode extends AbstractMutableTreeTableNode {
+ private String code;
+ private String libelle;
+ private boolean selected;
+ private int level;
+ private boolean selectionable = true;
+ public MyTreeTableNode(Object o, int level) {
+ super();
+ this.level = level;
+ switch(level) {
+ case LEVEL_ROOT: {
+ libelle = code = "Archive";
+ break;
+ }
+ case LEVEL_TYPE_DOC: {
+ Pair p = (Pair)o;
+ code = p.key;
+ libelle = p.libelle;
+ break;
+ }
+ default: libelle = code = o.toString();
+ }
+ }
+ @Override
+ public Object getValueAt(int i) {
+ if(i==0)
+ return libelle;
+ else
+ return selected;
+ }
+ @Override
+ public int getColumnCount() {
+ return 2;
+ }
+ @Override
+ public void setValueAt(Object aValue, int column) {
+ if(!selectionable) return;
+ selected = (Boolean)aValue;
+ // on propage sur les enfants
+ for(Enumeration<? extends MutableTreeTableNode> enfants=children(); enfants.hasMoreElements();) {
+ MutableTreeTableNode mttn = enfants.nextElement();
+ mttn.setValueAt(aValue, level);
+// tree.getTreeTableModel().valueForPathChanged(((MyTreeTableNode)mttn).getTreePath(), aValue);
+ }
+ tree.tableChanged(new TableModelEvent(tree.getModel()));
+ }
+ @Override
+ public boolean isEditable(int column) {
+ return column==1 && selectionable;
+ }
+ public TreePath getTreePath() {
+ Object[] parentPath = null;
+ if(getParent()!=null)
+ getParentNode().getTreePath().getPath();
+ else
+ parentPath = new Object[0];
+ Object[] path = Arrays.copyOf(parentPath, parentPath.length+1);
+ path[parentPath.length] = this;
+ return new TreePath(path);
+ }
+ private MyTreeTableNode getParentNode() {
+ return(MyTreeTableNode)getParent();
+ }
+ }
+
+}
package fr.gouv.finances.cp.xemelios.ui.tools;
import fr.gouv.finances.cp.utils.PropertiesExpansion;
-import fr.gouv.finances.cp.xemelios.importers.ImportServiceSwingProvider;
import fr.gouv.finances.cp.xemelios.ui.MainWindow;
+import fr.gouv.finances.cp.xemelios.ui.importArchive.ArchiveWizardDisplayer;
import fr.gouv.finances.dgfip.xemelios.auth.XemeliosUser;
import fr.gouv.finances.dgfip.xemelios.common.Constants;
import fr.gouv.finances.dgfip.xemelios.common.config.DocumentModel;
import fr.gouv.finances.dgfip.xemelios.data.DataLayerManager;
import fr.gouv.finances.dgfip.xemelios.importers.EtatImporteur;
-import fr.gouv.finances.dgfip.xemelios.importers.XemeliosArchiveImporter;
import fr.gouv.finances.dgfip.xemelios.tools.ServiceException;
import fr.gouv.finances.dgfip.xemelios.tools.ToolServiceProviderFactory;
import fr.gouv.finances.dgfip.xemelios.tools.XemeliosToolServiceProvider;
}
private void importXemeliosArchive(File archive) throws Exception {
- ImportServiceSwingProvider isp = new ImportServiceSwingProvider(MainWindow.getInstance(), null, 0);
- isp.setDisplayFeedback(false);
- XemeliosArchiveImporter xai = new XemeliosArchiveImporter(MainWindow.getInstance().getDocModels(), archive, isp, MainWindow.getInstance().getEnvProperties());
- xai.setUser(MainWindow.getInstance().getConnectedUser());
- MainWindow.XemeliosArchiveImporterWorker worker = new MainWindow.XemeliosArchiveImporterWorker(xai);
- worker.execute();
+// ImportServiceSwingProvider isp = new ImportServiceSwingProvider(MainWindow.getInstance(), null, 0);
+// isp.setDisplayFeedback(false);
+// XemeliosArchiveImporter xai = new XemeliosArchiveImporter(MainWindow.getInstance().getDocModels(), archive, isp, MainWindow.getInstance().getEnvProperties());
+// xai.setUser(MainWindow.getInstance().getConnectedUser());
+// MainWindow.XemeliosArchiveImporterWorker worker = new MainWindow.XemeliosArchiveImporterWorker(xai);
+// worker.execute();
+ ArchiveWizardDisplayer awd = new ArchiveWizardDisplayer(MainWindow.getInstance(), archive);
}
@Override
import javax.xml.namespace.QName;
public class DeleteModel implements XmlMarshallable {
- public static final transient String TAG="delete";
- public static final transient QName QN = new QName(TAG);
-
-
- private String name;
- public DeleteModel(QName tagName) {
- super();
- }
+ public static final transient String TAG = "delete";
+ public static final transient QName QN = new QName(TAG);
+ private String name;
- public void addCharacterData(String cData) throws SAXException { }
+ public DeleteModel(QName tagName) {
+ super();
+ }
- public void addChild(XmlMarshallable child, QName tagName) throws SAXException {
- }
+ @Override
+ public void addCharacterData(String cData) throws SAXException {
+ }
- public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
- name=attributes.getValue("name");
- return this;
- }
+ @Override
+ public void addChild(XmlMarshallable child, QName tagName) throws SAXException {
+ }
- public void marshall(XmlOutputter output) {
- output.startTag(TAG);
- output.addAttribute("name",name);
- output.endTag(TAG);
- }
+ @Override
+ public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
+ name = attributes.getValue("name");
+ return this;
+ }
- public void validate() throws InvalidXmlDefinition { }
+ @Override
+ public void marshall(XmlOutputter output) {
+ output.startTag(TAG);
+ output.addAttribute("name", name);
+ output.endTag(TAG);
+ }
- public DeleteModel clone() {
- DeleteModel dm = new DeleteModel(QN);
- dm.name=this.name;
- return dm;
- }
+ @Override
+ public void validate() throws InvalidXmlDefinition {
+ }
- public String getName() {
- return name;
- }
+ @Override
+ public DeleteModel clone() {
+ DeleteModel dm = new DeleteModel(QN);
+ dm.name = this.name;
+ return dm;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ public String getName() {
+ return name;
+ }
- @Override
- public String toString() {
- return "- "+getName();
- }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return "- " + getName();
+ }
+ @Override
public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
return null;
}
+ @Override
public QName getQName() {
return QN;
}
-
}