001/**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package edu.sampleu.kew.krad.controller;
017
018import javax.servlet.http.HttpServletRequest;
019import javax.servlet.http.HttpServletResponse;
020
021import org.kuali.rice.kew.service.KEWServiceLocator;
022import org.kuali.rice.kew.stats.service.StatsService;
023import org.kuali.rice.krad.web.controller.UifControllerBase;
024import org.kuali.rice.krad.web.form.UifFormBase;
025import org.springframework.stereotype.Controller;
026import org.springframework.validation.BindingResult;
027import org.springframework.web.bind.annotation.ModelAttribute;
028import org.springframework.web.bind.annotation.RequestMapping;
029import org.springframework.web.servlet.ModelAndView;
030
031import edu.sampleu.kew.krad.form.StatsForm;
032
033/**
034 * This is a description of what this class does - Venkat don't forget to fill this in. 
035 * 
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 *
038 */
039@Controller
040@RequestMapping(value = "/stats")
041public class StatsController extends UifControllerBase {
042
043    /**
044     * @see org.kuali.rice.krad.web.controller.UifControllerBase#createInitialForm(javax.servlet.http.HttpServletRequest)
045     */
046    @Override
047    protected StatsForm createInitialForm() {
048        return new StatsForm();
049    }
050
051        @Override
052        @RequestMapping(params = "methodToCall=start")
053        public ModelAndView start(UifFormBase form) {
054
055                StatsForm statForm = (StatsForm) form;
056
057                try{
058                statForm.determineBeginDate();
059                statForm.determineEndDate();
060        
061                StatsService statsService = this.getStatsService();
062                statsService.NumUsersReport(statForm.getStats());
063                statsService.DocumentsRoutedReport(statForm.getStats(), statForm.getBeginningDate(), statForm.getEndingDate());
064                statsService.NumActiveItemsReport(statForm.getStats());
065                statsService.NumberOfDocTypesReport(statForm.getStats());
066                statsService.NumInitiatedDocsByDocTypeReport(statForm.getStats());
067                
068                }catch (Exception e) {
069                        throw new RuntimeException(e);
070                }
071        
072                return super.start(statForm);
073        }
074        
075         public StatsService getStatsService() {
076        return (StatsService) KEWServiceLocator.getService(KEWServiceLocator.STATS_SERVICE);
077    }
078}