|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| SubmitInvoiceImpl.java | - | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* SubmitInvoiceImpl.java
|
|
| 3 |
* Copyright 2002-2004 Bill2, Inc.
|
|
| 4 |
*
|
|
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 6 |
* you may not use this file except in compliance with the License.
|
|
| 7 |
* You may obtain a copy of the License at
|
|
| 8 |
*
|
|
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 10 |
*
|
|
| 11 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 14 |
* See the License for the specific language governing permissions and
|
|
| 15 |
* limitations under the License.
|
|
| 16 |
*/
|
|
| 17 |
package command;
|
|
| 18 |
|
|
| 19 |
import example.command.SubmitInvoice;
|
|
| 20 |
import example.entity.Country;
|
|
| 21 |
import example.entity.CountryFactory;
|
|
| 22 |
import example.entity.Invoice;
|
|
| 23 |
import org.dentaku.services.container.ContainerManager;
|
|
| 24 |
import org.dentaku.services.persistence.PersistenceManager;
|
|
| 25 |
import org.apache.commons.logging.Log;
|
|
| 26 |
import org.apache.commons.logging.LogFactory;
|
|
| 27 |
|
|
| 28 |
import java.util.Date;
|
|
| 29 |
|
|
| 30 |
public class SubmitInvoiceImpl extends SubmitInvoice { |
|
| 31 |
private static Log log = LogFactory.getLog(SubmitInvoiceImpl.class); |
|
| 32 | 0 |
public boolean execute() throws Exception { |
| 33 | 0 |
boolean result = true; |
| 34 | 0 |
PersistenceManager pm = (PersistenceManager) ContainerManager.getInstance().getContainer().lookup(PersistenceManager.ROLE); |
| 35 | 0 |
try {
|
| 36 | 0 |
Invoice inv = getInvoice(); |
| 37 |
|
|
| 38 |
// relate the country
|
|
| 39 | 0 |
CountryFactory countryFactory = (CountryFactory) pm.getPersistenceFactory(CountryFactory.class.getName());
|
| 40 | 0 |
Country c = (Country)countryFactory.findByCountryAbbr("US").iterator().next();
|
| 41 |
//YUCK
|
|
| 42 | 0 |
inv.getBillAddress().setCountry(c); |
| 43 | 0 |
inv.getShipAddress().setCountry(c); |
| 44 |
|
|
| 45 | 0 |
inv.setTxnDate(new Date());
|
| 46 |
|
|
| 47 |
// now save everything out
|
|
| 48 |
// BRAIN DAMAGE: need to go through and find records that already exist in the DB instead of duplicating them
|
|
| 49 | 0 |
pm.saveOrUpdate(inv.getBillAddress()); |
| 50 | 0 |
pm.saveOrUpdate(inv.getShipAddress()); |
| 51 | 0 |
pm.saveOrUpdate(inv.getCreditCard()); |
| 52 | 0 |
pm.saveOrUpdate(inv); |
| 53 |
} catch (Exception e) {
|
|
| 54 | 0 |
e.printStackTrace(); |
| 55 | 0 |
pm.rollback(); |
| 56 | 0 |
result = false;
|
| 57 |
} finally {
|
|
| 58 | 0 |
pm.releaseSession(); |
| 59 |
} |
|
| 60 | 0 |
return result;
|
| 61 |
} |
|
| 62 |
} |
|
| 63 |
|
|
||||||||||