Author: fdesbois Date: 2010-02-23 19:20:55 +0100 (Tue, 23 Feb 2010) New Revision: 2879 Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/ConverterHelper.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollAccountConverter.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/migration/PollenMigrationCallbackHandler.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java trunk/pollen-business/src/main/resources/oldmappings/pollen/1.3/org/chorem/pollen/business/persistence/PollAccountImpl.hbm.xml trunk/pollen-business/src/main/resources/oldmappings/pollen/1.3/org/chorem/pollen/business/persistence/PollImpl.hbm.xml trunk/pollen-business/src/main/xmi/pollen.properties trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java trunk/pom.xml Log: - Use naturalId for pollId and accountId (last topia snapshot needed) - improve saves - resolve issue on migration 1.3 for h2 Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/ConverterHelper.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/ConverterHelper.java 2010-02-23 15:12:23 UTC (rev 2878) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/ConverterHelper.java 2010-02-23 18:20:55 UTC (rev 2879) @@ -54,7 +54,6 @@ public static void preparePollConverters() { String[] properties = new String[] { - Poll.POLL_ID, Poll.TITLE, Poll.DESCRIPTION, Poll.BEGIN_CHOICE_DATE, @@ -94,7 +93,6 @@ public static void preparePollAccountConverters() { String[] properties = new String[] { - PollAccount.ACCOUNT_ID, PollAccount.VOTING_ID, PollAccount.EMAIL }; @@ -137,6 +135,7 @@ public static PollDTO convert(Poll entity, PollDTO dto) { BinderProvider.getBinder(Poll.class, PollDTO.class).copy(entity, dto); dto.setId(entity.getTopiaId()); + dto.setPollId(entity.getPollId()); dto.setChoiceType(ChoiceType.valueOf(entity.getChoiceType())); dto.setPollType(PollType.valueOf(entity.getPollType())); dto.setVoteCounting(VoteCountingType.valueOf(entity.getVoteCounting())); @@ -162,6 +161,7 @@ public static PollAccountDTO convert(PollAccount entity, PollAccountDTO dto) { BinderProvider.getBinder(PollAccount.class, PollAccountDTO.class).copy(entity, dto); dto.setId(entity.getTopiaId()); + dto.setAccountId(entity.getAccountId()); return dto; } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollAccountConverter.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollAccountConverter.java 2010-02-23 15:12:23 UTC (rev 2878) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollAccountConverter.java 2010-02-23 18:20:55 UTC (rev 2879) @@ -47,7 +47,7 @@ */ public void populatePollAccountEntity(PollAccountDTO pollAccountDTO, PollAccount ePollAccount) throws TopiaException { - ePollAccount.setAccountId(pollAccountDTO.getAccountId()); + //ePollAccount.setAccountId(pollAccountDTO.getAccountId()); ePollAccount.setEmail(pollAccountDTO.getEmail()); ePollAccount.setVotingId(pollAccountDTO.getVotingId()); Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/migration/PollenMigrationCallbackHandler.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/migration/PollenMigrationCallbackHandler.java 2010-02-23 15:12:23 UTC (rev 2878) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/migration/PollenMigrationCallbackHandler.java 2010-02-23 18:20:55 UTC (rev 2879) @@ -197,25 +197,25 @@ // VoteCounting becomes a String field instead of a table "alter table poll add votecounting1 varchar;", "update poll as p set votecounting1 = (select v.name from votecounting v where v.topiaId = p.votecounting);", - "alter table poll drop column votecounting;", - "alter table poll alter column rename votecounting1 to votecounting;", "alter table result add votecounting1 varchar;", "update result as r set votecounting1 = (select v.name from votecounting v where v.topiaId = r.votecounting);", + "drop table votecounting;", + "alter table poll drop column votecounting;", + "alter table poll alter column votecounting1 rename to votecounting;", "alter table result drop column votecounting;", - "alter table result alter column rename votecounting1 to votecounting;", - "drop table votecounting;", + "alter table result alter column votecounting1 rename to votecounting;", // PollType becomes a String field instead of a table "alter table poll add polltype1 varchar;", "update poll as p set polltype1 = (select t.name from polltype t where t.topiaId = p.polltype);", + "drop table polltype;", "alter table poll drop column polltype;", - "alter table poll alter column rename polltype1 to polltype;", - "drop table polltype;", + "alter table poll alter column polltype1 rename to polltype;", // ChoiceType becomes a String field instead of a table "alter table poll add choicetype1 varchar;", "update poll as p set choicetype1 = (select t.name from choicetype t where t.topiaId = p.choicetype);", + "drop table choicetype;", "alter table poll drop column choicetype;", - "alter table poll alter column rename choicetype1 to choicetype;", - "drop table choicetype;" + "alter table poll alter column choicetype1 rename to choicetype;" }; } else { if (log.isErrorEnabled()) { Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java 2010-02-23 15:12:23 UTC (rev 2878) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java 2010-02-23 18:20:55 UTC (rev 2879) @@ -61,11 +61,10 @@ pollAccountDAO = PollenModelDAOHelper .getPollAccountDAO(transaction); - PollAccount pollAccountEntity = pollAccountDAO.create(); // Identifiant du compte - String id = UUID.randomUUID().toString(); - pollAccountDTO.setAccountId(id.replaceAll("-", "")); + String id = ContextUtil.createPollenUrlId(); + PollAccount pollAccountEntity = pollAccountDAO.create(id); converter.setTransaction(transaction); converter.populatePollAccountEntity(pollAccountDTO, @@ -97,11 +96,10 @@ pollAccountDAO = PollenModelDAOHelper .getPollAccountDAO(transaction); - pollAccountEntity = pollAccountDAO.create(); // Identifiant du compte - String id = UUID.randomUUID().toString(); - pollAccountEntity.setAccountId(id.replaceAll("-", "")); + String id = ContextUtil.createPollenUrlId(); + pollAccountEntity = pollAccountDAO.create(PollAccount.ACCOUNT_ID, id); converter.setTransaction(transaction); converter.populatePollAccountEntity(votingId, email, userId, Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-02-23 15:12:23 UTC (rev 2878) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-02-23 18:20:55 UTC (rev 2879) @@ -25,7 +25,6 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.PollenException; import org.chorem.pollen.business.converters.ConverterHelper; import org.chorem.pollen.business.converters.DataPollConverter; import org.chorem.pollen.business.dto.ChoiceDTO; @@ -35,7 +34,6 @@ import org.chorem.pollen.business.dto.VotingListDTO; import org.chorem.pollen.business.persistence.Choice; import org.chorem.pollen.business.persistence.ChoiceDAO; -import org.chorem.pollen.business.persistence.ChoiceImpl; import org.chorem.pollen.business.persistence.PersonToList; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollAccount; @@ -43,13 +41,13 @@ import org.chorem.pollen.business.persistence.PollDAO; import org.chorem.pollen.business.persistence.PollenModelDAOHelper; import org.chorem.pollen.business.persistence.PreventRule; -import org.chorem.pollen.business.persistence.PreventRuleImpl; +import org.chorem.pollen.business.persistence.PreventRuleDAO; import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.business.persistence.UserAccountDAO; import org.chorem.pollen.business.persistence.Vote; import org.chorem.pollen.business.persistence.VoteDAO; import org.chorem.pollen.business.persistence.VotingList; -import org.chorem.pollen.business.persistence.VotingListImpl; +import org.chorem.pollen.business.persistence.VotingListDAO; import org.chorem.pollen.business.utils.ContextUtil; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; @@ -85,20 +83,18 @@ pollDAO = PollenModelDAOHelper.getPollDAO(transaction); - Poll entity = ConverterHelper.convert(pollDTO, pollDAO.create()); - // ** Create new poll ID for urls - entity.setPollId(ContextUtil.createPollenUrlId()); + String pollId = ContextUtil.createPollenUrlId(); + Poll entity = ConverterHelper.convert(pollDTO, pollDAO.create(pollId)); // ** Creator managment PollAccount creator = prepareCreator(transaction, pollDTO); entity.setCreator(creator); // ** Create new choices + ChoiceDAO choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction); for (ChoiceDTO choiceDTO : pollDTO.getChoiceDTOs()) { - // Use new instance of Choice, the creation will be done by - // the poll entity Choice choice = - ConverterHelper.convert(choiceDTO, new ChoiceImpl()); + ConverterHelper.convert(choiceDTO, choiceDAO.create()); choice.setPoll(entity); } @@ -109,11 +105,10 @@ } // ** Create new preventRules + PreventRuleDAO ruleDAO = PollenModelDAOHelper.getPreventRuleDAO(transaction); for (PreventRuleDTO ruleDTO : pollDTO.getPreventRuleDTOs()) { - // Use new instance of PreventRule, the creation will be done by - // the poll entity PreventRule rule = - ConverterHelper.convert(ruleDTO, new PreventRuleImpl()); + ConverterHelper.convert(ruleDTO, ruleDAO.create()); rule.setPoll(entity); } @@ -168,6 +163,7 @@ } // Create new account if account properties changed or no user found if (creator == null) { + accountProperties.put(PollAccount.ACCOUNT_ID, ContextUtil.createPollenUrlId()); creator = accountDAO.create(accountProperties); } return creator; @@ -187,10 +183,9 @@ private static final VotingList createVotingList(TopiaContext transaction, VotingListDTO listDTO) throws TopiaException { - // Use new instance of VotingList, the creation will be done by - // the poll entity + VotingListDAO dao = PollenModelDAOHelper.getVotingListDAO(transaction); VotingList votingList = - ConverterHelper.convert(listDTO, new VotingListImpl()); + ConverterHelper.convert(listDTO, dao.create()); PollAccountDAO pollAccountDAO = PollenModelDAOHelper.getPollAccountDAO(transaction); @@ -202,8 +197,9 @@ // Create a new PollAccount if not already exists if (account == null) { - account = - ConverterHelper.convert(accountDTO, pollAccountDAO.create()); + String accountId = ContextUtil.createPollenUrlId(); + account = pollAccountDAO.create(accountId); + ConverterHelper.convert(accountDTO, account); } // Create association between VotingList and PollAccount Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2010-02-23 15:12:23 UTC (rev 2878) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2010-02-23 18:20:55 UTC (rev 2879) @@ -71,7 +71,7 @@ // .getId()); if (pollAccountEntity == null) { log.debug("Nouveau compte associé au vote"); - pollAccountEntity = pollAccountDAO.create(); + pollAccountEntity = pollAccountDAO.create(ContextUtil.createPollenUrlId()); // EVO #108 : Migration to ToPIA 2.3, the entity must be // commited because an other findBy is called in the // converter (wtf ?! :/). This behavior doesn't work Modified: trunk/pollen-business/src/main/resources/oldmappings/pollen/1.3/org/chorem/pollen/business/persistence/PollAccountImpl.hbm.xml =================================================================== --- trunk/pollen-business/src/main/resources/oldmappings/pollen/1.3/org/chorem/pollen/business/persistence/PollAccountImpl.hbm.xml 2010-02-23 15:12:23 UTC (rev 2878) +++ trunk/pollen-business/src/main/resources/oldmappings/pollen/1.3/org/chorem/pollen/business/persistence/PollAccountImpl.hbm.xml 2010-02-23 18:20:55 UTC (rev 2879) @@ -3,9 +3,11 @@ <hibernate-mapping default-access="field" auto-import="true" package="org.chorem.pollen.business.persistence"> <class name="org.chorem.pollen.business.persistence.PollAccountImpl" table="pollAccount" node="org.chorem.pollen.business.persistence.PollAccountImpl" abstract="false" proxy="org.chorem.pollen.business.persistence.PollAccount" > <id name="topiaId" type="string" length="255" node="@topiaId"/> + <natural-id> + <property name="accountId" type="text" access="field" column="accountId" node="accountId"/> + </natural-id> <version name="topiaVersion" type="long" node="@topiaVersion"/> <property name="topiaCreateDate" type="timestamp" node="@topiaCreateDate"/> - <property name="accountId" type="text" access="field" column="accountId" node="accountId"/> <property name="votingId" type="text" access="field" column="votingId" node="votingId"/> <property name="email" type="text" access="field" column="email" node="email"/> <bag name="votingListPersonToList" inverse="true" lazy="true" cascade="all,delete-orphan" node="votingListPersonToList" embed-xml="false"> Modified: trunk/pollen-business/src/main/resources/oldmappings/pollen/1.3/org/chorem/pollen/business/persistence/PollImpl.hbm.xml =================================================================== --- trunk/pollen-business/src/main/resources/oldmappings/pollen/1.3/org/chorem/pollen/business/persistence/PollImpl.hbm.xml 2010-02-23 15:12:23 UTC (rev 2878) +++ trunk/pollen-business/src/main/resources/oldmappings/pollen/1.3/org/chorem/pollen/business/persistence/PollImpl.hbm.xml 2010-02-23 18:20:55 UTC (rev 2879) @@ -3,9 +3,11 @@ <hibernate-mapping default-access="field" auto-import="true" package="org.chorem.pollen.business.persistence"> <class name="org.chorem.pollen.business.persistence.PollImpl" table="poll" node="org.chorem.pollen.business.persistence.PollImpl" abstract="false" proxy="org.chorem.pollen.business.persistence.Poll" > <id name="topiaId" type="string" length="255" node="@topiaId"/> + <natural-id> + <property name="pollId" type="text" access="field" column="pollId" node="pollId"/> + </natural-id> <version name="topiaVersion" type="long" node="@topiaVersion"/> <property name="topiaCreateDate" type="timestamp" node="@topiaCreateDate"/> - <property name="pollId" type="text" access="field" column="pollId" node="pollId"/> <property name="title" type="text" access="field" column="title" node="title"/> <property name="description" type="text" access="field" column="description" node="description"/> <property name="beginChoiceDate" type="java.util.Date" access="field" column="beginChoiceDate" node="beginChoiceDate"/> Modified: trunk/pollen-business/src/main/xmi/pollen.properties =================================================================== --- trunk/pollen-business/src/main/xmi/pollen.properties 2010-02-23 15:12:23 UTC (rev 2878) +++ trunk/pollen-business/src/main/xmi/pollen.properties 2010-02-23 18:20:55 UTC (rev 2879) @@ -1,4 +1,6 @@ # Pr\u00E9cise l'ent\u00EAte de l'ensemble des fichiers g\u00E9n\u00E9r\u00E9s model.tagvalue.copyright=/* *##%\n Copyright (C) 2009 Pollen\n *##%*/ #model.tagvalue.dbSchema=Pollen -model.tagvalue.java.lang.String=text \ No newline at end of file +model.tagvalue.java.lang.String=text +org.chorem.pollen.business.persistence.PollAccount.attribute.accountId.tagvalue.naturalId=true +org.chorem.pollen.business.persistence.Poll.attribute.pollId.tagvalue.naturalId=true \ No newline at end of file Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-02-23 15:12:23 UTC (rev 2878) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-02-23 18:20:55 UTC (rev 2879) @@ -16,6 +16,7 @@ package org.chorem.pollen.business.services; +import java.util.ArrayList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -24,10 +25,13 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.dto.ChoiceDTO; import org.chorem.pollen.business.dto.PollAccountDTO; import org.chorem.pollen.business.dto.PollDTO; import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.dto.VoteDTO; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.business.persistence.PollenModelDAOHelper; import org.chorem.pollen.business.utils.ContextUtil; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; @@ -40,7 +44,6 @@ import org.junit.Test; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; /** * Tests du service de gestion des sondages. @@ -78,9 +81,10 @@ /** * Test of createPoll method, of class ServicePollImpl. + * @throws Exception */ @Test - public void testCreatePoll() throws TopiaException { + public void testCreatePoll() throws Exception { log.info("### START ###"); PollDTO dto = new PollDTO(); dto.setBeginChoiceDate(new Date()); @@ -97,6 +101,20 @@ dto.setPollType(PollType.RESTRICTED); dto.setVoteCounting(VoteCountingType.NORMAL); dto.setTitle("Test_createPoll"); + + List<ChoiceDTO> choices = new ArrayList<ChoiceDTO>(); + ChoiceDTO choice1 = new ChoiceDTO(); + choice1.setName("choice1"); + choices.add(choice1); + ChoiceDTO choice2 = new ChoiceDTO(); + choice2.setName("choice2"); + choices.add(choice2); + ChoiceDTO choice3 = new ChoiceDTO(); + choice3.setName("choice3"); + choices.add(choice3); + + dto.setChoiceDTOs(choices); + String result = instance.createPoll(dto); if (log.isDebugEnabled()) { log.debug("result: " + result); @@ -107,12 +125,20 @@ try { transaction = ContextUtil.getInstance().getContext().beginTransaction(); - TopiaEntity entity = transaction.findByTopiaId(result); + Poll entity = PollenModelDAOHelper. + getPollDAO(transaction).findByTopiaId(result); Assert.assertNotNull(entity); - } catch (TopiaException eee) { + + Assert.assertEquals(3, entity.getChoice().size()); + Assert.assertNotNull(entity.getCreator()); + Assert.assertEquals("erwan", entity.getCreator().getVotingId()); + Assert.assertNotNull(entity.getCreator().getAccountId()); + + } catch (Exception eee) { if (transaction != null) { transaction.rollbackTransaction(); } + throw eee; } finally { if (transaction != null) { transaction.closeContext(); Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-02-23 15:12:23 UTC (rev 2878) +++ trunk/pom.xml 2010-02-23 18:20:55 UTC (rev 2879) @@ -299,7 +299,7 @@ <!-- customized versions --> <!--javadoc.version>2.4</javadoc.version--> - <topia.version>2.3.0-beta-8</topia.version> + <topia.version>2.3.0-beta-9-SNAPSHOT</topia.version> <eugene.version>2.0.0-beta-4</eugene.version> <tapestry.version>5.1.0.5</tapestry.version> <nuiton-utils.version>1.1.5-SNAPSHOT</nuiton-utils.version>