public String getPoolNameToBeDrawn() { if ((sectionAuthorType != null) && (sectionAuthorType.equals(SectionDataIfc.RANDOM_DRAW_FROM_QUESTIONPOOL))) { if ("".equals(poolNameToBeDrawn)) { // after 2.2. poolNameToBeDrawn should not be an empty string // This is for backward compatibility, for versions prior 2.2, // we didn't store poolname in metadata so when a user deletes a pool used for random draw // assessment, exception occurs when viewing the assessment. The items are still there, but // it still needs to the original pool object to get the poolname for JSF display. // After 2.2 we save this information in section metadata. If users delete the pools we can // now still retrive the random draw pool names used in an assessment. QuestionPoolService qpservice = new QuestionPoolService(); QuestionPoolFacade poolfacade = qpservice.getPool(poolIdToBeDrawn, AgentFacade.getAgentString()); if (poolfacade != null) { return poolfacade.getTitle(); } // else the pool is no longer there return ""; } else { // get poolname from section metadata return poolNameToBeDrawn; } } return ""; }
// This sets the metString that holds the extended time info for the user private String extractMetaString(PublishedAssessmentFacade publishedAssessment) { short itemNum = 1; String meta = null; String extendedTimeData = publishedAssessment.getAssessmentMetaDataByLabel(EXTENDED_TIME_KEY + itemNum); while ((extendedTimeData != null) && (!extendedTimeData.equals(""))) { String[] extendedTimeItems = extendedTimeData.split("[|]"); // Get target user/group value String target = extendedTimeItems[0]; // If it's a group determine if user is a member boolean isMember = isUserInGroup(target); String userId = AgentFacade.getAgentString(); if (target.equals(userId) || isMember) { meta = extendedTimeData; } itemNum++; extendedTimeData = publishedAssessment.getAssessmentMetaDataByLabel(EXTENDED_TIME_KEY + itemNum); } return meta; }
public String confirmDeleteItem() { ItemService delegate = new ItemService(); String itemId = ContextUtil.lookupParam("itemid"); ItemFacade itemf = delegate.getItem(Long.valueOf(itemId), AgentFacade.getAgentString()); setItemToDelete(itemf); return "removeQuestion"; }
private boolean isUserInGroup(String groupId) { String realmId = "/site/" + siteId + "/group/" + groupId; boolean isMember = false; try { AuthzGroup group = authzGroupService.getAuthzGroup(realmId); if (group.getUserRole(AgentFacade.getAgentString()) != null) isMember = true; } catch (Exception e) { return false; // this isn't a group } return isMember; }
public java.util.ArrayList getItemContentsForRandomDraw() { // same ordering for each student ArrayList randomsample = new ArrayList(); long seed = (long) AgentFacade.getAgentString().hashCode(); Collections.shuffle(itemContents, new Random(seed)); int samplesize = numberToBeDrawn.intValue(); for (int i = 0; i < samplesize; i++) { randomsample.add(itemContents.get(i)); } return randomsample; }
/** * Derived property. * * @return ArrayList of model SelectItems */ public ArrayList getPoolSelectList() { poolListSelectItems = new ArrayList(); QuestionPoolService delegate = new QuestionPoolService(); ArrayList<QuestionPoolFacade> qplist = delegate.getBasicInfoOfAllPools(AgentFacade.getAgentString()); Iterator<QuestionPoolFacade> iter = qplist.iterator(); try { while (iter.hasNext()) { QuestionPoolFacade pool = (QuestionPoolFacade) iter.next(); // SAM-2269 - if the parent pool ID is greater than 0 (question pool IDs start at 1), get // the parent pool Long parentPoolID = pool.getParentPoolId(); QuestionPoolFacade parent = null; if (parentPoolID > 0) { for (QuestionPoolFacade qp : qplist) { if (parentPoolID.equals(qp.getQuestionPoolId())) { parent = qp; break; } } } // SAM-2269 - add the appropriate string to the list String original = pool.getDisplayName() + " (" + delegate.getCountItems(pool.getQuestionPoolId()) + ")"; if (parent != null) { poolListSelectItems.add( new SelectItem( pool.getQuestionPoolId().toString(), FormattedText.convertFormattedTextToPlaintext( parent.getDisplayName() + ": " + original))); } else { poolListSelectItems.add( new SelectItem( pool.getQuestionPoolId().toString(), FormattedText.convertFormattedTextToPlaintext(original))); } } } catch (Exception e) { throw new RuntimeException(e); } Collections.sort(poolListSelectItems, new ItemComparator()); return poolListSelectItems; }
/** * This will populate the StudentScoresBean with the data associated with the particular versioned * assessment based on the publishedId. * * @param publishedId String * @param bean StudentScoresBean * @return boolean */ public boolean studentScores(String publishedId, StudentScoresBean bean, boolean isValueChange) { log.debug("studentScores()"); try { // SAK-4121, do not pass studentName as f:param, will cause javascript error if name contains // apostrophe // bean.setStudentName(cu.lookupParam("studentName")); bean.setPublishedId(publishedId); String studentId = ContextUtil.lookupParam("studentid"); bean.setStudentId(studentId); AgentFacade agent = new AgentFacade(studentId); bean.setStudentName(agent.getFirstName() + " " + agent.getLastName()); bean.setLastName(agent.getLastName()); bean.setFirstName(agent.getFirstName()); bean.setAssessmentGradingId(ContextUtil.lookupParam("gradingData")); bean.setItemId(ContextUtil.lookupParam("itemId")); bean.setEmail(agent.getEmail()); DeliveryBean dbean = (DeliveryBean) ContextUtil.lookupBean("delivery"); dbean.setActionString("gradeAssessment"); DeliveryActionListener listener = new DeliveryActionListener(); listener.processAction(null); // Added for SAK-13930 DeliveryBean updatedDeliveryBean = (DeliveryBean) ContextUtil.lookupBean("delivery"); ArrayList parts = updatedDeliveryBean.getPageContents().getPartsContents(); Iterator iter = parts.iterator(); while (iter.hasNext()) { ArrayList items = ((SectionContentsBean) iter.next()).getItemContents(); Iterator iter2 = items.iterator(); while (iter2.hasNext()) { ItemContentsBean question = (ItemContentsBean) iter2.next(); if (question.getGradingComment() != null && !question.getGradingComment().equals("")) { question.setGradingComment( FormattedText.convertFormattedTextToPlaintext(question.getGradingComment())); } } } // End of SAK-13930 GradingService service = new GradingService(); AssessmentGradingData adata = (AssessmentGradingData) service.load(bean.getAssessmentGradingId(), false); bean.setComments(FormattedText.convertFormattedTextToPlaintext(adata.getComments())); buildItemContentsMap(dbean); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
/** * This will populate the QuestionScoresBean with the data associated with the particular * versioned assessment based on the publishedId. * * @todo Some of this code will change when we move this to Hibernate persistence. * @param publishedId String * @param bean QuestionScoresBean * @return boolean */ public boolean questionScores( String publishedId, QuestionScoresBean bean, boolean isValueChange) { log.debug("questionScores()"); try { PublishedAssessmentService pubService = new PublishedAssessmentService(); PublishedItemService pubItemService = new PublishedItemService(); // get the PublishedAssessment based on publishedId QuestionScoresBean questionBean = (QuestionScoresBean) ContextUtil.lookupBean("questionScores"); PublishedAssessmentIfc publishedAssessment = questionBean.getPublishedAssessment(); if (publishedAssessment == null) { publishedAssessment = pubService.getPublishedAssessment(publishedId); questionBean.setPublishedAssessment(publishedAssessment); } // build a hashMap (publishedItemId, publishedItem) HashMap publishedItemHash = pubService.preparePublishedItemHash(publishedAssessment); log.debug("questionScores(): publishedItemHash.size = " + publishedItemHash.size()); // build a hashMap (publishedItemTextId, publishedItemText) HashMap publishedItemTextHash = pubService.preparePublishedItemTextHash(publishedAssessment); log.debug("questionScores(): publishedItemTextHash.size = " + publishedItemTextHash.size()); HashMap publishedAnswerHash = pubService.preparePublishedAnswerHash(publishedAssessment); // re-attach session and load all lazy loaded parent/child stuff // Set<Long> publishedAnswerHashKeySet = publishedAnswerHash.keySet(); // // for (Long key : publishedAnswerHashKeySet) { // AnswerIfc answer = (AnswerIfc) publishedAnswerHash.get(key); // // if (!Hibernate.isInitialized(answer.getChildAnswerSet())) { // pubItemService.eagerFetchAnswer(answer); // } // } log.debug("questionScores(): publishedAnswerHash.size = " + publishedAnswerHash.size()); HashMap agentResultsByItemGradingIdMap = new HashMap(); GradingService delegate = new GradingService(); TotalScoresBean totalBean = (TotalScoresBean) ContextUtil.lookupBean("totalScores"); if (ContextUtil.lookupParam("sortBy") != null && !ContextUtil.lookupParam("sortBy").trim().equals("")) bean.setSortType(ContextUtil.lookupParam("sortBy")); String itemId = ContextUtil.lookupParam("itemId"); if (ContextUtil.lookupParam("newItemId") != null && !ContextUtil.lookupParam("newItemId").trim().equals("") && !ContextUtil.lookupParam("newItemId").trim().equals("null")) itemId = ContextUtil.lookupParam("newItemId"); if (ContextUtil.lookupParam("sortAscending") != null && !ContextUtil.lookupParam("sortAscending").trim().equals("")) { bean.setSortAscending( Boolean.valueOf(ContextUtil.lookupParam("sortAscending")).booleanValue()); } String which = bean.getAllSubmissions(); if (which == null && totalBean.getAllSubmissions() != null) { // use totalscore's selection which = totalBean.getAllSubmissions(); bean.setAllSubmissions(which); } totalBean.setSelectedSectionFilterValue( bean.getSelectedSectionFilterValue()); // set section pulldown if (bean.getSelectedSARationaleView() == null) { // if bean.showSARationaleInLine is null, then set inline to be // the default bean.setSelectedSARationaleView(QuestionScoresBean.SHOW_SA_RATIONALE_RESPONSES_INLINE); } if ("true".equalsIgnoreCase(totalBean.getAnonymous())) { boolean groupRelease = publishedAssessment .getAssessmentAccessControl() .getReleaseTo() .equals(AssessmentAccessControl.RELEASE_TO_SELECTED_GROUPS); if (groupRelease) { totalBean.setSelectedSectionFilterValue( TotalScoresBean.RELEASED_SECTIONS_GROUPS_SELECT_VALUE); } else { totalBean.setSelectedSectionFilterValue(TotalScoresBean.ALL_SECTIONS_SELECT_VALUE); } } bean.setPublishedId(publishedId); Date dueDate = null; HashMap map = getItemScores(Long.valueOf(publishedId), Long.valueOf(itemId), which, isValueChange); log.debug("questionScores(): map .size = " + map.size()); ResourceLoader rb = null; ArrayList allscores = new ArrayList(); Iterator keyiter = map.keySet().iterator(); while (keyiter.hasNext()) { allscores.addAll((ArrayList) map.get(keyiter.next())); } log.debug("questionScores(): allscores.size = " + allscores.size()); // / // now we need filter by sections selected ArrayList scores = new ArrayList(); // filtered list Map useridMap = totalBean.getUserIdMap(TotalScoresBean.CALLED_FROM_QUESTION_SCORE_LISTENER); bean.setUserIdMap(useridMap); log.debug("questionScores(): useridMap.size = " + useridMap.size()); /* * if ("true".equalsIgnoreCase(totalBean.getAnonymous())){ // skip * section filter if it is anonymous grading, SAK-4395, * scores.addAll(allscores); } */ if (totalBean.getReleaseToAnonymous()) { // skip section filter if it's published to anonymous users scores.addAll(allscores); } else { Iterator allscores_iter = allscores.iterator(); // get the Map of all users(keyed on userid) belong to the // selected sections while (allscores_iter.hasNext()) { // AssessmentGradingData data = (AssessmentGradingData) // allscores_iter.next(); ItemGradingData idata = (ItemGradingData) allscores_iter.next(); // String agentid = // idata.getAssessmentGrading().getAgentId(); String agentid = idata.getAgentId(); // now we only include scores of users belong to the // selected sections if (useridMap.containsKey(agentid)) { scores.add(idata); } } } log.debug("questionScores(): scores.size = " + scores.size()); Iterator iter = scores.iterator(); ArrayList agents = new ArrayList(); log.debug("questionScores(): calling populateSections "); populateSections( publishedAssessment, bean, totalBean, scores, pubService); // set up the Q1, Q2... links if (!iter.hasNext()) { // this section has no students log.debug("questionScores(): this section has no students"); bean.setAgents(agents); bean.setAllAgents(agents); bean.setTotalPeople(Integer.toString(bean.getAgents().size())); bean.setAnonymous(totalBean.getAnonymous()); // return true; } // List them by item and assessmentgradingid, so we can // group answers by item and save them for update use. HashMap scoresByItem = new HashMap(); while (iter.hasNext()) { ItemGradingData idata = (ItemGradingData) iter.next(); ItemTextIfc pubItemText = (ItemTextIfc) publishedItemTextHash.get(idata.getPublishedItemTextId()); AnswerIfc pubAnswer = (AnswerIfc) publishedAnswerHash.get(idata.getPublishedAnswerId()); ArrayList temp = (ArrayList) scoresByItem.get(idata.getAssessmentGradingId() + ":" + idata.getPublishedItemId()); if (temp == null) temp = new ArrayList(); // Very small numbers, so bubblesort is fast Iterator iter2 = temp.iterator(); ArrayList newList = new ArrayList(); boolean added = false; while (iter2.hasNext()) { ItemGradingData tmpData = (ItemGradingData) iter2.next(); ItemTextIfc tmpPublishedText = (ItemTextIfc) publishedItemTextHash.get(tmpData.getPublishedItemTextId()); AnswerIfc tmpAnswer = (AnswerIfc) publishedAnswerHash.get(tmpData.getPublishedAnswerId()); if (pubAnswer != null && tmpAnswer != null && !added && (pubItemText.getSequence().intValue() < tmpPublishedText.getSequence().intValue() || (pubItemText.getSequence().intValue() == tmpPublishedText.getSequence().intValue() && pubAnswer.getSequence().intValue() < tmpAnswer.getSequence().intValue()))) { newList.add(idata); added = true; } newList.add(tmpData); } if (!added) newList.add(idata); scoresByItem.put( idata.getAssessmentGradingId() + ":" + idata.getPublishedItemId(), newList); } log.debug("questionScores(): scoresByItem.size = " + scoresByItem.size()); bean.setScoresByItem(scoresByItem); try { bean.setAnonymous( publishedAssessment .getEvaluationModel() .getAnonymousGrading() .equals(EvaluationModel.ANONYMOUS_GRADING) ? "true" : "false"); } catch (RuntimeException e) { // log.info("No evaluation model."); bean.setAnonymous("false"); } // below properties don't seem to be used in jsf pages, try { bean.setLateHandling( publishedAssessment.getAssessmentAccessControl().getLateHandling().toString()); } catch (Exception e) { // log.info("No access control model."); bean.setLateHandling(AssessmentAccessControl.NOT_ACCEPT_LATE_SUBMISSION.toString()); } try { bean.setDueDate(publishedAssessment.getAssessmentAccessControl().getDueDate().toString()); dueDate = publishedAssessment.getAssessmentAccessControl().getDueDate(); } catch (RuntimeException e) { // log.info("No due date."); bean.setDueDate(new Date().toString()); } try { bean.setMaxScore(publishedAssessment.getEvaluationModel().getFixedTotalScore()); } catch (RuntimeException e) { double score = (double) 0.0; Iterator iter2 = publishedAssessment.getSectionArraySorted().iterator(); while (iter2.hasNext()) { SectionDataIfc sdata = (SectionDataIfc) iter2.next(); Iterator iter3 = sdata.getItemArraySortedForGrading().iterator(); while (iter3.hasNext()) { ItemDataIfc idata = (ItemDataIfc) iter3.next(); if (idata.getItemId().equals(Long.valueOf(itemId))) score = idata.getScore().doubleValue(); } } bean.setMaxScore(score); } // need to get id from somewhere else, not from data. data only // contains answered items , we want to return all items. // ItemDataIfc item = (ItemDataIfc) publishedItemHash.get(data.getPublishedItemId()); ItemDataIfc item = (ItemDataIfc) publishedItemHash.get(Long.valueOf(itemId)); if (item != null) { log.debug("item!=null steting type id = " + item.getTypeId().toString()); bean.setTypeId(item.getTypeId().toString()); bean.setItemId(item.getItemId().toString()); bean.setPartName(item.getSection().getSequence().toString()); bean.setItemName(item.getSequence().toString()); item.setHint("***"); // Keyword to not show student answer // for short answer/ essey question, if there is a model short // answer for this question // set haveModelShortAnswer to true if (item.getTypeId().equals(Long.valueOf(5))) { Iterator iterator = publishedAnswerHash.values().iterator(); while (iterator.hasNext()) { PublishedAnswer publishedAnswer = (PublishedAnswer) iterator.next(); if (publishedAnswer.getItem().getItemId().equals(item.getItemId())) { if (publishedAnswer.getText() == null || publishedAnswer.getText().equals("")) { bean.setHaveModelShortAnswer(false); } else { bean.setHaveModelShortAnswer(true); } break; } } } } else { log.debug("item==null "); } ArrayList deliveryItems = new ArrayList(); // so we can use the var if (item != null) deliveryItems.add(item); bean.setDeliveryItem(deliveryItems); if (ContextUtil.lookupParam("roleSelection") != null) { bean.setRoleSelection(ContextUtil.lookupParam("roleSelection")); } if (bean.getSortType() == null) { if (bean.getAnonymous().equals("true")) { bean.setSortType("totalAutoScore"); } else { bean.setSortType("lastName"); } } // recordingData encapsulates the inbeanation needed for recording. // set recording agent, agent assessmentId, // set course_assignment_context value // set max tries (0=unlimited), and 30 seconds max length // String courseContext = bean.getAssessmentName() + " total "; // Note this is HTTP-centric right now, we can't use in Faces // AuthoringHelper authoringHelper = new AuthoringHelper(); // authoringHelper.getRemoteUserID() needs servlet stuff // authoringHelper.getRemoteUserName() needs servlet stuff /* Dump the grading and agent information into AgentResults */ iter = scoresByItem.values().iterator(); while (iter.hasNext()) { AgentResults results = new AgentResults(); // Get all the answers for this question to put in one grading // row ArrayList answerList = (ArrayList) iter.next(); results.setItemGradingArrayList(answerList); Iterator iter2 = answerList.iterator(); ArrayList itemGradingAttachmentList = new ArrayList(); HashMap<Long, Set<String>> fibmap = new HashMap<Long, Set<String>>(); while (iter2.hasNext()) { ItemGradingData gdata = (ItemGradingData) iter2.next(); results.setItemGrading(gdata); itemGradingAttachmentList.addAll(gdata.getItemGradingAttachmentList()); agentResultsByItemGradingIdMap.put(gdata.getItemGradingId(), results); ItemTextIfc gdataPubItemText = (ItemTextIfc) publishedItemTextHash.get(gdata.getPublishedItemTextId()); AnswerIfc gdataAnswer = (AnswerIfc) publishedAnswerHash.get(gdata.getPublishedAnswerId()); // This all just gets the text of the answer to display String answerText = noAnswer; String rationale = ""; String fullAnswerText = noAnswer; // if question type = MC, MR, Survey, TF, Matching, if user // has not submit an answer // answerText = noAnswer. These question type do not use the // itemGrading.answerText field for // storing answers, thye use temGrading.publishedAnswerId to // make their selection if (bean.getTypeId().equals("1") || bean.getTypeId().equals("2") || bean.getTypeId().equals("12") || bean.getTypeId().equals("3") || bean.getTypeId().equals("4") || bean.getTypeId().equals("9") || bean.getTypeId().equals("13")) { if (gdataAnswer != null) answerText = gdataAnswer.getText(); } else { // this handles the other question types: SAQ, File // upload, Audio, FIB, Fill in Numeric // These question type use itemGrading.answetText to // store information about their answer if ((bean.getTypeId().equals("8") || bean.getTypeId().equals("11") || bean.getTypeId().equals("14")) && gdataAnswer == null) { answerText = ""; } else if (bean.getTypeId().equals("14")) { // gopalrc - EMI answerText = gdataPubItemText.getSequence() + ": " + gdataAnswer.getLabel(); } else { answerText = gdata.getAnswerText(); } } if ("4".equals(bean.getTypeId())) { if (rb == null) { rb = new ResourceLoader("org.sakaiproject.tool.assessment.bundle.EvaluationMessages"); } if ("true".equals(answerText)) { answerText = rb.getString("true_msg"); } else if ("false".equals(answerText)) { answerText = rb.getString("false_msg"); } } if (bean.getTypeId().equals("9")) { if (gdataPubItemText == null) { // the matching pair is deleted answerText = ""; } else { answerText = gdataPubItemText.getSequence() + ":" + answerText; } } if (bean.getTypeId().equals("8")) { if (gdataAnswer != null && gdataAnswer.getSequence() != null) { answerText = gdataAnswer.getSequence() + ":" + answerText; } } if (bean.getTypeId().equals("11")) { if (gdataAnswer != null && gdataAnswer.getSequence() != null) { answerText = gdataAnswer.getSequence() + ":" + answerText; } } if (bean.getTypeId().equals("13")) { if (gdataPubItemText == null) { answerText = ""; } else { int answerNo = gdataPubItemText.getSequence().intValue(); answerText = answerNo + ":" + answerText; } } // file upload if (bean.getTypeId().equals("6")) { gdata.setMediaArray(delegate.getMediaArray2(gdata.getItemGradingId().toString())); } // audio recording if (bean.getTypeId().equals("7")) { ArrayList mediaList = delegate.getMediaArray2(gdata.getItemGradingId().toString()); setDurationIsOver(item, mediaList); gdata.setMediaArray(mediaList); } if (bean.getTypeId().equals("16")) { if (gdataPubItemText == null) { // the matching pair is deleted answerText = ""; } else { answerText = gdataPubItemText.getSequence() + ":" + answerText; } } if (answerText == null) answerText = noAnswer; else { if (gdata.getRationale() != null && !gdata.getRationale().trim().equals("")) rationale = "\nRationale: " + gdata.getRationale(); } // Huong's temp commandout // answerText = answerText.replaceAll("<.*?>", ""); answerText = answerText.replaceAll("(\r\n|\r)", "<br/>"); rationale = rationale.replaceAll("<.*?>", ""); rationale = rationale.replaceAll("(\r\n|\r)", "<br/>"); fullAnswerText = answerText; // this is the // non-abbreviated answers // for essay questions int answerTextLength = ServerConfigurationService.getInt("samigo.questionScore.answerText.length", 1000); if (bean.getTypeId().equals("5")) { answerTextLength = 35; } // Fix for SAK-6932: Strip out all HTML tags except image tags if (answerText.length() > answerTextLength) { String noHTMLAnswerText; noHTMLAnswerText = answerText.replaceAll("<((..?)|([^iI][^mM][^gG].*?))>", ""); int index = noHTMLAnswerText.toLowerCase().indexOf("<img"); if (index != -1) { answerText = noHTMLAnswerText; } else { if (noHTMLAnswerText.length() > answerTextLength) { answerText = noHTMLAnswerText.substring(0, answerTextLength) + "..."; } else { answerText = noHTMLAnswerText; } } } /* * // no need to shorten it if (rationale.length() > 35) * rationale = rationale.substring(0, 35) + "..."; */ // SAM-755-"checkmark" indicates right, add "X" to indicate wrong if (gdataAnswer != null) { String checkmarkGif = "<img src='/samigo-app/images/delivery/checkmark.gif'>"; String crossmarkGif = "<img src='/samigo-app/images/crossmark.gif'>"; if (bean.getTypeId().equals("8") || bean.getTypeId().equals("11")) { answerText = FormattedText.escapeHtml(answerText, true); if (gdata.getIsCorrect() == null) { boolean result = false; if (bean.getTypeId().equals("8")) { result = delegate.getFIBResult(gdata, fibmap, item, publishedAnswerHash); } else { result = delegate.getFINResult(gdata, item, publishedAnswerHash); } if (result) { answerText = checkmarkGif + answerText; } else { answerText = crossmarkGif + answerText; } } else { if (gdata.getIsCorrect().booleanValue()) { answerText = checkmarkGif + answerText; } else { answerText = crossmarkGif + answerText; } } } else if (bean.getTypeId().equals("15")) { // CALCULATED_QUESTION answerText = FormattedText.escapeHtml(answerText, true); // need to do something here for fill in the blanks if (gdataAnswer.getScore() > 0) { // if score is 0, there is no way to tell if user got the correct answer // by using "autoscore"... wish there was a better way to tell if its correct or not Double autoscore = gdata.getAutoScore(); if (!(Double.valueOf(0)).equals(autoscore)) { answerText = checkmarkGif + answerText; } else if (Double.valueOf(0).equals(autoscore)) { answerText = crossmarkGif + answerText; } } } else if (!bean.getTypeId().equals("3")) { if ((gdataAnswer.getIsCorrect() != null && gdataAnswer.getIsCorrect()) || (gdataAnswer.getPartialCredit() != null && gdataAnswer.getPartialCredit() > 0)) { answerText = checkmarkGif + answerText; } else if (gdataAnswer.getIsCorrect() != null && !gdataAnswer.getIsCorrect()) { answerText = crossmarkGif + answerText; } } } // -- Got the answer text -- if (!answerList.get(0).equals(gdata)) { // We already have // an agentResults // for this one results.setAnswer(results.getAnswer() + "<br/>" + answerText); if (gdata.getAutoScore() != null) { results.setTotalAutoScore( Double.toString( (Double.valueOf(results.getExactTotalAutoScore())).doubleValue() + gdata.getAutoScore().doubleValue())); } else { results.setTotalAutoScore( Double.toString( (Double.valueOf(results.getExactTotalAutoScore())).doubleValue())); } results.setItemGradingAttachmentList(itemGradingAttachmentList); } else { results.setItemGradingId(gdata.getItemGradingId()); results.setAssessmentGradingId(gdata.getAssessmentGradingId()); if (gdata.getAutoScore() != null) { // for example, if an assessment has one fileupload // question, the autoscore = null results.setTotalAutoScore(gdata.getAutoScore().toString()); } else { results.setTotalAutoScore(Double.toString(0)); } results.setComments(FormattedText.convertFormattedTextToPlaintext(gdata.getComments())); results.setAnswer(answerText); results.setFullAnswer(fullAnswerText); results.setRationale(rationale); results.setSubmittedDate(gdata.getSubmittedDate()); AgentFacade agent = new AgentFacade(gdata.getAgentId()); // log.info("Rachel: agentid = " + gdata.getAgentId()); results.setLastName(agent.getLastName()); results.setFirstName(agent.getFirstName()); results.setEmail(agent.getEmail()); if (results.getLastName() != null && results.getLastName().length() > 0) results.setLastInitial(results.getLastName().substring(0, 1)); else if (results.getFirstName() != null && results.getFirstName().length() > 0) results.setLastInitial(results.getFirstName().substring(0, 1)); else results.setLastInitial("Anonymous"); results.setIdString(agent.getIdString()); results.setAgentEid(agent.getEidString()); results.setAgentDisplayId(agent.getDisplayIdString()); log.debug("testing agent getEid agent.getFirstname= " + agent.getFirstName()); log.debug("testing agent getEid agent.getid= " + agent.getIdString()); log.debug("testing agent getEid agent.geteid = " + agent.getEidString()); log.debug( "testing agent getDisplayId agent.getdisplayid = " + agent.getDisplayIdString()); results.setRole(agent.getRole()); results.setItemGradingAttachmentList(itemGradingAttachmentList); agents.add(results); } } } // log.info("Sort type is " + bean.getSortType() + "."); bs = new BeanSort(agents, bean.getSortType()); if ((bean.getSortType()).equals("assessmentGradingId") || (bean.getSortType()).equals("totalAutoScore") || (bean.getSortType()).equals("totalOverrideScore") || (bean.getSortType()).equals("finalScore")) { bs.toNumericSort(); } else { bs.toStringSort(); } if (bean.isSortAscending()) { log.debug("sortAscending"); agents = (ArrayList) bs.sort(); } else { log.debug("!sortAscending"); agents = (ArrayList) bs.sortDesc(); } // log.info("Listing agents."); bean.setAgents(agents); bean.setAllAgents(agents); bean.setTotalPeople(Integer.valueOf(bean.getAgents().size()).toString()); bean.setAgentResultsByItemGradingId(agentResultsByItemGradingIdMap); } catch (RuntimeException e) { e.printStackTrace(); return false; } return true; }
public void processAction(ActionEvent ae) throws AbortProcessingException { AssessmentBean assessmentBean = (AssessmentBean) ContextUtil.lookupBean("assessmentBean"); SectionBean sectionBean = (SectionBean) ContextUtil.lookupBean("sectionBean"); String sectionId = (String) FacesContext.getCurrentInstance() .getExternalContext() .getRequestParameterMap() .get("sectionId"); if (sectionId != null) { sectionBean.setSectionId(sectionId); } else { // i am afraid on returning from removal, EditPartListener is accled to // to re-populate the part // so i can't read sectionId from a form. - daisyf sectionId = sectionBean.getSectionId(); } AuthorBean author = (AuthorBean) ContextUtil.lookupBean("author"); isEditPendingAssessmentFlow = author.getIsEditPendingAssessmentFlow(); // log.info("**SectionId = "+sectionId); // #1a. prepare sectionBean AssessmentService assessmentService = null; SectionFacade section = null; if (isEditPendingAssessmentFlow) { EventTrackingService.post( EventTrackingService.newEvent( "sam.assessment.revise", "siteId=" + AgentFacade.getCurrentSiteId() + ", sectionId=" + sectionId, true)); assessmentService = new AssessmentService(); } else { EventTrackingService.post( EventTrackingService.newEvent( "sam.pubassessment.revise", "siteId=" + AgentFacade.getCurrentSiteId() + ", sectionId=" + sectionId, true)); assessmentService = new PublishedAssessmentService(); } section = assessmentService.getSection(sectionId); section.setAssessment(assessmentBean.getAssessment()); sectionBean.setSection(section); sectionBean.setSectionTitle(FormattedText.convertFormattedTextToPlaintext(section.getTitle())); sectionBean.setSectionDescription(section.getDescription()); sectionBean.setNoOfItems(String.valueOf(section.getItemSet().size())); populateMetaData(section, sectionBean); // todo: get poolsavailable and then add the current pool used, because we need to show it as // one of the choices. /* Huong moved to getPoolsAvailable in SectionBean.java ArrayList poolidlist = sectionBean.getPoolsAvailable(); String currpoolid= sectionBean.getSelectedPool(); // current pool used for random draw if (!("".equals(currpoolid)) && (currpoolid !=null)) { //System.out.println("current pool id not null or empty"); //now we need to get the poolid and displayName QuestionPoolService delegate = new QuestionPoolService();// QuestionPoolFacade pool= delegate.getPool(new Long(currpoolid), AgentFacade.getAgentString());// // now add the current pool used to the list, so it's available in the pulldown poolidlist.add(new SelectItem((pool.getQuestionPoolId().toString()), pool.getDisplayName()));// //System.out.println("added editing pool: "+ pool.getDisplayName());// sectionBean.setPoolsAvailable(poolidlist);// } */ boolean hideRandom = false; if ((sectionBean.getType() == null) || sectionBean.getType().equals(SectionDataIfc.QUESTIONS_AUTHORED_ONE_BY_ONE.toString())) { int itemsize = Integer.parseInt(sectionBean.getNoOfItems()); if (itemsize > 0) { hideRandom = true; } } sectionBean.setHideRandom(hideRandom); }
public void processAction(ActionEvent ae) throws AbortProcessingException { FacesContext context = FacesContext.getCurrentInstance(); // Map reqMap = context.getExternalContext().getRequestMap(); // Map requestParams = context.getExternalContext().getRequestParameterMap(); AssessmentBean assessmentBean = (AssessmentBean) ContextUtil.lookupBean("assessmentBean"); String assessmentId = assessmentBean.getAssessmentId(); SectionBean sectionBean = (SectionBean) ContextUtil.lookupBean("sectionBean"); // create an assessment based on the title entered and the assessment // template selected // #1 - read from form editpart.jsp String title = TextFormat.convertPlaintextToFormattedTextNoHighUnicode(log, sectionBean.getSectionTitle()) .trim(); if (title == null || title.equals("")) { String err = ContextUtil.getLocalizedString( "org.sakaiproject.tool.assessment.bundle.AuthorMessages", "empty_part_title_error"); context.addMessage(null, new FacesMessage(err)); sectionBean.setOutcome("editPart"); return; } String description = sectionBean.getSectionDescription(); String sectionId = sectionBean.getSectionId(); AuthorBean author = (AuthorBean) ContextUtil.lookupBean("author"); isEditPendingAssessmentFlow = author.getIsEditPendingAssessmentFlow(); // #1a. prepare sectionBean AssessmentService assessmentService = null; SectionFacade section = null; // permission check String creator; if (isEditPendingAssessmentFlow) { assessmentService = new AssessmentService(); AssessmentFacade af = assessmentService.getBasicInfoOfAnAssessment(assessmentId); creator = af.getCreatedBy(); } else { PublishedAssessmentService pubService = new PublishedAssessmentService(); assessmentService = pubService; PublishedAssessmentFacade paf = pubService.getSettingsOfPublishedAssessment(assessmentId); creator = paf.getCreatedBy(); } AuthorizationBean authzBean = (AuthorizationBean) ContextUtil.lookupBean("authorization"); if (!authzBean.isUserAllowedToEditAssessment( assessmentId, creator, !isEditPendingAssessmentFlow)) { String err = ContextUtil.getLocalizedString( "org.sakaiproject.tool.assessment.bundle.AuthorMessages", "denied_edit_assessment_error"); context.addMessage(null, new FacesMessage(err)); sectionBean.setOutcome("editPart"); return; } if (isEditPendingAssessmentFlow) { EventTrackingService.post( EventTrackingService.newEvent( "sam.assessment.revise", "siteId=" + AgentFacade.getCurrentSiteId() + ", sectionId=" + sectionId, true)); } else { EventTrackingService.post( EventTrackingService.newEvent( "sam.pubassessment.revise", "siteId=" + AgentFacade.getCurrentSiteId() + ", sectionId=" + sectionId, true)); } boolean addItemsFromPool = false; sectionBean.setOutcome("editAssessment"); if ((sectionBean.getType().equals("2")) && (sectionBean.getSelectedPool().equals(""))) { String selectedPool_err = ContextUtil.getLocalizedString( "org.sakaiproject.tool.assessment.bundle.AuthorMessages", "selectedPool_error"); context.addMessage(null, new FacesMessage(selectedPool_err)); sectionBean.setOutcome("editPart"); return; } if (isEditPendingAssessmentFlow && !("".equals(sectionBean.getType())) && ((SectionDataIfc.RANDOM_DRAW_FROM_QUESTIONPOOL.toString()) .equals(sectionBean.getType()))) { addItemsFromPool = true; if (validateItemsDrawn(sectionBean)) { section = getOrAddSection(assessmentService, assessmentId, sectionId); } else { sectionBean.setOutcome("editPart"); return; } } else { section = getOrAddSection(assessmentService, assessmentId, sectionId); } if (section == null) { log.info("section == null - Should not come to here. Simply return."); log.info("assessmentId =" + assessmentId); log.info("sectionId =" + sectionId); return; } log.debug("**** section title =" + section.getTitle()); log.debug("**** title =" + title); // title, description, and question ordering are editable for both pending and publish // assessments if (title != null) section.setTitle(title); section.setDescription(description); if (!("".equals(sectionBean.getQuestionOrdering()))) section.addSectionMetaData( SectionDataIfc.QUESTIONS_ORDERING, sectionBean.getQuestionOrdering()); if (isEditPendingAssessmentFlow) { if (!("".equals(sectionBean.getKeyword()))) section.addSectionMetaData( SectionMetaDataIfc.KEYWORDS, TextFormat.convertPlaintextToFormattedTextNoHighUnicode(log, sectionBean.getKeyword())); if (!("".equals(sectionBean.getObjective()))) section.addSectionMetaData( SectionMetaDataIfc.OBJECTIVES, TextFormat.convertPlaintextToFormattedTextNoHighUnicode( log, sectionBean.getObjective())); if (!("".equals(sectionBean.getRubric()))) section.addSectionMetaData( SectionMetaDataIfc.RUBRICS, TextFormat.convertPlaintextToFormattedTextNoHighUnicode(log, sectionBean.getRubric())); if (!("".equals(sectionBean.getType()))) { section.addSectionMetaData(SectionDataIfc.AUTHOR_TYPE, sectionBean.getType()); if ((SectionDataIfc.RANDOM_DRAW_FROM_QUESTIONPOOL.toString()) .equals(sectionBean.getType())) { if ((sectionBean.getNumberSelected() != null) && !("".equals(sectionBean.getNumberSelected()))) { section.addSectionMetaData( SectionDataIfc.NUM_QUESTIONS_DRAWN, sectionBean.getNumberSelected()); } if (!("".equals(sectionBean.getSelectedPool()))) { section.addSectionMetaData( SectionDataIfc.POOLID_FOR_RANDOM_DRAW, sectionBean.getSelectedPool()); String poolname = ""; QuestionPoolService qpservice = new QuestionPoolService(); QuestionPoolFacade poolfacade = qpservice.getPool( new Long(sectionBean.getSelectedPool()), AgentFacade.getAgentString()); if (poolfacade != null) { poolname = poolfacade.getTitle(); } section.addSectionMetaData(SectionDataIfc.POOLNAME_FOR_RANDOM_DRAW, poolname); } section.addSectionMetaData( SectionDataIfc.RANDOMIZATION_TYPE, sectionBean.getRandomizationType()); } } if (addItemsFromPool) { boolean hasRandomPartScore = false; Double score = null; String requestedScore = sectionBean.getRandomPartScore(); if (requestedScore != null && !requestedScore.equals("")) { hasRandomPartScore = true; score = new Double(requestedScore); } boolean hasRandomPartDiscount = false; Double discount = null; String requestedDiscount = sectionBean.getRandomPartDiscount(); if (requestedDiscount != null && !requestedDiscount.equals("")) { hasRandomPartDiscount = true; discount = new Double(requestedDiscount); } if (hasRandomPartScore && score != null) { section.addSectionMetaData(SectionDataIfc.POINT_VALUE_FOR_QUESTION, score.toString()); } else { section.addSectionMetaData(SectionDataIfc.POINT_VALUE_FOR_QUESTION, ""); } if (hasRandomPartDiscount && discount != null) { section.addSectionMetaData( SectionDataIfc.DISCOUNT_VALUE_FOR_QUESTION, discount.toString()); } else { section.addSectionMetaData(SectionDataIfc.DISCOUNT_VALUE_FOR_QUESTION, ""); } } } assessmentService.saveOrUpdateSection(section); if (addItemsFromPool) { // update random questions from question pool int success = assessmentService.updateRandomPoolQuestions( assessmentService.getSection(section.getSectionId().toString())); if (success != AssessmentService.UPDATE_SUCCESS) { if (success == AssessmentService.UPDATE_ERROR_DRAW_SIZE_TOO_LARGE) { // shouldn't get here since there is a check, but might as well verify String err = ContextUtil.getLocalizedString( "org.sakaiproject.tool.assessment.bundle.AuthorMessages", "qdrawn_error"); context.addMessage( null, new FacesMessage( err + " " + section.getSectionMetaDataByLabel(SectionDataIfc.NUM_QUESTIONS_DRAWN))); } } } // added by daisyf, 10/10/06 updateAttachment( section.getSectionAttachmentList(), sectionBean.getAttachmentList(), section.getData()); // #2 - goto editAssessment.jsp, so reset assessmentBean AssessmentIfc assessment = assessmentService.getAssessment(Long.valueOf(assessmentBean.getAssessmentId())); assessmentBean.setAssessment(assessment); assessmentService.updateAssessmentLastModifiedInfo(assessment); EventTrackingService.post( EventTrackingService.newEvent( "sam.assessment.revise", "siteId=" + AgentFacade.getCurrentSiteId() + ", sectionId=" + section.getSectionId(), true)); }
public String getEid() { return AgentFacade.getEid(); }
public String getAgentString() { return AgentFacade.getAgentString(); }
/** delete specified Item */ public String deleteItem() { ItemService delegate = new ItemService(); Long deleteId = this.getItemToDelete().getItemId(); ItemFacade itemf = delegate.getItem(deleteId, AgentFacade.getAgentString()); // save the currSection before itemf.setSection(null), used to reorder question sequences SectionFacade currSection = (SectionFacade) itemf.getSection(); Integer currSeq = itemf.getSequence(); QuestionPoolService qpdelegate = new QuestionPoolService(); if (qpdelegate.getPoolIdsByItem(deleteId.toString()) == null || qpdelegate.getPoolIdsByItem(deleteId.toString()).isEmpty()) { // if no reference to this item at all, ie, this item is created in assessment but not // assigned to any pool AuthorizationBean authzBean = (AuthorizationBean) ContextUtil.lookupBean("authorization"); AssessmentService assessdelegate = new AssessmentService(); AssessmentFacade af = assessdelegate.getBasicInfoOfAnAssessmentFromSectionId(currSection.getSectionId()); if (!authzBean.isUserAllowedToEditAssessment( af.getAssessmentBaseId().toString(), af.getCreatedBy(), false)) { throw new IllegalArgumentException( "User does not have permission to delete item in assessment: " + af.getAssessmentBaseId()); } delegate.deleteItem(deleteId, AgentFacade.getAgentString()); } else { if (currSection == null) { // if this item is created from question pool QuestionPoolBean qpoolbean = (QuestionPoolBean) ContextUtil.lookupBean("questionpool"); ItemFacade itemfacade = delegate.getItem(deleteId, AgentFacade.getAgentString()); ArrayList items = new ArrayList(); items.add(itemfacade); qpoolbean.setItemsToDelete(items); qpoolbean.removeQuestionsFromPool(); return "editPool"; } else { // // if some pools still reference to this item, ie, this item is // created in assessment but also assigned a a pool // then just set section = null itemf.setSection(null); delegate.saveItem(itemf); } } // An item has been deleted EventTrackingService.post( EventTrackingService.newEvent( "sam.assessment.item.delete", "/sam/" + AgentFacade.getCurrentSiteId() + "/removed itemId=" + deleteId, true)); AssessmentService assessdelegate = new AssessmentService(); // reorder item numbers SectionFacade sectfacade = assessdelegate.getSection(currSection.getSectionId().toString()); Set itemset = sectfacade.getItemFacadeSet(); // should be size-1 now. Iterator iter = itemset.iterator(); while (iter.hasNext()) { ItemFacade itemfacade = (ItemFacade) iter.next(); Integer itemfacadeseq = itemfacade.getSequence(); if (itemfacadeseq.compareTo(currSeq) > 0) { itemfacade.setSequence(Integer.valueOf(itemfacadeseq.intValue() - 1)); delegate.saveItem(itemfacade); } } // go to editAssessment.jsp, need to first reset assessmentBean AssessmentBean assessmentBean = (AssessmentBean) ContextUtil.lookupBean("assessmentBean"); AssessmentFacade assessment = assessdelegate.getAssessment(assessmentBean.getAssessmentId()); assessmentBean.setAssessment(assessment); assessdelegate.updateAssessmentLastModifiedInfo(assessment); // Assessment has been revised EventTrackingService.post( EventTrackingService.newEvent( "sam.asessment.revise", "/sam/" + AgentFacade.getCurrentSiteId() + "/removed itemId=" + deleteId + "from assessmentId=" + assessmentBean.getAssessmentId(), true)); return "editAssessment"; }
public java.util.ArrayList getItemContentsForRandomQuestionOrdering() { // same ordering for each student long seed = (long) AgentFacade.getAgentString().hashCode(); Collections.shuffle(itemContents, new Random(seed)); return itemContents; }