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>");