r822 - in trunk: echobase-domain/src/main/java/fr/ifremer/echobase/entities echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/internalDb echobase-domain/src/main/resources/META-INF/services echobase-domain/src/main/xmi echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery echobase-ui echobase-ui/src/main/java/fr/ifremer/echobase/ui
Author: tchemit Date: 2013-07-15 10:32:35 +0200 (Mon, 15 Jul 2013) New Revision: 822 Url: http://forge.codelutin.com/projects/echobase/repository/revisions/822 Log: fixes #2875: Normalisation du nom des requ?\195?\168tes Added: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/ExportQueries.java trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/internalDb/MigrationCallBackForVersion2_2.java Modified: trunk/echobase-domain/src/main/resources/META-INF/services/fr.ifremer.echobase.persistence.migration.internalDb.MigrationCallBackForVersion trunk/echobase-domain/src/main/xmi/echobase-internal.properties trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryService.java trunk/echobase-ui/deploy.sh trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseInternalDbTransactionFilter.java Added: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/ExportQueries.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/ExportQueries.java (rev 0) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/ExportQueries.java 2013-07-15 08:32:35 UTC (rev 822) @@ -0,0 +1,41 @@ +package fr.ifremer.echobase.entities; + +/* + * #%L + * EchoBase :: Domain + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2013 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import java.util.regex.Pattern; + +/** + * Useful methods aroud {@link ExportQuery}. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.2 + */ +public class ExportQueries { + + protected static final Pattern NAME_PATTERN = Pattern.compile("[\\d\\w_-]+"); + + public static boolean isQueryNameValid(String queryName) { + return NAME_PATTERN.matcher(queryName).matches(); + } +} Property changes on: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/ExportQueries.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/internalDb/MigrationCallBackForVersion2_2.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/internalDb/MigrationCallBackForVersion2_2.java (rev 0) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/internalDb/MigrationCallBackForVersion2_2.java 2013-07-15 08:32:35 UTC (rev 822) @@ -0,0 +1,111 @@ +package fr.ifremer.echobase.persistence.migration.internalDb; + +/* + * #%L + * EchoBase :: Domain + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2013 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.echobase.entities.ExportQueries; +import fr.ifremer.echobase.entities.ExportQuery; +import fr.ifremer.echobase.entities.ExportQueryImpl; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaSQLQuery; +import org.nuiton.util.Version; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since TODO + */ +public class MigrationCallBackForVersion2_2 extends MigrationCallBackForVersion { + @Override + public Version getVersion() { + return new Version("2.2"); + } + + public static final String EXPORT_QUERY_UPDATE = + "UPDATE exportquery SET name = '%s', topiaversion = topiaversion + 1 WHERE topiaid = '%s'"; + + @Override + protected void prepareMigrationScript(TopiaContextImplementor tx, + List<String> queries, + boolean showSql, + boolean showProgression) throws TopiaException { + // normalize queries names + normalizeExportQueryNames(tx, queries); + } + + protected void normalizeExportQueryNames(TopiaContextImplementor tx, List<String> queries) { + + TopiaSQLQuery<ExportQuery> query = new TopiaSQLQuery<ExportQuery>() { + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + PreparedStatement result = connection.prepareStatement("select topiaid, name from exportquery;"); + return result; + } + + @Override + protected ExportQuery prepareResult(ResultSet set) throws SQLException { + ExportQuery result = new ExportQueryImpl(); + result.setTopiaId(set.getString(1)); + result.setName(set.getString(2)); + return result; + } + }; + + List<ExportQuery> exportQueries = query.findMultipleResult(tx); + + for (ExportQuery exportQuery : exportQueries) { + String queryName = exportQuery.getName(); + if (!ExportQueries.isQueryNameValid(queryName)) { + + // rename query (replace all none acceptable caracters by *_*) + StringBuilder nameBuilder = new StringBuilder(); + boolean nameHasChanged = false; + for (char c : queryName.toCharArray()) { + if (ExportQueries.isQueryNameValid(String.valueOf(c))) { + nameBuilder.append(c); + } else { + nameBuilder.append('_'); + nameHasChanged = true; + } + } + if (nameHasChanged) { + + // resave with normalized name + String newQueryName = nameBuilder.toString(); + + queries.add(String.format(EXPORT_QUERY_UPDATE, newQueryName, exportQuery.getTopiaId())); + } + } + } + } + + +} Property changes on: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/internalDb/MigrationCallBackForVersion2_2.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-domain/src/main/resources/META-INF/services/fr.ifremer.echobase.persistence.migration.internalDb.MigrationCallBackForVersion =================================================================== --- trunk/echobase-domain/src/main/resources/META-INF/services/fr.ifremer.echobase.persistence.migration.internalDb.MigrationCallBackForVersion 2013-07-15 08:32:13 UTC (rev 821) +++ trunk/echobase-domain/src/main/resources/META-INF/services/fr.ifremer.echobase.persistence.migration.internalDb.MigrationCallBackForVersion 2013-07-15 08:32:35 UTC (rev 822) @@ -0,0 +1 @@ +fr.ifremer.echobase.persistence.migration.internalDb.MigrationCallBackForVersion2_2 \ No newline at end of file Modified: trunk/echobase-domain/src/main/xmi/echobase-internal.properties =================================================================== --- trunk/echobase-domain/src/main/xmi/echobase-internal.properties 2013-07-15 08:32:13 UTC (rev 821) +++ trunk/echobase-domain/src/main/xmi/echobase-internal.properties 2013-07-15 08:32:35 UTC (rev 822) @@ -25,7 +25,7 @@ model.tagValue.generateOperatorForDAOHelper=true model.tagValue.generateStandaloneEnumForDAOHelper=true model.tagValue.constantPrefix=PROPERTY_ -model.tagValue.version=1.3 +model.tagValue.version=2.2 model.tagValue.noPCS=true model.tagValue.doNotGenerateBooleanGetMethods=true model.tagValue.indexForeignKeys=true Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryService.java 2013-07-15 08:32:13 UTC (rev 821) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryService.java 2013-07-15 08:32:35 UTC (rev 822) @@ -26,6 +26,7 @@ import com.google.common.base.Charsets; import fr.ifremer.echobase.EchoBaseTechnicalException; import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.entities.ExportQueries; import fr.ifremer.echobase.entities.ExportQuery; import fr.ifremer.echobase.entities.ExportQueryDAO; import fr.ifremer.echobase.services.EchoBaseServiceSupport; @@ -37,7 +38,6 @@ import java.util.List; import java.util.Map; -import java.util.regex.Pattern; /** * Service to deal with sql export. @@ -63,7 +63,6 @@ return entityToSave; } - protected static final Pattern NAME_PATTERN = Pattern.compile("[\\d\\w_-]+"); public ExportQuery createOrUpdate(ExportQuery exportQuery, EchoBaseUser user) throws ExportQueryNameAlreadyExistException, ExportQueryInvalidNameException { @@ -78,7 +77,7 @@ String queryName = exportQuery.getName(); - if (!NAME_PATTERN.matcher(queryName).matches()) { + if (!ExportQueries.isQueryNameValid(queryName)) { // can not accept a non alpha numeric name throw new ExportQueryInvalidNameException(); Property changes on: trunk/echobase-ui/deploy.sh ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseInternalDbTransactionFilter.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseInternalDbTransactionFilter.java 2013-07-15 08:32:13 UTC (rev 821) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseInternalDbTransactionFilter.java 2013-07-15 08:32:35 UTC (rev 822) @@ -24,7 +24,6 @@ package fr.ifremer.echobase.ui; import com.opensymphony.xwork2.ActionContext; -import fr.ifremer.echobase.persistence.EchoBaseEntityHelper; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -54,7 +53,7 @@ } @Override - protected synchronized TopiaContext beginTransaction(ServletRequest request) { + protected /*synchronized*/ TopiaContext beginTransaction(ServletRequest request) { EchoBaseApplicationContext applicationContext = EchoBaseActionSupport.getEchoBaseApplicationContext(); @@ -66,18 +65,18 @@ return transaction; } - /** - * Hook method to close the topia transaction of the request at the end of - * the request when all filter has been consumed. - * - * @param transaction the transaction to close (can be null if transaction - * was not required while the current request) - * @since 1.0 - */ - protected void onCloseTransaction(TopiaContext transaction) { - //FIXME Check if this necessary any longer ? - EchoBaseEntityHelper.closeConnection(transaction); - } +// /** +// * Hook method to close the topia transaction of the request at the end of +// * the request when all filter has been consumed. +// * +// * @param transaction the transaction to close (can be null if transaction +// * was not required while the current request) +// * @since 1.0 +// */ +// protected void onCloseTransaction(TopiaContext transaction) { +// //FIXME Check if this necessary any longer ? +// EchoBaseEntityHelper.closeConnection(transaction); +// } // public static void closeConnection(TopiaContext transaction) { // if (transaction == null) {
participants (1)
-
tchemit@users.forge.codelutin.com