1 package ejava.projects.eleague.blimpl;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5
6 import javax.xml.bind.JAXBException;
7 import javax.xml.stream.XMLStreamException;
8
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11
12 import ejava.projects.eleague.dao.ClubDAO;
13 import ejava.projects.eleague.dto.ELeague;
14 import ejava.projects.eleague.dto.Season;
15 import ejava.projects.eleague.xml.ELeagueParser;
16
17 public class LeagueIngestor {
18 private static final Logger logger = LoggerFactory.getLogger(LeagueIngestor.class);
19 private InputStream is;
20 private ClubDAO clubDAO;
21
22 public void setInputStream(InputStream is) {
23 this.is = is;
24 }
25
26 public void setClubDAO(ClubDAO clubDAO) {
27 this.clubDAO = clubDAO;
28 }
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public void ingest() throws JAXBException, XMLStreamException, IOException {
43 ELeagueParser parser = new ELeagueParser(ELeague.class, is);
44
45 Object object = parser.getObject(
46 "contact", "league-metadata", "club", "season");
47 while (object != null) {
48 if (object instanceof ejava.projects.eleague.dto.Club) {
49 createVenue((ejava.projects.eleague.dto.Club)object);
50 }
51 else if (object instanceof ejava.projects.eleague.dto.Season) {
52 checkSeason((ejava.projects.eleague.dto.Season)object);
53 }
54 object = parser.getObject(
55 "contact", "league-metadata", "club", "season");
56 }
57 is.close();
58 }
59
60 private void checkSeason(Season season) {
61 if ("Spring NeverEnds".equals(season.getName())) {
62 logger.info("checking {} for null contact", season.getName());
63 for (ejava.projects.eleague.dto.Division division : season.getDivision()) {
64 if (division.getContact() == null) {
65 logger.error("current season has no contact, " +
66 "check project version: refId {}", division.getRefid());
67 }
68 }
69 }
70 }
71
72
73
74
75
76
77 private void createVenue(ejava.projects.eleague.dto.Club clubDTO) {
78 for (ejava.projects.eleague.dto.Venue venueDTO : clubDTO.getVenue()) {
79 ejava.projects.eleague.bo.Address addressBO =
80 new ejava.projects.eleague.bo.Address();
81 addressBO.setCity(venueDTO.getCity());
82
83 ejava.projects.eleague.bo.Venue venueBO =
84 new ejava.projects.eleague.bo.Venue();
85 venueBO.setName(venueDTO.getName());
86 venueBO.setAddress(addressBO);
87
88 clubDAO.createVenue(venueBO);
89 logger.debug("created venue: {} for club {}", venueBO, clubDTO.getName());
90 }
91 }
92 }