r352 - in trunk/faxtomail-service/src: main/java/com/franciaflex/faxtomail/services/service test/java/com/franciaflex/faxtomail/services/service
Author: echatellier Date: 2014-07-07 11:49:31 +0200 (Mon, 07 Jul 2014) New Revision: 352 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/352 Log: fixes #5382: Mettre ?\195?\160 jour la table client ?\195?\160 partir de la table interm?\195?\169diaire Added: trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/ClientServiceTest.java Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ClientService.java trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ClientService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ClientService.java 2014-07-07 08:50:47 UTC (rev 351) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ClientService.java 2014-07-07 09:49:31 UTC (rev 352) @@ -24,29 +24,34 @@ * #L% */ +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; + import com.franciaflex.faxtomail.persistence.entities.Client; import com.franciaflex.faxtomail.persistence.entities.ClientImpl; import com.franciaflex.faxtomail.persistence.entities.ClientTopiaDao; import com.franciaflex.faxtomail.persistence.entities.Email; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserTopiaDao; import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.persistence.entities.NewClient; import com.franciaflex.faxtomail.persistence.entities.NewClientTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.NewClientType; import com.franciaflex.faxtomail.services.FaxToMailServiceSupport; import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.math.NumberUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.beans.Binder; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - /** * @author Kevin Morin (Code Lutin) * @@ -110,24 +115,78 @@ return client; } + /** + * Récupère les information de la table NewClient pour mettre à jour la table Client. + */ public void updateNewClients() { - NewClientTopiaDao dao = getPersistenceContext().getNewClientDao(); - List<NewClient> newClients = dao.findAll(); + NewClientTopiaDao newClientDao = getPersistenceContext().getNewClientDao(); + ClientTopiaDao clientDao = getPersistenceContext().getClientDao(); + FaxToMailUserTopiaDao faxToMailUserDao = getPersistenceContext().getFaxToMailUserDao(); + Iterable<NewClient> newClients = newClientDao.findAll(); + Binder<NewClient, Client> binder = BinderFactory.newBinder(NewClient.class, Client.class); + + for (NewClient newClient : newClients) { + + NewClientType type = newClient.getType(); + switch (type) { + case CREATION: + case UPDATE: - Binder<NewClient, Client> binder = new Binder<>(); - List<Client> clients = new ArrayList<>(); - for (NewClient newClient : newClients) { - Client client = new ClientImpl(); - binder.copyExcluding(newClient, client, - NewClient.PROPERTY_TOPIA_ID, - NewClient.PROPERTY_TOPIA_CREATE_DATE, - NewClient.PROPERTY_TOPIA_VERSION); - clients.add(client); + // find client to create or update + Client client = clientDao.forIdEquals(newClient.getId()).findUniqueOrNull(); + if (client == null) { + client = new ClientImpl(); + if (type == NewClientType.UPDATE && log.isWarnEnabled()) { + log.warn("Can't find client " + newClient.getId() + " to update. Client created."); + } + } else { + if (type == NewClientType.CREATION && log.isWarnEnabled()) { + log.warn("Creating a already existing client " + newClient.getId() + ". Client updated."); + } + } + + // update client instance + binder.copyExcluding(newClient, client, + Client.PROPERTY_TOPIA_ID, + Client.PROPERTY_TOPIA_CREATE_DATE, + Client.PROPERTY_TOPIA_VERSION); + + // update person in charge + FaxToMailUser personInCharge = null; + if (StringUtils.isNotBlank(newClient.getPersonInCharge())) { + faxToMailUserDao.forLoginEquals(newClient.getPersonInCharge()).findUniqueOrNull(); + } + client.setPersonInCharge(personInCharge); + + // persist + if (client.isPersisted()) { + clientDao.update(client); + } else { + clientDao.create(client); + } + + break; + + case DELETION: + Client deleteClient = clientDao.forIdEquals(newClient.getId()).findUniqueOrNull(); + if (deleteClient == null) { + if (log.isWarnEnabled()) { + log.warn("Can't find client " + newClient.getId() + " to delete"); + } + } else { + // FIXME le delete ne fonctionnera pas si des mails porte sur ce client + clientDao.delete(deleteClient); + if (log.isDebugEnabled()) { + log.debug("Client " + newClient.getId() + " deleted"); + } + } + break; + } + } - //TODO kmorin 20140626 update some clients and add others -// dao.deleteAll(newClients); -// getPersistenceContext().commit(); + newClientDao.deleteAll(newClients); + getPersistenceContext().commit(); } } Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java 2014-07-07 08:50:47 UTC (rev 351) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java 2014-07-07 09:49:31 UTC (rev 352) @@ -346,7 +346,7 @@ File ediDirectory = getApplicationConfig().getEdiDirectory(); ediDirectory.mkdirs(); - String fileDate = DateFormatUtils.format(now, "yyMMddhhmmss"); + String fileDate = DateFormatUtils.format(now, "yyMMddHHmmss"); // create a file for each commande for (RangeRow rangeRow : email.getRangeRow()) { Added: trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/ClientServiceTest.java =================================================================== --- trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/ClientServiceTest.java (rev 0) +++ trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/ClientServiceTest.java 2014-07-07 09:49:31 UTC (rev 352) @@ -0,0 +1,81 @@ +package com.franciaflex.faxtomail.services.service; + +import org.junit.Assert; +import org.junit.Test; + +import com.franciaflex.faxtomail.persistence.entities.ClientTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.NewClient; +import com.franciaflex.faxtomail.persistence.entities.NewClientImpl; +import com.franciaflex.faxtomail.persistence.entities.NewClientTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.NewClientType; + +/* + * #%L + * FaxToMail :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2014 Franciaflex, Code Lutin + * %% + * 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/gpl-3.0.html>. + * #L% + */ + +/** + * Test de client service. + * + * @author Eric Chatellier + */ +public class ClientServiceTest extends AbstractFaxToMailServiceTest { + + /** + * Ajout des clients dans la table temporaire et appel le service de traitement de cette table. + */ + @Test + public void testAddNewClientInTmpTable() { + + ClientService clientService = newService(ClientService.class); + NewClientTopiaDao newClientDao = getServiceContext().getPersistenceContext().getNewClientDao(); + ClientTopiaDao clientDao = getServiceContext().getPersistenceContext().getClientDao(); + + // asserts + Assert.assertNull(clientDao.forEmailAddressEquals("gerard.menvussa@lutin.com").findAnyOrNull()); + + // add new clients + NewClient newClient = new NewClientImpl(); + newClient.setId("253142"); + newClient.setEmailAddress("gerard.menvussa@lutin.com"); + newClient.setType(NewClientType.UPDATE); + newClient = newClientDao.create(newClient); + + // precedure de mise à jour + clientService.updateNewClients(); + + // asserts + Assert.assertNotNull(clientDao.forEmailAddressEquals("gerard.menvussa@lutin.com").findAnyOrNull()); + + // add new clients + NewClient deleteClient = new NewClientImpl(); + deleteClient.setId("253142"); + deleteClient.setType(NewClientType.DELETION); + deleteClient = newClientDao.create(deleteClient); + + // precedure de mise à jour + clientService.updateNewClients(); + + // asserts + Assert.assertNull(clientDao.forIdEquals("253142").findAnyOrNull()); + } +} Property changes on: trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/ClientServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
echatellier@users.forge.codelutin.com