/*
Copyright 2006 - 2010 Under Dusken
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package no.dusken.aranea.admin.control;
import no.dusken.aranea.model.Banner;
import no.dusken.aranea.model.BannerLocation;
import no.dusken.aranea.service.BannerLocationService;
import no.dusken.aranea.service.BannerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PlaceBannerController extends AbstractController {
private BannerLocationService bannerLocationService;
private BannerService bannerService;
private Logger log = LoggerFactory.getLogger(this.getClass());
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) {
Map<String, Object> map = new HashMap<String, Object>();
List<BannerLocation> bannerLocations = bannerLocationService
.getBannerLocations();
List<Banner> banners = bannerService.getBanners();
if (request.getParameter("submit") != null) {
try {
// traverse the bannerlocations, and look for banners
for (BannerLocation bl : bannerLocations) {
Long bannerID = ServletRequestUtils.getLongParameter(
request, bl.getID().toString());
Banner b = bannerService.getEntity(bannerID);
bl.setBanner(b);
bannerLocationService.saveOrUpdate(bl);
}
} catch (Exception e) {
log.error("Saving in placeBanner failed", e);
return new ModelAndView("no/dusken/aranea/base/admin/placeBanners/failed", map);
}
}
map.put("bannerLocations", bannerLocations);
map.put("banners", banners);
return new ModelAndView("no/dusken/aranea/base/admin/placeBanners/edit", map);
}
@Required
public void setBannerLocationService(
BannerLocationService bannerLocationService) {
this.bannerLocationService = bannerLocationService;
}
@Required
public void setBannerService(BannerService bannerService) {
this.bannerService = bannerService;
}
}