public SlideshowData generateTimelineData(String resourceHolderId) throws Exception {
    ResourceHolder resourceHolder = resourceHolderRepository.findOne(resourceHolderId);
    exceptionNullResourceHolder(resourceHolder);
    Resource resource = getIdResource();
    Asset defaultAsset = defaultAsset(resource);
    Slideshow timeline = new Slideshow();
    setTimeline(defaultAsset, timeline);
    ResourceSchedule schedule = ScheduleServiceImplSimple.findOne(resource.getScheduleId());
    nullExceptionSchedule(schedule);

    ArrayList<ResourceSchedule> getResourceSchedules = schedule.getResourceSchedules();
    int sizeOfResourceSchedules = getResourceSchedules.size();
    if (sizeOfResourceSchedules == 0) {
      throw new Exception("", null);
    }

    HashMap<String, Asset> assets = setRecourceIds(getResourceSchedules);
    List<SlideshowInterval> timelineIntervalList = new ArrayList<>();
    int slide = 0;
    Calendar calendar = GregorianCalendar.getInstance();
    long timeInMillis = calendar.getTimeInMillis();
    slide =
        resourceSchedules(
            defaultAsset, getResourceSchedules, assets, timelineIntervalList, slide, timeInMillis);
    if (sizeOfResourceSchedules > 0) {
      ResourceSchedule sizeOfResourceSchedule =
          getResourceSchedules.get(sizeOfResourceSchedules - 1);
      if (timeInMillis > sizeOfResourceSchedule.getEndTime()) {
        slide = 0;
      }
      timelineIntervalList.add(
          resourceScheduleToDate(
              sizeOfResourceSchedule, assets.get(sizeOfResourceSchedule.getResourceId())));
    }
    timeline.setDate(timelineIntervalList);
    return new SlideshowData(timeline, slide);
  }
Exemplo n.º 2
0
  public SlideshowData generateTimelineData(String resourceHolderId, String contentId)
      throws Exception {

    Resource resource = getResource(contentId);

    Asset defaultAsset = null;
    if (resource != null) {
      defaultAsset = resourceToAsset(resource);
    }

    Slideshow timeline = new Slideshow();

    if (defaultAsset != null) {
      setDefaultProperties(defaultAsset, timeline);
    } else {
      setOptionalProperties(timeline);
    }

    ResourceSchedule schedule = ScheduleServiceImplSimple.findOne(resource.getScheduleId());

    if (schedule == null) {
      try {
        throw new Exception("");
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    if (schedule.getResourceSchedules().size() == 0) {
      throw new Exception("", null);
    }

    Set<String> resourceIds = new HashSet<>();

    // zmienic
    for (ResourceSchedule item : schedule.getResourceSchedules()) {
      resourceIds.add(item.getResourceId());
    }

    Iterable<Resource> resourcesSet = resourceHolderResourceRepository.findAll(resourceIds);
    HashMap<String, Asset> assets = resourcesToAssetMap(resourcesSet);

    List<SlideshowInterval> timelineIntervalList = new ArrayList<>();
    int slide = 0;

    Calendar calendar = GregorianCalendar.getInstance();

    for (int i = 0; i < schedule.getResourceSchedules().size() - 1; ++i) {
      long startTime = schedule.getResourceSchedules().get(i).getStartTime();

      if (calendar.getTimeInMillis() > startTime) {
        ++slide;
      }
      timelineIntervalList.add(
          resourceScheduleToDate(
              schedule.getResourceSchedules().get(i),
              assets.get(schedule.getResourceSchedules().get(i).getResourceId())));
      if (defaultAsset != null) {
        if (schedule.getResourceSchedules().get(i).getEndTime()
            != schedule.getResourceSchedules().get(i + 1).getStartTime()) {
          if (schedule.getResourceSchedules().get(i).getEndTime() < calendar.getTimeInMillis()) {
            ++slide;
          }
          timelineIntervalList.add(
              defaultDate(
                  schedule.getResourceSchedules().get(i).getEndTime(),
                  schedule.getResourceSchedules().get(i + 1).getStartTime(),
                  defaultAsset));
        }
      }
    }
    if (schedule.getResourceSchedules().size() > 0) {
      if (calendar.getTimeInMillis()
          > schedule
              .getResourceSchedules()
              .get(schedule.getResourceSchedules().size() - 1)
              .getEndTime()) {
        slide = 0;
      }

      timelineIntervalList.add(
          resourceScheduleToDate(
              schedule.getResourceSchedules().get(schedule.getResourceSchedules().size() - 1),
              assets.get(
                  schedule
                      .getResourceSchedules()
                      .get(schedule.getResourceSchedules().size() - 1)
                      .getResourceId())));
    }

    timeline.setDate(timelineIntervalList);
    return new SlideshowData(timeline, slide);
  }