r17 - in trunk/billy-business/src/main/java/org/chorem/billy: . business dto external impl
Author: fdesbois Date: 2009-09-21 10:46:39 +0200 (Mon, 21 Sep 2009) New Revision: 17 Modified: trunk/billy-business/src/main/java/org/chorem/billy/ContextUtilBilly.java trunk/billy-business/src/main/java/org/chorem/billy/business/ClientHelper.java trunk/billy-business/src/main/java/org/chorem/billy/business/InvoiceHelper.java trunk/billy-business/src/main/java/org/chorem/billy/dto/Client.java trunk/billy-business/src/main/java/org/chorem/billy/external/ImportUrl.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: Cleaning code and add javadoc Modified: trunk/billy-business/src/main/java/org/chorem/billy/ContextUtilBilly.java =================================================================== --- trunk/billy-business/src/main/java/org/chorem/billy/ContextUtilBilly.java 2009-09-09 13:25:30 UTC (rev 16) +++ trunk/billy-business/src/main/java/org/chorem/billy/ContextUtilBilly.java 2009-09-21 08:46:39 UTC (rev 17) @@ -85,13 +85,6 @@ */ private static Properties loadFileProperties(String filename) throws URISyntaxException, IOException { - /*Properties props = new Properties(); - URL url = Resource.getURL(filename); - if (log.isDebugEnabled()) { - log.debug(url); - } - props.load(url.openStream()); - return props;*/ return PropertiesLoader.loadPropertiesFile(filename); } 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-09-09 13:25:30 UTC (rev 16) +++ trunk/billy-business/src/main/java/org/chorem/billy/business/ClientHelper.java 2009-09-21 08:46:39 UTC (rev 17) @@ -47,8 +47,16 @@ */ public class ClientHelper { - - + /** + * Create or update a client from a ClientPerson DTO. One entity for client company, service and person. + * Exist parameters : Company Name, Service name (subdivision) and person name. + * @param person ClientPerson DTO for create or update the corresponding entity + * @param transaction Topia transaction for DAO usage + * @param log logging + * @return the ClientEntity added or updated + * @throws org.nuiton.topia.TopiaException + * @throws org.chorem.exceptions.EntityException + */ public static ClientEntity createUpdateClient(ClientPerson person, TopiaContext transaction, Log log) throws TopiaException, EntityException { @@ -56,7 +64,7 @@ Map<String, Object> existParams = new HashMap<String, Object>(); existParams.put(ClientEntity.NAME, client.getName()); - // TODO Add siret + // TODO Add siret/siren existParams.put(ClientEntity.SUB_DIVISION_NAME, person.getSubDivisionName()); existParams.put(ClientEntity.PERSON_NAME, person.getName()); // TODO Add email @@ -78,13 +86,24 @@ return entity; } + /** + * Conversion of ClientEntity to ClientPerson DTO. The company client is an other DTO called Client and + * linked to the ClientPerson DTO. A client can be linked from parameters, if this client is null, a new + * one is created from ClientEntity company attributes (name, siret, source). + * Url from ChoReg is added to the DTO for UI usage. + * @param entity ClientEntity from DataBase + * @param client existing Client to link + * @return the ClientPerson DTO corresponding to the entity + * @throws org.chorem.billy.BillyException + * @see org.chorem.billy.external.ImportUrl + */ public static ClientPerson getClientPerson(ClientEntity entity, Client client) throws BillyException { 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 + String topiaId = entity.getTopiaId(); // specifique a un triplet Client / Service / ClientPerson person.setId(ContextUtilBilly.convertId(topiaId)); person.setSubDivisionName(entity.getSubDivisionName()); @@ -100,6 +119,7 @@ ImportUrl importUrl = new ImportUrl(); client = importUrl.setClientUrl(client); } catch (NoClassDefFoundError eee) { + // No ChoReg in ClassLoader } } @@ -108,27 +128,4 @@ return person; } - /*public static Client getClientOrganization(ClientEntity entity) throws ConvertException { - Client result = Convert.toDTO(entity, ClientEntity.class, ClientOrganization.class); - - result.setId(ContextUtilBilly.convertId(entity.getTopiaId())); - - for (SubDivisionEntity divisionEntity : entity.getSubDivisionEntity()) { - SubDivision sub = Convert.toDTO(divisionEntity, SubDivisionEntity.class, SubDivision.class); - sub.setId(ContextUtilBilly.convertId(divisionEntity.getTopiaId())); - - for (ClientEntity clientEntity : divisionEntity.getClientEntity()) { - Client client = Convert.toDTO(clientEntity, ClientEntity.class, Client.class); - client.setId(ContextUtilBilly.convertId(clientEntity.getTopiaId())); - sub.addClient(client); - client.setSubDivision(sub); - } - - result.addSubDivision(sub); - sub.setClientOrganization(result); - } - - return result; - }*/ - } Modified: trunk/billy-business/src/main/java/org/chorem/billy/business/InvoiceHelper.java =================================================================== --- trunk/billy-business/src/main/java/org/chorem/billy/business/InvoiceHelper.java 2009-09-09 13:25:30 UTC (rev 16) +++ trunk/billy-business/src/main/java/org/chorem/billy/business/InvoiceHelper.java 2009-09-21 08:46:39 UTC (rev 17) @@ -41,6 +41,14 @@ */ public class InvoiceHelper { + /** + * Conversion from InvoiceEntity to Invoice DTO for UI usage. + * @param entity InvoiceEntity to convert + * @return the Invoice DTO corresponding to the entity + * @throws org.chorem.exceptions.ConvertException + * @throws org.chorem.billy.BillyException + * @see org.chorem.utils.Convert#toDTO(org.nuiton.topia.persistence.TopiaEntity, java.lang.Class, java.lang.Class) + */ public static Invoice getInvoice(InvoiceEntity entity) throws ConvertException, BillyException { Invoice invoice = Convert.toDTO(entity, InvoiceEntity.class, Invoice.class); Modified: trunk/billy-business/src/main/java/org/chorem/billy/dto/Client.java =================================================================== --- trunk/billy-business/src/main/java/org/chorem/billy/dto/Client.java 2009-09-09 13:25:30 UTC (rev 16) +++ trunk/billy-business/src/main/java/org/chorem/billy/dto/Client.java 2009-09-21 08:46:39 UTC (rev 17) @@ -6,7 +6,7 @@ import java.util.Map; import org.apache.commons.lang.builder.ToStringBuilder; -// FIXME, must be generated by BeanGenerator in ToPIA-persistence +// FIXME, must be generated by BeanGenerator in ToPIA-persistence (problem with Map) public class Client implements java.io.Serializable { public Map<String, List<ClientPerson>> services; Modified: trunk/billy-business/src/main/java/org/chorem/billy/external/ImportUrl.java =================================================================== --- trunk/billy-business/src/main/java/org/chorem/billy/external/ImportUrl.java 2009-09-09 13:25:30 UTC (rev 16) +++ trunk/billy-business/src/main/java/org/chorem/billy/external/ImportUrl.java 2009-09-21 08:46:39 UTC (rev 17) @@ -33,6 +33,8 @@ * * Created on 2009-08-26 * + * ChoReg usage for Urls to others applications (Depends on source attribute of Client or other entity to link). + * * @author fdesbois * @version $Revision$ * @@ -49,14 +51,17 @@ choreg = ChoremRegistryImpl.getInstance(); } + /** + * Set urls for UI usage from ChoReg. + * @param client Client DTO to set urls. + * @return the Client with urls for his uis (in an other application). + * @throws org.chorem.billy.BillyException + */ public Client setClientUrl(Client client) throws BillyException { try { String viewUrl = choreg.findViewUrl(null, client.getSource()); client.setViewUrl(viewUrl); - /*String formUrl = choreg.findFormUrl(null, client.getSource()); - client.setFormUrl(formUrl); - String listUrl = choreg.findListUrl(null, client.getSource(), null); - client.setFormUrl(listUrl);*/ + // TODO add formUrl and listUrl (not supported yet in ChoReg) } catch (NoServiceException eee) { if (log.isWarnEnabled()) { 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-09-09 13:25:30 UTC (rev 16) +++ trunk/billy-business/src/main/java/org/chorem/billy/impl/ServiceClientImpl.java 2009-09-21 08:46:39 UTC (rev 17) @@ -57,8 +57,6 @@ private TopiaContext context; - private List<Client> clientsImportedCache; - public ServiceClientImpl() { this.context = ContextUtilBilly.getRootContext(); } @@ -76,30 +74,7 @@ List<ClientPerson> persons = services.get(subDivisionName); for (ClientPerson person : persons) { - ClientHelper.createUpdateClient(person, transaction, log); - - /* Map<String, Object> existParams = new HashMap<String, Object>(); - - existParams.put(ClientEntity.NAME, client.getName()); - // TODO Add siret - existParams.put(ClientEntity.SUB_DIVISION_NAME, subDivisionName); - existParams.put(ClientEntity.PERSON_NAME, person.getName()); - // TODO Add email - - Map<String, Object> saveParams = new HashMap<String, Object>(existParams); - - saveParams.put(ClientEntity.SIRET, client.getSiret()); - saveParams.put(ClientEntity.SOURCE, client.getSource()); - saveParams.put(ClientEntity.PERSON_EMAIL, person.getEmail()); - saveParams.put(ClientEntity.PERSON_SOURCE, person.getSource()); - - ClientEntityDAO dao = BillyModelDAOHelper.getClientEntityDAO(transaction); - - ClientEntity entity = ServiceHelper.createUpdateEntity(dao, person.getId(), existParams, saveParams, log); - - String id = ContextUtilBilly.convertId(entity.getTopiaId()); - person.setId(id);*/ } } @@ -110,6 +85,12 @@ } } + /** + * Getting all clients from DataBase and others applications (ChoReg usage). Client DTO contains + * all hierarchy of the company, his services and persons. + * @return the complete list of existing clients + * @throws org.chorem.billy.BillyException + */ @Override public List<Client> getClients() throws BillyException { TopiaContext transaction = null; @@ -148,31 +129,13 @@ services.put(entity.getSubDivisionName(), persons); } - /*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()); - person.setClient(client);*/ + ClientPerson person = ClientHelper.getClientPerson(entity, client); - ClientPerson person = ClientHelper.getClientPerson(entity, client); - - - persons.add(person); - - //Client client = ClientHelper.getClient(entity); - //results.add(client); + persons.add(person); } - /*for (String key : clients.keySet()) { - results.add(clients.get(key)); - }*/ + results = importXpilClients(results); - results = importXpilReferences(results); - transaction.closeContext(); } catch (Exception eee) { ContextUtilBilly.serviceException(transaction, "Unable to get all clients", eee); @@ -180,6 +143,11 @@ return results; } + /** + * Delete a clientPerson : topiaId for ClientEntity corresponding to the personId in ClientPerson DTO. + * @param personId the topiaId from ClientPerson DTO. + * @throws org.chorem.billy.BillyException + */ @Override public void deleteClientPerson(String personId) throws BillyException { TopiaContext transaction = null; @@ -197,6 +165,12 @@ } } + /** + * Delete all ClientPerson from a Client company. (topiaId for ClientEntity corresponding to the personId + * in ClientPerson DTO.) + * @param client Client DTO contains persons to delete + * @throws org.chorem.billy.BillyException + */ @Override public void deleteClient(Client client) throws BillyException { TopiaContext transaction = null; @@ -229,96 +203,87 @@ } } - private List<Client> importXpilReferences(List<Client> input) throws BillyException { + /** + * ChoReg usage for Clients with xPIL format (Clients from others chorem applications) + * @param input Client list from DB (existing entities) + * @return complete list of client from DB and imported ones. + * @throws org.chorem.billy.BillyException + */ + private List<Client> importXpilClients(List<Client> input) throws BillyException { try { ImportXPIL xpil = new ImportXPIL(); ImportUrl importUrl = new ImportUrl(); - if (log.isInfoEnabled()) { - log.info("ImportXPIL..."); - } + if (log.isInfoEnabled()) { + log.info("ImportXPIL..."); + } - //if (clientsImportedCache == null) { + int nbPersonsImported = 0; // use for log + int nbPersonsFromXpil = 0; // use for log + + for (Client client : xpil.findAll()) { + + Client clientFind = getClient(input, client); + if (clientFind == null) { // new Client from xPIL + input.add(client); + importUrl.setClientUrl(client); // Url for Client from xPIL (already set if clientFind from DB) if (log.isDebugEnabled()) { - log.debug("New imports, create Cache"); + log.debug("Add Client : " + client.getName() + " _ " + client.getSiret() + " _ " + client.getSource()); } - clientsImportedCache = xpil.findAll(); - //} + } else { // Client already exist - int nbPersonsImported = 0; - int nbPersonsFromXpil = 0; + // MAJ CLIENT + clientFind.setSource(client.getSource()); + clientFind.setSiret(client.getSiret()); + clientFind.setName(client.getName()); - for (Client client : clientsImportedCache) { + Map<String, List<ClientPerson>> servicesFind = clientFind.getServices(); - Client clientFind = getClient(input, client); - if (clientFind == null) { // new Client from xPIL - input.add(client); - importUrl.setClientUrl(client); // Url for Client from xPIL (already set if clientFind from DB) - if (log.isDebugEnabled()) { - log.debug("Add Client : " + client.getName() + " _ " + client.getSiret() + " _ " + client.getSource()); - } - } else { // Client already exist + for (String serviceName : client.getServices().keySet()) { - // MAJ CLIENT - clientFind.setSource(client.getSource()); - clientFind.setSiret(client.getSiret()); - clientFind.setName(client.getName()); + List<ClientPerson> persons = client.getServices().get(serviceName); - Map<String, List<ClientPerson>> servicesFind = clientFind.getServices(); + List<ClientPerson> personsFind = servicesFind.get(serviceName); + if (personsFind == null) { // new Service with List persons from xPIL - for (String serviceName : client.getServices().keySet()) { + servicesFind.put(serviceName, persons); + if (log.isDebugEnabled()) { + log.debug("Add Service : " + serviceName + " with " + persons.size() + " persons"); + } + } else { // Service already exist - List<ClientPerson> persons = client.getServices().get(serviceName); + for (ClientPerson person : persons) { - List<ClientPerson> personsFind = servicesFind.get(serviceName); - if (personsFind == null) { // new Service with List persons from xPIL - - servicesFind.put(serviceName, persons); - if (log.isDebugEnabled()) { - log.debug("Add Service : " + serviceName + " with " + persons.size() + " persons"); - } - } else { // Service already exist - - for (ClientPerson person : persons) { - - ClientPerson personFind = getClientPerson(personsFind, person); - if (personFind == null) { // new ClientPerson from xPIL - personsFind.add(person); - if (log.isDebugEnabled()) { - log.debug("Add Person : " + person.getName() + " _ " + person.getEmail() + " _ " + person.getSource()); - } - nbPersonsImported++; - } else { - // MAJ PERSON - personFind.setSource(person.getSource()); - personFind.setName(person.getName()); - personFind.setEmail(person.getEmail()); + ClientPerson personFind = getClientPerson(personsFind, person); + if (personFind == null) { // new ClientPerson from xPIL + personsFind.add(person); + if (log.isDebugEnabled()) { + log.debug("Add Person : " + person.getName() + " _ " + person.getEmail() + " _ " + person.getSource()); } + nbPersonsImported++; + } else { + // MAJ PERSON + personFind.setSource(person.getSource()); + personFind.setName(person.getName()); + personFind.setEmail(person.getEmail()); } } - - nbPersonsFromXpil += persons.size(); } + + nbPersonsFromXpil += persons.size(); } } + } - /*ImportUrl importUrl = new ImportUrl(); - for (Client client : input) { - if (client.getSource() != null && !client.getSource().isEmpty()) { - importUrl.setClientUrl(client); - } - }*/ - - if (log.isInfoEnabled()) { - if (nbPersonsFromXpil != 0) { - log.info("...clients imported"); - log.info("Persons from xPIL = " + nbPersonsFromXpil); - log.info("Persons imported from client organisations = " + nbPersonsImported); - } else { - log.info("...no clients imported. Probably no service available"); - } + if (log.isInfoEnabled()) { + if (nbPersonsFromXpil != 0) { + log.info("...clients imported"); + log.info("Persons from xPIL = " + nbPersonsFromXpil); + log.info("Persons imported from client organisations = " + nbPersonsImported); + } else { + log.info("...no clients imported. Probably no service available"); } - //} + } } catch (NoClassDefFoundError eee) { if (log.isWarnEnabled()) { log.warn("No ChoremRegistry available"); @@ -353,31 +318,4 @@ return null; } - /*private ClientOrganization getClientOrganization(List<ClientOrganization> input, ClientOrganization organizationFromXpil) { - for (ClientOrganization in : input) { - if (organizationFromXpil.getSource().equals(in.getSource())) { - return in; - } - } - return null; - } - - private SubDivision getDivision(ClientOrganization input, SubDivision subDivisionFromXpil) { - for (SubDivision in : input.getSubDivision()) { - if (in.getName().equals(subDivisionFromXpil.getName())) { - return in; - } - } - return null; - } - - private Client getClient(SubDivision input, Client clientFromXpil) { - for (Client in : input.getClient()) { - if (clientFromXpil.getPersonSource().equals(in.getPersonSource())) { - return in; - } - } - return null; - }*/ - } 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-09-09 13:25:30 UTC (rev 16) +++ trunk/billy-business/src/main/java/org/chorem/billy/impl/ServiceInvoiceImpl.java 2009-09-21 08:46:39 UTC (rev 17) @@ -34,7 +34,6 @@ import org.chorem.billy.dto.Client; import org.chorem.billy.dto.ClientPerson; import org.chorem.billy.dto.Invoice; -import org.chorem.billy.external.ImportUrl; import org.chorem.billy.persistence.ClientEntity; import org.chorem.billy.persistence.InvoiceEntity; import org.chorem.billy.persistence.InvoiceEntityDAO; @@ -65,6 +64,11 @@ this.context = ContextUtilBilly.getRootContext(); } + /** + * Create or update an Invoice. Exist parameters : Number and date of the Invoice. + * @param invoice invoice to create or update. + * @throws org.chorem.billy.BillyException + */ @Override public void createUpdateInvoice(Invoice invoice) throws BillyException { TopiaContext transaction = null; @@ -103,6 +107,11 @@ } } + /** + * Delete of invoice with id in parameters. + * @param invoiceId not necessary a topiaId (conversion will be done in ServiceHelper). + * @throws org.chorem.billy.BillyException + */ @Override public void deleteInvoice(String invoiceId) throws BillyException { TopiaContext transaction = null; @@ -120,6 +129,11 @@ } } + /** + * Getting all existing invoices. + * @return List of Invoice + * @throws org.chorem.billy.BillyException + */ @Override public List<Invoice> getAllInvoices() throws BillyException { List<Invoice> results = new ArrayList<Invoice>(); @@ -150,6 +164,10 @@ throw new UnsupportedOperationException("Not supported yet."); } + /** + * Getting a new invoice with client and clientperson inialisation. + * @return a fresh new Invoice + */ @Override public Invoice getNewInvoice() { Invoice invoice = new Invoice(); @@ -159,6 +177,12 @@ return invoice; } + /** + * Getting an existing Invoice corresponding to invoiceId in parameters. + * @param invoiceId not necessary a topiaId (conversion will be done in ServiceHelper). + * @return the Invoice find, if not exist an exception will be thrown (EntityException from ServiceHelper) + * @throws org.chorem.billy.BillyException + */ @Override public Invoice getInvoice(String invoiceId) throws BillyException { Invoice result = null;
participants (1)
-
fdesbois@users.chorem.org