Author: fdesbois Date: 2009-08-27 13:26:57 +0200 (Thu, 27 Aug 2009) New Revision: 7 Added: trunk/billy-business/src/main/java/org/chorem/billy/business/InvoiceHelper.java Modified: trunk/billy-business/src/main/java/org/chorem/billy/business/ClientHelper.java trunk/billy-business/src/main/java/org/chorem/billy/impl/ServiceClientImpl.java trunk/billy-business/src/main/java/org/chorem/billy/impl/ServiceInvoiceImpl.java Log: Add ServiceInvoice implementations for createUpdate, getAll and delete Modified: trunk/billy-business/src/main/java/org/chorem/billy/business/ClientHelper.java =================================================================== --- trunk/billy-business/src/main/java/org/chorem/billy/business/ClientHelper.java 2009-08-27 11:04:29 UTC (rev 6) +++ trunk/billy-business/src/main/java/org/chorem/billy/business/ClientHelper.java 2009-08-27 11:26:57 UTC (rev 7) @@ -76,6 +76,28 @@ return entity; } + public static ClientPerson getClientPerson(ClientEntity entity, Client client) { + ClientPerson person = new ClientPerson(); + person.setName(entity.getPersonName()); + person.setSource(entity.getSource()); + person.setEmail(entity.getPersonEmail()); + + String topiaId = entity.getTopiaId(); // specifique à un triplet Client / Service / ClientPerson + person.setId(ContextUtilBilly.convertId(topiaId)); + person.setSubDivisionName(entity.getSubDivisionName()); + + if (client == null) { + client = new Client(); + client.setName(entity.getName()); + client.setSiret(entity.getSiret()); + client.setSource(entity.getSource()); + } + + person.setClient(client); + + return person; + } + /*public static Client getClientOrganization(ClientEntity entity) throws ConvertException { Client result = Convert.toDTO(entity, ClientEntity.class, ClientOrganization.class); Added: trunk/billy-business/src/main/java/org/chorem/billy/business/InvoiceHelper.java =================================================================== --- trunk/billy-business/src/main/java/org/chorem/billy/business/InvoiceHelper.java (rev 0) +++ trunk/billy-business/src/main/java/org/chorem/billy/business/InvoiceHelper.java 2009-08-27 11:26:57 UTC (rev 7) @@ -0,0 +1,57 @@ +/** + * *##% Billy Business + * Copyright (C) 2009 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 Lesser 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>. ##%* + */ + +package org.chorem.billy.business; + +import org.chorem.billy.ContextUtilBilly; +import org.chorem.billy.dto.ClientPerson; +import org.chorem.billy.dto.Invoice; +import org.chorem.billy.persistence.ClientEntity; +import org.chorem.billy.persistence.InvoiceEntity; +import org.chorem.exceptions.ConvertException; +import org.chorem.utils.Convert; + +/** + * InvoiceHelper.java + * + * Created on 2009-08-27 + * + * @author fdesbois + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class InvoiceHelper { + + public static Invoice getInvoice(InvoiceEntity entity) throws ConvertException { + Invoice invoice = Convert.toDTO(entity, InvoiceEntity.class, Invoice.class); + + invoice.setId(ContextUtilBilly.convertId(entity.getTopiaId())); + + ClientEntity client = entity.getClientEntity(); + + ClientPerson person = ClientHelper.getClientPerson(client, null); + + invoice.setClientPerson(person); + + return invoice; + } + +} Property changes on: trunk/billy-business/src/main/java/org/chorem/billy/business/InvoiceHelper.java ___________________________________________________________________ Added: svn:keywords + Author Revision Date Modified: trunk/billy-business/src/main/java/org/chorem/billy/impl/ServiceClientImpl.java =================================================================== --- trunk/billy-business/src/main/java/org/chorem/billy/impl/ServiceClientImpl.java 2009-08-27 11:04:29 UTC (rev 6) +++ trunk/billy-business/src/main/java/org/chorem/billy/impl/ServiceClientImpl.java 2009-08-27 11:26:57 UTC (rev 7) @@ -147,7 +147,7 @@ services.put(entity.getSubDivisionName(), persons); } - ClientPerson person = new ClientPerson(); + /*ClientPerson person = new ClientPerson(); person.setName(entity.getPersonName()); person.setSource(entity.getSource()); person.setEmail(entity.getPersonEmail()); @@ -155,8 +155,11 @@ String topiaId = entity.getTopiaId(); // specifique à un triplet Client / Service / ClientPerson person.setId(ContextUtilBilly.convertId(topiaId)); person.setSubDivisionName(entity.getSubDivisionName()); - person.setClient(client); + person.setClient(client);*/ + ClientPerson person = ClientHelper.getClientPerson(entity, client); + + persons.add(person); //Client client = ClientHelper.getClient(entity); Modified: trunk/billy-business/src/main/java/org/chorem/billy/impl/ServiceInvoiceImpl.java =================================================================== --- trunk/billy-business/src/main/java/org/chorem/billy/impl/ServiceInvoiceImpl.java 2009-08-27 11:04:29 UTC (rev 6) +++ trunk/billy-business/src/main/java/org/chorem/billy/impl/ServiceInvoiceImpl.java 2009-08-27 11:26:57 UTC (rev 7) @@ -1,9 +1,3 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.chorem.billy.impl; /** * *##% Billy Business * Copyright (C) 2009 CodeLutin @@ -23,15 +17,28 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. ##%* */ +package org.chorem.billy.impl; + + +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.billy.BillyException; +import org.chorem.billy.BillyModelDAOHelper; import org.chorem.billy.ContextUtilBilly; +import org.chorem.billy.business.ClientHelper; +import org.chorem.billy.business.InvoiceHelper; import org.chorem.billy.dto.Invoice; +import org.chorem.billy.persistence.ClientEntity; +import org.chorem.billy.persistence.InvoiceEntity; +import org.chorem.billy.persistence.InvoiceEntityDAO; import org.chorem.billy.services.ServiceInvoice; import org.chorem.billy.services.ServiceInvoiceAbstract; import org.chorem.utils.PeriodDates; +import org.chorem.utils.ServiceHelper; import org.nuiton.topia.TopiaContext; /** @@ -57,17 +64,77 @@ @Override public void createUpdateInvoice(Invoice invoice) throws BillyException { - throw new UnsupportedOperationException("Not supported yet."); + TopiaContext transaction = null; + try { + transaction = context.beginTransaction(); + + InvoiceEntityDAO dao = BillyModelDAOHelper.getInvoiceEntityDAO(transaction); + + Map<String, Object> existParams = new HashMap<String, Object>(); + + existParams.put(InvoiceEntity.INVOICE_NUMBER, invoice.getInvoiceNumber()); + existParams.put(InvoiceEntity.INVOICE_DATE, invoice.getInvoiceDate()); + + Map<String, Object> saveParams = new HashMap<String, Object>(existParams); + + saveParams.put(InvoiceEntity.HOPE_DATE, invoice.getHopeDate()); + saveParams.put(InvoiceEntity.EFFECTIVE_DATE, invoice.getEffectiveDate()); + saveParams.put(InvoiceEntity.AMOUNT, invoice.getAmount()); + + if (invoice.getClientPerson() == null) { + ContextUtilBilly.serviceException(transaction, "Unable to create or update invoice", + new IllegalArgumentException("Client must be provided to create update the invoice")); + } + ClientEntity client = ClientHelper.createUpdateClient(invoice.getClientPerson(), transaction, log); + + saveParams.put(InvoiceEntity.CLIENT_ENTITY, client); + + InvoiceEntity entity = ServiceHelper.createUpdateEntity(dao, invoice.getId(), existParams, saveParams, log); + + invoice.setId(ContextUtilBilly.convertId(entity.getTopiaId())); + + transaction.commitTransaction(); + transaction.closeContext(); + } catch (Exception eee) { + ContextUtilBilly.serviceException(transaction, "Unable to create or update invoice", eee); + } } @Override public void deleteInvoice(String invoiceId) throws BillyException { - throw new UnsupportedOperationException("Not supported yet."); + TopiaContext transaction = null; + try { + transaction = context.beginTransaction(); + + InvoiceEntityDAO dao = BillyModelDAOHelper.getInvoiceEntityDAO(transaction); + + ServiceHelper.deleteEntity(dao, invoiceId, log); + + transaction.commitTransaction(); + transaction.closeContext(); + } catch (Exception eee) { + ContextUtilBilly.serviceException(transaction, "Unable to delete invoice with id = " + invoiceId, eee); + } } @Override public List<Invoice> getAllInvoices() throws BillyException { - throw new UnsupportedOperationException("Not supported yet."); + List<Invoice> results = new ArrayList<Invoice>(); + TopiaContext transaction = null; + try { + transaction = context.beginTransaction(); + + InvoiceEntityDAO dao = BillyModelDAOHelper.getInvoiceEntityDAO(transaction); + + for (InvoiceEntity entity : dao.findAll()) { + results.add(InvoiceHelper.getInvoice(entity)); + } + + transaction.closeContext(); + } catch (Exception eee) { + ContextUtilBilly.serviceException(transaction, "Unable to get all invoices", eee); + } + return results; } @Override