001: package org.sakaiproject.metaobj.shared.control;
002:
003: import org.sakaiproject.metaobj.utils.mvc.intf.Controller;
004: import org.sakaiproject.metaobj.utils.mvc.intf.FormController;
005: import org.sakaiproject.metaobj.utils.mvc.intf.CancelableController;
006: import org.sakaiproject.metaobj.shared.mgt.StructuredArtifactDefinitionManager;
007: import org.sakaiproject.metaobj.shared.model.StructuredArtifactDefinitionBean;
008: import org.sakaiproject.content.api.ResourceEditingHelper;
009: import org.sakaiproject.content.api.ResourceToolActionPipe;
010: import org.sakaiproject.content.api.ResourceToolAction;
011: import org.sakaiproject.tool.api.ToolSession;
012: import org.sakaiproject.tool.api.ActiveTool;
013: import org.sakaiproject.tool.cover.ToolManager;
014: import org.sakaiproject.tool.cover.SessionManager;
015: import org.sakaiproject.site.api.Site;
016: import org.sakaiproject.site.cover.SiteService;
017: import org.sakaiproject.exception.IdUnusedException;
018: import org.springframework.web.servlet.ModelAndView;
019: import org.springframework.validation.Errors;
020:
021: import java.util.*;
022:
023: /**
024: * Created by IntelliJ IDEA.
025: * User: johnellis
026: * Date: Jan 29, 2007
027: * Time: 11:07:06 AM
028: * To change this template use File | Settings | File Templates.
029: */
030: public class FormCreateResourceHelper implements Controller,
031: FormController, CancelableController {
032:
033: private StructuredArtifactDefinitionManager structuredArtifactDefinitionManager;
034:
035: public ModelAndView handleRequest(Object requestModel, Map request,
036: Map session, Map application, Errors errors) {
037: FormCreateHelperBean bean = (FormCreateHelperBean) requestModel;
038:
039: if (bean.getFormId() == null || bean.getFormId().length() == 0) {
040: errors.rejectValue("formId", "FORM_ID_REQUIRED");
041: return null;
042: }
043:
044: session.put(ResourceEditingHelper.CREATE_SUB_TYPE, bean
045: .getFormId());
046:
047: return new ModelAndView("formHelper");
048: }
049:
050: public StructuredArtifactDefinitionManager getStructuredArtifactDefinitionManager() {
051: return structuredArtifactDefinitionManager;
052: }
053:
054: public void setStructuredArtifactDefinitionManager(
055: StructuredArtifactDefinitionManager structuredArtifactDefinitionManager) {
056: this .structuredArtifactDefinitionManager = structuredArtifactDefinitionManager;
057: }
058:
059: /**
060: * Create a map of all data the form requries.
061: * Useful for building up drop down lists, etc.
062: *
063: * @param request
064: * @param command
065: * @param errors
066: * @return ref data
067: */
068: public Map referenceData(Map request, Object command, Errors errors) {
069: Map ref = new Hashtable();
070:
071: Map<String, List> homes = getStructuredArtifactDefinitionManager()
072: .findCategorizedHomes(false);
073: List categorizedHomes = new ArrayList();
074: for (Iterator<String> i = homes.keySet().iterator(); i
075: .hasNext();) {
076: try {
077: Site site = SiteService.getSite(i.next());
078: List homesList = homes.get(site.getId());
079: Collections.sort(homesList);
080: categorizedHomes.add(new SiteHomeWrapper(site,
081: homesList));
082: } catch (IdUnusedException e) {
083: throw new RuntimeException(e);
084: }
085: }
086: Collections.sort(categorizedHomes);
087:
088: ref.put("categorizedFormList", categorizedHomes);
089: List globalHomes = getStructuredArtifactDefinitionManager()
090: .findGlobalHomes();
091: globalHomes = filterHidden(globalHomes);
092: Collections.sort(globalHomes);
093: ref.put("globalForms", globalHomes);
094: return ref;
095: }
096:
097: protected List filterHidden(List globalHomes) {
098: for (Iterator<StructuredArtifactDefinitionBean> i = globalHomes
099: .iterator(); i.hasNext();) {
100: if (i.next().isSystemOnly()) {
101: i.remove();
102: }
103: }
104:
105: return globalHomes;
106: }
107:
108: public boolean isCancel(Map request) {
109: Object cancel = request.get("canceling");
110: if (cancel == null) {
111: return false;
112: }
113: return cancel.equals("true");
114: }
115:
116: public ModelAndView processCancel(Map request, Map session,
117: Map application, Object command, Errors errors)
118: throws Exception {
119: ResourceToolActionPipe pipe = (ResourceToolActionPipe) session
120: .get(ResourceToolAction.ACTION_PIPE);
121: pipe.setActionCanceled(true);
122: pipe.setActionCompleted(false);
123: return new ModelAndView("cancel");
124: }
125:
126: }
|