0001: /**********************************************************************************
0002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/wizard/tool/src/java/org/theospi/portfolio/wizard/tool/WizardTool.java $
0003: * $Id: WizardTool.java 22351 2007-03-09 14:11:59Z bkirschn@umich.edu $
0004: ***********************************************************************************
0005: *
0006: * Copyright (c) 2005, 2006, 2007 The Sakai Foundation.
0007: *
0008: * Licensed under the Educational Community License, Version 1.0 (the "License");
0009: * you may not use this file except in compliance with the License.
0010: * You may obtain a copy of the License at
0011: *
0012: * http://www.opensource.org/licenses/ecl1.php
0013: *
0014: * Unless required by applicable law or agreed to in writing, software
0015: * distributed under the License is distributed on an "AS IS" BASIS,
0016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017: * See the License for the specific language governing permissions and
0018: * limitations under the License.
0019: *
0020: **********************************************************************************/package org.theospi.portfolio.wizard.tool;
0021:
0022: import org.apache.commons.logging.Log;
0023: import org.apache.commons.logging.LogFactory;
0024: import org.sakaiproject.assignment.taggable.api.TaggableActivity;
0025: import org.sakaiproject.assignment.taggable.api.TaggingManager;
0026: import org.sakaiproject.assignment.taggable.api.TaggingProvider;
0027: import org.sakaiproject.authz.api.Member;
0028: import org.sakaiproject.component.cover.ComponentManager;
0029: import org.sakaiproject.content.api.ContentHostingService;
0030: import org.sakaiproject.content.api.ContentResource;
0031: import org.sakaiproject.content.api.FilePickerHelper;
0032: import org.sakaiproject.entity.api.Reference;
0033: import org.sakaiproject.exception.IdUnusedException;
0034: import org.sakaiproject.exception.PermissionException;
0035: import org.sakaiproject.exception.TypeException;
0036: import org.sakaiproject.exception.ImportException;
0037: import org.sakaiproject.exception.UnsupportedFileTypeException;
0038: import org.sakaiproject.metaobj.security.AuthenticationManager;
0039: import org.sakaiproject.metaobj.shared.mgt.IdManager;
0040: import org.sakaiproject.metaobj.shared.model.Agent;
0041: import org.sakaiproject.metaobj.shared.model.Id;
0042: import org.sakaiproject.metaobj.shared.model.StructuredArtifactDefinitionBean;
0043: import org.sakaiproject.metaobj.shared.control.ToolFinishedView;
0044: import org.sakaiproject.metaobj.worksite.mgt.WorksiteManager;
0045: import org.sakaiproject.site.api.Group;
0046: import org.sakaiproject.site.api.Site;
0047: import org.sakaiproject.site.cover.SiteService;
0048: import org.sakaiproject.tool.api.*;
0049: import org.sakaiproject.tool.cover.SessionManager;
0050: import org.sakaiproject.tool.cover.ToolManager;
0051: import org.sakaiproject.user.api.User;
0052: import org.sakaiproject.user.api.UserNotDefinedException;
0053: import org.sakaiproject.user.cover.UserDirectoryService;
0054: import org.theospi.portfolio.guidance.mgt.GuidanceHelper;
0055: import org.theospi.portfolio.guidance.mgt.GuidanceManager;
0056: import org.theospi.portfolio.guidance.model.Guidance;
0057: import org.theospi.portfolio.matrix.MatrixFunctionConstants;
0058: import org.theospi.portfolio.matrix.MatrixManager;
0059: import org.theospi.portfolio.matrix.WizardPageHelper;
0060: import org.theospi.portfolio.matrix.model.WizardPage;
0061: import org.theospi.portfolio.review.ReviewHelper;
0062: import org.theospi.portfolio.review.mgt.ReviewManager;
0063: import org.theospi.portfolio.review.model.Review;
0064: import org.theospi.portfolio.security.AudienceSelectionHelper;
0065: import org.theospi.portfolio.security.Authorization;
0066: import org.theospi.portfolio.security.AuthorizationFacade;
0067: import org.theospi.portfolio.shared.model.OspException;
0068: import org.theospi.portfolio.shared.tool.BuilderScreen;
0069: import org.theospi.portfolio.shared.tool.BuilderTool;
0070: import org.theospi.portfolio.style.StyleHelper;
0071: import org.theospi.portfolio.wizard.WizardFunctionConstants;
0072: import org.theospi.portfolio.wizard.mgt.WizardManager;
0073: import org.theospi.portfolio.wizard.model.CompletedWizard;
0074: import org.theospi.portfolio.wizard.model.CompletedWizardPage;
0075: import org.theospi.portfolio.wizard.model.Wizard;
0076: import org.theospi.portfolio.wizard.model.WizardPageSequence;
0077: import org.theospi.portfolio.wizard.taggable.api.WizardActivityProducer;
0078: import org.theospi.portfolio.workflow.mgt.WorkflowManager;
0079:
0080: import javax.faces.context.ExternalContext;
0081: import javax.faces.context.FacesContext;
0082:
0083: import java.io.IOException;
0084: import java.text.MessageFormat;
0085: import java.util.*;
0086:
0087: public class WizardTool extends BuilderTool {
0088:
0089: static final private String BAD_FILE_TYPE_ID = "badFileType";
0090: static final private String BAD_IMPORT_ID = "badImport";
0091:
0092: protected final Log logger = LogFactory.getLog(getClass());
0093:
0094: private WizardManager wizardManager;
0095: private GuidanceManager guidanceManager;
0096: private AuthenticationManager authManager;
0097: private AuthorizationFacade authzManager;
0098: private MatrixManager matrixManager;
0099: private WorkflowManager workflowManager;
0100: private ContentHostingService contentHosting;
0101: private ReviewManager reviewManager;
0102: private TaggingManager taggingManager;
0103: private WizardActivityProducer wizardActivityProducer;
0104:
0105: private IdManager idManager;
0106: private DecoratedWizard current = null;
0107: private DecoratedWizardPage currentPage = null;
0108:
0109: private String expandedGuidanceSection = "false";
0110: private List wizardTypes = null;
0111: private DecoratedCategory currentCategory;
0112: private DecoratedCategoryChild moveCategoryChild;
0113: private List deletedItems = new ArrayList();
0114: private int nextWizard = 0;
0115: private String currentUserId;
0116:
0117: private String lastSaveWizard = "";
0118: private boolean pageSaved = false;
0119: private String lastSavePage = "";
0120: private String lastError = "";
0121:
0122: private boolean loadCompletedWizard = false;
0123:
0124: // import variables
0125: private String importFilesString = "";
0126: private List importFiles = new ArrayList();
0127:
0128: // Constants
0129:
0130: public final static String LIST_PAGE = "listWizards";
0131: public final static String EDIT_PAGE = "editWizard";
0132: public final static String EDIT_PAGE_TYPE = "editWizardType";
0133: public final static String EDIT_PAGES_PAGE = "editWizardPages";
0134: public final static String EDIT_SUPPORT_PAGE = "editWizardSupport";
0135: public final static String EDIT_DESIGN_PAGE = "editWizardDesign";
0136: public final static String EDIT_PROPERTIES_PAGE = "editWizardProperties";
0137: public final static String CONFIRM_SUBMIT_PAGE = "confirmSubmit";
0138: public final static String IMPORT_PAGE = "importWizard";
0139: public final static String CONFIRM_DELETE_PAGE = "confirmDeleteWizard";
0140: public final static String CANCEL_RUN_WIZARD_PAGE = "runWizardEnd";
0141:
0142: private BuilderScreen[] screens = {
0143: // new BuilderScreen(EDIT_PAGE_TYPE),
0144: new BuilderScreen(EDIT_PAGE),
0145: new BuilderScreen(EDIT_SUPPORT_PAGE),
0146: new BuilderScreen(EDIT_PAGES_PAGE),
0147: // new BuilderScreen(EDIT_DESIGN_PAGE),
0148: // new BuilderScreen(EDIT_PROPERTIES_PAGE)
0149: };
0150:
0151: public WizardTool() {
0152: setScreens(screens);
0153: }
0154:
0155: protected void saveScreen(BuilderScreen screen) {
0156: processActionSave(screen.getNavigationKey());
0157: }
0158:
0159: public WizardManager getWizardManager() {
0160: return wizardManager;
0161: }
0162:
0163: public void setWizardManager(WizardManager wizardManager) {
0164: this .wizardManager = wizardManager;
0165: }
0166:
0167: /**
0168: * @return Returns the currentUserId.
0169: */
0170: public String getCurrentUserId() {
0171: return currentUserId;
0172: }
0173:
0174: /**
0175: * @param currentUserId The currentUserId to set.
0176: */
0177: public void setCurrentUserId(String currentUserId) {
0178: this .currentUserId = currentUserId;
0179: }
0180:
0181: public String getOwnerCheckMessage() {
0182: String message = "";
0183: String readOnly = "";
0184: try {
0185: if (currentUserId == null)
0186: setCurrentUserId(SessionManager
0187: .getCurrentSessionUserId());
0188:
0189: if (!currentUserId.equalsIgnoreCase(SessionManager
0190: .getCurrentSessionUserId())) {
0191: readOnly = getMessageFromBundle("read_only");
0192: }
0193: User user = UserDirectoryService.getUser(currentUserId);
0194: message = getMessageFromBundle("wizard_owner_message",
0195: new Object[] { readOnly, user.getDisplayName() });
0196: } catch (UserNotDefinedException e) {
0197: throw new OspException(e);
0198: }
0199:
0200: return message;
0201: }
0202:
0203: public boolean isFromEvaluation() {
0204: ToolSession session = SessionManager.getCurrentToolSession();
0205:
0206: if (session.getAttribute("is_eval_page_id") != null) {
0207: return true;
0208: }
0209:
0210: return false;
0211: }
0212:
0213: public DecoratedWizard getCurrent() {
0214: ToolSession session = SessionManager.getCurrentToolSession();
0215:
0216: //WIZARD_RESET_CURRENT gets set in the WizardListGenerator
0217: String resetCurrent = (String) session
0218: .getAttribute("WIZARD_RESET_CURRENT");
0219:
0220: if (current == null
0221: || (resetCurrent != null && resetCurrent.equals("true"))) {
0222: //This should have come from the eval tool...
0223: String id = (String) session
0224: .getAttribute("CURRENT_WIZARD_ID");
0225: String userId = "";
0226: if (id != null) {
0227: userId = (String) session
0228: .getAttribute("WIZARD_USER_ID");
0229: session.removeAttribute("WIZARD_USER_ID");
0230: session.removeAttribute("CURRENT_WIZARD_ID");
0231: session.removeAttribute("WIZARD_RESET_CURRENT");
0232: this .setCurrentUserId(userId);
0233: } else {
0234: Placement placement = ToolManager.getCurrentPlacement();
0235:
0236: id = placement.getPlacementConfig().getProperty(
0237: WizardManager.EXPOSED_WIZARD_KEY);
0238: userId = SessionManager.getCurrentSessionUserId();
0239: this .setCurrentUserId(userId);
0240: }
0241: if (id == null)
0242: return null;
0243: Wizard wizard = getWizardManager().getWizard(id,
0244: WizardManager.WIZARD_OPERATE_CHECK);
0245: if (wizard == null)
0246: return null;
0247: setCurrent(new DecoratedWizard(this , wizard));
0248:
0249: loadCompletedWizard = true;
0250: }
0251: if (loadCompletedWizard) {
0252: current.setRunningWizard(new DecoratedCompletedWizard(this ,
0253: current, getWizardManager().getCompletedWizard(
0254: current.getBase(), getCurrentUserId())));
0255: loadCompletedWizard = false;
0256: }
0257: Wizard wizard = current.getBase();
0258:
0259: if (session.getAttribute(GuidanceManager.CURRENT_GUIDANCE) != null) {
0260: Guidance guidance = (Guidance) session
0261: .getAttribute(GuidanceManager.CURRENT_GUIDANCE);
0262: wizard.setGuidanceId(guidance.getId());
0263:
0264: session.removeAttribute(GuidanceManager.CURRENT_GUIDANCE);
0265: setExpandedGuidanceSection("true");
0266: }
0267: if (wizard.getGuidanceId() != null
0268: && wizard.getGuidance() == null) {
0269: wizard.setGuidance(getGuidanceManager().getGuidance(
0270: wizard.getGuidanceId()));
0271: }
0272:
0273: if (wizard.getExposedPageId() != null
0274: && !wizard.getExposedPageId().equals("")
0275: && (wizard.getExposeAsTool() == null || wizard
0276: .getExposeAsTool().booleanValue())) {
0277: wizard.setExposeAsTool(new Boolean(true));
0278: }
0279:
0280: return current;
0281: }
0282:
0283: public void setCurrent(DecoratedWizard current) {
0284: this .current = current;
0285: }
0286:
0287: public Reference decorateReference(String reference) {
0288: return getWizardManager().decorateReference(
0289: getCurrent().getBase(), reference);
0290: }
0291:
0292: public List getWizards() {
0293: Placement placement = ToolManager.getCurrentPlacement();
0294: String currentSiteId = placement.getContext();
0295: List returned = new ArrayList();
0296:
0297: String user = currentUserId != null ? currentUserId
0298: : SessionManager.getCurrentSessionUserId();
0299: setCurrentUserId(user);
0300:
0301: List wizards = getWizardManager().listAllWizardsByOwner(user,
0302: currentSiteId);
0303:
0304: DecoratedWizard lastWizard = null;
0305:
0306: for (Iterator i = wizards.iterator(); i.hasNext();) {
0307: Wizard wizard = (Wizard) i.next();
0308: DecoratedWizard current = new DecoratedWizard(this , wizard);
0309: current.setTotalPages(getWizardManager().getTotalPageCount(
0310: wizard));
0311: returned.add(current);
0312: if (lastWizard != null) {
0313: lastWizard.setNext(current);
0314: current.setPrev(lastWizard);
0315: }
0316: lastWizard = current;
0317: }
0318:
0319: if (lastWizard != null) {
0320: setNextWizard(lastWizard.getBase().getSequence() + 1);
0321: }
0322:
0323: return returned;
0324: }
0325:
0326: public void clearInterface() {
0327: lastSaveWizard = "";
0328: pageSaved = false;
0329: lastSavePage = "";
0330: lastError = "";
0331: }
0332:
0333: public String processActionPublish(Wizard wizard) {
0334: clearInterface();
0335: getWizardManager().deletePreviewWizardData(wizard);
0336: getWizardManager().publishWizard(wizard);
0337: current = null;
0338: return LIST_PAGE;
0339: }
0340:
0341: public String processActionPreview(Wizard wizard) {
0342: clearInterface();
0343: getWizardManager().previewWizard(wizard);
0344: current = null;
0345: return LIST_PAGE;
0346: }
0347:
0348: public String processActionEdit(Wizard wizard) {
0349: clearInterface();
0350: wizard = getWizardManager().getWizard(wizard.getId(),
0351: WizardManager.WIZARD_EDIT_CHECK);
0352: setCurrent(new DecoratedWizard(this , wizard, false));
0353: return startBuilder();
0354: }
0355:
0356: public String processActionDelete(Wizard wizard) {
0357: clearInterface();
0358:
0359: if (getTaggingManager().isTaggable()) {
0360: List<WizardPageSequence> pages = wizard.getRootCategory()
0361: .getChildPages();
0362: for (WizardPageSequence page : pages) {
0363: removeTags(page);
0364: }
0365: }
0366:
0367: getWizardManager().deleteWizard(wizard);
0368: current = null;
0369: return LIST_PAGE;
0370: }
0371:
0372: public String processActionConfirmDelete(Wizard wizard) {
0373: clearInterface();
0374: setCurrent(new DecoratedWizard(this , wizard, false));
0375: return CONFIRM_DELETE_PAGE;
0376: }
0377:
0378: public String processActionCancel() {
0379: clearInterface();
0380: setCurrent(null);
0381: cancelBoundValues();
0382: return LIST_PAGE;
0383: }
0384:
0385: /**
0386: * This function is used to cancel a running wizard. This will
0387: * ensure that the user is returned to the caller correctly (aka the list wizard page)
0388: * @return String next page, this is null
0389: */
0390: public String processActionCancelRun() {
0391: processActionCancel();
0392: return returnToCaller();
0393: }
0394:
0395: /**
0396: * This function is used to cancel a running wizard. This will
0397: * ensure that the user is returned to the caller correctly (aka the list wizard page)
0398: * @return String next page, this is null
0399: */
0400: public String getCancelTool() {
0401: processActionCancel();
0402: returnToCaller();
0403: return "";
0404: }
0405:
0406: public String processActionChangeUser() {
0407: clearInterface();
0408: return LIST_PAGE;
0409: }
0410:
0411: protected Id cleanBlankId(String id) {
0412: if (id.equals(""))
0413: return null;
0414: return getIdManager().getId(id);
0415: }
0416:
0417: public String processActionSaveFinished() {
0418: clearInterface();
0419: processActionSave(getCurrentScreen().getNavigationKey());
0420: return LIST_PAGE;
0421: }
0422:
0423: protected void processActionSave(String currentView) {
0424: clearInterface();
0425: if (currentView.equals(EDIT_PAGE)
0426: && getCurrent().getBase().getType().equals(
0427: WizardFunctionConstants.WIZARD_TYPE_SEQUENTIAL)) {
0428: boolean foundOne = false;
0429: List pageList = getCurrent().getRootCategory().getBase()
0430: .getChildPages();
0431: List decoratedPageList = getCurrent().getRootCategory()
0432: .getCategoryPageList();
0433: for (Iterator i = decoratedPageList.iterator(); i.hasNext();) {
0434: DecoratedWizardPage page = (DecoratedWizardPage) i
0435: .next();
0436: if (!pageList.contains(page.getBase())) {
0437: pageList.add(page.getBase());
0438: page.getBase().setCategory(
0439: getCurrent().getRootCategory().getBase());
0440: foundOne = true;
0441: }
0442: }
0443: if (foundOne) {
0444: getCurrent().getRootCategory().resequencePages();
0445: }
0446: }
0447:
0448: if (getTaggingManager().isTaggable()) {
0449: Iterator i = deletedItems.iterator();
0450: while (i.hasNext()) {
0451: Object obj = i.next();
0452: if (obj instanceof WizardPageSequence) {
0453: removeTags((WizardPageSequence) obj);
0454: }
0455: }
0456: }
0457:
0458: getWizardManager().deleteObjects(deletedItems);
0459: deletedItems.clear();
0460: Wizard wizard = getCurrent().getBase();
0461: wizard.setEvalWorkflows(getWorkflowManager()
0462: .createEvalWorkflows(wizard));
0463:
0464: getWizardManager().saveWizard(wizard);
0465: }
0466:
0467: protected void removeTags(WizardPageSequence ps) {
0468: for (TaggingProvider provider : getTaggingManager()
0469: .getProviders()) {
0470: TaggableActivity activity = getWizardActivityProducer()
0471: .getActivity(ps.getWizardPageDefinition());
0472: try {
0473: provider.removeTags(activity);
0474: } catch (PermissionException pe) {
0475: logger.error(pe.getMessage(), pe);
0476: }
0477: }
0478: }
0479:
0480: public String processActionNew() {
0481: clearInterface();
0482: Session session = SessionManager.getCurrentSession();
0483: Wizard newWizard = getWizardManager().createNew();
0484: newWizard.setSequence(getNextWizard());
0485:
0486: setCurrent(new DecoratedWizard(this , newWizard, true));
0487: session.setAttribute("newWizard", "true");
0488:
0489: return EDIT_PAGE_TYPE;
0490: }
0491:
0492: public void processSubmitWizard(CompletedWizard completedWizard) {
0493: clearInterface();
0494: completedWizard
0495: .setStatus(MatrixFunctionConstants.PENDING_STATUS);
0496: getWizardManager().saveWizard(completedWizard);
0497: lastSaveWizard = completedWizard.getWizard().getName();
0498: }
0499:
0500: public String processActionNewSteps() {
0501: return startBuilder();
0502: }
0503:
0504: public String processActionRemoveGuidance() {
0505: clearInterface();
0506: //Placement placement = ToolManager.getCurrentPlacement();
0507: //String currentSite = placement.getContext();
0508: Wizard wizard = getCurrent().getBase();
0509: getGuidanceManager().deleteGuidance(wizard.getGuidance());
0510: wizard.setGuidance(null);
0511: //session.setAttribute(WizardManager.CURRENT_WIZARD, getCurrent().getBase());
0512:
0513: return getCurrentScreen().getNavigationKey();
0514: }
0515:
0516: public void processActionGuidanceHelper(Wizard w, int types) {
0517: clearInterface();
0518: showGuidance(w, "tool", (types & 1) != 0, (types & 2) != 0,
0519: (types & 4) != 0);
0520: }
0521:
0522: public void processActionGuidanceHelper() {
0523: clearInterface();
0524: processActionGuidanceHelper(getCurrent().getBase(), 7);
0525: }
0526:
0527: public void processActionViewGuidance() {
0528: clearInterface();
0529: showGuidance(getCurrent().getBase(), "view", true, true, true);
0530: }
0531:
0532: protected void showGuidance(Wizard wizard, String view,
0533: boolean instructions, boolean rationale, boolean examples) {
0534: ExternalContext context = FacesContext.getCurrentInstance()
0535: .getExternalContext();
0536: //Tool tool = ToolManager.getCurrentTool();
0537: ToolSession session = SessionManager.getCurrentToolSession();
0538:
0539: Placement placement = ToolManager.getCurrentPlacement();
0540: String currentSite = placement.getContext();
0541: //session.setAttribute(tool.getId() + Tool.HELPER_DONE_URL, "");
0542: //session.setAttribute(WizardManager.CURRENT_WIZARD_ID, getCurrent().getBase().getId());
0543: //Wizard wizard = getCurrent().getBase();
0544:
0545: Guidance guidance = wizard.getGuidance();
0546: if (guidance == null) {
0547: guidance = getGuidanceManager().createNew(
0548: wizard.getName() + " Guidance", currentSite,
0549: wizard.getId(),
0550: WizardFunctionConstants.OPERATE_WIZARD,
0551: WizardFunctionConstants.EDIT_WIZARD);
0552: }
0553:
0554: session.setAttribute(GuidanceHelper.SHOW_INSTRUCTION_FLAG,
0555: new Boolean(instructions));
0556: session.setAttribute(GuidanceHelper.SHOW_RATIONALE_FLAG,
0557: new Boolean(rationale));
0558: session.setAttribute(GuidanceHelper.SHOW_EXAMPLE_FLAG,
0559: new Boolean(examples));
0560:
0561: session
0562: .setAttribute(GuidanceManager.CURRENT_GUIDANCE,
0563: guidance);
0564:
0565: try {
0566: context.redirect("osp.guidance.helper/" + view);
0567: } catch (IOException e) {
0568: throw new RuntimeException("Failed to redirect to helper",
0569: e);
0570: }
0571: }
0572:
0573: public String processExecPage(WizardPageSequence pageSeq) {
0574: clearInterface();
0575: ExternalContext context = FacesContext.getCurrentInstance()
0576: .getExternalContext();
0577: ToolSession session = SessionManager.getCurrentToolSession();
0578:
0579: WizardPage page = null;
0580:
0581: List cpages = getWizardManager()
0582: .getCompletedWizardPagesByPageDef(
0583: pageSeq.getWizardPageDefinition().getId());
0584: String currentUser = getCurrentUserId();
0585: for (Iterator i = cpages.iterator(); i.hasNext();) {
0586: CompletedWizardPage wizpage = (CompletedWizardPage) i
0587: .next();
0588:
0589: WizardPage wpage = getMatrixManager().getWizardPage(
0590: wizpage.getWizardPage().getId());
0591: if (currentUser.equalsIgnoreCase(wpage.getOwner().getId()
0592: .getValue())) {
0593: page = wpage;
0594: break;
0595: }
0596: }
0597: if (page == null)
0598: throw new NullPointerException(
0599: "Failed to find the requested page");
0600:
0601: session
0602: .removeAttribute(WizardPageHelper.SEQUENTIAL_WIZARD_PAGES);
0603: session
0604: .removeAttribute(WizardPageHelper.SEQUENTIAL_WIZARD_CURRENT_STEP);
0605:
0606: session.setAttribute(WizardPageHelper.WIZARD_PAGE, page);
0607: String redirectAddress = "osp.wizard.page.helper/wizardPage.osp";
0608:
0609: if (!getCurrentUserId().equalsIgnoreCase(
0610: SessionManager.getCurrentSessionUserId()))
0611: session.setAttribute("readOnlyMatrix", "true");
0612: session.setAttribute(WizardPageHelper.WIZARD_OWNER,
0613: getCurrent().getRunningWizard().getBase().getOwner());
0614:
0615: if (WizardFunctionConstants.WIZARD_TYPE_SEQUENTIAL
0616: .equals(getCurrent().getBase().getType())) {
0617: redirectAddress = "osp.wizard.page.helper/sequentialWizardPage.osp";
0618: }
0619:
0620: try {
0621: context.redirect(redirectAddress);
0622: } catch (IOException e) {
0623: throw new RuntimeException("Failed to redirect to helper",
0624: e);
0625: }
0626:
0627: return null;
0628: }
0629:
0630: public String processExecPages() {
0631: clearInterface();
0632: ExternalContext context = FacesContext.getCurrentInstance()
0633: .getExternalContext();
0634: ToolSession session = SessionManager.getCurrentToolSession();
0635:
0636: CompletedWizard cwiz = current.getRunningWizard().getBase();
0637:
0638: ArrayList pages = new ArrayList();
0639:
0640: for (Iterator i = cwiz.getRootCategory().getChildPages()
0641: .iterator(); i.hasNext();) {
0642: CompletedWizardPage wizpage = (CompletedWizardPage) i
0643: .next();
0644:
0645: WizardPage page = getMatrixManager().getWizardPage(
0646: wizpage.getWizardPage().getId());
0647: pages.add(page);
0648: }
0649:
0650: session.setAttribute(WizardPageHelper.WIZARD_PAGE, pages);
0651: String redirectAddress = "osp.wizard.page.helper/wizardPage.osp";
0652:
0653: if (!getCurrentUserId().equalsIgnoreCase(
0654: SessionManager.getCurrentSessionUserId()))
0655: session.setAttribute("readOnlyMatrix", "true");
0656: session.setAttribute(WizardPageHelper.WIZARD_OWNER,
0657: getCurrent().getRunningWizard().getBase().getOwner());
0658:
0659: session
0660: .removeAttribute(WizardPageHelper.SEQUENTIAL_WIZARD_PAGES);
0661: session
0662: .removeAttribute(WizardPageHelper.SEQUENTIAL_WIZARD_CURRENT_STEP);
0663:
0664: Map map = (Map) session
0665: .getAttribute(ToolFinishedView.ALTERNATE_DONE_URL_MAP);
0666:
0667: if (map == null) {
0668: map = new HashMap();
0669: }
0670:
0671: if (WizardFunctionConstants.WIZARD_TYPE_SEQUENTIAL
0672: .equals(getCurrent().getBase().getType())) {
0673: session.setAttribute(
0674: WizardPageHelper.SEQUENTIAL_WIZARD_PAGES, pages);
0675: session.setAttribute(
0676: WizardPageHelper.SEQUENTIAL_WIZARD_CURRENT_STEP,
0677: new Integer(0));
0678: redirectAddress = "osp.wizard.page.helper/sequentialWizardPage.osp";
0679:
0680: // this page goes to back to the list page
0681: map.put("finishSeqWizard", CANCEL_RUN_WIZARD_PAGE);
0682: }
0683:
0684: map.put("submitWizard", CONFIRM_SUBMIT_PAGE);
0685:
0686: // this page goes to back to the list page
0687: map.put("submitWizardPage", CANCEL_RUN_WIZARD_PAGE);
0688: session.setAttribute(ToolFinishedView.ALTERNATE_DONE_URL_MAP,
0689: map);
0690:
0691: try {
0692: context.redirect(redirectAddress);
0693: } catch (IOException e) {
0694: throw new RuntimeException("Failed to redirect to helper",
0695: e);
0696: }
0697:
0698: return null;
0699: }
0700:
0701: public void processEditReflection() {
0702: ExternalContext context = FacesContext.getCurrentInstance()
0703: .getExternalContext();
0704: ToolSession session = SessionManager.getCurrentToolSession();
0705:
0706: //CWM use a constant for the below values
0707: session.setAttribute("process_type_key",
0708: CompletedWizard.PROCESS_TYPE_KEY);
0709: session.setAttribute(CompletedWizard.PROCESS_TYPE_KEY, current
0710: .getRunningWizard().getBase().getId().getValue());
0711: session.setAttribute(ReviewHelper.REVIEW_TYPE_KEY, Integer
0712: .toString(Review.REFLECTION_TYPE));
0713:
0714: try {
0715: context
0716: .redirect("osp.review.processor.helper/reviewHelper.osp?current_review_id="
0717: + ((Review) current.getRunningWizard()
0718: .getReflections().get(0))
0719: .getReviewContentNode()
0720: .getResource().getId());
0721: } catch (IOException e) {
0722: throw new RuntimeException("Failed to redirect to helper",
0723: e);
0724: }
0725: }
0726:
0727: /**
0728: * This is the action for redirecting the user to the "add reflection" form for
0729: * to a completed wizard.
0730: */
0731: public void processActionReflection() {
0732: processActionReviewHelper(Review.REFLECTION_TYPE);
0733: }
0734:
0735: /**
0736: * This is the action for redirecting the user to the "add evaluation" form for
0737: * to a completed wizard.
0738: */
0739: public void processActionEvaluate() {
0740: if (getCanEvaluate())
0741: processActionReviewHelper(Review.EVALUATION_TYPE);
0742: }
0743:
0744: /**
0745: * This is the action for redirecting the user to the "add feedback/review" form for
0746: * to a completed wizard.
0747: */
0748: public void processActionReview() {
0749: processActionReviewHelper(Review.FEEDBACK_TYPE);
0750: }
0751:
0752: protected void processActionReviewHelper(int type) {
0753: ExternalContext context = FacesContext.getCurrentInstance()
0754: .getExternalContext();
0755: ToolSession session = SessionManager.getCurrentToolSession();
0756:
0757: //CWM use a constant for the below values
0758: session.setAttribute("process_type_key",
0759: CompletedWizard.PROCESS_TYPE_KEY);
0760: session.setAttribute(CompletedWizard.PROCESS_TYPE_KEY, current
0761: .getRunningWizard().getBase().getId().getValue());
0762: session.setAttribute(ReviewHelper.REVIEW_TYPE_KEY, Integer
0763: .toString(type));
0764: Wizard wiz = current.getBase();
0765:
0766: // we want to have this reload when we come back
0767: current.setRunningWizard(null);
0768: loadCompletedWizard = true;
0769:
0770: String urlParams = "?objectId=" + wiz.getId() + "&objectTitle="
0771: + wiz.getName() + "&objectDesc=" + wiz.getDescription();
0772:
0773: try {
0774: context
0775: .redirect("osp.review.processor.helper/reviewHelper.osp"
0776: + urlParams);
0777: } catch (IOException e) {
0778: throw new RuntimeException("Failed to redirect to helper",
0779: e);
0780: }
0781: }
0782:
0783: public void processActionAudienceHelper() {
0784: ExternalContext context = FacesContext.getCurrentInstance()
0785: .getExternalContext();
0786: //Tool tool = ToolManager.getCurrentTool();
0787: ToolSession session = SessionManager.getCurrentToolSession();
0788:
0789: //Placement placement = ToolManager.getCurrentPlacement();
0790: //String currentSite = placement.getContext();
0791: Wizard wizard = getCurrent().getBase();
0792:
0793: session.setAttribute(AudienceSelectionHelper.AUDIENCE_FUNCTION,
0794: WizardFunctionConstants.EVALUATE_WIZARD);
0795: session.setAttribute(
0796: AudienceSelectionHelper.AUDIENCE_QUALIFIER, wizard
0797: .getId().getValue());
0798: session.setAttribute(
0799: AudienceSelectionHelper.AUDIENCE_INSTRUCTIONS,
0800: getMessageFromBundle("audience_instructions"));
0801: session.setAttribute(
0802: AudienceSelectionHelper.AUDIENCE_GLOBAL_TITLE,
0803: getMessageFromBundle("audience_global_title"));
0804: session.setAttribute(
0805: AudienceSelectionHelper.AUDIENCE_INDIVIDUAL_TITLE,
0806: getMessageFromBundle("audience_individual_title"));
0807: session.setAttribute(
0808: AudienceSelectionHelper.AUDIENCE_GROUP_TITLE,
0809: getMessageFromBundle("audience_group_title"));
0810: session.setAttribute(
0811: AudienceSelectionHelper.AUDIENCE_PUBLIC_FLAG, "false");
0812: session.setAttribute(
0813: AudienceSelectionHelper.AUDIENCE_PUBLIC_TITLE, null);
0814: session.setAttribute(
0815: AudienceSelectionHelper.AUDIENCE_SELECTED_TITLE,
0816: getMessageFromBundle("audience_selected_title"));
0817: session.setAttribute(
0818: AudienceSelectionHelper.AUDIENCE_FILTER_INSTRUCTIONS,
0819: getMessageFromBundle("audience_filter_instructions"));
0820: session.setAttribute(
0821: AudienceSelectionHelper.AUDIENCE_GUEST_EMAIL, null);
0822:
0823: session.setAttribute(
0824: AudienceSelectionHelper.AUDIENCE_WORKSITE_LIMITED,
0825: "true");
0826: session.setAttribute(
0827: AudienceSelectionHelper.AUDIENCE_BROWSE_INDIVIDUAL,
0828: getMessageFromBundle("audience_browse_individual"));
0829:
0830: //Guidance guidance = wizard.getGuidance();
0831: //if (guidance == null) {
0832: // guidance = getGuidanceManager().createNew(wizard.getName() + " Guidance", currentSite, null, "", "");
0833: //}
0834:
0835: //session.setAttribute(GuidanceManager.CURRENT_GUIDANCE, guidance);
0836:
0837: try {
0838: context.redirect("osp.audience.helper/tool.jsf?panel=Main");
0839: } catch (IOException e) {
0840: throw new RuntimeException("Failed to redirect to helper",
0841: e);
0842: }
0843: }
0844:
0845: public boolean isMaintainer() {
0846: return new Boolean(getAuthzManager()
0847: .isAuthorized(
0848: WorksiteManager.WORKSITE_MAINTAIN,
0849: getIdManager().getId(
0850: ToolManager.getCurrentPlacement()
0851: .getContext()))).booleanValue();
0852: }
0853:
0854: public String processPermissions() {
0855: clearInterface();
0856: ExternalContext context = FacesContext.getCurrentInstance()
0857: .getExternalContext();
0858:
0859: //todo userCan = null;
0860:
0861: try {
0862: context.redirect("osp.permissions.helper/editPermissions?"
0863: + "message=" + getPermissionsMessage()
0864: + "&name=wizard" + "&qualifier="
0865: + ToolManager.getCurrentPlacement().getContext()
0866: + "&returnView=matrixRedirect");
0867: } catch (IOException e) {
0868: throw new RuntimeException("Failed to redirect to helper",
0869: e);
0870: }
0871: return null;
0872: }
0873:
0874: public String getPermissionsMessage() {
0875: return getMessageFromBundle("perm_description", new Object[] {
0876: getTool().getTitle(), getWorksite().getTitle() });
0877: }
0878:
0879: public Tool getTool() {
0880: return ToolManager.getCurrentTool();
0881: }
0882:
0883: public Site getWorksite() {
0884: try {
0885: return SiteService.getSite(ToolManager
0886: .getCurrentPlacement().getContext());
0887: } catch (IdUnusedException e) {
0888: throw new OspException(e);
0889: }
0890: }
0891:
0892: public String importWizard() {
0893: return IMPORT_PAGE;
0894: }
0895:
0896: public String processPickImportFiles() {
0897: clearInterface();
0898: ExternalContext context = FacesContext.getCurrentInstance()
0899: .getExternalContext();
0900: ToolSession session = SessionManager.getCurrentToolSession();
0901: session.setAttribute(FilePickerHelper.FILE_PICKER_ATTACH_LINKS,
0902: new Boolean(true).toString());
0903: /*
0904: List wsItemRefs = EntityManager.newReferenceList();
0905:
0906: for (Iterator i=importFiles.iterator();i.hasNext();) {
0907: WizardStyleItem wsItem = (WizardStyleItem)i.next();
0908: wsItemRefs.add(wsItem.getBaseReference().getBase());
0909: }*/
0910:
0911: session.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS,
0912: importFiles);
0913: session
0914: .setAttribute(
0915: FilePickerHelper.FILE_PICKER_RESOURCE_FILTER,
0916: ComponentManager
0917: .get("org.sakaiproject.content.api.ContentResourceFilter.wizardImportFile"));
0918:
0919: try {
0920: context.redirect("sakai.filepicker.helper/tool");
0921: } catch (IOException e) {
0922: throw new RuntimeException("Failed to redirect to helper",
0923: e);
0924: }
0925: return null;
0926: }
0927:
0928: /**
0929: * This is called to put the file names into the text box.
0930: * It updates the list of files if the user is returning from the file picker
0931: * @return String the names of the files being imported
0932: */
0933: public String getImportFilesString() {
0934: ToolSession session = SessionManager.getCurrentToolSession();
0935: if (session.getAttribute(FilePickerHelper.FILE_PICKER_CANCEL) == null
0936: && session
0937: .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS) != null) {
0938:
0939: List refs = (List) session
0940: .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
0941: //importFiles.clear();
0942: importFilesString = "";
0943: for (int i = 0; i < refs.size(); i++) {
0944: Reference ref = (Reference) refs.get(i);
0945: String nodeId = getContentHosting()
0946: .getUuid(ref.getId());
0947: String id = getContentHosting().resolveUuid(nodeId);
0948:
0949: ContentResource resource = null;
0950: try {
0951: resource = getContentHosting().getResource(id);
0952: } catch (PermissionException pe) {
0953: logger
0954: .warn(
0955: "Failed loading content: no permission to view file",
0956: pe);
0957: } catch (TypeException pe) {
0958: logger.warn("Wrong type", pe);
0959: } catch (IdUnusedException pe) {
0960: logger.warn("UnusedId: ", pe);
0961: }
0962:
0963: importFilesString += resource.getProperties()
0964: .getProperty(
0965: resource.getProperties()
0966: .getNamePropDisplayName())
0967: + " ";
0968: }
0969: importFiles = refs;
0970: session
0971: .removeAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
0972: } else if (session
0973: .getAttribute(FilePickerHelper.FILE_PICKER_CANCEL) == null
0974: && session
0975: .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS) == null) {
0976: importFiles.clear();
0977: importFilesString = "";
0978: }
0979:
0980: return importFilesString;
0981: }
0982:
0983: public void setImportFilesString(String importFilesString) {
0984: this .importFilesString = importFilesString;
0985: }
0986:
0987: /**
0988: * Called when the user clicks the Import Button
0989: * @return String next view
0990: */
0991: public String processImportWizards() {
0992: clearInterface();
0993: if (importFiles.size() == 0) {
0994: return IMPORT_PAGE;
0995: }
0996:
0997: for (Iterator i = importFiles.iterator(); i.hasNext();) {
0998: Reference ref = (Reference) i.next();
0999:
1000: try {
1001: wizardManager.importResource(getIdManager().getId(
1002: getWorksite().getId()), getContentHosting()
1003: .getUuid(ref.getId()));
1004: } catch (ImportException ie) {
1005: lastError = BAD_IMPORT_ID;
1006: } catch (UnsupportedFileTypeException ufte) {
1007: lastError = BAD_FILE_TYPE_ID;
1008: }
1009: }
1010:
1011: return LIST_PAGE;
1012: }
1013:
1014: /**
1015: * This gets the list of evluators for the wizard
1016: * @param wizard
1017: * @return List
1018: */
1019: protected List getEvaluators(Wizard wizard) {
1020: ResourceBundle myResources = ResourceBundle
1021: .getBundle("org.theospi.portfolio.wizard.bundle.Messages");
1022:
1023: List evalList = new ArrayList();
1024: Id id = wizard.getId() == null ? wizard.getNewId() : wizard
1025: .getId();
1026:
1027: List evaluators = getAuthzManager().getAuthorizations(null,
1028: WizardFunctionConstants.EVALUATE_WIZARD, id);
1029:
1030: for (Iterator iter = evaluators.iterator(); iter.hasNext();) {
1031: Authorization az = (Authorization) iter.next();
1032: Agent agent = az.getAgent();
1033: String userId = az.getAgent().getEid().getValue();
1034: if (agent.isRole()) {
1035: evalList.add(MessageFormat.format(myResources
1036: .getString("decorated_role_format"),
1037: new Object[] { agent.getDisplayName() }));
1038: } else {
1039: evalList.add(MessageFormat
1040: .format(myResources
1041: .getString("decorated_user_format"),
1042: new Object[] { agent.getDisplayName(),
1043: userId }));
1044: }
1045: }
1046:
1047: return evalList;
1048: }
1049:
1050: public String processActionSelectStyle() {
1051: clearInterface();
1052: ExternalContext context = FacesContext.getCurrentInstance()
1053: .getExternalContext();
1054: ToolSession session = SessionManager.getCurrentToolSession();
1055: session.removeAttribute(StyleHelper.CURRENT_STYLE);
1056: session.removeAttribute(StyleHelper.CURRENT_STYLE_ID);
1057:
1058: session.setAttribute(StyleHelper.STYLE_SELECTABLE, "true");
1059:
1060: Wizard wizard = getCurrent().getBase();
1061:
1062: if (wizard.getStyle() != null)
1063: session.setAttribute(StyleHelper.CURRENT_STYLE_ID, wizard
1064: .getStyle().getId().getValue());
1065:
1066: try {
1067: context.redirect("osp.style.helper/listStyle");
1068: } catch (IOException e) {
1069: throw new RuntimeException("Failed to redirect to helper",
1070: e);
1071: }
1072: return null;
1073: }
1074:
1075: public List getUserListForSelect() {
1076: Placement placement = ToolManager.getCurrentPlacement();
1077: String currentSiteId = placement.getContext();
1078: List theList = new ArrayList(getUserList(currentSiteId));
1079:
1080: String user = currentUserId != null ? currentUserId
1081: : SessionManager.getCurrentSessionUserId();
1082: setCurrentUserId(user);
1083:
1084: return theList;
1085: }
1086:
1087: private Set getUserList(String worksiteId) {
1088: Set members = new HashSet();
1089: Set users = new HashSet();
1090:
1091: try {
1092: Site site = SiteService.getSite(worksiteId);
1093: if (site.hasGroups()) {
1094: String currentUser = SessionManager
1095: .getCurrentSessionUserId();
1096: Collection groups = site
1097: .getGroupsWithMember(currentUser);
1098: for (Iterator iter = groups.iterator(); iter.hasNext();) {
1099: Group group = (Group) iter.next();
1100: members.addAll(group.getMembers());
1101: }
1102: } else {
1103: members.addAll(site.getMembers());
1104: }
1105:
1106: Collections.sort(new ArrayList(members));
1107:
1108: for (Iterator memb = members.iterator(); memb.hasNext();) {
1109: try {
1110: Member member = (Member) memb.next();
1111: User user = UserDirectoryService.getUser(member
1112: .getUserId());
1113: users.add(createSelect(user.getId(), user
1114: .getSortName()));
1115: } catch (UserNotDefinedException e) {
1116: //TODO replace with a message bundle
1117: logger.warn("User " + e.getId()
1118: + " cannot be found");
1119: }
1120: }
1121: } catch (IdUnusedException e) {
1122: throw new OspException(e);
1123: }
1124: return users;
1125: }
1126:
1127: public boolean getCanCreate() {
1128: return getAuthzManager()
1129: .isAuthorized(
1130: WizardFunctionConstants.CREATE_WIZARD,
1131: getIdManager().getId(
1132: ToolManager.getCurrentPlacement()
1133: .getContext()));
1134: }
1135:
1136: public boolean getCanView() {
1137: return getAuthzManager()
1138: .isAuthorized(
1139: WizardFunctionConstants.VIEW_WIZARD,
1140: getIdManager().getId(
1141: ToolManager.getCurrentPlacement()
1142: .getContext()));
1143: }
1144:
1145: /**
1146: * This is to check if the current user is authorized by tool permissions to review
1147: * the current wizard. individual wizard permissions for review does not exist
1148: * @return boolean is authorized
1149: */
1150: public boolean getCanReview() {
1151: return getCanReview(current.getBase());
1152: }
1153:
1154: /**
1155: * This is to check if the current user is authorized by tool permissions to review
1156: * the wizards. individual wizard permissions for review does not exist
1157: * @return boolean is authorized
1158: */
1159: public boolean getCanReview(Wizard wizard) {
1160:
1161: return getAuthzManager().isAuthorized(
1162: WizardFunctionConstants.REVIEW_WIZARD, wizard.getId());
1163: }
1164:
1165: /**
1166: * This is to check if the current user is authorized by tool permissions to review
1167: * the various wizards
1168: * @return boolean is authorized
1169: */
1170: public boolean getCanReviewTool() {
1171: return getAuthzManager()
1172: .isAuthorized(
1173: WizardFunctionConstants.REVIEW_WIZARD,
1174: getIdManager().getId(
1175: ToolManager.getCurrentPlacement()
1176: .getContext()));
1177: }
1178:
1179: /**
1180: * This is to check if the current user is authorized by tool permissions to evaluate
1181: * the various wizards
1182: * @return boolean is authorized
1183: */
1184: public boolean getCanEvaluateTool() {
1185: return getAuthzManager()
1186: .isAuthorized(
1187: WizardFunctionConstants.EVALUATE_WIZARD,
1188: getIdManager().getId(
1189: ToolManager.getCurrentPlacement()
1190: .getContext()));
1191: }
1192:
1193: /**
1194: * This is to check if the current user is listed as an evaluator of the current wizard
1195: * @return boolean is authorized
1196: */
1197: public boolean getCanEvaluate() {
1198: return getCanEvaluate(current.getBase());
1199: }
1200:
1201: /**
1202: * This is to check if the current user is listed as an evaluator of the given wizard
1203: * @param Wizard wizard to check
1204: * @return boolean is authorized
1205: */
1206: public boolean getCanEvaluate(Wizard wizard) {
1207: return getAuthzManager()
1208: .isAuthorized(WizardFunctionConstants.EVALUATE_WIZARD,
1209: wizard.getId());
1210: }
1211:
1212: /**
1213: * This is to check if the current user is can operate on the wizard.
1214: * The operate permission mean view or review or evaluate wizard
1215: * @param Wizard wizard to check
1216: * @return boolean is authorized
1217: */
1218: public boolean getCanOperate(Wizard wizard) {
1219: return getAuthzManager().isAuthorized(
1220: WizardFunctionConstants.OPERATE_WIZARD, wizard.getId());
1221: }
1222:
1223: public boolean getCanPublish(Wizard wizard) {
1224: return getAuthzManager().isAuthorized(
1225: WizardFunctionConstants.PUBLISH_WIZARD, wizard.getId())
1226: && !wizard.isPublished();
1227: }
1228:
1229: public boolean getCanDelete(Wizard wizard) {
1230: if (wizard.getOwner() == null)
1231: return false;
1232: return (getAuthzManager().isAuthorized(
1233: WizardFunctionConstants.DELETE_WIZARD, wizard.getId()) || SessionManager
1234: .getCurrentSessionUserId().equalsIgnoreCase(
1235: wizard.getOwner().getId().getValue()));
1236: }
1237:
1238: public boolean getCanEdit(Wizard wizard) {
1239: if (wizard.getOwner() == null)
1240: return false;
1241: return getAuthzManager().isAuthorized(
1242: WizardFunctionConstants.EDIT_WIZARD, wizard.getId())
1243: || SessionManager.getCurrentSessionUserId()
1244: .equalsIgnoreCase(
1245: wizard.getOwner().getId().getValue());
1246: }
1247:
1248: public boolean getCanExport(Wizard wizard) {
1249: if (wizard.getOwner() == null)
1250: return false;
1251: return getAuthzManager().isAuthorized(
1252: WizardFunctionConstants.EXPORT_WIZARD, wizard.getId())
1253: || SessionManager.getCurrentSessionUserId()
1254: .equalsIgnoreCase(
1255: wizard.getOwner().getId().getValue());
1256: }
1257:
1258: protected Collection getFormsForSelect(String type) {
1259: Placement placement = ToolManager.getCurrentPlacement();
1260: String currentSiteId = placement.getContext();
1261: Collection forms = getWizardManager().getAvailableForms(
1262: currentSiteId, type);
1263:
1264: List retForms = new ArrayList();
1265: for (Iterator iter = forms.iterator(); iter.hasNext();) {
1266: StructuredArtifactDefinitionBean sad = (StructuredArtifactDefinitionBean) iter
1267: .next();
1268: retForms.add(createSelect(sad.getId().getValue(), sad
1269: .getDecoratedDescription()));
1270: }
1271:
1272: return retForms;
1273: }
1274:
1275: public Collection getCommentFormsForSelect() {
1276: return getFormsForSelect(WizardFunctionConstants.COMMENT_TYPE);
1277: }
1278:
1279: public Collection getReflectionFormsForSelect() {
1280: return getFormsForSelect(WizardFunctionConstants.REFLECTION_TYPE);
1281: }
1282:
1283: public Collection getEvaluationFormsForSelect() {
1284: return getFormsForSelect(WizardFunctionConstants.EVALUATION_TYPE);
1285: }
1286:
1287: protected Collection getWizardsForSelect(String type) {
1288: //TODO is only here just in case we decide to give wizards types
1289: // The type isn't being used yet
1290: Placement placement = ToolManager.getCurrentPlacement();
1291: String currentSiteId = placement.getContext();
1292: List wizards = getWizardManager().listWizardsByType(
1293: SessionManager.getCurrentSessionUserId(),
1294: currentSiteId, type);
1295:
1296: List retWizards = new ArrayList();
1297: for (Iterator iter = wizards.iterator(); iter.hasNext();) {
1298: Wizard wizard = (Wizard) iter.next();
1299: retWizards.add(createSelect(wizard.getId().getValue(),
1300: wizard.getName()));
1301: }
1302:
1303: return retWizards;
1304: }
1305:
1306: public Collection getCommentWizardsForSelect() {
1307: return getWizardsForSelect(WizardFunctionConstants.COMMENT_TYPE);
1308: }
1309:
1310: public Collection getReflectionWizardsForSelect() {
1311: return getWizardsForSelect(WizardFunctionConstants.REFLECTION_TYPE);
1312: }
1313:
1314: public Collection getEvaluationWizardsForSelect() {
1315: return getWizardsForSelect(WizardFunctionConstants.EVALUATION_TYPE);
1316: }
1317:
1318: private String safeGetValue(Id id) {
1319: if (id == null)
1320: return "";
1321: else
1322: return id.getValue();
1323: }
1324:
1325: public GuidanceManager getGuidanceManager() {
1326: return guidanceManager;
1327: }
1328:
1329: public void setGuidanceManager(GuidanceManager guidanceManager) {
1330: this .guidanceManager = guidanceManager;
1331: }
1332:
1333: public String getCommentItem() {
1334: return safeGetValue(current.getBase().getReviewDevice());
1335: }
1336:
1337: public void setCommentItem(String commentItem) {
1338: current.getBase().setReviewDevice(
1339: getIdManager().getId(commentItem));
1340: }
1341:
1342: public String getEvaluationItem() {
1343: return safeGetValue(current.getBase().getEvaluationDevice());
1344: }
1345:
1346: public void setEvaluationItem(String evaluationItem) {
1347: current.getBase().setEvaluationDevice(
1348: getIdManager().getId(evaluationItem));
1349: }
1350:
1351: public String getReflectionItem() {
1352: return safeGetValue(current.getBase().getReflectionDevice());
1353: }
1354:
1355: public void setReflectionItem(String reflectionItem) {
1356: current.getBase().setReflectionDevice(
1357: getIdManager().getId(reflectionItem));
1358: }
1359:
1360: public String getExpandedGuidanceSection() {
1361: return expandedGuidanceSection;
1362: }
1363:
1364: public void setExpandedGuidanceSection(
1365: String expandedGuidanceSection) {
1366: this .expandedGuidanceSection = expandedGuidanceSection;
1367: }
1368:
1369: public IdManager getIdManager() {
1370: return idManager;
1371: }
1372:
1373: public void setIdManager(IdManager idManager) {
1374: this .idManager = idManager;
1375: }
1376:
1377: public List getWizardTypes() {
1378: if (wizardTypes == null) {
1379: wizardTypes = new ArrayList();
1380: wizardTypes
1381: .add(createSelect(
1382: WizardFunctionConstants.WIZARD_TYPE_SEQUENTIAL,
1383: getMessageFromBundle(WizardFunctionConstants.WIZARD_TYPE_SEQUENTIAL)
1384: + getMessageFromBundle(WizardFunctionConstants.WIZARD_TYPE_SEQUENTIAL
1385: + "_additional")));
1386: wizardTypes
1387: .add(createSelect(
1388: WizardFunctionConstants.WIZARD_TYPE_HIERARCHICAL,
1389: getMessageFromBundle(WizardFunctionConstants.WIZARD_TYPE_HIERARCHICAL)
1390: + getMessageFromBundle(WizardFunctionConstants.WIZARD_TYPE_HIERARCHICAL
1391: + "_additional")));
1392: }
1393: return wizardTypes;
1394: }
1395:
1396: public void setWizardTypes(List wizardTypes) {
1397: this .wizardTypes = wizardTypes;
1398: }
1399:
1400: public DecoratedCategory getCurrentCategory() {
1401: return currentCategory;
1402: }
1403:
1404: public void setCurrentCategory(DecoratedCategory currentCategory) {
1405: this .currentCategory = currentCategory;
1406: }
1407:
1408: public DecoratedCategoryChild getMoveCategoryChild() {
1409: return moveCategoryChild;
1410: }
1411:
1412: public void setMoveCategoryChild(
1413: DecoratedCategoryChild moveCategoryChild) {
1414: this .moveCategoryChild = moveCategoryChild;
1415: }
1416:
1417: public boolean isMoving() {
1418: return getMoveCategoryChild() != null;
1419: }
1420:
1421: public List getDeletedItems() {
1422: return deletedItems;
1423: }
1424:
1425: public void setDeletedItems(List deletedItems) {
1426: this .deletedItems = deletedItems;
1427: }
1428:
1429: public String getMovingInstructions() {
1430: String key = null;
1431:
1432: if (getMoveCategoryChild() == null) {
1433: return null;
1434: }
1435:
1436: if (getMoveCategoryChild().isCategory()) {
1437: key = "move_category_instructions";
1438: } else {
1439: key = "move_page_instructions";
1440: }
1441:
1442: return getMessageFromBundle(key,
1443: new Object[] { getMoveCategoryChild().getTitle() });
1444: }
1445:
1446: public int getNextWizard() {
1447: return nextWizard;
1448: }
1449:
1450: public void setNextWizard(int nextWizard) {
1451: this .nextWizard = nextWizard;
1452: }
1453:
1454: public AuthorizationFacade getAuthzManager() {
1455: return authzManager;
1456: }
1457:
1458: public void setAuthzManager(AuthorizationFacade authzManager) {
1459: this .authzManager = authzManager;
1460: }
1461:
1462: public MatrixManager getMatrixManager() {
1463: return matrixManager;
1464: }
1465:
1466: public void setMatrixManager(MatrixManager matrixManager) {
1467: this .matrixManager = matrixManager;
1468: }
1469:
1470: /**
1471: * @return Returns the workflowManager.
1472: */
1473: public WorkflowManager getWorkflowManager() {
1474: return workflowManager;
1475: }
1476:
1477: /**
1478: * @param workflowManager The workflowManager to set.
1479: */
1480: public void setWorkflowManager(WorkflowManager workflowManager) {
1481: this .workflowManager = workflowManager;
1482: }
1483:
1484: public ContentHostingService getContentHosting() {
1485: return contentHosting;
1486: }
1487:
1488: public void setContentHosting(ContentHostingService contentHosting) {
1489: this .contentHosting = contentHosting;
1490: }
1491:
1492: /**
1493: * @return Returns the reviewManager.
1494: */
1495: public ReviewManager getReviewManager() {
1496: return reviewManager;
1497: }
1498:
1499: /**
1500: * @param reviewManager The reviewManager to set.
1501: */
1502: public void setReviewManager(ReviewManager reviewManager) {
1503: this .reviewManager = reviewManager;
1504: }
1505:
1506: /**
1507: * @return AuthenticationManager
1508: */
1509: public AuthenticationManager getAuthManager() {
1510: return authManager;
1511: }
1512:
1513: /**
1514: * @param manager
1515: */
1516: public void setAuthManager(AuthenticationManager manager) {
1517: authManager = manager;
1518: }
1519:
1520: public TaggingManager getTaggingManager() {
1521: return taggingManager;
1522: }
1523:
1524: public void setTaggingManager(TaggingManager taggingManager) {
1525: this .taggingManager = taggingManager;
1526: }
1527:
1528: public WizardActivityProducer getWizardActivityProducer() {
1529: return wizardActivityProducer;
1530: }
1531:
1532: public void setWizardActivityProducer(
1533: WizardActivityProducer wizardActivityProducer) {
1534: this .wizardActivityProducer = wizardActivityProducer;
1535: }
1536:
1537: public String getLastSaveWizard() {
1538: return lastSaveWizard;
1539: }
1540:
1541: public void setLastSaveWizard(String lastSaveWizard) {
1542: this .lastSaveWizard = lastSaveWizard;
1543: }
1544:
1545: protected void checkSubmittedPage() {
1546: ToolSession session = SessionManager.getCurrentToolSession();
1547: if (session.getAttribute("submittedPage") != null) {
1548: WizardPage page = (WizardPage) session
1549: .getAttribute("submittedPage");
1550: session.removeAttribute("submittedPage");
1551:
1552: lastSavePage = page.getPageDefinition().getTitle();
1553: }
1554: }
1555:
1556: protected void checkSavedPage() {
1557: ToolSession session = SessionManager.getCurrentToolSession();
1558: if (session.getAttribute("savedPage") != null) {
1559: WizardPage page = (WizardPage) session
1560: .getAttribute("savedPage");
1561: session.removeAttribute("savedPage");
1562:
1563: pageSaved = true;
1564: }
1565: }
1566:
1567: public boolean isPageSaved() {
1568: checkSavedPage();
1569: return pageSaved;
1570: }
1571:
1572: public void setPageSaved(boolean pageSaved) {
1573: this .pageSaved = pageSaved;
1574: }
1575:
1576: public String getLastSavePage() {
1577: checkSubmittedPage();
1578: return lastSavePage;
1579: }
1580:
1581: public void setLastSavePage(String lastSavePage) {
1582: this .lastSavePage = lastSavePage;
1583: }
1584:
1585: public String getLastError() {
1586: return lastError;
1587: }
1588:
1589: public void setLastError(String lastError) {
1590: this .lastError = lastError;
1591: }
1592:
1593: public DecoratedWizardPage getCurrentPage() {
1594: return currentPage;
1595: }
1596:
1597: public List getCurrentPageList() {
1598: List thepage = new ArrayList();
1599: thepage.add(currentPage);
1600: return thepage;
1601: }
1602:
1603: public List getCurrentCategoryList() {
1604: List thecategory = new ArrayList();
1605: thecategory.add(currentCategory);
1606: return thecategory;
1607: }
1608:
1609: public void setCurrentPage(DecoratedWizardPage currentPage) {
1610: this.currentPage = currentPage;
1611: }
1612:
1613: }
|