r3281 - in trunk: . pollen-services pollen-services/src/main/java/org/chorem/pollen/services pollen-services/src/main/java/org/chorem/pollen/services/exceptions pollen-services/src/main/java/org/chorem/pollen/services/impl pollen-services/src/main/resources/i18n pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user pollen-ui-struts2/src/main/resources/i18n pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user
Author: fdesbois Date: 2012-04-17 15:08:52 +0200 (Tue, 17 Apr 2012) New Revision: 3281 Url: http://chorem.org/repositories/revision/pollen/3281 Log: fixes #162 : use nuiton-csv to display row in error fixes #182 : add FavoriteListImport interface and implementations for CSV and LDAP Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/FavoriteListImport.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServicePredicates.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exceptions/FavoriteListImportException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteListImportCSV.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteListImportLDAP.java Modified: trunk/pollen-services/pom.xml trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java trunk/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties trunk/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteLists.java trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp trunk/pom.xml Modified: trunk/pollen-services/pom.xml =================================================================== --- trunk/pollen-services/pom.xml 2012-04-16 12:26:13 UTC (rev 3280) +++ trunk/pollen-services/pom.xml 2012-04-17 13:08:52 UTC (rev 3281) @@ -68,9 +68,14 @@ <artifactId>nuiton-utils</artifactId> </dependency> <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-csv</artifactId> + </dependency> + <dependency> <groupId>org.nuiton.i18n</groupId> <artifactId>nuiton-i18n</artifactId> </dependency> + <!-- used by SendEmail thread only --> <dependency> <groupId>net.sf.opencsv</groupId> <artifactId>opencsv</artifactId> Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/FavoriteListImport.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/FavoriteListImport.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/FavoriteListImport.java 2012-04-17 13:08:52 UTC (rev 3281) @@ -0,0 +1,35 @@ +package org.chorem.pollen.services; + +import org.chorem.pollen.business.persistence.PollAccount; +import org.chorem.pollen.services.exceptions.FavoriteListImportException; +import org.chorem.pollen.services.impl.FavoriteListImportCSV; +import org.chorem.pollen.services.impl.FavoriteListImportLDAP; + +import java.util.List; + +/** + * Used to import a favorite List or a List of {@link PollAccount} from a given + * source url (file, external service, ...) + * + * Created: 16/04/12 + * + * @author fdesbois <desbois@codelutin.com> + * @since 1.3 + * @see FavoriteListImportLDAP + * @see FavoriteListImportCSV + */ +public interface FavoriteListImport { + + /** + * Execute the import from given {@code url}. This will returned the + * successful list of {@link PollAccount} instanciated during import. No + * database save is done here, only the extraction from an input url to + * a list of entities to manage. + * + * @param url Url of the file or service that contains data to import + * @return the List of PollAccount imported + * @throws FavoriteListImportException for any import error + */ + public List<PollAccount> execute(String url) + throws FavoriteListImportException; +} Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServicePredicates.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServicePredicates.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServicePredicates.java 2012-04-17 13:08:52 UTC (rev 3281) @@ -0,0 +1,30 @@ +package org.chorem.pollen.services; + +import com.google.common.base.Predicate; +import org.apache.commons.lang3.StringUtils; +import org.chorem.pollen.business.persistence.PollAccount; + +/** + * Created: 16/04/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public final class PollenServicePredicates { + + private PollenServicePredicates() { + // never instanciate a class with static methods + } + + /** + * Check if the PollAccount is empty, i.e. has empty votingId or email. + */ + public static final Predicate<PollAccount> POLL_ACCOUNT_NOT_EMPTY = new Predicate<PollAccount>() { + + @Override + public boolean apply(PollAccount input) { + String votingId = input.getVotingId(); + String email = input.getEmail(); + return StringUtils.isNotBlank(votingId) && StringUtils.isNotBlank(email); + } + }; +} Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exceptions/FavoriteListImportException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exceptions/FavoriteListImportException.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exceptions/FavoriteListImportException.java 2012-04-17 13:08:52 UTC (rev 3281) @@ -0,0 +1,83 @@ +/* *##% Pollen + * Copyright (C) 2010 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. ##%*/ + +package org.chorem.pollen.services.exceptions; + +import org.chorem.pollen.services.FavoriteListImport; + +import java.util.Locale; + +import static org.nuiton.i18n.I18n._; +import static org.nuiton.i18n.I18n.l_; +import static org.nuiton.i18n.I18n.n_; + +/** + * Exception during {@link FavoriteListImport#execute(String)} error. There is + * always a cause from librairies used for import. + * + * @author fdesbois <desbois@codelutin.com> + */ +public class FavoriteListImportException extends Exception { + + private static final long serialVersionUID = 1L; + + private static final String I18N_KEY = n_("pollen.error.import"); + + private String importName; + + private String causeMessage; + + public FavoriteListImportException(String importName, String causeMessage, Throwable cause) { + super(_(I18N_KEY, importName, causeMessage), cause); + this.importName = importName; + this.causeMessage = causeMessage; + } + + public FavoriteListImportException(String importName, Throwable cause) { + this(importName, cause.getMessage(), cause); + } + + /** + * @return the name of import (CSV, LDAP, ...) + */ + public String getImportName() { + return importName; + } + + /** + * @return the error message source from import execution. + */ + public String getCauseMessage() { + return causeMessage; + } + + /** + * Get the message depends on {@code locale}. + * + * @param locale Locale to translate the message + * @return the localized message or default one if locale is null + */ + public String getLocalizedMessage(Locale locale) { + String result; + if (locale == null) { + result = getMessage(); + + } else { + result = l_(locale, I18N_KEY, getImportName(), getCauseMessage()); + } + return result; + } +} Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteListImportCSV.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteListImportCSV.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteListImportCSV.java 2012-04-17 13:08:52 UTC (rev 3281) @@ -0,0 +1,162 @@ +package org.chorem.pollen.services.impl; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.PollenTechnicalException; +import org.chorem.pollen.business.persistence.PollAccount; +import org.chorem.pollen.services.FavoriteListImport; +import org.chorem.pollen.services.PollenServicePredicates; +import org.chorem.pollen.services.PollenServiceSupport; +import org.chorem.pollen.services.exceptions.FavoriteListImportException; +import org.nuiton.util.StringUtil; +import org.nuiton.util.csv.Import; +import org.nuiton.util.csv.ImportModel; +import org.nuiton.util.csv.ImportRuntimeException; +import org.nuiton.util.csv.ImportableColumn; +import org.nuiton.util.csv.ModelBuilder; +import org.nuiton.util.csv.ValueParser; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.Reader; +import java.text.ParseException; +import java.util.List; + +import static org.nuiton.i18n.I18n._; + +/** + * Implementation of {@link FavoriteListImport} as a service for CSV import. + * Nuiton-CSV is used to manage the {@link Import} using a specific {@link + * ImportModel} for pollen. Empty rows (no votingId or no email) are ignored. + * + * Created: 16/04/12 + * + * @author fdesbois <desbois@codelutin.com> + * @since 1.3 + */ +public class FavoriteListImportCSV extends PollenServiceSupport implements FavoriteListImport { + + private static final Log log = LogFactory.getLog(FavoriteListImportCSV.class); + + private static final ValueParser<String> EMAIL_PARSER = new ValueParser<String>() { + + @Override + public String parse(String value) throws ParseException { + if (value != null && !StringUtil.isEmail(value)) { + throw new ParseException(_("pollen.error.email.invalid"), 0); + } + return value; + } + }; + + protected class FavoriteListImportModel implements ImportModel<PollAccount> { + + @Override + public char getSeparator() { + return ','; + } + + @Override + public void pushCsvHeaderNames(List<String> headerNames) { + } + + @Override + public PollAccount newEmptyInstance() { + return newInstance(getDAO(PollAccount.class)); + } + + @Override + public Iterable<ImportableColumn<PollAccount, Object>> getColumnsForImport() { + ModelBuilder modelBuilder = new ModelBuilder(); + modelBuilder.newMandatoryColumn(PollAccount.PROPERTY_VOTING_ID, + PollAccount.PROPERTY_VOTING_ID); + modelBuilder.newMandatoryColumn(PollAccount.PROPERTY_EMAIL, + PollAccount.PROPERTY_EMAIL, + EMAIL_PARSER); + return modelBuilder.getColumnsForImport(); + } + } + + @Override + public List<PollAccount> execute(String url) throws FavoriteListImportException { + + List<PollAccount> results; + Reader reader = null; + try { + reader = new FileReader(new File(url)); + + Import<PollAccount> csvImport = Import.newImport(new FavoriteListImportModel(), reader); + + // Filter on empty account (without email or votingId) + results = Lists.newArrayList( + Iterables.filter(csvImport, + PollenServicePredicates.POLL_ACCOUNT_NOT_EMPTY) + ); + + if (log.isInfoEnabled()) { + log.info(results.size() + " comptes importés."); + } + + } catch (FileNotFoundException ex) { + throw new PollenTechnicalException(ex); + + } catch (ImportRuntimeException ex) { + if (log.isDebugEnabled()) { + log.debug("Error during CSV import", ex); + } + throw new FavoriteListImportException("CSV", ex); + + } finally { + IOUtils.closeQuietly(reader); + } + return results; + } + +// @Override +// public List<PollAccount> execute(String url) throws FavoriteListImportException { +// +// List<PollAccount> results; +// Reader reader = null; +// try { +// reader = new FileReader(new File(url)); +// +// // Définition de la stratégie de mapping +// ColumnPositionMappingStrategy<PollAccountImpl> strat = +// new ColumnPositionMappingStrategy<PollAccountImpl>(); +// +// String[] columns = new String[] { +// PollAccount.PROPERTY_VOTING_ID, +// PollAccount.PROPERTY_EMAIL +// }; +// +// strat.setType(PollAccountImpl.class); +// strat.setColumnMapping(columns); +// +// // Parsing du fichier CSV +// CsvToBean<PollAccountImpl> csv = new CsvToBean<PollAccountImpl>(); +// List<PollAccount> importedData = Lists.<PollAccount>newArrayList(csv.parse(strat, reader)); +// +// // Suppression des comptes null +// results = Lists.newArrayList( +// Iterables.filter(importedData, +// PollenServicePredicates.POLL_ACCOUNT_NOT_EMPTY) +// ); +// +// if (log.isInfoEnabled()) { +// log.info(results.size() + " comptes importés."); +// } +// +// } catch (Exception ex) { +// log.warn("Error during CSV import", ex); +// throw new FavoriteListImportException(ex); +// +// } finally { +// IOUtils.closeQuietly(reader); +// } +// return results; +// } +} Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteListImportLDAP.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteListImportLDAP.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteListImportLDAP.java 2012-04-17 13:08:52 UTC (rev 3281) @@ -0,0 +1,99 @@ +package org.chorem.pollen.services.impl; + +import com.google.common.collect.Lists; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.persistence.PollAccount; +import org.chorem.pollen.business.persistence.PollAccountDAO; +import org.chorem.pollen.services.FavoriteListImport; +import org.chorem.pollen.services.PollenServiceSupport; +import org.chorem.pollen.services.exceptions.FavoriteListImportException; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.DirContext; +import javax.naming.directory.InitialDirContext; +import javax.naming.directory.SearchControls; +import javax.naming.directory.SearchResult; +import java.util.List; +import java.util.Properties; + +/** + * LDAP Import of {@link PollAccount}. The behavior is the same than the one + * from pollen 1.2.x + * + * TODO-fdesbois-2012-04-17 : tests and documentation + * + * Created: 16/04/12 + * + * @author fdesbois <desbois@codelutin.com> + * @since 1.3 + */ +public class FavoriteListImportLDAP extends PollenServiceSupport implements FavoriteListImport { + + private static final Log log = LogFactory.getLog(FavoriteListImportLDAP.class); + + @Override + public List<PollAccount> execute(String url) throws FavoriteListImportException { + + long start = System.nanoTime(); + + List<PollAccount> results = Lists.newArrayList(); + try { + + // Initialisation du contexte + Properties env = new Properties(); +// if (server != null) { +// env.put(Context.INITIAL_CONTEXT_FACTORY, +// "com.sun.jndi.ldap.LdapCtxFactory"); +// env.put(Context.PROVIDER_URL, "ldap://" + server + "/"); +// } + DirContext ictx = new InitialDirContext(env); + + // Recherche en profondeur + SearchControls control = new SearchControls(); + control.setSearchScope(SearchControls.SUBTREE_SCOPE); + + // Création des comptes avec les résultats de la recherche + NamingEnumeration<SearchResult> e = ictx.search(url, null, + control); + while (e.hasMore()) { + SearchResult r = e.next(); + + if (log.isDebugEnabled()) { + log.debug("Result: " + r.getName() + "(object: " + + r.getClassName() + ")"); + } + + Attribute nameAttr = r.getAttributes().get("cn"); + Attribute emailAttr = r.getAttributes().get("mail"); + + if (nameAttr != null) { + PollAccountDAO dao = getDAO(PollAccount.class); + PollAccount account = newInstance(dao); + account.setVotingId(nameAttr.get().toString()); + account.setEmail(emailAttr.get().toString()); + results.add(account); + + if (log.isDebugEnabled()) { + log.debug("New account - name: " + + nameAttr.get().toString() + ", email: " + + emailAttr.get().toString()); + } + } + } + } catch (NamingException ex) { + log.error("Exception de nommage lors de l'import depuis LDAP", ex); + throw new FavoriteListImportException("LDAP", ex); + } + + long duration = (System.nanoTime() - start) / 1000000000; + if (log.isInfoEnabled()) { + log.info(results.size() + " comptes importés en " + duration + + " sec."); + } + + return results; + } +} Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java 2012-04-16 12:26:13 UTC (rev 3280) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java 2012-04-17 13:08:52 UTC (rev 3281) @@ -124,8 +124,9 @@ } } - public void createFavoriteList(UserAccount user, - String name) throws FavoriteListAlreadyExistException, UserNotFoundException { + public PersonList createFavoriteList(UserAccount user, + String name) + throws FavoriteListAlreadyExistException, UserNotFoundException { Preconditions.checkNotNull(user); Preconditions.checkNotNull(name); @@ -135,7 +136,8 @@ UserAccountDAO userDAO = getDAO(UserAccount.class); PersonListDAO dao = getDAO(PersonList.class); - + + PersonList result; try { UserAccount userToUse = @@ -154,13 +156,14 @@ throw new FavoriteListAlreadyExistException(); } - PersonList favoriteListCreated = dao.create( + result = dao.create( PersonList.PROPERTY_OWNER, userToUse ); - favoriteListCreated.setName(name); + result.setName(name); } catch (TopiaException e) { throw new PollenTechnicalException(e); } + return result; } public PersonList deleteFavoriteList(UserAccount user, Modified: trunk/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties =================================================================== --- trunk/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties 2012-04-16 12:26:13 UTC (rev 3280) +++ trunk/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties 2012-04-17 13:08:52 UTC (rev 3281) @@ -20,6 +20,8 @@ pollen.email.voteEmail.subject=[Pollen] Vote reporting (%s) pollen.email.votingEmail.content=A new poll has been created\: "%s".\nYou can participate with the identifier %s by following this link\: \n%s pollen.email.votingEmail.subject=[Pollen] Invitation to vote (%s) +pollen.error.email.invalid=The email doesn't have the good format +pollen.error.import=Error during %1$s import \: %2$s pollen.feed.addChoiceContent= pollen.feed.addChoiceTitle= pollen.feed.addCommentContent=%s Modified: trunk/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties =================================================================== --- trunk/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties 2012-04-16 12:26:13 UTC (rev 3280) +++ trunk/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties 2012-04-17 13:08:52 UTC (rev 3281) @@ -22,6 +22,8 @@ pollen.email.voteEmail.subject=[Pollen] Notification de vote (%s) pollen.email.votingEmail.content=Un nouveau sondage a été créé \: "%s".\nVous pouvez y participer avec l'identifiant %s à l'adresse suivante \: \n%s pollen.email.votingEmail.subject=[Pollen] Invitation au vote (%s) +pollen.error.email.invalid=Email non valide +pollen.error.import=Erreur pendant l'import %1$s \: %2$s pollen.feed.addChoiceContent= pollen.feed.addChoiceTitle= pollen.feed.addCommentContent=%s Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-04-16 12:26:13 UTC (rev 3280) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-04-17 13:08:52 UTC (rev 3281) @@ -312,4 +312,10 @@ result.clear(); } } + + @Override + public boolean hasErrors() { + boolean result = super.hasErrors(); + return result || hasActionErrors(); + } } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteLists.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteLists.java 2012-04-16 12:26:13 UTC (rev 3280) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteLists.java 2012-04-17 13:08:52 UTC (rev 3281) @@ -24,13 +24,22 @@ package org.chorem.pollen.ui.actions.user; import com.google.common.base.Preconditions; +import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.business.persistence.PersonList; +import org.chorem.pollen.business.persistence.PollAccount; +import org.chorem.pollen.services.FavoriteListImport; import org.chorem.pollen.services.exceptions.FavoriteListAlreadyExistException; +import org.chorem.pollen.services.exceptions.FavoriteListImportException; +import org.chorem.pollen.services.exceptions.FavoriteListNotFoundException; +import org.chorem.pollen.services.exceptions.ParticipantAlreadyFoundInListException; +import org.chorem.pollen.services.impl.FavoriteListImportCSV; +import org.chorem.pollen.services.impl.FavoriteListImportLDAP; import org.chorem.pollen.services.impl.FavoriteService; import org.chorem.pollen.ui.actions.PageSkin; import org.chorem.pollen.ui.actions.PollenActionSupport; import java.io.File; +import java.util.List; /** * Manage favorite lists of a connected user. @@ -53,6 +62,15 @@ protected String ldapImport; protected String action; + + private FavoriteService favoriteService; + + public FavoriteService getFavoriteService() { + if (favoriteService == null) { + favoriteService = newService(FavoriteService.class); + } + return favoriteService; + } public void setCsvImport(File csvImport) { this.csvImport = csvImport; @@ -100,11 +118,35 @@ Preconditions.checkNotNull(favoriteList); Preconditions.checkNotNull(favoriteList.getName()); - String result = INPUT; - FavoriteService service = newService(FavoriteService.class); try { - service.createFavoriteList(getPollenUserAccount(), - favoriteList.getName()); + PersonList personList = + getFavoriteService().createFavoriteList(getPollenUserAccount(), + favoriteList.getName()); + + if (csvImportFileName != null) { + + FavoriteListImport importService = newService(FavoriteListImportCSV.class); + + addImport(importService, csvImport.getAbsolutePath(), personList); + } + + if (StringUtils.isNotBlank(ldapImport)) { + + FavoriteListImport importService = newService(FavoriteListImportLDAP.class); + + addImport(importService, ldapImport, personList); + } + + } catch (FavoriteListAlreadyExistException ex) { + addFieldError("createFavoriteList.name", + _("pollen.error.favoriteList.already.used")); + } + + String result; + if (hasErrors()) { + result = INPUT; + + } else { getTransaction().commitTransaction(); addActionMessage(_("pollen.information.favoriteList.created", @@ -112,9 +154,6 @@ action = null; favoriteList = null; result = SUCCESS; - } catch (FavoriteListAlreadyExistException e) { - addFieldError("createFavoriteList.name", - _("pollen.error.favoriteList.already.used")); } return result; } @@ -123,10 +162,9 @@ Preconditions.checkNotNull(favoriteList); - FavoriteService service = newService(FavoriteService.class); - - PersonList deletedFavoritedList = service.deleteFavoriteList(getPollenUserAccount(), - favoriteList); + PersonList deletedFavoritedList = + getFavoriteService().deleteFavoriteList(getPollenUserAccount(), + favoriteList); getTransaction().commitTransaction(); addActionMessage(_("pollen.information.favoriteList.deleted", @@ -138,8 +176,34 @@ protected PersonList getFavoriteList() { if (favoriteList == null) { - favoriteList = newService(FavoriteService.class).newFavoriteList(); + favoriteList = getFavoriteService().newFavoriteList(); } return favoriteList; } + + protected void addImport(FavoriteListImport service, String url, PersonList list) + throws FavoriteListNotFoundException { + + List<PollAccount> importedAccounts; + try { + importedAccounts = service.execute(url); + + for (PollAccount importedAccount : importedAccounts) { + try { + getFavoriteService().addPollAccountToFavoriteList(list, importedAccount); + + } catch (ParticipantAlreadyFoundInListException ex) { + // WARNING ? + addActionError( + _("pollen.error.favoriteList.import.participantExists" + ,importedAccount.getVotingId()) + ); + } + } + + } catch (FavoriteListImportException ex) { + String message = ex.getLocalizedMessage(getLocale()); + addActionError(message); + } + } } Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties =================================================================== --- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-04-16 12:26:13 UTC (rev 3280) +++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-04-17 13:08:52 UTC (rev 3281) @@ -128,6 +128,7 @@ pollen.error.email.invalid=The email doesn't have the good format pollen.error.email.required=You must provide an email pollen.error.favoriteList.already.used=List name already used +pollen.error.favoriteList.import.participantExists=The name '%1$s' is already used in the list pollen.error.favoriteList.not.found=Favorite list not found pollen.error.favoriteList.not.owned.by.user=You are not owner of this favorite list pollen.error.favoriteList.participant.already.found.in.list=Member was same name already in favorite list Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties =================================================================== --- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-04-16 12:26:13 UTC (rev 3280) +++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-04-17 13:08:52 UTC (rev 3281) @@ -135,6 +135,7 @@ pollen.error.email.invalid=Email non valide pollen.error.email.required=Email obligatoire pollen.error.favoriteList.already.used=Nom de liste déjà utilisé +pollen.error.favoriteList.import.participantExists=Le nom '%1$s' est déjà utilisé dans la liste pollen.error.favoriteList.not.found=Liste non trouvée pollen.error.favoriteList.not.owned.by.user=La liste d'utilisateur ne vous appartient pas pollen.error.favoriteList.participant.already.found.in.list=Nom déjà utilisé dans la liste Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp 2012-04-16 12:26:13 UTC (rev 3280) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp 2012-04-17 13:08:52 UTC (rev 3281) @@ -76,7 +76,8 @@ <br/> <s:form id='createForm' method="POST" namespace="/user" - cssClass="hidden favoriteForm"> + cssClass="hidden favoriteForm" + enctype="multipart/form-data"> <s:hidden name="action" value="create"/> <fieldset> Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-04-16 12:26:13 UTC (rev 3280) +++ trunk/pom.xml 2012-04-17 13:08:52 UTC (rev 3281) @@ -66,6 +66,12 @@ <dependency> <groupId>org.nuiton</groupId> + <artifactId>nuiton-csv</artifactId> + <version>${nuitonUtilsVersion}</version> + </dependency> + + <dependency> + <groupId>org.nuiton</groupId> <artifactId>nuiton-validator</artifactId> <version>${nuitonUtilsVersion}</version> </dependency>
participants (1)
-
fdesbois@users.chorem.org