org.opentestsystem.delivery.testadmin.service.impl.ScheduleReportServiceImpl.java Source code

Java tutorial

Introduction

Here is the source code for org.opentestsystem.delivery.testadmin.service.impl.ScheduleReportServiceImpl.java

Source

/*******************************************************************************
 * Educational Online Test Delivery System
 * Copyright (c) 2013 American Institutes for Research
 * 
 * Distributed under the AIR Open Source License, Version 1.0
 * See accompanying file AIR-License-1_0.txt or at
 * http://www.smarterapp.org/documents/American_Institutes_for_Research_Open_Source_Software_License.pdf
 ******************************************************************************/
package org.opentestsystem.delivery.testadmin.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.DurationFieldType;
import org.opentestsystem.delivery.testadmin.domain.TestAdminReport;
import org.opentestsystem.delivery.testadmin.domain.schedule.Schedule;
import org.opentestsystem.delivery.testadmin.domain.schedule.ScheduledDay;
import org.opentestsystem.delivery.testadmin.persistence.ScheduleRepository;
import org.opentestsystem.delivery.testadmin.service.ScheduleReportService;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class ScheduleReportServiceImpl implements ScheduleReportService {

    @Autowired
    ScheduleRepository scheduleRepository;

    public List<TestAdminReport> buildScheduledReport(String institutionId, DateTime startDate, DateTime endDate) {
        List<Schedule> scheduledList = scheduleRepository.findScheduleByStartDateAndEndDate(institutionId,
                startDate, endDate);

        List<ScheduledDay> allScheduleDays = new ArrayList<ScheduledDay>();
        for (Schedule schedule : scheduledList) {
            allScheduleDays.addAll(schedule.getScheduledDays());
        }
        // Now Filter the Scheduled based on the given Date
        int days = Days.daysBetween(startDate, endDate).getDays();
        List<DateTime> rangeOfdates = new ArrayList<DateTime>();
        if (days == 0) {
            rangeOfdates.add(startDate);
        } else {
            for (int i = 0; i <= days; i++) {
                DateTime d = startDate.withFieldAdded(DurationFieldType.days(), i);
                rangeOfdates.add(d);
            }
        }
        return populateScheduleReport(allScheduleDays, rangeOfdates, institutionId);
    }

}