001/** 002 * Copyright 2011-2014 The Kuali Foundation Licensed under the Educational 003 * Community License, Version 2.0 (the "License"); you may not use this file 004 * except in compliance with the License. You may obtain a copy of the License 005 * at 006 * 007 * http://www.osedu.org/licenses/ECL-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software 010 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 011 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 012 * License for the specific language governing permissions and limitations under 013 * the License. 014 */ 015package org.kuali.mobility.computerlabs.controllers; 016 017import org.kuali.mobility.computerlabs.entity.Lab; 018import org.kuali.mobility.computerlabs.entity.LabGroup; 019import org.kuali.mobility.computerlabs.service.ComputerLabsService; 020import org.kuali.mobility.security.user.api.User; 021import org.kuali.mobility.shared.Constants; 022import org.slf4j.Logger; 023import org.slf4j.LoggerFactory; 024import org.springframework.context.ApplicationContext; 025import org.springframework.context.ApplicationContextAware; 026import org.springframework.stereotype.Controller; 027import org.springframework.ui.Model; 028import org.springframework.web.bind.annotation.PathVariable; 029import org.springframework.web.bind.annotation.RequestMapping; 030import org.springframework.web.bind.annotation.RequestMethod; 031import org.springframework.web.bind.annotation.RequestParam; 032 033import javax.annotation.Resource; 034import javax.servlet.http.HttpServletRequest; 035import java.util.List; 036import java.util.Properties; 037 038/** 039 * @author Kuali Mobility Team (mobility.collab@kuali.org) 040 */ 041@Controller 042@RequestMapping("/computerlabs") 043public class ComputerLabsController implements ApplicationContextAware { 044 045 private static Logger LOG = LoggerFactory.getLogger(ComputerLabsController.class); 046 private ApplicationContext applicationContext; 047 048 @Resource(name="computerLabService") 049 private ComputerLabsService computerLabService; 050 051 @Resource(name="kmeProperties") 052 private Properties kmeProperties; 053 054 @Resource(name="computerLabProperties") 055 private Properties computerLabProperties; 056 057 @RequestMapping(method = RequestMethod.GET) 058 public String viewCampus(HttpServletRequest request, Model uiModel) { 059 String viewName = null; 060 User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY); 061 String campus = null; 062 if (user.getViewCampus() == null) { 063 viewName = "redirect:/campus?toolName=computerlabs"; 064 } else if( "3".equalsIgnoreCase( getKmeProperties().getProperty("kme.uiVersion","classic") ) ) { 065 viewName = "ui3/computerlabs/index"; 066 } else { 067 campus = user.getViewCampus(); 068 if (getComputerLabProperties() != null) { 069 String groupLabs = getComputerLabProperties().getProperty("computerlabs.groupLabs"); 070 if (groupLabs != null 071 && "true".equalsIgnoreCase(groupLabs)) { 072 List<? extends LabGroup> groups = getComputerLabService().getLabGroups(); 073 uiModel.addAttribute("labGroups", groups); 074 viewName = "computerlabs/groups"; 075 } else { 076 viewName = "redirect:/computerlabs/list"; 077 } 078 } else { 079 viewName = "redirect:/computerlabs/list"; 080 } 081 LOG.debug("Computerlabs campus different " + user.getViewCampus()); 082 uiModel.addAttribute("campus", campus); 083 } 084 return viewName; 085 } 086 087 @RequestMapping(value = "/list") 088 public String getList(Model uiModel, HttpServletRequest request, 089 @RequestParam(required = false) String groupId ) { 090 String viewName = null; 091 User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY); 092 String campus = null; 093 if (user.getViewCampus() == null) { 094 viewName = "redirect:/campus?toolName=computerlabs"; 095 } else { 096 campus = user.getViewCampus(); 097 String filteredCampus = (String)request.getSession().getAttribute("campus"); 098 uiModel.addAttribute("campus", filteredCampus); 099 LOG.debug("Computerlabs campus different " + user.getViewCampus()); 100 101 LabGroup group = getComputerLabService().getLabGroup((groupId == null ? filteredCampus : groupId)); 102 uiModel.addAttribute("group", group); 103 104 if (getComputerLabProperties() != null) { 105 String groupLabs = getComputerLabProperties().getProperty("computerlabs.groupLabs"); 106 if (groupLabs != null 107 && "true".equalsIgnoreCase(groupLabs)) { 108 uiModel.addAttribute("pageTitle", group.getName()); 109 } 110 uiModel.addAttribute( "useMaps", getComputerLabProperties().getProperty("computerlabs.useMaps", "true")); 111 uiModel.addAttribute( "useDetail", getComputerLabProperties().getProperty("computerlabs.useDetail", "true")); 112 uiModel.addAttribute( "groupSeats", getComputerLabProperties().getProperty("computerlabs.groupSeats", "true")); 113 uiModel.addAttribute( "feedStatus", getComputerLabProperties().getProperty("computerlabs.feedStatus", "false")); 114 } 115 viewName = "computerlabs/list"; 116 } 117 return viewName; 118 } 119 120 @RequestMapping(value = "/feeds") 121 public String retrieveAndSaveSpreadsheetDataAsXML(Model uiModel, 122 HttpServletRequest request) { 123 String feedURL = getComputerLabProperties().getProperty("computerlabs.feedURL"); 124 getComputerLabService().retrieveAndSaveSpreadsheetDataAsXML(feedURL); 125 return "computerlabs/list"; 126 } 127 128 @RequestMapping(value = "/details") 129 public String getViewSeatDetails(Model uiModel, 130 HttpServletRequest request, 131 @RequestParam(required = true) String labUid) { 132 User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY); 133 String campus = null; 134 if( user != null ) { 135 campus = user.getViewCampus(); 136 } 137 Lab lab = (Lab)getComputerLabService().getLab(labUid); 138 uiModel.addAttribute("lab", lab); 139 uiModel.addAttribute("campus", campus); 140 return "computerlabs/details"; 141 } 142 143 @RequestMapping(value="/templates/{key}") 144 public String getAngularTemplates( 145 @PathVariable("key") String key, 146 HttpServletRequest request, 147 Model uiModel ) { 148 if (getComputerLabProperties() != null) { 149 uiModel.addAttribute( "useMaps", getComputerLabProperties().getProperty("computerlabs.useMaps", "true")); 150 uiModel.addAttribute( "useDetail", getComputerLabProperties().getProperty("computerlabs.useDetail", "true")); 151 } 152 return "ui3/computerlabs/templates/"+key; 153 } 154 155 @RequestMapping(value = "/js/computerlabs.js") 156 public String getJavaScript(Model uiModel) { 157 if (getComputerLabProperties() != null) { 158 uiModel.addAttribute( "groupLabs", getComputerLabProperties().getProperty("computerlabs.groupLabs", "false")); 159 uiModel.addAttribute( "useMaps", getComputerLabProperties().getProperty("computerlabs.useMaps", "true")); 160 uiModel.addAttribute( "useDetail", getComputerLabProperties().getProperty("computerlabs.useDetail", "true")); 161 uiModel.addAttribute( "groupSeats", getComputerLabProperties().getProperty("computerlabs.groupSeats", "true")); 162 uiModel.addAttribute( "feedStatus", getComputerLabProperties().getProperty("computerlabs.feedStatus", "false")); 163 } 164 return "ui3/computerlabs/js/computerlabs"; 165 } 166 167 /** 168 * @return the computerLabService 169 */ 170 public ComputerLabsService getComputerLabService() { 171 return computerLabService; 172 } 173 174 /** 175 * @param computerLabService the computerLabService to set 176 */ 177 public void setComputerLabService(ComputerLabsService computerLabService) { 178 this.computerLabService = computerLabService; 179 } 180 181 /** 182 * @return the applicationContext 183 */ 184 public ApplicationContext getApplicationContext() { 185 return applicationContext; 186 } 187 188 /** 189 * @param applicationContext the applicationContext to set 190 */ 191 public void setApplicationContext(ApplicationContext applicationContext) { 192 this.applicationContext = applicationContext; 193 } 194 195 public Properties getKmeProperties() { 196 return kmeProperties; 197 } 198 199 public void setKmeProperties(Properties kmeProperties) { 200 this.kmeProperties = kmeProperties; 201 } 202 203 public Properties getComputerLabProperties() { 204 return computerLabProperties; 205 } 206 207 public void setComputerLabProperties(Properties computerLabProperties) { 208 this.computerLabProperties = computerLabProperties; 209 } 210}