Coverage Report - org.kuali.rice.ken.web.spring.ContentTypeController
 
Classes in this File Line Coverage Branch Coverage Complexity
ContentTypeController
0%
0/79
0%
0/4
1.375
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.ken.web.spring;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.util.Collection;
 20  
 import java.util.HashMap;
 21  
 import java.util.Map;
 22  
 
 23  
 import javax.servlet.ServletException;
 24  
 import javax.servlet.http.HttpServletRequest;
 25  
 import javax.servlet.http.HttpServletResponse;
 26  
 
 27  
 import org.apache.log4j.Logger;
 28  
 import org.kuali.rice.ken.bo.NotificationContentType;
 29  
 import org.kuali.rice.ken.service.NotificationAuthorizationService;
 30  
 import org.kuali.rice.ken.service.NotificationContentTypeService;
 31  
 import org.kuali.rice.ken.service.NotificationService;
 32  
 import org.springframework.web.servlet.ModelAndView;
 33  
 import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
 34  
 
 35  
 /**
 36  
  * Controller that manages ContentTypes (add/update)
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  */
 39  0
 public class ContentTypeController extends MultiActionController {
 40  
    
 41  0
    private static String view = "";
 42  
    protected NotificationService notificationService;
 43  
    protected NotificationContentTypeService notificationContentTypeService;
 44  
    protected NotificationAuthorizationService notificationAuthzService;
 45  
    
 46  
    /**
 47  
     * Set the Notification Services
 48  
     * @param notificationService
 49  
     */   
 50  
    public void setNotificationService(NotificationService notificationService) {
 51  0
       this.notificationService = notificationService;
 52  0
    }
 53  
    
 54  
    /**
 55  
     * Set the Notification Services
 56  
     * @param notificationService
 57  
     */   
 58  
    public void setNotificationContentTypeService(NotificationContentTypeService notificationContentTypeService) {
 59  0
       this.notificationContentTypeService = notificationContentTypeService;
 60  0
    }
 61  
    
 62  
    /**
 63  
     * Set the Notification Authorization Services
 64  
     * @param notificationAuthzService
 65  
     */   
 66  
    public void setNotificationAuthorizationService(NotificationAuthorizationService notificationAuthzService) {
 67  0
       this.notificationAuthzService = notificationAuthzService;
 68  0
    }
 69  
 
 70  
    /** Logger for this class and subclasses */
 71  0
    private static final Logger LOG = Logger.getLogger(NotificationController.class);
 72  
    
 73  
    @Override
 74  
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
 75  
        // only allow admins access to this controller
 76  
        // yuck, we should implement ACEGI down the road
 77  0
        String user = request.getRemoteUser();
 78  0
        if (!notificationAuthzService.isUserAdministrator(user)) {
 79  0
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
 80  
            //response.sendError(HttpServletResponse.SC_FORBIDDEN, "User " + user + " is not a Notification System administrator");
 81  0
            throw new SecurityException("User " + user + " is not a Notification System administrator");
 82  
        }
 83  0
        return super.handleRequestInternal(request, response);
 84  
    }
 85  
 
 86  
    /**
 87  
     * display ContentTypes
 88  
     * @param request : a servlet request
 89  
     * @param response : a servlet response
 90  
     * @throws ServletException : an exception
 91  
     * @throws IOException : an exception
 92  
     * @return a ModelAndView object
 93  
     */   
 94  
    public ModelAndView displayContentTypes(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 95  
 
 96  0
       view = "ContentTypeManager";
 97  
       
 98  0
       Collection<NotificationContentType> contentTypes = this.notificationContentTypeService.getAllCurrentContentTypes();
 99  0
       Map<String, Object> model = new HashMap<String, Object>();
 100  0
       model.put("contentTypes", contentTypes);
 101  0
       return new ModelAndView(view, model);
 102  
    }
 103  
 
 104  
 /**
 105  
     * display ContentTypeForm
 106  
     * @param request : a servlet request
 107  
     * @param response : a servlet response
 108  
     * @throws ServletException : an exception
 109  
     * @throws IOException : an exception
 110  
     * @return a ModelAndView object
 111  
     */   
 112  
    public ModelAndView displayContentTypeForm(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 113  
 
 114  0
       view = "ContentTypeForm";
 115  
       NotificationContentType notificationContentType;
 116  
       String actionrequested; 
 117  0
       String name = request.getParameter("name");
 118  0
       LOG.debug("name param: "+name);
 119  
  
 120  0
       if (name == null) {
 121  0
          actionrequested = new String("add");
 122  0
          notificationContentType = new NotificationContentType();
 123  
       } else {
 124  0
           actionrequested = new String("update"); 
 125  0
          notificationContentType = this.notificationContentTypeService.getNotificationContentType(name);
 126  
       }
 127  
 
 128  0
       Map<String, Object> model = new HashMap<String, Object>();
 129  0
       model.put("notificationContentType",notificationContentType);
 130  0
       model.put("actionrequested", actionrequested);
 131  0
       return new ModelAndView(view, model);
 132  
    }
 133  
    
 134  
    /**
 135  
     * addContentType
 136  
     * @param request : a servlet request
 137  
     * @param response : a servlet response
 138  
     * @throws ServletException : an exception
 139  
     * @throws IOException : an exception
 140  
     * @return a ModelAndView object
 141  
     */   
 142  
    public ModelAndView addContentType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 143  0
        view = "ContentTypeManager";
 144  0
        String id = request.getParameter("id");
 145  0
        String name = request.getParameter("name");
 146  0
        String description = request.getParameter("description");
 147  0
        String namespace = request.getParameter("namespace");
 148  0
        String xsd = request.getParameter("xsd");
 149  0
        String xsl = request.getParameter("xsl");
 150  
        
 151  0
        LOG.debug("id: "+id);
 152  0
        LOG.debug("name: "+name);
 153  0
        LOG.debug("description: "+description);
 154  0
        LOG.debug("namespace: "+namespace);
 155  0
        LOG.debug("xsd: "+xsd);
 156  0
        LOG.debug("xsl: "+xsl);
 157  
        
 158  0
        NotificationContentType notificationContentType = new NotificationContentType();
 159  0
        notificationContentType.setName(name);
 160  0
        notificationContentType.setDescription(description);
 161  0
        notificationContentType.setNamespace(namespace);
 162  0
        notificationContentType.setXsd(xsd);
 163  0
        notificationContentType.setXsl(xsl);
 164  
        
 165  0
        this.notificationContentTypeService.saveNotificationContentType(notificationContentType);
 166  
        
 167  0
        Collection<NotificationContentType> contentTypes = this.notificationContentTypeService.getAllCurrentContentTypes();
 168  0
        Map<String, Object> model = new HashMap<String, Object>();
 169  0
        model.put("contentTypes", contentTypes);            
 170  0
        return new ModelAndView(view, model);     
 171  
    }
 172  
    
 173  
    /**
 174  
     * updateContentType
 175  
     * @param request : a servlet request
 176  
     * @param response : a servlet response
 177  
     * @throws ServletException : an exception
 178  
     * @throws IOException : an exception
 179  
     * @return a ModelAndView object
 180  
     */   
 181  
    public ModelAndView updateContentType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 182  0
        view = "ContentTypeManager";
 183  0
        String id = request.getParameter("id");
 184  0
        String name = request.getParameter("name");
 185  0
        String description = request.getParameter("description");
 186  0
        String namespace = request.getParameter("namespace");
 187  0
        String xsd = request.getParameter("xsd");
 188  0
        String xsl = request.getParameter("xsl");
 189  
        
 190  0
        LOG.debug("id: "+id);
 191  0
        LOG.debug("name: "+name);
 192  0
        LOG.debug("description: "+description);
 193  0
        LOG.debug("namespace: "+namespace);
 194  0
        LOG.debug("xsd: "+xsd);
 195  0
        LOG.debug("xsl: "+xsl);
 196  
        
 197  0
        NotificationContentType notificationContentType = this.notificationContentTypeService.getNotificationContentType(name);
 198  
         
 199  0
        notificationContentType.setName(name);
 200  0
        notificationContentType.setDescription(description);
 201  0
        notificationContentType.setNamespace(namespace);
 202  0
        notificationContentType.setXsd(xsd);
 203  0
        notificationContentType.setXsl(xsl);
 204  
        
 205  0
        this.notificationContentTypeService.saveNotificationContentType(notificationContentType);
 206  
        
 207  
        
 208  
        // get updated content type collection
 209  0
        Collection<NotificationContentType> contentTypes = this.notificationContentTypeService.getAllCurrentContentTypes();
 210  0
        Map<String, Object> model = new HashMap<String, Object>();
 211  0
        model.put("contentTypes", contentTypes);
 212  0
        return new ModelAndView(view, model);     
 213  
    }
 214  
 }