Author: tchemit Date: 2012-06-01 11:42:49 +0200 (Fri, 01 Jun 2012) New Revision: 3408 Url: http://chorem.org/repositories/revision/pollen/3408 Log: using topia 2.6.11 (use new migration mode) fixes #574: Mauvais d?\195?\169pouillement Vote Condorcet fixes #576: Impossible de modifier un vote condorcet pour revenir ?\195?\160 "null" Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java trunk/pollen-persistence/src/main/resources/META-INF/services/org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG$MigrationCallBackForVersion Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallback.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_1.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_3.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_3_1.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java trunk/pom.xml Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallback.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallback.java 2012-05-28 17:06:39 UTC (rev 3407) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallback.java 2012-06-01 09:42:49 UTC (rev 3408) @@ -24,7 +24,7 @@ package org.chorem.pollen.entities.migration; import org.chorem.pollen.entities.PollenDAOHelper; -import org.nuiton.topia.migration.TopiaMigrationCallbackByClass; +import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG; import org.nuiton.util.Version; import org.nuiton.util.VersionUtil; @@ -36,29 +36,31 @@ * @author tchemit <chemit@codelutin.com> * @since 1.3 */ -public class PollenMigrationCallback extends TopiaMigrationCallbackByClass { +public class PollenMigrationCallback extends TopiaMigrationCallbackByClassNG { - public static final Version V_1_1 = VersionUtil.valueOf("1.1"); +// public static final Version V_1_1 = VersionUtil.valueOf("1.1"); +// +// public static final Version V_1_2 = VersionUtil.valueOf("1.2"); +// +// public static final Version V_1_3 = VersionUtil.valueOf("1.3"); +// +// public static final Version V_1_3_1 = VersionUtil.valueOf("1.3.1"); +// +// public static final Version V_1_4 = VersionUtil.valueOf("1.4"); - public static final Version V_1_2 = VersionUtil.valueOf("1.2"); +// /** Les versions de mise à jour disponibles. */ +// public static final Version[] AVAILABLE_VERSIONS = new Version[]{ +// V_1_1, V_1_2, V_1_3, V_1_3_1, V_1_4 +// }; - public static final Version V_1_3 = VersionUtil.valueOf("1.3"); - - public static final Version V_1_3_1 = VersionUtil.valueOf("1.3.1"); - - /** Les versions de mise à jour disponibles. */ - public static final Version[] AVAILABLE_VERSIONS = new Version[]{ - V_1_1, V_1_2, V_1_3, V_1_3_1 - }; - public PollenMigrationCallback() { - super(new PollenMigrationCallBackForVersionResolver()); + super(new MigrationCallBackForVersionResolverByServiceLoader()); } - @Override - public Version[] getAvailableVersions() { - return AVAILABLE_VERSIONS; - } +// @Override +// public Version[] getAvailableVersions() { +// return AVAILABLE_VERSIONS; +// } @Override public Version getApplicationVersion() { @@ -70,26 +72,26 @@ return true; } - /** - * Migration resolver for each version. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0.1 - */ - public static class PollenMigrationCallBackForVersionResolver implements MigrationCallBackForVersionResolver { - - @Override - public Class<? extends MigrationCallBackForVersion> getCallBack(Version version) { - - String fqn = PollenMigrationCallback.class.getName() + "V" + version.getValidName(); - Class<?> klass; - try { - klass = Class.forName(fqn); - } catch (ClassNotFoundException e) { - throw new IllegalStateException( - "Could not find migration class " + fqn, e); - } - return (Class<? extends MigrationCallBackForVersion>) klass; - } - } +// /** +// * Migration resolver for each version. +// * +// * @author tchemit <chemit@codelutin.com> +// * @since 1.0.1 +// */ +// public static class PollenMigrationCallBackForVersionResolver implements MigrationCallBackForVersionResolver { +// +// @Override +// public Class<? extends MigrationCallBackForVersion> getCallBack(Version version) { +// +// String fqn = PollenMigrationCallback.class.getName() + "V" + version.getValidName(); +// Class<?> klass; +// try { +// klass = Class.forName(fqn); +// } catch (ClassNotFoundException e) { +// throw new IllegalStateException( +// "Could not find migration class " + fqn, e); +// } +// return (Class<? extends MigrationCallBackForVersion>) klass; +// } +// } } Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_1.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_1.java 2012-05-28 17:06:39 UTC (rev 3407) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_1.java 2012-06-01 09:42:49 UTC (rev 3408) @@ -28,7 +28,9 @@ import org.hibernate.dialect.PostgreSQLDialect; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.migration.TopiaMigrationCallbackByClass; +import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG; +import org.nuiton.util.Version; +import org.nuiton.util.VersionUtil; import java.util.Arrays; import java.util.List; @@ -39,10 +41,11 @@ * @author tchemit <chemit@codelutin.com> * @since 1.3 */ -public class PollenMigrationCallbackV1_1 extends TopiaMigrationCallbackByClass.MigrationCallBackForVersion { +public class PollenMigrationCallbackV1_1 extends TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion { - public PollenMigrationCallbackV1_1(TopiaMigrationCallbackByClass callBack) { - super(PollenMigrationCallback.V_1_1, callBack); + @Override + public Version getVersion() { + return VersionUtil.valueOf("1.1"); } @Override Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2.java 2012-05-28 17:06:39 UTC (rev 3407) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2.java 2012-06-01 09:42:49 UTC (rev 3408) @@ -28,7 +28,9 @@ import org.hibernate.dialect.PostgreSQLDialect; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.migration.TopiaMigrationCallbackByClass; +import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG; +import org.nuiton.util.Version; +import org.nuiton.util.VersionUtil; import java.util.Arrays; import java.util.List; @@ -39,10 +41,11 @@ * @author tchemit <chemit@codelutin.com> * @since 1.3 */ -public class PollenMigrationCallbackV1_2 extends TopiaMigrationCallbackByClass.MigrationCallBackForVersion { +public class PollenMigrationCallbackV1_2 extends TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion { - public PollenMigrationCallbackV1_2(TopiaMigrationCallbackByClass callBack) { - super(PollenMigrationCallback.V_1_2, callBack); + @Override + public Version getVersion() { + return VersionUtil.valueOf("1.2"); } @Override Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_3.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_3.java 2012-05-28 17:06:39 UTC (rev 3407) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_3.java 2012-06-01 09:42:49 UTC (rev 3408) @@ -33,7 +33,9 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.topia.framework.TopiaSQLQuery; -import org.nuiton.topia.migration.TopiaMigrationCallbackByClass; +import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG; +import org.nuiton.util.Version; +import org.nuiton.util.VersionUtil; import java.sql.Connection; import java.sql.PreparedStatement; @@ -48,10 +50,11 @@ * @author tchemit <chemit@codelutin.com> * @since 1.3 */ -public class PollenMigrationCallbackV1_3 extends TopiaMigrationCallbackByClass.MigrationCallBackForVersion { +public class PollenMigrationCallbackV1_3 extends TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion { - public PollenMigrationCallbackV1_3(TopiaMigrationCallbackByClass callBack) { - super(PollenMigrationCallback.V_1_3, callBack); + @Override + public Version getVersion() { + return VersionUtil.valueOf("1.3"); } @Override @@ -60,14 +63,6 @@ boolean showSql, boolean showProgression) throws TopiaException { -// Dialect dialect = -// Dialect.getDialect(tx.getHibernateConfiguration().getProperties()); -// -// if (dialect instanceof PostgreSQLDialect) { -// -// } else if (dialect instanceof H2Dialect) { -// } - // change choice type to use enumeration migrateChoiceTypes(tx, queries); @@ -86,11 +81,11 @@ // add author column for Comment addCommentAuthorColumn(queries); } - + private void addCommentAuthorColumn(List<String> queries) { queries.add("ALTER TABLE comment ADD COLUMN author VARCHAR(255);"); - + queries.add("UPDATE comment AS c SET author = (SELECT p.votingId FROM pollAccount p WHERE c.pollAccount = p.topiaId);"); queries.add("ALTER TABLE comment ALTER COLUMN author TYPE VARCHAR(255);"); Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_3_1.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_3_1.java 2012-05-28 17:06:39 UTC (rev 3407) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_3_1.java 2012-06-01 09:42:49 UTC (rev 3408) @@ -26,7 +26,9 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.topia.framework.TopiaSQLQuery; -import org.nuiton.topia.migration.TopiaMigrationCallbackByClass; +import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG; +import org.nuiton.util.Version; +import org.nuiton.util.VersionUtil; import java.sql.Connection; import java.sql.PreparedStatement; @@ -40,10 +42,11 @@ * @author tchemit <chemit@codelutin.com> * @since 1.3.1 */ -public class PollenMigrationCallbackV1_3_1 extends TopiaMigrationCallbackByClass.MigrationCallBackForVersion { +public class PollenMigrationCallbackV1_3_1 extends TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion { - public PollenMigrationCallbackV1_3_1(TopiaMigrationCallbackByClass callBack) { - super(PollenMigrationCallback.V_1_3_1, callBack); + @Override + public Version getVersion() { + return VersionUtil.valueOf("1.3.1"); } @Override Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java 2012-06-01 09:42:49 UTC (rev 3408) @@ -0,0 +1,125 @@ +/* + * #%L + * Pollen :: Persistence + * + * $Id: PollenMigrationCallbackV1_3_1.java 3407 2012-05-28 17:06:39Z tchemit $ + * $HeadURL: http://svn.chorem.org/svn/pollen/trunk/pollen-persistence/src/main/java/org/... $ + * %% + * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit + * %% + * 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% + */ +package org.chorem.pollen.entities.migration; + +import org.chorem.pollen.business.persistence.VoteToChoice; +import org.chorem.pollen.business.persistence.VoteToChoiceImpl; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaSQLQuery; +import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG; +import org.nuiton.util.Version; +import org.nuiton.util.VersionUtil; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +/** + * Migration for version {@code 1.4}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class PollenMigrationCallbackV1_4 extends TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion { + + @Override + public Version getVersion() { + return VersionUtil.valueOf("1.4"); + } + + @Override + protected void prepareMigrationScript(TopiaContextImplementor tx, + List<String> queries, + boolean showSql, + boolean showProgression) throws TopiaException { + + // remove all votes of condorcet type with a null value (<=0) + // see http://chorem.org/issues/574 + // see http://chorem.org/issues/576 + removeAllCondorcetNullVotes(tx, queries); + } + + private void removeAllCondorcetNullVotes(TopiaContextImplementor tx, + List<String> queries) throws TopiaException { + + // get all votes from all polls with votecountingtype = 2 (condorcet) + + TopiaSQLQuery<String> getAllVotesQuery = new TopiaSQLQuery<String>() { + + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + PreparedStatement ps = connection.prepareStatement("select topiaid from vote where vote in (select topiaid from poll where votecountingtype=2);"); + return ps; + } + + @Override + protected String prepareResult(ResultSet set) throws SQLException { + return set.getString(1); + } + }; + List<String> voteIds = getAllVotesQuery.findMultipleResult(tx); + + for (String voteId : voteIds) { + + // get voteToChoice for this vote + VoteToChoice voteToChoice = + new GetVoteToChoiceSQLQuery(voteId).findSingleResult(tx); + + if (voteToChoice.getVoteValue() <= 0) { + + // delete this vote + + queries.add("DELETE FROM votetochoice where topiaid ='" + voteToChoice.getTopiaId() + "';"); + } + } + } + + private static class GetVoteToChoiceSQLQuery extends TopiaSQLQuery<VoteToChoice> { + + private final String voteId; + + public GetVoteToChoiceSQLQuery(String voteId) { + this.voteId = voteId; + } + + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + PreparedStatement ps = connection.prepareStatement( + "SELECT topiaid, votevalue FROM votetochoice WHERE vote = ?;"); + ps.setString(1, voteId); + return ps; + } + + @Override + protected VoteToChoice prepareResult(ResultSet set) throws SQLException { + VoteToChoice result = new VoteToChoiceImpl(); + result.setTopiaId(set.getString(1)); + result.setVoteValue(set.getInt(2)); + return result; + } + } +} Added: trunk/pollen-persistence/src/main/resources/META-INF/services/org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG$MigrationCallBackForVersion =================================================================== --- trunk/pollen-persistence/src/main/resources/META-INF/services/org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG$MigrationCallBackForVersion (rev 0) +++ trunk/pollen-persistence/src/main/resources/META-INF/services/org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG$MigrationCallBackForVersion 2012-06-01 09:42:49 UTC (rev 3408) @@ -0,0 +1,5 @@ +org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_1 +org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_2 +org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_3 +org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_3_1 +org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_4 \ No newline at end of file Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-05-28 17:06:39 UTC (rev 3407) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-06-01 09:42:49 UTC (rev 3408) @@ -34,6 +34,7 @@ import org.chorem.pollen.business.persistence.Vote; import org.chorem.pollen.business.persistence.VoteToChoice; import org.chorem.pollen.common.PollType; +import org.chorem.pollen.common.VoteCountingType; /** * Votes to a poll. @@ -81,14 +82,27 @@ } } - int nbVotes = 0; int totalValues = 0; for (VoteToChoice voteToChoice : vote.getChoiceVoteToChoice()) { Integer value = voteToChoice.getVoteValue(); + if (value == null) { + // not vote + continue; + } // XXX-fdesbois-2012-04-11 : for a VoteCountingType#NUMBER the difference between 0 and null value could be important - if (value != null && value != 0) { + if (isCondorcetVoteCounting()) { + if (value > 0) { + + // for condorcet vote, must be strictly greater than 0 + // see http://chorem.org/issues/574 + // see http://chorem.org/issues/576 + nbVotes++; + totalValues += value; + } + // for other vote type, value must be > 0 + } else if (value != 0) { nbVotes++; totalValues += value; } Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-05-28 17:06:39 UTC (rev 3407) +++ trunk/pom.xml 2012-06-01 09:42:49 UTC (rev 3408) @@ -176,7 +176,7 @@ <projectId>pollen</projectId> <!-- customized versions --> - <topiaVersion>2.6.10</topiaVersion> + <topiaVersion>2.6.11-SNAPSHOT</topiaVersion> <eugenePluginVersion>2.4.2</eugenePluginVersion> <nuitonI18nVersion>2.4.1</nuitonI18nVersion>