OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 148 → Rev 149

/trunk/OpenConcerto/src/org/openconcerto/erp/config/InstallationPanel.java
95,7 → 95,7
public class InstallationPanel extends JPanel {
private static final boolean DEBUG_FK = false;
 
static public void insertUndef(final SQLCreateTable ct) throws SQLException {
public static void insertUndef(final SQLCreateTable ct) throws SQLException {
// check that we can use insertReturnFirstField()
if (ct.getPrimaryKey().size() != 1)
throw new IllegalStateException("Not one and only one field in the PK : " + ct.getPrimaryKey());
106,7 → 106,7
SQLTable.setUndefID(ct.getRoot().getSchema(), ct.getName(), ((Number) insertion.getRows().get(0)).intValue());
}
 
static private SQLName getTableName(final SQLCreateTable ct) {
private static SQLName getTableName(final SQLCreateTable ct) {
return new SQLName(ct.getRoot().getName(), ct.getName());
}
 
126,7 → 126,9
 
@Override
public void actionPerformed(ActionEvent e) {
if (finderPanel != null) {
finderPanel.saveConfigFile();
}
bar.setIndeterminate(true);
up.setEnabled(false);
new Thread(new Runnable() {
136,360 → 138,8
System.setProperty(SQLSchema.NOAUTO_CREATE_METADATA, "false");
final ComptaPropsConfiguration conf = ComptaPropsConfiguration.create(true);
 
try {
final SQLDataSource ds = conf.getSystemRoot().getDataSource();
System.err.println("SystemRoot:" + conf.getSystemRoot());
System.err.println("Root:" + conf.getRoot());
updateDatabase(conf);
 
// FixUnbounded varchar
fixUnboundedVarchar(conf.getRoot());
 
// FIXME DROP CONSTRAINT UNIQUE ORDRE ON
// CONTACT_FOURNISSEUR
 
checkCompteDefault(conf.getRoot());
 
updateSocieteTable(conf.getRoot());
updateVille(conf.getRoot().getTable("ADRESSE"));
 
// Champ user 1.4.1
final SQLTable tableUser = conf.getRoot().getTable("USER_COMMON");
if (tableUser != null) {
final AlterTable alter = new AlterTable(tableUser);
boolean alterUser = false;
if (!tableUser.contains("DISABLED")) {
alter.addBooleanColumn("DISABLED", Boolean.FALSE, false);
alterUser = true;
}
if (!tableUser.contains("TEL")) {
alter.addVarCharColumn("TEL", 128);
alterUser = true;
}
 
if (alterUser) {
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableUser.getName());
conf.getRoot().getSchema().updateVersion();
}
}
 
// Champ Paye
final SQLTable tableCaisse = conf.getRoot().getTable("CAISSE_COTISATION");
if (!tableCaisse.contains("NUMERO_COMPTE_PCE")) {
final AlterTable alter = new AlterTable(tableCaisse);
alter.addVarCharColumn("NUMERO_COMPTE_PCE", 128);
alter.addVarCharColumn("NUMERO_COMPTE_PCE_CHARGES", 128);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableCaisse.getName());
conf.getRoot().getSchema().updateVersion();
}
 
final SQLTable tableRC = conf.getRoot().getTable("RUBRIQUE_COTISATION");
if (!tableRC.contains("PART_CSG_SANS_ABATTEMENT")) {
final AlterTable alter = new AlterTable(tableRC);
alter.addBooleanColumn("PART_CSG_SANS_ABATTEMENT", Boolean.FALSE, false);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableRC.getName());
conf.getRoot().getSchema().updateVersion();
}
 
// Paye simplifiee
{
final SQLTable tableRB = conf.getRoot().getTable("RUBRIQUE_BRUT");
if (!tableRB.contains("AVANTAGE_NATURE")) {
final AlterTable alter = new AlterTable(tableRB);
alter.addBooleanColumn("AVANTAGE_NATURE", Boolean.FALSE, false);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableRB.getName());
conf.getRoot().getSchema().updateVersion();
}
 
if (!tableRC.contains("LIGNE_PAYE_SIMPLIFIEE")) {
final AlterTable alter = new AlterTable(tableRC);
 
alter.addBooleanColumn("ALLEGEMENT_COTISATION", Boolean.FALSE, false);
alter.addVarCharColumn("LIGNE_PAYE_SIMPLIFIEE", 256);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableRC.getName());
conf.getRoot().getSchema().updateVersion();
Map<String, String> liaison = new HashMap<String, String>();
liaison.put("COTCSA", LignePayeSimplifiee.SANTE_SECURITE.getId());
liaison.put("COTMALADIE", LignePayeSimplifiee.SANTE_SECURITE.getId());
liaison.put("COTAF", LignePayeSimplifiee.FAMILLE_ALLOCATIONS.getId());
liaison.put("COTVEUV", LignePayeSimplifiee.SANTE_SECURITE.getId());
 
liaison.put("COTVIEIL", LignePayeSimplifiee.RETRAITE_SECURITE_NON_PLAF.getId());
liaison.put("COTVIEILPLAF", LignePayeSimplifiee.RETRAITE_SECURITE_PLAF.getId());
liaison.put("COTFNALPLAF", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
liaison.put("COTFNAL", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
liaison.put("COTAT", LignePayeSimplifiee.ACCIDENTS_TRAVAIL.getId());
 
liaison.put("COTVTRAN", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
liaison.put("COTCH", LignePayeSimplifiee.ASSURANCE_CHOMAGE_CHOMAGE.getId());
liaison.put("COTCHAGS", LignePayeSimplifiee.ASSURANCE_CHOMAGE_CHOMAGE.getId());
liaison.put("COTAGFF", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_T1.getId());
liaison.put("COTRNonCadre", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_T1.getId());
 
liaison.put("COTCSGIMP", LignePayeSimplifiee.CSG_IMP.getId());
liaison.put("COTCSGDED", LignePayeSimplifiee.CSG_NON_IMP.getId());
liaison.put("COTFILLON", LignePayeSimplifiee.ALLEGEMENT_COTISATIONS.getId());
liaison.put("COTFNGS", LignePayeSimplifiee.ASSURANCE_CHOMAGE_CHOMAGE.getId());
liaison.put("COTCADRET1", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_TA.getId());
liaison.put("COTCADRET2", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_TB.getId());
 
liaison.put("COT_CADRE_RET_C_A", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_TA.getId());
liaison.put("COT_CADRE_RET_C_B", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_TB.getId());
liaison.put("COT_CADRE_RET_C_C", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_TC.getId());
liaison.put("COTAPEC", LignePayeSimplifiee.ASSURANCE_CHOMAGE_APEC.getId());
liaison.put("COTAPECFORF", LignePayeSimplifiee.ASSURANCE_CHOMAGE_APEC.getId());
liaison.put("COTCET", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_TA.getId());
 
liaison.put("COTPREVCADRETA", LignePayeSimplifiee.SANTE_COMPLEMENAIRE_DECES.getId());
liaison.put("COTGMP", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_GMP.getId());
liaison.put("COTCRDSIMP", LignePayeSimplifiee.CSG_IMP.getId());
liaison.put("COTGMP2", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_GMP.getId());
liaison.put("TAXEAPPR", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
liaison.put("CDA", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
 
liaison.put("FOR", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
liaison.put("COTAPECTA", LignePayeSimplifiee.ASSURANCE_CHOMAGE_APEC.getId());
liaison.put("COTFILLON2011", LignePayeSimplifiee.ALLEGEMENT_COTISATIONS.getId());
liaison.put("COTSYNDIC", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
liaison.put("COTPREV", LignePayeSimplifiee.RETRAITE_SUPPLEMENTAIRE.getId());
liaison.put("COT_MUTUELLE", LignePayeSimplifiee.SANTE_COMPLEMENAIRE_SANTE.getId());
liaison.put("COT_PENIBLE", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
 
SQLSelect sel = new SQLSelect();
sel.addSelect(conf.getRoot().findTable("RUBRIQUE_COTISATION").getField("CODE"));
sel.addSelect(conf.getRoot().findTable("RUBRIQUE_COTISATION").getField("NOM"));
sel.addSelect(conf.getRoot().findTable("RUBRIQUE_COTISATION").getKey());
List<SQLRow> rubCotis = SQLRowListRSH.execute(sel);
 
for (SQLRow sqlRow : rubCotis) {
final String code = sqlRow.getString("CODE");
if (liaison.containsKey(code)) {
sqlRow.createEmptyUpdateRow().put("LIGNE_PAYE_SIMPLIFIEE", liaison.get(code)).commit();
}
if (sqlRow.getString("NOM").toUpperCase().contains("FILLON")) {
sqlRow.createEmptyUpdateRow().put("ALLEGEMENT_COTISATION", Boolean.TRUE).commit();
}
}
}
}
 
final SQLTable tableRnet = conf.getRoot().getTable("RUBRIQUE_NET");
if (!tableRnet.contains("NUMERO_COMPTE_PCE_CHARGES")) {
final AlterTable alter = new AlterTable(tableRnet);
alter.addVarCharColumn("NUMERO_COMPTE_PCE_CHARGES", 128);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableCaisse.getName());
conf.getRoot().getSchema().updateVersion();
}
 
if (!tableRC.contains("PART_PAT_IMPOSABLE")) {
final AlterTable alter = new AlterTable(tableRC);
alter.addBooleanColumn("PART_PAT_IMPOSABLE", Boolean.FALSE, false);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableRC.getName());
conf.getRoot().getSchema().updateVersion();
}
 
if (!tableRC.contains("REDUCTION_FILLON")) {
final AlterTable alter = new AlterTable(tableRC);
alter.addBooleanColumn("REDUCTION_FILLON", Boolean.FALSE, false);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableRC.getName());
conf.getRoot().getSchema().updateVersion();
}
 
// Vérification des droits existants
checkRights(conf.getRoot());
 
if (!conf.getRoot().contains("DEVISE")) {
System.out.println("InstallationPanel.InstallationPanel() ADD DEVISE");
try {
SQLUtils.executeAtomic(ds, new SQLUtils.SQLFactory<Object>() {
@Override
public Object create() throws SQLException {
final SQLCreateTable createDevise = new SQLCreateTable(conf.getRoot(), "DEVISE");
createDevise.addVarCharColumn("CODE", 128);
createDevise.addVarCharColumn("NOM", 128);
createDevise.addVarCharColumn("LIBELLE", 128);
createDevise.addVarCharColumn("LIBELLE_CENT", 128);
createDevise.addDecimalColumn("TAUX", 16, 8, BigDecimal.ONE, false);
createDevise.addDecimalColumn("TAUX_COMMERCIAL", 16, 8, BigDecimal.ONE, false);
ds.execute(createDevise.asString());
insertUndef(createDevise);
conf.getRoot().getSchema().updateVersion();
return null;
}
});
} catch (Exception ex) {
throw new IllegalStateException("Erreur lors de la création de la table DEVISE", ex);
}
} else if (!conf.getRoot().getTable("DEVISE").contains("TAUX_COMMERCIAL")) {
final SQLTable tDevise = conf.getRoot().getTable("DEVISE");
final AlterTable alterDevise = new AlterTable(tDevise);
alterDevise.addDecimalColumn("TAUX_COMMERCIAL", 16, 8, BigDecimal.ONE, false);
ds.execute(alterDevise.asString());
tDevise.getSchema().updateVersion();
}
 
if (!conf.getRoot().contains("TYPE_MODELE")) {
System.out.println("InstallationPanel.InstallationPanel() ADD TYPE_MODELE");
try {
SQLUtils.executeAtomic(ds, new SQLUtils.SQLFactory<Object>() {
@Override
public Object create() throws SQLException {
final SQLCreateTable createTypeModele = new SQLCreateTable(conf.getRoot(), "TYPE_MODELE");
createTypeModele.addVarCharColumn("NOM", 128);
createTypeModele.addVarCharColumn("TABLE", 128);
createTypeModele.addVarCharColumn("DEFAULT_MODELE", 128);
ds.execute(createTypeModele.asString());
 
insertUndef(createTypeModele);
 
conf.getRoot().getSchema().updateVersion();
 
conf.getRoot().refetch();
 
return null;
}
});
final String[] type = new String[] { "Avoir client", "AVOIR_CLIENT", "Avoir", "Bon de livraison", "BON_DE_LIVRAISON", "BonLivraison", "Commande Client",
"COMMANDE_CLIENT", "CommandeClient", "Devis", "DEVIS", "Devis", "Facture", "SAISIE_VENTE_FACTURE", "VenteFacture" };
// ('FR', 'Français', 1.000), ('EN',
// 'Anglais', 2.000)
final List<String> values = new ArrayList<String>();
final SQLBase base = conf.getRoot().getBase();
 
for (int i = 0; i < type.length; i += 3) {
final int order = values.size() + 1;
values.add("(" + base.quoteString(type[i]) + ", " + base.quoteString(type[i + 1]) + ", " + base.quoteString(type[i + 2]) + ", " + order + ")");
}
final String valuesStr = CollectionUtils.join(values, ", ");
final String insertVals = "INSERT INTO " + conf.getRoot().getTable("TYPE_MODELE").getSQLName().quote() + "(" + SQLBase.quoteIdentifier("NOM") + ", "
+ SQLBase.quoteIdentifier("TABLE") + ", " + SQLBase.quoteIdentifier("DEFAULT_MODELE") + ", " + SQLBase.quoteIdentifier(SQLSyntax.ORDER_NAME) + ") VALUES"
+ valuesStr;
 
ds.execute(insertVals);
} catch (Exception ex) {
throw new IllegalStateException("Erreur lors de la création de la table TYPE_MODELE", ex);
}
}
 
SQLTable.setUndefID(conf.getRoot().getSchema(), "DEVISE", 1);
SQLTable.setUndefID(conf.getRoot().getSchema(), "TYPE_MODELE", 1);
 
// DSN
final DSNInstallationUtils dsnUtils = new DSNInstallationUtils();
dsnUtils.updateDSNCommonTable(conf.getRoot());
 
// ECo contribution
final EcoContributionInstallationUtils ecoUtils = new EcoContributionInstallationUtils();
ecoUtils.updateEcoCommonTable(conf.getRoot());
 
// we need to upgrade all roots
// ///////////////////////////
conf.getSystemRoot().mapAllRoots();
conf.getSystemRoot().refetch();
 
final Set<String> childrenNames = conf.getSystemRoot().getChildrenNames();
 
SwingUtilities.invokeLater(new Runnable() {
 
@Override
public void run() {
bar.setIndeterminate(false);
bar.setMaximum(childrenNames.size() + 1);
}
});
int i = 1;
for (final String childName : childrenNames) {
System.out.println("InstallationPanel.InstallationPanel() UPDATE SCHEMA " + childName);
final int barValue = i;
 
SwingUtilities.invokeLater(new Runnable() {
 
@Override
public void run() {
bar.setValue(barValue);
}
});
i++;
final DBRoot root = conf.getSystemRoot().getRoot(childName);
try {
conf.getSystemRoot().getDataSource().execute("CREATE LANGUAGE plpgsql;");
} catch (Exception e) {
System.err.println("Warning: cannot add language plpgsql" + e.getMessage());
}
final SQLTable tableUndef = root.getTable(SQLTable.undefTable);
if (tableUndef != null && tableUndef.getField("UNDEFINED_ID").isNullable() == Boolean.FALSE) {
final AlterTable alterUndef = new AlterTable(tableUndef);
alterUndef.alterColumn("TABLENAME", EnumSet.allOf(Properties.class), "varchar(250)", "''", false);
alterUndef.alterColumn("UNDEFINED_ID", EnumSet.allOf(Properties.class), "int", null, true);
try {
ds.execute(alterUndef.asString());
tableUndef.getSchema().updateVersion();
} catch (SQLException ex) {
throw new IllegalStateException("Erreur lors de la modification de UNDEFINED_ID", ex);
}
}
 
if (DEBUG_FK) {
findBadForeignKey(root);
}
 
if (childName.equalsIgnoreCase("Common")) {
updateCommon(root);
} else if (childName.startsWith(conf.getAppName()) || childName.equalsIgnoreCase("Default")
) {
SQLUtils.executeAtomic(ds, new SQLUtils.SQLFactory<Object>() {
@Override
public Object create() throws SQLException {
fixUnboundedVarchar(root);
fixUnboundedNumeric(root);
fixCompletion(root);
try {
updateSocieteSchema(root);
} catch (Exception e) {
throw new SQLException(e);
}
updateToV1Dot2(root);
updateToV1Dot3(root);
updateToV1Dot4(root);
// DSN
dsnUtils.updateDSN(root);
// Eco contribution
ecoUtils.updateEco(root);
updateStyle(root);
createBanque(root);
createAssocAnalytique(root, conf);
updateStock(root);
updateVille(root.getTable("ADRESSE"));
 
Updater_1_5.update(root);
return null;
}
 
});
}
 
}
error = false;
} catch (Throwable e1) {
ExceptionHandler.handle("Echec de mise à jour", e1);
error = true;
}
 
conf.destroy();
SwingUtilities.invokeLater(new Runnable() {
 
509,7 → 159,7
}
 
});
if (finderPanel.getToken() == null) {
if (finderPanel != null && finderPanel.getToken() == null) {
c.weightx = 1;
c.gridwidth = GridBagConstraints.REMAINDER;
this.add(new JLabelBold("Création de l'utilisateur openconcerto dans la base"), c);
563,124 → 213,6
}
});
 
// Injection SQL
// c.gridy++;
// c.weightx = 1;
// c.gridwidth = GridBagConstraints.REMAINDER;
// c.insets = new Insets(10, 3, 2, 2);
// this.add(new TitledSeparator("Injecter la base", true), c);
//
// c.gridy++;
// c.weightx = 0;
// c.gridwidth = 1;
// c.insets = DefaultGridBagConstraints.getDefaultInsets();
// this.add(new JLabel("Fichier"), c);
//
// final JTextField chemin = new JTextField();
// c.gridx++;
// c.weightx = 1;
// this.add(chemin, c);
//
// c.gridx++;
// c.weightx = 0;
// JButton browse = new JButton("...");
// browse.addActionListener(new ActionListener() {
//
// @Override
// public void actionPerformed(ActionEvent e) {
// JFileChooser choose = new JFileChooser();
// if (choose.showOpenDialog(InstallationPanel.this) ==
// JFileChooser.APPROVE_OPTION) {
// chemin.setText(choose.getSelectedFile().getAbsolutePath());
// }
// }
// });
// this.add(browse, c);
//
// c.gridy++;
// c.gridx = 0;
// JButton inject = new JButton("Injecter");
// this.add(inject, c);
// inject.addActionListener(new ActionListener() {
//
// @Override
// public void actionPerformed(ActionEvent e) {
// File f = new File(chemin.getText());
// if (!f.exists()) {
// JOptionPane.showMessageDialog(InstallationPanel.this,
// "Impossible de trouver le fichier "
// + chemin.getText());
// return;
// }
// BufferedReader input = null;
// try {
//
// input = new BufferedReader(new FileReader(f));
// StringBuffer sql = new StringBuffer();
// String s;
// while ((s = input.readLine()) != null) {
// sql.append(s + "\n");
// }
// input.close();
//
// try {
// final SQLServer sqlServer =
// finderPanel.getServerConfig().createSQLServer();
// Number n = (Number)
// sqlServer.getBase("postgres").getDataSource().executeScalar("select COUNT(*) from
// pg_database WHERE datname='OpenConcerto'");
// if (n.intValue() > 0) {
// JOptionPane.showMessageDialog(InstallationPanel.this,
// "La base OpenConcerto est déjà présente sur le serveur!");
// return;
// }
// // System.err.println(sqlServer.getBase("OpenConcerto"));
// sqlServer.getBase("postgres").getDataSource()
// .execute("CREATE DATABASE \"OpenConcerto\" WITH TEMPLATE = template0 ENCODING =
// 'UTF8' LC_COLLATE = 'fr_FR.UTF-8' LC_CTYPE = 'fr_FR.UTF-8';");
//
// sqlServer.getBase("postgres").getDataSource().execute("ALTER DATABASE
// \"OpenConcerto\" OWNER TO openconcerto;");
//
// SQLUtils.executeScript(sql.toString(),
// sqlServer.getSystemRoot("OpenConcerto"));
// sqlServer.destroy();
// JOptionPane.showMessageDialog(InstallationPanel.this,
// "Création de la base OpenConerto terminée.");
// System.err.println("Création de la base OpenConerto terminée.");
//
// } catch (SQLException e1) {
// // TODO Auto-generated catch block
//
// e1.printStackTrace();
// JOptionPane.showMessageDialog(InstallationPanel.this,
// "Une erreur s'est produite pendant l'injection du script, vérifier la connexion au
// serveur et le script.");
// }
//
// } catch (FileNotFoundException ex) {
// // TODO Auto-generated catch block
// ex.printStackTrace();
// } catch (IOException ex) {
// // TODO Auto-generated catch block
// ex.printStackTrace();
// } finally {
// if (input != null) {
// try {
// input.close();
// } catch (IOException ex) {
// // TODO Auto-generated catch block
// ex.printStackTrace();
// }
// }
// }
//
// }
// });
 
// c.gridy++;
// this.add(bd, c);
 
c.gridy++;
c.weightx = 1;
c.gridwidth = GridBagConstraints.REMAINDER;
1371,7 → 903,7
size = 2048;
else
// e.g. IDCC.NOM > 350
size = 512;
size = 1024;
alter.alterColumn(fName, EnumSet.allOf(Properties.class), "varchar(" + size + ")", "''", false);
}
}
1386,8 → 918,12
}
 
for (final String sql : ChangeTable.cat(alters, root.getName())) {
ds.execute(sql);
try {
// ds.execute(sql);
} catch (Exception e) {
e.printStackTrace();
}
}
root.refetch();
}
 
3838,7 → 3374,6
CorrectOrder orderCorrect = new CorrectOrder(sysRoot);
orderCorrect.change(tableCommercial);
 
// new AddFK(sysRoot).changeAll(root);
sysRoot.reload(Collections.singleton(root.getName()));
 
try {
4437,4 → 3972,360
}
}
 
public void updateDatabase(final ComptaPropsConfiguration conf) {
try {
final SQLDataSource ds = conf.getSystemRoot().getDataSource();
System.err.println("SystemRoot:" + conf.getSystemRoot());
System.err.println("Root:" + conf.getRoot());
 
// FixUnbounded varchar
fixUnboundedVarchar(conf.getRoot());
 
// FIXME DROP CONSTRAINT UNIQUE ORDRE ON
// CONTACT_FOURNISSEUR
 
checkCompteDefault(conf.getRoot());
 
updateSocieteTable(conf.getRoot());
updateVille(conf.getRoot().getTable("ADRESSE"));
 
// Champ user 1.4.1
final SQLTable tableUser = conf.getRoot().getTable("USER_COMMON");
if (tableUser != null) {
final AlterTable alter = new AlterTable(tableUser);
boolean alterUser = false;
if (!tableUser.contains("DISABLED")) {
alter.addBooleanColumn("DISABLED", Boolean.FALSE, false);
alterUser = true;
}
if (!tableUser.contains("TEL")) {
alter.addVarCharColumn("TEL", 128);
alterUser = true;
}
 
if (alterUser) {
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableUser.getName());
conf.getRoot().getSchema().updateVersion();
}
}
 
// Champ Paye
final SQLTable tableCaisse = conf.getRoot().getTable("CAISSE_COTISATION");
if (!tableCaisse.contains("NUMERO_COMPTE_PCE")) {
final AlterTable alter = new AlterTable(tableCaisse);
alter.addVarCharColumn("NUMERO_COMPTE_PCE", 128);
alter.addVarCharColumn("NUMERO_COMPTE_PCE_CHARGES", 128);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableCaisse.getName());
conf.getRoot().getSchema().updateVersion();
}
 
final SQLTable tableRC = conf.getRoot().getTable("RUBRIQUE_COTISATION");
if (!tableRC.contains("PART_CSG_SANS_ABATTEMENT")) {
final AlterTable alter = new AlterTable(tableRC);
alter.addBooleanColumn("PART_CSG_SANS_ABATTEMENT", Boolean.FALSE, false);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableRC.getName());
conf.getRoot().getSchema().updateVersion();
}
 
// Paye simplifiee
{
final SQLTable tableRB = conf.getRoot().getTable("RUBRIQUE_BRUT");
if (!tableRB.contains("AVANTAGE_NATURE")) {
final AlterTable alter = new AlterTable(tableRB);
alter.addBooleanColumn("AVANTAGE_NATURE", Boolean.FALSE, false);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableRB.getName());
conf.getRoot().getSchema().updateVersion();
}
 
if (!tableRC.contains("LIGNE_PAYE_SIMPLIFIEE")) {
final AlterTable alter = new AlterTable(tableRC);
 
alter.addBooleanColumn("ALLEGEMENT_COTISATION", Boolean.FALSE, false);
alter.addVarCharColumn("LIGNE_PAYE_SIMPLIFIEE", 256);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableRC.getName());
conf.getRoot().getSchema().updateVersion();
Map<String, String> liaison = new HashMap<String, String>();
liaison.put("COTCSA", LignePayeSimplifiee.SANTE_SECURITE.getId());
liaison.put("COTMALADIE", LignePayeSimplifiee.SANTE_SECURITE.getId());
liaison.put("COTAF", LignePayeSimplifiee.FAMILLE_ALLOCATIONS.getId());
liaison.put("COTVEUV", LignePayeSimplifiee.SANTE_SECURITE.getId());
 
liaison.put("COTVIEIL", LignePayeSimplifiee.RETRAITE_SECURITE_NON_PLAF.getId());
liaison.put("COTVIEILPLAF", LignePayeSimplifiee.RETRAITE_SECURITE_PLAF.getId());
liaison.put("COTFNALPLAF", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
liaison.put("COTFNAL", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
liaison.put("COTAT", LignePayeSimplifiee.ACCIDENTS_TRAVAIL.getId());
 
liaison.put("COTVTRAN", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
liaison.put("COTCH", LignePayeSimplifiee.ASSURANCE_CHOMAGE_CHOMAGE.getId());
liaison.put("COTCHAGS", LignePayeSimplifiee.ASSURANCE_CHOMAGE_CHOMAGE.getId());
liaison.put("COTAGFF", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_T1.getId());
liaison.put("COTRNonCadre", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_T1.getId());
 
liaison.put("COTCSGIMP", LignePayeSimplifiee.CSG_IMP.getId());
liaison.put("COTCSGDED", LignePayeSimplifiee.CSG_NON_IMP.getId());
liaison.put("COTFILLON", LignePayeSimplifiee.ALLEGEMENT_COTISATIONS.getId());
liaison.put("COTFNGS", LignePayeSimplifiee.ASSURANCE_CHOMAGE_CHOMAGE.getId());
liaison.put("COTCADRET1", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_TA.getId());
liaison.put("COTCADRET2", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_TB.getId());
 
liaison.put("COT_CADRE_RET_C_A", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_TA.getId());
liaison.put("COT_CADRE_RET_C_B", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_TB.getId());
liaison.put("COT_CADRE_RET_C_C", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_TC.getId());
liaison.put("COTAPEC", LignePayeSimplifiee.ASSURANCE_CHOMAGE_APEC.getId());
liaison.put("COTAPECFORF", LignePayeSimplifiee.ASSURANCE_CHOMAGE_APEC.getId());
liaison.put("COTCET", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_TA.getId());
 
liaison.put("COTPREVCADRETA", LignePayeSimplifiee.SANTE_COMPLEMENAIRE_DECES.getId());
liaison.put("COTGMP", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_GMP.getId());
liaison.put("COTCRDSIMP", LignePayeSimplifiee.CSG_IMP.getId());
liaison.put("COTGMP2", LignePayeSimplifiee.RETRAITE_COMPLEMENTAIRE_GMP.getId());
liaison.put("TAXEAPPR", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
liaison.put("CDA", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
 
liaison.put("FOR", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
liaison.put("COTAPECTA", LignePayeSimplifiee.ASSURANCE_CHOMAGE_APEC.getId());
liaison.put("COTFILLON2011", LignePayeSimplifiee.ALLEGEMENT_COTISATIONS.getId());
liaison.put("COTSYNDIC", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
liaison.put("COTPREV", LignePayeSimplifiee.RETRAITE_SUPPLEMENTAIRE.getId());
liaison.put("COT_MUTUELLE", LignePayeSimplifiee.SANTE_COMPLEMENAIRE_SANTE.getId());
liaison.put("COT_PENIBLE", LignePayeSimplifiee.AUTRES_CONTRIBUTIONS.getId());
 
SQLSelect sel = new SQLSelect();
sel.addSelect(conf.getRoot().findTable("RUBRIQUE_COTISATION").getField("CODE"));
sel.addSelect(conf.getRoot().findTable("RUBRIQUE_COTISATION").getField("NOM"));
sel.addSelect(conf.getRoot().findTable("RUBRIQUE_COTISATION").getKey());
List<SQLRow> rubCotis = SQLRowListRSH.execute(sel);
 
for (SQLRow sqlRow : rubCotis) {
final String code = sqlRow.getString("CODE");
if (liaison.containsKey(code)) {
sqlRow.createEmptyUpdateRow().put("LIGNE_PAYE_SIMPLIFIEE", liaison.get(code)).commit();
}
if (sqlRow.getString("NOM").toUpperCase().contains("FILLON")) {
sqlRow.createEmptyUpdateRow().put("ALLEGEMENT_COTISATION", Boolean.TRUE).commit();
}
}
}
}
 
final SQLTable tableRnet = conf.getRoot().getTable("RUBRIQUE_NET");
if (!tableRnet.contains("NUMERO_COMPTE_PCE_CHARGES")) {
final AlterTable alter = new AlterTable(tableRnet);
alter.addVarCharColumn("NUMERO_COMPTE_PCE_CHARGES", 128);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableCaisse.getName());
conf.getRoot().getSchema().updateVersion();
}
 
if (!tableRC.contains("PART_PAT_IMPOSABLE")) {
final AlterTable alter = new AlterTable(tableRC);
alter.addBooleanColumn("PART_PAT_IMPOSABLE", Boolean.FALSE, false);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableRC.getName());
conf.getRoot().getSchema().updateVersion();
}
 
if (!tableRC.contains("REDUCTION_FILLON")) {
final AlterTable alter = new AlterTable(tableRC);
alter.addBooleanColumn("REDUCTION_FILLON", Boolean.FALSE, false);
final String req = alter.asString();
conf.getRoot().getDBSystemRoot().getDataSource().execute(req);
conf.getRoot().refetchTable(tableRC.getName());
conf.getRoot().getSchema().updateVersion();
}
 
// Vérification des droits existants
checkRights(conf.getRoot());
 
if (!conf.getRoot().contains("DEVISE")) {
System.out.println("InstallationPanel.InstallationPanel() ADD DEVISE");
try {
SQLUtils.executeAtomic(ds, new SQLUtils.SQLFactory<Object>() {
@Override
public Object create() throws SQLException {
final SQLCreateTable createDevise = new SQLCreateTable(conf.getRoot(), "DEVISE");
createDevise.addVarCharColumn("CODE", 128);
createDevise.addVarCharColumn("NOM", 128);
createDevise.addVarCharColumn("LIBELLE", 128);
createDevise.addVarCharColumn("LIBELLE_CENT", 128);
createDevise.addDecimalColumn("TAUX", 16, 8, BigDecimal.ONE, false);
createDevise.addDecimalColumn("TAUX_COMMERCIAL", 16, 8, BigDecimal.ONE, false);
ds.execute(createDevise.asString());
insertUndef(createDevise);
conf.getRoot().getSchema().updateVersion();
return null;
}
});
} catch (Exception ex) {
throw new IllegalStateException("Erreur lors de la création de la table DEVISE", ex);
}
} else if (!conf.getRoot().getTable("DEVISE").contains("TAUX_COMMERCIAL")) {
final SQLTable tDevise = conf.getRoot().getTable("DEVISE");
final AlterTable alterDevise = new AlterTable(tDevise);
alterDevise.addDecimalColumn("TAUX_COMMERCIAL", 16, 8, BigDecimal.ONE, false);
ds.execute(alterDevise.asString());
tDevise.getSchema().updateVersion();
}
 
if (!conf.getRoot().contains("TYPE_MODELE")) {
System.out.println("InstallationPanel.InstallationPanel() ADD TYPE_MODELE");
try {
SQLUtils.executeAtomic(ds, new SQLUtils.SQLFactory<Object>() {
@Override
public Object create() throws SQLException {
final SQLCreateTable createTypeModele = new SQLCreateTable(conf.getRoot(), "TYPE_MODELE");
createTypeModele.addVarCharColumn("NOM", 128);
createTypeModele.addVarCharColumn("TABLE", 128);
createTypeModele.addVarCharColumn("DEFAULT_MODELE", 128);
ds.execute(createTypeModele.asString());
 
insertUndef(createTypeModele);
 
conf.getRoot().getSchema().updateVersion();
 
conf.getRoot().refetch();
 
return null;
}
});
final String[] type = new String[] { "Avoir client", "AVOIR_CLIENT", "Avoir", "Bon de livraison", "BON_DE_LIVRAISON", "BonLivraison", "Commande Client", "COMMANDE_CLIENT",
"CommandeClient", "Devis", "DEVIS", "Devis", "Facture", "SAISIE_VENTE_FACTURE", "VenteFacture" };
// ('FR', 'Français', 1.000), ('EN',
// 'Anglais', 2.000)
final List<String> values = new ArrayList<String>();
final SQLBase base = conf.getRoot().getBase();
 
for (int i = 0; i < type.length; i += 3) {
final int order = values.size() + 1;
values.add("(" + base.quoteString(type[i]) + ", " + base.quoteString(type[i + 1]) + ", " + base.quoteString(type[i + 2]) + ", " + order + ")");
}
final String valuesStr = CollectionUtils.join(values, ", ");
final String insertVals = "INSERT INTO " + conf.getRoot().getTable("TYPE_MODELE").getSQLName().quote() + "(" + SQLBase.quoteIdentifier("NOM") + ", "
+ SQLBase.quoteIdentifier("TABLE") + ", " + SQLBase.quoteIdentifier("DEFAULT_MODELE") + ", " + SQLBase.quoteIdentifier(SQLSyntax.ORDER_NAME) + ") VALUES" + valuesStr;
 
ds.execute(insertVals);
} catch (Exception ex) {
throw new IllegalStateException("Erreur lors de la création de la table TYPE_MODELE", ex);
}
}
 
SQLTable.setUndefID(conf.getRoot().getSchema(), "DEVISE", 1);
SQLTable.setUndefID(conf.getRoot().getSchema(), "TYPE_MODELE", 1);
 
// DSN
final DSNInstallationUtils dsnUtils = new DSNInstallationUtils();
dsnUtils.updateDSNCommonTable(conf.getRoot());
 
// ECo contribution
final EcoContributionInstallationUtils ecoUtils = new EcoContributionInstallationUtils();
ecoUtils.updateEcoCommonTable(conf.getRoot());
 
 
// we need to upgrade all roots
// ///////////////////////////
conf.getSystemRoot().mapAllRoots();
conf.getSystemRoot().refetch();
 
final Set<String> childrenNames = conf.getSystemRoot().getChildrenNames();
 
SwingUtilities.invokeLater(new Runnable() {
 
@Override
public void run() {
bar.setIndeterminate(false);
bar.setMaximum(childrenNames.size() + 1);
}
});
int i = 1;
for (final String childName : childrenNames) {
System.out.println("InstallationPanel.InstallationPanel() UPDATE SCHEMA " + childName);
final int barValue = i;
 
SwingUtilities.invokeLater(new Runnable() {
 
@Override
public void run() {
bar.setValue(barValue);
}
});
i++;
final DBRoot root = conf.getSystemRoot().getRoot(childName);
try {
conf.getSystemRoot().getDataSource().execute("CREATE LANGUAGE plpgsql;");
} catch (Exception e) {
System.err.println("Warning: cannot add language plpgsql" + e.getMessage());
}
final SQLTable tableUndef = root.getTable(SQLTable.undefTable);
if (tableUndef != null && tableUndef.getField("UNDEFINED_ID").isNullable() == Boolean.FALSE) {
final AlterTable alterUndef = new AlterTable(tableUndef);
alterUndef.alterColumn("TABLENAME", EnumSet.allOf(Properties.class), "varchar(250)", "''", false);
alterUndef.alterColumn("UNDEFINED_ID", EnumSet.allOf(Properties.class), "int", null, true);
try {
ds.execute(alterUndef.asString());
tableUndef.getSchema().updateVersion();
} catch (SQLException ex) {
throw new IllegalStateException("Erreur lors de la modification de UNDEFINED_ID", ex);
}
}
 
if (DEBUG_FK) {
findBadForeignKey(root);
}
 
if (childName.equalsIgnoreCase("Common")) {
updateCommon(root);
} else if (childName.startsWith(conf.getAppName()) || childName.equalsIgnoreCase("Default")
) {
SQLUtils.executeAtomic(ds, new SQLUtils.SQLFactory<Object>() {
@Override
public Object create() throws SQLException {
fixUnboundedVarchar(root);
fixUnboundedNumeric(root);
fixCompletion(root);
try {
updateSocieteSchema(root);
} catch (Exception e) {
throw new SQLException(e);
}
updateToV1Dot2(root);
updateToV1Dot3(root);
updateToV1Dot4(root);
// DSN
dsnUtils.updateDSN(root);
// Eco contribution
ecoUtils.updateEco(root);
updateStyle(root);
createBanque(root);
createAssocAnalytique(root, conf);
updateStock(root);
updateVille(root.getTable("ADRESSE"));
 
Updater_1_5.update(root);
return null;
}
 
});
}
 
}
error = false;
} catch (Throwable e1) {
ExceptionHandler.handle("Echec de mise à jour", e1);
error = true;
}
}
 
}