01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-util/tool-lib/src/java/org/sakaiproject/metaobj/shared/control/PublishStructuredArtifactDefinitionController.java $
03: * $Id: PublishStructuredArtifactDefinitionController.java 14230 2006-09-05 18:02:51Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 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.sakaiproject.metaobj.shared.control;
21:
22: import java.util.Map;
23:
24: import org.sakaiproject.metaobj.shared.SharedFunctionConstants;
25: import org.sakaiproject.metaobj.shared.model.PersistenceException;
26: import org.sakaiproject.metaobj.shared.model.StructuredArtifactDefinitionBean;
27: import org.sakaiproject.metaobj.utils.mvc.intf.LoadObjectController;
28: import org.springframework.validation.Errors;
29: import org.springframework.web.servlet.ModelAndView;
30:
31: public class PublishStructuredArtifactDefinitionController extends
32: AbstractStructuredArtifactDefinitionController implements
33: LoadObjectController {
34: public final static String SITE_PUBLISH_ACTION = "site_publish";
35: public final static String GLOBAL_PUBLISH_ACTION = "global_publish";
36: public final static String SUGGEST_GLOBAL_PUBLISH_ACTION = "suggest_global_publish";
37:
38: public ModelAndView handleRequest(Object requestModel, Map request,
39: Map session, Map application, Errors errors) {
40: StructuredArtifactDefinitionBean sad = (StructuredArtifactDefinitionBean) requestModel;
41: if (sad.getAction().equals(SITE_PUBLISH_ACTION)) {
42: sad
43: .setSiteState(StructuredArtifactDefinitionBean.STATE_PUBLISHED);
44: checkPermission(SharedFunctionConstants.PUBLISH_ARTIFACT_DEF);
45: try {
46: getStructuredArtifactDefinitionManager().save(sad);
47: } catch (PersistenceException e) {
48: errors.rejectValue(e.getField(), e.getErrorCode(), e
49: .getErrorInfo(), e.getDefaultMessage());
50: }
51: }
52: if (sad.getAction().equals(GLOBAL_PUBLISH_ACTION)) {
53: sad
54: .setGlobalState(StructuredArtifactDefinitionBean.STATE_PUBLISHED);
55: sad.setSiteId(null);
56: checkPermission(SharedFunctionConstants.PUBLISH_ARTIFACT_DEF);
57: try {
58: getStructuredArtifactDefinitionManager().save(sad);
59: } catch (PersistenceException e) {
60: errors.rejectValue(e.getField(), e.getErrorCode(), e
61: .getErrorInfo(), e.getDefaultMessage());
62: }
63: }
64: if (sad.getAction().equals(SUGGEST_GLOBAL_PUBLISH_ACTION)) {
65: sad
66: .setGlobalState(StructuredArtifactDefinitionBean.STATE_WAITING_APPROVAL);
67: checkPermission(SharedFunctionConstants.SUGGEST_GLOBAL_PUBLISH_ARTIFACT_DEF);
68: try {
69: getStructuredArtifactDefinitionManager().save(sad);
70: } catch (PersistenceException e) {
71: errors.rejectValue(e.getField(), e.getErrorCode(), e
72: .getErrorInfo(), e.getDefaultMessage());
73: }
74: }
75:
76: return prepareListView(request, sad.getId().getValue());
77: }
78:
79: public ModelAndView processCancel(Map request, Map session,
80: Map application, Object command, Errors errors)
81: throws Exception {
82: return prepareListView(request, null);
83: }
84:
85: public Object fillBackingObject(Object incomingModel, Map request,
86: Map session, Map application) throws Exception {
87: StructuredArtifactDefinitionBean sad = (StructuredArtifactDefinitionBean) incomingModel;
88: String action = sad.getAction();
89: sad = getStructuredArtifactDefinitionManager().loadHome(
90: sad.getId());
91: sad.setAction(action);
92: return sad;
93: }
94:
95: }
|