org.opentestsystem.delivery.testreg.rest.ProctorPackageController.java Source code

Java tutorial

Introduction

Here is the source code for org.opentestsystem.delivery.testreg.rest.ProctorPackageController.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.testreg.rest;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.opentestsystem.delivery.testreg.service.ProctorPackageService;
import org.opentestsystem.shared.web.AbstractRestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.MediaType;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ProctorPackageController extends AbstractRestController {

    @Autowired
    private ProctorPackageService proctorassessmentService;

    /**
     * Exports Assessments.
     *
     * @param request
     *            HttpServlet request
     * @param response
     *            HttpServlet response
     * @return SearchResponse containing assessments
     */
    @RequestMapping(value = "/proctorassessments", method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE)
    @Secured({ "ROLE_Entity Read" })
    @ResponseBody
    public String exportProctorPackage(final HttpServletRequest request, final HttpServletResponse response,
            @RequestParam(value = "entityLevel", required = true) final String entityLevel,
            @RequestParam(value = "entityName", required = true) final String entityName,
            @RequestParam(value = "stateAbbreviation", required = false) final String stateAbbreviation,
            @RequestParam(value = "date", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") final Date date) {
        DateTime localDate;
        if (date == null) {
            localDate = LocalDate.now().toDateTimeAtStartOfDay();
        } else {
            localDate = new LocalDate(date.getTime()).toDateTimeAtStartOfDay();
        }
        return proctorassessmentService.exportProctorPackage(entityLevel, entityName, stateAbbreviation, localDate);

    }

}