Skip to content

Commit

Permalink
SAM-3255 do a simple query to see if assessment id is valid instead o…
Browse files Browse the repository at this point in the history
…f doing a Hibernate load (sakaiproject#4826)
  • Loading branch information
ottenhoff authored and jonespm committed Sep 26, 2017
1 parent 10477d4 commit 9844f4e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,21 @@ public Set preparePublishedAnswerFeedbackSet(
return h;
}

/**
* This was created for GradebookExternalAssessmentService.
* We just want a quick answer whether Samigo is responsible for an id.
*/
public boolean isPublishedAssessmentIdValid(Long publishedAssessmentId) {
List<PublishedAssessmentData> list = (List<PublishedAssessmentData>) getHibernateTemplate()
.findByNamedParam("from PublishedAssessmentData where publishedAssessmentId = :id", "id", publishedAssessmentId);

if (!list.isEmpty()) {
PublishedAssessmentData f = list.get(0);
return f.getPublishedAssessmentId() > 0;
}
return false;
}

public PublishedAssessmentFacade getPublishedAssessment(Long assessmentId) {
return getPublishedAssessment(assessmentId, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public Set preparePublishedAnswerSet(PublishedItemText publishedItemText,
public Set preparePublishedAnswerFeedbackSet(PublishedAnswer publishedAnswer,
Set answerFeedbackSet);

public boolean isPublishedAssessmentIdValid(Long publishedAssessmentId);

public PublishedAssessmentFacade getPublishedAssessment(Long assessmentId);

public PublishedAssessmentFacade getPublishedAssessment(Long assessmentId, boolean withGroupsInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ public String getAppKey() {


private PublishedAssessmentIfc getPublishedAssessment(String id) {
// SAM-3068 avoid looking up another tool's id
if (!StringUtils.isNumeric(id)) {
return null;
}

PublishedAssessmentIfc a = (PublishedAssessmentIfc) pubAssessmentCache.get(id);
if (a != null) {
log.debug("Returning assessment {} from cache", id);
Expand All @@ -116,17 +111,24 @@ private PublishedAssessmentIfc getPublishedAssessment(String id) {
}

public boolean isAssignmentDefined(String id) {
if (log.isDebugEnabled()) {
log.debug("Samigo provider isAssignmentDefined: " + id);
// SAM-3068 avoid looking up another tool's id
if (!StringUtils.isNumeric(id)) {
return false;
}
return getPublishedAssessment(id) != null;

log.debug("Samigo provider isAssignmentDefined: {}", id);
Long longId = Long.parseLong(id);
return PersistenceService.getInstance().getPublishedAssessmentFacadeQueries().isPublishedAssessmentIdValid(longId);
}


public boolean isAssignmentGrouped(String id) {
if (log.isDebugEnabled()) {
log.debug("Samigo provider isAssignmentGrouped: " + id);
// SAM-3068 avoid looking up another tool's id
if (!StringUtils.isNumeric(id)) {
return false;
}

log.debug("Samigo provider isAssignmentGrouped: {}", id);

Boolean g = null;
if (groupedCache.containsKey(id)) {
Expand Down

0 comments on commit 9844f4e

Please sign in to comment.