0001: /**********************************************************************************
0002: * $URL: https://source.sakaiproject.org/svn/assignment/tags/sakai_2-4-1/assignment-tool/tool/src/java/org/sakaiproject/assignment/tool/AssignmentAction.java $
0003: * $Id: AssignmentAction.java 20376 2007-01-17 16:27:10Z lance@indiana.edu $
0004: ***********************************************************************************
0005: *
0006: * Copyright (c) 2003, 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.assignment.tool;
0021:
0022: import java.util.ArrayList;
0023: import java.util.Arrays;
0024: import java.util.Collection;
0025: import java.util.Collections;
0026: import java.util.Comparator;
0027: import java.util.Date;
0028: import java.util.Hashtable;
0029: import java.util.Iterator;
0030: import java.util.List;
0031: import java.util.HashMap;
0032: import java.util.Map;
0033: import java.util.Set;
0034: import java.util.Vector;
0035:
0036: import org.sakaiproject.announcement.api.AnnouncementChannel;
0037: import org.sakaiproject.announcement.api.AnnouncementMessageEdit;
0038: import org.sakaiproject.announcement.api.AnnouncementMessageHeaderEdit;
0039: import org.sakaiproject.announcement.api.AnnouncementService;
0040: import org.sakaiproject.assignment.api.Assignment;
0041: import org.sakaiproject.assignment.api.AssignmentContentEdit;
0042: import org.sakaiproject.assignment.api.AssignmentEdit;
0043: import org.sakaiproject.assignment.api.AssignmentSubmission;
0044: import org.sakaiproject.assignment.api.AssignmentSubmissionEdit;
0045: import org.sakaiproject.assignment.cover.AssignmentService;
0046: import org.sakaiproject.authz.api.AuthzGroup;
0047: import org.sakaiproject.authz.api.PermissionsHelper;
0048: import org.sakaiproject.authz.cover.AuthzGroupService;
0049: import org.sakaiproject.calendar.api.Calendar;
0050: import org.sakaiproject.calendar.api.CalendarEvent;
0051: import org.sakaiproject.calendar.api.CalendarService;
0052: import org.sakaiproject.cheftool.Context;
0053: import org.sakaiproject.cheftool.JetspeedRunData;
0054: import org.sakaiproject.cheftool.PagedResourceActionII;
0055: import org.sakaiproject.cheftool.PortletConfig;
0056: import org.sakaiproject.cheftool.RunData;
0057: import org.sakaiproject.cheftool.VelocityPortlet;
0058: import org.sakaiproject.component.cover.ComponentManager;
0059: import org.sakaiproject.component.cover.ServerConfigurationService;
0060: import org.sakaiproject.content.api.ContentTypeImageService;
0061: import org.sakaiproject.content.api.FilePickerHelper;
0062: import org.sakaiproject.entity.api.Reference;
0063: import org.sakaiproject.entity.api.ResourceProperties;
0064: import org.sakaiproject.entity.api.ResourcePropertiesEdit;
0065: import org.sakaiproject.entity.cover.EntityManager;
0066: import org.sakaiproject.event.api.SessionState;
0067: import org.sakaiproject.event.cover.EventTrackingService;
0068: import org.sakaiproject.event.cover.NotificationService;
0069: import org.sakaiproject.exception.IdInvalidException;
0070: import org.sakaiproject.exception.IdUnusedException;
0071: import org.sakaiproject.exception.IdUsedException;
0072: import org.sakaiproject.exception.InUseException;
0073: import org.sakaiproject.exception.PermissionException;
0074: import org.sakaiproject.javax.PagingPosition;
0075: import org.sakaiproject.service.gradebook.shared.AssignmentHasIllegalPointsException;
0076: import org.sakaiproject.service.gradebook.shared.ConflictingAssignmentNameException;
0077: import org.sakaiproject.service.gradebook.shared.ConflictingExternalIdException;
0078: import org.sakaiproject.service.gradebook.shared.GradebookNotFoundException;
0079: import org.sakaiproject.service.gradebook.shared.GradebookService;
0080: import org.sakaiproject.site.api.Group;
0081: import org.sakaiproject.site.api.Site;
0082: import org.sakaiproject.site.cover.SiteService;
0083: import org.sakaiproject.time.api.Time;
0084: import org.sakaiproject.time.api.TimeBreakdown;
0085: import org.sakaiproject.time.cover.TimeService;
0086: import org.sakaiproject.tool.cover.ToolManager;
0087: import org.sakaiproject.tool.api.Tool;
0088: import org.sakaiproject.user.api.User;
0089: import org.sakaiproject.user.cover.UserDirectoryService;
0090: import org.sakaiproject.util.FormattedText;
0091: import org.sakaiproject.util.ParameterParser;
0092: import org.sakaiproject.util.ResourceLoader;
0093: import org.sakaiproject.util.SortedIterator;
0094: import org.sakaiproject.util.StringUtil;
0095: import org.sakaiproject.util.Validator;
0096:
0097: /**
0098: * <p>
0099: * AssignmentAction is the action class for the assignment tool.
0100: * </p>
0101: */
0102: public class AssignmentAction extends PagedResourceActionII {
0103: private static ResourceLoader rb = new ResourceLoader("assignment");
0104:
0105: /** The attachments */
0106: private static final String ATTACHMENTS = "Assignment.attachments";
0107:
0108: /** The content type image lookup service in the State. */
0109: private static final String STATE_CONTENT_TYPE_IMAGE_SERVICE = "Assignment.content_type_image_service";
0110:
0111: /** The calendar service in the State. */
0112: private static final String STATE_CALENDAR_SERVICE = "Assignment.calendar_service";
0113:
0114: /** The announcement service in the State. */
0115: private static final String STATE_ANNOUNCEMENT_SERVICE = "Assignment.announcement_service";
0116:
0117: /** The calendar object */
0118: private static final String CALENDAR = "calendar";
0119:
0120: /** The announcement channel */
0121: private static final String ANNOUNCEMENT_CHANNEL = "announcement_channel";
0122:
0123: /** The state mode */
0124: private static final String STATE_MODE = "Assignment.mode";
0125:
0126: /** The context string */
0127: private static final String STATE_CONTEXT_STRING = "Assignment.context_string";
0128:
0129: /** The user */
0130: private static final String STATE_USER = "Assignment.user";
0131:
0132: // SECTION MOD
0133: /** Used to keep track of the section info not currently being used. */
0134: private static final String STATE_SECTION_STRING = "Assignment.section_string";
0135:
0136: /** **************************** sort assignment ********************** */
0137: /** state sort * */
0138: private static final String SORTED_BY = "Assignment.sorted_by";
0139:
0140: /** state sort ascendingly * */
0141: private static final String SORTED_ASC = "Assignment.sorted_asc";
0142:
0143: /** sort by assignment title */
0144: private static final String SORTED_BY_TITLE = "title";
0145:
0146: /** sort by assignment section */
0147: private static final String SORTED_BY_SECTION = "section";
0148:
0149: /** sort by assignment due date */
0150: private static final String SORTED_BY_DUEDATE = "duedate";
0151:
0152: /** sort by assignment open date */
0153: private static final String SORTED_BY_OPENDATE = "opendate";
0154:
0155: /** sort by assignment status */
0156: private static final String SORTED_BY_ASSIGNMENT_STATUS = "assignment_status";
0157:
0158: /** sort by assignment submission status */
0159: private static final String SORTED_BY_SUBMISSION_STATUS = "submission_status";
0160:
0161: /** sort by assignment number of submissions */
0162: private static final String SORTED_BY_NUM_SUBMISSIONS = "num_submissions";
0163:
0164: /** sort by assignment number of ungraded submissions */
0165: private static final String SORTED_BY_NUM_UNGRADED = "num_ungraded";
0166:
0167: /** sort by assignment submission grade */
0168: private static final String SORTED_BY_GRADE = "grade";
0169:
0170: /** sort by assignment maximun grade available */
0171: private static final String SORTED_BY_MAX_GRADE = "max_grade";
0172:
0173: /** sort by assignment range */
0174: private static final String SORTED_BY_FOR = "for";
0175:
0176: /** sort by group title */
0177: private static final String SORTED_BY_GROUP_TITLE = "group_title";
0178:
0179: /** sort by group description */
0180: private static final String SORTED_BY_GROUP_DESCRIPTION = "group_description";
0181:
0182: /** *************************** sort submission in instructor grade view *********************** */
0183: /** state sort submission* */
0184: private static final String SORTED_GRADE_SUBMISSION_BY = "Assignment.grade_submission_sorted_by";
0185:
0186: /** state sort submission ascendingly * */
0187: private static final String SORTED_GRADE_SUBMISSION_ASC = "Assignment.grade_submission_sorted_asc";
0188:
0189: /** state sort submission by submitters last name * */
0190: private static final String SORTED_GRADE_SUBMISSION_BY_LASTNAME = "sorted_grade_submission_by_lastname";
0191:
0192: /** state sort submission by submit time * */
0193: private static final String SORTED_GRADE_SUBMISSION_BY_SUBMIT_TIME = "sorted_grade_submission_by_submit_time";
0194:
0195: /** state sort submission by submission status * */
0196: private static final String SORTED_GRADE_SUBMISSION_BY_STATUS = "sorted_grade_submission_by_status";
0197:
0198: /** state sort submission by submission grade * */
0199: private static final String SORTED_GRADE_SUBMISSION_BY_GRADE = "sorted_grade_submission_by_grade";
0200:
0201: /** state sort submission by submission released * */
0202: private static final String SORTED_GRADE_SUBMISSION_BY_RELEASED = "sorted_grade_submission_by_released";
0203:
0204: /** *************************** sort submission *********************** */
0205: /** state sort submission* */
0206: private static final String SORTED_SUBMISSION_BY = "Assignment.submission_sorted_by";
0207:
0208: /** state sort submission ascendingly * */
0209: private static final String SORTED_SUBMISSION_ASC = "Assignment.submission_sorted_asc";
0210:
0211: /** state sort submission by submitters last name * */
0212: private static final String SORTED_SUBMISSION_BY_LASTNAME = "sorted_submission_by_lastname";
0213:
0214: /** state sort submission by submit time * */
0215: private static final String SORTED_SUBMISSION_BY_SUBMIT_TIME = "sorted_submission_by_submit_time";
0216:
0217: /** state sort submission by submission grade * */
0218: private static final String SORTED_SUBMISSION_BY_GRADE = "sorted_submission_by_grade";
0219:
0220: /** state sort submission by submission status * */
0221: private static final String SORTED_SUBMISSION_BY_STATUS = "sorted_submission_by_status";
0222:
0223: /** state sort submission by submission released * */
0224: private static final String SORTED_SUBMISSION_BY_RELEASED = "sorted_submission_by_released";
0225:
0226: /** state sort submission by assignment title */
0227: private static final String SORTED_SUBMISSION_BY_ASSIGNMENT = "sorted_submission_by_assignment";
0228:
0229: /** state sort submission by max grade */
0230: private static final String SORTED_SUBMISSION_BY_MAX_GRADE = "sorted_submission_by_max_grade";
0231:
0232: /** ******************** student's view assignment submission ****************************** */
0233: /** the assignment object been viewing * */
0234: private static final String VIEW_SUBMISSION_ASSIGNMENT_REFERENCE = "Assignment.view_submission_assignment_reference";
0235:
0236: /** the submission text to the assignment * */
0237: private static final String VIEW_SUBMISSION_TEXT = "Assignment.view_submission_text";
0238:
0239: /** the submission answer to Honor Pledge * */
0240: private static final String VIEW_SUBMISSION_HONOR_PLEDGE_YES = "Assignment.view_submission_honor_pledge_yes";
0241:
0242: /** ***************** student's preview of submission *************************** */
0243: /** the assignment id * */
0244: private static final String PREVIEW_SUBMISSION_ASSIGNMENT_REFERENCE = "preview_submission_assignment_reference";
0245:
0246: /** the submission text * */
0247: private static final String PREVIEW_SUBMISSION_TEXT = "preview_submission_text";
0248:
0249: /** the submission honor pledge answer * */
0250: private static final String PREVIEW_SUBMISSION_HONOR_PLEDGE_YES = "preview_submission_honor_pledge_yes";
0251:
0252: /** the submission attachments * */
0253: private static final String PREVIEW_SUBMISSION_ATTACHMENTS = "preview_attachments";
0254:
0255: /** the flag indicate whether the to show the student view or not */
0256: private static final String PREVIEW_ASSIGNMENT_STUDENT_VIEW_HIDE_FLAG = "preview_assignment_student_view_hide_flag";
0257:
0258: /** the flag indicate whether the to show the assignment info or not */
0259: private static final String PREVIEW_ASSIGNMENT_ASSIGNMENT_HIDE_FLAG = "preview_assignment_assignment_hide_flag";
0260:
0261: /** the assignment id */
0262: private static final String PREVIEW_ASSIGNMENT_ASSIGNMENT_ID = "preview_assignment_assignment_id";
0263:
0264: /** the assignment content id */
0265: private static final String PREVIEW_ASSIGNMENT_ASSIGNMENTCONTENT_ID = "preview_assignment_assignmentcontent_id";
0266:
0267: /** ************** view assignment ***************************************** */
0268: /** the hide assignment flag in the view assignment page * */
0269: private static final String VIEW_ASSIGNMENT_HIDE_ASSIGNMENT_FLAG = "view_assignment_hide_assignment_flag";
0270:
0271: /** the hide student view flag in the view assignment page * */
0272: private static final String VIEW_ASSIGNMENT_HIDE_STUDENT_VIEW_FLAG = "view_assignment_hide_student_view_flag";
0273:
0274: /** ******************* instructor's view assignment ***************************** */
0275: private static final String VIEW_ASSIGNMENT_ID = "view_assignment_id";
0276:
0277: /** ******************* instructor's edit assignment ***************************** */
0278: private static final String EDIT_ASSIGNMENT_ID = "edit_assignment_id";
0279:
0280: /** ******************* instructor's delete assignment ids ***************************** */
0281: private static final String DELETE_ASSIGNMENT_IDS = "delete_assignment_ids";
0282:
0283: /** ******************* flags controls the grade assignment page layout ******************* */
0284: private static final String GRADE_ASSIGNMENT_EXPAND_FLAG = "grade_assignment_expand_flag";
0285:
0286: private static final String GRADE_SUBMISSION_EXPAND_FLAG = "grade_submission_expand_flag";
0287:
0288: /** ******************* instructor's grade submission ***************************** */
0289: private static final String GRADE_SUBMISSION_ASSIGNMENT_ID = "grade_submission_assignment_id";
0290:
0291: private static final String GRADE_SUBMISSION_SUBMISSION_ID = "grade_submission_submission_id";
0292:
0293: private static final String GRADE_SUBMISSION_FEEDBACK_COMMENT = "grade_submission_feedback_comment";
0294:
0295: private static final String GRADE_SUBMISSION_FEEDBACK_TEXT = "grade_submission_feedback_text";
0296:
0297: private static final String GRADE_SUBMISSION_FEEDBACK_ATTACHMENT = "grade_submission_feedback_attachment";
0298:
0299: private static final String GRADE_SUBMISSION_GRADE = "grade_submission_grade";
0300:
0301: private static final String GRADE_SUBMISSION_ASSIGNMENT_EXPAND_FLAG = "grade_submission_assignment_expand_flag";
0302:
0303: private static final String GRADE_SUBMISSION_ALLOW_RESUBMIT = "grade_submission_allow_resubmit";
0304:
0305: /** ******************* instructor's export assignment ***************************** */
0306: private static final String EXPORT_ASSIGNMENT_REF = "export_assignment_ref";
0307:
0308: private static final String EXPORT_ASSIGNMENT_ID = "export_assignment_id";
0309:
0310: /** ****************** instructor's new assignment ****************************** */
0311: private static final String NEW_ASSIGNMENT_TITLE = "new_assignment_title";
0312:
0313: // open date
0314: private static final String NEW_ASSIGNMENT_OPENMONTH = "new_assignment_openmonth";
0315:
0316: private static final String NEW_ASSIGNMENT_OPENDAY = "new_assignment_openday";
0317:
0318: private static final String NEW_ASSIGNMENT_OPENYEAR = "new_assignment_openyear";
0319:
0320: private static final String NEW_ASSIGNMENT_OPENHOUR = "new_assignment_openhour";
0321:
0322: private static final String NEW_ASSIGNMENT_OPENMIN = "new_assignment_openmin";
0323:
0324: private static final String NEW_ASSIGNMENT_OPENAMPM = "new_assignment_openampm";
0325:
0326: // due date
0327: private static final String NEW_ASSIGNMENT_DUEMONTH = "new_assignment_duemonth";
0328:
0329: private static final String NEW_ASSIGNMENT_DUEDAY = "new_assignment_dueday";
0330:
0331: private static final String NEW_ASSIGNMENT_DUEYEAR = "new_assignment_dueyear";
0332:
0333: private static final String NEW_ASSIGNMENT_DUEHOUR = "new_assignment_duehour";
0334:
0335: private static final String NEW_ASSIGNMENT_DUEMIN = "new_assignment_duemin";
0336:
0337: private static final String NEW_ASSIGNMENT_DUEAMPM = "new_assignment_dueampm";
0338:
0339: // close date
0340: private static final String NEW_ASSIGNMENT_ENABLECLOSEDATE = "new_assignment_enableclosedate";
0341:
0342: private static final String NEW_ASSIGNMENT_CLOSEMONTH = "new_assignment_closemonth";
0343:
0344: private static final String NEW_ASSIGNMENT_CLOSEDAY = "new_assignment_closeday";
0345:
0346: private static final String NEW_ASSIGNMENT_CLOSEYEAR = "new_assignment_closeyear";
0347:
0348: private static final String NEW_ASSIGNMENT_CLOSEHOUR = "new_assignment_closehour";
0349:
0350: private static final String NEW_ASSIGNMENT_CLOSEMIN = "new_assignment_closemin";
0351:
0352: private static final String NEW_ASSIGNMENT_CLOSEAMPM = "new_assignment_closeampm";
0353:
0354: private static final String NEW_ASSIGNMENT_ATTACHMENT = "new_assignment_attachment";
0355:
0356: private static final String NEW_ASSIGNMENT_SECTION = "new_assignment_section";
0357:
0358: private static final String NEW_ASSIGNMENT_SUBMISSION_TYPE = "new_assignment_submission_type";
0359:
0360: private static final String NEW_ASSIGNMENT_GRADE_TYPE = "new_assignment_grade_type";
0361:
0362: private static final String NEW_ASSIGNMENT_GRADE_POINTS = "new_assignment_grade_points";
0363:
0364: private static final String NEW_ASSIGNMENT_DESCRIPTION = "new_assignment_instructions";
0365:
0366: private static final String NEW_ASSIGNMENT_DUE_DATE_SCHEDULED = "new_assignment_due_date_scheduled";
0367:
0368: private static final String NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED = "new_assignment_open_date_announced";
0369:
0370: private static final String NEW_ASSIGNMENT_CHECK_ADD_HONOR_PLEDGE = "new_assignment_check_add_honor_pledge";
0371:
0372: private static final String NEW_ASSIGNMENT_HIDE_OPTION_FLAG = "new_assignment_hide_option_flag";
0373:
0374: private static final String NEW_ASSIGNMENT_FOCUS = "new_assignment_focus";
0375:
0376: private static final String NEW_ASSIGNMENT_DESCRIPTION_EMPTY = "new_assignment_description_empty";
0377:
0378: private static final String NEW_ASSIGNMENT_ADD_TO_GRADEBOOK = "new_assignment_add_to_gradebook";
0379:
0380: // the three choices for Gradebook Integration
0381: private static final String GRADEBOOK_INTEGRATION_NO = "no";
0382: private static final String GRADEBOOK_INTEGRATION_ADD = "add";
0383: private static final String GRADEBOOK_INTEGRATION_ASSOCIATE = "associate";
0384:
0385: private static final String NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT = "new_assignment_associate_gradebook_assignment";
0386:
0387: private static final String NEW_ASSIGNMENT_RANGE = "new_assignment_range";
0388:
0389: private static final String NEW_ASSIGNMENT_GROUPS = "new_assignment_groups";
0390:
0391: private static final String ATTACHMENTS_MODIFIED = "attachments_modified";
0392:
0393: /** **************************** instructor's view student submission ***************** */
0394: // the show/hide table based on member id
0395: private static final String STUDENT_LIST_SHOW_TABLE = "STUDENT_LIST_SHOW_TABLE";
0396:
0397: /** **************************** student view grade submission id *********** */
0398: private static final String VIEW_GRADE_SUBMISSION_ID = "view_grade_submission_id";
0399:
0400: // alert for grade exceeds max grade setting
0401: private static final String GRADE_GREATER_THAN_MAX_ALERT = "grade_greater_than_max_alert";
0402:
0403: /** **************************** modes *************************** */
0404: /** The list view of assignments */
0405: private static final String MODE_LIST_ASSIGNMENTS = "lisofass1"; // set in velocity template
0406:
0407: /** The student view of an assignment submission */
0408: private static final String MODE_STUDENT_VIEW_SUBMISSION = "Assignment.mode_view_submission";
0409:
0410: /** The student preview of an assignment submission */
0411: private static final String MODE_STUDENT_PREVIEW_SUBMISSION = "Assignment.mode_student_preview_submission";
0412:
0413: /** The student view of graded submission */
0414: private static final String MODE_STUDENT_VIEW_GRADE = "Assignment.mode_student_view_grade";
0415:
0416: /** The student view of assignments */
0417: private static final String MODE_STUDENT_VIEW_ASSIGNMENT = "Assignment.mode_student_view_assignment";
0418:
0419: /** The instructor view of creating a new assignment or editing an existing one */
0420: private static final String MODE_INSTRUCTOR_NEW_EDIT_ASSIGNMENT = "Assignment.mode_instructor_new_edit_assignment";
0421:
0422: /** The instructor view to delete an assignment */
0423: private static final String MODE_INSTRUCTOR_DELETE_ASSIGNMENT = "Assignment.mode_instructor_delete_assignment";
0424:
0425: /** The instructor view to grade an assignment */
0426: private static final String MODE_INSTRUCTOR_GRADE_ASSIGNMENT = "Assignment.mode_instructor_grade_assignment";
0427:
0428: /** The instructor view to grade a submission */
0429: private static final String MODE_INSTRUCTOR_GRADE_SUBMISSION = "Assignment.mode_instructor_grade_submission";
0430:
0431: /** The instructor view of preview grading a submission */
0432: private static final String MODE_INSTRUCTOR_PREVIEW_GRADE_SUBMISSION = "Assignment.mode_instructor_preview_grade_submission";
0433:
0434: /** The instructor preview of one assignment */
0435: private static final String MODE_INSTRUCTOR_PREVIEW_ASSIGNMENT = "Assignment.mode_instructor_preview_assignments";
0436:
0437: /** The instructor view of one assignment */
0438: private static final String MODE_INSTRUCTOR_VIEW_ASSIGNMENT = "Assignment.mode_instructor_view_assignments";
0439:
0440: /** The instructor view to list students of an assignment */
0441: private static final String MODE_INSTRUCTOR_VIEW_STUDENTS_ASSIGNMENT = "lisofass2"; // set in velocity template
0442:
0443: /** The instructor view of assignment submission report */
0444: private static final String MODE_INSTRUCTOR_REPORT_SUBMISSIONS = "grarep"; // set in velocity template
0445:
0446: /** The student view of assignment submission report */
0447: private static final String MODE_STUDENT_VIEW = "stuvie"; // set in velocity template
0448:
0449: /** ************************* vm names ************************** */
0450: /** The list view of assignments */
0451: private static final String TEMPLATE_LIST_ASSIGNMENTS = "_list_assignments";
0452:
0453: /** The student view of assignment */
0454: private static final String TEMPLATE_STUDENT_VIEW_ASSIGNMENT = "_student_view_assignment";
0455:
0456: /** The student view of showing an assignment submission */
0457: private static final String TEMPLATE_STUDENT_VIEW_SUBMISSION = "_student_view_submission";
0458:
0459: /** The student preview an assignment submission */
0460: private static final String TEMPLATE_STUDENT_PREVIEW_SUBMISSION = "_student_preview_submission";
0461:
0462: /** The student view of graded submission */
0463: private static final String TEMPLATE_STUDENT_VIEW_GRADE = "_student_view_grade";
0464:
0465: /** The instructor view to create a new assignment or edit an existing one */
0466: private static final String TEMPLATE_INSTRUCTOR_NEW_EDIT_ASSIGNMENT = "_instructor_new_edit_assignment";
0467:
0468: /** The instructor view to edit assignment */
0469: private static final String TEMPLATE_INSTRUCTOR_DELETE_ASSIGNMENT = "_instructor_delete_assignment";
0470:
0471: /** The instructor view to edit assignment */
0472: private static final String TEMPLATE_INSTRUCTOR_GRADE_SUBMISSION = "_instructor_grading_submission";
0473:
0474: /** The instructor preview to edit assignment */
0475: private static final String TEMPLATE_INSTRUCTOR_PREVIEW_GRADE_SUBMISSION = "_instructor_preview_grading_submission";
0476:
0477: /** The instructor view to grade the assignment */
0478: private static final String TEMPLATE_INSTRUCTOR_GRADE_ASSIGNMENT = "_instructor_list_submissions";
0479:
0480: /** The instructor preview of assignment */
0481: private static final String TEMPLATE_INSTRUCTOR_PREVIEW_ASSIGNMENT = "_instructor_preview_assignment";
0482:
0483: /** The instructor view of assignment */
0484: private static final String TEMPLATE_INSTRUCTOR_VIEW_ASSIGNMENT = "_instructor_view_assignment";
0485:
0486: /** The instructor view to edit assignment */
0487: private static final String TEMPLATE_INSTRUCTOR_VIEW_STUDENTS_ASSIGNMENT = "_instructor_student_list_submissions";
0488:
0489: /** The instructor view to assignment submission report */
0490: private static final String TEMPLATE_INSTRUCTOR_REPORT_SUBMISSIONS = "_instructor_report_submissions";
0491:
0492: /** The opening mark comment */
0493: private static final String COMMENT_OPEN = "{{";
0494:
0495: /** The closing mark for comment */
0496: private static final String COMMENT_CLOSE = "}}";
0497:
0498: /** The selected view */
0499: private static final String STATE_SELECTED_VIEW = "state_selected_view";
0500:
0501: /** The configuration choice of with grading option or not */
0502: private static final String WITH_GRADES = "with_grades";
0503:
0504: /** The alert flag when doing global navigation from improper mode */
0505: private static final String ALERT_GLOBAL_NAVIGATION = "alert_global_navigation";
0506:
0507: /** The total list item before paging */
0508: private static final String STATE_PAGEING_TOTAL_ITEMS = "state_paging_total_items";
0509:
0510: /** is current user allowed to grade assignment? */
0511: private static final String STATE_ALLOW_GRADE_SUBMISSION = "state_allow_grade_submission";
0512:
0513: /** property for previous feedback attachments **/
0514: private static final String PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS = "prop_submission_previous_feedback_attachments";
0515:
0516: /**
0517: * central place for dispatching the build routines based on the state name
0518: */
0519: public String buildMainPanelContext(VelocityPortlet portlet,
0520: Context context, RunData data, SessionState state) {
0521: String template = null;
0522:
0523: context.put("tlang", rb);
0524:
0525: context.put("cheffeedbackhelper", this );
0526:
0527: String contextString = (String) state
0528: .getAttribute(STATE_CONTEXT_STRING);
0529:
0530: // allow add assignment?
0531: boolean allowAddAssignment = AssignmentService
0532: .allowAddAssignment(contextString);
0533: context.put("allowAddAssignment", Boolean
0534: .valueOf(allowAddAssignment));
0535:
0536: Object allowGradeSubmission = state
0537: .getAttribute(STATE_ALLOW_GRADE_SUBMISSION);
0538:
0539: // allow update site?
0540: context.put("allowUpdateSite", Boolean.valueOf(SiteService
0541: .allowUpdateSite((String) state
0542: .getAttribute(STATE_CONTEXT_STRING))));
0543:
0544: // grading option
0545: context.put("withGrade", state.getAttribute(WITH_GRADES));
0546:
0547: String mode = (String) state.getAttribute(STATE_MODE);
0548:
0549: if (!mode.equals(MODE_LIST_ASSIGNMENTS)) {
0550: // allow grade assignment?
0551: if (state.getAttribute(STATE_ALLOW_GRADE_SUBMISSION) == null) {
0552: state.setAttribute(STATE_ALLOW_GRADE_SUBMISSION,
0553: Boolean.FALSE);
0554: }
0555: context.put("allowGradeSubmission", state
0556: .getAttribute(STATE_ALLOW_GRADE_SUBMISSION));
0557: }
0558:
0559: if (mode.equals(MODE_LIST_ASSIGNMENTS)) {
0560: // build the context for the student assignment view
0561: template = build_list_assignments_context(portlet, context,
0562: data, state);
0563: } else if (mode.equals(MODE_STUDENT_VIEW_ASSIGNMENT)) {
0564: // the student view of assignment
0565: template = build_student_view_assignment_context(portlet,
0566: context, data, state);
0567: } else if (mode.equals(MODE_STUDENT_VIEW_SUBMISSION)) {
0568: // disable auto-updates while leaving the list view
0569: justDelivered(state);
0570:
0571: // build the context for showing one assignment submission
0572: template = build_student_view_submission_context(portlet,
0573: context, data, state);
0574: } else if (mode.equals(MODE_STUDENT_PREVIEW_SUBMISSION)) {
0575: // build the context for showing one assignment submission
0576: template = build_student_preview_submission_context(
0577: portlet, context, data, state);
0578: } else if (mode.equals(MODE_STUDENT_VIEW_GRADE)) {
0579: // disable auto-updates while leaving the list view
0580: justDelivered(state);
0581:
0582: // build the context for showing one graded submission
0583: template = build_student_view_grade_context(portlet,
0584: context, data, state);
0585: } else if (mode.equals(MODE_INSTRUCTOR_NEW_EDIT_ASSIGNMENT)) {
0586: // allow add assignment?
0587: boolean allowAddSiteAssignment = AssignmentService
0588: .allowAddSiteAssignment(contextString);
0589: context.put("allowAddSiteAssignment", Boolean
0590: .valueOf(allowAddSiteAssignment));
0591:
0592: // disable auto-updates while leaving the list view
0593: justDelivered(state);
0594:
0595: // build the context for the instructor's create new assignment view
0596: template = build_instructor_new_edit_assignment_context(
0597: portlet, context, data, state);
0598: } else if (mode.equals(MODE_INSTRUCTOR_DELETE_ASSIGNMENT)) {
0599: if (state.getAttribute(DELETE_ASSIGNMENT_IDS) != null) {
0600: // disable auto-updates while leaving the list view
0601: justDelivered(state);
0602:
0603: // build the context for the instructor's delete assignment
0604: template = build_instructor_delete_assignment_context(
0605: portlet, context, data, state);
0606: }
0607: } else if (mode.equals(MODE_INSTRUCTOR_GRADE_ASSIGNMENT)) {
0608: if (allowGradeSubmission != null
0609: && ((Boolean) allowGradeSubmission).booleanValue()) {
0610: // if allowed for grading, build the context for the instructor's grade assignment
0611: template = build_instructor_grade_assignment_context(
0612: portlet, context, data, state);
0613: }
0614: } else if (mode.equals(MODE_INSTRUCTOR_GRADE_SUBMISSION)) {
0615: if (allowGradeSubmission != null
0616: && ((Boolean) allowGradeSubmission).booleanValue()) {
0617: // if allowed for grading, disable auto-updates while leaving the list view
0618: justDelivered(state);
0619:
0620: // build the context for the instructor's grade submission
0621: template = build_instructor_grade_submission_context(
0622: portlet, context, data, state);
0623: }
0624: } else if (mode
0625: .equals(MODE_INSTRUCTOR_PREVIEW_GRADE_SUBMISSION)) {
0626: if (allowGradeSubmission != null
0627: && ((Boolean) allowGradeSubmission).booleanValue()) {
0628: // if allowed for grading, build the context for the instructor's preview grade submission
0629: template = build_instructor_preview_grade_submission_context(
0630: portlet, context, data, state);
0631: }
0632: } else if (mode.equals(MODE_INSTRUCTOR_PREVIEW_ASSIGNMENT)) {
0633: // build the context for preview one assignment
0634: template = build_instructor_preview_assignment_context(
0635: portlet, context, data, state);
0636: } else if (mode.equals(MODE_INSTRUCTOR_VIEW_ASSIGNMENT)) {
0637: // disable auto-updates while leaving the list view
0638: justDelivered(state);
0639:
0640: // build the context for view one assignment
0641: template = build_instructor_view_assignment_context(
0642: portlet, context, data, state);
0643: } else if (mode
0644: .equals(MODE_INSTRUCTOR_VIEW_STUDENTS_ASSIGNMENT)) {
0645: if (allowGradeSubmission != null
0646: && ((Boolean) allowGradeSubmission).booleanValue()) {
0647: // if allowed for grading, build the context for the instructor's create new assignment view
0648: template = build_instructor_view_students_assignment_context(
0649: portlet, context, data, state);
0650: }
0651: } else if (mode.equals(MODE_INSTRUCTOR_REPORT_SUBMISSIONS)) {
0652: if (allowGradeSubmission != null
0653: && ((Boolean) allowGradeSubmission).booleanValue()) {
0654: // if allowed for grading, build the context for the instructor's view of report submissions
0655: template = build_instructor_report_submissions(portlet,
0656: context, data, state);
0657: }
0658: }
0659:
0660: if (template == null) {
0661: // default to student list view
0662: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
0663: template = build_list_assignments_context(portlet, context,
0664: data, state);
0665: }
0666:
0667: return template;
0668:
0669: } // buildNormalContext
0670:
0671: /**
0672: * build the student view of showing an assignment submission
0673: */
0674: protected String build_student_view_submission_context(
0675: VelocityPortlet portlet, Context context, RunData data,
0676: SessionState state) {
0677: context.put("context", (String) state
0678: .getAttribute(STATE_CONTEXT_STRING));
0679:
0680: User user = (User) state.getAttribute(STATE_USER);
0681: String currentAssignmentReference = (String) state
0682: .getAttribute(VIEW_SUBMISSION_ASSIGNMENT_REFERENCE);
0683: try {
0684: Assignment currentAssignment = AssignmentService
0685: .getAssignment(currentAssignmentReference);
0686: context.put("assignment", currentAssignment);
0687: AssignmentSubmission s = AssignmentService.getSubmission(
0688: currentAssignment.getReference(), user);
0689: if (s != null) {
0690: context.put("submission", s);
0691: ResourceProperties p = s.getProperties();
0692: if (p
0693: .getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT) != null) {
0694: context
0695: .put(
0696: "prevFeedbackText",
0697: p
0698: .getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT));
0699: }
0700:
0701: if (p
0702: .getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT) != null) {
0703: context
0704: .put(
0705: "prevFeedbackComment",
0706: p
0707: .getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT));
0708: }
0709:
0710: if (p
0711: .getProperty(PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS) != null) {
0712: context.put("prevFeedbackAttachments",
0713: getPrevFeedbackAttachments(p));
0714: }
0715: }
0716: } catch (IdUnusedException e) {
0717: addAlert(state, "Cannot find the assignment.");
0718: } catch (PermissionException e) {
0719: addAlert(state, rb.getString("youarenot16"));
0720: }
0721:
0722: // name value pairs for the vm
0723: context.put("name_submission_text", VIEW_SUBMISSION_TEXT);
0724: context.put("value_submission_text", state
0725: .getAttribute(VIEW_SUBMISSION_TEXT));
0726: context.put("name_submission_honor_pledge_yes",
0727: VIEW_SUBMISSION_HONOR_PLEDGE_YES);
0728: context.put("value_submission_honor_pledge_yes", state
0729: .getAttribute(VIEW_SUBMISSION_HONOR_PLEDGE_YES));
0730: context.put("attachments", state.getAttribute(ATTACHMENTS));
0731: context.put("contentTypeImageService", state
0732: .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
0733: context.put("currentTime", TimeService.newTime());
0734:
0735: boolean allowSubmit = AssignmentService
0736: .allowAddSubmission((String) state
0737: .getAttribute(STATE_CONTEXT_STRING));
0738: if (!allowSubmit) {
0739: addAlert(state,
0740: "You are not allowed to submit to this assignment. ");
0741: }
0742: context.put("allowSubmit", new Boolean(allowSubmit));
0743:
0744: String template = (String) getContext(data).get("template");
0745: return template + TEMPLATE_STUDENT_VIEW_SUBMISSION;
0746:
0747: } // build_student_view_submission_context
0748:
0749: /**
0750: * build the student view of assignment
0751: */
0752: protected String build_student_view_assignment_context(
0753: VelocityPortlet portlet, Context context, RunData data,
0754: SessionState state) {
0755: context.put("context", (String) state
0756: .getAttribute(STATE_CONTEXT_STRING));
0757:
0758: String aId = (String) state.getAttribute(VIEW_ASSIGNMENT_ID);
0759: try {
0760: Assignment currentAssignment = AssignmentService
0761: .getAssignment(aId);
0762: context.put("assignment", currentAssignment);
0763: } catch (IdUnusedException e) {
0764: addAlert(state, "Cannot find the assignment.");
0765: } catch (PermissionException e) {
0766: addAlert(state, rb.getString("youarenot14"));
0767: }
0768:
0769: context.put("contentTypeImageService", state
0770: .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
0771: context.put("gradeTypeTable", gradeTypeTable());
0772: context.put("userDirectoryService", UserDirectoryService
0773: .getInstance());
0774:
0775: String template = (String) getContext(data).get("template");
0776: return template + TEMPLATE_STUDENT_VIEW_ASSIGNMENT;
0777:
0778: } // build_student_view_submission_context
0779:
0780: /**
0781: * build the student preview of showing an assignment submission
0782: */
0783: protected String build_student_preview_submission_context(
0784: VelocityPortlet portlet, Context context, RunData data,
0785: SessionState state) {
0786: User user = (User) state.getAttribute(STATE_USER);
0787: String aReference = (String) state
0788: .getAttribute(PREVIEW_SUBMISSION_ASSIGNMENT_REFERENCE);
0789:
0790: try {
0791: context.put("assignment", AssignmentService
0792: .getAssignment(aReference));
0793: context.put("submission", AssignmentService.getSubmission(
0794: aReference, user));
0795: } catch (IdUnusedException e) {
0796: addAlert(state, rb.getString("cannotfin3"));
0797: } catch (PermissionException e) {
0798: addAlert(state, rb.getString("youarenot16"));
0799: }
0800:
0801: context
0802: .put("text", state
0803: .getAttribute(PREVIEW_SUBMISSION_TEXT));
0804: context.put("honor_pledge_yes", state
0805: .getAttribute(PREVIEW_SUBMISSION_HONOR_PLEDGE_YES));
0806: context.put("attachments", state
0807: .getAttribute(PREVIEW_SUBMISSION_ATTACHMENTS));
0808: context.put("contentTypeImageService", state
0809: .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
0810:
0811: String template = (String) getContext(data).get("template");
0812: return template + TEMPLATE_STUDENT_PREVIEW_SUBMISSION;
0813:
0814: } // build_student_preview_submission_context
0815:
0816: /**
0817: * build the student view of showing a graded submission
0818: */
0819: protected String build_student_view_grade_context(
0820: VelocityPortlet portlet, Context context, RunData data,
0821: SessionState state) {
0822: context.put("contentTypeImageService", state
0823: .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
0824: try {
0825: AssignmentSubmission s = AssignmentService
0826: .getSubmission((String) state
0827: .getAttribute(VIEW_GRADE_SUBMISSION_ID));
0828: context.put("assignment", s.getAssignment());
0829: context.put("submission", s);
0830: } catch (IdUnusedException e) {
0831: addAlert(state, rb.getString("cannotfin5"));
0832: } catch (PermissionException e) {
0833: addAlert(state,
0834: "You are not allowed to get the submission to this assignment. ");
0835: }
0836:
0837: String template = (String) getContext(data).get("template");
0838: return template + TEMPLATE_STUDENT_VIEW_GRADE;
0839:
0840: } // build_student_view_grade_context
0841:
0842: /**
0843: * build the view of assignments list
0844: */
0845: protected String build_list_assignments_context(
0846: VelocityPortlet portlet, Context context, RunData data,
0847: SessionState state) {
0848: String contextString = (String) state
0849: .getAttribute(STATE_CONTEXT_STRING);
0850: context.put("contextString", contextString);
0851: context.put("user", (User) state.getAttribute(STATE_USER));
0852: context.put("service", AssignmentService.getInstance());
0853: context.put("currentTime", TimeService.newTime());
0854: String sortedBy = (String) state.getAttribute(SORTED_BY);
0855: String sortedAsc = (String) state.getAttribute(SORTED_ASC);
0856: // clean sort criteria
0857: if (sortedBy.equals(SORTED_BY_GROUP_TITLE)
0858: || sortedBy.equals(SORTED_BY_GROUP_DESCRIPTION)) {
0859: sortedBy = SORTED_BY_DUEDATE;
0860: sortedAsc = Boolean.TRUE.toString();
0861: state.setAttribute(SORTED_BY, sortedBy);
0862: state.setAttribute(SORTED_ASC, sortedAsc);
0863: }
0864: context.put("sortedBy", sortedBy);
0865: context.put("sortedAsc", sortedAsc);
0866: if (state.getAttribute(STATE_SELECTED_VIEW) != null) {
0867: context
0868: .put("view", state
0869: .getAttribute(STATE_SELECTED_VIEW));
0870: }
0871:
0872: List assignments = prepPage(state);
0873:
0874: context.put("assignments", assignments.iterator());
0875:
0876: // allow get assignment
0877: context.put("allowGetAssignment", Boolean
0878: .valueOf(AssignmentService
0879: .allowGetAssignment(contextString)));
0880:
0881: // test whether user user can grade at least one assignment
0882: // and update the state variable.
0883: boolean allowGradeSubmission = false;
0884: for (Iterator aIterator = assignments.iterator(); !allowGradeSubmission
0885: && aIterator.hasNext();) {
0886: if (AssignmentService
0887: .allowGradeSubmission(((Assignment) aIterator
0888: .next()).getReference())) {
0889: allowGradeSubmission = true;
0890: }
0891: }
0892: state.setAttribute(STATE_ALLOW_GRADE_SUBMISSION, new Boolean(
0893: allowGradeSubmission));
0894: context.put("allowGradeSubmission", state
0895: .getAttribute(STATE_ALLOW_GRADE_SUBMISSION));
0896:
0897: // allow remove assignment?
0898: boolean allowRemoveAssignment = false;
0899: for (Iterator aIterator = assignments.iterator(); !allowRemoveAssignment
0900: && aIterator.hasNext();) {
0901: if (AssignmentService
0902: .allowRemoveAssignment(((Assignment) aIterator
0903: .next()).getReference())) {
0904: allowRemoveAssignment = true;
0905: }
0906: }
0907: context.put("allowRemoveAssignment", Boolean
0908: .valueOf(allowRemoveAssignment));
0909:
0910: add2ndToolbarFields(data, context);
0911:
0912: // inform the observing courier that we just updated the page...
0913: // if there are pending requests to do so they can be cleared
0914: justDelivered(state);
0915:
0916: pagingInfoToContext(state, context);
0917:
0918: // put site object into context
0919: try {
0920: // get current site
0921: Site site = SiteService.getSite(contextString);
0922: context.put("site", site);
0923: // any group in the site?
0924: Collection groups = site.getGroups();
0925: context
0926: .put(
0927: "groups",
0928: (groups != null && groups.size() > 0) ? Boolean.TRUE
0929: : Boolean.FALSE);
0930:
0931: // add active user list
0932: AuthzGroup realm = AuthzGroupService
0933: .getAuthzGroup(SiteService
0934: .siteReference(contextString));
0935: if (realm != null) {
0936: context.put("activeUserIds", realm.getUsers());
0937: }
0938: } catch (Exception ignore) {
0939: Log.warn("chef", this + ignore.getMessage() + " siteId= "
0940: + contextString);
0941: }
0942:
0943: boolean allowSubmit = AssignmentService
0944: .allowAddSubmission(contextString);
0945: context.put("allowSubmit", new Boolean(allowSubmit));
0946:
0947: String template = (String) getContext(data).get("template");
0948: return template + TEMPLATE_LIST_ASSIGNMENTS;
0949:
0950: } // build_list_assignments_context
0951:
0952: /**
0953: * build the instructor view of creating a new assignment or editing an existing one
0954: */
0955: protected String build_instructor_new_edit_assignment_context(
0956: VelocityPortlet portlet, Context context, RunData data,
0957: SessionState state) {
0958: // is the assignment an new assignment
0959: String assignmentId = (String) state
0960: .getAttribute(EDIT_ASSIGNMENT_ID);
0961: if (assignmentId != null) {
0962: try {
0963: Assignment a = AssignmentService
0964: .getAssignment(assignmentId);
0965: context.put("assignment", a);
0966: } catch (IdUnusedException e) {
0967: addAlert(state, rb.getString("cannotfin3") + ": "
0968: + assignmentId);
0969: } catch (PermissionException e) {
0970: addAlert(state, rb.getString("youarenot14") + ": "
0971: + assignmentId);
0972: }
0973: }
0974:
0975: // set up context variables
0976: setAssignmentFormContext(state, context);
0977:
0978: context.put("fField", state.getAttribute(NEW_ASSIGNMENT_FOCUS));
0979:
0980: String sortedBy = (String) state.getAttribute(SORTED_BY);
0981: String sortedAsc = (String) state.getAttribute(SORTED_ASC);
0982: context.put("sortedBy", sortedBy);
0983: context.put("sortedAsc", sortedAsc);
0984:
0985: String template = (String) getContext(data).get("template");
0986: return template + TEMPLATE_INSTRUCTOR_NEW_EDIT_ASSIGNMENT;
0987:
0988: } // build_instructor_new_assignment_context
0989:
0990: protected void setAssignmentFormContext(SessionState state,
0991: Context context) {
0992: // put the names and values into vm file
0993: context.put("name_title", NEW_ASSIGNMENT_TITLE);
0994:
0995: context.put("name_OpenMonth", NEW_ASSIGNMENT_OPENMONTH);
0996: context.put("name_OpenDay", NEW_ASSIGNMENT_OPENDAY);
0997: context.put("name_OpenYear", NEW_ASSIGNMENT_OPENYEAR);
0998: context.put("name_OpenHour", NEW_ASSIGNMENT_OPENHOUR);
0999: context.put("name_OpenMin", NEW_ASSIGNMENT_OPENMIN);
1000: context.put("name_OpenAMPM", NEW_ASSIGNMENT_OPENAMPM);
1001:
1002: context.put("name_DueMonth", NEW_ASSIGNMENT_DUEMONTH);
1003: context.put("name_DueDay", NEW_ASSIGNMENT_DUEDAY);
1004: context.put("name_DueYear", NEW_ASSIGNMENT_DUEYEAR);
1005: context.put("name_DueHour", NEW_ASSIGNMENT_DUEHOUR);
1006: context.put("name_DueMin", NEW_ASSIGNMENT_DUEMIN);
1007: context.put("name_DueAMPM", NEW_ASSIGNMENT_DUEAMPM);
1008:
1009: context.put("name_EnableCloseDate",
1010: NEW_ASSIGNMENT_ENABLECLOSEDATE);
1011: context.put("name_CloseMonth", NEW_ASSIGNMENT_CLOSEMONTH);
1012: context.put("name_CloseDay", NEW_ASSIGNMENT_CLOSEDAY);
1013: context.put("name_CloseYear", NEW_ASSIGNMENT_CLOSEYEAR);
1014: context.put("name_CloseHour", NEW_ASSIGNMENT_CLOSEHOUR);
1015: context.put("name_CloseMin", NEW_ASSIGNMENT_CLOSEMIN);
1016: context.put("name_CloseAMPM", NEW_ASSIGNMENT_CLOSEAMPM);
1017:
1018: context.put("name_Section", NEW_ASSIGNMENT_SECTION);
1019: context.put("name_SubmissionType",
1020: NEW_ASSIGNMENT_SUBMISSION_TYPE);
1021: context.put("name_GradeType", NEW_ASSIGNMENT_GRADE_TYPE);
1022: context.put("name_GradePoints", NEW_ASSIGNMENT_GRADE_POINTS);
1023: context.put("name_Description", NEW_ASSIGNMENT_DESCRIPTION);
1024: // do not show the choice when there is no Schedule tool yet
1025: if (state.getAttribute(CALENDAR) != null)
1026: context
1027: .put(
1028: "name_CheckAddDueDate",
1029: ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE);
1030: context.put("name_CheckAutoAnnounce",
1031: ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE);
1032: context.put("name_CheckAddHonorPledge",
1033: NEW_ASSIGNMENT_CHECK_ADD_HONOR_PLEDGE);
1034:
1035: // offer the gradebook integration choice only in the Assignments with Grading tool
1036: boolean withGrade = ((Boolean) state.getAttribute(WITH_GRADES))
1037: .booleanValue();
1038: if (withGrade) {
1039: context.put("name_Addtogradebook",
1040: NEW_ASSIGNMENT_ADD_TO_GRADEBOOK);
1041: context.put("name_AssociateGradebookAssignment",
1042: NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT);
1043: }
1044: // gradebook integration
1045: context.put("withGradebook", Boolean
1046: .valueOf(isGradebookDefined()));
1047:
1048: // set the values
1049: context.put("value_title", state
1050: .getAttribute(NEW_ASSIGNMENT_TITLE));
1051: context.put("value_OpenMonth", state
1052: .getAttribute(NEW_ASSIGNMENT_OPENMONTH));
1053: context.put("value_OpenDay", state
1054: .getAttribute(NEW_ASSIGNMENT_OPENDAY));
1055: context.put("value_OpenYear", state
1056: .getAttribute(NEW_ASSIGNMENT_OPENYEAR));
1057: context.put("value_OpenHour", state
1058: .getAttribute(NEW_ASSIGNMENT_OPENHOUR));
1059: context.put("value_OpenMin", state
1060: .getAttribute(NEW_ASSIGNMENT_OPENMIN));
1061: context.put("value_OpenAMPM", state
1062: .getAttribute(NEW_ASSIGNMENT_OPENAMPM));
1063:
1064: context.put("value_DueMonth", state
1065: .getAttribute(NEW_ASSIGNMENT_DUEMONTH));
1066: context.put("value_DueDay", state
1067: .getAttribute(NEW_ASSIGNMENT_DUEDAY));
1068: context.put("value_DueYear", state
1069: .getAttribute(NEW_ASSIGNMENT_DUEYEAR));
1070: context.put("value_DueHour", state
1071: .getAttribute(NEW_ASSIGNMENT_DUEHOUR));
1072: context.put("value_DueMin", state
1073: .getAttribute(NEW_ASSIGNMENT_DUEMIN));
1074: context.put("value_DueAMPM", state
1075: .getAttribute(NEW_ASSIGNMENT_DUEAMPM));
1076:
1077: context.put("value_EnableCloseDate", state
1078: .getAttribute(NEW_ASSIGNMENT_ENABLECLOSEDATE));
1079: context.put("value_CloseMonth", state
1080: .getAttribute(NEW_ASSIGNMENT_CLOSEMONTH));
1081: context.put("value_CloseDay", state
1082: .getAttribute(NEW_ASSIGNMENT_CLOSEDAY));
1083: context.put("value_CloseYear", state
1084: .getAttribute(NEW_ASSIGNMENT_CLOSEYEAR));
1085: context.put("value_CloseHour", state
1086: .getAttribute(NEW_ASSIGNMENT_CLOSEHOUR));
1087: context.put("value_CloseMin", state
1088: .getAttribute(NEW_ASSIGNMENT_CLOSEMIN));
1089: context.put("value_CloseAMPM", state
1090: .getAttribute(NEW_ASSIGNMENT_CLOSEAMPM));
1091:
1092: context.put("value_Sections", state
1093: .getAttribute(NEW_ASSIGNMENT_SECTION));
1094: context.put("value_SubmissionType", state
1095: .getAttribute(NEW_ASSIGNMENT_SUBMISSION_TYPE));
1096: context.put("value_GradeType", state
1097: .getAttribute(NEW_ASSIGNMENT_GRADE_TYPE));
1098: // format to show one decimal place
1099: String maxGrade = (String) state
1100: .getAttribute(NEW_ASSIGNMENT_GRADE_POINTS);
1101: context.put("value_GradePoints", displayGrade(state, maxGrade));
1102: context.put("value_Description", state
1103: .getAttribute(NEW_ASSIGNMENT_DESCRIPTION));
1104: // don't show the choice when there is no Schedule tool yet
1105: if (state.getAttribute(CALENDAR) != null)
1106: context
1107: .put(
1108: "value_CheckAddDueDate",
1109: state
1110: .getAttribute(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE));
1111: context
1112: .put(
1113: "value_CheckAutoAnnounce",
1114: state
1115: .getAttribute(ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE));
1116: String s = (String) state
1117: .getAttribute(NEW_ASSIGNMENT_CHECK_ADD_HONOR_PLEDGE);
1118: if (s == null)
1119: s = "1";
1120: context.put("value_CheckAddHonorPledge", s);
1121:
1122: // get all available assignments from Gradebook tool except for those created from
1123: boolean gradebookExists = isGradebookDefined();
1124: if (gradebookExists) {
1125: GradebookService g = (GradebookService) (org.sakaiproject.service.gradebook.shared.GradebookService) ComponentManager
1126: .get("org.sakaiproject.service.gradebook.GradebookService");
1127: String gradebookUid = ToolManager.getInstance()
1128: .getCurrentPlacement().getContext();
1129:
1130: // get all assignments in Gradebook
1131: List gradebookAssignments = g.getAssignments(gradebookUid);
1132: List gradebookAssignmentsExceptSamigo = new Vector();
1133:
1134: // filtering out those from Samigo
1135: for (Iterator i = gradebookAssignments.iterator(); i
1136: .hasNext();) {
1137: org.sakaiproject.service.gradebook.shared.Assignment gAssignment = (org.sakaiproject.service.gradebook.shared.Assignment) i
1138: .next();
1139: if (!gAssignment.isExternallyMaintained()
1140: || gAssignment.isExternallyMaintained()
1141: && gAssignment.getExternalAppName().equals(
1142: getToolTitle())) {
1143: gradebookAssignmentsExceptSamigo.add(gAssignment);
1144: }
1145: }
1146: context.put("gradebookAssignments",
1147: gradebookAssignmentsExceptSamigo);
1148: if (StringUtil.trimToNull((String) state
1149: .getAttribute(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK)) == null) {
1150: state.setAttribute(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK,
1151: GRADEBOOK_INTEGRATION_NO);
1152: }
1153: context.put("gradebookChoice", state
1154: .getAttribute(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK));
1155: context.put("gradebookChoice_no", GRADEBOOK_INTEGRATION_NO);
1156: context.put("gradebookChoice_add",
1157: GRADEBOOK_INTEGRATION_ADD);
1158: context.put("gradebookChoice_associate",
1159: GRADEBOOK_INTEGRATION_ASSOCIATE);
1160: context
1161: .put(
1162: "associateGradebookAssignment",
1163: state
1164: .getAttribute(NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT));
1165: }
1166:
1167: context.put("monthTable", monthTable());
1168: context.put("gradeTypeTable", gradeTypeTable());
1169: context.put("submissionTypeTable", submissionTypeTable());
1170: context.put("hide_assignment_option_flag", state
1171: .getAttribute(NEW_ASSIGNMENT_HIDE_OPTION_FLAG));
1172: context.put("attachments", state.getAttribute(ATTACHMENTS));
1173: context.put("contentTypeImageService", state
1174: .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
1175:
1176: String range = (String) state
1177: .getAttribute(NEW_ASSIGNMENT_RANGE);
1178: String contextString = (String) state
1179: .getAttribute(STATE_CONTEXT_STRING);
1180:
1181: // put site object into context
1182: try {
1183: // get current site
1184: Site site = SiteService.getSite((String) state
1185: .getAttribute(STATE_CONTEXT_STRING));
1186: context.put("site", site);
1187: } catch (Exception ignore) {
1188: }
1189:
1190: if (AssignmentService.getAllowGroupAssignments()) {
1191: Collection groupsAllowAddAssignment = AssignmentService
1192: .getGroupsAllowAddAssignment(contextString);
1193: if (range != null && range.length() != 0) {
1194: context.put("range", range);
1195: } else {
1196: if (AssignmentService
1197: .allowAddSiteAssignment(contextString)) {
1198: // default to make site selection
1199: context.put("range", "site");
1200: } else if (groupsAllowAddAssignment.size() > 0) {
1201: // to group otherwise
1202: context.put("range", "groups");
1203: }
1204: }
1205:
1206: // group list which user can add message to
1207: if (groupsAllowAddAssignment.size() > 0) {
1208: String sort = (String) state.getAttribute(SORTED_BY);
1209: String asc = (String) state.getAttribute(SORTED_ASC);
1210: if (sort == null
1211: || (!sort.equals(SORTED_BY_GROUP_TITLE) && !sort
1212: .equals(SORTED_BY_GROUP_DESCRIPTION))) {
1213: sort = SORTED_BY_GROUP_TITLE;
1214: asc = Boolean.TRUE.toString();
1215: state.setAttribute(SORTED_BY, sort);
1216: state.setAttribute(SORTED_ASC, asc);
1217: }
1218: context.put("groups", new SortedIterator(
1219: groupsAllowAddAssignment.iterator(),
1220: new AssignmentComparator(state, sort, asc)));
1221: context.put("assignmentGroups", state
1222: .getAttribute(NEW_ASSIGNMENT_GROUPS));
1223: }
1224: }
1225:
1226: context.put("allowGroupAssignmentsInGradebook",
1227: new Boolean(AssignmentService
1228: .getAllowGroupAssignmentsInGradebook()));
1229:
1230: } // setAssignmentFormContext
1231:
1232: /**
1233: * build the instructor view of create a new assignment
1234: */
1235: protected String build_instructor_preview_assignment_context(
1236: VelocityPortlet portlet, Context context, RunData data,
1237: SessionState state) {
1238: context.put("time", TimeService.newTime());
1239:
1240: context.put("user", UserDirectoryService.getCurrentUser());
1241:
1242: context.put("value_Title", (String) state
1243: .getAttribute(NEW_ASSIGNMENT_TITLE));
1244:
1245: // open time
1246: int openMonth = ((Integer) state
1247: .getAttribute(NEW_ASSIGNMENT_OPENMONTH)).intValue();
1248: int openDay = ((Integer) state
1249: .getAttribute(NEW_ASSIGNMENT_OPENDAY)).intValue();
1250: int openYear = ((Integer) state
1251: .getAttribute(NEW_ASSIGNMENT_OPENYEAR)).intValue();
1252: int openHour = ((Integer) state
1253: .getAttribute(NEW_ASSIGNMENT_OPENHOUR)).intValue();
1254: int openMin = ((Integer) state
1255: .getAttribute(NEW_ASSIGNMENT_OPENMIN)).intValue();
1256: String openAMPM = (String) state
1257: .getAttribute(NEW_ASSIGNMENT_OPENAMPM);
1258: if ((openAMPM.equals("PM")) && (openHour != 12)) {
1259: openHour = openHour + 12;
1260: }
1261: if ((openHour == 12) && (openAMPM.equals("AM"))) {
1262: openHour = 0;
1263: }
1264: Time openTime = TimeService.newTimeLocal(openYear, openMonth,
1265: openDay, openHour, openMin, 0, 0);
1266: context.put("value_OpenDate", openTime);
1267:
1268: // due time
1269: int dueMonth = ((Integer) state
1270: .getAttribute(NEW_ASSIGNMENT_DUEMONTH)).intValue();
1271: int dueDay = ((Integer) state
1272: .getAttribute(NEW_ASSIGNMENT_DUEDAY)).intValue();
1273: int dueYear = ((Integer) state
1274: .getAttribute(NEW_ASSIGNMENT_DUEYEAR)).intValue();
1275: int dueHour = ((Integer) state
1276: .getAttribute(NEW_ASSIGNMENT_DUEHOUR)).intValue();
1277: int dueMin = ((Integer) state
1278: .getAttribute(NEW_ASSIGNMENT_DUEMIN)).intValue();
1279: String dueAMPM = (String) state
1280: .getAttribute(NEW_ASSIGNMENT_DUEAMPM);
1281: if ((dueAMPM.equals("PM")) && (dueHour != 12)) {
1282: dueHour = dueHour + 12;
1283: }
1284: if ((dueHour == 12) && (dueAMPM.equals("AM"))) {
1285: dueHour = 0;
1286: }
1287: Time dueTime = TimeService.newTimeLocal(dueYear, dueMonth,
1288: dueDay, dueHour, dueMin, 0, 0);
1289: context.put("value_DueDate", dueTime);
1290:
1291: // close time
1292: Time closeTime = TimeService.newTime();
1293: Boolean enableCloseDate = (Boolean) state
1294: .getAttribute(NEW_ASSIGNMENT_ENABLECLOSEDATE);
1295: context.put("value_EnableCloseDate", enableCloseDate);
1296: if ((enableCloseDate).booleanValue()) {
1297: int closeMonth = ((Integer) state
1298: .getAttribute(NEW_ASSIGNMENT_CLOSEMONTH))
1299: .intValue();
1300: int closeDay = ((Integer) state
1301: .getAttribute(NEW_ASSIGNMENT_CLOSEDAY)).intValue();
1302: int closeYear = ((Integer) state
1303: .getAttribute(NEW_ASSIGNMENT_CLOSEYEAR)).intValue();
1304: int closeHour = ((Integer) state
1305: .getAttribute(NEW_ASSIGNMENT_CLOSEHOUR)).intValue();
1306: int closeMin = ((Integer) state
1307: .getAttribute(NEW_ASSIGNMENT_CLOSEMIN)).intValue();
1308: String closeAMPM = (String) state
1309: .getAttribute(NEW_ASSIGNMENT_CLOSEAMPM);
1310: if ((closeAMPM.equals("PM")) && (closeHour != 12)) {
1311: closeHour = closeHour + 12;
1312: }
1313: if ((closeHour == 12) && (closeAMPM.equals("AM"))) {
1314: closeHour = 0;
1315: }
1316: closeTime = TimeService.newTimeLocal(closeYear, closeMonth,
1317: closeDay, closeHour, closeMin, 0, 0);
1318: context.put("value_CloseDate", closeTime);
1319: }
1320:
1321: context.put("value_Sections", state
1322: .getAttribute(NEW_ASSIGNMENT_SECTION));
1323: context.put("value_SubmissionType", state
1324: .getAttribute(NEW_ASSIGNMENT_SUBMISSION_TYPE));
1325: context.put("value_GradeType", state
1326: .getAttribute(NEW_ASSIGNMENT_GRADE_TYPE));
1327: String maxGrade = (String) state
1328: .getAttribute(NEW_ASSIGNMENT_GRADE_POINTS);
1329: context.put("value_GradePoints", displayGrade(state, maxGrade));
1330: context.put("value_Description", state
1331: .getAttribute(NEW_ASSIGNMENT_DESCRIPTION));
1332: context
1333: .put(
1334: "value_CheckAddDueDate",
1335: state
1336: .getAttribute(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE));
1337: context
1338: .put(
1339: "value_CheckAutoAnnounce",
1340: state
1341: .getAttribute(ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE));
1342: context.put("value_CheckAddHonorPledge", state
1343: .getAttribute(NEW_ASSIGNMENT_CHECK_ADD_HONOR_PLEDGE));
1344:
1345: // get all available assignments from Gradebook tool except for those created from
1346: if (isGradebookDefined()) {
1347: context.put("gradebookChoice", state
1348: .getAttribute(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK));
1349: context
1350: .put(
1351: "associateGradebookAssignment",
1352: state
1353: .getAttribute(NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT));
1354: }
1355:
1356: context.put("monthTable", monthTable());
1357: context.put("gradeTypeTable", gradeTypeTable());
1358: context.put("submissionTypeTable", submissionTypeTable());
1359: context.put("hide_assignment_option_flag", state
1360: .getAttribute(NEW_ASSIGNMENT_HIDE_OPTION_FLAG));
1361: context.put("attachments", state.getAttribute(ATTACHMENTS));
1362: context.put("contentTypeImageService", state
1363: .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
1364:
1365: context.put("preview_assignment_assignment_hide_flag", state
1366: .getAttribute(PREVIEW_ASSIGNMENT_ASSIGNMENT_HIDE_FLAG));
1367: context
1368: .put(
1369: "preview_assignment_student_view_hide_flag",
1370: state
1371: .getAttribute(PREVIEW_ASSIGNMENT_STUDENT_VIEW_HIDE_FLAG));
1372: context.put("value_assignment_id", state
1373: .getAttribute(PREVIEW_ASSIGNMENT_ASSIGNMENT_ID));
1374: context.put("value_assignmentcontent_id", state
1375: .getAttribute(PREVIEW_ASSIGNMENT_ASSIGNMENTCONTENT_ID));
1376:
1377: context.put("currentTime", TimeService.newTime());
1378:
1379: String template = (String) getContext(data).get("template");
1380: return template + TEMPLATE_INSTRUCTOR_PREVIEW_ASSIGNMENT;
1381:
1382: } // build_instructor_preview_assignment_context
1383:
1384: /**
1385: * build the instructor view to delete an assignment
1386: */
1387: protected String build_instructor_delete_assignment_context(
1388: VelocityPortlet portlet, Context context, RunData data,
1389: SessionState state) {
1390: Vector assignments = new Vector();
1391: Vector assignmentIds = (Vector) state
1392: .getAttribute(DELETE_ASSIGNMENT_IDS);
1393: for (int i = 0; i < assignmentIds.size(); i++) {
1394: try {
1395: Assignment a = AssignmentService
1396: .getAssignment((String) assignmentIds.get(i));
1397:
1398: Iterator submissions = AssignmentService
1399: .getSubmissions(a);
1400: if (submissions.hasNext()) {
1401: // if there is submission to the assignment, show the alert
1402: addAlert(state, rb.getString("areyousur") + " \""
1403: + a.getTitle() + "\" "
1404: + rb.getString("whihassub") + "\n");
1405: }
1406: assignments.add(a);
1407: } catch (IdUnusedException e) {
1408: addAlert(state, rb.getString("cannotfin3"));
1409: } catch (PermissionException e) {
1410: addAlert(state, rb.getString("youarenot14"));
1411: }
1412: }
1413: context.put("assignments", assignments);
1414: context.put("service", AssignmentService.getInstance());
1415: context.put("currentTime", TimeService.newTime());
1416:
1417: String template = (String) getContext(data).get("template");
1418: return template + TEMPLATE_INSTRUCTOR_DELETE_ASSIGNMENT;
1419:
1420: } // build_instructor_delete_assignment_context
1421:
1422: /**
1423: * build the instructor view to grade an submission
1424: */
1425: protected String build_instructor_grade_submission_context(
1426: VelocityPortlet portlet, Context context, RunData data,
1427: SessionState state) {
1428: int gradeType = -1;
1429:
1430: // assignment
1431: try {
1432: Assignment a = AssignmentService
1433: .getAssignment((String) state
1434: .getAttribute(GRADE_SUBMISSION_ASSIGNMENT_ID));
1435: context.put("assignment", a);
1436: gradeType = a.getContent().getTypeOfGrade();
1437: } catch (IdUnusedException e) {
1438: addAlert(state, rb.getString("cannotfin5"));
1439: } catch (PermissionException e) {
1440: addAlert(state,
1441: "You are not allowed to view the assignment submission. ");
1442: }
1443:
1444: // assignment submission
1445: try {
1446: AssignmentSubmission s = AssignmentService
1447: .getSubmission((String) state
1448: .getAttribute(GRADE_SUBMISSION_SUBMISSION_ID));
1449: if (s != null) {
1450: context.put("submission", s);
1451: ResourceProperties p = s.getProperties();
1452: if (p
1453: .getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT) != null) {
1454: context
1455: .put(
1456: "prevFeedbackText",
1457: p
1458: .getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT));
1459: }
1460:
1461: if (p
1462: .getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT) != null) {
1463: context
1464: .put(
1465: "prevFeedbackComment",
1466: p
1467: .getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT));
1468: }
1469:
1470: if (p
1471: .getProperty(PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS) != null) {
1472: context.put("prevFeedbackAttachments",
1473: getPrevFeedbackAttachments(p));
1474: }
1475:
1476: if (p.getProperty(GRADE_SUBMISSION_ALLOW_RESUBMIT) != null) {
1477: context
1478: .put(
1479: "value_allowResubmit",
1480: p
1481: .getProperty(GRADE_SUBMISSION_ALLOW_RESUBMIT));
1482: }
1483: }
1484: } catch (IdUnusedException e) {
1485: addAlert(state, rb.getString("cannotfin5"));
1486: } catch (PermissionException e) {
1487: addAlert(state,
1488: "You are not allowed to view the assignment submission. ");
1489: }
1490:
1491: context.put("user", state.getAttribute(STATE_USER));
1492: context.put("submissionTypeTable", submissionTypeTable());
1493: context.put("gradeTypeTable", gradeTypeTable());
1494: context.put("instructorAttachments", state
1495: .getAttribute(ATTACHMENTS));
1496: context.put("contentTypeImageService", state
1497: .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
1498: context.put("service", AssignmentService.getInstance());
1499:
1500: // names
1501: context.put("name_grade_assignment_id",
1502: GRADE_SUBMISSION_ASSIGNMENT_ID);
1503: context.put("name_feedback_comment",
1504: GRADE_SUBMISSION_FEEDBACK_COMMENT);
1505: context.put("name_feedback_text",
1506: GRADE_SUBMISSION_FEEDBACK_TEXT);
1507: context.put("name_feedback_attachment",
1508: GRADE_SUBMISSION_FEEDBACK_ATTACHMENT);
1509: context.put("name_grade", GRADE_SUBMISSION_GRADE);
1510:
1511: // values
1512: context.put("value_grade_assignment_id", state
1513: .getAttribute(GRADE_SUBMISSION_ASSIGNMENT_ID));
1514: context.put("value_feedback_comment", state
1515: .getAttribute(GRADE_SUBMISSION_FEEDBACK_COMMENT));
1516: context.put("value_feedback_text", state
1517: .getAttribute(GRADE_SUBMISSION_FEEDBACK_TEXT));
1518: context.put("value_feedback_attachment", state
1519: .getAttribute(ATTACHMENTS));
1520: if (state.getAttribute(GRADE_SUBMISSION_ALLOW_RESUBMIT) != null) {
1521: context.put("value_allowResubmit", state
1522: .getAttribute(GRADE_SUBMISSION_ALLOW_RESUBMIT));
1523: }
1524:
1525: // format to show one decimal place in grade
1526: context.put("value_grade", (gradeType == 3) ? displayGrade(
1527: state, (String) state
1528: .getAttribute(GRADE_SUBMISSION_GRADE)) : state
1529: .getAttribute(GRADE_SUBMISSION_GRADE));
1530:
1531: context.put("assignment_expand_flag", state
1532: .getAttribute(GRADE_SUBMISSION_ASSIGNMENT_EXPAND_FLAG));
1533: context.put("gradingAttachments", state
1534: .getAttribute(ATTACHMENTS));
1535:
1536: String template = (String) getContext(data).get("template");
1537: return template + TEMPLATE_INSTRUCTOR_GRADE_SUBMISSION;
1538:
1539: } // build_instructor_grade_submission_context
1540:
1541: private List getPrevFeedbackAttachments(ResourceProperties p) {
1542: String attachmentsString = p
1543: .getProperty(PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS);
1544: String[] attachmentsReferences = attachmentsString.split(",");
1545: List prevFeedbackAttachments = EntityManager.newReferenceList();
1546: for (int k = 0; k < attachmentsReferences.length; k++) {
1547: prevFeedbackAttachments.add(EntityManager
1548: .newReference(attachmentsReferences[k]));
1549: }
1550: return prevFeedbackAttachments;
1551: }
1552:
1553: /**
1554: * build the instructor preview of grading submission
1555: */
1556: protected String build_instructor_preview_grade_submission_context(
1557: VelocityPortlet portlet, Context context, RunData data,
1558: SessionState state) {
1559:
1560: // assignment
1561: int gradeType = -1;
1562: try {
1563: Assignment a = AssignmentService
1564: .getAssignment((String) state
1565: .getAttribute(GRADE_SUBMISSION_ASSIGNMENT_ID));
1566: context.put("assignment", a);
1567: gradeType = a.getContent().getTypeOfGrade();
1568: } catch (IdUnusedException e) {
1569: addAlert(state, rb.getString("cannotfin3"));
1570: } catch (PermissionException e) {
1571: addAlert(state, rb.getString("youarenot14"));
1572: }
1573:
1574: // submission
1575: try {
1576: context
1577: .put(
1578: "submission",
1579: AssignmentService
1580: .getSubmission((String) state
1581: .getAttribute(GRADE_SUBMISSION_SUBMISSION_ID)));
1582: } catch (IdUnusedException e) {
1583: addAlert(state, rb.getString("cannotfin5"));
1584: } catch (PermissionException e) {
1585: addAlert(state,
1586: "You are not allowed to view the assignment submission. ");
1587: }
1588:
1589: User user = (User) state.getAttribute(STATE_USER);
1590: context.put("user", user);
1591: context.put("submissionTypeTable", submissionTypeTable());
1592: context.put("gradeTypeTable", gradeTypeTable());
1593: context.put("contentTypeImageService", state
1594: .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
1595: context.put("service", AssignmentService.getInstance());
1596:
1597: // filter the feedback text for the instructor comment and mark it as red
1598: String feedbackText = (String) state
1599: .getAttribute(GRADE_SUBMISSION_FEEDBACK_TEXT);
1600: context.put("feedback_comment", state
1601: .getAttribute(GRADE_SUBMISSION_FEEDBACK_COMMENT));
1602: context.put("feedback_text", feedbackText);
1603: context.put("feedback_attachment", state
1604: .getAttribute(GRADE_SUBMISSION_FEEDBACK_ATTACHMENT));
1605:
1606: // format to show one decimal place
1607: String grade = (String) state
1608: .getAttribute(GRADE_SUBMISSION_GRADE);
1609: if (gradeType == 3) {
1610: grade = displayGrade(state, grade);
1611: }
1612: context.put("grade", grade);
1613:
1614: context.put("comment_open", COMMENT_OPEN);
1615: context.put("comment_close", COMMENT_CLOSE);
1616:
1617: context.put("allowResubmit", state
1618: .getAttribute(GRADE_SUBMISSION_ALLOW_RESUBMIT));
1619:
1620: String template = (String) getContext(data).get("template");
1621: return template + TEMPLATE_INSTRUCTOR_PREVIEW_GRADE_SUBMISSION;
1622:
1623: } // build_instructor_preview_grade_submission_context
1624:
1625: /**
1626: * build the instructor view to grade an assignment
1627: */
1628: protected String build_instructor_grade_assignment_context(
1629: VelocityPortlet portlet, Context context, RunData data,
1630: SessionState state) {
1631: context.put("user", state.getAttribute(STATE_USER));
1632:
1633: // sorting related fields
1634: context.put("sortedBy", state
1635: .getAttribute(SORTED_GRADE_SUBMISSION_BY));
1636: context.put("sortedAsc", state
1637: .getAttribute(SORTED_GRADE_SUBMISSION_ASC));
1638: context.put("sort_lastName",
1639: SORTED_GRADE_SUBMISSION_BY_LASTNAME);
1640: context.put("sort_submitTime",
1641: SORTED_GRADE_SUBMISSION_BY_SUBMIT_TIME);
1642: context.put("sort_submitStatus",
1643: SORTED_GRADE_SUBMISSION_BY_STATUS);
1644: context.put("sort_submitGrade",
1645: SORTED_GRADE_SUBMISSION_BY_GRADE);
1646: context.put("sort_submitReleased",
1647: SORTED_GRADE_SUBMISSION_BY_RELEASED);
1648:
1649: try {
1650: Assignment a = AssignmentService
1651: .getAssignment((String) state
1652: .getAttribute(EXPORT_ASSIGNMENT_REF));
1653: context.put("assignment", a);
1654: state.setAttribute(EXPORT_ASSIGNMENT_ID, a.getId());
1655:
1656: context.put("userSubmissions", prepPage(state));
1657: } catch (IdUnusedException e) {
1658: addAlert(state, rb.getString("cannotfin3"));
1659: } catch (PermissionException e) {
1660: addAlert(state, rb.getString("youarenot14"));
1661: }
1662:
1663: context.put("submissionTypeTable", submissionTypeTable());
1664: context.put("gradeTypeTable", gradeTypeTable());
1665: context.put("attachments", state.getAttribute(ATTACHMENTS));
1666: context.put("contentTypeImageService", state
1667: .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
1668: context.put("service", AssignmentService.getInstance());
1669:
1670: context.put("assignment_expand_flag", state
1671: .getAttribute(GRADE_ASSIGNMENT_EXPAND_FLAG));
1672: context.put("submission_expand_flag", state
1673: .getAttribute(GRADE_SUBMISSION_EXPAND_FLAG));
1674:
1675: // the user directory service
1676: context.put("userDirectoryService", UserDirectoryService
1677: .getInstance());
1678: add2ndToolbarFields(data, context);
1679:
1680: pagingInfoToContext(state, context);
1681:
1682: String contextString = (String) state
1683: .getAttribute(STATE_CONTEXT_STRING);
1684: context.put("accessPointUrl", (ServerConfigurationService
1685: .getAccessUrl()).concat(AssignmentService
1686: .submissionsZipReference(contextString, (String) state
1687: .getAttribute(EXPORT_ASSIGNMENT_REF))));
1688:
1689: String template = (String) getContext(data).get("template");
1690: return template + TEMPLATE_INSTRUCTOR_GRADE_ASSIGNMENT;
1691:
1692: } // build_instructor_grade_assignment_context
1693:
1694: /**
1695: * build the instructor view of an assignment
1696: */
1697: protected String build_instructor_view_assignment_context(
1698: VelocityPortlet portlet, Context context, RunData data,
1699: SessionState state) {
1700: try {
1701: context.put("assignment", AssignmentService
1702: .getAssignment((String) state
1703: .getAttribute(VIEW_ASSIGNMENT_ID)));
1704: } catch (IdUnusedException e) {
1705: addAlert(state, rb.getString("cannotfin3"));
1706: } catch (PermissionException e) {
1707: addAlert(state, rb.getString("youarenot14"));
1708: }
1709:
1710: context.put("currentTime", TimeService.newTime());
1711: context.put("submissionTypeTable", submissionTypeTable());
1712: context.put("gradeTypeTable", gradeTypeTable());
1713: context.put("hideAssignmentFlag", state
1714: .getAttribute(VIEW_ASSIGNMENT_HIDE_ASSIGNMENT_FLAG));
1715: context.put("hideStudentViewFlag", state
1716: .getAttribute(VIEW_ASSIGNMENT_HIDE_STUDENT_VIEW_FLAG));
1717: context.put("contentTypeImageService", state
1718: .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
1719:
1720: // the user directory service
1721: context.put("userDirectoryService", UserDirectoryService
1722: .getInstance());
1723:
1724: String template = (String) getContext(data).get("template");
1725: return template + TEMPLATE_INSTRUCTOR_VIEW_ASSIGNMENT;
1726:
1727: } // build_instructor_view_assignment_context
1728:
1729: /**
1730: * build the instructor view to view the list of students for an assignment
1731: */
1732: protected String build_instructor_view_students_assignment_context(
1733: VelocityPortlet portlet, Context context, RunData data,
1734: SessionState state) {
1735: Iterator assignments = AssignmentService
1736: .getAssignmentsForContext((String) state
1737: .getAttribute(STATE_CONTEXT_STRING));
1738: Vector assignmentsVector = new Vector();
1739: while (assignments.hasNext()) {
1740: Assignment a = (Assignment) assignments.next();
1741: String deleted = a.getProperties().getProperty(
1742: ResourceProperties.PROP_ASSIGNMENT_DELETED);
1743: if ((deleted == null || deleted.equals(""))
1744: && (!a.getDraft())) {
1745: assignmentsVector.add(a);
1746: }
1747: }
1748:
1749: List studentMembers = new Vector();
1750: if (assignmentsVector.size() != 0) {
1751: List allowAddAssignmentUsers = AssignmentService
1752: .allowAddAssignmentUsers((String) state
1753: .getAttribute(STATE_CONTEXT_STRING));
1754: List allowAddSubmissionUsers = AssignmentService
1755: .allowAddSubmissionUsers(((Assignment) assignmentsVector
1756: .get(0)).getReference());
1757: for (int i = 0; i < allowAddSubmissionUsers.size(); i++) {
1758: User allowAddSubmissionUser = (User) allowAddSubmissionUsers
1759: .get(i);
1760: if (!allowAddAssignmentUsers
1761: .contains(allowAddSubmissionUser)) {
1762: studentMembers.add(allowAddSubmissionUser);
1763: }
1764: }
1765: }
1766: context.put("studentMembers", studentMembers);
1767: context.put("assignmentService", AssignmentService
1768: .getInstance());
1769: context.put("assignments", assignmentsVector);
1770: if (state.getAttribute(STUDENT_LIST_SHOW_TABLE) != null) {
1771: context.put("studentListShowTable", (Hashtable) state
1772: .getAttribute(STUDENT_LIST_SHOW_TABLE));
1773: }
1774:
1775: add2ndToolbarFields(data, context);
1776:
1777: pagingInfoToContext(state, context);
1778:
1779: String template = (String) getContext(data).get("template");
1780: return template + TEMPLATE_INSTRUCTOR_VIEW_STUDENTS_ASSIGNMENT;
1781:
1782: } // build_instructor_view_students_assignment_context
1783:
1784: /**
1785: * build the instructor view to report the submissions
1786: */
1787: protected String build_instructor_report_submissions(
1788: VelocityPortlet portlet, Context context, RunData data,
1789: SessionState state) {
1790: context.put("submissions", prepPage(state));
1791:
1792: context.put("sortedBy", (String) state
1793: .getAttribute(SORTED_SUBMISSION_BY));
1794: context.put("sortedAsc", (String) state
1795: .getAttribute(SORTED_SUBMISSION_ASC));
1796: context.put("sortedBy_lastName", SORTED_SUBMISSION_BY_LASTNAME);
1797: context.put("sortedBy_submitTime",
1798: SORTED_SUBMISSION_BY_SUBMIT_TIME);
1799: context.put("sortedBy_grade", SORTED_SUBMISSION_BY_GRADE);
1800: context.put("sortedBy_status", SORTED_SUBMISSION_BY_STATUS);
1801: context.put("sortedBy_released", SORTED_SUBMISSION_BY_RELEASED);
1802: context.put("sortedBy_assignment",
1803: SORTED_SUBMISSION_BY_ASSIGNMENT);
1804: context
1805: .put("sortedBy_maxGrade",
1806: SORTED_SUBMISSION_BY_MAX_GRADE);
1807:
1808: add2ndToolbarFields(data, context);
1809:
1810: String contextString = (String) state
1811: .getAttribute(STATE_CONTEXT_STRING);
1812: context.put("accessPointUrl", ServerConfigurationService
1813: .getAccessUrl()
1814: + AssignmentService.gradesSpreadsheetReference(
1815: contextString, null));
1816:
1817: pagingInfoToContext(state, context);
1818:
1819: String template = (String) getContext(data).get("template");
1820: return template + TEMPLATE_INSTRUCTOR_REPORT_SUBMISSIONS;
1821:
1822: } // build_instructor_report_submissions
1823:
1824: // Is Gradebook defined for the site?
1825: protected boolean isGradebookDefined() {
1826: boolean rv = false;
1827: try {
1828: GradebookService g = (GradebookService) (org.sakaiproject.service.gradebook.shared.GradebookService) ComponentManager
1829: .get("org.sakaiproject.service.gradebook.GradebookService");
1830: String gradebookUid = ToolManager.getInstance()
1831: .getCurrentPlacement().getContext();
1832: if (g.isGradebookDefined(gradebookUid)) {
1833: rv = true;
1834: }
1835: } catch (Exception e) {
1836: Log.debug("chef", this
1837: + rb.getString("addtogradebook.alertMessage")
1838: + "\n" + e.getMessage());
1839: }
1840:
1841: return rv;
1842:
1843: } // isGradebookDefined()
1844:
1845: /**
1846: ** Retrieve tool title from Tool configuration file or use default
1847: ** (This should return i18n version of tool title if available)
1848: **/
1849: private String getToolTitle() {
1850: Tool tool = ToolManager.getTool("sakai.assignment.grades");
1851: String toolTitle = null;
1852:
1853: if (tool == null)
1854: toolTitle = "Assignments";
1855: else
1856: toolTitle = tool.getTitle();
1857:
1858: return toolTitle;
1859: }
1860:
1861: /**
1862: * integration with gradebook
1863: *
1864: * @param state
1865: * @param assignmentRef Assignment reference
1866: * @param associateGradebookAssignment The title for the associated GB assignment
1867: * @param addUpdateRemoveAssignment "add" for adding the assignment; "update" for updating the assignment; "remove" for remove assignment
1868: * @param oldAssignment_title The original assignment title
1869: * @param newAssignment_title The updated assignment title
1870: * @param newAssignment_maxPoints The maximum point of the assignment
1871: * @param newAssignment_dueTime The due time of the assignment
1872: * @param submissionRef Any submission grade need to be updated? Do bulk update if null
1873: * @param updateRemoveSubmission "update" for update submission;"remove" for remove submission
1874: */
1875: protected void integrateGradebook(SessionState state,
1876: String assignmentRef, String associateGradebookAssignment,
1877: String addUpdateRemoveAssignment,
1878: String oldAssignment_title, String newAssignment_title,
1879: int newAssignment_maxPoints, Time newAssignment_dueTime,
1880: String submissionRef, String updateRemoveSubmission) {
1881: associateGradebookAssignment = StringUtil
1882: .trimToNull(associateGradebookAssignment);
1883:
1884: // add or remove external grades to gradebook
1885: // a. if Gradebook does not exists, do nothing, 'cos setting should have been hidden
1886: // b. if Gradebook exists, just call addExternal and removeExternal and swallow any exception. The
1887: // exception are indication that the assessment is already in the Gradebook or there is nothing
1888: // to remove.
1889: boolean gradebookExists = isGradebookDefined();
1890:
1891: if (gradebookExists) {
1892: String assignmentToolTitle = getToolTitle();
1893:
1894: GradebookService g = (GradebookService) (org.sakaiproject.service.gradebook.shared.GradebookService) ComponentManager
1895: .get("org.sakaiproject.service.gradebook.GradebookService");
1896: String gradebookUid = ToolManager.getInstance()
1897: .getCurrentPlacement().getContext();
1898: boolean isExternalAssignmentDefined = g
1899: .isExternalAssignmentDefined(gradebookUid,
1900: assignmentRef);
1901: boolean isExternalAssociateAssignmentDefined = g
1902: .isExternalAssignmentDefined(gradebookUid,
1903: associateGradebookAssignment);
1904: boolean isAssignmentDefined = g.isAssignmentDefined(
1905: gradebookUid, associateGradebookAssignment);
1906:
1907: if (addUpdateRemoveAssignment != null) {
1908: // add an entry into Gradebook for newly created assignment or modified assignment, and there wasn't a correspond record in gradebook yet
1909: if ((addUpdateRemoveAssignment
1910: .equals(GRADEBOOK_INTEGRATION_ADD) || (addUpdateRemoveAssignment
1911: .equals("update") && !isExternalAssignmentDefined))
1912: && associateGradebookAssignment == null) {
1913: // add assignment into gradebook
1914: try {
1915: // add assignment to gradebook
1916: g.addExternalAssessment(gradebookUid,
1917: assignmentRef, null,
1918: newAssignment_title,
1919: newAssignment_maxPoints / 10.0,
1920: new Date(newAssignment_dueTime
1921: .getTime()),
1922: assignmentToolTitle);
1923: } catch (AssignmentHasIllegalPointsException e) {
1924: addAlert(
1925: state,
1926: rb
1927: .getString("addtogradebook.illegalPoints"));
1928: } catch (ConflictingAssignmentNameException e) {
1929: // add alert prompting for change assignment title
1930: addAlert(
1931: state,
1932: rb
1933: .getString("addtogradebook.nonUniqueTitle"));
1934: } catch (ConflictingExternalIdException e) {
1935: // this shouldn't happen, as we have already checked for assignment reference before. Log the error
1936: Log.warn("chef", this + e.getMessage());
1937: } catch (GradebookNotFoundException e) {
1938: // this shouldn't happen, as we have checked for gradebook existence before
1939: Log.warn("chef", this + e.getMessage());
1940: } catch (Exception e) {
1941: // ignore
1942: Log.warn("chef", this + e.getMessage());
1943: }
1944: } else if (addUpdateRemoveAssignment.equals("update")) {
1945: // is there such record in gradebook?
1946: if (isExternalAssignmentDefined
1947: && associateGradebookAssignment == null) {
1948: try {
1949: Assignment a = AssignmentService
1950: .getAssignment(assignmentRef);
1951:
1952: // update attributes for existing assignment
1953: g
1954: .updateExternalAssessment(
1955: gradebookUid,
1956: assignmentRef,
1957: null,
1958: a.getTitle(),
1959: a.getContent()
1960: .getMaxGradePoint() / 10.0,
1961: new Date(a.getDueTime()
1962: .getTime()));
1963: } catch (Exception e) {
1964: Log.warn("chef", "Cannot find assignment "
1965: + assignmentRef + ": "
1966: + e.getMessage());
1967: }
1968: } else if (associateGradebookAssignment != null
1969: && isExternalAssociateAssignmentDefined) {
1970: try {
1971: Assignment a = AssignmentService
1972: .getAssignment(associateGradebookAssignment);
1973:
1974: // update attributes for existing assignment
1975: g.updateExternalAssessment(gradebookUid,
1976: associateGradebookAssignment, null,
1977: newAssignment_title,
1978: newAssignment_maxPoints / 10.0,
1979: new Date(newAssignment_dueTime
1980: .getTime()));
1981: } catch (Exception e) {
1982: Log.warn("chef", "Cannot find assignment "
1983: + assignmentRef + ": "
1984: + e.getMessage());
1985: }
1986: }
1987:
1988: } // addUpdateRemove != null
1989: else if (addUpdateRemoveAssignment.equals("remove")) {
1990: // remove assignment and all submission grades
1991: if (isExternalAssignmentDefined) {
1992: try {
1993: g.removeExternalAssessment(gradebookUid,
1994: assignmentRef);
1995: } catch (Exception e) {
1996: Log.warn("chef",
1997: "Exception when removing assignment "
1998: + assignmentRef
1999: + " and its submissions:"
2000: + e.getMessage());
2001: }
2002: }
2003: }
2004: }
2005:
2006: if (updateRemoveSubmission != null) {
2007: try {
2008: Assignment a = AssignmentService
2009: .getAssignment(assignmentRef);
2010:
2011: if (updateRemoveSubmission.equals("update")
2012: && a.getProperties().getProperty(
2013: NEW_ASSIGNMENT_ADD_TO_GRADEBOOK) != null
2014: && !a.getProperties().getProperty(
2015: NEW_ASSIGNMENT_ADD_TO_GRADEBOOK)
2016: .equals(GRADEBOOK_INTEGRATION_NO)
2017: && a.getContent().getTypeOfGrade() == Assignment.SCORE_GRADE_TYPE) {
2018: if (submissionRef == null) {
2019: // bulk add all grades for assignment into gradebook
2020: Iterator submissions = AssignmentService
2021: .getSubmissions(a);
2022:
2023: Map m = new HashMap();
2024:
2025: // any score to copy over? get all the assessmentGradingData and copy over
2026: while (submissions.hasNext()) {
2027: AssignmentSubmission aSubmission = (AssignmentSubmission) submissions
2028: .next();
2029: User[] submitters = aSubmission
2030: .getSubmitters();
2031: String submitterId = submitters[0]
2032: .getId();
2033: String gradeString = StringUtil
2034: .trimToNull(aSubmission
2035: .getGrade());
2036: Double grade = (gradeString != null && aSubmission
2037: .getGradeReleased()) ? Double
2038: .valueOf(displayGrade(state,
2039: gradeString)) : null;
2040: m.put(submitterId, grade);
2041: }
2042:
2043: // need to update only when there is at least one submission
2044: if (m.size() > 0) {
2045: if (associateGradebookAssignment != null) {
2046: if (isExternalAssociateAssignmentDefined) {
2047: // the associated assignment is externally maintained
2048: g
2049: .updateExternalAssessmentScores(
2050: gradebookUid,
2051: associateGradebookAssignment,
2052: m);
2053: } else if (isAssignmentDefined) {
2054: // the associated assignment is internal one, update records one by one
2055: submissions = AssignmentService
2056: .getSubmissions(a);
2057: while (submissions.hasNext()) {
2058: AssignmentSubmission aSubmission = (AssignmentSubmission) submissions
2059: .next();
2060: User[] submitters = aSubmission
2061: .getSubmitters();
2062: String submitterId = submitters[0]
2063: .getId();
2064: String gradeString = StringUtil
2065: .trimToNull(aSubmission
2066: .getGrade());
2067: Double grade = (gradeString != null && aSubmission
2068: .getGradeReleased()) ? Double
2069: .valueOf(displayGrade(
2070: state,
2071: gradeString))
2072: : null;
2073: g
2074: .setAssignmentScore(
2075: gradebookUid,
2076: associateGradebookAssignment,
2077: submitterId,
2078: grade,
2079: assignmentToolTitle);
2080: }
2081: }
2082: } else if (isExternalAssignmentDefined) {
2083: g.updateExternalAssessmentScores(
2084: gradebookUid,
2085: assignmentRef, m);
2086: }
2087: }
2088: } else {
2089: try {
2090: // only update one submission
2091: AssignmentSubmission aSubmission = (AssignmentSubmission) AssignmentService
2092: .getSubmission(submissionRef);
2093: User[] submitters = aSubmission
2094: .getSubmitters();
2095: String gradeString = StringUtil
2096: .trimToNull(aSubmission
2097: .getGrade());
2098:
2099: if (associateGradebookAssignment != null) {
2100: if (g
2101: .isExternalAssignmentDefined(
2102: gradebookUid,
2103: associateGradebookAssignment)) {
2104: // the associated assignment is externally maintained
2105: g
2106: .updateExternalAssessmentScore(
2107: gradebookUid,
2108: associateGradebookAssignment,
2109: submitters[0]
2110: .getId(),
2111: (gradeString != null && aSubmission
2112: .getGradeReleased()) ? Double
2113: .valueOf(displayGrade(
2114: state,
2115: gradeString))
2116: : null);
2117: } else if (g
2118: .isAssignmentDefined(
2119: gradebookUid,
2120: associateGradebookAssignment)) {
2121: // the associated assignment is internal one, update records
2122: g
2123: .setAssignmentScore(
2124: gradebookUid,
2125: associateGradebookAssignment,
2126: submitters[0]
2127: .getId(),
2128: (gradeString != null && aSubmission
2129: .getGradeReleased()) ? Double
2130: .valueOf(displayGrade(
2131: state,
2132: gradeString))
2133: : null,
2134: assignmentToolTitle);
2135: }
2136: } else {
2137: g
2138: .updateExternalAssessmentScore(
2139: gradebookUid,
2140: assignmentRef,
2141: submitters[0]
2142: .getId(),
2143: (gradeString != null && aSubmission
2144: .getGradeReleased()) ? Double
2145: .valueOf(displayGrade(
2146: state,
2147: gradeString))
2148: : null);
2149: }
2150: } catch (Exception e) {
2151: Log.warn("chef",
2152: "Cannot find submission "
2153: + submissionRef + ": "
2154: + e.getMessage());
2155: }
2156: }
2157:
2158: } else if (updateRemoveSubmission.equals("remove")) {
2159: if (submissionRef == null) {
2160: // remove all submission grades (when changing the associated entry in Gradebook)
2161: Iterator submissions = AssignmentService
2162: .getSubmissions(a);
2163:
2164: // any score to copy over? get all the assessmentGradingData and copy over
2165: while (submissions.hasNext()) {
2166: AssignmentSubmission aSubmission = (AssignmentSubmission) submissions
2167: .next();
2168: User[] submitters = aSubmission
2169: .getSubmitters();
2170: if (isExternalAssociateAssignmentDefined) {
2171: // if the old associated assignment is an external maintained one
2172: g
2173: .updateExternalAssessmentScore(
2174: gradebookUid,
2175: associateGradebookAssignment,
2176: submitters[0]
2177: .getId(),
2178: null);
2179: } else if (isAssignmentDefined) {
2180: g
2181: .setAssignmentScore(
2182: gradebookUid,
2183: associateGradebookAssignment,
2184: submitters[0]
2185: .getId(),
2186: null,
2187: assignmentToolTitle);
2188: }
2189: }
2190: } else {
2191: // remove only one submission grade
2192: try {
2193: AssignmentSubmission aSubmission = (AssignmentSubmission) AssignmentService
2194: .getSubmission(submissionRef);
2195: User[] submitters = aSubmission
2196: .getSubmitters();
2197: g.updateExternalAssessmentScore(
2198: gradebookUid, assignmentRef,
2199: submitters[0].getId(), null);
2200: } catch (Exception e) {
2201: Log.warn("chef",
2202: "Cannot find submission "
2203: + submissionRef + ": "
2204: + e.getMessage());
2205: }
2206: }
2207: }
2208: } catch (Exception e) {
2209: Log.warn("chef", "Cannot find assignment "
2210: + assignmentRef + ": " + e.getMessage());
2211: }
2212: } // updateRemoveSubmission != null
2213: } // if gradebook exists
2214: } // integrateGradebook
2215:
2216: /**
2217: * Go to the instructor view
2218: */
2219: public void doView_instructor(RunData data) {
2220: SessionState state = ((JetspeedRunData) data)
2221: .getPortletSessionState(((JetspeedRunData) data)
2222: .getJs_peid());
2223:
2224: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
2225: state.setAttribute(SORTED_BY, SORTED_BY_DUEDATE);
2226: state.setAttribute(SORTED_ASC, Boolean.TRUE.toString());
2227:
2228: } // doView_instructor
2229:
2230: /**
2231: * Go to the student view
2232: */
2233: public void doView_student(RunData data) {
2234: SessionState state = ((JetspeedRunData) data)
2235: .getPortletSessionState(((JetspeedRunData) data)
2236: .getJs_peid());
2237:
2238: // to the student list of assignment view
2239: state.setAttribute(SORTED_BY, SORTED_BY_DUEDATE);
2240: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
2241:
2242: } // doView_student
2243:
2244: /**
2245: * Action is to view the content of one specific assignment submission
2246: */
2247: public void doView_submission(RunData data) {
2248: SessionState state = ((JetspeedRunData) data)
2249: .getPortletSessionState(((JetspeedRunData) data)
2250: .getJs_peid());
2251:
2252: // reset the submission context
2253: resetViewSubmission(state);
2254:
2255: ParameterParser params = data.getParameters();
2256: String assignmentReference = params
2257: .getString("assignmentReference");
2258: state.setAttribute(VIEW_SUBMISSION_ASSIGNMENT_REFERENCE,
2259: assignmentReference);
2260:
2261: User u = (User) state.getAttribute(STATE_USER);
2262:
2263: try {
2264: AssignmentSubmission submission = AssignmentService
2265: .getSubmission(assignmentReference, u);
2266:
2267: if (submission != null) {
2268: state.setAttribute(VIEW_SUBMISSION_TEXT, submission
2269: .getSubmittedText());
2270: state.setAttribute(VIEW_SUBMISSION_HONOR_PLEDGE_YES,
2271: (new Boolean(submission.getHonorPledgeFlag()))
2272: .toString());
2273: List v = EntityManager.newReferenceList();
2274: Iterator l = submission.getSubmittedAttachments()
2275: .iterator();
2276: while (l.hasNext()) {
2277: v.add(l.next());
2278: }
2279: state.setAttribute(ATTACHMENTS, v);
2280: } else {
2281: state.setAttribute(VIEW_SUBMISSION_HONOR_PLEDGE_YES,
2282: "false");
2283: state.setAttribute(ATTACHMENTS, EntityManager
2284: .newReferenceList());
2285: }
2286:
2287: state
2288: .setAttribute(STATE_MODE,
2289: MODE_STUDENT_VIEW_SUBMISSION);
2290: } catch (IdUnusedException e) {
2291: addAlert(state, rb.getString("cannotfin5"));
2292: } catch (PermissionException e) {
2293: addAlert(state,
2294: "You are not allowed to view the assignment submission. ");
2295: } // try
2296:
2297: } // doView_submission
2298:
2299: /**
2300: * Preview of the submission
2301: */
2302: public void doPreview_submission(RunData data) {
2303: SessionState state = ((JetspeedRunData) data)
2304: .getPortletSessionState(((JetspeedRunData) data)
2305: .getJs_peid());
2306:
2307: ParameterParser params = data.getParameters();
2308: // String assignmentId = params.getString(assignmentId);
2309: state
2310: .setAttribute(
2311: PREVIEW_SUBMISSION_ASSIGNMENT_REFERENCE,
2312: state
2313: .getAttribute(VIEW_SUBMISSION_ASSIGNMENT_REFERENCE));
2314:
2315: // retrieve the submission text (as formatted text)
2316: boolean checkForFormattingErrors = true; // the student is submitting something - so check for errors
2317: String text = processFormattedTextFromBrowser(state, params
2318: .getCleanString(VIEW_SUBMISSION_TEXT),
2319: checkForFormattingErrors);
2320:
2321: state.setAttribute(PREVIEW_SUBMISSION_TEXT, text);
2322: state.setAttribute(VIEW_SUBMISSION_TEXT, text);
2323:
2324: // assign the honor pledge attribute
2325: String honor_pledge_yes = params
2326: .getString(VIEW_SUBMISSION_HONOR_PLEDGE_YES);
2327: if (honor_pledge_yes == null) {
2328: honor_pledge_yes = "false";
2329: }
2330: state.setAttribute(PREVIEW_SUBMISSION_HONOR_PLEDGE_YES,
2331: honor_pledge_yes);
2332: state.setAttribute(VIEW_SUBMISSION_HONOR_PLEDGE_YES,
2333: honor_pledge_yes);
2334:
2335: state.setAttribute(PREVIEW_SUBMISSION_ATTACHMENTS, state
2336: .getAttribute(ATTACHMENTS));
2337: if (state.getAttribute(STATE_MESSAGE) == null) {
2338: state.setAttribute(STATE_MODE,
2339: MODE_STUDENT_PREVIEW_SUBMISSION);
2340: }
2341: } // doPreview_submission
2342:
2343: /**
2344: * Preview of the grading of submission
2345: */
2346: public void doPreview_grade_submission(RunData data) {
2347: SessionState state = ((JetspeedRunData) data)
2348: .getPortletSessionState(((JetspeedRunData) data)
2349: .getJs_peid());
2350:
2351: // read user input
2352: readGradeForm(data, state, "read");
2353:
2354: if (state.getAttribute(STATE_MESSAGE) == null) {
2355: state.setAttribute(STATE_MODE,
2356: MODE_INSTRUCTOR_PREVIEW_GRADE_SUBMISSION);
2357: }
2358:
2359: } // doPreview_grade_submission
2360:
2361: /**
2362: * Action is to end the preview submission process
2363: */
2364: public void doDone_preview_submission(RunData data) {
2365: SessionState state = ((JetspeedRunData) data)
2366: .getPortletSessionState(((JetspeedRunData) data)
2367: .getJs_peid());
2368:
2369: // back to the student list view of assignments
2370: state.setAttribute(STATE_MODE, MODE_STUDENT_VIEW_SUBMISSION);
2371:
2372: } // doDone_preview_submission
2373:
2374: /**
2375: * Action is to end the view assignment process
2376: */
2377: public void doDone_view_assignment(RunData data) {
2378: SessionState state = ((JetspeedRunData) data)
2379: .getPortletSessionState(((JetspeedRunData) data)
2380: .getJs_peid());
2381:
2382: // back to the student list view of assignments
2383: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
2384:
2385: } // doDone_view_assignments
2386:
2387: /**
2388: * Action is to end the preview new assignment process
2389: */
2390: public void doDone_preview_new_assignment(RunData data) {
2391: SessionState state = ((JetspeedRunData) data)
2392: .getPortletSessionState(((JetspeedRunData) data)
2393: .getJs_peid());
2394:
2395: // back to the new assignment page
2396: state.setAttribute(STATE_MODE,
2397: MODE_INSTRUCTOR_NEW_EDIT_ASSIGNMENT);
2398:
2399: } // doDone_preview_new_assignment
2400:
2401: /**
2402: * Action is to end the preview edit assignment process
2403: */
2404: public void doDone_preview_edit_assignment(RunData data) {
2405: SessionState state = ((JetspeedRunData) data)
2406: .getPortletSessionState(((JetspeedRunData) data)
2407: .getJs_peid());
2408:
2409: // back to the edit assignment page
2410: state.setAttribute(STATE_MODE,
2411: MODE_INSTRUCTOR_NEW_EDIT_ASSIGNMENT);
2412:
2413: } // doDone_preview_edit_assignment
2414:
2415: /**
2416: * Action is to end the user view assignment process and redirect him to the assignment list view
2417: */
2418: public void doCancel_student_view_assignment(RunData data) {
2419: SessionState state = ((JetspeedRunData) data)
2420: .getPortletSessionState(((JetspeedRunData) data)
2421: .getJs_peid());
2422:
2423: // reset the view assignment
2424: state.setAttribute(VIEW_ASSIGNMENT_ID, "");
2425:
2426: // back to the student list view of assignments
2427: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
2428:
2429: } // doCancel_student_view_assignment
2430:
2431: /**
2432: * Action is to end the show submission process
2433: */
2434: public void doCancel_show_submission(RunData data) {
2435: SessionState state = ((JetspeedRunData) data)
2436: .getPortletSessionState(((JetspeedRunData) data)
2437: .getJs_peid());
2438:
2439: // reset the view assignment
2440: state.setAttribute(VIEW_ASSIGNMENT_ID, "");
2441:
2442: // back to the student list view of assignments
2443: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
2444:
2445: } // doCancel_show_submission
2446:
2447: /**
2448: * Action is to cancel the delete assignment process
2449: */
2450: public void doCancel_delete_assignment(RunData data) {
2451: SessionState state = ((JetspeedRunData) data)
2452: .getPortletSessionState(((JetspeedRunData) data)
2453: .getJs_peid());
2454:
2455: // reset the show assignment object
2456: state.setAttribute(DELETE_ASSIGNMENT_IDS, new Vector());
2457:
2458: // back to the instructor list view of assignments
2459: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
2460:
2461: } // doCancel_delete_assignment
2462:
2463: /**
2464: * Action is to end the show submission process
2465: */
2466: public void doCancel_edit_assignment(RunData data) {
2467: SessionState state = ((JetspeedRunData) data)
2468: .getPortletSessionState(((JetspeedRunData) data)
2469: .getJs_peid());
2470:
2471: // back to the student list view of assignments
2472: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
2473:
2474: } // doCancel_edit_assignment
2475:
2476: /**
2477: * Action is to end the show submission process
2478: */
2479: public void doCancel_new_assignment(RunData data) {
2480: SessionState state = ((JetspeedRunData) data)
2481: .getPortletSessionState(((JetspeedRunData) data)
2482: .getJs_peid());
2483:
2484: // reset the assignment object
2485: resetAssignment(state);
2486:
2487: // back to the student list view of assignments
2488: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
2489:
2490: } // doCancel_new_assignment
2491:
2492: /**
2493: * Action is to cancel the grade submission process
2494: */
2495: public void doCancel_grade_submission(RunData data) {
2496: SessionState state = ((JetspeedRunData) data)
2497: .getPortletSessionState(((JetspeedRunData) data)
2498: .getJs_peid());
2499:
2500: // reset the assignment object
2501: // resetAssignment (state);
2502:
2503: // back to the student list view of assignments
2504: state
2505: .setAttribute(STATE_MODE,
2506: MODE_INSTRUCTOR_GRADE_ASSIGNMENT);
2507:
2508: } // doCancel_grade_submission
2509:
2510: /**
2511: * Action is to cancel the preview grade process
2512: */
2513: public void doCancel_preview_grade_submission(RunData data) {
2514: SessionState state = ((JetspeedRunData) data)
2515: .getPortletSessionState(((JetspeedRunData) data)
2516: .getJs_peid());
2517:
2518: // back to the instructor view of grading a submission
2519: state
2520: .setAttribute(STATE_MODE,
2521: MODE_INSTRUCTOR_GRADE_SUBMISSION);
2522:
2523: } // doCancel_preview_grade_submission
2524:
2525: /**
2526: * Action is to return to the view of list assignments
2527: */
2528: public void doList_assignments(RunData data) {
2529: SessionState state = ((JetspeedRunData) data)
2530: .getPortletSessionState(((JetspeedRunData) data)
2531: .getJs_peid());
2532:
2533: // back to the student list view of assignments
2534: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
2535: state.setAttribute(SORTED_BY, SORTED_BY_DUEDATE);
2536:
2537: } // doList_assignments
2538:
2539: /**
2540: * Action is to cancel the student view grade process
2541: */
2542: public void doCancel_view_grade(RunData data) {
2543: SessionState state = ((JetspeedRunData) data)
2544: .getPortletSessionState(((JetspeedRunData) data)
2545: .getJs_peid());
2546:
2547: // reset the view grade submission id
2548: state.setAttribute(VIEW_GRADE_SUBMISSION_ID, "");
2549:
2550: // back to the student list view of assignments
2551: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
2552:
2553: } // doCancel_view_grade
2554:
2555: /**
2556: * Action is to save the grade to submission
2557: */
2558: public void doSave_grade_submission(RunData data) {
2559: SessionState state = ((JetspeedRunData) data)
2560: .getPortletSessionState(((JetspeedRunData) data)
2561: .getJs_peid());
2562: readGradeForm(data, state, "save");
2563: if (state.getAttribute(STATE_MESSAGE) == null) {
2564: grade_submission_option(data, "save");
2565: }
2566:
2567: } // doSave_grade_submission
2568:
2569: /**
2570: * Action is to release the grade to submission
2571: */
2572: public void doRelease_grade_submission(RunData data) {
2573: SessionState state = ((JetspeedRunData) data)
2574: .getPortletSessionState(((JetspeedRunData) data)
2575: .getJs_peid());
2576: readGradeForm(data, state, "release");
2577: if (state.getAttribute(STATE_MESSAGE) == null) {
2578: grade_submission_option(data, "release");
2579: }
2580:
2581: } // doRelease_grade_submission
2582:
2583: /**
2584: * Action is to return submission with or without grade
2585: */
2586: public void doReturn_grade_submission(RunData data) {
2587: SessionState state = ((JetspeedRunData) data)
2588: .getPortletSessionState(((JetspeedRunData) data)
2589: .getJs_peid());
2590: readGradeForm(data, state, "return");
2591: if (state.getAttribute(STATE_MESSAGE) == null) {
2592: grade_submission_option(data, "return");
2593: }
2594:
2595: } // doReturn_grade_submission
2596:
2597: /**
2598: * Action is to return submission with or without grade from preview
2599: */
2600: public void doReturn_preview_grade_submission(RunData data) {
2601: grade_submission_option(data, "return");
2602:
2603: } // doReturn_grade_preview_submission
2604:
2605: /**
2606: * Action is to save submission with or without grade from preview
2607: */
2608: public void doSave_preview_grade_submission(RunData data) {
2609: grade_submission_option(data, "save");
2610:
2611: } // doSave_grade_preview_submission
2612:
2613: /**
2614: * Common grading routine plus specific operation to differenciate cases when saving, releasing or returning grade.
2615: */
2616: private void grade_submission_option(RunData data,
2617: String gradeOption) {
2618: SessionState state = ((JetspeedRunData) data)
2619: .getPortletSessionState(((JetspeedRunData) data)
2620: .getJs_peid());
2621:
2622: boolean withGrade = state.getAttribute(WITH_GRADES) != null ? ((Boolean) state
2623: .getAttribute(WITH_GRADES)).booleanValue()
2624: : false;
2625:
2626: String sId = (String) state
2627: .getAttribute(GRADE_SUBMISSION_SUBMISSION_ID);
2628:
2629: try {
2630: // for points grading, one have to enter number as the points
2631: String grade = (String) state
2632: .getAttribute(GRADE_SUBMISSION_GRADE);
2633:
2634: AssignmentSubmissionEdit sEdit = AssignmentService
2635: .editSubmission(sId);
2636: Assignment a = sEdit.getAssignment();
2637: int typeOfGrade = a.getContent().getTypeOfGrade();
2638:
2639: if (!withGrade) {
2640: // no grade input needed for the without-grade version of assignment tool
2641: sEdit.setGraded(true);
2642: if (gradeOption.equals("return")
2643: || gradeOption.equals("release")) {
2644: sEdit.setGradeReleased(true);
2645: }
2646: } else if (grade == null) {
2647: sEdit.setGrade("");
2648: sEdit.setGraded(false);
2649: sEdit.setGradeReleased(false);
2650: } else {
2651: if (typeOfGrade == 1) {
2652: sEdit.setGrade("no grade");
2653: sEdit.setGraded(true);
2654: } else {
2655: if (!grade.equals("")) {
2656: if (typeOfGrade == 3) {
2657: sEdit.setGrade(grade);
2658: } else {
2659: sEdit.setGrade(grade);
2660: }
2661: sEdit.setGraded(true);
2662: }
2663: }
2664: }
2665:
2666: if (gradeOption.equals("release")) {
2667: sEdit.setGradeReleased(true);
2668: sEdit.setGraded(true);
2669: // clear the returned flag
2670: sEdit.setReturned(false);
2671: sEdit.setTimeReturned(null);
2672: } else if (gradeOption.equals("return")) {
2673: if (StringUtil.trimToNull(grade) != null) {
2674: sEdit.setGradeReleased(true);
2675: sEdit.setGraded(true);
2676: }
2677: sEdit.setReturned(true);
2678: sEdit.setTimeReturned(TimeService.newTime());
2679: sEdit.setHonorPledgeFlag(Boolean.FALSE.booleanValue());
2680: }
2681:
2682: if (state.getAttribute(GRADE_SUBMISSION_ALLOW_RESUBMIT) != null
2683: && ((Boolean) state
2684: .getAttribute(GRADE_SUBMISSION_ALLOW_RESUBMIT))
2685: .booleanValue()) {
2686: sEdit.getPropertiesEdit().addProperty(
2687: GRADE_SUBMISSION_ALLOW_RESUBMIT,
2688: Boolean.TRUE.toString());
2689: state.removeAttribute(GRADE_SUBMISSION_ALLOW_RESUBMIT);
2690: } else {
2691: sEdit.getPropertiesEdit().removeProperty(
2692: GRADE_SUBMISSION_ALLOW_RESUBMIT);
2693: }
2694:
2695: // the instructor comment
2696: String feedbackCommentString = StringUtil
2697: .trimToNull((String) state
2698: .getAttribute(GRADE_SUBMISSION_FEEDBACK_COMMENT));
2699: if (feedbackCommentString != null) {
2700: sEdit.setFeedbackComment(feedbackCommentString);
2701: }
2702:
2703: // the instructor inline feedback
2704: String feedbackTextString = (String) state
2705: .getAttribute(GRADE_SUBMISSION_FEEDBACK_TEXT);
2706: if (feedbackTextString != null) {
2707: sEdit.setFeedbackText(feedbackTextString);
2708: }
2709:
2710: List v = (List) state
2711: .getAttribute(GRADE_SUBMISSION_FEEDBACK_ATTACHMENT);
2712: if (v != null) {
2713: // clear the old attachments first
2714: sEdit.clearFeedbackAttachments();
2715:
2716: for (int i = 0; i < v.size(); i++) {
2717: sEdit.addFeedbackAttachment((Reference) v.get(i));
2718: }
2719: }
2720:
2721: String sReference = sEdit.getReference();
2722:
2723: AssignmentService.commitEdit(sEdit);
2724:
2725: // update grades in gradebook
2726: String aReference = a.getReference();
2727: String associateGradebookAssignment = StringUtil
2728: .trimToNull(a
2729: .getProperties()
2730: .getProperty(
2731: NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT));
2732:
2733: if (gradeOption.equals("release")
2734: || gradeOption.equals("return")) {
2735: // update grade in gradebook
2736: integrateGradebook(state, aReference,
2737: associateGradebookAssignment, null, null, null,
2738: -1, null, sReference, "update");
2739: } else {
2740: // remove grade from gradebook
2741: integrateGradebook(state, aReference,
2742: associateGradebookAssignment, null, null, null,
2743: -1, null, sReference, "remove");
2744: }
2745: } catch (IdUnusedException e) {
2746: } catch (PermissionException e) {
2747: } catch (InUseException e) {
2748: addAlert(state, rb.getString("somelsis") + " "
2749: + rb.getString("submiss"));
2750: } // try
2751:
2752: if (state.getAttribute(STATE_MESSAGE) == null) {
2753: state.setAttribute(STATE_MODE,
2754: MODE_INSTRUCTOR_GRADE_ASSIGNMENT);
2755: state.setAttribute(ATTACHMENTS, EntityManager
2756: .newReferenceList());
2757: }
2758:
2759: } // grade_submission_option
2760:
2761: /**
2762: * Action is to save the submission as a draft
2763: */
2764: public void doSave_submission(RunData data) {
2765: SessionState state = ((JetspeedRunData) data)
2766: .getPortletSessionState(((JetspeedRunData) data)
2767: .getJs_peid());
2768: ParameterParser params = data.getParameters();
2769:
2770: // retrieve the submission text (as formatted text)
2771: boolean checkForFormattingErrors = true; // the student is submitting something - so check for errors
2772: String text = processFormattedTextFromBrowser(state, params
2773: .getCleanString(VIEW_SUBMISSION_TEXT),
2774: checkForFormattingErrors);
2775:
2776: if (text == null) {
2777: text = (String) state.getAttribute(VIEW_SUBMISSION_TEXT);
2778: }
2779:
2780: String honorPledgeYes = params
2781: .getString(VIEW_SUBMISSION_HONOR_PLEDGE_YES);
2782: if (honorPledgeYes == null) {
2783: honorPledgeYes = "false";
2784: }
2785:
2786: String aReference = (String) state
2787: .getAttribute(VIEW_SUBMISSION_ASSIGNMENT_REFERENCE);
2788: User u = (User) state.getAttribute(STATE_USER);
2789:
2790: if (state.getAttribute(STATE_MESSAGE) == null) {
2791: try {
2792: Assignment a = AssignmentService
2793: .getAssignment(aReference);
2794: String assignmentId = a.getId();
2795:
2796: AssignmentSubmission submission = AssignmentService
2797: .getSubmission(aReference, u);
2798: if (submission != null) {
2799: // the submission already exists, change the text and honor pledge value, save as draft
2800: try {
2801: AssignmentSubmissionEdit edit = AssignmentService
2802: .editSubmission(submission
2803: .getReference());
2804: edit.setSubmittedText(text);
2805: edit.setHonorPledgeFlag(Boolean.valueOf(
2806: honorPledgeYes).booleanValue());
2807: edit.setSubmitted(false);
2808: // edit.addSubmitter (u);
2809: edit.setAssignment(a);
2810:
2811: // add attachments
2812: List attachments = (List) state
2813: .getAttribute(ATTACHMENTS);
2814: if (attachments != null) {
2815: // clear the old attachments first
2816: edit.clearSubmittedAttachments();
2817:
2818: // add each new attachment
2819: Iterator it = attachments.iterator();
2820: while (it.hasNext()) {
2821: edit
2822: .addSubmittedAttachment((Reference) it
2823: .next());
2824: }
2825: }
2826: AssignmentService.commitEdit(edit);
2827: } catch (IdUnusedException e) {
2828: addAlert(state, rb.getString("cannotfin2")
2829: + " " + a.getTitle());
2830: } catch (PermissionException e) {
2831: addAlert(state, rb.getString("youarenot12"));
2832: } catch (InUseException e) {
2833: addAlert(state, rb.getString("somelsis") + " "
2834: + rb.getString("submiss"));
2835: }
2836: } else {
2837: // new submission, save as draft
2838: try {
2839: AssignmentSubmissionEdit edit = AssignmentService
2840: .addSubmission(
2841: (String) state
2842: .getAttribute(STATE_CONTEXT_STRING),
2843: assignmentId);
2844: edit.setSubmittedText(text);
2845: edit.setHonorPledgeFlag(Boolean.valueOf(
2846: honorPledgeYes).booleanValue());
2847: edit.setSubmitted(false);
2848: // edit.addSubmitter (u);
2849: edit.setAssignment(a);
2850:
2851: // add attachments
2852: List attachments = (List) state
2853: .getAttribute(ATTACHMENTS);
2854: if (attachments != null) {
2855: // add each attachment
2856: Iterator it = attachments.iterator();
2857: while (it.hasNext()) {
2858: edit
2859: .addSubmittedAttachment((Reference) it
2860: .next());
2861: }
2862: }
2863: AssignmentService.commitEdit(edit);
2864: } catch (PermissionException e) {
2865: addAlert(state, rb.getString("youarenot4"));
2866: }
2867: }
2868: } catch (IdUnusedException e) {
2869: addAlert(state, rb.getString("cannotfin5"));
2870: } catch (PermissionException e) {
2871: addAlert(state,
2872: "You are not allowed to view the assignment submission. ");
2873: }
2874: }
2875:
2876: if (state.getAttribute(STATE_MESSAGE) == null) {
2877: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
2878: state.setAttribute(ATTACHMENTS, EntityManager
2879: .newReferenceList());
2880: }
2881:
2882: } // doSave_submission
2883:
2884: /**
2885: * Action is to post the submission
2886: */
2887: public void doPost_submission(RunData data) {
2888: SessionState state = ((JetspeedRunData) data)
2889: .getPortletSessionState(((JetspeedRunData) data)
2890: .getJs_peid());
2891: ParameterParser params = data.getParameters();
2892:
2893: // retrieve the submission text (as formatted text)
2894: boolean checkForFormattingErrors = true; // the student is submitting something - so check for errors
2895: String text = processFormattedTextFromBrowser(state, params
2896: .getCleanString(VIEW_SUBMISSION_TEXT),
2897: checkForFormattingErrors);
2898:
2899: if (text == null) {
2900: text = (String) state.getAttribute(VIEW_SUBMISSION_TEXT);
2901: } else {
2902: state.setAttribute(VIEW_SUBMISSION_TEXT, text);
2903: }
2904:
2905: String honorPledgeYes = params
2906: .getString(VIEW_SUBMISSION_HONOR_PLEDGE_YES);
2907: if (honorPledgeYes == null) {
2908: honorPledgeYes = (String) state
2909: .getAttribute(VIEW_SUBMISSION_HONOR_PLEDGE_YES);
2910: }
2911:
2912: if (honorPledgeYes == null) {
2913: honorPledgeYes = "false";
2914: }
2915:
2916: User u = (User) state.getAttribute(STATE_USER);
2917: String aReference = (String) state
2918: .getAttribute(VIEW_SUBMISSION_ASSIGNMENT_REFERENCE);
2919: Assignment a = null;
2920: String assignmentId = "";
2921: if (state.getAttribute(STATE_MESSAGE) == null) {
2922: try {
2923: a = AssignmentService.getAssignment(aReference);
2924: assignmentId = a.getId();
2925:
2926: if (a.getContent().getHonorPledge() != 1) {
2927: if (!Boolean.valueOf(honorPledgeYes).booleanValue()) {
2928: addAlert(state, rb.getString("youarenot18"));
2929: }
2930: state.setAttribute(
2931: VIEW_SUBMISSION_HONOR_PLEDGE_YES,
2932: honorPledgeYes);
2933: }
2934:
2935: // check the submission inputs based on the submission type
2936: int submissionType = a.getContent()
2937: .getTypeOfSubmission();
2938: if (submissionType == 1) {
2939: // for the inline only submission
2940: if (text.length() == 0) {
2941: addAlert(state, rb.getString("youmust7"));
2942: }
2943: } else if (submissionType == 2) {
2944: // for the attachment only submission
2945: Vector v = (Vector) state.getAttribute(ATTACHMENTS);
2946: if ((v == null) || (v.size() == 0)) {
2947: addAlert(state, rb.getString("youmust1"));
2948: }
2949: } else if (submissionType == 3) {
2950: // for the inline and attachment submission
2951: Vector v = (Vector) state.getAttribute(ATTACHMENTS);
2952: if ((text.length() == 0)
2953: && ((v == null) || (v.size() == 0))) {
2954: addAlert(state, rb.getString("youmust2"));
2955: }
2956: }
2957: } catch (IdUnusedException e) {
2958: addAlert(state, rb.getString("cannotfin2"));
2959: } catch (PermissionException e) {
2960: addAlert(state, rb.getString("youarenot14"));
2961: }
2962: }
2963:
2964: if ((state.getAttribute(STATE_MESSAGE) == null) && (a != null)) {
2965: try {
2966: AssignmentSubmission submission = AssignmentService
2967: .getSubmission(a.getReference(), u);
2968: if (submission != null) {
2969: // the submission already exists, change the text and honor pledge value, post it
2970: try {
2971: AssignmentSubmissionEdit sEdit = AssignmentService
2972: .editSubmission(submission
2973: .getReference());
2974: sEdit.setSubmittedText(text);
2975: sEdit.setHonorPledgeFlag(Boolean.valueOf(
2976: honorPledgeYes).booleanValue());
2977: sEdit.setTimeSubmitted(TimeService.newTime());
2978: sEdit.setSubmitted(true);
2979:
2980: // for resubmissions
2981: // when resubmit, keep the Returned flag on till the instructor grade again.
2982: if (sEdit.getReturned()) {
2983: ResourcePropertiesEdit sPropertiesEdit = sEdit
2984: .getPropertiesEdit();
2985: if (sEdit.getGraded()) {
2986: // add the current grade into previous grade histroy
2987: String previousGrades = (String) sEdit
2988: .getProperties()
2989: .getProperty(
2990: ResourceProperties.PROP_SUBMISSION_SCALED_PREVIOUS_GRADES);
2991: if (previousGrades == null) {
2992: previousGrades = (String) sEdit
2993: .getProperties()
2994: .getProperty(
2995: ResourceProperties.PROP_SUBMISSION_PREVIOUS_GRADES);
2996: if (previousGrades != null) {
2997: int typeOfGrade = a
2998: .getContent()
2999: .getTypeOfGrade();
3000: if (typeOfGrade == 3) {
3001: // point grade assignment type
3002: // some old unscaled grades, need to scale the number and remove the old property
3003: String[] grades = StringUtil
3004: .split(
3005: previousGrades,
3006: " ");
3007: String newGrades = "";
3008: for (int jj = 0; jj < grades.length; jj++) {
3009: String grade = grades[jj];
3010: if (grade.indexOf(".") == -1) {
3011: // show the grade with decimal point
3012: grade = grade
3013: .concat(".0");
3014: }
3015: newGrades = newGrades
3016: .concat(grade
3017: + " ");
3018: }
3019: previousGrades = newGrades;
3020: }
3021: sPropertiesEdit
3022: .removeProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_GRADES);
3023: } else {
3024: previousGrades = "";
3025: }
3026: }
3027: previousGrades = previousGrades
3028: .concat(sEdit.getGradeDisplay()
3029: + " ");
3030:
3031: sPropertiesEdit
3032: .addProperty(
3033: ResourceProperties.PROP_SUBMISSION_SCALED_PREVIOUS_GRADES,
3034: previousGrades);
3035:
3036: // clear the current grade and make the submission ungraded
3037: sEdit.setGraded(false);
3038: sEdit.setGrade("");
3039: sEdit.setGradeReleased(false);
3040: }
3041:
3042: // keep the history of assignment feed back text
3043: String feedbackTextHistory = sPropertiesEdit
3044: .getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT) != null ? sPropertiesEdit
3045: .getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT)
3046: : "";
3047: feedbackTextHistory = sEdit
3048: .getFeedbackText()
3049: + "\n" + feedbackTextHistory;
3050: sPropertiesEdit
3051: .addProperty(
3052: ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT,
3053: feedbackTextHistory);
3054:
3055: // keep the history of assignment feed back comment
3056: String feedbackCommentHistory = sPropertiesEdit
3057: .getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT) != null ? sPropertiesEdit
3058: .getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT)
3059: : "";
3060: feedbackCommentHistory = sEdit
3061: .getFeedbackComment()
3062: + "\n" + feedbackCommentHistory;
3063: sPropertiesEdit
3064: .addProperty(
3065: ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT,
3066: feedbackCommentHistory);
3067:
3068: // keep the history of assignment feed back comment
3069: String feedbackAttachmentHistory = sPropertiesEdit
3070: .getProperty(PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS) != null ? sPropertiesEdit
3071: .getProperty(PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS)
3072: : "";
3073: List feedbackAttachments = sEdit
3074: .getFeedbackAttachments();
3075: for (int k = 0; k < feedbackAttachments
3076: .size(); k++) {
3077: feedbackAttachmentHistory = ((Reference) feedbackAttachments
3078: .get(k)).getReference()
3079: + ","
3080: + feedbackAttachmentHistory;
3081: }
3082:
3083: sPropertiesEdit
3084: .addProperty(
3085: PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS,
3086: feedbackAttachmentHistory);
3087:
3088: // reset the previous grading context
3089: sEdit.setFeedbackText("");
3090: sEdit.setFeedbackComment("");
3091: sEdit.clearFeedbackAttachments();
3092:
3093: sPropertiesEdit
3094: .removeProperty(GRADE_SUBMISSION_ALLOW_RESUBMIT);
3095: }
3096: // sEdit.addSubmitter (u);
3097: sEdit.setAssignment(a);
3098:
3099: // add attachments
3100: List attachments = (List) state
3101: .getAttribute(ATTACHMENTS);
3102: if (attachments != null) {
3103: // clear the old attachments first
3104: sEdit.clearSubmittedAttachments();
3105:
3106: // add each new attachment
3107: Iterator it = attachments.iterator();
3108: while (it.hasNext()) {
3109: sEdit
3110: .addSubmittedAttachment((Reference) it
3111: .next());
3112: }
3113: }
3114:
3115: AssignmentService.commitEdit(sEdit);
3116: } catch (IdUnusedException e) {
3117: addAlert(state, rb.getString("cannotfin2")
3118: + " " + a.getTitle());
3119: } catch (PermissionException e) {
3120: addAlert(state,
3121: "You do not have permission to edit the submission. ");
3122: } catch (InUseException e) {
3123: addAlert(state, rb.getString("somelsis") + " "
3124: + rb.getString("submiss"));
3125: }
3126: } else {
3127: // new submission, post it
3128: try {
3129: AssignmentSubmissionEdit edit = AssignmentService
3130: .addSubmission(
3131: (String) state
3132: .getAttribute(STATE_CONTEXT_STRING),
3133: assignmentId);
3134: edit.setSubmittedText(text);
3135: edit.setHonorPledgeFlag(Boolean.valueOf(
3136: honorPledgeYes).booleanValue());
3137: edit.setTimeSubmitted(TimeService.newTime());
3138: edit.setSubmitted(true);
3139: // edit.addSubmitter (u);
3140: edit.setAssignment(a);
3141:
3142: // add attachments
3143: List attachments = (List) state
3144: .getAttribute(ATTACHMENTS);
3145: if (attachments != null) {
3146: // add each attachment
3147: Iterator it = attachments.iterator();
3148: while (it.hasNext()) {
3149: edit
3150: .addSubmittedAttachment((Reference) it
3151: .next());
3152: }
3153: }
3154:
3155: AssignmentService.commitEdit(edit);
3156: } catch (PermissionException e) {
3157: addAlert(state, rb.getString("youarenot13"));
3158: }
3159: } // if -else
3160: } catch (IdUnusedException e) {
3161: addAlert(state, rb.getString("cannotfin5"));
3162: } catch (PermissionException e) {
3163: addAlert(state,
3164: "You are not allowed to view the assignment submission. ");
3165: }
3166:
3167: } // if
3168:
3169: if (state.getAttribute(STATE_MESSAGE) == null) {
3170: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
3171: state.setAttribute(ATTACHMENTS, EntityManager
3172: .newReferenceList());
3173: }
3174:
3175: } // doPost_submission
3176:
3177: /**
3178: * Action is to show the new assignment screen
3179: */
3180: public void doNew_assignment(RunData data, Context context) {
3181: SessionState state = ((JetspeedRunData) data)
3182: .getPortletSessionState(((JetspeedRunData) data)
3183: .getJs_peid());
3184:
3185: if (!alertGlobalNavigation(state, data)) {
3186: if (AssignmentService.allowAddAssignment((String) state
3187: .getAttribute(STATE_CONTEXT_STRING))) {
3188: resetAssignment(state);
3189: state.setAttribute(ATTACHMENTS, EntityManager
3190: .newReferenceList());
3191: state.setAttribute(STATE_MODE,
3192: MODE_INSTRUCTOR_NEW_EDIT_ASSIGNMENT);
3193: } else {
3194: addAlert(state, rb.getString("youarenot2"));
3195: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
3196: }
3197: }
3198:
3199: } // doNew_Assignment
3200:
3201: /**
3202: * Action is to save the input infos for assignment fields
3203: *
3204: * @param validify
3205: * Need to validify the inputs or not
3206: */
3207: protected void setNewAssignmentParameters(RunData data,
3208: boolean validify) {
3209: // read the form inputs
3210: SessionState state = ((JetspeedRunData) data)
3211: .getPortletSessionState(((JetspeedRunData) data)
3212: .getJs_peid());
3213: ParameterParser params = data.getParameters();
3214:
3215: // put the input value into the state attributes
3216: String title = params.getString(NEW_ASSIGNMENT_TITLE);
3217: state.setAttribute(NEW_ASSIGNMENT_TITLE, title);
3218:
3219: if (title.length() == 0) {
3220: // empty assignment title
3221: addAlert(state, rb.getString("plespethe1"));
3222: }
3223:
3224: // open time
3225: int openMonth = (new Integer(params
3226: .getString(NEW_ASSIGNMENT_OPENMONTH))).intValue();
3227: state.setAttribute(NEW_ASSIGNMENT_OPENMONTH, new Integer(
3228: openMonth));
3229: int openDay = (new Integer(params
3230: .getString(NEW_ASSIGNMENT_OPENDAY))).intValue();
3231: state
3232: .setAttribute(NEW_ASSIGNMENT_OPENDAY, new Integer(
3233: openDay));
3234: int openYear = (new Integer(params
3235: .getString(NEW_ASSIGNMENT_OPENYEAR))).intValue();
3236: state.setAttribute(NEW_ASSIGNMENT_OPENYEAR, new Integer(
3237: openYear));
3238: int openHour = (new Integer(params
3239: .getString(NEW_ASSIGNMENT_OPENHOUR))).intValue();
3240: state.setAttribute(NEW_ASSIGNMENT_OPENHOUR, new Integer(
3241: openHour));
3242: int openMin = (new Integer(params
3243: .getString(NEW_ASSIGNMENT_OPENMIN))).intValue();
3244: state
3245: .setAttribute(NEW_ASSIGNMENT_OPENMIN, new Integer(
3246: openMin));
3247: String openAMPM = params.getString(NEW_ASSIGNMENT_OPENAMPM);
3248: state.setAttribute(NEW_ASSIGNMENT_OPENAMPM, openAMPM);
3249: if ((openAMPM.equals("PM")) && (openHour != 12)) {
3250: openHour = openHour + 12;
3251: }
3252: if ((openHour == 12) && (openAMPM.equals("AM"))) {
3253: openHour = 0;
3254: }
3255: Time openTime = TimeService.newTimeLocal(openYear, openMonth,
3256: openDay, openHour, openMin, 0, 0);
3257: // validate date
3258: if (!Validator.checkDate(openDay, openMonth, openYear)) {
3259: addAlert(state, rb.getString("date.invalid")
3260: + rb.getString("date.opendate") + ".");
3261: }
3262:
3263: // due time
3264: int dueMonth = (new Integer(params
3265: .getString(NEW_ASSIGNMENT_DUEMONTH))).intValue();
3266: state.setAttribute(NEW_ASSIGNMENT_DUEMONTH, new Integer(
3267: dueMonth));
3268: int dueDay = (new Integer(params
3269: .getString(NEW_ASSIGNMENT_DUEDAY))).intValue();
3270: state.setAttribute(NEW_ASSIGNMENT_DUEDAY, new Integer(dueDay));
3271: int dueYear = (new Integer(params
3272: .getString(NEW_ASSIGNMENT_DUEYEAR))).intValue();
3273: state
3274: .setAttribute(NEW_ASSIGNMENT_DUEYEAR, new Integer(
3275: dueYear));
3276: int dueHour = (new Integer(params
3277: .getString(NEW_ASSIGNMENT_DUEHOUR))).intValue();
3278: state
3279: .setAttribute(NEW_ASSIGNMENT_DUEHOUR, new Integer(
3280: dueHour));
3281: int dueMin = (new Integer(params
3282: .getString(NEW_ASSIGNMENT_DUEMIN))).intValue();
3283: state.setAttribute(NEW_ASSIGNMENT_DUEMIN, new Integer(dueMin));
3284: String dueAMPM = params.getString(NEW_ASSIGNMENT_DUEAMPM);
3285: state.setAttribute(NEW_ASSIGNMENT_DUEAMPM, dueAMPM);
3286: if ((dueAMPM.equals("PM")) && (dueHour != 12)) {
3287: dueHour = dueHour + 12;
3288: }
3289: if ((dueHour == 12) && (dueAMPM.equals("AM"))) {
3290: dueHour = 0;
3291: }
3292: Time dueTime = TimeService.newTimeLocal(dueYear, dueMonth,
3293: dueDay, dueHour, dueMin, 0, 0);
3294: // validate date
3295: if (!Validator.checkDate(dueDay, dueMonth, dueYear)) {
3296: addAlert(state, rb.getString("date.invalid")
3297: + rb.getString("date.duedate") + ".");
3298: }
3299:
3300: state.setAttribute(NEW_ASSIGNMENT_ENABLECLOSEDATE, new Boolean(
3301: true));
3302:
3303: // close time
3304: int closeMonth = (new Integer(params
3305: .getString(NEW_ASSIGNMENT_CLOSEMONTH))).intValue();
3306: state.setAttribute(NEW_ASSIGNMENT_CLOSEMONTH, new Integer(
3307: closeMonth));
3308: int closeDay = (new Integer(params
3309: .getString(NEW_ASSIGNMENT_CLOSEDAY))).intValue();
3310: state.setAttribute(NEW_ASSIGNMENT_CLOSEDAY, new Integer(
3311: closeDay));
3312: int closeYear = (new Integer(params
3313: .getString(NEW_ASSIGNMENT_CLOSEYEAR))).intValue();
3314: state.setAttribute(NEW_ASSIGNMENT_CLOSEYEAR, new Integer(
3315: closeYear));
3316: int closeHour = (new Integer(params
3317: .getString(NEW_ASSIGNMENT_CLOSEHOUR))).intValue();
3318: state.setAttribute(NEW_ASSIGNMENT_CLOSEHOUR, new Integer(
3319: closeHour));
3320: int closeMin = (new Integer(params
3321: .getString(NEW_ASSIGNMENT_CLOSEMIN))).intValue();
3322: state.setAttribute(NEW_ASSIGNMENT_CLOSEMIN, new Integer(
3323: closeMin));
3324: String closeAMPM = params.getString(NEW_ASSIGNMENT_CLOSEAMPM);
3325: state.setAttribute(NEW_ASSIGNMENT_CLOSEAMPM, closeAMPM);
3326: if ((closeAMPM.equals("PM")) && (closeHour != 12)) {
3327: closeHour = closeHour + 12;
3328: }
3329: if ((closeHour == 12) && (closeAMPM.equals("AM"))) {
3330: closeHour = 0;
3331: }
3332: Time closeTime = TimeService.newTimeLocal(closeYear,
3333: closeMonth, closeDay, closeHour, closeMin, 0, 0);
3334: // validate date
3335: if (!Validator.checkDate(closeDay, closeMonth, closeYear)) {
3336: addAlert(state, rb.getString("date.invalid")
3337: + rb.getString("date.closedate") + ".");
3338: }
3339: if (closeTime.before(openTime)) {
3340: addAlert(state, rb.getString("acesubdea3"));
3341: }
3342: if (closeTime.before(dueTime)) {
3343: addAlert(state, rb.getString("acesubdea2"));
3344: }
3345:
3346: // SECTION MOD
3347: String sections_string = "";
3348: String mode = (String) state.getAttribute(STATE_MODE);
3349: if (mode == null)
3350: mode = "";
3351:
3352: state.setAttribute(NEW_ASSIGNMENT_SECTION, sections_string);
3353: state.setAttribute(NEW_ASSIGNMENT_SUBMISSION_TYPE, new Integer(
3354: params.getString(NEW_ASSIGNMENT_SUBMISSION_TYPE)));
3355:
3356: int gradeType = -1;
3357:
3358: // grade type and grade points
3359: if (state.getAttribute(WITH_GRADES) != null
3360: && ((Boolean) state.getAttribute(WITH_GRADES))
3361: .booleanValue()) {
3362: gradeType = Integer.parseInt(params
3363: .getString(NEW_ASSIGNMENT_GRADE_TYPE));
3364: state.setAttribute(NEW_ASSIGNMENT_GRADE_TYPE, new Integer(
3365: gradeType));
3366: }
3367:
3368: // treat the new assignment description as formatted text
3369: boolean checkForFormattingErrors = true; // instructor is creating a new assignment - so check for errors
3370: String description = processFormattedTextFromBrowser(state,
3371: params.getCleanString(NEW_ASSIGNMENT_DESCRIPTION),
3372: checkForFormattingErrors);
3373: state.setAttribute(NEW_ASSIGNMENT_DESCRIPTION, description);
3374:
3375: if (state.getAttribute(CALENDAR) != null) {
3376: // calendar enabled for the site
3377: if (params
3378: .getString(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE) != null
3379: && params
3380: .getString(
3381: ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE)
3382: .equalsIgnoreCase(Boolean.TRUE.toString())) {
3383: state
3384: .setAttribute(
3385: ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE,
3386: Boolean.TRUE.toString());
3387: } else {
3388: state
3389: .setAttribute(
3390: ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE,
3391: Boolean.FALSE.toString());
3392: }
3393: } else {
3394: // no calendar yet for the site
3395: state
3396: .removeAttribute(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE);
3397: }
3398:
3399: if (params
3400: .getString(ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE) != null
3401: && params
3402: .getString(
3403: ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE)
3404: .equalsIgnoreCase(Boolean.TRUE.toString())) {
3405: state
3406: .setAttribute(
3407: ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE,
3408: Boolean.TRUE.toString());
3409: } else {
3410: state
3411: .setAttribute(
3412: ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE,
3413: Boolean.FALSE.toString());
3414: }
3415:
3416: String s = params
3417: .getString(NEW_ASSIGNMENT_CHECK_ADD_HONOR_PLEDGE);
3418:
3419: // set the honor pledge to be "no honor pledge"
3420: if (s == null)
3421: s = "1";
3422: state.setAttribute(NEW_ASSIGNMENT_CHECK_ADD_HONOR_PLEDGE, s);
3423:
3424: String grading = params
3425: .getString(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK);
3426: state.setAttribute(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK, grading);
3427:
3428: // only when choose to associate with assignment in Gradebook
3429: String associateAssignment = params
3430: .getString(NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT);
3431:
3432: if (grading != null) {
3433: if (grading.equals(GRADEBOOK_INTEGRATION_ASSOCIATE)) {
3434: state.setAttribute(
3435: NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT,
3436: associateAssignment);
3437: } else {
3438: state.setAttribute(
3439: NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT,
3440: "");
3441: }
3442:
3443: if (!grading.equals(GRADEBOOK_INTEGRATION_NO)) {
3444: // gradebook integration only available to point-grade assignment
3445: if (gradeType != Assignment.SCORE_GRADE_TYPE) {
3446: addAlert(
3447: state,
3448: rb
3449: .getString("addtogradebook.wrongGradeScale"));
3450: }
3451:
3452: // if chosen as "associate", have to choose one assignment from Gradebook
3453: if (grading.equals(GRADEBOOK_INTEGRATION_ASSOCIATE)
3454: && StringUtil.trimToNull(associateAssignment) == null) {
3455: addAlert(state, rb
3456: .getString("grading.associate.alert"));
3457: }
3458: }
3459: }
3460:
3461: List attachments = (List) state.getAttribute(ATTACHMENTS);
3462: state.setAttribute(NEW_ASSIGNMENT_ATTACHMENT, attachments);
3463:
3464: // correct inputs
3465: // checks on the times
3466: if (validify && dueTime.before(openTime)) {
3467: addAlert(state, rb.getString("assig3"));
3468: }
3469:
3470: if (validify) {
3471: if (((description == null) || (description.length() == 0))
3472: && ((attachments == null || attachments.size() == 0))) {
3473: // if there is no description nor an attachment, show the following alert message.
3474: // One could ignore the message and still post the assignment
3475: if (state
3476: .getAttribute(NEW_ASSIGNMENT_DESCRIPTION_EMPTY) == null) {
3477: state.setAttribute(
3478: NEW_ASSIGNMENT_DESCRIPTION_EMPTY,
3479: Boolean.TRUE.toString());
3480: } else {
3481: state
3482: .removeAttribute(NEW_ASSIGNMENT_DESCRIPTION_EMPTY);
3483: }
3484: } else {
3485: state.removeAttribute(NEW_ASSIGNMENT_DESCRIPTION_EMPTY);
3486: }
3487: }
3488:
3489: if (validify
3490: && state.getAttribute(NEW_ASSIGNMENT_DESCRIPTION_EMPTY) != null) {
3491: addAlert(state, rb.getString("thiasshas"));
3492: }
3493:
3494: if (state.getAttribute(WITH_GRADES) != null
3495: && ((Boolean) state.getAttribute(WITH_GRADES))
3496: .booleanValue()) {
3497: // the grade point
3498: String gradePoints = params
3499: .getString(NEW_ASSIGNMENT_GRADE_POINTS);
3500: state
3501: .setAttribute(NEW_ASSIGNMENT_GRADE_POINTS,
3502: gradePoints);
3503: if (gradePoints != null) {
3504: if (gradeType == 3) {
3505: if ((gradePoints.length() == 0)) {
3506: // in case of releasing grade, user must specify a grade
3507: addAlert(state, rb.getString("plespethe2"));
3508: } else {
3509: validPointGrade(state, gradePoints);
3510: // when scale is points, grade must be integer and less than maximum value
3511: if (state.getAttribute(STATE_MESSAGE) == null) {
3512: gradePoints = scalePointGrade(state,
3513: gradePoints);
3514: }
3515: state.setAttribute(NEW_ASSIGNMENT_GRADE_POINTS,
3516: gradePoints);
3517: }
3518: }
3519: }
3520: }
3521:
3522: // assignment range?
3523: String range = data.getParameters().getString("range");
3524: state.setAttribute(NEW_ASSIGNMENT_RANGE, range);
3525: if (range.equals("groups")) {
3526: String[] groupChoice = data.getParameters().getStrings(
3527: "selectedGroups");
3528: if (groupChoice != null && groupChoice.length != 0) {
3529: state.setAttribute(NEW_ASSIGNMENT_GROUPS,
3530: new ArrayList(Arrays.asList(groupChoice)));
3531: } else {
3532: state.setAttribute(NEW_ASSIGNMENT_GROUPS, null);
3533: addAlert(state, rb
3534: .getString("java.alert.youchoosegroup"));
3535: }
3536: } else {
3537: state.removeAttribute(NEW_ASSIGNMENT_GROUPS);
3538: }
3539:
3540: } // setNewAssignmentParameters
3541:
3542: /**
3543: * Action is to hide the preview assignment student view
3544: */
3545: public void doHide_submission_assignment_instruction(RunData data) {
3546: SessionState state = ((JetspeedRunData) data)
3547: .getPortletSessionState(((JetspeedRunData) data)
3548: .getJs_peid());
3549: state.setAttribute(GRADE_SUBMISSION_ASSIGNMENT_EXPAND_FLAG,
3550: new Boolean(false));
3551:
3552: // save user input
3553: readGradeForm(data, state, "read");
3554:
3555: } // doHide_preview_assignment_student_view
3556:
3557: /**
3558: * Action is to show the preview assignment student view
3559: */
3560: public void doShow_submission_assignment_instruction(RunData data) {
3561: SessionState state = ((JetspeedRunData) data)
3562: .getPortletSessionState(((JetspeedRunData) data)
3563: .getJs_peid());
3564: state.setAttribute(GRADE_SUBMISSION_ASSIGNMENT_EXPAND_FLAG,
3565: new Boolean(true));
3566:
3567: // save user input
3568: readGradeForm(data, state, "read");
3569:
3570: } // doShow_submission_assignment_instruction
3571:
3572: /**
3573: * Action is to hide the preview assignment student view
3574: */
3575: public void doHide_preview_assignment_student_view(RunData data) {
3576: SessionState state = ((JetspeedRunData) data)
3577: .getPortletSessionState(((JetspeedRunData) data)
3578: .getJs_peid());
3579: state.setAttribute(PREVIEW_ASSIGNMENT_STUDENT_VIEW_HIDE_FLAG,
3580: new Boolean(true));
3581:
3582: } // doHide_preview_assignment_student_view
3583:
3584: /**
3585: * Action is to show the preview assignment student view
3586: */
3587: public void doShow_preview_assignment_student_view(RunData data) {
3588: SessionState state = ((JetspeedRunData) data)
3589: .getPortletSessionState(((JetspeedRunData) data)
3590: .getJs_peid());
3591: state.setAttribute(PREVIEW_ASSIGNMENT_STUDENT_VIEW_HIDE_FLAG,
3592: new Boolean(false));
3593:
3594: } // doShow_preview_assignment_student_view
3595:
3596: /**
3597: * Action is to hide the preview assignment assignment infos
3598: */
3599: public void doHide_preview_assignment_assignment(RunData data) {
3600: SessionState state = ((JetspeedRunData) data)
3601: .getPortletSessionState(((JetspeedRunData) data)
3602: .getJs_peid());
3603: state.setAttribute(PREVIEW_ASSIGNMENT_ASSIGNMENT_HIDE_FLAG,
3604: new Boolean(true));
3605:
3606: } // doHide_preview_assignment_assignment
3607:
3608: /**
3609: * Action is to show the preview assignment assignment info
3610: */
3611: public void doShow_preview_assignment_assignment(RunData data) {
3612: SessionState state = ((JetspeedRunData) data)
3613: .getPortletSessionState(((JetspeedRunData) data)
3614: .getJs_peid());
3615: state.setAttribute(PREVIEW_ASSIGNMENT_ASSIGNMENT_HIDE_FLAG,
3616: new Boolean(false));
3617:
3618: } // doShow_preview_assignment_assignment
3619:
3620: /**
3621: * Action is to hide the assignment option
3622: */
3623: public void doHide_assignment_option(RunData data) {
3624: setNewAssignmentParameters(data, false);
3625: SessionState state = ((JetspeedRunData) data)
3626: .getPortletSessionState(((JetspeedRunData) data)
3627: .getJs_peid());
3628: state.setAttribute(NEW_ASSIGNMENT_HIDE_OPTION_FLAG,
3629: new Boolean(true));
3630: state.setAttribute(NEW_ASSIGNMENT_FOCUS,
3631: "eventSubmit_doShow_assignment_option");
3632:
3633: } // doHide_assignment_option
3634:
3635: /**
3636: * Action is to show the assignment option
3637: */
3638: public void doShow_assignment_option(RunData data) {
3639: setNewAssignmentParameters(data, false);
3640: SessionState state = ((JetspeedRunData) data)
3641: .getPortletSessionState(((JetspeedRunData) data)
3642: .getJs_peid());
3643: state.setAttribute(NEW_ASSIGNMENT_HIDE_OPTION_FLAG,
3644: new Boolean(false));
3645: state.setAttribute(NEW_ASSIGNMENT_FOCUS,
3646: NEW_ASSIGNMENT_CHECK_ADD_HONOR_PLEDGE);
3647:
3648: } // doShow_assignment_option
3649:
3650: /**
3651: * Action is to hide the assignment content in the view assignment page
3652: */
3653: public void doHide_view_assignment(RunData data) {
3654: SessionState state = ((JetspeedRunData) data)
3655: .getPortletSessionState(((JetspeedRunData) data)
3656: .getJs_peid());
3657: state.setAttribute(VIEW_ASSIGNMENT_HIDE_ASSIGNMENT_FLAG,
3658: new Boolean(true));
3659:
3660: } // doHide_view_assignment
3661:
3662: /**
3663: * Action is to show the assignment content in the view assignment page
3664: */
3665: public void doShow_view_assignment(RunData data) {
3666: SessionState state = ((JetspeedRunData) data)
3667: .getPortletSessionState(((JetspeedRunData) data)
3668: .getJs_peid());
3669: state.setAttribute(VIEW_ASSIGNMENT_HIDE_ASSIGNMENT_FLAG,
3670: new Boolean(false));
3671:
3672: } // doShow_view_assignment
3673:
3674: /**
3675: * Action is to hide the student view in the view assignment page
3676: */
3677: public void doHide_view_student_view(RunData data) {
3678: SessionState state = ((JetspeedRunData) data)
3679: .getPortletSessionState(((JetspeedRunData) data)
3680: .getJs_peid());
3681: state.setAttribute(VIEW_ASSIGNMENT_HIDE_STUDENT_VIEW_FLAG,
3682: new Boolean(true));
3683:
3684: } // doHide_view_student_view
3685:
3686: /**
3687: * Action is to show the student view in the view assignment page
3688: */
3689: public void doShow_view_student_view(RunData data) {
3690: SessionState state = ((JetspeedRunData) data)
3691: .getPortletSessionState(((JetspeedRunData) data)
3692: .getJs_peid());
3693: state.setAttribute(VIEW_ASSIGNMENT_HIDE_STUDENT_VIEW_FLAG,
3694: new Boolean(false));
3695:
3696: } // doShow_view_student_view
3697:
3698: /**
3699: * Action is to post assignment
3700: */
3701: public void doPost_assignment(RunData data) {
3702: // post assignment
3703: postOrSaveAssignment(data, "post");
3704:
3705: } // doPost_assignment
3706:
3707: /**
3708: * post or save assignment
3709: */
3710: private void postOrSaveAssignment(RunData data, String postOrSave) {
3711: SessionState state = ((JetspeedRunData) data)
3712: .getPortletSessionState(((JetspeedRunData) data)
3713: .getJs_peid());
3714:
3715: String siteId = (String) state
3716: .getAttribute(STATE_CONTEXT_STRING);
3717:
3718: boolean post = (postOrSave != null && postOrSave.equals("post")) ? true
3719: : false;
3720:
3721: // assignment old title
3722: String aOldTitle = null;
3723:
3724: // assignment old associated Gradebook entry if any
3725: String oAssociateGradebookAssignment = null;
3726:
3727: String mode = (String) state.getAttribute(STATE_MODE);
3728: if (!mode.equals(MODE_INSTRUCTOR_PREVIEW_ASSIGNMENT)) {
3729: // read input data if the mode is not preview mode
3730: setNewAssignmentParameters(data, true);
3731: }
3732:
3733: if (state.getAttribute(STATE_MESSAGE) == null) {
3734: ParameterParser params = data.getParameters();
3735:
3736: // put the names and values into vm file
3737: String title = (String) state
3738: .getAttribute(NEW_ASSIGNMENT_TITLE);
3739:
3740: // open time
3741: int openMonth = ((Integer) state
3742: .getAttribute(NEW_ASSIGNMENT_OPENMONTH)).intValue();
3743: int openDay = ((Integer) state
3744: .getAttribute(NEW_ASSIGNMENT_OPENDAY)).intValue();
3745: int openYear = ((Integer) state
3746: .getAttribute(NEW_ASSIGNMENT_OPENYEAR)).intValue();
3747: int openHour = ((Integer) state
3748: .getAttribute(NEW_ASSIGNMENT_OPENHOUR)).intValue();
3749: int openMin = ((Integer) state
3750: .getAttribute(NEW_ASSIGNMENT_OPENMIN)).intValue();
3751: String openAMPM = (String) state
3752: .getAttribute(NEW_ASSIGNMENT_OPENAMPM);
3753: if ((openAMPM.equals("PM")) && (openHour != 12)) {
3754: openHour = openHour + 12;
3755: }
3756: if ((openHour == 12) && (openAMPM.equals("AM"))) {
3757: openHour = 0;
3758: }
3759: Time openTime = TimeService.newTimeLocal(openYear,
3760: openMonth, openDay, openHour, openMin, 0, 0);
3761:
3762: // due time
3763: int dueMonth = ((Integer) state
3764: .getAttribute(NEW_ASSIGNMENT_DUEMONTH)).intValue();
3765: int dueDay = ((Integer) state
3766: .getAttribute(NEW_ASSIGNMENT_DUEDAY)).intValue();
3767: int dueYear = ((Integer) state
3768: .getAttribute(NEW_ASSIGNMENT_DUEYEAR)).intValue();
3769: int dueHour = ((Integer) state
3770: .getAttribute(NEW_ASSIGNMENT_DUEHOUR)).intValue();
3771: int dueMin = ((Integer) state
3772: .getAttribute(NEW_ASSIGNMENT_DUEMIN)).intValue();
3773: String dueAMPM = (String) state
3774: .getAttribute(NEW_ASSIGNMENT_DUEAMPM);
3775: if ((dueAMPM.equals("PM")) && (dueHour != 12)) {
3776: dueHour = dueHour + 12;
3777: }
3778: if ((dueHour == 12) && (dueAMPM.equals("AM"))) {
3779: dueHour = 0;
3780: }
3781: Time dueTime = TimeService.newTimeLocal(dueYear, dueMonth,
3782: dueDay, dueHour, dueMin, 0, 0);
3783:
3784: // close time
3785: Time closeTime = TimeService.newTime();
3786: boolean enableCloseDate = ((Boolean) state
3787: .getAttribute(NEW_ASSIGNMENT_ENABLECLOSEDATE))
3788: .booleanValue();
3789: if (enableCloseDate) {
3790: int closeMonth = ((Integer) state
3791: .getAttribute(NEW_ASSIGNMENT_CLOSEMONTH))
3792: .intValue();
3793: int closeDay = ((Integer) state
3794: .getAttribute(NEW_ASSIGNMENT_CLOSEDAY))
3795: .intValue();
3796: int closeYear = ((Integer) state
3797: .getAttribute(NEW_ASSIGNMENT_CLOSEYEAR))
3798: .intValue();
3799: int closeHour = ((Integer) state
3800: .getAttribute(NEW_ASSIGNMENT_CLOSEHOUR))
3801: .intValue();
3802: int closeMin = ((Integer) state
3803: .getAttribute(NEW_ASSIGNMENT_CLOSEMIN))
3804: .intValue();
3805: String closeAMPM = (String) state
3806: .getAttribute(NEW_ASSIGNMENT_CLOSEAMPM);
3807: if ((closeAMPM.equals("PM")) && (closeHour != 12)) {
3808: closeHour = closeHour + 12;
3809: }
3810: if ((closeHour == 12) && (closeAMPM.equals("AM"))) {
3811: closeHour = 0;
3812: }
3813: closeTime = TimeService
3814: .newTimeLocal(closeYear, closeMonth, closeDay,
3815: closeHour, closeMin, 0, 0);
3816: }
3817:
3818: // sections
3819: String s = (String) state
3820: .getAttribute(NEW_ASSIGNMENT_SECTION);
3821:
3822: int submissionType = ((Integer) state
3823: .getAttribute(NEW_ASSIGNMENT_SUBMISSION_TYPE))
3824: .intValue();
3825:
3826: int gradeType = ((Integer) state
3827: .getAttribute(NEW_ASSIGNMENT_GRADE_TYPE))
3828: .intValue();
3829:
3830: String gradePoints = (String) state
3831: .getAttribute(NEW_ASSIGNMENT_GRADE_POINTS);
3832:
3833: String description = (String) state
3834: .getAttribute(NEW_ASSIGNMENT_DESCRIPTION);
3835:
3836: String checkAddDueTime = state
3837: .getAttribute(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE) != null ? (String) state
3838: .getAttribute(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE)
3839: : null;
3840:
3841: String checkAutoAnnounce = (String) state
3842: .getAttribute(ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE);
3843:
3844: String checkAddHonorPledge = (String) state
3845: .getAttribute(NEW_ASSIGNMENT_CHECK_ADD_HONOR_PLEDGE);
3846:
3847: String addtoGradebook = (String) state
3848: .getAttribute(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK) != null ? (String) state
3849: .getAttribute(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK)
3850: : "";
3851:
3852: String associateGradebookAssignment = (String) state
3853: .getAttribute(NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT);
3854:
3855: // the attachments
3856: List attachments = (List) state.getAttribute(ATTACHMENTS);
3857: List attachments1 = EntityManager
3858: .newReferenceList(attachments);
3859:
3860: // correct inputs
3861: if (state.getAttribute(STATE_MESSAGE) == null) {
3862: String assignmentId = params.getString("assignmentId");
3863: String assignmentContentId = params
3864: .getString("assignmentContentId");
3865:
3866: // AssignmentContent object
3867: AssignmentContentEdit ac = null;
3868: if (assignmentContentId.length() == 0) {
3869: // new assignment
3870: // only show alert when dealing with new assignment
3871: // allow editing assignment after due date
3872: if (dueTime.before(TimeService.newTime())) {
3873: addAlert(state, rb.getString("assig4"));
3874: } else {
3875: try {
3876: ac = AssignmentService
3877: .addAssignmentContent((String) state
3878: .getAttribute(STATE_CONTEXT_STRING));
3879: } catch (PermissionException e) {
3880: addAlert(state, rb.getString("youarenot3"));
3881: }
3882: }
3883: } else {
3884: try {
3885: // edit assignment
3886: ac = AssignmentService
3887: .editAssignmentContent(assignmentContentId);
3888: } catch (InUseException e) {
3889: addAlert(state, rb.getString("theassicon"));
3890: } catch (IdUnusedException e) {
3891: addAlert(state, rb.getString("cannotfin4"));
3892: } catch (PermissionException e) {
3893: addAlert(state, rb.getString("youarenot15"));
3894: }
3895:
3896: }
3897:
3898: // Assignment
3899: AssignmentEdit a = null;
3900: if (assignmentId.length() == 0) {
3901: // create a new assignment
3902: try {
3903: a = AssignmentService
3904: .addAssignment((String) state
3905: .getAttribute(STATE_CONTEXT_STRING));
3906: } catch (PermissionException e) {
3907: addAlert(state, rb.getString("youarenot1"));
3908: }
3909: } else {
3910: try {
3911: // edit assignment
3912: a = AssignmentService
3913: .editAssignment(assignmentId);
3914: aOldTitle = a.getTitle();
3915: } catch (InUseException e) {
3916: addAlert(state, rb.getString("theassicon"));
3917: } catch (IdUnusedException e) {
3918: addAlert(state, rb.getString("cannotfin3"));
3919: } catch (PermissionException e) {
3920: addAlert(state, rb.getString("youarenot14"));
3921: } // try-catch
3922: } // if-else
3923:
3924: if ((state.getAttribute(STATE_MESSAGE) == null)
3925: && (ac != null) && (a != null)) {
3926: ac.setTitle(title);
3927: ac.setInstructions(description);
3928: ac.setHonorPledge(Integer
3929: .parseInt(checkAddHonorPledge));
3930: ac.setTypeOfSubmission(submissionType);
3931: ac.setTypeOfGrade(gradeType);
3932: if (gradeType == 3) {
3933: try {
3934: ac.setMaxGradePoint(Integer
3935: .parseInt(gradePoints));
3936: } catch (NumberFormatException e) {
3937: alertInvalidPoint(state, gradePoints);
3938: }
3939: }
3940: ac.setGroupProject(true);
3941: ac.setIndividuallyGraded(false);
3942:
3943: if (submissionType != 1) {
3944: ac.setAllowAttachments(true);
3945: } else {
3946: ac.setAllowAttachments(false);
3947: }
3948:
3949: // clear attachments
3950: ac.clearAttachments();
3951:
3952: // add each attachment
3953: Iterator it = EntityManager.newReferenceList(
3954: attachments1).iterator();
3955: while (it.hasNext()) {
3956: Reference r = (Reference) it.next();
3957: ac.addAttachment(r);
3958: }
3959: state.setAttribute(ATTACHMENTS_MODIFIED,
3960: new Boolean(false));
3961:
3962: // commit the changes
3963: AssignmentService.commitEdit(ac);
3964:
3965: }
3966:
3967: a.setTitle(title);
3968: a.setContent(ac);
3969: a.setContext((String) state
3970: .getAttribute(STATE_CONTEXT_STRING));
3971: a.setSection(s);
3972: // old open time
3973: Time oldOpenTime = a.getOpenTime();
3974: a.setOpenTime(openTime);
3975: // old due time
3976: Time oldDueTime = a.getDueTime();
3977: a.setDueTime(dueTime);
3978: // set the drop dead date as the due date
3979: a.setDropDeadTime(dueTime);
3980: if (enableCloseDate) {
3981: a.setCloseTime(closeTime);
3982: } else {
3983: // if editing an old assignment with close date
3984: if (a.getCloseTime() != null) {
3985: a.setCloseTime(null);
3986: }
3987: }
3988:
3989: // post the assignment
3990: a.setDraft(!post);
3991:
3992: // set the auto check/auto announce property
3993: ResourcePropertiesEdit aPropertiesEdit = a
3994: .getPropertiesEdit();
3995: if (aPropertiesEdit.getProperty("newAssignment") != null) {
3996: if (aPropertiesEdit.getProperty("newAssignment")
3997: .equalsIgnoreCase(Boolean.TRUE.toString())) {
3998: // not a newly created assignment, been added.
3999: aPropertiesEdit.addProperty("newAssignment",
4000: Boolean.FALSE.toString());
4001: }
4002: } else {
4003: // for newly created assignment
4004: aPropertiesEdit.addProperty("newAssignment",
4005: Boolean.TRUE.toString());
4006: }
4007: if (checkAddDueTime != null) {
4008: aPropertiesEdit
4009: .addProperty(
4010: ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE,
4011: checkAddDueTime);
4012: } else {
4013: aPropertiesEdit
4014: .removeProperty(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE);
4015: }
4016: aPropertiesEdit
4017: .addProperty(
4018: ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE,
4019: checkAutoAnnounce);
4020: aPropertiesEdit
4021: .addProperty(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK,
4022: addtoGradebook);
4023: oAssociateGradebookAssignment = aPropertiesEdit
4024: .getProperty(NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT);
4025: aPropertiesEdit.addProperty(
4026: NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT,
4027: associateGradebookAssignment);
4028:
4029: if (addtoGradebook.equals(GRADEBOOK_INTEGRATION_ADD)) {
4030: // if the choice is to add an entry into Gradebook, let just mark it as associated with such new entry then
4031: aPropertiesEdit.addProperty(
4032: NEW_ASSIGNMENT_ADD_TO_GRADEBOOK,
4033: GRADEBOOK_INTEGRATION_ASSOCIATE);
4034: aPropertiesEdit
4035: .addProperty(
4036: NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT,
4037: a.getReference());
4038:
4039: }
4040: // set group property
4041: String range = (String) state
4042: .getAttribute(NEW_ASSIGNMENT_RANGE);
4043: try {
4044: if (range.equals("site")) {
4045: a.setAccess(Assignment.AssignmentAccess.SITE);
4046: a.clearGroupAccess();
4047: } else if (range.equals("groups")) {
4048: try {
4049: Site site = SiteService.getSite(siteId);
4050: Collection groupChoice = (Collection) state
4051: .getAttribute(NEW_ASSIGNMENT_GROUPS);
4052: Collection groups = new Vector();
4053: for (Iterator iGroups = groupChoice
4054: .iterator(); iGroups.hasNext();) {
4055: String groupId = (String) iGroups
4056: .next();
4057: groups.add(site.getGroup(groupId));
4058: }
4059: a.setGroupAccess(groups);
4060: } catch (Exception e) {
4061: Log.warn("chef", this
4062: + "cannot find site with id "
4063: + siteId);
4064: }
4065: }
4066: } catch (PermissionException e) {
4067: addAlert(state, rb.getString("youarenot1"));
4068: }
4069:
4070: if (state.getAttribute(STATE_MESSAGE) == null) {
4071: // commit assignment first
4072: AssignmentService.commitEdit(a);
4073:
4074: if (state.getAttribute(STATE_MESSAGE) == null) {
4075: state.setAttribute(STATE_MODE,
4076: MODE_LIST_ASSIGNMENTS);
4077: state.setAttribute(ATTACHMENTS, EntityManager
4078: .newReferenceList());
4079: resetAssignment(state);
4080: }
4081:
4082: if (post) {
4083: // add due date to schedule and add open date to announcement only if user is posting the assignment
4084:
4085: // add the due date to schedule if the schedule exists
4086: if (state.getAttribute(CALENDAR) != null) {
4087: Calendar c = (Calendar) state
4088: .getAttribute(CALENDAR);
4089: String dueDateScheduled = a
4090: .getProperties()
4091: .getProperty(
4092: NEW_ASSIGNMENT_DUE_DATE_SCHEDULED);
4093: String oldEventId = aPropertiesEdit
4094: .getProperty(ResourceProperties.PROP_ASSIGNMENT_DUEDATE_CALENDAR_EVENT_ID);
4095: CalendarEvent e = null;
4096:
4097: if (dueDateScheduled != null
4098: || oldEventId != null) {
4099: // find the old event
4100: boolean found = false;
4101: if (oldEventId != null && c != null) {
4102: try {
4103: e = c.getEvent(oldEventId);
4104: found = true;
4105: } catch (IdUnusedException ee) {
4106: Log.warn("chef",
4107: "The old event has been deleted: event id="
4108: + oldEventId
4109: + ". ");
4110: } catch (PermissionException ee) {
4111: Log.warn("chef",
4112: "You do not have the permission to view the schedule event id= "
4113: + oldEventId
4114: + ".");
4115: }
4116: } else {
4117: TimeBreakdown b = oldDueTime
4118: .breakdownLocal();
4119: // TODO: check- this was new Time(year...), not local! -ggolden
4120: Time startTime = TimeService
4121: .newTimeLocal(b.getYear(),
4122: b.getMonth(), b
4123: .getDay(),
4124: 0, 0, 0, 0);
4125: Time endTime = TimeService
4126: .newTimeLocal(b.getYear(),
4127: b.getMonth(), b
4128: .getDay(),
4129: 23, 59, 59, 999);
4130: try {
4131: Iterator events = c
4132: .getEvents(
4133: TimeService
4134: .newTimeRange(
4135: startTime,
4136: endTime),
4137: null)
4138: .iterator();
4139:
4140: while ((!found)
4141: && (events.hasNext())) {
4142: e = (CalendarEvent) events
4143: .next();
4144: if (((String) e
4145: .getDisplayName())
4146: .indexOf(rb
4147: .getString("assig1")
4148: + " "
4149: + title) != -1) {
4150: found = true;
4151: }
4152: }
4153: } catch (PermissionException ignore) {
4154: // ignore PermissionException
4155: }
4156: }
4157:
4158: if (found) {
4159: // remove the founded old event
4160: try {
4161: c
4162: .removeEvent(c
4163: .getEditEvent(
4164: e
4165: .getId(),
4166: CalendarService.EVENT_REMOVE_CALENDAR));
4167: } catch (PermissionException ee) {
4168: Log.warn("chef", rb
4169: .getString("cannotrem")
4170: + " " + title + ". ");
4171: } catch (InUseException ee) {
4172: Log
4173: .warn(
4174: "chef",
4175: rb
4176: .getString("somelsis")
4177: + " "
4178: + rb
4179: .getString("calen"));
4180: } catch (IdUnusedException ee) {
4181: Log
4182: .warn(
4183: "chef",
4184: rb
4185: .getString("cannotfin6")
4186: + e
4187: .getId());
4188: }
4189: }
4190: }
4191:
4192: if (checkAddDueTime
4193: .equalsIgnoreCase(Boolean.TRUE
4194: .toString())) {
4195: if (c != null) {
4196: // commit related properties into Assignment object
4197: String ref = "";
4198: try {
4199: ref = a.getReference();
4200: AssignmentEdit aEdit = AssignmentService
4201: .editAssignment(ref);
4202:
4203: try {
4204: e = null;
4205: CalendarEvent.EventAccess eAccess = CalendarEvent.EventAccess.SITE;
4206: Collection eGroups = new Vector();
4207:
4208: if (aEdit
4209: .getAccess()
4210: .equals(
4211: Assignment.AssignmentAccess.GROUPED)) {
4212: eAccess = CalendarEvent.EventAccess.GROUPED;
4213: Collection groupRefs = aEdit
4214: .getGroups();
4215:
4216: // make a collection of Group objects from the collection of group ref strings
4217: Site site = SiteService
4218: .getSite((String) state
4219: .getAttribute(STATE_CONTEXT_STRING));
4220: for (Iterator iGroupRefs = groupRefs
4221: .iterator(); iGroupRefs
4222: .hasNext();) {
4223: String groupRef = (String) iGroupRefs
4224: .next();
4225: eGroups
4226: .add(site
4227: .getGroup(groupRef));
4228: }
4229: }
4230: e = c
4231: .addEvent(
4232: /* TimeRange */TimeService
4233: .newTimeRange(
4234: dueTime
4235: .getTime(), /* 0 duration */
4236: 0 * 60 * 1000),
4237: /* title */rb
4238: .getString("due")
4239: + " "
4240: + title,
4241: /* description */rb
4242: .getString("assig1")
4243: + " "
4244: + title
4245: + " "
4246: + "is due on "
4247: + dueTime
4248: .toStringLocalFull()
4249: + ". ",
4250: /* type */rb
4251: .getString("deadl"),
4252: /* location */"",
4253: /* access */eAccess,
4254: /* groups */eGroups,
4255: /* attachments */EntityManager
4256: .newReferenceList());
4257:
4258: aEdit
4259: .getProperties()
4260: .addProperty(
4261: NEW_ASSIGNMENT_DUE_DATE_SCHEDULED,
4262: Boolean.TRUE
4263: .toString());
4264: if (e != null) {
4265: aEdit
4266: .getProperties()
4267: .addProperty(
4268: ResourceProperties.PROP_ASSIGNMENT_DUEDATE_CALENDAR_EVENT_ID,
4269: e
4270: .getId());
4271: }
4272: } catch (IdUnusedException ee) {
4273: Log.warn("chef", ee
4274: .getMessage());
4275: } catch (PermissionException ee) {
4276: Log
4277: .warn(
4278: "chef",
4279: rb
4280: .getString("cannotfin1"));
4281: } catch (Exception ee) {
4282: Log.warn("chef", ee
4283: .getMessage());
4284: }
4285: // try-catch
4286:
4287: AssignmentService
4288: .commitEdit(aEdit);
4289: } catch (Exception ignore) {
4290: // ignore the exception
4291: Log
4292: .warn(
4293: "chef",
4294: rb
4295: .getString("cannotfin2")
4296: + ref);
4297: }
4298: } // if
4299: } // if
4300: }
4301:
4302: // the open date been announced
4303: if (checkAutoAnnounce
4304: .equalsIgnoreCase(Boolean.TRUE
4305: .toString())) {
4306: AnnouncementChannel channel = (AnnouncementChannel) state
4307: .getAttribute(ANNOUNCEMENT_CHANNEL);
4308: if (channel != null) {
4309: String openDateAnnounced = a
4310: .getProperties()
4311: .getProperty(
4312: NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED);
4313:
4314: // open date has been announced or title has been changed?
4315: boolean openDateMessageModified = false;
4316: if (openDateAnnounced != null
4317: && openDateAnnounced
4318: .equalsIgnoreCase(Boolean.TRUE
4319: .toString())) {
4320: if (oldOpenTime != null
4321: && (!oldOpenTime
4322: .toStringLocalFull()
4323: .equals(
4324: openTime
4325: .toStringLocalFull())) // open time changes
4326: || !aOldTitle.equals(title)) // assignment title changes
4327: {
4328: // need to change message
4329: openDateMessageModified = true;
4330: }
4331:
4332: }
4333:
4334: // add the open date to annoucement
4335: if (openDateAnnounced == null // no announcement yet
4336: || (openDateAnnounced != null
4337: && openDateAnnounced
4338: .equalsIgnoreCase(Boolean.TRUE
4339: .toString()) && openDateMessageModified)) // announced, but open date or announcement title changes
4340: {
4341: // announcement channel is in place
4342: try {
4343: AnnouncementMessageEdit message = channel
4344: .addAnnouncementMessage();
4345: AnnouncementMessageHeaderEdit header = message
4346: .getAnnouncementHeaderEdit();
4347: header
4348: .setDraft(/* draft */false);
4349: header
4350: .replaceAttachments(/* attachment */EntityManager
4351: .newReferenceList());
4352:
4353: if (openDateAnnounced == null) {
4354: // making new announcement
4355: header
4356: .setSubject(/* subject */rb
4357: .getString("assig6")
4358: + " "
4359: + title);
4360: message
4361: .setBody(/* body */rb
4362: .getString("opedat")
4363: + " "
4364: + FormattedText
4365: .convertPlaintextToFormattedText(title)
4366: + " is "
4367: + openTime
4368: .toStringLocalFull()
4369: + ". ");
4370: } else {
4371: // revised announcement
4372: header
4373: .setSubject(/* subject */rb
4374: .getString("assig5")
4375: + " "
4376: + title);
4377: message
4378: .setBody(/* body */rb
4379: .getString("newope")
4380: + " "
4381: + FormattedText
4382: .convertPlaintextToFormattedText(title)
4383: + " is "
4384: + openTime
4385: .toStringLocalFull()
4386: + ". ");
4387: }
4388:
4389: // group information
4390: if (a
4391: .getAccess()
4392: .equals(
4393: Assignment.AssignmentAccess.GROUPED)) {
4394: try {
4395: // get the group ids selected
4396: Collection groupRefs = a
4397: .getGroups();
4398:
4399: // make a collection of Group objects
4400: Collection groups = new Vector();
4401:
4402: //make a collection of Group objects from the collection of group ref strings
4403: Site site = SiteService
4404: .getSite((String) state
4405: .getAttribute(STATE_CONTEXT_STRING));
4406: for (Iterator iGroupRefs = groupRefs
4407: .iterator(); iGroupRefs
4408: .hasNext();) {
4409: String groupRef = (String) iGroupRefs
4410: .next();
4411: groups
4412: .add(site
4413: .getGroup(groupRef));
4414: }
4415:
4416: // set access
4417: header
4418: .setGroupAccess(groups);
4419: } catch (Exception exception) {
4420: // log
4421: Log
4422: .warn(
4423: "chef",
4424: exception
4425: .getMessage());
4426: }
4427: } else {
4428: // site announcement
4429: header.clearGroupAccess();
4430: }
4431:
4432: channel
4433: .commitMessage(
4434: message,
4435: NotificationService.NOTI_NONE);
4436:
4437: // commit related properties into Assignment object
4438: String ref = "";
4439: try {
4440: ref = a.getReference();
4441: AssignmentEdit aEdit = AssignmentService
4442: .editAssignment(ref);
4443: aEdit
4444: .getPropertiesEdit()
4445: .addProperty(
4446: NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED,
4447: Boolean.TRUE
4448: .toString());
4449: if (message != null) {
4450: aEdit
4451: .getPropertiesEdit()
4452: .addProperty(
4453: ResourceProperties.PROP_ASSIGNMENT_OPENDATE_ANNOUNCEMENT_MESSAGE_ID,
4454: message
4455: .getId());
4456: }
4457: AssignmentService
4458: .commitEdit(aEdit);
4459: } catch (Exception ignore) {
4460: // ignore the exception
4461: Log
4462: .warn(
4463: "chef",
4464: rb
4465: .getString("cannotfin2")
4466: + ref);
4467: }
4468:
4469: } catch (PermissionException ee) {
4470: Log
4471: .warn(
4472: "chef",
4473: rb
4474: .getString("cannotmak"));
4475: }
4476: }
4477: }
4478: } // if
4479:
4480: // integrate with Gradebook
4481: String aReference = a.getReference();
4482: String addUpdateRemoveAssignment = "remove";
4483: if (!addtoGradebook
4484: .equals(GRADEBOOK_INTEGRATION_NO)) {
4485: // if integrate with Gradebook
4486: if (!AssignmentService
4487: .getAllowGroupAssignmentsInGradebook()
4488: && (range.equals("groups"))) {
4489: // if grouped assignment is not allowed to add into Gradebook
4490: addAlert(
4491: state,
4492: rb
4493: .getString("java.alert.noGroupedAssignmentIntoGB"));
4494: String ref = "";
4495: try {
4496: ref = a.getReference();
4497: AssignmentEdit aEdit = AssignmentService
4498: .editAssignment(ref);
4499: aEdit
4500: .getPropertiesEdit()
4501: .removeProperty(
4502: NEW_ASSIGNMENT_ADD_TO_GRADEBOOK);
4503: aEdit
4504: .getPropertiesEdit()
4505: .removeProperty(
4506: NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT);
4507: AssignmentService.commitEdit(aEdit);
4508: } catch (Exception ignore) {
4509: // ignore the exception
4510: Log.warn("chef", rb
4511: .getString("cannotfin2")
4512: + ref);
4513: }
4514: integrateGradebook(state, aReference,
4515: associateGradebookAssignment,
4516: "remove", null, null, -1, null,
4517: null, null);
4518: } else {
4519: if (addtoGradebook
4520: .equals(GRADEBOOK_INTEGRATION_ADD)) {
4521: addUpdateRemoveAssignment = GRADEBOOK_INTEGRATION_ADD;
4522: } else if (addtoGradebook
4523: .equals(GRADEBOOK_INTEGRATION_ASSOCIATE)) {
4524: addUpdateRemoveAssignment = "update";
4525: }
4526:
4527: if (!addUpdateRemoveAssignment
4528: .equals("remove")
4529: && gradeType == 3) {
4530: try {
4531: integrateGradebook(
4532: state,
4533: aReference,
4534: associateGradebookAssignment,
4535: addUpdateRemoveAssignment,
4536: aOldTitle,
4537: title,
4538: Integer
4539: .parseInt(gradePoints),
4540: dueTime, null, null);
4541:
4542: // add all existing grades, if any, into Gradebook
4543: integrateGradebook(
4544: state,
4545: aReference,
4546: associateGradebookAssignment,
4547: null, null, null, -1,
4548: null, null, "update");
4549:
4550: // if the assignment has been assoicated with a different entry in gradebook before, remove those grades from the entry in Gradebook
4551: if (StringUtil
4552: .trimToNull(oAssociateGradebookAssignment) != null
4553: && !oAssociateGradebookAssignment
4554: .equals(associateGradebookAssignment)) {
4555: integrateGradebook(
4556: state,
4557: aReference,
4558: oAssociateGradebookAssignment,
4559: null, null, null,
4560: -1, null, null,
4561: "remove");
4562:
4563: // if the old assoicated assignment entry in GB is an external one, but doesn't have anything assoicated with it in Assignment tool, remove it
4564: boolean gradebookExists = isGradebookDefined();
4565: if (gradebookExists) {
4566: GradebookService g = (GradebookService) (org.sakaiproject.service.gradebook.shared.GradebookService) ComponentManager
4567: .get("org.sakaiproject.service.gradebook.GradebookService");
4568: String gradebookUid = ToolManager
4569: .getInstance()
4570: .getCurrentPlacement()
4571: .getContext();
4572: boolean isExternalAssignmentDefined = g
4573: .isExternalAssignmentDefined(
4574: gradebookUid,
4575: oAssociateGradebookAssignment);
4576: if (isExternalAssignmentDefined) {
4577: // iterate through all assignments currently in the site, see if any is associated with this GB entry
4578: Iterator i = AssignmentService
4579: .getAssignmentsForContext(siteId);
4580: boolean found = false;
4581: while (!found
4582: && i
4583: .hasNext()) {
4584: Assignment aI = (Assignment) i
4585: .next();
4586: String gbEntry = aI
4587: .getProperties()
4588: .getProperty(
4589: NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT);
4590: if (gbEntry != null
4591: && gbEntry
4592: .equals(oAssociateGradebookAssignment)) {
4593: found = true;
4594: }
4595: }
4596: // so if none of the assignment in this site is associated with the entry, remove the entry
4597: if (!found) {
4598: g
4599: .removeExternalAssessment(
4600: gradebookUid,
4601: oAssociateGradebookAssignment);
4602: }
4603: }
4604: }
4605: }
4606: } catch (NumberFormatException nE) {
4607: alertInvalidPoint(state,
4608: gradePoints);
4609: }
4610: } else {
4611: integrateGradebook(
4612: state,
4613: aReference,
4614: associateGradebookAssignment,
4615: "remove", null, null, -1,
4616: null, null, null);
4617: }
4618: }
4619: } else {
4620: // remove assignment entry from Gradebook
4621: integrateGradebook(state, aReference,
4622: oAssociateGradebookAssignment,
4623: "remove", null, null, -1, null,
4624: null, "remove");
4625: }
4626: } // if post
4627:
4628: } // if
4629:
4630: } // if
4631:
4632: } // if
4633:
4634: } // doPost_assignment
4635:
4636: /**
4637: * Action is to post new assignment
4638: */
4639: public void doSave_assignment(RunData data) {
4640: postOrSaveAssignment(data, "save");
4641:
4642: } // doSave_assignment
4643:
4644: /**
4645: * Action is to preview the selected assignment
4646: */
4647: public void doPreview_assignment(RunData data) {
4648: SessionState state = ((JetspeedRunData) data)
4649: .getPortletSessionState(((JetspeedRunData) data)
4650: .getJs_peid());
4651:
4652: setNewAssignmentParameters(data, false);
4653:
4654: String assignmentId = data.getParameters().getString(
4655: "assignmentId");
4656: state.setAttribute(PREVIEW_ASSIGNMENT_ASSIGNMENT_ID,
4657: assignmentId);
4658:
4659: String assignmentContentId = data.getParameters().getString(
4660: "assignmentContentId");
4661: state.setAttribute(PREVIEW_ASSIGNMENT_ASSIGNMENTCONTENT_ID,
4662: assignmentContentId);
4663:
4664: state.setAttribute(PREVIEW_ASSIGNMENT_ASSIGNMENT_HIDE_FLAG,
4665: new Boolean(false));
4666: state.setAttribute(PREVIEW_ASSIGNMENT_STUDENT_VIEW_HIDE_FLAG,
4667: new Boolean(true));
4668: if (state.getAttribute(STATE_MESSAGE) == null) {
4669: state.setAttribute(STATE_MODE,
4670: MODE_INSTRUCTOR_PREVIEW_ASSIGNMENT);
4671: }
4672:
4673: } // doPreview_assignment
4674:
4675: /**
4676: * Action is to view the selected assignment
4677: */
4678: public void doView_assignment(RunData data) {
4679: SessionState state = ((JetspeedRunData) data)
4680: .getPortletSessionState(((JetspeedRunData) data)
4681: .getJs_peid());
4682: ParameterParser params = data.getParameters();
4683:
4684: // show the assignment portion
4685: state.setAttribute(VIEW_ASSIGNMENT_HIDE_ASSIGNMENT_FLAG,
4686: new Boolean(false));
4687: // show the student view portion
4688: state.setAttribute(VIEW_ASSIGNMENT_HIDE_STUDENT_VIEW_FLAG,
4689: new Boolean(true));
4690:
4691: String assignmentId = params.getString("assignmentId");
4692: state.setAttribute(VIEW_ASSIGNMENT_ID, assignmentId);
4693:
4694: try {
4695: Assignment a = AssignmentService
4696: .getAssignment(assignmentId);
4697: EventTrackingService.post(EventTrackingService.newEvent(
4698: AssignmentService.SECURE_ACCESS_ASSIGNMENT, a
4699: .getReference(), false));
4700: } catch (IdUnusedException e) {
4701: addAlert(state, rb.getString("cannotfin3"));
4702: } catch (PermissionException e) {
4703: addAlert(state, rb.getString("youarenot14"));
4704: }
4705:
4706: if (state.getAttribute(STATE_MESSAGE) == null) {
4707: state.setAttribute(STATE_MODE,
4708: MODE_INSTRUCTOR_VIEW_ASSIGNMENT);
4709: }
4710:
4711: } // doView_Assignment
4712:
4713: /**
4714: * Action is for student to view one assignment content
4715: */
4716: public void doView_assignment_as_student(RunData data) {
4717: SessionState state = ((JetspeedRunData) data)
4718: .getPortletSessionState(((JetspeedRunData) data)
4719: .getJs_peid());
4720: ParameterParser params = data.getParameters();
4721:
4722: String assignmentId = params.getString("assignmentId");
4723: state.setAttribute(VIEW_ASSIGNMENT_ID, assignmentId);
4724:
4725: if (state.getAttribute(STATE_MESSAGE) == null) {
4726: state
4727: .setAttribute(STATE_MODE,
4728: MODE_STUDENT_VIEW_ASSIGNMENT);
4729: }
4730:
4731: } // doView_assignment_as_student
4732:
4733: /**
4734: * Action is to show the edit assignment screen
4735: */
4736: public void doEdit_assignment(RunData data) {
4737: SessionState state = ((JetspeedRunData) data)
4738: .getPortletSessionState(((JetspeedRunData) data)
4739: .getJs_peid());
4740: ParameterParser params = data.getParameters();
4741:
4742: String assignmentId = StringUtil.trimToNull(params
4743: .getString("assignmentId"));
4744: // whether the user can modify the assignment
4745: state.setAttribute(EDIT_ASSIGNMENT_ID, assignmentId);
4746:
4747: try {
4748: Assignment a = AssignmentService
4749: .getAssignment(assignmentId);
4750: Iterator submissions = AssignmentService.getSubmissions(a);
4751: if (submissions.hasNext()) {
4752: boolean anySubmitted = false;
4753: for (; submissions.hasNext() && !anySubmitted;) {
4754: AssignmentSubmission s = (AssignmentSubmission) submissions
4755: .next();
4756: if (s.getSubmitted()) {
4757: anySubmitted = true;
4758: }
4759: }
4760: if (anySubmitted) {
4761: // if there is any submitted submission to this assignment, show alert
4762: addAlert(state, rb.getString("assig1") + " "
4763: + a.getTitle() + " "
4764: + rb.getString("hassum"));
4765: } else {
4766: // otherwise, show alert about someone has started working on the assignment, not necessarily submitted
4767: addAlert(state, rb.getString("hasDraftSum"));
4768: }
4769: }
4770:
4771: // SECTION MOD
4772: state.setAttribute(STATE_SECTION_STRING, a.getSection());
4773:
4774: // put the names and values into vm file
4775: state.setAttribute(NEW_ASSIGNMENT_TITLE, a.getTitle());
4776: TimeBreakdown openTime = a.getOpenTime().breakdownLocal();
4777: state.setAttribute(NEW_ASSIGNMENT_OPENMONTH, new Integer(
4778: openTime.getMonth()));
4779: state.setAttribute(NEW_ASSIGNMENT_OPENDAY, new Integer(
4780: openTime.getDay()));
4781: state.setAttribute(NEW_ASSIGNMENT_OPENYEAR, new Integer(
4782: openTime.getYear()));
4783: int openHour = openTime.getHour();
4784: if (openHour >= 12) {
4785: state.setAttribute(NEW_ASSIGNMENT_OPENAMPM, "PM");
4786: } else {
4787: state.setAttribute(NEW_ASSIGNMENT_OPENAMPM, "AM");
4788: }
4789: if (openHour == 0) {
4790: // for midnight point, we mark it as 12AM
4791: openHour = 12;
4792: }
4793: state.setAttribute(NEW_ASSIGNMENT_OPENHOUR, new Integer(
4794: (openHour > 12) ? openHour - 12 : openHour));
4795: state.setAttribute(NEW_ASSIGNMENT_OPENMIN, new Integer(
4796: openTime.getMin()));
4797:
4798: TimeBreakdown dueTime = a.getDueTime().breakdownLocal();
4799: state.setAttribute(NEW_ASSIGNMENT_DUEMONTH, new Integer(
4800: dueTime.getMonth()));
4801: state.setAttribute(NEW_ASSIGNMENT_DUEDAY, new Integer(
4802: dueTime.getDay()));
4803: state.setAttribute(NEW_ASSIGNMENT_DUEYEAR, new Integer(
4804: dueTime.getYear()));
4805: int dueHour = dueTime.getHour();
4806: if (dueHour >= 12) {
4807: state.setAttribute(NEW_ASSIGNMENT_DUEAMPM, "PM");
4808: } else {
4809: state.setAttribute(NEW_ASSIGNMENT_DUEAMPM, "AM");
4810: }
4811: if (dueHour == 0) {
4812: // for midnight point, we mark it as 12AM
4813: dueHour = 12;
4814: }
4815: state.setAttribute(NEW_ASSIGNMENT_DUEHOUR, new Integer(
4816: (dueHour > 12) ? dueHour - 12 : dueHour));
4817: state.setAttribute(NEW_ASSIGNMENT_DUEMIN, new Integer(
4818: dueTime.getMin()));
4819: // generate alert when editing an assignment past due date
4820: if (a.getDueTime().before(TimeService.newTime())) {
4821: addAlert(state, rb.getString("youarenot17"));
4822: }
4823:
4824: if (a.getCloseTime() != null) {
4825: state.setAttribute(NEW_ASSIGNMENT_ENABLECLOSEDATE,
4826: new Boolean(true));
4827: TimeBreakdown closeTime = a.getCloseTime()
4828: .breakdownLocal();
4829: state.setAttribute(NEW_ASSIGNMENT_CLOSEMONTH,
4830: new Integer(closeTime.getMonth()));
4831: state.setAttribute(NEW_ASSIGNMENT_CLOSEDAY,
4832: new Integer(closeTime.getDay()));
4833: state.setAttribute(NEW_ASSIGNMENT_CLOSEYEAR,
4834: new Integer(closeTime.getYear()));
4835: int closeHour = closeTime.getHour();
4836: if (closeHour >= 12) {
4837: state.setAttribute(NEW_ASSIGNMENT_CLOSEAMPM, "PM");
4838: } else {
4839: state.setAttribute(NEW_ASSIGNMENT_CLOSEAMPM, "AM");
4840: }
4841: if (closeHour == 0) {
4842: // for the midnight point, we mark it as 12 AM
4843: closeHour = 12;
4844: }
4845: state.setAttribute(NEW_ASSIGNMENT_CLOSEHOUR,
4846: new Integer((closeHour > 12) ? closeHour - 12
4847: : closeHour));
4848: state.setAttribute(NEW_ASSIGNMENT_CLOSEMIN,
4849: new Integer(closeTime.getMin()));
4850: } else {
4851: state.setAttribute(NEW_ASSIGNMENT_ENABLECLOSEDATE,
4852: new Boolean(false));
4853: state.setAttribute(NEW_ASSIGNMENT_CLOSEMONTH, state
4854: .getAttribute(NEW_ASSIGNMENT_DUEMONTH));
4855: state.setAttribute(NEW_ASSIGNMENT_CLOSEDAY, state
4856: .getAttribute(NEW_ASSIGNMENT_DUEDAY));
4857: state.setAttribute(NEW_ASSIGNMENT_CLOSEYEAR, state
4858: .getAttribute(NEW_ASSIGNMENT_DUEYEAR));
4859: state.setAttribute(NEW_ASSIGNMENT_CLOSEHOUR, state
4860: .getAttribute(NEW_ASSIGNMENT_DUEHOUR));
4861: state.setAttribute(NEW_ASSIGNMENT_CLOSEMIN, state
4862: .getAttribute(NEW_ASSIGNMENT_DUEMIN));
4863: state.setAttribute(NEW_ASSIGNMENT_CLOSEAMPM, state
4864: .getAttribute(NEW_ASSIGNMENT_DUEAMPM));
4865: }
4866: state.setAttribute(NEW_ASSIGNMENT_SECTION, a.getSection());
4867:
4868: state.setAttribute(NEW_ASSIGNMENT_SUBMISSION_TYPE,
4869: new Integer(a.getContent().getTypeOfSubmission()));
4870: int typeOfGrade = a.getContent().getTypeOfGrade();
4871: state.setAttribute(NEW_ASSIGNMENT_GRADE_TYPE, new Integer(
4872: typeOfGrade));
4873: if (typeOfGrade == 3) {
4874: state.setAttribute(NEW_ASSIGNMENT_GRADE_POINTS, a
4875: .getContent().getMaxGradePointDisplay());
4876: }
4877: state.setAttribute(NEW_ASSIGNMENT_DESCRIPTION, a
4878: .getContent().getInstructions());
4879: state
4880: .setAttribute(
4881: ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE,
4882: a
4883: .getProperties()
4884: .getProperty(
4885: ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE));
4886: state
4887: .setAttribute(
4888: ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE,
4889: a
4890: .getProperties()
4891: .getProperty(
4892: ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE));
4893: state.setAttribute(NEW_ASSIGNMENT_CHECK_ADD_HONOR_PLEDGE,
4894: Integer.toString(a.getContent().getHonorPledge()));
4895: state.setAttribute(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK, a
4896: .getProperties().getProperty(
4897: NEW_ASSIGNMENT_ADD_TO_GRADEBOOK));
4898: state
4899: .setAttribute(
4900: NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT,
4901: a
4902: .getProperties()
4903: .getProperty(
4904: NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT));
4905: state.setAttribute(ATTACHMENTS, a.getContent()
4906: .getAttachments());
4907:
4908: // group setting
4909: if (a.getAccess().equals(Assignment.AssignmentAccess.SITE)) {
4910: state.setAttribute(NEW_ASSIGNMENT_RANGE, "site");
4911: } else {
4912: state.setAttribute(NEW_ASSIGNMENT_RANGE, "groups");
4913: }
4914:
4915: state.setAttribute(NEW_ASSIGNMENT_GROUPS, a.getGroups());
4916: } catch (IdUnusedException e) {
4917: addAlert(state, rb.getString("cannotfin3"));
4918: } catch (PermissionException e) {
4919: addAlert(state, rb.getString("youarenot14"));
4920: }
4921:
4922: state.setAttribute(STATE_MODE,
4923: MODE_INSTRUCTOR_NEW_EDIT_ASSIGNMENT);
4924:
4925: } // doEdit_Assignment
4926:
4927: /**
4928: * Action is to show the delete assigment confirmation screen
4929: */
4930: public void doDelete_confirm_assignment(RunData data) {
4931: SessionState state = ((JetspeedRunData) data)
4932: .getPortletSessionState(((JetspeedRunData) data)
4933: .getJs_peid());
4934: ParameterParser params = data.getParameters();
4935:
4936: String[] assignmentIds = params
4937: .getStrings("selectedAssignments");
4938:
4939: if (assignmentIds != null) {
4940: Vector ids = new Vector();
4941: for (int i = 0; i < assignmentIds.length; i++) {
4942: String id = (String) assignmentIds[i];
4943: if (!AssignmentService.allowRemoveAssignment(id)) {
4944: addAlert(state, rb.getString("youarenot9") + " "
4945: + id + ". ");
4946: }
4947: ids.add(id);
4948: }
4949:
4950: if (state.getAttribute(STATE_MESSAGE) == null) {
4951: // can remove all the selected assignments
4952: state.setAttribute(DELETE_ASSIGNMENT_IDS, ids);
4953: state.setAttribute(STATE_MODE,
4954: MODE_INSTRUCTOR_DELETE_ASSIGNMENT);
4955: }
4956: } else {
4957: addAlert(state, rb.getString("youmust6"));
4958: }
4959:
4960: } // doDelete_confirm_Assignment
4961:
4962: /**
4963: * Action is to delete the confirmed assignments
4964: */
4965: public void doDelete_assignment(RunData data) {
4966: SessionState state = ((JetspeedRunData) data)
4967: .getPortletSessionState(((JetspeedRunData) data)
4968: .getJs_peid());
4969:
4970: // get the delete assignment ids
4971: Vector ids = (Vector) state.getAttribute(DELETE_ASSIGNMENT_IDS);
4972: for (int i = 0; i < ids.size(); i++) {
4973:
4974: String assignmentId = (String) ids.get(i);
4975: try {
4976: AssignmentEdit aEdit = AssignmentService
4977: .editAssignment(assignmentId);
4978:
4979: ResourcePropertiesEdit pEdit = aEdit
4980: .getPropertiesEdit();
4981:
4982: String associateGradebookAssignment = pEdit
4983: .getProperty(NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT);
4984:
4985: String title = aEdit.getTitle();
4986:
4987: // remove releted event if there is one
4988: String isThereEvent = pEdit
4989: .getProperty(NEW_ASSIGNMENT_DUE_DATE_SCHEDULED);
4990: if (isThereEvent != null
4991: && isThereEvent.equals(Boolean.TRUE.toString())) {
4992: // remove the associated calender event
4993: Calendar c = (Calendar) state
4994: .getAttribute(CALENDAR);
4995: if (c != null) {
4996: // already has calendar object
4997: // get the old event
4998: CalendarEvent e = null;
4999: boolean found = false;
5000: String oldEventId = pEdit
5001: .getProperty(ResourceProperties.PROP_ASSIGNMENT_DUEDATE_CALENDAR_EVENT_ID);
5002: if (oldEventId != null) {
5003: try {
5004: e = c.getEvent(oldEventId);
5005: found = true;
5006: } catch (IdUnusedException ee) {
5007: // no action needed for this condition
5008: } catch (PermissionException ee) {
5009: }
5010: } else {
5011: TimeBreakdown b = aEdit.getDueTime()
5012: .breakdownLocal();
5013: // TODO: check- this was new Time(year...), not local! -ggolden
5014: Time startTime = TimeService.newTimeLocal(b
5015: .getYear(), b.getMonth(), b
5016: .getDay(), 0, 0, 0, 0);
5017: Time endTime = TimeService.newTimeLocal(b
5018: .getYear(), b.getMonth(), b
5019: .getDay(), 23, 59, 59, 999);
5020: Iterator events = c.getEvents(
5021: TimeService.newTimeRange(startTime,
5022: endTime), null).iterator();
5023: while ((!found) && (events.hasNext())) {
5024: e = (CalendarEvent) events.next();
5025: if (((String) e.getDisplayName())
5026: .indexOf(rb.getString("assig1")
5027: + " " + title) != -1) {
5028: found = true;
5029: }
5030: }
5031: }
5032: // remove the founded old event
5033: if (found) {
5034: // found the old event delete it
5035: try {
5036: c
5037: .removeEvent(c
5038: .getEditEvent(
5039: e.getId(),
5040: CalendarService.EVENT_REMOVE_CALENDAR));
5041: pEdit
5042: .removeProperty(NEW_ASSIGNMENT_DUE_DATE_SCHEDULED);
5043: pEdit
5044: .removeProperty(ResourceProperties.PROP_ASSIGNMENT_DUEDATE_CALENDAR_EVENT_ID);
5045: } catch (PermissionException ee) {
5046: Log.warn("chef", rb
5047: .getString("cannotrem")
5048: + " " + title + ". ");
5049: } catch (InUseException ee) {
5050: Log.warn("chef", rb
5051: .getString("somelsis")
5052: + " " + rb.getString("calen"));
5053: } catch (IdUnusedException ee) {
5054: Log.warn("chef", rb
5055: .getString("cannotfin6")
5056: + e.getId());
5057: }
5058: }
5059: }
5060: } // if-else
5061:
5062: if (!AssignmentService.getSubmissions(aEdit).hasNext()) {
5063: // there is no submission to this assignment yet, delete the assignment record completely
5064: try {
5065: AssignmentService.removeAssignment(aEdit);
5066: } catch (PermissionException e) {
5067: addAlert(state, rb.getString("youarenot11")
5068: + " " + aEdit.getTitle() + ". ");
5069: }
5070: } else {
5071: // remove the assignment by marking the remove status property true
5072: pEdit.addProperty(
5073: ResourceProperties.PROP_ASSIGNMENT_DELETED,
5074: Boolean.TRUE.toString());
5075:
5076: AssignmentService.commitEdit(aEdit);
5077: }
5078:
5079: // remove from Gradebook
5080: integrateGradebook(state, (String) ids.get(i),
5081: associateGradebookAssignment, "remove", null,
5082: null, -1, null, null, null);
5083: } catch (InUseException e) {
5084: addAlert(state, rb.getString("somelsis") + " "
5085: + rb.getString("assig2"));
5086: } catch (IdUnusedException e) {
5087: addAlert(state, rb.getString("cannotfin3"));
5088: } catch (PermissionException e) {
5089: addAlert(state, rb.getString("youarenot6"));
5090: }
5091: } // for
5092:
5093: if (state.getAttribute(STATE_MESSAGE) == null) {
5094: state.setAttribute(DELETE_ASSIGNMENT_IDS, new Vector());
5095:
5096: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
5097: }
5098:
5099: } // doDelete_Assignment
5100:
5101: /**
5102: * Action is to delete the assignment and also the related AssignmentSubmission
5103: */
5104: public void doDeep_delete_assignment(RunData data) {
5105: SessionState state = ((JetspeedRunData) data)
5106: .getPortletSessionState(((JetspeedRunData) data)
5107: .getJs_peid());
5108:
5109: // get the delete assignment ids
5110: Vector ids = (Vector) state.getAttribute(DELETE_ASSIGNMENT_IDS);
5111: for (int i = 0; i < ids.size(); i++) {
5112: String currentId = (String) ids.get(i);
5113: try {
5114: AssignmentEdit a = AssignmentService
5115: .editAssignment(currentId);
5116: try {
5117: AssignmentService.removeAssignment(a);
5118: } catch (PermissionException e) {
5119: addAlert(state, rb.getString("youarenot11") + " "
5120: + a.getTitle() + ". ");
5121: }
5122: } catch (IdUnusedException e) {
5123: addAlert(state, rb.getString("cannotfin3"));
5124: } catch (PermissionException e) {
5125: addAlert(state, rb.getString("youarenot14"));
5126: } catch (InUseException e) {
5127: addAlert(state, rb.getString("somelsis") + " "
5128: + rb.getString("assig2"));
5129: }
5130: }
5131: if (state.getAttribute(STATE_MESSAGE) == null) {
5132: state.setAttribute(DELETE_ASSIGNMENT_IDS, new Vector());
5133: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
5134: }
5135:
5136: } // doDeep_delete_Assignment
5137:
5138: /**
5139: * Action is to show the duplicate assignment screen
5140: */
5141: public void doDuplicate_assignment(RunData data) {
5142: SessionState state = ((JetspeedRunData) data)
5143: .getPortletSessionState(((JetspeedRunData) data)
5144: .getJs_peid());
5145:
5146: // we are changing the view, so start with first page again.
5147: resetPaging(state);
5148:
5149: String contextString = (String) state
5150: .getAttribute(STATE_CONTEXT_STRING);
5151: ParameterParser params = data.getParameters();
5152: String assignmentId = StringUtil.trimToNull(params
5153: .getString("assignmentId"));
5154:
5155: if (assignmentId != null) {
5156: try {
5157: AssignmentEdit aEdit = AssignmentService
5158: .addDuplicateAssignment(contextString,
5159: assignmentId);
5160:
5161: // clean the duplicate's property
5162: ResourcePropertiesEdit aPropertiesEdit = aEdit
5163: .getPropertiesEdit();
5164: aPropertiesEdit
5165: .removeProperty(NEW_ASSIGNMENT_DUE_DATE_SCHEDULED);
5166: aPropertiesEdit
5167: .removeProperty(ResourceProperties.PROP_ASSIGNMENT_DUEDATE_CALENDAR_EVENT_ID);
5168: aPropertiesEdit
5169: .removeProperty(NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED);
5170: aPropertiesEdit
5171: .removeProperty(ResourceProperties.PROP_ASSIGNMENT_OPENDATE_ANNOUNCEMENT_MESSAGE_ID);
5172:
5173: AssignmentService.commitEdit(aEdit);
5174: } catch (PermissionException e) {
5175: addAlert(state, rb.getString("youarenot5"));
5176: } catch (IdInvalidException e) {
5177: addAlert(state, rb.getString("theassiid") + " "
5178: + assignmentId + " " + rb.getString("isnotval"));
5179: } catch (IdUnusedException e) {
5180: addAlert(state, rb.getString("theassiid") + " "
5181: + assignmentId + " "
5182: + rb.getString("hasnotbee"));
5183: } catch (Exception e) {
5184: }
5185:
5186: }
5187:
5188: } // doDuplicate_Assignment
5189:
5190: /**
5191: * Action is to show the grade submission screen
5192: */
5193: public void doGrade_submission(RunData data) {
5194: SessionState state = ((JetspeedRunData) data)
5195: .getPortletSessionState(((JetspeedRunData) data)
5196: .getJs_peid());
5197:
5198: // reset the submission context
5199: resetViewSubmission(state);
5200:
5201: ParameterParser params = data.getParameters();
5202:
5203: // reset the grade assignment id
5204: state.setAttribute(GRADE_SUBMISSION_ASSIGNMENT_ID, params
5205: .getString("assignmentId"));
5206: state.setAttribute(GRADE_SUBMISSION_SUBMISSION_ID, params
5207: .getString("submissionId"));
5208:
5209: try {
5210: AssignmentSubmission s = AssignmentService
5211: .getSubmission((String) state
5212: .getAttribute(GRADE_SUBMISSION_SUBMISSION_ID));
5213:
5214: if ((s.getFeedbackText() != null)
5215: && (s.getFeedbackText().length() == 0)) {
5216: state.setAttribute(GRADE_SUBMISSION_FEEDBACK_TEXT, s
5217: .getSubmittedText());
5218: } else {
5219: state.setAttribute(GRADE_SUBMISSION_FEEDBACK_TEXT, s
5220: .getFeedbackText());
5221: }
5222: state.setAttribute(GRADE_SUBMISSION_FEEDBACK_COMMENT, s
5223: .getFeedbackComment());
5224:
5225: List v = EntityManager.newReferenceList();
5226: Iterator attachments = s.getFeedbackAttachments()
5227: .iterator();
5228: while (attachments.hasNext()) {
5229: v.add(attachments.next());
5230: }
5231: state.setAttribute(ATTACHMENTS, v);
5232:
5233: state.setAttribute(GRADE_SUBMISSION_GRADE, s.getGrade());
5234: } catch (IdUnusedException e) {
5235: addAlert(state, rb.getString("cannotfin5"));
5236: } catch (PermissionException e) {
5237: addAlert(state,
5238: "You are not allowed to view the assignment submission. ");
5239: }
5240:
5241: if (state.getAttribute(STATE_MESSAGE) == null) {
5242: state.setAttribute(GRADE_SUBMISSION_ASSIGNMENT_EXPAND_FLAG,
5243: new Boolean(false));
5244: state.setAttribute(STATE_MODE,
5245: MODE_INSTRUCTOR_GRADE_SUBMISSION);
5246: }
5247:
5248: } // doGrade_submission
5249:
5250: /**
5251: * Action is to release all the grades of the submission
5252: */
5253: public void doRelease_grades(RunData data) {
5254: SessionState state = ((JetspeedRunData) data)
5255: .getPortletSessionState(((JetspeedRunData) data)
5256: .getJs_peid());
5257:
5258: ParameterParser params = data.getParameters();
5259:
5260: try {
5261: // get the assignment
5262: Assignment a = AssignmentService.getAssignment(params
5263: .getString("assignmentId"));
5264:
5265: String aReference = a.getReference();
5266:
5267: Iterator submissions = AssignmentService.getSubmissions(a);
5268: while (submissions.hasNext()) {
5269: AssignmentSubmission s = (AssignmentSubmission) submissions
5270: .next();
5271: AssignmentSubmissionEdit sEdit = AssignmentService
5272: .editSubmission(s.getReference());
5273: String grade = s.getGrade();
5274: if (s.getGraded()) {
5275: boolean withGrade = state.getAttribute(WITH_GRADES) != null ? ((Boolean) state
5276: .getAttribute(WITH_GRADES)).booleanValue()
5277: : false;
5278: if (withGrade) {
5279: // for the assignment tool with grade option, a valide grade is needed
5280: if (grade != null && !grade.equals("")) {
5281: sEdit.setGradeReleased(true);
5282: }
5283: } else {
5284: // for the assignment tool without grade option, no grade is needed
5285: sEdit.setGradeReleased(true);
5286: }
5287: }
5288:
5289: // also set the return status
5290: sEdit.setReturned(true);
5291: sEdit.setTimeReturned(TimeService.newTime());
5292: sEdit.setHonorPledgeFlag(Boolean.FALSE.booleanValue());
5293:
5294: AssignmentService.commitEdit(sEdit);
5295: } // while
5296:
5297: // add grades into Gradebook
5298: String integrateWithGradebook = a.getProperties()
5299: .getProperty(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK);
5300: if (integrateWithGradebook != null
5301: && !integrateWithGradebook
5302: .equals(GRADEBOOK_INTEGRATION_NO)) {
5303: // integrate with Gradebook
5304: String associateGradebookAssignment = StringUtil
5305: .trimToNull(a
5306: .getProperties()
5307: .getProperty(
5308: NEW_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT));
5309:
5310: integrateGradebook(state, aReference,
5311: associateGradebookAssignment, null, null, null,
5312: -1, null, null, "update");
5313: }
5314: } catch (IdUnusedException e) {
5315: addAlert(state, rb.getString("cannotfin3"));
5316: } catch (PermissionException e) {
5317: addAlert(state, rb.getString("youarenot14"));
5318: } catch (InUseException e) {
5319: addAlert(state, rb.getString("somelsis") + " "
5320: + rb.getString("submiss"));
5321: }
5322:
5323: } // doRelease_grades
5324:
5325: /**
5326: * Action is to show the assignment in grading page
5327: */
5328: public void doExpand_grade_assignment(RunData data) {
5329: SessionState state = ((JetspeedRunData) data)
5330: .getPortletSessionState(((JetspeedRunData) data)
5331: .getJs_peid());
5332: state.setAttribute(GRADE_ASSIGNMENT_EXPAND_FLAG, new Boolean(
5333: true));
5334:
5335: } // doExpand_grade_assignment
5336:
5337: /**
5338: * Action is to hide the assignment in grading page
5339: */
5340: public void doCollapse_grade_assignment(RunData data) {
5341: SessionState state = ((JetspeedRunData) data)
5342: .getPortletSessionState(((JetspeedRunData) data)
5343: .getJs_peid());
5344: state.setAttribute(GRADE_ASSIGNMENT_EXPAND_FLAG, new Boolean(
5345: false));
5346:
5347: } // doCollapse_grade_assignment
5348:
5349: /**
5350: * Action is to show the submissions in grading page
5351: */
5352: public void doExpand_grade_submission(RunData data) {
5353: SessionState state = ((JetspeedRunData) data)
5354: .getPortletSessionState(((JetspeedRunData) data)
5355: .getJs_peid());
5356: state.setAttribute(GRADE_SUBMISSION_EXPAND_FLAG, new Boolean(
5357: true));
5358:
5359: } // doExpand_grade_submission
5360:
5361: /**
5362: * Action is to hide the submissions in grading page
5363: */
5364: public void doCollapse_grade_submission(RunData data) {
5365: SessionState state = ((JetspeedRunData) data)
5366: .getPortletSessionState(((JetspeedRunData) data)
5367: .getJs_peid());
5368: state.setAttribute(GRADE_SUBMISSION_EXPAND_FLAG, new Boolean(
5369: false));
5370:
5371: } // doCollapse_grade_submission
5372:
5373: /**
5374: * Action is to show the grade assignment
5375: */
5376: public void doGrade_assignment(RunData data) {
5377: SessionState state = ((JetspeedRunData) data)
5378: .getPortletSessionState(((JetspeedRunData) data)
5379: .getJs_peid());
5380: ParameterParser params = data.getParameters();
5381:
5382: // reset the export assignment id
5383: state.setAttribute(EXPORT_ASSIGNMENT_REF, "");
5384:
5385: String assignmentId = StringUtil.trimToNull(params
5386: .getString("assignmentId"));
5387: if (assignmentId != null) {
5388: // get the assignment id
5389: state.setAttribute(EXPORT_ASSIGNMENT_REF, assignmentId);
5390: try {
5391: Assignment a = AssignmentService
5392: .getAssignment(assignmentId);
5393: state.setAttribute(EXPORT_ASSIGNMENT_ID, a.getId());
5394: state.setAttribute(STATE_MODE,
5395: MODE_INSTRUCTOR_GRADE_ASSIGNMENT);
5396:
5397: // we are changing the view, so start with first page again.
5398: resetPaging(state);
5399: } catch (IdUnusedException e) {
5400: addAlert(state, rb.getString("theisno"));
5401: } catch (PermissionException e) {
5402: addAlert(state, rb.getString("youarenot14"));
5403: }
5404: }
5405:
5406: } // doGrade_Assignment
5407:
5408: /**
5409: * Action is to show the grade assignment
5410: */
5411: public void doGrade_assignment_from(RunData data) {
5412: SessionState state = ((JetspeedRunData) data)
5413: .getPortletSessionState(((JetspeedRunData) data)
5414: .getJs_peid());
5415: ParameterParser params = data.getParameters();
5416:
5417: state.setAttribute(EXPORT_ASSIGNMENT_REF, params
5418: .getString("assignmentId"));
5419:
5420: try {
5421: Assignment a = AssignmentService
5422: .getAssignment((String) state
5423: .getAttribute(EXPORT_ASSIGNMENT_REF));
5424: state.setAttribute(EXPORT_ASSIGNMENT_ID, a.getId());
5425: state.setAttribute(GRADE_ASSIGNMENT_EXPAND_FLAG,
5426: new Boolean(false));
5427: state.setAttribute(GRADE_SUBMISSION_EXPAND_FLAG,
5428: new Boolean(true));
5429: state.setAttribute(STATE_MODE,
5430: MODE_INSTRUCTOR_GRADE_ASSIGNMENT);
5431:
5432: // we are changing the view, so start with first page again.
5433: resetPaging(state);
5434: } catch (IdUnusedException e) {
5435: addAlert(state, rb.getString("cannotfin3"));
5436: } catch (PermissionException e) {
5437: addAlert(state, rb.getString("youarenot14"));
5438: }
5439: } // doGrade_assignment_from
5440:
5441: /**
5442: * Action is to show the View Students assignment screen
5443: */
5444: public void doView_students_assignment(RunData data) {
5445: SessionState state = ((JetspeedRunData) data)
5446: .getPortletSessionState(((JetspeedRunData) data)
5447: .getJs_peid());
5448: state.setAttribute(STATE_MODE,
5449: MODE_INSTRUCTOR_VIEW_STUDENTS_ASSIGNMENT);
5450:
5451: } // doView_students_Assignment
5452:
5453: /**
5454: * Action is to show the student submissions
5455: */
5456: public void doShow_student_submission(RunData data) {
5457: SessionState state = ((JetspeedRunData) data)
5458: .getPortletSessionState(((JetspeedRunData) data)
5459: .getJs_peid());
5460: Hashtable t = (Hashtable) state
5461: .getAttribute(STUDENT_LIST_SHOW_TABLE);
5462: ParameterParser params = data.getParameters();
5463:
5464: String id = params.getString("studentId");
5465: // add the student id into the table
5466: t.put(id, "show");
5467:
5468: state.setAttribute(STUDENT_LIST_SHOW_TABLE, t);
5469:
5470: } // doShow_student_submission
5471:
5472: /**
5473: * Action is to hide the student submissions
5474: */
5475: public void doHide_student_submission(RunData data) {
5476: SessionState state = ((JetspeedRunData) data)
5477: .getPortletSessionState(((JetspeedRunData) data)
5478: .getJs_peid());
5479: Hashtable t = (Hashtable) state
5480: .getAttribute(STUDENT_LIST_SHOW_TABLE);
5481: ParameterParser params = data.getParameters();
5482:
5483: String id = params.getString("studentId");
5484: // remove the student id from the table
5485: t.remove(id);
5486:
5487: state.setAttribute(STUDENT_LIST_SHOW_TABLE, t);
5488:
5489: } // doHide_student_submission
5490:
5491: /**
5492: * Action is to show the graded assignment submission
5493: */
5494: public void doView_grade(RunData data) {
5495: SessionState state = ((JetspeedRunData) data)
5496: .getPortletSessionState(((JetspeedRunData) data)
5497: .getJs_peid());
5498:
5499: ParameterParser params = data.getParameters();
5500:
5501: state.setAttribute(VIEW_GRADE_SUBMISSION_ID, params
5502: .getString("submissionId"));
5503:
5504: state.setAttribute(STATE_MODE, MODE_STUDENT_VIEW_GRADE);
5505:
5506: } // doView_grade
5507:
5508: /**
5509: * Action is to show the student submissions
5510: */
5511: public void doReport_submissions(RunData data) {
5512: SessionState state = ((JetspeedRunData) data)
5513: .getPortletSessionState(((JetspeedRunData) data)
5514: .getJs_peid());
5515:
5516: state.setAttribute(STATE_MODE,
5517: MODE_INSTRUCTOR_REPORT_SUBMISSIONS);
5518: state.setAttribute(SORTED_BY, SORTED_SUBMISSION_BY_LASTNAME);
5519: state.setAttribute(SORTED_ASC, Boolean.TRUE.toString());
5520:
5521: } // doReport_submissions
5522:
5523: /**
5524: *
5525: *
5526: */
5527: public void doAssignment_form(RunData data) {
5528: ParameterParser params = data.getParameters();
5529:
5530: String option = (String) params.getString("option");
5531: if (option != null) {
5532: if (option.equals("post")) {
5533: // post assignment
5534: doPost_assignment(data);
5535: } else if (option.equals("save")) {
5536: // save assignment
5537: doSave_assignment(data);
5538: } else if (option.equals("preview")) {
5539: // preview assignment
5540: doPreview_assignment(data);
5541: } else if (option.equals("cancel")) {
5542: // cancel creating assignment
5543: doCancel_new_assignment(data);
5544: } else if (option.equals("canceledit")) {
5545: // cancel editing assignment
5546: doCancel_edit_assignment(data);
5547: } else if (option.equals("attach")) {
5548: // attachments
5549: doAttachments(data);
5550: } else if (option.equals("view")) {
5551: // view
5552: doView(data);
5553: } else if (option.equals("permissions")) {
5554: // permissions
5555: doPermissions(data);
5556: } else if (option.equals("returngrade")) {
5557: // return grading
5558: doReturn_grade_submission(data);
5559: } else if (option.equals("savegrade")) {
5560: // save grading
5561: doSave_grade_submission(data);
5562: } else if (option.equals("previewgrade")) {
5563: // preview grading
5564: doPreview_grade_submission(data);
5565: } else if (option.equals("cancelgrade")) {
5566: // cancel grading
5567: doCancel_grade_submission(data);
5568: } else if (option.equals("sortbygrouptitle")) {
5569: // read input data
5570: setNewAssignmentParameters(data, true);
5571:
5572: // sort by group title
5573: doSortbygrouptitle(data);
5574: } else if (option.equals("sortbygroupdescription")) {
5575: // read input data
5576: setNewAssignmentParameters(data, true);
5577:
5578: // sort group by description
5579: doSortbygroupdescription(data);
5580: } else if (option.equals("hide_instruction")) {
5581: // hide the assignment instruction
5582: doHide_submission_assignment_instruction(data);
5583: } else if (option.equals("show_instruction")) {
5584: // show the assignment instruction
5585: doShow_submission_assignment_instruction(data);
5586: } else if (option.equals("sortbygroupdescription")) {
5587: // show the assignment instruction
5588: doShow_submission_assignment_instruction(data);
5589: }
5590:
5591: }
5592: }
5593:
5594: /**
5595: * Action is to use when doAattchmentsadding requested, corresponding to chef_Assignments-new "eventSubmit_doAattchmentsadding" when "add attachments" is clicked
5596: */
5597: public void doAttachments(RunData data) {
5598: SessionState state = ((JetspeedRunData) data)
5599: .getPortletSessionState(((JetspeedRunData) data)
5600: .getJs_peid());
5601: ParameterParser params = data.getParameters();
5602:
5603: String mode = (String) state.getAttribute(STATE_MODE);
5604: if (mode.equals(MODE_STUDENT_VIEW_SUBMISSION)) {
5605: // retrieve the submission text (as formatted text)
5606: boolean checkForFormattingErrors = true; // the student is submitting something - so check for errors
5607: String text = processFormattedTextFromBrowser(state, params
5608: .getCleanString(VIEW_SUBMISSION_TEXT),
5609: checkForFormattingErrors);
5610:
5611: state.setAttribute(VIEW_SUBMISSION_TEXT, text);
5612: if (params.getString(VIEW_SUBMISSION_HONOR_PLEDGE_YES) != null) {
5613: state.setAttribute(VIEW_SUBMISSION_HONOR_PLEDGE_YES,
5614: "true");
5615: }
5616: // TODO: file picker to save in dropbox? -ggolden
5617: // User[] users = { UserDirectoryService.getCurrentUser() };
5618: // state.setAttribute(ResourcesAction.STATE_SAVE_ATTACHMENT_IN_DROPBOX, users);
5619: } else if (mode.equals(MODE_INSTRUCTOR_NEW_EDIT_ASSIGNMENT)) {
5620: setNewAssignmentParameters(data, false);
5621: } else if (mode.equals(MODE_INSTRUCTOR_GRADE_SUBMISSION)) {
5622: readGradeForm(data, state, "read");
5623: }
5624:
5625: if (state.getAttribute(STATE_MESSAGE) == null) {
5626: // get into helper mode with this helper tool
5627: startHelper(data.getRequest(), "sakai.filepicker");
5628:
5629: state.setAttribute(FilePickerHelper.FILE_PICKER_TITLE_TEXT,
5630: rb.getString("gen.addatttoassig"));
5631: state.setAttribute(
5632: FilePickerHelper.FILE_PICKER_INSTRUCTION_TEXT, rb
5633: .getString("gen.addatttoassiginstr"));
5634:
5635: // use the real attachment list
5636: state.setAttribute(
5637: FilePickerHelper.FILE_PICKER_ATTACHMENTS, state
5638: .getAttribute(ATTACHMENTS));
5639: }
5640: }
5641:
5642: /**
5643: * readGradeForm
5644: */
5645: public void readGradeForm(RunData data, SessionState state,
5646: String gradeOption) {
5647:
5648: ParameterParser params = data.getParameters();
5649:
5650: boolean withGrade = state.getAttribute(WITH_GRADES) != null ? ((Boolean) state
5651: .getAttribute(WITH_GRADES)).booleanValue()
5652: : false;
5653:
5654: if (params.getString("allowResubmit") != null) {
5655: state.setAttribute(GRADE_SUBMISSION_ALLOW_RESUBMIT,
5656: Boolean.TRUE);
5657: } else {
5658: state.setAttribute(GRADE_SUBMISSION_ALLOW_RESUBMIT,
5659: Boolean.FALSE);
5660: }
5661:
5662: boolean checkForFormattingErrors = false; // so that grading isn't held up by formatting errors
5663: String feedbackComment = processFormattedTextFromBrowser(
5664: state,
5665: params
5666: .getCleanString(GRADE_SUBMISSION_FEEDBACK_COMMENT),
5667: checkForFormattingErrors);
5668: if (feedbackComment != null) {
5669: state.setAttribute(GRADE_SUBMISSION_FEEDBACK_COMMENT,
5670: feedbackComment);
5671: }
5672:
5673: String feedbackText = processAssignmentFeedbackFromBrowser(
5674: state, params
5675: .getCleanString(GRADE_SUBMISSION_FEEDBACK_TEXT));
5676: if (feedbackText != null) {
5677: state.setAttribute(GRADE_SUBMISSION_FEEDBACK_TEXT,
5678: feedbackText);
5679: }
5680:
5681: state.setAttribute(GRADE_SUBMISSION_FEEDBACK_ATTACHMENT, state
5682: .getAttribute(ATTACHMENTS));
5683:
5684: String g = params.getCleanString(GRADE_SUBMISSION_GRADE);
5685: if (g != null) {
5686: state.setAttribute(GRADE_SUBMISSION_GRADE, g);
5687: }
5688:
5689: String sId = (String) state
5690: .getAttribute(GRADE_SUBMISSION_SUBMISSION_ID);
5691:
5692: try {
5693: // for points grading, one have to enter number as the points
5694: String grade = (String) state
5695: .getAttribute(GRADE_SUBMISSION_GRADE);
5696:
5697: Assignment a = AssignmentService.getSubmission(sId)
5698: .getAssignment();
5699: int typeOfGrade = a.getContent().getTypeOfGrade();
5700:
5701: if (withGrade) {
5702: // do grade validation only for Assignment with Grade tool
5703: if (typeOfGrade == 3) {
5704: if ((grade.length() == 0)) {
5705: if (gradeOption.equals("release")) {
5706: // in case of releasing grade, user must specify a grade
5707: addAlert(state, rb.getString("plespethe2"));
5708: }
5709: } else {
5710: // the preview grade process might already scaled up the grade by 10
5711: if (!((String) state.getAttribute(STATE_MODE))
5712: .equals(MODE_INSTRUCTOR_PREVIEW_GRADE_SUBMISSION)) {
5713: validPointGrade(state, grade);
5714:
5715: if (state.getAttribute(STATE_MESSAGE) == null) {
5716: int maxGrade = a.getContent()
5717: .getMaxGradePoint();
5718: try {
5719: if (Integer
5720: .parseInt(scalePointGrade(
5721: state, grade)) > maxGrade) {
5722: if (state
5723: .getAttribute(GRADE_GREATER_THAN_MAX_ALERT) == null) {
5724: // alert user first when he enters grade bigger than max scale
5725: addAlert(state, rb
5726: .getString("grad2"));
5727: state
5728: .setAttribute(
5729: GRADE_GREATER_THAN_MAX_ALERT,
5730: Boolean.TRUE);
5731: } else {
5732: // remove the alert once user confirms he wants to give student higher grade
5733: state
5734: .removeAttribute(GRADE_GREATER_THAN_MAX_ALERT);
5735: }
5736: }
5737: } catch (NumberFormatException e) {
5738: alertInvalidPoint(state, grade);
5739: }
5740: }
5741:
5742: if (state.getAttribute(STATE_MESSAGE) == null) {
5743: grade = scalePointGrade(state, grade);
5744: }
5745: state.setAttribute(GRADE_SUBMISSION_GRADE,
5746: grade);
5747: }
5748: }
5749: }
5750:
5751: // if ungraded and grade type is not "ungraded" type
5752: if ((grade == null || grade.equals("ungraded"))
5753: && (typeOfGrade != 1)
5754: && gradeOption.equals("release")) {
5755: addAlert(state, rb.getString("plespethe2"));
5756: }
5757: }
5758: } catch (IdUnusedException e) {
5759: addAlert(state, rb.getString("cannotfin5"));
5760: } catch (PermissionException e) {
5761: addAlert(state,
5762: "You are not allowed to view the assignment submission. ");
5763: }
5764: }
5765:
5766: /**
5767: * Populate the state object, if needed - override to do something!
5768: */
5769: protected void initState(SessionState state,
5770: VelocityPortlet portlet, JetspeedRunData data) {
5771: super .initState(state, portlet, data);
5772:
5773: String siteId = ToolManager.getCurrentPlacement().getContext();
5774:
5775: // show the list of assignment view first
5776: if (state.getAttribute(STATE_SELECTED_VIEW) == null) {
5777: state.setAttribute(STATE_SELECTED_VIEW,
5778: MODE_LIST_ASSIGNMENTS);
5779: }
5780:
5781: if (state.getAttribute(STATE_USER) == null) {
5782: state.setAttribute(STATE_USER, UserDirectoryService
5783: .getCurrentUser());
5784: }
5785:
5786: /** The content type image lookup service in the State. */
5787: ContentTypeImageService iService = (ContentTypeImageService) state
5788: .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE);
5789: if (iService == null) {
5790: iService = org.sakaiproject.content.cover.ContentTypeImageService
5791: .getInstance();
5792: state.setAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE,
5793: iService);
5794: } // if
5795:
5796: /** The calendar service in the State. */
5797: CalendarService cService = (CalendarService) state
5798: .getAttribute(STATE_CALENDAR_SERVICE);
5799: if (cService == null) {
5800: cService = org.sakaiproject.calendar.cover.CalendarService
5801: .getInstance();
5802: state.setAttribute(STATE_CALENDAR_SERVICE, cService);
5803:
5804: String calendarId = ServerConfigurationService.getString(
5805: "calendar", null);
5806: if (calendarId == null) {
5807: calendarId = cService.calendarReference(siteId,
5808: SiteService.MAIN_CONTAINER);
5809: try {
5810: state.setAttribute(CALENDAR, cService
5811: .getCalendar(calendarId));
5812: } catch (IdUnusedException e) {
5813: Log.info("chef", "No calendar found for site "
5814: + siteId);
5815: state.removeAttribute(CALENDAR);
5816: } catch (PermissionException e) {
5817: Log.info("chef",
5818: "No permission to get the calender. ");
5819: state.removeAttribute(CALENDAR);
5820: } catch (Exception ex) {
5821: Log.info("chef",
5822: "Assignment : Action : init state : calendar exception : "
5823: + ex);
5824: state.removeAttribute(CALENDAR);
5825: }
5826: }
5827: } // if
5828:
5829: /** The announcement service in the State. */
5830: AnnouncementService aService = (AnnouncementService) state
5831: .getAttribute(STATE_ANNOUNCEMENT_SERVICE);
5832: if (aService == null) {
5833: aService = org.sakaiproject.announcement.cover.AnnouncementService
5834: .getInstance();
5835: state.setAttribute(STATE_ANNOUNCEMENT_SERVICE, aService);
5836:
5837: String channelId = ServerConfigurationService.getString(
5838: "channel", null);
5839: if (channelId == null) {
5840: channelId = aService.channelReference(siteId,
5841: SiteService.MAIN_CONTAINER);
5842: try {
5843: state.setAttribute(ANNOUNCEMENT_CHANNEL, aService
5844: .getAnnouncementChannel(channelId));
5845: } catch (IdUnusedException e) {
5846: Log.warn("chef", "No announcement channel found. ");
5847: // the announcement channel is not created yet; go create
5848: try {
5849: aService.addAnnouncementChannel(channelId);
5850: } catch (PermissionException ee) {
5851: Log
5852: .warn("chef",
5853: "Can not create announcement channel. ");
5854: } catch (IdUsedException ee) {
5855:
5856: } catch (IdInvalidException ee) {
5857: Log
5858: .warn("chef",
5859: "The announcement channel could not be created because the Id is invalid. ");
5860: } catch (Exception ex) {
5861: Log.warn("chef",
5862: "Assignment : Action : init state : announcement exception : "
5863: + ex);
5864: }
5865: } catch (PermissionException e) {
5866: Log.warn("chef",
5867: "No permission to annoucement channel. ");
5868: } catch (Exception ex) {
5869: Log.warn("chef",
5870: "Assignment : Action : init state : calendar exception : "
5871: + ex);
5872: }
5873: }
5874:
5875: } // if
5876:
5877: if (state.getAttribute(STATE_CONTEXT_STRING) == null) {
5878: state.setAttribute(STATE_CONTEXT_STRING, siteId);
5879: } // if context string is null
5880:
5881: if (state.getAttribute(SORTED_BY) == null) {
5882: state.setAttribute(SORTED_BY, SORTED_BY_DUEDATE);
5883: }
5884:
5885: if (state.getAttribute(SORTED_ASC) == null) {
5886: state.setAttribute(SORTED_ASC, Boolean.TRUE.toString());
5887: }
5888:
5889: if (state.getAttribute(SORTED_GRADE_SUBMISSION_BY) == null) {
5890: state.setAttribute(SORTED_GRADE_SUBMISSION_BY,
5891: SORTED_GRADE_SUBMISSION_BY_LASTNAME);
5892: }
5893:
5894: if (state.getAttribute(SORTED_GRADE_SUBMISSION_ASC) == null) {
5895: state.setAttribute(SORTED_GRADE_SUBMISSION_ASC,
5896: Boolean.TRUE.toString());
5897: }
5898:
5899: if (state.getAttribute(SORTED_SUBMISSION_BY) == null) {
5900: state.setAttribute(SORTED_SUBMISSION_BY,
5901: SORTED_SUBMISSION_BY_LASTNAME);
5902: }
5903:
5904: if (state.getAttribute(SORTED_SUBMISSION_ASC) == null) {
5905: state.setAttribute(SORTED_SUBMISSION_ASC, Boolean.TRUE
5906: .toString());
5907: }
5908:
5909: if (state.getAttribute(NEW_ASSIGNMENT_HIDE_OPTION_FLAG) == null) {
5910: resetAssignment(state);
5911: }
5912:
5913: if (state.getAttribute(STUDENT_LIST_SHOW_TABLE) == null) {
5914: state
5915: .setAttribute(STUDENT_LIST_SHOW_TABLE,
5916: new Hashtable());
5917: }
5918:
5919: if (state.getAttribute(ATTACHMENTS_MODIFIED) == null) {
5920: state
5921: .setAttribute(ATTACHMENTS_MODIFIED, new Boolean(
5922: false));
5923: }
5924:
5925: // SECTION MOD
5926: if (state.getAttribute(STATE_SECTION_STRING) == null) {
5927: state.setAttribute(STATE_SECTION_STRING, "001");
5928: }
5929:
5930: // // setup the observer to notify the Main panel
5931: // if (state.getAttribute(STATE_OBSERVER) == null)
5932: // {
5933: // // the delivery location for this tool
5934: // String deliveryId = clientWindowId(state, portlet.getID());
5935: //
5936: // // the html element to update on delivery
5937: // String elementId = mainPanelUpdateId(portlet.getID());
5938: //
5939: // // the event resource reference pattern to watch for
5940: // String pattern = AssignmentService.assignmentReference((String) state.getAttribute (STATE_CONTEXT_STRING), "");
5941: //
5942: // state.setAttribute(STATE_OBSERVER, new MultipleEventsObservingCourier(deliveryId, elementId, pattern));
5943: // }
5944:
5945: if (state.getAttribute(STATE_MODE) == null) {
5946: state.setAttribute(STATE_MODE, MODE_LIST_ASSIGNMENTS);
5947: }
5948:
5949: if (state.getAttribute(STATE_TOP_PAGE_MESSAGE) == null) {
5950: state.setAttribute(STATE_TOP_PAGE_MESSAGE, new Integer(0));
5951: }
5952:
5953: if (state.getAttribute(WITH_GRADES) == null) {
5954: PortletConfig config = portlet.getPortletConfig();
5955: String withGrades = StringUtil.trimToNull(config
5956: .getInitParameter("withGrades"));
5957: if (withGrades == null) {
5958: withGrades = Boolean.FALSE.toString();
5959: }
5960: state.setAttribute(WITH_GRADES, new Boolean(withGrades));
5961: }
5962: } // initState
5963:
5964: /**
5965: * reset the attributes for view submission
5966: */
5967: private void resetViewSubmission(SessionState state) {
5968: state.removeAttribute(VIEW_SUBMISSION_ASSIGNMENT_REFERENCE);
5969: state.removeAttribute(VIEW_SUBMISSION_TEXT);
5970: state.setAttribute(VIEW_SUBMISSION_HONOR_PLEDGE_YES, "false");
5971: state.removeAttribute(GRADE_GREATER_THAN_MAX_ALERT);
5972:
5973: } // resetViewSubmission
5974:
5975: /**
5976: * reset the attributes for view submission
5977: */
5978: private void resetAssignment(SessionState state) {
5979: // put the input value into the state attributes
5980: state.setAttribute(NEW_ASSIGNMENT_TITLE, "");
5981:
5982: // get current time
5983: Time t = TimeService.newTime();
5984: TimeBreakdown tB = t.breakdownLocal();
5985: int month = tB.getMonth();
5986: int day = tB.getDay();
5987: int year = tB.getYear();
5988:
5989: // set the open time to be 12:00 PM
5990: state
5991: .setAttribute(NEW_ASSIGNMENT_OPENMONTH, new Integer(
5992: month));
5993: state.setAttribute(NEW_ASSIGNMENT_OPENDAY, new Integer(day));
5994: state.setAttribute(NEW_ASSIGNMENT_OPENYEAR, new Integer(year));
5995: state.setAttribute(NEW_ASSIGNMENT_OPENHOUR, new Integer(12));
5996: state.setAttribute(NEW_ASSIGNMENT_OPENMIN, new Integer(0));
5997: state.setAttribute(NEW_ASSIGNMENT_OPENAMPM, "PM");
5998:
5999: // due date is shifted forward by 7 days
6000: t.setTime(t.getTime() + 7 * 24 * 60 * 60 * 1000);
6001: tB = t.breakdownLocal();
6002: month = tB.getMonth();
6003: day = tB.getDay();
6004: year = tB.getYear();
6005:
6006: // set the due time to be 5:00pm
6007: state.setAttribute(NEW_ASSIGNMENT_DUEMONTH, new Integer(month));
6008: state.setAttribute(NEW_ASSIGNMENT_DUEDAY, new Integer(day));
6009: state.setAttribute(NEW_ASSIGNMENT_DUEYEAR, new Integer(year));
6010: state.setAttribute(NEW_ASSIGNMENT_DUEHOUR, new Integer(5));
6011: state.setAttribute(NEW_ASSIGNMENT_DUEMIN, new Integer(0));
6012: state.setAttribute(NEW_ASSIGNMENT_DUEAMPM, "PM");
6013:
6014: // enable the close date by default
6015: state.setAttribute(NEW_ASSIGNMENT_ENABLECLOSEDATE, new Boolean(
6016: true));
6017: // set the close time to be 5:00 pm, same as the due time by default
6018: state.setAttribute(NEW_ASSIGNMENT_CLOSEMONTH,
6019: new Integer(month));
6020: state.setAttribute(NEW_ASSIGNMENT_CLOSEDAY, new Integer(day));
6021: state.setAttribute(NEW_ASSIGNMENT_CLOSEYEAR, new Integer(year));
6022: state.setAttribute(NEW_ASSIGNMENT_CLOSEHOUR, new Integer(5));
6023: state.setAttribute(NEW_ASSIGNMENT_CLOSEMIN, new Integer(0));
6024: state.setAttribute(NEW_ASSIGNMENT_CLOSEAMPM, "PM");
6025:
6026: state.setAttribute(NEW_ASSIGNMENT_SECTION, "001");
6027: state.setAttribute(NEW_ASSIGNMENT_SUBMISSION_TYPE, new Integer(
6028: Assignment.TEXT_AND_ATTACHMENT_ASSIGNMENT_SUBMISSION));
6029: state.setAttribute(NEW_ASSIGNMENT_GRADE_TYPE, new Integer(
6030: Assignment.UNGRADED_GRADE_TYPE));
6031: state.setAttribute(NEW_ASSIGNMENT_GRADE_POINTS, "");
6032: state.setAttribute(NEW_ASSIGNMENT_DESCRIPTION, "");
6033: state.setAttribute(
6034: ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE,
6035: Boolean.FALSE.toString());
6036: state.setAttribute(
6037: ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE,
6038: Boolean.FALSE.toString());
6039: // make the honor pledge not include as the default
6040: state.setAttribute(NEW_ASSIGNMENT_CHECK_ADD_HONOR_PLEDGE,
6041: (new Integer(Assignment.HONOR_PLEDGE_NONE)).toString());
6042:
6043: state.setAttribute(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK,
6044: GRADEBOOK_INTEGRATION_NO);
6045:
6046: state.setAttribute(NEW_ASSIGNMENT_ATTACHMENT, EntityManager
6047: .newReferenceList());
6048:
6049: state.setAttribute(NEW_ASSIGNMENT_HIDE_OPTION_FLAG,
6050: new Boolean(false));
6051:
6052: state.setAttribute(NEW_ASSIGNMENT_FOCUS, NEW_ASSIGNMENT_TITLE);
6053:
6054: state.removeAttribute(NEW_ASSIGNMENT_DESCRIPTION_EMPTY);
6055:
6056: // reset the global navigaion alert flag
6057: if (state.getAttribute(ALERT_GLOBAL_NAVIGATION) != null) {
6058: state.removeAttribute(ALERT_GLOBAL_NAVIGATION);
6059: }
6060:
6061: state.setAttribute(NEW_ASSIGNMENT_RANGE, "site");
6062: state.removeAttribute(NEW_ASSIGNMENT_GROUPS);
6063:
6064: // remove the edit assignment id if any
6065: state.removeAttribute(EDIT_ASSIGNMENT_ID);
6066:
6067: } // resetNewAssignment
6068:
6069: /**
6070: * construct a Hashtable using integer as the key and three character string of the month as the value
6071: */
6072: private Hashtable monthTable() {
6073: Hashtable n = new Hashtable();
6074: n.put(new Integer(1), rb.getString("jan"));
6075: n.put(new Integer(2), rb.getString("feb"));
6076: n.put(new Integer(3), rb.getString("mar"));
6077: n.put(new Integer(4), rb.getString("apr"));
6078: n.put(new Integer(5), rb.getString("may"));
6079: n.put(new Integer(6), rb.getString("jun"));
6080: n.put(new Integer(7), rb.getString("jul"));
6081: n.put(new Integer(8), rb.getString("aug"));
6082: n.put(new Integer(9), rb.getString("sep"));
6083: n.put(new Integer(10), rb.getString("oct"));
6084: n.put(new Integer(11), rb.getString("nov"));
6085: n.put(new Integer(12), rb.getString("dec"));
6086: return n;
6087:
6088: } // monthTable
6089:
6090: /**
6091: * construct a Hashtable using the integer as the key and grade type String as the value
6092: */
6093: private Hashtable gradeTypeTable() {
6094: Hashtable n = new Hashtable();
6095: n.put(new Integer(2), rb.getString("letter"));
6096: n.put(new Integer(3), rb.getString("points"));
6097: n.put(new Integer(4), rb.getString("pass"));
6098: n.put(new Integer(5), rb.getString("check"));
6099: n.put(new Integer(1), rb.getString("ungra"));
6100: return n;
6101:
6102: } // gradeTypeTable
6103:
6104: /**
6105: * construct a Hashtable using the integer as the key and submission type String as the value
6106: */
6107: private Hashtable submissionTypeTable() {
6108: Hashtable n = new Hashtable();
6109: n.put(new Integer(1), rb.getString("inlin"));
6110: n.put(new Integer(2), rb.getString("attaonly"));
6111: n.put(new Integer(3), rb.getString("inlinatt"));
6112: return n;
6113:
6114: } // submissionTypeTable
6115:
6116: /**
6117: * Sort based on the given property
6118: */
6119: public void doSort(RunData data) {
6120: SessionState state = ((JetspeedRunData) data)
6121: .getPortletSessionState(((JetspeedRunData) data)
6122: .getJs_peid());
6123:
6124: // we are changing the sort, so start from the first page again
6125: resetPaging(state);
6126:
6127: setupSort(data, data.getParameters().getString("criteria"));
6128: }
6129:
6130: /**
6131: * setup sorting parameters
6132: *
6133: * @param criteria
6134: * String for sortedBy
6135: */
6136: private void setupSort(RunData data, String criteria) {
6137: SessionState state = ((JetspeedRunData) data)
6138: .getPortletSessionState(((JetspeedRunData) data)
6139: .getJs_peid());
6140:
6141: // current sorting sequence
6142: String asc = "";
6143: if (!criteria.equals(state.getAttribute(SORTED_BY))) {
6144: state.setAttribute(SORTED_BY, criteria);
6145: asc = Boolean.TRUE.toString();
6146: state.setAttribute(SORTED_ASC, asc);
6147: } else {
6148: // current sorting sequence
6149: asc = (String) state.getAttribute(SORTED_ASC);
6150:
6151: // toggle between the ascending and descending sequence
6152: if (asc.equals(Boolean.TRUE.toString())) {
6153: asc = Boolean.FALSE.toString();
6154: } else {
6155: asc = Boolean.TRUE.toString();
6156: }
6157: state.setAttribute(SORTED_ASC, asc);
6158: }
6159:
6160: } // doSort
6161:
6162: /**
6163: * Do sort by group title
6164: */
6165: public void doSortbygrouptitle(RunData data) {
6166: setupSort(data, SORTED_BY_GROUP_TITLE);
6167:
6168: } // doSortbygrouptitle
6169:
6170: /**
6171: * Do sort by group description
6172: */
6173: public void doSortbygroupdescription(RunData data) {
6174: setupSort(data, SORTED_BY_GROUP_DESCRIPTION);
6175:
6176: } // doSortbygroupdescription
6177:
6178: /**
6179: * Sort submission based on the given property
6180: */
6181: public void doSort_submission(RunData data) {
6182: SessionState state = ((JetspeedRunData) data)
6183: .getPortletSessionState(((JetspeedRunData) data)
6184: .getJs_peid());
6185:
6186: // we are changing the sort, so start from the first page again
6187: resetPaging(state);
6188:
6189: // get the ParameterParser from RunData
6190: ParameterParser params = data.getParameters();
6191:
6192: String criteria = params.getString("criteria");
6193:
6194: // current sorting sequence
6195: String asc = "";
6196:
6197: if (!criteria.equals(state.getAttribute(SORTED_SUBMISSION_BY))) {
6198: state.setAttribute(SORTED_SUBMISSION_BY, criteria);
6199: asc = Boolean.TRUE.toString();
6200: state.setAttribute(SORTED_SUBMISSION_ASC, asc);
6201: } else {
6202: // current sorting sequence
6203: state.setAttribute(SORTED_SUBMISSION_BY, criteria);
6204: asc = (String) state.getAttribute(SORTED_SUBMISSION_ASC);
6205:
6206: // toggle between the ascending and descending sequence
6207: if (asc.equals(Boolean.TRUE.toString())) {
6208: asc = Boolean.FALSE.toString();
6209: } else {
6210: asc = Boolean.TRUE.toString();
6211: }
6212: state.setAttribute(SORTED_SUBMISSION_ASC, asc);
6213: }
6214: } // doSort_submission
6215:
6216: /**
6217: * Sort submission based on the given property in instructor grade view
6218: */
6219: public void doSort_grade_submission(RunData data) {
6220: SessionState state = ((JetspeedRunData) data)
6221: .getPortletSessionState(((JetspeedRunData) data)
6222: .getJs_peid());
6223:
6224: // we are changing the sort, so start from the first page again
6225: resetPaging(state);
6226:
6227: // get the ParameterParser from RunData
6228: ParameterParser params = data.getParameters();
6229:
6230: String criteria = params.getString("criteria");
6231:
6232: // current sorting sequence
6233: String asc = "";
6234:
6235: if (!criteria.equals(state
6236: .getAttribute(SORTED_GRADE_SUBMISSION_BY))) {
6237: state.setAttribute(SORTED_GRADE_SUBMISSION_BY, criteria);
6238: asc = Boolean.TRUE.toString();
6239: state.setAttribute(SORTED_GRADE_SUBMISSION_ASC, asc);
6240: } else {
6241: // current sorting sequence
6242: state.setAttribute(SORTED_GRADE_SUBMISSION_BY, criteria);
6243: asc = (String) state
6244: .getAttribute(SORTED_GRADE_SUBMISSION_ASC);
6245:
6246: // toggle between the ascending and descending sequence
6247: if (asc.equals(Boolean.TRUE.toString())) {
6248: asc = Boolean.FALSE.toString();
6249: } else {
6250: asc = Boolean.TRUE.toString();
6251: }
6252: state.setAttribute(SORTED_GRADE_SUBMISSION_ASC, asc);
6253: }
6254: } // doSort_grade_submission
6255:
6256: /**
6257: * the UserSubmission clas
6258: */
6259: public class UserSubmission {
6260: /**
6261: * the User object
6262: */
6263: User m_user = null;
6264:
6265: /**
6266: * the AssignmentSubmission object
6267: */
6268: AssignmentSubmission m_submission = null;
6269:
6270: public UserSubmission(User u, AssignmentSubmission s) {
6271: m_user = u;
6272: m_submission = s;
6273: }
6274:
6275: /**
6276: * Returns the AssignmentSubmission object
6277: */
6278: public AssignmentSubmission getSubmission() {
6279: return m_submission;
6280: }
6281:
6282: /**
6283: * Returns the User object
6284: */
6285: public User getUser() {
6286: return m_user;
6287: }
6288: }
6289:
6290: /**
6291: * the AssignmentComparator clas
6292: */
6293: private class AssignmentComparator implements Comparator {
6294: /**
6295: * the SessionState object
6296: */
6297: SessionState m_state = null;
6298:
6299: /**
6300: * the criteria
6301: */
6302: String m_criteria = null;
6303:
6304: /**
6305: * the criteria
6306: */
6307: String m_asc = null;
6308:
6309: /**
6310: * the user
6311: */
6312: User m_user = null;
6313:
6314: /**
6315: * constructor
6316: *
6317: * @param state
6318: * The state object
6319: * @param criteria
6320: * The sort criteria string
6321: * @param asc
6322: * The sort order string. TRUE_STRING if ascending; "false" otherwise.
6323: */
6324: public AssignmentComparator(SessionState state,
6325: String criteria, String asc) {
6326: m_state = state;
6327: m_criteria = criteria;
6328: m_asc = asc;
6329:
6330: } // constructor
6331:
6332: /**
6333: * constructor
6334: *
6335: * @param state
6336: * The state object
6337: * @param criteria
6338: * The sort criteria string
6339: * @param asc
6340: * The sort order string. TRUE_STRING if ascending; "false" otherwise.
6341: * @param user
6342: * The user object
6343: */
6344: public AssignmentComparator(SessionState state,
6345: String criteria, String asc, User user) {
6346: m_state = state;
6347: m_criteria = criteria;
6348: m_asc = asc;
6349: m_user = user;
6350: } // constructor
6351:
6352: /**
6353: * caculate the range string for an assignment
6354: */
6355: private String getAssignmentRange(Assignment a) {
6356: String rv = "";
6357: if (a.getAccess().equals(Assignment.AssignmentAccess.SITE)) {
6358: // site assignment
6359: rv = rb.getString("range.allgroups");
6360: } else {
6361: try {
6362: // get current site
6363: Site site = SiteService.getSite(ToolManager
6364: .getCurrentPlacement().getContext());
6365: for (Iterator k = a.getGroups().iterator(); k
6366: .hasNext();) {
6367: // announcement by group
6368: rv = rv.concat(site.getGroup((String) k.next())
6369: .getTitle());
6370: }
6371: } catch (Exception ignore) {
6372: }
6373: }
6374:
6375: return rv;
6376:
6377: } // getAssignmentRange
6378:
6379: /**
6380: * implementing the compare function
6381: *
6382: * @param o1
6383: * The first object
6384: * @param o2
6385: * The second object
6386: * @return The compare result. 1 is o1 < o2; -1 otherwise
6387: */
6388: public int compare(Object o1, Object o2) {
6389: int result = -1;
6390:
6391: /** *********** fo sorting assignments ****************** */
6392: if (m_criteria.equals(SORTED_BY_TITLE)) {
6393: // sorted by the assignment title
6394: String s1 = ((Assignment) o1).getTitle();
6395: String s2 = ((Assignment) o2).getTitle();
6396: result = s1.compareToIgnoreCase(s2);
6397: } else if (m_criteria.equals(SORTED_BY_SECTION)) {
6398: // sorted by the assignment section
6399: String s1 = ((Assignment) o1).getSection();
6400: String s2 = ((Assignment) o2).getSection();
6401: result = s1.compareToIgnoreCase(s2);
6402: } else if (m_criteria.equals(SORTED_BY_DUEDATE)) {
6403: // sorted by the assignment due date
6404: Time t1 = ((Assignment) o1).getDueTime();
6405: Time t2 = ((Assignment) o2).getDueTime();
6406:
6407: if (t1 == null) {
6408: result = -1;
6409: } else if (t2 == null) {
6410: result = 1;
6411: } else if (t1.before(t2)) {
6412: result = -1;
6413: } else {
6414: result = 1;
6415: }
6416: } else if (m_criteria.equals(SORTED_BY_OPENDATE)) {
6417: // sorted by the assignment open
6418: Time t1 = ((Assignment) o1).getOpenTime();
6419: Time t2 = ((Assignment) o2).getOpenTime();
6420:
6421: if (t1 == null) {
6422: result = -1;
6423: } else if (t2 == null) {
6424: result = 1;
6425: }
6426: if (t1.before(t2)) {
6427: result = -1;
6428: } else {
6429: result = 1;
6430: }
6431: } else if (m_criteria.equals(SORTED_BY_ASSIGNMENT_STATUS)) {
6432: String s1 = getAssignmentStatus((Assignment) o1);
6433: String s2 = getAssignmentStatus((Assignment) o2);
6434: result = s1.compareToIgnoreCase(s2);
6435: } else if (m_criteria.equals(SORTED_BY_NUM_SUBMISSIONS)) {
6436: // sort by numbers of submissions
6437:
6438: // initialize
6439: int subNum1 = 0;
6440: int subNum2 = 0;
6441:
6442: Iterator submissions1 = AssignmentService
6443: .getSubmissions((Assignment) o1);
6444: while (submissions1.hasNext()) {
6445: AssignmentSubmission submission1 = (AssignmentSubmission) submissions1
6446: .next();
6447: if (submission1.getSubmitted())
6448: subNum1++;
6449: }
6450:
6451: Iterator submissions2 = AssignmentService
6452: .getSubmissions((Assignment) o2);
6453: while (submissions2.hasNext()) {
6454: AssignmentSubmission submission2 = (AssignmentSubmission) submissions2
6455: .next();
6456: if (submission2.getSubmitted())
6457: subNum2++;
6458: }
6459:
6460: result = (subNum1 > subNum2) ? 1 : -1;
6461:
6462: } else if (m_criteria.equals(SORTED_BY_NUM_UNGRADED)) {
6463: // sort by numbers of ungraded submissions
6464:
6465: // initialize
6466: int ungraded1 = 0;
6467: int ungraded2 = 0;
6468:
6469: Iterator submissions1 = AssignmentService
6470: .getSubmissions((Assignment) o1);
6471: while (submissions1.hasNext()) {
6472: AssignmentSubmission submission1 = (AssignmentSubmission) submissions1
6473: .next();
6474: if (submission1.getSubmitted()
6475: && !submission1.getGraded())
6476: ungraded1++;
6477: }
6478:
6479: Iterator submissions2 = AssignmentService
6480: .getSubmissions((Assignment) o2);
6481: while (submissions2.hasNext()) {
6482: AssignmentSubmission submission2 = (AssignmentSubmission) submissions2
6483: .next();
6484: if (submission2.getSubmitted()
6485: && !submission2.getGraded())
6486: ungraded2++;
6487: }
6488:
6489: result = (ungraded1 > ungraded2) ? 1 : -1;
6490:
6491: } else if (m_criteria.equals(SORTED_BY_SUBMISSION_STATUS)) {
6492: try {
6493: AssignmentSubmission submission1 = AssignmentService
6494: .getSubmission(((Assignment) o1).getId(),
6495: m_user);
6496: String status1 = getSubmissionStatus(submission1,
6497: (Assignment) o1);
6498:
6499: AssignmentSubmission submission2 = AssignmentService
6500: .getSubmission(((Assignment) o2).getId(),
6501: m_user);
6502: String status2 = getSubmissionStatus(submission2,
6503: (Assignment) o2);
6504:
6505: result = status1.compareTo(status2);
6506: } catch (IdUnusedException e) {
6507: return 1;
6508: } catch (PermissionException e) {
6509: return 1;
6510: }
6511: } else if (m_criteria.equals(SORTED_BY_GRADE)) {
6512: try {
6513: AssignmentSubmission submission1 = AssignmentService
6514: .getSubmission(((Assignment) o1).getId(),
6515: m_user);
6516: String grade1 = " ";
6517: if (submission1 != null && submission1.getGraded()
6518: && submission1.getGradeReleased()) {
6519: grade1 = submission1.getGrade();
6520: }
6521:
6522: AssignmentSubmission submission2 = AssignmentService
6523: .getSubmission(((Assignment) o2).getId(),
6524: m_user);
6525: String grade2 = " ";
6526: if (submission2 != null && submission2.getGraded()
6527: && submission2.getGradeReleased()) {
6528: grade2 = submission2.getGrade();
6529: }
6530:
6531: result = grade1.compareTo(grade2);
6532: } catch (IdUnusedException e) {
6533: return 1;
6534: } catch (PermissionException e) {
6535: return 1;
6536: }
6537: } else if (m_criteria.equals(SORTED_BY_MAX_GRADE)) {
6538: String maxGrade1 = maxGrade(((Assignment) o1)
6539: .getContent().getTypeOfGrade(), (Assignment) o1);
6540: String maxGrade2 = maxGrade(((Assignment) o2)
6541: .getContent().getTypeOfGrade(), (Assignment) o2);
6542:
6543: try {
6544: // do integer comparation inside point grade type
6545: int max1 = Integer.parseInt(maxGrade1);
6546: int max2 = Integer.parseInt(maxGrade2);
6547: result = (max1 < max2) ? -1 : 1;
6548: } catch (NumberFormatException e) {
6549: // otherwise do an alpha-compare
6550: result = maxGrade1.compareTo(maxGrade2);
6551: }
6552: }
6553: // group related sorting
6554: else if (m_criteria.equals(SORTED_BY_FOR)) {
6555: // sorted by the public view attribute
6556: String factor1 = getAssignmentRange((Assignment) o1);
6557: String factor2 = getAssignmentRange((Assignment) o2);
6558: result = factor1.compareToIgnoreCase(factor2);
6559: } else if (m_criteria.equals(SORTED_BY_GROUP_TITLE)) {
6560: // sorted by the group title
6561: String factor1 = ((Group) o1).getTitle();
6562: String factor2 = ((Group) o2).getTitle();
6563: result = factor1.compareToIgnoreCase(factor2);
6564: } else if (m_criteria.equals(SORTED_BY_GROUP_DESCRIPTION)) {
6565: // sorted by the group description
6566: String factor1 = ((Group) o1).getDescription();
6567: String factor2 = ((Group) o2).getDescription();
6568: if (factor1 == null) {
6569: factor1 = "";
6570: }
6571: if (factor2 == null) {
6572: factor2 = "";
6573: }
6574: result = factor1.compareToIgnoreCase(factor2);
6575: }
6576: /** ***************** for sorting submissions in instructor grade assignment view ************* */
6577: else if (m_criteria
6578: .equals(SORTED_GRADE_SUBMISSION_BY_LASTNAME)) {
6579: // sorted by the submitters sort name
6580: UserSubmission u1 = (UserSubmission) o1;
6581: UserSubmission u2 = (UserSubmission) o2;
6582:
6583: if (u1 == null || u2 == null || u1.getUser() == null
6584: || u2.getUser() == null) {
6585: result = 1;
6586: } else {
6587: String lName1 = u1.getUser().getLastName();
6588: String lName2 = u2.getUser().getLastName();
6589: result = lName1.toLowerCase().compareTo(
6590: lName2.toLowerCase());
6591: }
6592: } else if (m_criteria
6593: .equals(SORTED_GRADE_SUBMISSION_BY_SUBMIT_TIME)) {
6594: // sorted by submission time
6595: UserSubmission u1 = (UserSubmission) o1;
6596: UserSubmission u2 = (UserSubmission) o2;
6597:
6598: if (u1 == null || u2 == null) {
6599: result = -1;
6600: } else {
6601: AssignmentSubmission s1 = u1.getSubmission();
6602: AssignmentSubmission s2 = u2.getSubmission();
6603:
6604: if (s1 == null || s1.getTimeSubmitted() == null) {
6605: result = -1;
6606: } else if (s2 == null
6607: || s2.getTimeSubmitted() == null) {
6608: result = 1;
6609: } else if (s1.getTimeSubmitted().before(
6610: s2.getTimeSubmitted())) {
6611: result = -1;
6612: } else {
6613: result = 1;
6614: }
6615: }
6616: } else if (m_criteria
6617: .equals(SORTED_GRADE_SUBMISSION_BY_STATUS)) {
6618: // sort by submission status
6619: UserSubmission u1 = (UserSubmission) o1;
6620: UserSubmission u2 = (UserSubmission) o2;
6621:
6622: String status1 = "";
6623: String status2 = "";
6624:
6625: if (u1 == null) {
6626: status1 = rb.getString("listsub.nosub");
6627: } else {
6628: AssignmentSubmission s1 = u1.getSubmission();
6629: if (s1 == null) {
6630: status1 = rb.getString("listsub.nosub");
6631: } else {
6632: status1 = getSubmissionStatus(m_state,
6633: (AssignmentSubmission) s1);
6634: }
6635: }
6636:
6637: if (u2 == null) {
6638: status2 = rb.getString("listsub.nosub");
6639: } else {
6640: AssignmentSubmission s2 = u2.getSubmission();
6641: if (s2 == null) {
6642: status2 = rb.getString("listsub.nosub");
6643: } else {
6644: status2 = getSubmissionStatus(m_state,
6645: (AssignmentSubmission) s2);
6646: }
6647: }
6648:
6649: result = status1.toLowerCase().compareTo(
6650: status2.toLowerCase());
6651: } else if (m_criteria
6652: .equals(SORTED_GRADE_SUBMISSION_BY_GRADE)) {
6653: // sort by submission status
6654: UserSubmission u1 = (UserSubmission) o1;
6655: UserSubmission u2 = (UserSubmission) o2;
6656:
6657: if (u1 == null || u2 == null) {
6658: result = -1;
6659: } else {
6660: AssignmentSubmission s1 = u1.getSubmission();
6661: AssignmentSubmission s2 = u2.getSubmission();
6662:
6663: //sort by submission grade
6664: if (s1 == null) {
6665: result = -1;
6666: } else if (s2 == null) {
6667: result = 1;
6668: } else {
6669: String grade1 = s1.getGrade();
6670: String grade2 = s2.getGrade();
6671: if (grade1 == null) {
6672: grade1 = "";
6673: }
6674: if (grade2 == null) {
6675: grade2 = "";
6676: }
6677:
6678: // if scale is points
6679: if ((s1.getAssignment().getContent()
6680: .getTypeOfGrade() == 3)
6681: && ((s2.getAssignment().getContent()
6682: .getTypeOfGrade() == 3))) {
6683: if (grade1.equals("")) {
6684: result = -1;
6685: } else if (grade2.equals("")) {
6686: result = 1;
6687: } else {
6688: result = (new Integer(grade1))
6689: .intValue() > (new Integer(
6690: grade2)).intValue() ? 1 : -1;
6691:
6692: }
6693: } else {
6694: result = grade1.compareTo(grade2);
6695: }
6696: }
6697: }
6698: } else if (m_criteria
6699: .equals(SORTED_GRADE_SUBMISSION_BY_RELEASED)) {
6700: // sort by submission status
6701: UserSubmission u1 = (UserSubmission) o1;
6702: UserSubmission u2 = (UserSubmission) o2;
6703:
6704: if (u1 == null || u2 == null) {
6705: result = -1;
6706: } else {
6707: AssignmentSubmission s1 = u1.getSubmission();
6708: AssignmentSubmission s2 = u2.getSubmission();
6709:
6710: if (s1 == null) {
6711: result = -1;
6712: } else if (s2 == null) {
6713: result = 1;
6714: } else {
6715: // sort by submission released
6716: String released1 = (new Boolean(s1
6717: .getGradeReleased())).toString();
6718: String released2 = (new Boolean(s2
6719: .getGradeReleased())).toString();
6720:
6721: result = released1.compareTo(released2);
6722: }
6723: }
6724: }
6725: /****** for other sort on submissions **/
6726: else if (m_criteria.equals(SORTED_SUBMISSION_BY_LASTNAME)) {
6727: // sorted by the submitters sort name
6728: User[] u1 = ((AssignmentSubmission) o1).getSubmitters();
6729: User[] u2 = ((AssignmentSubmission) o2).getSubmitters();
6730:
6731: if (u1 == null || u2 == null) {
6732: return 1;
6733: } else {
6734: String submitters1 = "";
6735: String submitters2 = "";
6736:
6737: for (int j = 0; j < u1.length; j++) {
6738: if (u1[j] != null
6739: && u1[j].getLastName() != null) {
6740: if (j > 0) {
6741: submitters1 = submitters1.concat("; ");
6742: }
6743: submitters1 = submitters1.concat(""
6744: + u1[j].getLastName());
6745: }
6746: }
6747:
6748: for (int j = 0; j < u2.length; j++) {
6749: if (u2[j] != null
6750: && u2[j].getLastName() != null) {
6751: if (j > 0) {
6752: submitters2 = submitters2.concat("; ");
6753: }
6754: submitters2 = submitters2.concat(u2[j]
6755: .getLastName());
6756: }
6757: }
6758: result = submitters1.toLowerCase().compareTo(
6759: submitters2.toLowerCase());
6760: }
6761: } else if (m_criteria
6762: .equals(SORTED_SUBMISSION_BY_SUBMIT_TIME)) {
6763: // sorted by submission time
6764: Time t1 = ((AssignmentSubmission) o1)
6765: .getTimeSubmitted();
6766: Time t2 = ((AssignmentSubmission) o2)
6767: .getTimeSubmitted();
6768:
6769: if (t1 == null) {
6770: result = -1;
6771: } else if (t2 == null) {
6772: result = 1;
6773: } else if (t1.before(t2)) {
6774: result = -1;
6775: } else {
6776: result = 1;
6777: }
6778: } else if (m_criteria.equals(SORTED_SUBMISSION_BY_STATUS)) {
6779: // sort by submission status
6780: String status1 = getSubmissionStatus(m_state,
6781: (AssignmentSubmission) o1);
6782: String status2 = getSubmissionStatus(m_state,
6783: (AssignmentSubmission) o2);
6784:
6785: result = status1.compareTo(status2);
6786: } else if (m_criteria.equals(SORTED_SUBMISSION_BY_GRADE)) {
6787: // sort by submission grade
6788: String grade1 = ((AssignmentSubmission) o1).getGrade();
6789: String grade2 = ((AssignmentSubmission) o2).getGrade();
6790: if (grade1 == null) {
6791: grade1 = "";
6792: }
6793: if (grade2 == null) {
6794: grade2 = "";
6795: }
6796:
6797: // if scale is points
6798: if ((((AssignmentSubmission) o1).getAssignment()
6799: .getContent().getTypeOfGrade() == 3)
6800: && ((((AssignmentSubmission) o2)
6801: .getAssignment().getContent()
6802: .getTypeOfGrade() == 3))) {
6803: if (grade1.equals("")) {
6804: result = -1;
6805: } else if (grade2.equals("")) {
6806: result = 1;
6807: } else {
6808: result = (new Integer(grade1)).intValue() > (new Integer(
6809: grade2)).intValue() ? 1 : -1;
6810:
6811: }
6812: } else {
6813: result = grade1.compareTo(grade2);
6814: }
6815: } else if (m_criteria.equals(SORTED_SUBMISSION_BY_GRADE)) {
6816: // sort by submission grade
6817: String grade1 = ((AssignmentSubmission) o1).getGrade();
6818: String grade2 = ((AssignmentSubmission) o2).getGrade();
6819: if (grade1 == null) {
6820: grade1 = "";
6821: }
6822: if (grade2 == null) {
6823: grade2 = "";
6824: }
6825:
6826: // if scale is points
6827: if ((((AssignmentSubmission) o1).getAssignment()
6828: .getContent().getTypeOfGrade() == 3)
6829: && ((((AssignmentSubmission) o2)
6830: .getAssignment().getContent()
6831: .getTypeOfGrade() == 3))) {
6832: if (grade1.equals("")) {
6833: result = -1;
6834: } else if (grade2.equals("")) {
6835: result = 1;
6836: } else {
6837: result = (new Integer(grade1)).intValue() > (new Integer(
6838: grade2)).intValue() ? 1 : -1;
6839:
6840: }
6841: } else {
6842: result = grade1.compareTo(grade2);
6843: }
6844: } else if (m_criteria
6845: .equals(SORTED_SUBMISSION_BY_MAX_GRADE)) {
6846: Assignment a1 = ((AssignmentSubmission) o1)
6847: .getAssignment();
6848: Assignment a2 = ((AssignmentSubmission) o2)
6849: .getAssignment();
6850: String maxGrade1 = maxGrade(a1.getContent()
6851: .getTypeOfGrade(), a1);
6852: String maxGrade2 = maxGrade(a2.getContent()
6853: .getTypeOfGrade(), a2);
6854:
6855: try {
6856: // do integer comparation inside point grade type
6857: int max1 = Integer.parseInt(maxGrade1);
6858: int max2 = Integer.parseInt(maxGrade2);
6859: result = (max1 < max2) ? -1 : 1;
6860: } catch (NumberFormatException e) {
6861: // otherwise do an alpha-compare
6862: result = maxGrade1.compareTo(maxGrade2);
6863: }
6864: } else if (m_criteria.equals(SORTED_SUBMISSION_BY_RELEASED)) {
6865: // sort by submission released
6866: String released1 = (new Boolean(
6867: ((AssignmentSubmission) o1).getGradeReleased()))
6868: .toString();
6869: String released2 = (new Boolean(
6870: ((AssignmentSubmission) o2).getGradeReleased()))
6871: .toString();
6872:
6873: result = released1.compareTo(released2);
6874: } else if (m_criteria
6875: .equals(SORTED_SUBMISSION_BY_ASSIGNMENT)) {
6876: // sort by submission's assignment
6877: String title1 = ((AssignmentSubmission) o1)
6878: .getAssignment().getContent().getTitle();
6879: String title2 = ((AssignmentSubmission) o2)
6880: .getAssignment().getContent().getTitle();
6881:
6882: result = title1.toLowerCase().compareTo(
6883: title2.toLowerCase());
6884: }
6885:
6886: // sort ascending or descending
6887: if (m_asc.equals(Boolean.FALSE.toString())) {
6888: result = -result;
6889: }
6890: return result;
6891: } // compare
6892:
6893: /**
6894: * get the submissin status
6895: */
6896: private String getSubmissionStatus(SessionState state,
6897: AssignmentSubmission s) {
6898: String status = "";
6899: if (s.getReturned()) {
6900: if (s.getTimeReturned() != null
6901: && s.getTimeSubmitted() != null
6902: && s.getTimeReturned().before(
6903: s.getTimeSubmitted())) {
6904: status = rb.getString("listsub.resubmi");
6905: } else {
6906: status = rb.getString("gen.returned");
6907: }
6908: } else if (s.getGraded()) {
6909: if (state.getAttribute(WITH_GRADES) != null
6910: && ((Boolean) state.getAttribute(WITH_GRADES))
6911: .booleanValue()) {
6912: status = rb.getString("grad3");
6913: } else {
6914: status = rb.getString("gen.commented");
6915: }
6916: } else {
6917: status = rb.getString("gen.ung1");
6918: }
6919:
6920: return status;
6921:
6922: } // getSubmissionStatus
6923:
6924: /**
6925: * get the status string of assignment
6926: */
6927: private String getAssignmentStatus(Assignment a) {
6928: String status = "";
6929: Time currentTime = TimeService.newTime();
6930:
6931: if (a.getDraft())
6932: status = rb.getString("draft2");
6933: else if (a.getOpenTime().after(currentTime))
6934: status = rb.getString("notope");
6935: else if (a.getDueTime().after(currentTime))
6936: status = rb.getString("ope");
6937: else if ((a.getCloseTime() != null)
6938: && (a.getCloseTime().before(currentTime)))
6939: status = rb.getString("clos");
6940: else
6941: status = rb.getString("due2");
6942: return status;
6943: } // getAssignmentStatus
6944:
6945: /**
6946: * get submission status
6947: */
6948: private String getSubmissionStatus(
6949: AssignmentSubmission submission, Assignment assignment) {
6950: String status = "";
6951:
6952: if (submission != null)
6953: if (submission.getSubmitted())
6954: if (submission.getGraded()
6955: && submission.getGradeReleased())
6956: status = rb.getString("grad3");
6957: else if (submission.getReturned())
6958: status = rb.getString("return")
6959: + " "
6960: + submission.getTimeReturned()
6961: .toStringLocalFull();
6962: else {
6963: status = rb.getString("submitt")
6964: + submission.getTimeSubmitted()
6965: .toStringLocalFull();
6966: if (submission.getTimeSubmitted().after(
6967: assignment.getDueTime()))
6968: status = status + rb.getString("late");
6969: }
6970: else
6971: status = rb.getString("inpro");
6972: else
6973: status = rb.getString("notsta");
6974:
6975: return status;
6976:
6977: } // getSubmissionStatus
6978:
6979: /**
6980: * get assignment maximun grade available based on the assignment grade type
6981: *
6982: * @param gradeType
6983: * The int value of grade type
6984: * @param a
6985: * The assignment object
6986: * @return The max grade String
6987: */
6988: private String maxGrade(int gradeType, Assignment a) {
6989: String maxGrade = "";
6990:
6991: if (gradeType == -1) {
6992: // Grade type not set
6993: maxGrade = rb.getString("granotset");
6994: } else if (gradeType == 1) {
6995: // Ungraded grade type
6996: maxGrade = rb.getString("nogra");
6997: } else if (gradeType == 2) {
6998: // Letter grade type
6999: maxGrade = "A";
7000: } else if (gradeType == 3) {
7001: // Score based grade type
7002: maxGrade = Integer.toString(a.getContent()
7003: .getMaxGradePoint());
7004: } else if (gradeType == 4) {
7005: // Pass/fail grade type
7006: maxGrade = rb.getString("pass2");
7007: } else if (gradeType == 5) {
7008: // Grade type that only requires a check
7009: maxGrade = rb.getString("check2");
7010: }
7011:
7012: return maxGrade;
7013:
7014: } // maxGrade
7015:
7016: } // DiscussionComparator
7017:
7018: /**
7019: * Fire up the permissions editor
7020: */
7021: public void doPermissions(RunData data) {
7022: SessionState state = ((JetspeedRunData) data)
7023: .getPortletSessionState(((JetspeedRunData) data)
7024: .getJs_peid());
7025: if (!alertGlobalNavigation(state, data)) {
7026: // we are changing the view, so start with first page again.
7027: resetPaging(state);
7028:
7029: // clear search form
7030: doSearch_clear(data, null);
7031:
7032: if (SiteService.allowUpdateSite((String) state
7033: .getAttribute(STATE_CONTEXT_STRING))) {
7034: // get into helper mode with this helper tool
7035: startHelper(data.getRequest(),
7036: "sakai.permissions.helper");
7037:
7038: String contextString = (String) state
7039: .getAttribute(STATE_CONTEXT_STRING);
7040: String siteRef = SiteService
7041: .siteReference(contextString);
7042:
7043: // setup for editing the permissions of the site for this tool, using the roles of this site, too
7044: state.setAttribute(PermissionsHelper.TARGET_REF,
7045: siteRef);
7046:
7047: // ... with this description
7048: state.setAttribute(PermissionsHelper.DESCRIPTION, rb
7049: .getString("setperfor")
7050: + " "
7051: + SiteService.getSiteDisplay(contextString));
7052:
7053: // ... showing only locks that are prpefixed with this
7054: state.setAttribute(PermissionsHelper.PREFIX, "asn.");
7055:
7056: // disable auto-updates while leaving the list view
7057: justDelivered(state);
7058: }
7059:
7060: // reset the global navigaion alert flag
7061: if (state.getAttribute(ALERT_GLOBAL_NAVIGATION) != null) {
7062: state.removeAttribute(ALERT_GLOBAL_NAVIGATION);
7063: }
7064:
7065: // switching back to assignment list view
7066: state.setAttribute(STATE_SELECTED_VIEW,
7067: MODE_LIST_ASSIGNMENTS);
7068: doList_assignments(data);
7069: }
7070:
7071: } // doPermissions
7072:
7073: /**
7074: * transforms the Iterator to Vector
7075: */
7076: private Vector iterator_to_vector(Iterator l) {
7077: Vector v = new Vector();
7078: while (l.hasNext()) {
7079: v.add(l.next());
7080: }
7081: return v;
7082: } // iterator_to_vector
7083:
7084: /**
7085: * Implement this to return alist of all the resources that there are to page. Sort them as appropriate.
7086: */
7087: protected List readResourcesPage(SessionState state, int first,
7088: int last) {
7089:
7090: List returnResources = (List) state
7091: .getAttribute(STATE_PAGEING_TOTAL_ITEMS);
7092:
7093: PagingPosition page = new PagingPosition(first, last);
7094: page.validate(returnResources.size());
7095: returnResources = returnResources.subList(page.getFirst() - 1,
7096: page.getLast());
7097:
7098: return returnResources;
7099:
7100: } // readAllResources
7101:
7102: /*
7103: * (non-Javadoc)
7104: *
7105: * @see org.sakaiproject.cheftool.PagedResourceActionII#sizeResources(org.sakaiproject.service.framework.session.SessionState)
7106: */
7107: protected int sizeResources(SessionState state) {
7108: String mode = (String) state.getAttribute(STATE_MODE);
7109: String contextString = (String) state
7110: .getAttribute(STATE_CONTEXT_STRING);
7111: // all the resources for paging
7112: List returnResources = new Vector();
7113:
7114: boolean allowAddAssignment = AssignmentService
7115: .allowAddAssignment(contextString);
7116: if (mode.equalsIgnoreCase(MODE_LIST_ASSIGNMENTS)) {
7117: String view = "";
7118: if (state.getAttribute(STATE_SELECTED_VIEW) != null) {
7119: view = (String) state.getAttribute(STATE_SELECTED_VIEW);
7120: }
7121:
7122: if (allowAddAssignment
7123: && view.equals(MODE_LIST_ASSIGNMENTS)) {
7124: // read all Assignments
7125: returnResources = AssignmentService
7126: .getListAssignmentsForContext((String) state
7127: .getAttribute(STATE_CONTEXT_STRING));
7128: } else if (allowAddAssignment
7129: && view.equals(MODE_STUDENT_VIEW)
7130: || !allowAddAssignment) {
7131: // in the student list view of assignments
7132: Iterator assignments = AssignmentService
7133: .getAssignmentsForContext(contextString);
7134: Time currentTime = TimeService.newTime();
7135: while (assignments.hasNext()) {
7136: Assignment a = (Assignment) assignments.next();
7137: try {
7138: String deleted = a
7139: .getProperties()
7140: .getProperty(
7141: ResourceProperties.PROP_ASSIGNMENT_DELETED);
7142: if (deleted == null || deleted.equals("")) {
7143: // show not deleted assignments
7144: Time openTime = a.getOpenTime();
7145: if (openTime != null
7146: && currentTime.after(openTime)
7147: && !a.getDraft()) {
7148: returnResources.add(a);
7149: }
7150: } else if (deleted
7151: .equalsIgnoreCase(Boolean.TRUE
7152: .toString())
7153: && AssignmentService.getSubmission(a
7154: .getReference(), (User) state
7155: .getAttribute(STATE_USER)) != null) {
7156: // and those deleted assignments but the user has made submissions to them
7157: returnResources.add(a);
7158: }
7159: } catch (IdUnusedException e) {
7160: addAlert(state, rb.getString("cannotfin3"));
7161: } catch (PermissionException e) {
7162: addAlert(state, rb.getString("youarenot14"));
7163: }
7164: }
7165: }
7166: } else if (mode
7167: .equalsIgnoreCase(MODE_INSTRUCTOR_REPORT_SUBMISSIONS)) {
7168: Vector submissions = new Vector();
7169:
7170: Vector assignments = iterator_to_vector(AssignmentService
7171: .getAssignmentsForContext((String) state
7172: .getAttribute(STATE_CONTEXT_STRING)));
7173: if (assignments.size() > 0) {
7174: // users = AssignmentService.allowAddSubmissionUsers (((Assignment)assignments.get(0)).getReference ());
7175: }
7176:
7177: for (int j = 0; j < assignments.size(); j++) {
7178: Assignment a = (Assignment) assignments.get(j);
7179: String deleted = a.getProperties().getProperty(
7180: ResourceProperties.PROP_ASSIGNMENT_DELETED);
7181: if ((deleted == null || deleted.equals(""))
7182: && (!a.getDraft())) {
7183: try {
7184: Vector assignmentSubmissions = iterator_to_vector(AssignmentService
7185: .getSubmissions(a));
7186: for (int k = 0; k < assignmentSubmissions
7187: .size(); k++) {
7188: AssignmentSubmission s = (AssignmentSubmission) assignmentSubmissions
7189: .get(k);
7190: if (s != null
7191: && (s.getSubmitted() || (s
7192: .getReturned() && (s
7193: .getTimeLastModified()
7194: .before(s.getTimeReturned()))))) {
7195: // has been subitted or has been returned and not work on it yet
7196: submissions.add(s);
7197: } // if-else
7198: }
7199: } catch (Exception e) {
7200: }
7201: }
7202: }
7203:
7204: returnResources = submissions;
7205: } else if (mode
7206: .equalsIgnoreCase(MODE_INSTRUCTOR_GRADE_ASSIGNMENT)) {
7207: try {
7208: Assignment a = AssignmentService
7209: .getAssignment((String) state
7210: .getAttribute(EXPORT_ASSIGNMENT_REF));
7211: Iterator submissionsIterator = AssignmentService
7212: .getSubmissions(a);
7213: List submissions = new Vector();
7214: while (submissionsIterator.hasNext()) {
7215: submissions.add(submissionsIterator.next());
7216: }
7217:
7218: // get all active site users
7219: String authzGroupId = SiteService
7220: .siteReference(contextString);
7221:
7222: // all users that can submit
7223: List allowAddSubmissionUsers = AssignmentService
7224: .allowAddSubmissionUsers((String) state
7225: .getAttribute(EXPORT_ASSIGNMENT_REF));
7226:
7227: try {
7228: AuthzGroup group = AuthzGroupService
7229: .getAuthzGroup(authzGroupId);
7230: Set grants = group.getUsers();
7231: for (Iterator iUserIds = grants.iterator(); iUserIds
7232: .hasNext();) {
7233: String userId = (String) iUserIds.next();
7234: try {
7235: User u = UserDirectoryService
7236: .getUser(userId);
7237: // only include those users that can submit to this assignment
7238: if (allowAddSubmissionUsers.contains(u)) {
7239: boolean found = false;
7240: for (int i = 0; !found
7241: && i < submissions.size(); i++) {
7242: AssignmentSubmission s = (AssignmentSubmission) submissions
7243: .get(i);
7244: if (s.getSubmitterIds().contains(
7245: userId)) {
7246: returnResources
7247: .add(new UserSubmission(
7248: u, s));
7249: found = true;
7250: }
7251: }
7252:
7253: // add those users who haven't made any submissions
7254: if (!found) {
7255: returnResources
7256: .add(new UserSubmission(u,
7257: null));
7258: }
7259: }
7260: } catch (Exception e) {
7261: Log.warn("chef", this + e.getMessage()
7262: + " userId = " + userId);
7263: }
7264: }
7265: } catch (Exception e) {
7266: Log.warn("chef", e.getMessage() + " authGroupId="
7267: + authzGroupId);
7268: }
7269:
7270: } catch (IdUnusedException e) {
7271: addAlert(state, rb.getString("cannotfin3"));
7272: } catch (PermissionException e) {
7273: addAlert(state, rb.getString("youarenot14"));
7274: }
7275:
7276: }
7277:
7278: // sort them all
7279: String ascending = "true";
7280: String sort = "";
7281: ascending = (String) state.getAttribute(SORTED_ASC);
7282: sort = (String) state.getAttribute(SORTED_BY);
7283: if (mode.equalsIgnoreCase(MODE_INSTRUCTOR_GRADE_ASSIGNMENT)
7284: && !sort.startsWith("sorted_grade_submission_by")) {
7285: ascending = (String) state
7286: .getAttribute(SORTED_GRADE_SUBMISSION_ASC);
7287: sort = (String) state
7288: .getAttribute(SORTED_GRADE_SUBMISSION_BY);
7289: } else if (mode
7290: .equalsIgnoreCase(MODE_INSTRUCTOR_REPORT_SUBMISSIONS)
7291: && sort.startsWith("sorted_submission_by")) {
7292: ascending = (String) state
7293: .getAttribute(SORTED_SUBMISSION_ASC);
7294: sort = (String) state.getAttribute(SORTED_SUBMISSION_BY);
7295: } else {
7296: ascending = (String) state.getAttribute(SORTED_ASC);
7297: sort = (String) state.getAttribute(SORTED_BY);
7298: }
7299:
7300: if ((returnResources.size() > 1)
7301: && !mode
7302: .equalsIgnoreCase(MODE_INSTRUCTOR_VIEW_STUDENTS_ASSIGNMENT)) {
7303: Collections.sort(returnResources, new AssignmentComparator(
7304: state, sort, ascending));
7305: }
7306:
7307: // record the total item number
7308: state.setAttribute(STATE_PAGEING_TOTAL_ITEMS, returnResources);
7309:
7310: return returnResources.size();
7311: }
7312:
7313: public void doView(RunData data) {
7314: SessionState state = ((JetspeedRunData) data)
7315: .getPortletSessionState(((JetspeedRunData) data)
7316: .getJs_peid());
7317: if (!alertGlobalNavigation(state, data)) {
7318: // we are changing the view, so start with first page again.
7319: resetPaging(state);
7320:
7321: // clear search form
7322: doSearch_clear(data, null);
7323:
7324: String viewMode = data.getParameters().getString("view");
7325: state.setAttribute(STATE_SELECTED_VIEW, viewMode);
7326:
7327: if (viewMode.equals(MODE_LIST_ASSIGNMENTS)) {
7328: doList_assignments(data);
7329: } else if (viewMode
7330: .equals(MODE_INSTRUCTOR_VIEW_STUDENTS_ASSIGNMENT)) {
7331: doView_students_assignment(data);
7332: } else if (viewMode
7333: .equals(MODE_INSTRUCTOR_REPORT_SUBMISSIONS)) {
7334: doReport_submissions(data);
7335: } else if (viewMode.equals(MODE_STUDENT_VIEW)) {
7336: doView_student(data);
7337: }
7338:
7339: // reset the global navigaion alert flag
7340: if (state.getAttribute(ALERT_GLOBAL_NAVIGATION) != null) {
7341: state.removeAttribute(ALERT_GLOBAL_NAVIGATION);
7342: }
7343: }
7344:
7345: } // doView
7346:
7347: /**
7348: * put those variables related to 2ndToolbar into context
7349: */
7350: private void add2ndToolbarFields(RunData data, Context context) {
7351: SessionState state = ((JetspeedRunData) data)
7352: .getPortletSessionState(((JetspeedRunData) data)
7353: .getJs_peid());
7354:
7355: context.put("totalPageNumber", new Integer(
7356: totalPageNumber(state)));
7357: context.put("form_search", FORM_SEARCH);
7358: context.put("formPageNumber", FORM_PAGE_NUMBER);
7359: context.put("prev_page_exists", state
7360: .getAttribute(STATE_PREV_PAGE_EXISTS));
7361: context.put("next_page_exists", state
7362: .getAttribute(STATE_NEXT_PAGE_EXISTS));
7363: context.put("current_page", state
7364: .getAttribute(STATE_CURRENT_PAGE));
7365: context.put("selectedView", state.getAttribute(STATE_MODE));
7366:
7367: } // add2ndToolbarFields
7368:
7369: /**
7370: * valid grade?
7371: */
7372: private void validPointGrade(SessionState state, String grade) {
7373: if (grade != null && !grade.equals("")) {
7374: if (grade.startsWith("-")) {
7375: // check for negative sign
7376: addAlert(state, rb.getString("plesuse3"));
7377: } else {
7378: int index = grade.indexOf(".");
7379: if (index != -1) {
7380: // when there is decimal points inside the grade, scale the number by 10
7381: // but only one decimal place is supported
7382: // for example, change 100.0 to 1000
7383: if (!grade.equals(".")) {
7384: if (grade.length() > index + 2) {
7385: // if there are more than one decimal point
7386: addAlert(state, rb.getString("plesuse2"));
7387: } else {
7388: // decimal points is the only allowed character inside grade
7389: // replace it with '1', and try to parse the new String into int
7390: String gradeString = (grade.endsWith(".")) ? grade
7391: .substring(0, index).concat("0")
7392: : grade.substring(0, index).concat(
7393: grade.substring(index + 1));
7394: try {
7395: Integer.parseInt(gradeString);
7396: } catch (NumberFormatException e) {
7397: alertInvalidPoint(state, gradeString);
7398: }
7399: }
7400: } else {
7401: // grade is "."
7402: addAlert(state, rb.getString("plesuse1"));
7403: }
7404: } else {
7405: // There is no decimal point; should be int number
7406: String gradeString = grade + "0";
7407: try {
7408: Integer.parseInt(gradeString);
7409: } catch (NumberFormatException e) {
7410: alertInvalidPoint(state, gradeString);
7411: }
7412: }
7413: }
7414: }
7415:
7416: } // validPointGrade
7417:
7418: private void alertInvalidPoint(SessionState state, String grade) {
7419: String VALID_CHARS_FOR_INT = "-01234567890";
7420:
7421: boolean invalid = false;
7422: // case 1: contains invalid char for int
7423: for (int i = 0; i < grade.length() && !invalid; i++) {
7424: char c = grade.charAt(i);
7425: if (VALID_CHARS_FOR_INT.indexOf(c) == -1) {
7426: invalid = true;
7427: }
7428: }
7429: if (invalid) {
7430: addAlert(state, rb.getString("plesuse1"));
7431: } else {
7432: int maxInt = Integer.MAX_VALUE / 10;
7433: int maxDec = Integer.MAX_VALUE - maxInt * 10;
7434: // case 2: Due to our internal scaling, input String is larger than Integer.MAX_VALUE/10
7435: addAlert(state, rb.getString("plesuse4") + maxInt + "."
7436: + maxDec + ".");
7437: }
7438: }
7439:
7440: /**
7441: * display grade properly
7442: */
7443: private String displayGrade(SessionState state, String grade) {
7444: if (state.getAttribute(STATE_MESSAGE) == null) {
7445: if (grade != null && (grade.length() >= 1)) {
7446: if (grade.indexOf(".") != -1) {
7447: if (grade.startsWith(".")) {
7448: grade = "0".concat(grade);
7449: } else if (grade.endsWith(".")) {
7450: grade = grade.concat("0");
7451: }
7452: } else {
7453: try {
7454: Integer.parseInt(grade);
7455: grade = grade.substring(0, grade.length() - 1)
7456: + "."
7457: + grade.substring(grade.length() - 1);
7458: } catch (NumberFormatException e) {
7459: alertInvalidPoint(state, grade);
7460: }
7461: }
7462: } else {
7463: grade = "";
7464: }
7465: }
7466: return grade;
7467:
7468: } // displayGrade
7469:
7470: /**
7471: * scale the point value by 10 if there is a valid point grade
7472: */
7473: private String scalePointGrade(SessionState state, String point) {
7474: validPointGrade(state, point);
7475: if (state.getAttribute(STATE_MESSAGE) == null) {
7476: if (point != null && (point.length() >= 1)) {
7477: // when there is decimal points inside the grade, scale the number by 10
7478: // but only one decimal place is supported
7479: // for example, change 100.0 to 1000
7480: int index = point.indexOf(".");
7481: if (index != -1) {
7482: if (index == 0) {
7483: // if the point is the first char, add a 0 for the integer part
7484: point = "0".concat(point.substring(1));
7485: } else if (index < point.length() - 1) {
7486: // use scale integer for gradePoint
7487: point = point.substring(0, index)
7488: + point.substring(index + 1);
7489: } else {
7490: // decimal point is the last char
7491: point = point.substring(0, index) + "0";
7492: }
7493: } else {
7494: // if there is no decimal place, scale up the integer by 10
7495: point = point + "0";
7496: }
7497:
7498: // filter out the "zero grade"
7499: if (point.equals("00")) {
7500: point = "0";
7501: }
7502: }
7503: }
7504: return point;
7505:
7506: } // scalePointGrade
7507:
7508: /**
7509: * Processes formatted text that is coming back from the browser (from the formatted text editing widget).
7510: *
7511: * @param state
7512: * Used to pass in any user-visible alerts or errors when processing the text
7513: * @param strFromBrowser
7514: * The string from the browser
7515: * @param checkForFormattingErrors
7516: * Whether to check for formatted text errors - if true, look for errors in the formatted text. If false, accept the formatted text without looking for errors.
7517: * @return The formatted text
7518: */
7519: private String processFormattedTextFromBrowser(SessionState state,
7520: String strFromBrowser, boolean checkForFormattingErrors) {
7521: StringBuffer alertMsg = new StringBuffer();
7522: try {
7523: boolean replaceWhitespaceTags = true;
7524: String text = FormattedText.processFormattedText(
7525: strFromBrowser, alertMsg, checkForFormattingErrors,
7526: replaceWhitespaceTags);
7527: if (alertMsg.length() > 0)
7528: addAlert(state, alertMsg.toString());
7529: return text;
7530: } catch (Exception e) {
7531: Log.warn("chef", this + ": ", e);
7532: return strFromBrowser;
7533: }
7534: }
7535:
7536: /**
7537: * Processes the given assignmnent feedback text, as returned from the user's browser. Makes sure that the Chef-style markup {{like this}} is properly balanced.
7538: */
7539: private String processAssignmentFeedbackFromBrowser(
7540: SessionState state, String strFromBrowser) {
7541: if (strFromBrowser == null || strFromBrowser.length() == 0)
7542: return strFromBrowser;
7543:
7544: StringBuffer buf = new StringBuffer(strFromBrowser);
7545: int pos = -1;
7546: int numopentags = 0;
7547:
7548: while ((pos = buf.indexOf("{{")) != -1) {
7549: buf.replace(pos, pos + "{{".length(), "<ins>");
7550: numopentags++;
7551: }
7552:
7553: while ((pos = buf.indexOf("}}")) != -1) {
7554: buf.replace(pos, pos + "}}".length(), "</ins>");
7555: numopentags--;
7556: }
7557:
7558: while (numopentags > 0) {
7559: buf.append("</ins>");
7560: numopentags--;
7561: }
7562:
7563: boolean checkForFormattingErrors = false; // so that grading isn't held up by formatting errors
7564: buf = new StringBuffer(processFormattedTextFromBrowser(state,
7565: buf.toString(), checkForFormattingErrors));
7566:
7567: while ((pos = buf.indexOf("<ins>")) != -1) {
7568: buf.replace(pos, pos + "<ins>".length(), "{{");
7569: }
7570:
7571: while ((pos = buf.indexOf("</ins>")) != -1) {
7572: buf.replace(pos, pos + "</ins>".length(), "}}");
7573: }
7574:
7575: return buf.toString();
7576: }
7577:
7578: /**
7579: * Called to deal with old Chef-style assignment feedback annotation, {{like this}}.
7580: *
7581: * @param value
7582: * A formatted text string that may contain {{}} style markup
7583: * @return HTML ready to for display on a browser
7584: */
7585: public static String escapeAssignmentFeedback(String value) {
7586: if (value == null || value.length() == 0)
7587: return value;
7588:
7589: value = fixAssignmentFeedback(value);
7590:
7591: StringBuffer buf = new StringBuffer(value);
7592: int pos = -1;
7593:
7594: while ((pos = buf.indexOf("{{")) != -1) {
7595: buf.replace(pos, pos + "{{".length(),
7596: "<span class='highlight'>");
7597: }
7598:
7599: while ((pos = buf.indexOf("}}")) != -1) {
7600: buf.replace(pos, pos + "}}".length(), "</span>");
7601: }
7602:
7603: return FormattedText.escapeHtmlFormattedText(buf.toString());
7604: }
7605:
7606: /**
7607: * Escapes the given assignment feedback text, to be edited as formatted text (perhaps using the formatted text widget)
7608: */
7609: public static String escapeAssignmentFeedbackTextarea(String value) {
7610: if (value == null || value.length() == 0)
7611: return value;
7612:
7613: value = fixAssignmentFeedback(value);
7614:
7615: return FormattedText.escapeHtmlFormattedTextarea(value);
7616: }
7617:
7618: /**
7619: * Apply the fix to pre 1.1.05 assignments submissions feedback.
7620: */
7621: private static String fixAssignmentFeedback(String value) {
7622: if (value == null || value.length() == 0)
7623: return value;
7624:
7625: StringBuffer buf = new StringBuffer(value);
7626: int pos = -1;
7627:
7628: // <br/> -> \n
7629: while ((pos = buf.indexOf("<br/>")) != -1) {
7630: buf.replace(pos, pos + "<br/>".length(), "\n");
7631: }
7632:
7633: // <span class='chefAlert'>( -> {{
7634: while ((pos = buf.indexOf("<span class='chefAlert'>(")) != -1) {
7635: buf.replace(pos,
7636: pos + "<span class='chefAlert'>(".length(), "{{");
7637: }
7638:
7639: // )</span> -> }}
7640: while ((pos = buf.indexOf(")</span>")) != -1) {
7641: buf.replace(pos, pos + ")</span>".length(), "}}");
7642: }
7643:
7644: while ((pos = buf.indexOf("<ins>")) != -1) {
7645: buf.replace(pos, pos + "<ins>".length(), "{{");
7646: }
7647:
7648: while ((pos = buf.indexOf("</ins>")) != -1) {
7649: buf.replace(pos, pos + "</ins>".length(), "}}");
7650: }
7651:
7652: return buf.toString();
7653:
7654: } // fixAssignmentFeedback
7655:
7656: /**
7657: * Apply the fix to pre 1.1.05 assignments submissions feedback.
7658: */
7659: public static String showPrevFeedback(String value) {
7660: if (value == null || value.length() == 0)
7661: return value;
7662:
7663: StringBuffer buf = new StringBuffer(value);
7664: int pos = -1;
7665:
7666: // <br/> -> \n
7667: while ((pos = buf.indexOf("\n")) != -1) {
7668: buf.replace(pos, pos + "\n".length(), "<br />");
7669: }
7670:
7671: return buf.toString();
7672:
7673: } // showPrevFeedback
7674:
7675: private boolean alertGlobalNavigation(SessionState state,
7676: RunData data) {
7677: String mode = (String) state.getAttribute(STATE_MODE);
7678: ParameterParser params = data.getParameters();
7679:
7680: if (mode.equals(MODE_STUDENT_VIEW_SUBMISSION)
7681: || mode.equals(MODE_STUDENT_PREVIEW_SUBMISSION)
7682: || mode.equals(MODE_STUDENT_VIEW_GRADE)
7683: || mode.equals(MODE_INSTRUCTOR_NEW_EDIT_ASSIGNMENT)
7684: || mode.equals(MODE_INSTRUCTOR_DELETE_ASSIGNMENT)
7685: || mode.equals(MODE_INSTRUCTOR_GRADE_SUBMISSION)
7686: || mode
7687: .equals(MODE_INSTRUCTOR_PREVIEW_GRADE_SUBMISSION)
7688: || mode.equals(MODE_INSTRUCTOR_PREVIEW_ASSIGNMENT)
7689: || mode.equals(MODE_INSTRUCTOR_VIEW_ASSIGNMENT)) {
7690: if (state.getAttribute(ALERT_GLOBAL_NAVIGATION) == null) {
7691: addAlert(state, rb.getString("alert.globalNavi"));
7692: state.setAttribute(ALERT_GLOBAL_NAVIGATION,
7693: Boolean.TRUE);
7694:
7695: if (mode.equals(MODE_STUDENT_VIEW_SUBMISSION)) {
7696: // retrieve the submission text (as formatted text)
7697: boolean checkForFormattingErrors = true; // the student is submitting something - so check for errors
7698: String text = processFormattedTextFromBrowser(
7699: state,
7700: params.getCleanString(VIEW_SUBMISSION_TEXT),
7701: checkForFormattingErrors);
7702:
7703: state.setAttribute(VIEW_SUBMISSION_TEXT, text);
7704: if (params
7705: .getString(VIEW_SUBMISSION_HONOR_PLEDGE_YES) != null) {
7706: state.setAttribute(
7707: VIEW_SUBMISSION_HONOR_PLEDGE_YES,
7708: "true");
7709: }
7710: state.setAttribute(
7711: FilePickerHelper.FILE_PICKER_TITLE_TEXT, rb
7712: .getString("gen.addatt"));
7713:
7714: // TODO: file picker to save in dropbox? -ggolden
7715: // User[] users = { UserDirectoryService.getCurrentUser() };
7716: // state.setAttribute(ResourcesAction.STATE_SAVE_ATTACHMENT_IN_DROPBOX, users);
7717: } else if (mode
7718: .equals(MODE_INSTRUCTOR_NEW_EDIT_ASSIGNMENT)) {
7719: setNewAssignmentParameters(data, false);
7720: } else if (mode
7721: .equals(MODE_INSTRUCTOR_GRADE_SUBMISSION)) {
7722: readGradeForm(data, state, "read");
7723: }
7724:
7725: return true;
7726: }
7727: }
7728:
7729: return false;
7730:
7731: } // alertGlobalNavigation
7732:
7733: /**
7734: * Dispatch function inside add submission page
7735: */
7736: public void doRead_add_submission_form(RunData data) {
7737: String option = data.getParameters().getString("option");
7738: if (option.equals("cancel")) {
7739: // cancel
7740: doCancel_show_submission(data);
7741: } else if (option.equals("preview")) {
7742: // preview
7743: doPreview_submission(data);
7744: } else if (option.equals("save")) {
7745: // save draft
7746: doSave_submission(data);
7747: } else if (option.equals("post")) {
7748: // post
7749: doPost_submission(data);
7750: } else if (option.equals("revise")) {
7751: // done preview
7752: doDone_preview_submission(data);
7753: } else if (option.equals("attach")) {
7754: // attach
7755: doAttachments(data);
7756: }
7757: }
7758: }
|