import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
-import nu.xom.ParsingException;
-
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.commons.lang.StringEscapeUtils;
import fr.gouv.finances.cp.utils.PropertiesExpansion;
import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;
-import fr.gouv.finances.cp.xemelios.data.impl.MySqlDataLayer;
import fr.gouv.finances.cp.xemelios.data.impl.mysql.serialization.DataResultSetWrapperModel;
import fr.gouv.finances.cp.xemelios.data.impl.mysql.serialization.DrswParser;
import fr.gouv.finances.cp.xemelios.data.impl.mysql.serialization.ExportJobImpl;
}
@Override
- public void registerBudgetCollectivite(final DocumentModel dm, final Pair codeBudget, final Pair collectivite, final Pair[] parentCollectivites, final String docName, final String archiveName, final XemeliosUser user) throws DataConfigurationException, DataAccessException, UnauthorizedException {
+ public void registerBudgetCollectivite(final DocumentModel dm, final Pair codeBudget, final Pair collectivite, final Pair[] parentCollectivites, final String docName, final String archiveName, final XemeliosUser user)
+ throws DataConfigurationException, DataAccessException, UnauthorizedException {
if (!user.hasRole(XemeliosUser.ROLE_IMPORT)) {
throw new UnauthorizedException("Vous n'êtes pas autorisé à importer des fichiers");
}
if (!rs.next()) {
sb = new StringBuilder();
final StringBuffer binds = new StringBuffer();
- sb.append("INSERT INTO ").append(pc.getListBcTable().getBaseName())
+ sb.append("INSERT INTO ")
+ .append(pc.getListBcTable().getBaseName())
.append(" (" + pc.getBudgetCodeColname() + "," + pc.getCollectiviteCodeColname() + "," + pc.getInitialDocNameColname() + "," + pc.getArchiveNameColname() + "," + pc.getBudgetLibColname() + "," + pc.getCollectiviteLibColname());
binds.append(" VALUES (?,?,?,?,?,?");
for (int i = 0; i < parentCollectivites.length; i++) {
}
@Override
- public boolean importElement(final DocumentModel dm, final EtatModel currentEtat, final Pair codeBudget, final Pair collectivite, final String sourceFileName, final String elementName, final byte[] data, final String encoding, final String archiveName, final XemeliosUser user)
- throws DataConfigurationException, DataAccessException, UnauthorizedException {
+ public boolean importElement(final DocumentModel dm, final EtatModel currentEtat, final Pair codeBudget, final Pair collectivite, final String sourceFileName, final String elementName, final byte[] data, final String encoding,
+ final String archiveName, final XemeliosUser user) throws DataConfigurationException, DataAccessException, UnauthorizedException {
if (!user.hasRole(XemeliosUser.ROLE_IMPORT)) {
throw new UnauthorizedException(String.format(this.getMessages().getString(MessageEntries.NOT_ALLOWED_ROLE), this.getMessages().getString(MessageEntries.ROLE_IMPORT)));
}
// inserting document
final StringBuilder sb = new StringBuilder();
- sb.append("INSERT INTO ").append(sec.getDocumentTable().getBaseName()).append(" (" + pc.getBudgetCodeColname() + "," + pc.getCollectiviteCodeColname() + ", " + pc.getInitialDocNameColname() + ", DOC_ID, DOC, " + pc.getArchiveNameColname() + ") VALUES (?,?,?,?,?,?)");
+ sb.append("INSERT INTO ").append(sec.getDocumentTable().getBaseName())
+ .append(" (" + pc.getBudgetCodeColname() + "," + pc.getCollectiviteCodeColname() + ", " + pc.getInitialDocNameColname() + ", DOC_ID, DOC, " + pc.getArchiveNameColname() + ") VALUES (?,?,?,?,?,?)");
ps = con.prepareStatement(sb.toString());
ps.setString(1, codeBudget.key);
ps.setString(2, collectivite.key);
StringBuilder sql = null;
for (final TTable ixTable : sec.getIndexTables()) {
sql = new StringBuilder();
- sql.append("DELETE FROM ").append(ixTable.getBaseName()).append(" WHERE ").append(pc.getCollectiviteCodeColname()).append("=? AND ").append(pc.getBudgetCodeColname()).append("=? AND ").append(pc.getInitialDocNameColname()).append("=?");
+ sql.append("DELETE FROM ").append(ixTable.getBaseName()).append(" WHERE ").append(pc.getCollectiviteCodeColname()).append("=? AND ").append(pc.getBudgetCodeColname()).append("=? AND ").append(pc.getInitialDocNameColname())
+ .append("=?");
ps = con.prepareStatement(sql.toString());
ps.setString(1, collectivite.key);
ps.setString(2, budget.key);
// delete from special keys
if (pc.getSpecialKeyTable() != null) {
sql = new StringBuilder();
- sql.append("delete from ").append(pc.getSpecialKeyTable().getBaseName()).append(" where ").append(pc.getCollectiviteCodeColname()).append("=? AND ").append(pc.getBudgetCodeColname()).append("=? AND ").append(pc.getInitialDocNameColname()).append("=?");
+ sql.append("delete from ").append(pc.getSpecialKeyTable().getBaseName()).append(" where ").append(pc.getCollectiviteCodeColname()).append("=? AND ").append(pc.getBudgetCodeColname()).append("=? AND ")
+ .append(pc.getInitialDocNameColname()).append("=?");
ps = con.prepareStatement(sql.toString());
ps.setString(1, collectivite.key);
ps.setString(2, budget.key);
}
// delete from documents
sql = new StringBuilder();
- sql.append("delete from ").append(sec.getDocumentTable().getBaseName()).append(" where ").append(pc.getCollectiviteCodeColname()).append("=? AND ").append(pc.getBudgetCodeColname()).append("=? AND ").append(pc.getInitialDocNameColname()).append("=?");
+ sql.append("delete from ").append(sec.getDocumentTable().getBaseName()).append(" where ").append(pc.getCollectiviteCodeColname()).append("=? AND ").append(pc.getBudgetCodeColname()).append("=? AND ")
+ .append(pc.getInitialDocNameColname()).append("=?");
ps = con.prepareStatement(sql.toString());
ps.setString(1, collectivite.key);
ps.setString(2, budget.key);
ps.executeUpdate();
// delete from list bud/coll
sql = new StringBuilder();
- sql.append("delete from ").append(pc.getListBcTable().getBaseName()).append(" where ").append(pc.getCollectiviteCodeColname()).append("=? AND ").append(pc.getBudgetCodeColname()).append("=? AND ").append(pc.getInitialDocNameColname()).append("=?");
+ sql.append("delete from ").append(pc.getListBcTable().getBaseName()).append(" where ").append(pc.getCollectiviteCodeColname()).append("=? AND ").append(pc.getBudgetCodeColname()).append("=? AND ")
+ .append(pc.getInitialDocNameColname()).append("=?");
ps = con.prepareStatement(sql.toString());
ps.setString(1, collectivite.key);
ps.setString(2, budget.key);
}
@Override
- public void saveSpecialKeys(final DocumentModel dm, final Pair budget, final Pair collectivite, final String docName, final String archiveName, final Pair sk1, final Pair sk2, final Pair sk3, final XemeliosUser user) throws DataConfigurationException, DataAccessException, UnauthorizedException {
+ public void saveSpecialKeys(final DocumentModel dm, final Pair budget, final Pair collectivite, final String docName, final String archiveName, final Pair sk1, final Pair sk2, final Pair sk3, final XemeliosUser user)
+ throws DataConfigurationException, DataAccessException, UnauthorizedException {
if (!user.hasRole(XemeliosUser.ROLE_IMPORT)) {
throw new UnauthorizedException("Vous n'êtes pas autorisé à importer des fichiers");
}
}
@Override
- public Vector<Pair> getSpecialKeys2(final DocumentModel dm, final Pair collectivite, final Pair budget, final Pair key1, final boolean distinct, final XemeliosUser user) throws DataConfigurationException, DataAccessException, UnauthorizedException {
+ public Vector<Pair> getSpecialKeys2(final DocumentModel dm, final Pair collectivite, final Pair budget, final Pair key1, final boolean distinct, final XemeliosUser user) throws DataConfigurationException, DataAccessException,
+ UnauthorizedException {
if (!user.hasRole(XemeliosUser.ROLE_SEARCH)) {
throw new UnauthorizedException("Vous n'êtes pas autorisé à faire des recherches");
}
try {
con = PoolManager.getInstance().getConnection();
final StringBuilder sb = new StringBuilder();
- sb.append("SELECT ").append(distinct ? "DISTINCT " : " ").append("KEY2,LIB2 FROM ").append(pc.getSpecialKeyTable().getBaseName()).append(" WHERE KEY1=? AND " + pc.getCollectiviteCodeColname() + "=? AND " + pc.getBudgetCodeColname() + "=? AND KEY2 is not null");
+ sb.append("SELECT ").append(distinct ? "DISTINCT " : " ").append("KEY2,LIB2 FROM ").append(pc.getSpecialKeyTable().getBaseName())
+ .append(" WHERE KEY1=? AND " + pc.getCollectiviteCodeColname() + "=? AND " + pc.getBudgetCodeColname() + "=? AND KEY2 is not null");
ps = con.prepareStatement(sb.toString());
ps.setString(1, key1.key);
ps.setString(2, collectivite.key);
}
@Override
- public Vector<Pair> getSpecialKeys3(final DocumentModel dm, final Pair collectivite, final Pair budget, final Pair key1, final Pair key2, final boolean distinct, final XemeliosUser user) throws DataConfigurationException, DataAccessException, UnauthorizedException {
+ public Vector<Pair> getSpecialKeys3(final DocumentModel dm, final Pair collectivite, final Pair budget, final Pair key1, final Pair key2, final boolean distinct, final XemeliosUser user) throws DataConfigurationException, DataAccessException,
+ UnauthorizedException {
if (!user.hasRole(XemeliosUser.ROLE_SEARCH)) {
throw new UnauthorizedException("Vous n'êtes pas autorisé à faire des recherches");
}
try {
con = PoolManager.getInstance().getConnection();
final StringBuilder sb = new StringBuilder();
- sb.append("SELECT ").append(distinct ? "DISTINCT " : " ").append("KEY3,LIB3 FROM ").append(pc.getSpecialKeyTable().getBaseName()).append(" WHERE KEY1=? AND KEY2=? AND " + pc.getCollectiviteCodeColname() + "=? AND " + pc.getBudgetCodeColname() + "=?");
+ sb.append("SELECT ").append(distinct ? "DISTINCT " : " ").append("KEY3,LIB3 FROM ").append(pc.getSpecialKeyTable().getBaseName())
+ .append(" WHERE KEY1=? AND KEY2=? AND " + pc.getCollectiviteCodeColname() + "=? AND " + pc.getBudgetCodeColname() + "=?");
ps = con.prepareStatement(sb.toString());
ps.setString(1, key1.key);
ps.setString(2, key2.key);
try {
con = PoolManager.getInstance().getConnection();
final StringBuilder sb = new StringBuilder();
- sb.append("SELECT DISTINCT " + pc.getBudgetCodeColname() + ", " + pc.getBudgetLibColname() + " FROM ").append(pc.getListBcTable().getBaseName()).append(" WHERE " + pc.getCollectiviteCodeColname() + "=? ORDER BY " + pc.getBudgetLibColname());
+ sb.append("SELECT DISTINCT " + pc.getBudgetCodeColname() + ", " + pc.getBudgetLibColname() + " FROM ").append(pc.getListBcTable().getBaseName())
+ .append(" WHERE " + pc.getCollectiviteCodeColname() + "=? ORDER BY " + pc.getBudgetLibColname());
ps = con.prepareStatement(sb.toString());
ps.setString(1, collectivite.key);
final ResultSet rs = ps.executeQuery();
}
@Override
- public Collection<Pair> queryRepository(final DocumentModel dm, final Pair collectivite, final RecherchePaireModel rpm, final Pair refNomenclature, final XemeliosUser user) throws DataConfigurationException, DataAccessException, UnauthorizedException {
+ public Collection<Pair> queryRepository(final DocumentModel dm, final Pair collectivite, final RecherchePaireModel rpm, final Pair refNomenclature, final XemeliosUser user) throws DataConfigurationException, DataAccessException,
+ UnauthorizedException {
if (!user.hasRole(XemeliosUser.ROLE_SEARCH)) {
throw new UnauthorizedException("Vous n'êtes pas autorisé à faire des recherches");
}
final TTable sti = sec.getIndexTable(si.getTableId());
final StringBuilder sb = new StringBuilder();
sb.append("SELECT DISTINCT(").append(si.getColumn()).append(") FROM ").append(sti.getBaseName()).append(" ");
- sb.append("WHERE " + pc.getCollectiviteCodeColname() + "='").append(StringEscapeUtils.escapeSql(collectivite.key)).append("' AND " + pc.getBudgetCodeColname() + "='").append(StringEscapeUtils.escapeSql(budget.key)).append("' AND ").append(si.getColumn()).append(" IS NOT NULL ORDER BY 1");
+ sb.append("WHERE " + pc.getCollectiviteCodeColname() + "='").append(StringEscapeUtils.escapeSql(collectivite.key)).append("' AND " + pc.getBudgetCodeColname() + "='").append(StringEscapeUtils.escapeSql(budget.key)).append("' AND ")
+ .append(si.getColumn()).append(" IS NOT NULL ORDER BY 1");
final Vector<String> vRet = new Vector<String>();
Connection con = null;
}
@Override
- public boolean removeSpecialKey3(final DocumentModel dm, final Pair collectivite, final Pair budget, final Pair key1, final Pair key2, final Pair key3, final XemeliosUser user) throws DataConfigurationException, DataAccessException, UnauthorizedException {
+ public boolean removeSpecialKey3(final DocumentModel dm, final Pair collectivite, final Pair budget, final Pair key1, final Pair key2, final Pair key3, final XemeliosUser user) throws DataConfigurationException, DataAccessException,
+ UnauthorizedException {
if (!user.hasRole(XemeliosUser.ROLE_CLEAN)) {
throw new UnauthorizedException("Vous n'êtes pas autorisé à supprimer des données");
}
try {
con = PoolManager.getInstance().getConnection();
final StringBuilder sb = new StringBuilder();
- sb.append("SELECT " + pc.getInitialDocNameColname() + " FROM ").append(pc.getSpecialKeyTable().getBaseName()).append(" WHERE " + pc.getCollectiviteCodeColname() + "=? AND " + pc.getBudgetCodeColname() + "=? AND KEY1=? AND KEY2=? AND KEY3=?");
+ sb.append("SELECT " + pc.getInitialDocNameColname() + " FROM ").append(pc.getSpecialKeyTable().getBaseName())
+ .append(" WHERE " + pc.getCollectiviteCodeColname() + "=? AND " + pc.getBudgetCodeColname() + "=? AND KEY1=? AND KEY2=? AND KEY3=?");
ps = con.prepareStatement(sb.toString());
ps.setString(1, collectivite.key);
ps.setString(2, budget.key);
}
@Override
- public DataResultSet search(final ElementModel elementModel, final Pair collectivite, final Pair budget, final String xPath, final ListeResultatModel lrm, final Vector<CritereModel> models, final XemeliosUser user) throws DataConfigurationException, DataAccessException, UnauthorizedException {
+ public DataResultSet search(final ElementModel elementModel, final Pair collectivite, final Pair budget, final String xPath, final ListeResultatModel lrm, final Vector<CritereModel> models, final XemeliosUser user)
+ throws DataConfigurationException, DataAccessException, UnauthorizedException {
if (!user.hasRole(XemeliosUser.ROLE_SEARCH)) {
throw new UnauthorizedException("Vous n'êtes pas autorisé à faire des recherches");
}
@Override
public Pair[] getOperators(final String datatype) {
if ("string".equals(datatype)) {
- return new Pair[] { new Pair("starts-with", "commence par"), new Pair("contains", "contient"), new Pair("xem:does-not-contain", "ne contient pas"), new Pair("xem:ends-with", "fini par"), new Pair("xem:StringEquals", "égal à "), new Pair("xem:StringDiffers", "diffère de"),
- new Pair("xem:StringIsNotNull", "n'est pas nul") };
+ return new Pair[] { new Pair("starts-with", "commence par"), new Pair("contains", "contient"), new Pair("xem:does-not-contain", "ne contient pas"), new Pair("xem:ends-with", "fini par"), new Pair("xem:StringEquals", "égal à "),
+ new Pair("xem:StringDiffers", "diffère de"), new Pair("xem:StringIsNotNull", "n'est pas nul") };
} else if ("numeric".equals(datatype)) {
return new Pair[] { new Pair("=", "="), new Pair(">=", ">="), new Pair(">", ">"), new Pair("<", "<"), new Pair("<=", "<="), new Pair("!=", "!=") };
} else if ("date".equals(datatype)) {
}
@Override
- public ArrayList<String> getDocumentListFromSpecialKeys(final ElementModel em, final String collectivite, final String budget, final String sp1, final String sp2, final String sp3, final XemeliosUser user) throws DataConfigurationException, DataAccessException, UnauthorizedException {
+ public ArrayList<String> getDocumentListFromSpecialKeys(final ElementModel em, final String collectivite, final String budget, final String sp1, final String sp2, final String sp3, final XemeliosUser user) throws DataConfigurationException,
+ DataAccessException, UnauthorizedException {
if (!user.hasRole(XemeliosUser.ROLE_SEARCH)) {
throw new UnauthorizedException("Vous n'êtes pas autorisé à faire des recherches");
}
return ret;
}
- @Override
- public ArrayList<String> getDocumentListFromXPath(final ElementModel em, final String collectivite, final String budget, final String sp1, final String sp2, final String sp3, final String xpath, final XemeliosUser user) throws DataConfigurationException, DataAccessException,
- UnauthorizedException {
- if (!user.hasRole(XemeliosUser.ROLE_SEARCH)) {
- throw new UnauthorizedException("Vous n'êtes pas autorisé à faire des recherches");
- }
- if (!user.hasDocument(em.getParent().getParent().getId())) {
- throw new UnauthorizedException("Vous n'êtes pas autorisé à rechercher des " + em.getTitre());
- }
- if (!user.hasCollectivite(collectivite, em.getParent().getParent())) {
- throw new UnauthorizedException("Vous n'êtes pas autorisé à rechercher des données pour cette collectivité");
- }
- final ArrayList<String> ret = new ArrayList<String>();
- final StringBuffer selectClause = new StringBuffer();
- final StringBuffer fromClause = new StringBuffer();
- final StringBuffer whereClause = new StringBuffer();
- final ArrayList<String> addedTableNames = new ArrayList<String>();
- final EtatModel etatModel = em.getParent();
- final TDocument pc = this.getPersistenceConfig(etatModel.getParent(), user).getLayer(this.getLayerName()).getDocument(etatModel.getParent().getId());
- final TEtat sec = pc.getEtat(etatModel.getId());
- selectClause.append("SELECT DISTINCT(").append(sec.getMaintable().getBaseName()).append(".DOC_ID) ");
- fromClause.append("FROM ").append(sec.getMaintable().getBaseName()).append(" ");
- addedTableNames.add(sec.getMaintable().getId());
- whereClause.append(" WHERE ").append(sec.getMaintable().getBaseName()).append("." + pc.getCollectiviteCodeColname() + "=? AND ").append(sec.getMaintable().getBaseName()).append("." + pc.getBudgetCodeColname() + "=? ");
- final DocumentModel dm = etatModel.getParent();
- final Vector<SpecialKeyModel> specialKeys = dm.getSpecialKeys();
- if (sp1 != null) {
- // search SPK1 XPath
- SpecialKeyModel skm = null;
- for (final SpecialKeyModel sk : specialKeys) {
- if (sk.getPos() == 1) {
- skm = sk;
- }
- }
- if (skm != null) {
- final String path = skm.getPath();
- final TSqlIndex si = sec.getSqlIndexByPath(path);
- final String tName = sec.getIndexTable(si.getTableId()).getBaseName();
- whereClause.append("AND ").append(tName).append(".").append(si.getColumn()).append("=? ");
- if (!addedTableNames.contains(si.getTableId())) {
- fromClause.append(" LEFT OUTER JOIN ").append(tName).append(" ON ").append(sec.getMaintable().getBaseName()).append(".DOC_ID=").append(tName).append(".DOC_ID AND ").append(sec.getMaintable().getBaseName()).append("." + pc.getCollectiviteCodeColname() + "=").append(tName)
- .append("." + pc.getCollectiviteCodeColname() + " AND ").append(sec.getMaintable().getBaseName()).append("." + pc.getBudgetCodeColname() + "=").append(tName).append("." + pc.getBudgetCodeColname() + "");
- addedTableNames.add(si.getTableId());
- }
- } else {
- throw new DataConfigurationException("no special key in pos 1 defined for " + dm.getId());
- }
- }
- if (sp2 != null) {
- // search SPK1 XPath
- SpecialKeyModel skm = null;
- for (final SpecialKeyModel sk : specialKeys) {
- if (sk.getPos() == 2) {
- skm = sk;
- }
- }
- if (skm != null) {
- final String path = skm.getPath();
- final TSqlIndex si = sec.getSqlIndexByPath(path);
- final String tName = sec.getIndexTable(si.getTableId()).getBaseName();
- whereClause.append("AND ").append(tName).append(".").append(si.getColumn()).append("=? ");
- if (!addedTableNames.contains(si.getTableId())) {
- fromClause.append(" LEFT OUTER JOIN ").append(tName).append(" ON ").append(sec.getMaintable().getBaseName()).append(".DOC_ID=").append(tName).append(".DOC_ID AND ").append(sec.getMaintable().getBaseName()).append("." + pc.getCollectiviteCodeColname() + "=").append(tName)
- .append("." + pc.getCollectiviteCodeColname() + " AND ").append(sec.getMaintable().getBaseName()).append("." + pc.getBudgetCodeColname() + "=").append(tName).append("." + pc.getBudgetCodeColname() + "");
- addedTableNames.add(si.getTableId());
- }
- } else {
- throw new DataConfigurationException("no special key in pos 2 defined for " + dm.getId());
- }
- }
- if (sp3 != null) {
- // search SPK3 XPath
- SpecialKeyModel skm = null;
- for (final SpecialKeyModel sk : specialKeys) {
- if (sk.getPos() == 3) {
- skm = sk;
- }
- }
- if (skm != null) {
- final String path = skm.getPath();
- final TSqlIndex si = sec.getSqlIndexByPath(path);
- final String tName = sec.getIndexTable(si.getTableId()).getBaseName();
- whereClause.append("AND ").append(tName).append(".").append(si.getColumn()).append("=? ");
- if (!addedTableNames.contains(si.getTableId())) {
- fromClause.append(" LEFT OUTER JOIN ").append(tName).append(" ON ").append(sec.getMaintable().getBaseName()).append(".DOC_ID=").append(tName).append(".DOC_ID AND ").append(sec.getMaintable().getBaseName()).append("." + pc.getCollectiviteCodeColname() + "=").append(tName)
- .append("." + pc.getCollectiviteCodeColname() + " AND ").append(sec.getMaintable().getBaseName()).append("." + pc.getBudgetCodeColname() + "=").append(tName).append("." + pc.getBudgetCodeColname() + "");
- addedTableNames.add(si.getTableId());
- }
- } else {
- throw new DataConfigurationException("no special key in pos 3 defined for " + dm.getId());
- }
- }
- if (xpath != null) {
- /*
- * on suppose que le xpath est de la forme /toto/titi/tata[tutu/@V=x1][@tete=x2]... ou /toto/titi/tata est le chemin de l'element a chercher (pour
- * simplifier encore) on va chercher a isoler les chemins et les valeurs : /toto/titi/tata/tutu/@V -> x1 /toto/titi/tata/@tete -> x2 Si ces chemins
- * sont indexes, alors on pourra ajouter des clauses where dans le sql. Cette syntaxe devrait etre suffisante pour gérer la navigation dans le
- * compte de gestion. C'est du bricolage, mais je n'ai pas d'autre solution pour le moment
- */
- OracleDataLayer.logger.debug("xpath is " + xpath);
- if (xpath.startsWith(em.getPath().getPath())) {
- final String shortPath = xpath.substring(em.getPath().getPath().length());
- if (!shortPath.startsWith("[")) {
- throw new DataConfigurationException("XPath too complicated. This implementation can only deal with XPath formed by <path-to-element>[cond on sub-element][cond on sub element]...");
- }
- // decoupage par groupe de [...]
- final String[] conds = OracleDataLayer.splitConditions(shortPath);
- for (String s : conds) {
- OracleDataLayer.logger.debug(s);
- // pour le moment, on cherche les opérateurs <= >= = < >
- s = s.substring(1, s.length() - 1);
- String op = null;
- int pos = -1;
- pos = s.indexOf("<=");
- if (pos >= 0) {
- op = "<=";
- } else {
- pos = s.indexOf(">=");
- if (pos >= 0) {
- op = ">=";
- } else {
- pos = s.indexOf('=');
- if (pos >= 0) {
- op = "=";
- } else {
- pos = s.indexOf('<');
- if (pos >= 0) {
- op = "<";
- } else {
- pos = s.indexOf('>');
- if (pos >= 0) {
- op = ">";
- }
- }
- }
- }
- }
- final String left = s.substring(0, pos);
- final String right = s.substring(pos + op.length());
- final String indexedPath = em.getPath().getPath() + "/" + left;
- OracleDataLayer.logger.debug(indexedPath + " " + op + " " + right);
- //
- final TSqlIndex si = sec.getSqlIndexByPath(indexedPath);
- if (si != null) {
- final String tName = sec.getIndexTable(si.getTableId()).getBaseName();
- String value = null;
- if ("string".equals(si.getDatatype())) {
- value = MySqlDataLayer.sqlEscapeString(si.getFormattedStringValue(right));
- if (!value.startsWith("'") && !value.endsWith("'")) {
- value = "'".concat(value).concat("'");
- }
- } else {
- value = MySqlDataLayer.sqlEscapeString(right);
- }
- whereClause.append("AND ").append(tName).append(".").append(si.getColumn()).append(op).append(value).append(" ");
- if (!addedTableNames.contains(si.getTableId())) {
- fromClause.append(" LEFT OUTER JOIN ").append(tName).append(" ON ").append(sec.getMaintable().getBaseName()).append(".DOC_ID=").append(tName).append(".DOC_ID AND ").append(sec.getMaintable().getBaseName()).append("." + pc.getCollectiviteCodeColname() + "=").append(tName)
- .append("." + pc.getCollectiviteCodeColname() + " AND ").append(sec.getMaintable().getBaseName()).append("." + pc.getBudgetCodeColname() + "=").append(tName).append("." + pc.getBudgetCodeColname() + "");
- addedTableNames.add(si.getTableId());
- }
- } else {
- throw new DataConfigurationException("path not indexed: " + indexedPath);
- }
- }
- } else {
- throw new DataConfigurationException("XPath too complicated. only XPath starting with element path are allowed. Here, XPath should start with " + em.getPath().getPath());
- }
- }
-
- String sql = selectClause.append(fromClause.toString()).append(whereClause.toString()).toString();
- // en oracle, ceci n'a pas de sens :
- // COLUMN = ''
- // donc on le remplace par COLUMN IS NULL
- // dans l'idéal, il faudrait traiter les conditions XPath dans le bloc
- // if(xpath!=null) {...}
- // pour ajouter la gestion des OR et AND, et l'utilisation des fonctions
- // xpath, genre
- // xem:StringIsNull, upper-case, etc... Mais c'est long cher et risqué,
- // donc on fait ce
- // gros patch tout pourri !
- sql = sql.replaceAll("= *''", " IS NULL");
- OracleDataLayer.logger.debug(sql);
- // well, now sql is complete
- Connection con = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- try {
- con = PoolManager.getInstance().getConnection();
- ps = con.prepareStatement(sql);
- ps.setString(1, collectivite);
- OracleDataLayer.logger.debug("1(coll)->" + collectivite);
- ps.setString(2, budget);
- OracleDataLayer.logger.debug("2(budg)->" + budget);
- if (sp1 != null) {
- ps.setString(3, sp1);
- OracleDataLayer.logger.debug("3(sp1 )->" + sp1);
- }
- if (sp2 != null) {
- ps.setString(4, sp2);
- OracleDataLayer.logger.debug("4(sp2 )->" + sp2);
- }
- if (sp3 != null) {
- ps.setString(5, sp3);
- OracleDataLayer.logger.debug("5(sp3 )->" + sp3);
- }
- rs = ps.executeQuery();
- while (rs.next()) {
- ret.add(rs.getString(1));
- }
- } catch (final SQLException sqlEx) {
- throw new DataAccessException(sqlEx);
- } finally {
- if (rs != null) {
- try {
- rs.close();
- } catch (final Throwable t) {
- OracleDataLayer.logger.info("rs closed !", t);
- }
- }
- if (ps != null) {
- try {
- ps.close();
- } catch (final Throwable t) {
- OracleDataLayer.logger.info("ps closed !", t);
- }
- }
- if (con != null) {
- PoolManager.getInstance().releaseConnection(con);
- }
- }
- return ret;
- }
-
@Override
public nu.xom.Document getManifesteFromArchive(final String archiveName, final XemeliosUser user) throws DataConfigurationException, DataAccessException, UnauthorizedException {
DocumentModel dm = null;
return retour;
}
+ public Connection getConnection() throws SQLException {
+ return PoolManager.getInstance().getConnection();
+ }
+
+ public void releaseConnection(final Connection con) {
+ PoolManager.getInstance().releaseConnection(con);
+ }
+
@Override
public SimpleDateFormat getDateFormatter() {
return OracleDataLayer.oracleDateFormat;
}
@Override
- public String calculateAggregate(final DocumentModel dm, final EtatModel em, String columnXPath, final String operator, final ChampModel cm, final DataResultSet rs, final XemeliosUser user) throws DataConfigurationException, DataAccessException, UnauthorizedException {
+ public String calculateAggregate(final DocumentModel dm, final EtatModel em, String columnXPath, final String operator, final ChampModel cm, final DataResultSet rs, final XemeliosUser user) throws DataConfigurationException, DataAccessException,
+ UnauthorizedException {
if (!user.hasRole(XemeliosUser.ROLE_SEARCH)) {
throw new UnauthorizedException("Vous n'êtes pas autorisé à faire des recherches");
}
try {
con = PoolManager.getInstance().getConnection();
final StringBuilder sb = new StringBuilder();
- sb.append("SELECT " + pc.getCollectiviteCodeColname() + ", " + pc.getCollectiviteLibColname() + ", " + pc.getBudgetCodeColname() + ", " + pc.getBudgetLibColname() + ", " + pc.getInitialDocNameColname() + " FROM ").append(pc.getListBcTable().getBaseName());
+ sb.append("SELECT " + pc.getCollectiviteCodeColname() + ", " + pc.getCollectiviteLibColname() + ", " + pc.getBudgetCodeColname() + ", " + pc.getBudgetLibColname() + ", " + pc.getInitialDocNameColname() + " FROM ").append(
+ pc.getListBcTable().getBaseName());
if (coll != null) {
sb.append(" WHERE " + pc.getCollectiviteCodeColname() + "=? ");
}
}
@Override
- public DataResultSet getDataResultSetForExport(final int whatToExport, final ElementModel em, final Pair coll, final Pair budg, final String fic, final Pair SK1, final Pair SK2, final XemeliosUser user) throws DataConfigurationException, SQLException, UnauthorizedException {
+ public DataResultSet getDataResultSetForExport(final int whatToExport, final ElementModel em, final Pair coll, final Pair budg, final String fic, final Pair SK1, final Pair SK2, final XemeliosUser user) throws DataConfigurationException,
+ SQLException, UnauthorizedException {
if (!user.hasRole(XemeliosUser.ROLE_EXPORT)) {
throw new UnauthorizedException("Vous n'êtes pas autorisé à faire des exports");
}
Connection con = null;
try {
con = PoolManager.getInstance().getConnection();
- final String sql = "SELECT " + "EXPORT_ID, " + "FILE_NAME, " + "EXPORT_NAME, " + "DOC_ID, " + "ETAT_ID, " + "ELEMENT_ID, " + "CONFIG_ID, " + "EXPORT_SIZE, " + "PRIORITY, " + "EXPORT_STATUS, " + "SUBMIT_DATE, " + "RUN_DATE, " + "DOWNLOAD_DATE, " + "ERROR_MESSAGE, "
- + "GENERATED_FILE_NAME, " + "CLEANED, " + "UTI_LOGIN " + "FROM EXPORT_JOBS " + "WHERE UTI_LOGIN=? " + "AND (DOWNLOAD_DATE IS NULL OR DOWNLOAD_DATE<(SYSDATE+7)) AND CLEANED IS NULL";
+ final String sql = "SELECT " + "EXPORT_ID, " + "FILE_NAME, " + "EXPORT_NAME, " + "DOC_ID, " + "ETAT_ID, " + "ELEMENT_ID, " + "CONFIG_ID, " + "EXPORT_SIZE, " + "PRIORITY, " + "EXPORT_STATUS, " + "SUBMIT_DATE, " + "RUN_DATE, "
+ + "DOWNLOAD_DATE, " + "ERROR_MESSAGE, " + "GENERATED_FILE_NAME, " + "CLEANED, " + "UTI_LOGIN " + "FROM EXPORT_JOBS " + "WHERE UTI_LOGIN=? " + "AND (DOWNLOAD_DATE IS NULL OR DOWNLOAD_DATE<(SYSDATE+7)) AND CLEANED IS NULL";
final PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, user.getId());
final ResultSet rs = ps.executeQuery();
Connection con = null;
try {
con = PoolManager.getInstance().getConnection();
- final String sql = "SELECT " + "EXPORT_ID, " + "FILE_NAME, " + "EXPORT_NAME, " + "DOC_ID, " + "ETAT_ID, " + "ELEMENT_ID, " + "CONFIG_ID, " + "EXPORT_SIZE, " + "PRIORITY, " + "EXPORT_STATUS, " + "SUBMIT_DATE, " + "RUN_DATE, " + "DOWNLOAD_DATE, " + "ERROR_MESSAGE, "
- + "GENERATED_FILE_NAME, " + "CLEANED, " + "DRS, " + "UTI_LOGIN " + "FROM EXPORT_JOBS " + "WHERE EXPORT_ID=? " + "AND UTI_LOGIN=?";
+ final String sql = "SELECT " + "EXPORT_ID, " + "FILE_NAME, " + "EXPORT_NAME, " + "DOC_ID, " + "ETAT_ID, " + "ELEMENT_ID, " + "CONFIG_ID, " + "EXPORT_SIZE, " + "PRIORITY, " + "EXPORT_STATUS, " + "SUBMIT_DATE, " + "RUN_DATE, "
+ + "DOWNLOAD_DATE, " + "ERROR_MESSAGE, " + "GENERATED_FILE_NAME, " + "CLEANED, " + "DRS, " + "UTI_LOGIN " + "FROM EXPORT_JOBS " + "WHERE EXPORT_ID=? " + "AND UTI_LOGIN=?";
final PreparedStatement ps = con.prepareStatement(sql);
ps.setLong(1, exportId);
ps.setString(2, user);
}
@Override
- public String getInitialDocNameFromDocId(final EtatModel em, final String collectivite, final String budget, final String docId, final Connection con, final XemeliosUser user) throws DataConfigurationException, SQLException, UnauthorizedException {
+ public String getInitialDocNameFromDocId(final EtatModel em, final String collectivite, final String budget, final String docId, final Connection con, final XemeliosUser user) throws DataConfigurationException, SQLException,
+ UnauthorizedException {
if (!user.hasRole(XemeliosUser.ROLE_SEARCH)) {
throw new UnauthorizedException("Vous n'êtes pas autorisé à faire des recherches");
}
}
}
- private static String[] splitConditions(final String cond) throws DataConfigurationException {
- final ArrayList<String> ret = new ArrayList<String>();
- String s = cond;
- while ((s.length() > 0) && (s.charAt(0) == '[')) {
- final int end = OracleDataLayer.findClosingParenthesis(s, 0, "[]");
- ret.add(s.substring(0, end + 1));
- s = s.substring(end + 1);
- }
- final String aRet[] = new String[ret.size()];
- ret.toArray(aRet);
- return aRet;
- }
-
protected String buildSelectToExport(final int whatToExport, final ElementModel elementModel, final Pair coll, final Pair budg, final String fic, final Pair sk1, final Pair sk2, final XemeliosUser user) throws DataConfigurationException {
final EtatModel etatModel = elementModel.getParent();
final DocumentModel documentModel = etatModel.getParent();
return this.messages;
}
- /**
- * This method searches for the closing parenthesis that matches the specified one. <br>
- * <b>Warning :</b> it assumes that the character pointed out by <code>first</code> <b>is actually</b> an openning parenthesis.
- *
- * @param expr
- * The expression to search through.
- * @param first
- * Index of the openning parenthesis
- * @return Index of the closing parenthesis, if found.
- * @throws ParsingException
- * if no closing parenthesis were found.
- */
- private static int findClosingParenthesis(final String expr, final int first, final String delimitors) throws DataConfigurationException {
- final char OPENNING_DELIM = delimitors.charAt(0);
- final char CLOSING_DELIM = delimitors.charAt(1);
- final int len = expr.length();
- int close = -1;
- int pCount = 1;
- for (int i = (first + 1); i < len; i++) {
- final char c = expr.charAt(i);
- if (c == OPENNING_DELIM) {
- pCount++;
- } else if (c == CLOSING_DELIM) {
- pCount--;
- }
- if (pCount == 0) {
- close = i;
- break;
- }
- }
- if (close == (-1)) {
- throw new DataConfigurationException("unbalanced delimitor");
- }
- return close;
- }
-
/**
* Cette méthode est publique pour des raisons d'implémentation. Elle vérifie l'existence des tables d'un état
*
private TDocument pc = null;
private Stack<QName> stack = null;
private String key1 = null, key2 = null, key3 = null, key4 = null, key5 = null, key6 = null, key7 = null, key8 = null, key9 = null, key10 = null;
- private String pathToResetKey1 = null, pathToResetKey2 = null, pathToResetKey3 = null, pathToResetKey4 = null, pathToResetKey5 = null, pathToResetKey6 = null, pathToResetKey7 = null, pathToResetKey8 = null, pathToResetKey9 = null, pathToResetKey10 = null;
+ private String pathToResetKey1 = null, pathToResetKey2 = null, pathToResetKey3 = null, pathToResetKey4 = null, pathToResetKey5 = null, pathToResetKey6 = null, pathToResetKey7 = null, pathToResetKey8 = null, pathToResetKey9 = null,
+ pathToResetKey10 = null;
private String collectivite = null, budget = null, docId = null;
private SQLException sqlEx = null;
private long indexDuration = 0L;
this.pathToResetKey10 = null;
}
- public IndexerHandler(final TEtat sec, final String codeBudget, final String codeCollectivite, final String elementName, final Connection con, final NamespaceContext nsCtx, final String originFileName, final String archiveName) throws SQLException {
+ public IndexerHandler(final TEtat sec, final String codeBudget, final String codeCollectivite, final String elementName, final Connection con, final NamespaceContext nsCtx, final String originFileName, final String archiveName)
+ throws SQLException {
super();
this.sec = sec;
this.pc = sec.getParent();
}
//
final StringBuilder sql = new StringBuilder();
- sql.append("INSERT INTO ").append(elementTable.getBaseName()).append(" (" + this.pc.getCollectiviteCodeColname() + "," + this.pc.getBudgetCodeColname() + ",DOC_ID," + this.pc.getInitialDocNameColname() + ", " + this.pc.getArchiveNameColname() + ",");
+ sql.append("INSERT INTO ").append(elementTable.getBaseName())
+ .append(" (" + this.pc.getCollectiviteCodeColname() + "," + this.pc.getBudgetCodeColname() + ",DOC_ID," + this.pc.getInitialDocNameColname() + ", " + this.pc.getArchiveNameColname() + ",");
final Vector<Object> valuesToWrite = new Vector<Object>();
final Vector<TSqlIndex> indexesToWrite = new Vector<TSqlIndex>();
for (final Enumeration<TSqlIndex> enumer = this.cachedData.keys(); enumer.hasMoreElements();) {
}
final StringBuilder sql = new StringBuilder();
- sql.append("INSERT INTO ").append(elementTable.getBaseName()).append(" (" + this.pc.getCollectiviteCodeColname() + "," + this.pc.getBudgetCodeColname() + ",DOC_ID," + this.pc.getInitialDocNameColname() + "," + this.pc.getArchiveNameColname() + ",");
+ sql.append("INSERT INTO ").append(elementTable.getBaseName())
+ .append(" (" + this.pc.getCollectiviteCodeColname() + "," + this.pc.getBudgetCodeColname() + ",DOC_ID," + this.pc.getInitialDocNameColname() + "," + this.pc.getArchiveNameColname() + ",");
final Vector<Object> valuesToWrite = new Vector<Object>();
final Vector<TSqlIndex> indexesToWrite = new Vector<TSqlIndex>();
for (final Enumeration<TSqlIndex> enumer = this.cachedData.keys(); enumer.hasMoreElements();) {