Skip to content

Commit

Permalink
SAK-49757 Samigo: fix attachment to a question response and cleanup (s…
Browse files Browse the repository at this point in the history
…akaiproject#12429)

Co-authored-by: bgarciaentornos <[email protected]>
  • Loading branch information
ottenhoff and bgarciaentornos authored Mar 21, 2024
1 parent cb21c2a commit eec3ca0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.jsf2.model.PhaseAware;
import org.sakaiproject.jsf2.renderer.PagerRenderer;
import org.sakaiproject.portal.util.PortalUtils;
import org.sakaiproject.rubrics.api.RubricsConstants;
import org.sakaiproject.tool.api.ToolManager;
Expand Down Expand Up @@ -144,7 +143,7 @@ public class QuestionScoresBean implements Serializable, PhaseAware {
@Getter @Setter
private int firstRow;
@Getter @Setter
private int maxDisplayedRows = PagerRenderer.MAX_PAGE_SIZE;
private int maxDisplayedRows;
@Getter @Setter
private int dataRows;
@Getter @Setter
Expand Down Expand Up @@ -213,26 +212,29 @@ protected void init() {
searchString = defaultSearchString;
}

// Get allAgents only at the first time
if (allAgents == null) {
allAgents = getAllAgents(valueChanged);
}

List matchingAgents;
if (isFilteredSearch()) {
matchingAgents = findMatchingAgents(searchString);
}
else {
matchingAgents = getAllAgents(valueChanged);
matchingAgents = allAgents;
}
dataRows = matchingAgents.size();
List newAgents = new ArrayList();
List newAgents;
if (maxDisplayedRows == 0) {
newAgents.addAll(matchingAgents);
newAgents = matchingAgents;
} else {
int nextPageRow = Math.min(firstRow + maxDisplayedRows, dataRows);
newAgents.addAll(matchingAgents.subList(firstRow, nextPageRow));
log.debug("init(): subList " + firstRow + ", " + nextPageRow);
newAgents = new ArrayList(matchingAgents.subList(firstRow, nextPageRow));
log.debug("init(): subList {},{}", firstRow, nextPageRow);
}

agents.clear();
agents.addAll(newAgents);

agents = newAgents;
}

// Following three methods are for interface PhaseAware
Expand Down Expand Up @@ -350,39 +352,6 @@ public String getMaxPoint()
}
}

/** This is a read-only calculated property.
* @return list of uppercase student initials
*/
public String getAgentInitials()
{
List c = getAgents();


StringBuilder initialsbuf = new StringBuilder();

if (c.isEmpty())
{
return "";
}

for(AgentResults ar : (List<AgentResults>) c)
{
try
{
String initial = ar.getLastInitial();
initialsbuf.append(initial);
}
catch (Exception ex)
{
log.warn(ex.getMessage());
// if there is any problem, we skip, and go on
}
}

String initials = initialsbuf.toString();
return initials.toUpperCase();
}

/**
* get the total number of students for this assessment
*
Expand Down Expand Up @@ -569,7 +538,7 @@ public List findMatchingAgents(final String pattern) {
StringBuilder name1;
// name2 example: Doe, John
StringBuilder name2;
for(Iterator iter = getAllAgents(false).iterator(); iter.hasNext();) {
for(Iterator iter = allAgents.iterator(); iter.hasNext();) {
AgentResults result = (AgentResults)iter.next();
// name1 example: John Doe
name1 = new StringBuilder(result.getFirstName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.commons.lang3.StringUtils;

import org.sakaiproject.jsf2.model.PhaseAware;
import org.sakaiproject.jsf2.renderer.PagerRenderer;
import org.sakaiproject.tool.assessment.business.entity.RecordingData;
import org.sakaiproject.tool.assessment.services.assessment.PublishedAssessmentService;
import org.sakaiproject.tool.assessment.ui.bean.util.Validator;
Expand Down Expand Up @@ -82,7 +81,7 @@ public class SubmissionStatusBean implements Serializable, PhaseAware {

// Paging.
private int firstScoreRow;
private int maxDisplayedScoreRows = PagerRenderer.MAX_PAGE_SIZE;
private int maxDisplayedScoreRows;
private int scoreDataRows;

// Searching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.jsf2.model.PhaseAware;
import org.sakaiproject.jsf2.renderer.PagerRenderer;
import org.sakaiproject.portal.util.PortalUtils;
import org.sakaiproject.section.api.coursemanagement.CourseSection;
import org.sakaiproject.section.api.coursemanagement.EnrollmentRecord;
Expand Down Expand Up @@ -150,7 +149,7 @@ public class TotalScoresBean implements Serializable, PhaseAware {

// Paging.
private int firstScoreRow;
private int maxDisplayedScoreRows = PagerRenderer.MAX_PAGE_SIZE;
private int maxDisplayedScoreRows;
private int scoreDataRows;

// Searching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ public boolean questionScores(String publishedId, QuestionScoresBean bean,
log.debug("item = {}:{}-{}", thisItemTextIfc.getSequence(), thisItemTextIfc.getText(), thisItemTextIfc.getItem().getItemId());

}
Map publishedAnswerHash = pubService
.preparePublishedAnswerHash(publishedAssessment);
Map<Long, AnswerIfc> publishedAnswerHash = pubService.preparePublishedAnswerHash(publishedAssessment);
// re-attach session and load all lazy loaded parent/child stuff

// Set<Long> publishedAnswerHashKeySet = publishedAnswerHash.keySet();
Expand All @@ -270,8 +269,7 @@ public boolean questionScores(String publishedId, QuestionScoresBean bean,
// pubItemService.eagerFetchAnswer(answer);
// }
// }
log.debug("questionScores(): publishedAnswerHash.size = "
+ publishedAnswerHash.size());
log.debug("questionScores(): publishedAnswerHash.size = {}", publishedAnswerHash.size());
Map<Long, AgentResults> agentResultsByItemGradingIdMap = new HashMap<>();

TotalScoresBean totalBean = (TotalScoresBean) ContextUtil
Expand Down Expand Up @@ -326,14 +324,14 @@ public boolean questionScores(String publishedId, QuestionScoresBean bean,

Map map = getItemScores(Long.valueOf(publishedId), Long
.valueOf(itemId), which, isValueChange);
log.debug("questionScores(): map .size = " + map.size());
log.debug("questionScores(): map .size = {}", map.size());
List allscores = new ArrayList();
Iterator keyiter = map.keySet().iterator();
while (keyiter.hasNext()) {
allscores.addAll((List) map.get(keyiter.next()));
}

log.debug("questionScores(): allscores.size = " + allscores.size());
log.debug("questionScores(): allscores.size = {}", allscores.size());

// now we need filter by sections selected
List scores = new ArrayList(); // filtered list
Expand Down Expand Up @@ -369,7 +367,7 @@ public boolean questionScores(String publishedId, QuestionScoresBean bean,
}
}

log.debug("questionScores(): scores.size = " + scores.size());
log.debug("questionScores(): scores.size = {}", scores.size());

Iterator iter = scores.iterator();
List agents = new ArrayList();
Expand Down Expand Up @@ -435,8 +433,7 @@ public boolean questionScores(String publishedId, QuestionScoresBean bean,
scoresByItem.put(idata.getAssessmentGradingId() + ":"
+ idata.getPublishedItemId(), newList);
}
log.debug("questionScores(): scoresByItem.size = "
+ scoresByItem.size());
log.debug("questionScores(): scoresByItem.size = {}", scoresByItem.size());
bean.setScoresByItem(scoresByItem);

try {
Expand Down Expand Up @@ -1123,9 +1120,8 @@ private void populateSections(PublishedAssessmentIfc publishedAssessment,
QuestionScoresBean bean, TotalScoresBean totalBean,
List scores, PublishedAssessmentService pubService) {
List sections = new ArrayList();
log
.debug("questionScores(): populate sctions publishedAssessment.getSectionArraySorted size = "
+ publishedAssessment.getSectionArraySorted().size());
log.debug("questionScores(): populate sctions publishedAssessment.getSectionArraySorted size = {}",
publishedAssessment.getSectionArraySorted().size());
Iterator iter = publishedAssessment.getSectionArraySorted().iterator();
int i = 1;
while (iter.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void setMaxDisplayedScoreRows(QuestionScoresBean bean, boolean isValueCh
bean.setMaxDisplayedRows(bean.getAudioMaxDisplayedScoreRows());
}
else {
bean.setMaxDisplayedRows(5);
bean.setMaxDisplayedRows(0);
bean.setAudioMaxDisplayedScoreRows(5);
}
}
Expand Down

0 comments on commit eec3ca0

Please sign in to comment.