Package com.casamind.adware.server.domain

Examples of com.casamind.adware.server.domain.Schedule


  }

  private void doSchedule(Long scheduleId) {
    log.info("scheduleId = " + scheduleId);
    if (scheduleId != null) {
      Schedule schedule = DatastoreProxy.getScheduleById(scheduleId);
      if (schedule != null) {
        List<Long> adIds = schedule.getAdIds();
        if (adIds.size() > 0) {
          log.info("Found " + adIds.size() + " ads");
          log.info("Purging Google Calendar from '" + logFormatter.format(schedule.getMinDate()) + "' to '" + logFormatter.format(schedule.getMaxDate()) + "'");
          try {

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(schedule.getMinDate());
            calendar.add(Calendar.DAY_OF_YEAR, -2);
            Date minDate = calendar.getTime();
            CalendarEventFeed rangeFeed = proxy.getEventsRangeFeed(minDate, schedule.getMaxDate());
            List<CalendarEventEntry> entriesToDelete = new ArrayList<CalendarEventEntry>();
            entriesToDelete.addAll(rangeFeed.getEntries());
            int size = entriesToDelete.size();
            while (size > 0) {
              log.info("Adding " + size + " event entries to mass deletion batch...");
              proxy.batchEntries(entriesToDelete, BatchOperationType.DELETE);
              rangeFeed = proxy.getEventsRangeFeed(minDate, schedule.getMaxDate());
              entriesToDelete.clear();
              entriesToDelete.addAll(rangeFeed.getEntries());
              size = entriesToDelete.size();
            }
            log.info("Finshed mass deletion batch.");
View Full Code Here


    return datastoreItem;
  }

  public static Schedule createSchedule(Schedule entity) {
    ObjectifyGenericDAO<Schedule> dao = new ObjectifyGenericDAO<Schedule>(Schedule.class);
    Schedule datastoreItem = null;
    if (entity != null) {
      Key<Schedule> key = dao.put(entity);
      try {
        datastoreItem = dao.get(key);
      } catch (EntityNotFoundException e) {
View Full Code Here

        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) {
View Full Code Here

TOP

Related Classes of com.casamind.adware.server.domain.Schedule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.