1 package ejava.projects.esales.blimpl;
2
3 import java.io.InputStream;
4
5 import javax.xml.bind.JAXBException;
6 import javax.xml.stream.XMLStreamException;
7
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
10
11 import ejava.projects.esales.dao.AccountDAO;
12 import ejava.projects.esales.dto.ESales;
13 import ejava.projects.esales.xml.ESalesParser;
14
15 public class ESalesIngestor {
16 private static final Logger log = LoggerFactory.getLogger(ESalesIngestor.class);
17 InputStream is;
18 AccountDAO accountDAO;
19 ESalesParser parser;
20
21 public void setInputStream(InputStream is) {
22 this.is = is;
23 }
24
25 public void setAccountDAO(AccountDAO accountDAO) {
26 this.accountDAO = accountDAO;
27 }
28
29
30
31
32
33
34
35
36
37
38
39
40 public void ingest() throws JAXBException, XMLStreamException {
41 ESalesParser parser = new ESalesParser(ESales.class, is);
42
43 Object object = parser.getObject(
44 "address", "account", "auction", "image");
45 while (object != null) {
46 if (object instanceof ejava.projects.esales.dto.Account) {
47 createAccount((ejava.projects.esales.dto.Account)object);
48 }
49 object = parser.getObject(
50 "address", "account", "auction", "image");
51 }
52 }
53
54
55
56
57
58
59 private void createAccount(ejava.projects.esales.dto.Account accountDTO) {
60 ejava.projects.esales.bo.Account accountBO =
61 new ejava.projects.esales.bo.Account(accountDTO.getLogin());
62 accountBO.setFirstName(accountDTO.getFirstName());
63 for (Object o : accountDTO.getAddress()) {
64 ejava.projects.esales.dto.Address addressDTO =
65 (ejava.projects.esales.dto.Address)o;
66 ejava.projects.esales.bo.Address addressBO =
67 new ejava.projects.esales.bo.Address(
68 0,
69 addressDTO.getName(),
70 addressDTO.getCity());
71 accountBO.getAddresses().add(addressBO);
72 }
73 accountDAO.createAccount(accountBO);
74 log.debug("created account:" + accountBO);
75 }
76 }