sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
sb.append("\n");
sb.append("<ScheduleDTO xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
sb.append(" ");
sb.append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
Schedule schedule = new Schedule(new Date());
schedule.setMinDate(startDate);
schedule.setMaxDate(endDate);
scheduleDAO.put(schedule);
sb.append("\n<Id>" + UUID.randomUUID().toString() + "</Id>");
sb.append("\n<Date>" + xmlFormatter.format(schedule.getDateCreated()) + "</Date>");
sb.append("\n<Ads>");
for (Slot slot : slots) {
startTime = xmlFormatter.parse(xmlFormatter.format(slot.getStartDate()));
endTime = xmlFormatter.parse(xmlFormatter.format(slot.getStartDate()));
while (endTime.compareTo(slot.getEndDate()) < 0) {
if (slot.getProductIds().size() == 0) {
endTime = xmlFormatter.parse(xmlFormatter.format(slot.getEndDate()));
log.warning("Slot from '" + logFormatter.format(slot.getStartDate()) + "' to '" + logFormatter.format(slot.getEndDate()) + "' did not have any product! The slot will be skipped.");
} else {
for (int index = 0 ; index < slot.getProductIds().size() && endTime.compareTo(slot.getEndDate()) < 0; index++) {
Long prId = slot.getProductIds().get(index);
Product product = DatastoreProxy.getProductById(prId);
if (product != null) {
calendar.setTime(startTime);
calendar.add(Calendar.MINUTE, defaultSlotDurationInMinutes);
endTime = calendar.getTime();
List<Resource> resources = DatastoreProxy.getResourcesByProductId(product.getId());
List<String> resourcesURLs = new ArrayList<String>();
if (resources != null) {
for (Resource r : resources) {
if (r != null) {
resourcesURLs.add(r.getImageURL());
}
}
}
Long pbId = product.getPublisherId();
if (pbId != null) {
Publisher publisher = DatastoreProxy.getPublisherById(pbId);
if (publisher != null) {
Long cpId = publisher.getCompanyId();
if (cpId != null) {
Company company = DatastoreProxy.getCompanyById(cpId);
if (company != null) {
Ad ad = new Ad(startTime, endTime, company.getLastname(), product.getName(), product.getSlogan(), product.getText(), product.getLink(), resourcesURLs, true, new Double(1));
adDAO.put(ad);
schedule.getAdIds().add(ad.getId());
startTime = calendar.getTime();
sb.append("\n<AdDTO>");
sb.append("\n<Id>" + ad.getUUID() + "</Id>");
sb.append("\n<Company>");
sb.append("\n<Id>" + company.getUUID() + "</Id>");
sb.append("\n<Name>" + ad.getCompany() + "</Name>");
sb.append("\n</Company>");
sb.append("\n<Publisher>");
sb.append("\n<Id>" + publisher.getUUID() + "</Id>");
sb.append("\n<Name>" + publisher.getFirstname() + " " + publisher.getLastname() + "</Name>");
sb.append("\n</Publisher>");
sb.append("\n<Product>");
sb.append("\n<Id>" + product.getUUID() + "</Id>");
sb.append("\n<Name>" + ad.getProduct() + "</Name>");
sb.append("\n<Text>" + ad.getText() + "</Text>");
sb.append("\n<Link>" + ad.getLink() + "</Link>");
sb.append("\n<Slogan>" + ad.getSlogan() + "</Slogan>");
sb.append("\n</Product>");
sb.append("\n<Start>" + xmlFormatter.format(ad.getStartTime()) + "</Start>");
sb.append("\n<End>" + xmlFormatter.format(ad.getEndTime()) + "</End>");
sb.append("\n<IsCommercial>" + ad.isCommercial() + "</IsCommercial>");
sb.append("\n<Weight>" + ad.getWeight() + "</Weight>");
sb.append("\n<Resources>");
for (Resource rs : resources) {
sb.append("\n<ResourceDTO>");
sb.append("\n<Filename>" + rs.getUUID() + "</Filename>");
sb.append("\n<ImageURL>" + rs.getImageURL() + "</ImageURL>");
sb.append("\n</ResourceDTO>");
}
sb.append("\n</Resources>");
sb.append("\n</AdDTO>");
log.info("Appended: " + ad);;
}
}
}
}
productDAO.put(product);
}
}
}
}
}
sb.append("\n</Ads>");
sb.append("\n</ScheduleDTO>");
Schedule entity = DatastoreProxy.createSchedule(schedule);
this.scheduleId = entity == null ? null : entity.getId();
this.stringXML = sb.toString();
} else {
log.warning("No slots were found!");
}
} catch (ParseException e) {