01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/matrix/tool/src/java/org/theospi/portfolio/matrix/control/MoveLevelController.java $
03: * $Id: MoveLevelController.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.portfolio.matrix.control;
21:
22: import java.util.HashMap;
23: import java.util.Map;
24:
25: import org.apache.commons.logging.Log;
26: import org.apache.commons.logging.LogFactory;
27: import org.sakaiproject.metaobj.utils.mvc.intf.Controller;
28: import org.springframework.validation.Errors;
29: import org.springframework.web.servlet.ModelAndView;
30: import org.theospi.portfolio.matrix.model.Level;
31: import org.theospi.portfolio.matrix.model.Scaffolding;
32:
33: /**
34: * @author chmaurer
35: */
36: public class MoveLevelController implements Controller {
37:
38: protected final Log logger = LogFactory.getLog(getClass());
39:
40: /* (non-Javadoc)
41: * @see org.theospi.utils.mvc.intf.Controller#handleRequest(java.lang.Object, java.util.Map, java.util.Map, java.util.Map, org.springframework.validation.Errors)
42: */
43: public ModelAndView handleRequest(Object requestModel, Map request,
44: Map session, Map application, Errors errors) {
45: EditedScaffoldingStorage sessionBean = (EditedScaffoldingStorage) session
46: .get(EditedScaffoldingStorage.EDITED_SCAFFOLDING_STORAGE_SESSION_KEY);
47: Scaffolding scaffolding = sessionBean.getScaffolding();
48: Map model = new HashMap();
49:
50: String currentIndex = (String) request.get("current_index");
51: String destIndex = (String) request.get("dest_index");
52: if (currentIndex != null && destIndex != null) {
53: int current = Integer.parseInt(currentIndex);
54: int dest = Integer.parseInt(destIndex);
55: int max = scaffolding.getLevels().size() - 1;
56: if (dest == -1)
57: dest = max;
58: if (dest == max + 1)
59: dest = 0;
60: //remove then insert
61: Level obj = (Level) scaffolding.getLevels().remove(current);
62: scaffolding.getLevels().add(dest, obj);
63: }
64:
65: sessionBean.setScaffolding(scaffolding);
66: session
67: .put(
68: EditedScaffoldingStorage.EDITED_SCAFFOLDING_STORAGE_SESSION_KEY,
69: sessionBean);
70:
71: model.put(EditedScaffoldingStorage.STORED_SCAFFOLDING_FLAG,
72: "true");
73: return new ModelAndView("success", model);
74: }
75: }
|