0001: /**********************************************************************************
0002: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/author/AssessmentSettingsBean.java $
0003: * $Id: AssessmentSettingsBean.java 28709 2007-04-12 00:08:46Z ajpoland@iupui.edu $
0004: ***********************************************************************************
0005: *
0006: * Copyright (c) 2004, 2005, 2006 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.sakaiproject.tool.assessment.ui.bean.author;
0021:
0022: import java.io.Serializable;
0023: import java.text.SimpleDateFormat;
0024: import java.util.ArrayList;
0025: import java.util.Arrays;
0026: import java.util.Calendar;
0027: import java.util.Date;
0028: import java.util.HashMap;
0029: import java.util.Iterator;
0030: import java.util.List;
0031: import org.sakaiproject.util.ResourceLoader;
0032: import java.util.Set;
0033: import javax.faces.application.FacesMessage;
0034: import javax.faces.context.FacesContext;
0035: import javax.faces.context.ExternalContext;
0036: import javax.faces.model.SelectItem;
0037:
0038: import org.apache.commons.logging.Log;
0039: import org.apache.commons.logging.LogFactory;
0040:
0041: import org.sakaiproject.service.gradebook.shared.GradebookService;
0042: import org.sakaiproject.site.api.Site;
0043: import org.sakaiproject.site.api.SitePage;
0044: import org.sakaiproject.site.api.ToolConfiguration;
0045: import org.sakaiproject.site.cover.SiteService;
0046: import org.sakaiproject.spring.SpringBeanLocator;
0047: import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentAccessControlIfc;
0048: import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentFeedbackIfc;
0049: import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentMetaDataIfc;
0050: import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentTemplateIfc;
0051: import org.sakaiproject.tool.assessment.data.ifc.assessment.AttachmentIfc;
0052: import org.sakaiproject.tool.assessment.data.ifc.assessment.EvaluationModelIfc;
0053: import org.sakaiproject.tool.assessment.data.ifc.assessment.SecuredIPAddressIfc;
0054: import org.sakaiproject.tool.assessment.facade.AgentFacade;
0055: import org.sakaiproject.tool.assessment.facade.AssessmentFacade;
0056: import org.sakaiproject.tool.assessment.facade.AssessmentTemplateFacade;
0057: import org.sakaiproject.tool.assessment.facade.GradebookFacade;
0058: import org.sakaiproject.tool.assessment.integration.context.IntegrationContextFactory;
0059: import org.sakaiproject.tool.assessment.integration.helper.ifc.GradebookServiceHelper;
0060: import org.sakaiproject.tool.assessment.integration.helper.ifc.PublishingTargetHelper;
0061: import org.sakaiproject.tool.assessment.services.assessment.AssessmentService;
0062: import org.sakaiproject.tool.assessment.ui.listener.author.SaveAssessmentAttachmentListener;
0063: import org.sakaiproject.tool.assessment.ui.listener.author.SaveAssessmentSettings;
0064: import org.sakaiproject.tool.assessment.ui.listener.util.TimeUtil;
0065: import org.sakaiproject.tool.assessment.ui.listener.util.ContextUtil;
0066:
0067: import org.sakaiproject.tool.api.ToolSession;
0068: import org.sakaiproject.entity.impl.ReferenceComponent;
0069: import org.sakaiproject.exception.IdUnusedException;
0070: import org.sakaiproject.exception.PermissionException;
0071: import org.sakaiproject.exception.TypeException;
0072:
0073: import org.sakaiproject.content.api.ContentResource;
0074: import org.sakaiproject.content.api.FilePickerHelper;
0075: import org.sakaiproject.content.cover.ContentHostingService;
0076: import org.sakaiproject.tool.cover.SessionManager;
0077:
0078: /**
0079: *
0080: * To change the template for this generated type comment go to
0081: * Window>Preferences>Java>Code Generation>Code and Comments
0082: *
0083: * Used to be org.navigoproject.ui.web.asi.author.assessment.AssessmentActionForm.java
0084: */
0085: public class AssessmentSettingsBean implements Serializable {
0086: private static Log log = LogFactory
0087: .getLog(AssessmentSettingsBean.class);
0088:
0089: private static final IntegrationContextFactory integrationContextFactory = IntegrationContextFactory
0090: .getInstance();
0091: private static final GradebookServiceHelper gbsHelper = integrationContextFactory
0092: .getGradebookServiceHelper();
0093: private static final PublishingTargetHelper ptHelper = integrationContextFactory
0094: .getPublishingTargetHelper();
0095: private static final boolean integrated = integrationContextFactory
0096: .isIntegrated();
0097:
0098: /** Use serialVersionUID for interoperability. */
0099: private final static long serialVersionUID = -630950053380808339L;
0100: private String outcomeSave;
0101: private String outcomePublish;
0102: private AssessmentFacade assessment;
0103: private AssessmentTemplateFacade template;
0104: private Long assessmentId;
0105: private String title;
0106: private String creator;
0107: private String description;
0108: private boolean hasQuestions;
0109: private String templateTitle;
0110: private String templateDescription;
0111:
0112: // meta data
0113: private String objectives;
0114: private String keywords;
0115: private String rubrics;
0116: private String authors;
0117: private String templateAuthors;
0118:
0119: // these are properties in AssessmentAccessControl
0120: private Date startDate;
0121: private Date dueDate;
0122: private Date retractDate;
0123: private Date feedbackDate;
0124: private Integer timeLimit = new Integer(0); // in seconds, calculated from timedHours & timedMinutes
0125: private Integer timedHours = new Integer(0);
0126: private Integer timedMinutes = new Integer(0);
0127: private Integer timedSeconds = new Integer(0);
0128: private boolean timedAssessment = false;
0129: private boolean autoSubmit = false;
0130: private String assessmentFormat; // question (1)/part(2)/assessment(3) on separate page
0131: private String itemNavigation; // linear (1)or random (2)
0132: private String itemNumbering; // continuous between parts(1), restart between parts(2)
0133: private String unlimitedSubmissions;
0134: private String submissionsAllowed;
0135: private String submissionsSaved; // bad name, this is autoSaved
0136: private String lateHandling;
0137: private String submissionMessage;
0138: private String releaseTo;
0139: private SelectItem[] publishingTargets;
0140: private String[] targetSelected;
0141: private String firstTargetSelected;
0142: private String username;
0143: private String password;
0144: private String finalPageUrl;
0145: private String ipAddresses;
0146:
0147: // properties of AssesmentFeedback
0148: private String feedbackDelivery; // immediate, on specific date , no feedback
0149: //private String editComponents; // 0 = cannot
0150: private boolean showQuestionText = true;
0151: private boolean showStudentResponse = false;
0152: private boolean showCorrectResponse = false;
0153: private boolean showStudentScore = false;
0154: private boolean showStudentQuestionScore = false;
0155: private boolean showQuestionLevelFeedback = false;
0156: private boolean showSelectionLevelFeedback = false; // must be MC
0157: private boolean showGraderComments = false;
0158: private boolean showStatistics = false;
0159:
0160: // properties of EvaluationModel
0161: private String anonymousGrading;
0162: private boolean gradebookExists;
0163: private String toDefaultGradebook;
0164: private String scoringType;
0165: private String bgColor;
0166: private String bgImage;
0167: private HashMap values = new HashMap(); // contains only "can edit" element
0168: private String bgColorSelect;
0169: private String bgImageSelect;
0170:
0171: // extra properties
0172: private boolean noTemplate;
0173: private String publishedUrl;
0174: private String alias;
0175: private static boolean error;
0176:
0177: private List attachmentList;
0178:
0179: /**
0180: * we use the calendar widget which uses 'MM/dd/yyyy hh:mm:ss a'
0181: * used to take the internal format from calendar picker and move it
0182: * transparently in and out of the date properties
0183: *
0184: */
0185: //private static final String DISPLAY_DATEFORMAT = "MM/dd/yyyy hh:mm:ss a";
0186: private String display_dateFormat = ContextUtil.getLocalizedString(
0187: "org.sakaiproject.tool.assessment.bundle.GeneralMessages",
0188: "output_data_picker_w_sec");
0189:
0190: private SimpleDateFormat displayFormat = new SimpleDateFormat(
0191: display_dateFormat);
0192:
0193: /*
0194: * Creates a new AssessmentBean object.
0195: */
0196: public AssessmentSettingsBean() {
0197: }
0198:
0199: public AssessmentFacade getAssessment() {
0200: return assessment;
0201: }
0202:
0203: public void setAssessment(AssessmentFacade assessment) {
0204: try {
0205: //1. set the template info
0206: AssessmentService service = new AssessmentService();
0207: AssessmentTemplateIfc template = null;
0208: if (assessment.getAssessmentTemplateId() != null) {
0209: template = service.getAssessmentTemplate(assessment
0210: .getAssessmentTemplateId().toString());
0211: }
0212: if (template != null) {
0213: setNoTemplate(false);
0214: this .templateTitle = template.getTitle();
0215: this .templateDescription = template.getDescription();
0216: this .templateAuthors = template
0217: .getAssessmentMetaDataByLabel("author"); // see TemplateUploadListener line 142
0218: } else {
0219: setNoTemplate(true);
0220: }
0221: //2. set the assessment info
0222: this .assessment = assessment;
0223: // set the valueMap
0224: setValueMap(assessment.getAssessmentMetaDataMap());
0225: this .assessmentId = assessment.getAssessmentId();
0226: this .title = assessment.getTitle();
0227: this .creator = AgentFacade.getDisplayName(assessment
0228: .getCreatedBy());
0229: this .description = assessment.getDescription();
0230: // assessment meta data
0231: this .authors = assessment
0232: .getAssessmentMetaDataByLabel(AssessmentMetaDataIfc.AUTHORS);
0233: this .objectives = assessment
0234: .getAssessmentMetaDataByLabel(AssessmentMetaDataIfc.OBJECTIVES);
0235: this .keywords = assessment
0236: .getAssessmentMetaDataByLabel(AssessmentMetaDataIfc.KEYWORDS);
0237: this .rubrics = assessment
0238: .getAssessmentMetaDataByLabel(AssessmentMetaDataIfc.RUBRICS);
0239: this .bgColor = assessment
0240: .getAssessmentMetaDataByLabel(AssessmentMetaDataIfc.BGCOLOR);
0241: this .bgImage = assessment
0242: .getAssessmentMetaDataByLabel(AssessmentMetaDataIfc.BGIMAGE);
0243: if ((assessment
0244: .getAssessmentMetaDataByLabel(AssessmentMetaDataIfc.BGIMAGE) != null)
0245: && (!assessment.getAssessmentMetaDataByLabel(
0246: AssessmentMetaDataIfc.BGIMAGE).equals(""))) {
0247: this .bgImageSelect = "1";
0248: this .bgColorSelect = null;
0249: } else {
0250: this .bgImageSelect = null;
0251: this .bgColorSelect = "1";
0252: }
0253:
0254: // these are properties in AssessmentAccessControl
0255: AssessmentAccessControlIfc accessControl = null;
0256: accessControl = assessment.getAssessmentAccessControl();
0257: if (accessControl != null) {
0258: this .startDate = accessControl.getStartDate();
0259: this .dueDate = accessControl.getDueDate();
0260: this .retractDate = accessControl.getRetractDate();
0261: this .feedbackDate = accessControl.getFeedbackDate();
0262:
0263: // deal with releaseTo
0264: this .releaseTo = accessControl.getReleaseTo(); // list of String
0265: this .publishingTargets = getPublishingTargets();
0266: this .targetSelected = getTargetSelected(releaseTo);
0267: this .firstTargetSelected = getFirstTargetSelected(releaseTo);
0268: // SAK-1850 - when importing assessment forget to set releaseTo, we will catch it
0269: // and set it to host site
0270: if (!validateTarget(firstTargetSelected)) {
0271: releaseTo = AgentFacade.getCurrentSiteName();
0272: firstTargetSelected = AgentFacade
0273: .getCurrentSiteName();
0274: targetSelected = getTargetSelected(releaseTo);
0275: }
0276:
0277: this .timeLimit = accessControl.getTimeLimit(); // in seconds
0278: if (timeLimit != null && timeLimit.intValue() > 0)
0279: setTimeLimitDisplay(timeLimit.intValue());
0280: else
0281: resetTimeLimitDisplay();
0282: if ((new Integer(1)).equals(accessControl
0283: .getTimedAssessment()))
0284: this .timedAssessment = true;
0285: if ((new Integer(1)).equals(accessControl
0286: .getAutoSubmit()))
0287: this .autoSubmit = true;
0288: if (accessControl.getAssessmentFormat() != null)
0289: this .assessmentFormat = accessControl
0290: .getAssessmentFormat().toString(); // question/part/assessment on separate page
0291: if (accessControl.getItemNavigation() != null)
0292: this .itemNavigation = accessControl
0293: .getItemNavigation().toString(); // linear or random
0294: if (accessControl.getItemNumbering() != null)
0295: this .itemNumbering = accessControl
0296: .getItemNumbering().toString();
0297: if (accessControl.getSubmissionsSaved() != null) // bad name, this is autoSaved
0298: this .submissionsSaved = accessControl
0299: .getSubmissionsSaved().toString();
0300:
0301: // default to unlimited if control value is null
0302: if (accessControl.getUnlimitedSubmissions() != null
0303: && !accessControl.getUnlimitedSubmissions()
0304: .booleanValue()) {
0305: this .unlimitedSubmissions = AssessmentAccessControlIfc.LIMITED_SUBMISSIONS
0306: .toString();
0307: this .submissionsAllowed = accessControl
0308: .getSubmissionsAllowed().toString();
0309: } else {
0310: this .unlimitedSubmissions = AssessmentAccessControlIfc.UNLIMITED_SUBMISSIONS
0311: .toString();
0312: this .submissionsAllowed = "";
0313: }
0314: if (accessControl.getLateHandling() != null)
0315: this .lateHandling = accessControl.getLateHandling()
0316: .toString();
0317: if (accessControl.getSubmissionsSaved() != null)
0318: this .submissionsSaved = accessControl
0319: .getSubmissionsSaved().toString();
0320: this .submissionMessage = accessControl
0321: .getSubmissionMessage();
0322: this .username = accessControl.getUsername();
0323: this .password = accessControl.getPassword();
0324: this .finalPageUrl = accessControl.getFinalPageUrl();
0325: }
0326:
0327: // properties of AssesmentFeedback
0328: AssessmentFeedbackIfc feedback = assessment
0329: .getAssessmentFeedback();
0330: if (feedback != null) {
0331: if (feedback.getFeedbackDelivery() != null)
0332: this .feedbackDelivery = feedback
0333: .getFeedbackDelivery().toString();
0334: if (feedback.getFeedbackAuthoring() != null)
0335: this .feedbackAuthoring = feedback
0336: .getFeedbackAuthoring().toString();
0337: if ((Boolean.TRUE).equals(feedback
0338: .getShowQuestionText()))
0339: this .showQuestionText = true;
0340: if ((Boolean.TRUE).equals(feedback
0341: .getShowStudentResponse()))
0342: this .showStudentResponse = true;
0343: if ((Boolean.TRUE).equals(feedback
0344: .getShowCorrectResponse()))
0345: this .showCorrectResponse = true;
0346: if ((Boolean.TRUE).equals(feedback
0347: .getShowStudentScore()))
0348: this .showStudentScore = true;
0349: if ((Boolean.TRUE).equals(feedback
0350: .getShowStudentQuestionScore()))
0351: this .showStudentQuestionScore = true;
0352: if ((Boolean.TRUE).equals(feedback
0353: .getShowQuestionLevelFeedback()))
0354: this .showQuestionLevelFeedback = true;
0355: if ((Boolean.TRUE).equals(feedback
0356: .getShowSelectionLevelFeedback()))
0357: this .showSelectionLevelFeedback = true;// must be MC
0358: if ((Boolean.TRUE).equals(feedback
0359: .getShowGraderComments()))
0360: this .showGraderComments = true;
0361: if ((Boolean.TRUE).equals(feedback.getShowStatistics()))
0362: this .showStatistics = true;
0363: }
0364:
0365: // properties of EvaluationModel
0366: EvaluationModelIfc evaluation = assessment
0367: .getEvaluationModel();
0368: if (evaluation != null) {
0369: if (evaluation.getAnonymousGrading() != null)
0370: this .anonymousGrading = evaluation
0371: .getAnonymousGrading().toString();
0372: if (evaluation.getToGradeBook() != null)
0373: this .toDefaultGradebook = evaluation
0374: .getToGradeBook();
0375: if (evaluation.getScoringType() != null)
0376: this .scoringType = evaluation.getScoringType()
0377: .toString();
0378:
0379: String currentSiteId = AgentFacade.getCurrentSiteId();
0380: this .gradebookExists = gbsHelper
0381: .isGradebookExist(currentSiteId);
0382: /*
0383: GradebookService g = null;
0384: if (integrated)
0385: {
0386: g = (GradebookService) SpringBeanLocator.getInstance().
0387: getBean("org.sakaiproject.service.gradebook.GradebookService");
0388: }
0389:
0390: this.gradebookExists = gbsHelper.gradebookExists(
0391: GradebookFacade.getGradebookUId(), g);
0392: */
0393: }
0394:
0395: // ip addresses
0396: this .ipAddresses = "";
0397: Set ipAddressSet = assessment.getSecuredIPAddressSet();
0398: if (ipAddressSet != null) {
0399: Iterator iter = ipAddressSet.iterator();
0400: while (iter.hasNext()) {
0401: SecuredIPAddressIfc ip = (SecuredIPAddressIfc) iter
0402: .next();
0403: if (ip.getIpAddress() != null)
0404: this .ipAddresses = ip.getIpAddress() + "\n"
0405: + this .ipAddresses;
0406: }
0407: }
0408: // attachment
0409: this .attachmentList = assessment
0410: .getAssessmentAttachmentList();
0411: } catch (RuntimeException ex) {
0412: ex.printStackTrace();
0413: }
0414: }
0415:
0416: public String getBgColorSelect() {
0417: return this .bgColorSelect;
0418: }
0419:
0420: public void setBgColorSelect(String bgColorSelect) {
0421: this .bgColorSelect = bgColorSelect;
0422: }
0423:
0424: public String getBgImageSelect() {
0425: return this .bgImageSelect;
0426: }
0427:
0428: public void setBgImageSelect(String bgImageSelect) {
0429: this .bgImageSelect = bgImageSelect;
0430: }
0431:
0432: //Huong adding for outcome error
0433: public String getOutcomeSave() {
0434: return this .outcomeSave;
0435: }
0436:
0437: public void setOutcomeSave(String outcomeSave) {
0438: this .outcomeSave = outcomeSave;
0439: }
0440:
0441: public String getOutcomePublish() {
0442: return this .outcomePublish;
0443: }
0444:
0445: public void setOutcomePublish(String outcomePublish) {
0446: this .outcomePublish = outcomePublish;
0447: }
0448:
0449: // properties from Assessment
0450: public Long getAssessmentId() {
0451: return this .assessmentId;
0452: }
0453:
0454: public void setAssessmentId(Long assessmentId) {
0455: this .assessmentId = assessmentId;
0456: }
0457:
0458: public String getTitle() {
0459: return this .title;
0460: }
0461:
0462: public void setTitle(String title) {
0463: this .title = title;
0464: }
0465:
0466: public String getCreator() {
0467: return this .creator;
0468: }
0469:
0470: public void setCreator(String creator) {
0471: this .creator = creator;
0472: }
0473:
0474: public String getDescription() {
0475: return this .description;
0476: }
0477:
0478: public void setDescription(String description) {
0479: this .description = description;
0480: }
0481:
0482: // properties form AssessmentMetaData
0483: public String getObjectives() {
0484: return this .objectives;
0485: }
0486:
0487: public void setObjectives(String objectives) {
0488: this .objectives = objectives;
0489: }
0490:
0491: public String getKeywords() {
0492: return this .keywords;
0493: }
0494:
0495: public void setKeywords(String keywords) {
0496: this .keywords = keywords;
0497: }
0498:
0499: public String getRubrics() {
0500: return this .rubrics;
0501: }
0502:
0503: public void setRubrics(String rubrics) {
0504: this .rubrics = rubrics;
0505: }
0506:
0507: public String getAuthors() {
0508: return this .authors;
0509: }
0510:
0511: public void setAuthors(String authors) {
0512: this .authors = authors;
0513: }
0514:
0515: public String getBgColor() {
0516: if ((this .getBgColorSelect() != null)
0517: && (this .getBgColorSelect().equals("1")))
0518: return this .bgColor;
0519: else
0520: return "";
0521:
0522: }
0523:
0524: public void setBgColor(String bgColor) {
0525: if ((this .getBgColorSelect() != null)
0526: && (this .getBgColorSelect().equals("1")))
0527: this .bgColor = bgColor;
0528: else
0529: this .bgColor = "";
0530:
0531: }
0532:
0533: public String getBgImage() {
0534: if ((this .getBgImageSelect() != null)
0535: && (this .getBgImageSelect().equals("1")))
0536: return this .bgImage;
0537: else
0538: return "";
0539:
0540: }
0541:
0542: public void setBgImage(String bgImage) {
0543: if ((this .getBgImageSelect() != null)
0544: && (this .getBgImageSelect().equals("1")))
0545:
0546: this .bgImage = bgImage;
0547: else
0548: this .bgImage = "";
0549:
0550: }
0551:
0552: public boolean getHasQuestions() {
0553: return this .hasQuestions;
0554: }
0555:
0556: public void setHasQuestions(boolean hasQuestions) {
0557: this .hasQuestions = hasQuestions;
0558: }
0559:
0560: // copied from AssessmentAccessControl ;-)
0561: public Date getStartDate() {
0562: return this .startDate;
0563: }
0564:
0565: public void setStartDate(Date startDate) {
0566: this .startDate = startDate;
0567: }
0568:
0569: public Date getDueDate() {
0570: return this .dueDate;
0571: }
0572:
0573: public void setDueDate(Date dueDate) {
0574: this .dueDate = dueDate;
0575: }
0576:
0577: public Date getFeedbackDate() {
0578: return this .feedbackDate;
0579: }
0580:
0581: public void setFeedbackDate(Date feedbackDate) {
0582: this .feedbackDate = feedbackDate;
0583: }
0584:
0585: public Date getRetractDate() {
0586: return this .retractDate;
0587: }
0588:
0589: public void setRetractDate(Date retractDate) {
0590: this .retractDate = retractDate;
0591: }
0592:
0593: public String getReleaseTo() {
0594: this .releaseTo = "";
0595: if (targetSelected != null) {
0596: for (int i = 0; i < targetSelected.length; i++) {
0597: String user = targetSelected[i];
0598: if (!releaseTo.equals(""))
0599: releaseTo = releaseTo + ", " + user;
0600: else
0601: releaseTo = user;
0602: }
0603: }
0604: return this .releaseTo;
0605: }
0606:
0607: public void setReleaseTo(String releaseTo) {
0608: this .releaseTo = releaseTo;
0609: }
0610:
0611: public Integer getTimeLimit() {
0612: return new Integer(timedHours.intValue() * 3600
0613: + timedMinutes.intValue() * 60
0614: + timedSeconds.intValue());
0615: }
0616:
0617: public void setTimeLimit(Integer timeLimit) {
0618: this .timeLimit = timeLimit;
0619: }
0620:
0621: public void setTimedHours(Integer timedHours) {
0622: this .timedHours = timedHours;
0623: }
0624:
0625: public Integer getTimedHours() {
0626: return timedHours;
0627: }
0628:
0629: public void setTimedMinutes(Integer timedMinutes) {
0630: this .timedMinutes = timedMinutes;
0631: }
0632:
0633: public Integer getTimedMinutes() {
0634: return timedMinutes;
0635: }
0636:
0637: public void setTimedSeconds(Integer timedSeconds) {
0638: this .timedSeconds = timedSeconds;
0639: }
0640:
0641: public Integer getTimedSeconds() {
0642: return timedSeconds;
0643: }
0644:
0645: public boolean getTimedAssessment() {
0646: return timedAssessment;
0647: }
0648:
0649: public void setTimedAssessment(boolean timedAssessment) {
0650: this .timedAssessment = timedAssessment;
0651: }
0652:
0653: public boolean getAutoSubmit() {
0654: return autoSubmit;
0655: }
0656:
0657: public void setAutoSubmit(boolean autoSubmit) {
0658: this .autoSubmit = autoSubmit;
0659: }
0660:
0661: public String getAssessmentFormat() {
0662: return assessmentFormat;
0663: }
0664:
0665: public void setAssessmentFormat(String assessmentFormat) {
0666: this .assessmentFormat = assessmentFormat;
0667: }
0668:
0669: public String getItemNavigation() {
0670: return itemNavigation;
0671: }
0672:
0673: public void setItemNavigation(String itemNavigation) {
0674: this .itemNavigation = itemNavigation;
0675: }
0676:
0677: public String getItemNumbering() {
0678: return itemNumbering;
0679: }
0680:
0681: public void setItemNumbering(String itemNumbering) {
0682: this .itemNumbering = itemNumbering;
0683: }
0684:
0685: public String getUnlimitedSubmissions() {
0686: return unlimitedSubmissions;
0687: }
0688:
0689: public void setUnlimitedSubmissions(String unlimitedSubmissions) {
0690: this .unlimitedSubmissions = unlimitedSubmissions;
0691: }
0692:
0693: public String getSubmissionsAllowed() {
0694: return submissionsAllowed;
0695: }
0696:
0697: public void setSubmissionsAllowed(String submissionsAllowed) {
0698: this .submissionsAllowed = submissionsAllowed;
0699: }
0700:
0701: public void setLateHandling(String lateHandling) {
0702: this .lateHandling = lateHandling;
0703: }
0704:
0705: public String getLateHandling() {
0706: return lateHandling;
0707: }
0708:
0709: // bad name - this is autoSaved
0710: public void setSubmissionsSaved(String submissionSaved) {
0711: this .submissionsSaved = submissionSaved;
0712: }
0713:
0714: public String getSubmissionsSaved() {
0715: return submissionsSaved;
0716: }
0717:
0718: public void setSubmissionMessage(String submissionMessage) {
0719: this .submissionMessage = submissionMessage;
0720: }
0721:
0722: public String getSubmissionMessage() {
0723: return submissionMessage;
0724: }
0725:
0726: public String getUsername() {
0727: return this .username;
0728: }
0729:
0730: public void setUsername(String username) {
0731: this .username = username;
0732: }
0733:
0734: public String getPassword() {
0735: return this .password;
0736: }
0737:
0738: public void setPassword(String password) {
0739: this .password = password;
0740: }
0741:
0742: public void setFinalPageUrl(String finalPageUrl) {
0743: this .finalPageUrl = finalPageUrl;
0744: }
0745:
0746: public String getFinalPageUrl() {
0747: return finalPageUrl;
0748: }
0749:
0750: public String getFeedbackDelivery() {
0751: return feedbackDelivery;
0752: }
0753:
0754: public void setFeedbackDelivery(String feedbackDelivery) {
0755: this .feedbackDelivery = feedbackDelivery;
0756: }
0757:
0758: public boolean getShowQuestionText() {
0759: return showQuestionText;
0760: }
0761:
0762: public void setShowQuestionText(boolean showQuestionText) {
0763: this .showQuestionText = showQuestionText;
0764: }
0765:
0766: public boolean getShowStudentResponse() {
0767: return showStudentResponse;
0768: }
0769:
0770: public void setShowStudentResponse(boolean showStudentResponse) {
0771: this .showStudentResponse = showStudentResponse;
0772: }
0773:
0774: public boolean getShowCorrectResponse() {
0775: return showCorrectResponse;
0776: }
0777:
0778: public void setShowCorrectResponse(boolean showCorrectResponse) {
0779: this .showCorrectResponse = showCorrectResponse;
0780: }
0781:
0782: public boolean getShowStudentScore() {
0783: return showStudentScore;
0784: }
0785:
0786: public void setShowStudentScore(boolean showStudentScore) {
0787: this .showStudentScore = showStudentScore;
0788: }
0789:
0790: public boolean getShowStudentQuestionScore() {
0791: return showStudentQuestionScore;
0792: }
0793:
0794: public void setShowStudentQuestionScore(
0795: boolean showStudentQuestionScore) {
0796: this .showStudentQuestionScore = showStudentQuestionScore;
0797: }
0798:
0799: public boolean getShowQuestionLevelFeedback() {
0800: return showQuestionLevelFeedback;
0801: }
0802:
0803: public void setShowQuestionLevelFeedback(
0804: boolean showQuestionLevelFeedback) {
0805: this .showQuestionLevelFeedback = showQuestionLevelFeedback;
0806: }
0807:
0808: public boolean getShowSelectionLevelFeedback() {
0809: return showSelectionLevelFeedback;
0810: }
0811:
0812: public void setShowSelectionLevelFeedback(
0813: boolean showSelectionLevelFeedback) {
0814: this .showSelectionLevelFeedback = showSelectionLevelFeedback;
0815: }
0816:
0817: public boolean getShowGraderComments() {
0818: return showGraderComments;
0819: }
0820:
0821: public void setShowGraderComments(boolean showGraderComments) {
0822: this .showGraderComments = showGraderComments;
0823: }
0824:
0825: public boolean getShowStatistics() {
0826: return showStatistics;
0827: }
0828:
0829: public void setShowStatistics(boolean showStatistics) {
0830: this .showStatistics = showStatistics;
0831: }
0832:
0833: public String getAnonymousGrading() {
0834: return this .anonymousGrading;
0835: }
0836:
0837: public void setAnonymousGrading(String anonymousGrading) {
0838: this .anonymousGrading = anonymousGrading;
0839: }
0840:
0841: public String getToDefaultGradebook() {
0842: return this .toDefaultGradebook;
0843: }
0844:
0845: public void setToDefaultGradebook(String toDefaultGradebook) {
0846: this .toDefaultGradebook = toDefaultGradebook;
0847: }
0848:
0849: public boolean getGradebookExists() {
0850: return this .gradebookExists;
0851: }
0852:
0853: public void setGradebookExists(boolean gradebookExists) {
0854: this .gradebookExists = gradebookExists;
0855: }
0856:
0857: public String getScoringType() {
0858: return this .scoringType;
0859: }
0860:
0861: public void setScoringType(String scoringType) {
0862: this .scoringType = scoringType;
0863: }
0864:
0865: public void setValue(String key, Object value) {
0866: this .values.put(key, value);
0867: }
0868:
0869: // retrieve value in valueMap
0870: public Boolean getValue(String key) {
0871: Boolean returnValue = Boolean.FALSE;
0872: Object o = this .values.get(key);
0873:
0874: if (("true").equals((String) o))
0875: returnValue = Boolean.TRUE;
0876: return returnValue;
0877: }
0878:
0879: // newMap contains both the regular metadata such as "objectives" as well as
0880: // "can edit" element. However, we only want to have "can edit" elements inside
0881: // our valueMap, so we need to weed out the metadata
0882: public void setValueMap(HashMap newMap) {
0883: HashMap h = new HashMap();
0884: Iterator iter = newMap.keySet().iterator();
0885: while (iter.hasNext()) {
0886: String key = (String) iter.next();
0887: Object o = newMap.get(key);
0888: if ((key.equals("ASSESSMENT_AUTHORS"))
0889: || (key.equals("ASSESSMENT_KEYWORDS"))
0890: || (key.equals("ASSESSMENT_OBJECTIVES"))
0891: || (key.equals("ASSESSMENT_RUBRICS"))
0892: || (key.equals("ASSESSMENT_BGCOLOR"))
0893: || (key.equals("ASSESSMENT_BGIMAGE")))
0894: ;
0895: else {
0896: h.put(key, o);
0897: }
0898: }
0899: this .values = h;
0900: }
0901:
0902: public HashMap getValueMap() {
0903: return values;
0904: }
0905:
0906: public String getDateString(Date date) {
0907: if (date != null) {
0908: Calendar c = Calendar.getInstance();
0909: c.setTime(date);
0910: int mon = c.get(Calendar.MONTH);
0911: int day = c.get(Calendar.DAY_OF_MONTH);
0912: int year = c.get(Calendar.YEAR);
0913: String dateString = mon + "/" + day + "/" + year;
0914: return dateString;
0915: } else
0916: return "";
0917: }
0918:
0919: public void setTimeLimitDisplay(int time) {
0920: this .timedHours = new Integer(time / 60 / 60);
0921: this .timedMinutes = new Integer((time / 60) % 60);
0922: this .timedSeconds = new Integer(time % 60);
0923: }
0924:
0925: public void resetTimeLimitDisplay() {
0926: this .timedHours = new Integer(0);
0927: this .timedMinutes = new Integer(0);
0928: this .timedSeconds = new Integer(0);
0929: }
0930:
0931: // followings are set of SelectItem[] used in authorSettings.jsp
0932: public SelectItem[] getHours() {
0933: return hours;
0934: }
0935:
0936: public static void setHours(SelectItem[] hours) {
0937: AssessmentSettingsBean.hours = hours;
0938: }
0939:
0940: public SelectItem[] getMins() {
0941: return mins;
0942: }
0943:
0944: public static void setMins(SelectItem[] mins) {
0945: AssessmentSettingsBean.mins = mins;
0946: }
0947:
0948: private static List months;
0949: private static List days;
0950: private static SelectItem[] mins;
0951: private static SelectItem[] hours;
0952: // don't know what this is for, had to add it --esmiley
0953: private String feedbackAuthoring;// this was left out, but referenced in UI
0954:
0955: static {
0956: months = new ArrayList();
0957: for (int i = 1; i <= 12; i++) {
0958: months.add(new SelectItem(new Integer(i)));
0959: }
0960: days = new ArrayList();
0961: for (int i = 1; i < 32; i++) {
0962: days.add(new SelectItem(new Integer(i)));
0963: }
0964: hours = new SelectItem[24];
0965: for (int i = 0; i < 24; i++) {
0966: if (i < 10)
0967: hours[i] = new SelectItem(new Integer(i), "0" + i);
0968: else
0969: hours[i] = new SelectItem(new Integer(i), i + "");
0970: }
0971: mins = new SelectItem[60];
0972: for (int i = 0; i < 60; i++) {
0973: if (i < 10)
0974: mins[i] = new SelectItem(new Integer(i), "0" + i);
0975: else
0976: mins[i] = new SelectItem(new Integer(i), i + "");
0977: }
0978: }
0979:
0980: public String getIpAddresses() {
0981: return ipAddresses;
0982: }
0983:
0984: public void setIpAddresses(String ipAddresses) {
0985: this .ipAddresses = ipAddresses;
0986: }
0987:
0988: // the following methods are used to take the internal format from
0989: // calendar picker and move it transparently in and out of the date
0990: // properties
0991:
0992: /**
0993: * date from internal string of calendar widget
0994: * @param date Date object
0995: * @return date String "MM-dd-yyyy hh:mm:ss a"
0996: */
0997: private String getDisplayFormatFromDate(Date date) {
0998: String dateString = "";
0999: if (date == null) {
1000: return dateString;
1001: }
1002:
1003: try {
1004: //dateString = displayFormat.format(date);
1005: TimeUtil tu = new TimeUtil();
1006: dateString = tu.getDisplayDateTime(displayFormat, date);
1007: } catch (Exception ex) {
1008: // we will leave it as an empty string
1009: log.warn("Unable to format date.");
1010: ex.printStackTrace();
1011: }
1012: return dateString;
1013: }
1014:
1015: /**
1016: * format according to internal requirements of calendar widget
1017: * @param dateString "MM-dd-yyyy hh:mm:ss a"
1018: * @return Date object
1019: */
1020: private Date getDateFromDisplayFormat(String dateString) {
1021: Date date = null;
1022: if (dateString == null || dateString.trim().equals("")) {
1023: return date;
1024: }
1025:
1026: try {
1027: //Date date= (Date) displayFormat.parse(dateString);
1028: // dateString is in client timezone, change it to server time zone
1029: TimeUtil tu = new TimeUtil();
1030: date = tu.getServerDateTime(displayFormat, dateString);
1031: } catch (Exception ex) {
1032: // we will leave it as a null date
1033: log.warn("Unable to format date.");
1034: error = true;
1035: ex.printStackTrace();
1036: }
1037:
1038: return date;
1039: }
1040:
1041: public String getStartDateString() {
1042:
1043: return getDisplayFormatFromDate(startDate);
1044:
1045: }
1046:
1047: public void setStartDateString(String startDateString) {
1048: this .startDate = getDateFromDisplayFormat(startDateString);
1049: }
1050:
1051: public String getDueDateString() {
1052: return getDisplayFormatFromDate(dueDate);
1053: }
1054:
1055: public void setDueDateString(String dueDateString) {
1056: this .dueDate = getDateFromDisplayFormat(dueDateString);
1057:
1058: }
1059:
1060: public String getRetractDateString() {
1061: return getDisplayFormatFromDate(retractDate);
1062:
1063: }
1064:
1065: public void setRetractDateString(String retractDateString) {
1066:
1067: this .retractDate = getDateFromDisplayFormat(retractDateString);
1068:
1069: }
1070:
1071: public String getFeedbackDateString() {
1072: return getDisplayFormatFromDate(feedbackDate);
1073: }
1074:
1075: public void setFeedbackDateString(String feedbackDateString) {
1076: this .feedbackDate = getDateFromDisplayFormat(feedbackDateString);
1077: }
1078:
1079: public String getTemplateTitle() {
1080: return this .templateTitle;
1081: }
1082:
1083: public void setTemplateTitle(String title) {
1084: this .templateTitle = title;
1085: }
1086:
1087: public String getTemplateAuthors() {
1088: return this .templateAuthors;
1089: }
1090:
1091: public void setTemplateAuthors(String templateAuthors) {
1092: this .templateAuthors = templateAuthors;
1093: }
1094:
1095: public String getTemplateDescription() {
1096: return this .templateDescription;
1097: }
1098:
1099: public void setTemplateDescription(String templateDescription) {
1100: this .templateDescription = templateDescription;
1101: }
1102:
1103: public boolean getNoTemplate() {
1104: return this .noTemplate;
1105: }
1106:
1107: public void setNoTemplate(boolean noTemplate) {
1108: this .noTemplate = noTemplate;
1109: }
1110:
1111: public boolean validateTarget(String firstTarget) {
1112: HashMap targets = ptHelper.getTargets();
1113: if (targets.get(firstTarget) != null)
1114: return true;
1115: else
1116: return false;
1117: }
1118:
1119: public SelectItem[] getPublishingTargets() {
1120: HashMap targets = ptHelper.getTargets();
1121: Set e = targets.keySet();
1122: Iterator iter = e.iterator();
1123: // sort the targets
1124: String[] titles = new String[targets.size()];
1125: while (iter.hasNext()) {
1126: for (int m = 0; m < e.size(); m++) {
1127: String t = (String) iter.next();
1128: titles[m] = t;
1129: }
1130: }
1131: Arrays.sort(titles);
1132: SelectItem[] target = new SelectItem[targets.size()];
1133: for (int i = 0; i < titles.length; i++) {
1134: //target[i] = new SelectItem(titles[i]);
1135: if (titles[i].equals("Anonymous Users")) {
1136: ResourceLoader rb = new ResourceLoader(
1137: "org.sakaiproject.tool.assessment.bundle.AssessmentSettingsMessages");
1138: target[i] = new SelectItem(titles[i], rb
1139: .getString("anonymous_users"));
1140: } else {
1141: target[i] = new SelectItem(titles[i], titles[i]);
1142: }
1143: }
1144: /**
1145: SelectItem[] target = new SelectItem[targets.size()];
1146: while (iter.hasNext()){
1147: for (int i = 0; i < e.size(); i++) {
1148: target[i] = new SelectItem((String)iter.next());
1149: }
1150: }
1151: */
1152: return target;
1153: }
1154:
1155: public void setTargetSelected(String[] targetSelected) {
1156: this .targetSelected = targetSelected;
1157: }
1158:
1159: public String[] getTargetSelected() {
1160: return targetSelected;
1161: }
1162:
1163: public String[] getTargetSelected(String releaseTo) {
1164: if (releaseTo != null) {
1165: this .targetSelected = releaseTo.split(",");
1166: for (int i = 0; i < targetSelected.length; i++) {
1167: targetSelected[i] = targetSelected[i].trim();
1168: }
1169: }
1170: return this .targetSelected;
1171: }
1172:
1173: public void setFirstTargetSelected(String firstTargetSelected) {
1174: this .firstTargetSelected = firstTargetSelected.trim();
1175: this .targetSelected[0] = firstTargetSelected.trim();
1176: }
1177:
1178: public String getFirstTargetSelected() {
1179: return firstTargetSelected;
1180: }
1181:
1182: public String getFirstTargetSelected(String releaseTo) {
1183: if (releaseTo != null) {
1184: this .targetSelected = releaseTo.split(",");
1185: this .firstTargetSelected = targetSelected[0].trim();
1186: }
1187: return this .firstTargetSelected;
1188: }
1189:
1190: public String getPublishedUrl() {
1191: return this .publishedUrl;
1192: }
1193:
1194: public void setPublishedUrl(String publishedUrl) {
1195: this .publishedUrl = publishedUrl;
1196: }
1197:
1198: public String getAlias() {
1199: return this .alias;
1200: }
1201:
1202: public void setAlias(String alias) {
1203: this .alias = alias;
1204: }
1205:
1206: public String checkDate() {
1207: FacesContext context = FacesContext.getCurrentInstance();
1208: ResourceLoader rb = new ResourceLoader(
1209: "org.sakaiproject.tool.assessment.bundle.AuthorMessages");
1210: String err;
1211: if (this .error) {
1212: err = rb.getString("deliveryDate_error");
1213: context.addMessage(null, new FacesMessage(err));
1214: log.error("START DATE ADD MESSAGE");
1215: return "deliveryDate_error";
1216: } else {
1217: return "saveSettings";
1218: }
1219:
1220: }
1221:
1222: public String getFeedbackAuthoring() {
1223: return feedbackAuthoring;
1224: }
1225:
1226: public void setFeedbackAuthoring(String feedbackAuthoring) {
1227: this .feedbackAuthoring = feedbackAuthoring;
1228: }
1229:
1230: public List getAttachmentList() {
1231: return attachmentList;
1232: }
1233:
1234: public void setAttachmentList(List attachmentList) {
1235: this .attachmentList = attachmentList;
1236: }
1237:
1238: private boolean hasAttachment = false;
1239:
1240: public boolean getHasAttachment() {
1241: if (attachmentList != null && attachmentList.size() > 0)
1242: this .hasAttachment = true;
1243: return this .hasAttachment;
1244: }
1245:
1246: public String addAttachmentsRedirect() {
1247: // 1. redirect to add attachment
1248: try {
1249: List filePickerList = new ArrayList();
1250: if (attachmentList != null) {
1251: filePickerList = prepareReferenceList(attachmentList);
1252: }
1253: ToolSession currentToolSession = SessionManager
1254: .getCurrentToolSession();
1255: currentToolSession.setAttribute(
1256: FilePickerHelper.FILE_PICKER_ATTACHMENTS,
1257: filePickerList);
1258: ExternalContext context = FacesContext.getCurrentInstance()
1259: .getExternalContext();
1260: context.redirect("sakai.filepicker.helper/tool");
1261: } catch (Exception e) {
1262: log.error("fail to redirect to attachment page: "
1263: + e.getMessage());
1264: }
1265: return "editAssessmentSettings";
1266: }
1267:
1268: public void setAssessmentAttachment() {
1269: SaveAssessmentAttachmentListener lis = new SaveAssessmentAttachmentListener();
1270: lis.processAction(null);
1271: }
1272:
1273: private List prepareReferenceList(List attachmentList) {
1274: List list = new ArrayList();
1275: for (int i = 0; i < attachmentList.size(); i++) {
1276: ContentResource cr = null;
1277: AttachmentIfc attach = (AttachmentIfc) attachmentList
1278: .get(i);
1279: try {
1280: cr = ContentHostingService.getResource(attach
1281: .getResourceId());
1282: } catch (PermissionException e) {
1283: log
1284: .warn("PermissionException from ContentHostingService:"
1285: + e.getMessage());
1286: } catch (IdUnusedException e) {
1287: log
1288: .warn("IdUnusedException from ContentHostingService:"
1289: + e.getMessage());
1290: // <-- bad sign, some left over association of assessment and resource,
1291: // use case: user remove resource in file picker, then exit modification without
1292: // proper cancellation by clicking at the left nav instead of "cancel".
1293: // Also in this use case, any added resource would be left orphan.
1294: AssessmentService assessmentService = new AssessmentService();
1295: assessmentService.removeAssessmentAttachment(attach
1296: .getAttachmentId().toString());
1297: } catch (TypeException e) {
1298: log.warn("TypeException from ContentHostingService:"
1299: + e.getMessage());
1300: }
1301: if (cr != null) {
1302: ReferenceComponent ref = new ReferenceComponent(cr
1303: .getReference());
1304: if (ref != null)
1305: list.add(ref);
1306: }
1307: }
1308: return list;
1309: }
1310:
1311: private HashMap resourceHash = new HashMap();
1312:
1313: public HashMap getResourceHash() {
1314: return resourceHash;
1315: }
1316:
1317: public void setResourceHash(HashMap resourceHash) {
1318: this.resourceHash = resourceHash;
1319: }
1320: }
|