Skip to content

Commit

Permalink
SAK-33398 need to provide tools that implement ExternalAssignmentProv…
Browse files Browse the repository at this point in the history
…ider context on the ExternalAssessment (sakaiproject#4827)
  • Loading branch information
ottenhoff authored Sep 29, 2017
1 parent 0301c99 commit c3b176a
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -640,4 +640,10 @@ public String getDeepLinkWithPermissions(String context, String assignmentId, bo
void resetAssignment(Assignment assignment);

void postReviewableSubmissonAttachments(String submissionId);

/**
* This will return the internationalized title of the tool.
* This is used when creating a new gradebook item.
*/
public String getToolTitle();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

public final class AssignmentServiceConstants {

public static final String ASSIGNMENT_TOOL_ID = "sakai.assignment.grades";
/**
* The type string for this application: should not change over time as it may be stored in various parts of persistent entities.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ private Assignment getAssignment(String id) {
return assignment;
}

public boolean isAssignmentDefined(String id) {
public boolean isAssignmentDefined(String externalAppName, String id) {
if (!externalAppName.equals(getAppKey()) && !externalAppName.equals(assignmentService.getToolTitle())) {
return false;
}
return getAssignment(id) != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.sakaiproject.taggable.api.TaggingProvider;
import org.sakaiproject.time.api.TimeService;
import org.sakaiproject.tool.api.SessionManager;
import org.sakaiproject.tool.api.Tool;
import org.sakaiproject.tool.api.ToolManager;
import org.sakaiproject.user.api.CandidateDetailProvider;
import org.sakaiproject.user.api.User;
Expand Down Expand Up @@ -169,6 +170,19 @@ public String getLabel() {
return "assignment";
}

@Override
public String getToolTitle() {
Tool tool = toolManager.getTool(AssignmentServiceConstants.ASSIGNMENT_TOOL_ID);
String toolTitle = null;

if (tool == null)
toolTitle = "Assignments";
else
toolTitle = tool.getTitle();

return toolTitle;
}

@Override
public boolean willArchiveMerge() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public void AssignmentServiceIsValid() {
Assert.assertNotNull(assignmentService);
}

@Test
public void checkAssignmentToolTitle() {
Assert.assertNotNull(assignmentService.getToolTitle());
}

@Test
public void addAndGetAssignment() {
String userId = UUID.randomUUID().toString();
Expand Down
1 change: 1 addition & 0 deletions assignment/impl/src/webapp/WEB-INF/components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<property name="serverConfigurationService" ref="org.sakaiproject.component.api.ServerConfigurationService"/>
<property name="siteService" ref="org.sakaiproject.site.api.SiteService"/>
<property name="taggingManager" ref="org.sakaiproject.taggable.api.TaggingManager"/>
<property name="toolManager" ref="org.sakaiproject.tool.api.ToolManager"/>
<property name="userDirectoryService" ref="org.sakaiproject.user.api.UserDirectoryService"/>
</bean>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,7 @@ private void currentAssignmentGradebookIntegrationIntoContext(Context context, S
// filtering out those from Samigo
for (Iterator i = gradebookAssignments.iterator(); i.hasNext(); ) {
org.sakaiproject.service.gradebook.shared.Assignment gAssignment = (org.sakaiproject.service.gradebook.shared.Assignment) i.next();
if (!gAssignment.isExternallyMaintained() || gAssignment.isExternallyMaintained() && gAssignment.getExternalAppName().equals(getToolTitle())) {
if (!gAssignment.isExternallyMaintained() || gAssignment.isExternallyMaintained() && gAssignment.getExternalAppName().equals(assignmentService.getToolTitle())) {
gradebookAssignmentsExceptSamigo.add(gAssignment);

// gradebook item has been associated or not
Expand Down Expand Up @@ -4751,22 +4751,6 @@ private String build_instructor_download_upload_all(VelocityPortlet portlet, Con

} // build_instructor_upload_all

/**
* * Retrieve tool title from Tool configuration file or use default
* * (This should return i18n version of tool title if available)
**/
private String getToolTitle() {
Tool tool = toolManager.getTool(ASSIGNMENT_TOOL_ID);
String toolTitle = null;

if (tool == null)
toolTitle = "Assignments";
else
toolTitle = tool.getTitle();

return toolTitle;
}

/**
* integration with gradebook
*
Expand All @@ -4789,7 +4773,7 @@ private void integrateGradebook(SessionState state, String assignmentRef, String
// b. if Gradebook exists, just call addExternal and removeExternal and swallow any exception. The
// exception are indication that the assessment is already in the Gradebook or there is nothing
// to remove.
String assignmentToolTitle = getToolTitle();
String assignmentToolTitle = assignmentService.getToolTitle();

String gradebookUid = toolManager.getCurrentPlacement().getContext();
if (gradebookService.isGradebookDefined(gradebookUid) && gradebookService.currentUserHasGradingPerm(gradebookUid)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ public interface ExternalAssignmentProvider {

/**
* Check if an assignment/assessment exists with the given identifier.
* This will be in the form that is supplied to the Gradebook, so it
* will need to be parsed. If the prefix is not recognized as matching
* for this service, false is expected to be returned, even if there
* may be an assignment with the prefixed id.
* Note that this may seem strange but it is required because services
* do not currently register their prefixes with the Gradebook, so the
* external IDs are completely opaque and do not identify their source.
* If the externalAppName is not the tool's responsibility or if the
* id is not recognized as matching
* for this service, false is expected to be returned.
* @param externalId
*/
boolean isAssignmentDefined(String id);
boolean isAssignmentDefined(String externalAppName, String externalId);

/**
* Check if the given assignment is grouped.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public boolean isExternalAssignmentGrouped(String gradebookUid, String externalI
log.info("No assignment found for external assignment check: gradebookUid="+gradebookUid+", externalId="+externalId);
} else {
for (ExternalAssignmentProvider provider : getExternalAssignmentProviders().values()) {
if (provider.isAssignmentDefined(externalId)) {
if (provider.isAssignmentDefined(assignment.getExternalAppName(), externalId)) {
providerResponded = true;
result = result || provider.isAssignmentGrouped(externalId);
}
Expand Down Expand Up @@ -546,7 +546,7 @@ public boolean isExternalAssignmentVisible(String gradebookUid, String externalI
log.info("No assignment found for external assignment check: gradebookUid="+gradebookUid+", externalId="+externalId);
} else {
for (ExternalAssignmentProvider provider : getExternalAssignmentProviders().values()) {
if (provider.isAssignmentDefined(externalId)) {
if (provider.isAssignmentDefined(assignment.getExternalAppName(), externalId)) {
providerResponded = true;
result = result || provider.isAssignmentVisible(externalId, userId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@ public void updateExternalAssessmentComment(Long publishedAssessmentId, String s

public Long getExternalAssessmentCategoryId(String gradebookUId,
String publishedAssessmentId, GradebookExternalAssessmentService g);

public String getAppName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import org.sakaiproject.tool.assessment.data.dao.authz.AuthorizationData;
import org.sakaiproject.tool.assessment.data.ifc.assessment.PublishedAssessmentIfc;
import org.sakaiproject.tool.assessment.facade.PublishedAssessmentFacade;
import org.sakaiproject.tool.assessment.integration.context.IntegrationContextFactory;
import org.sakaiproject.tool.assessment.integration.helper.ifc.GradebookServiceHelper;
import org.sakaiproject.tool.assessment.services.PersistenceService;
import org.sakaiproject.tool.assessment.services.assessment.PublishedAssessmentService;
import org.sakaiproject.user.api.UserDirectoryService;
Expand Down Expand Up @@ -110,15 +112,24 @@ private PublishedAssessmentIfc getPublishedAssessment(String id) {
return a;
}

public boolean isAssignmentDefined(String id) {
// SAM-3068 avoid looking up another tool's id
if (!StringUtils.isNumeric(id)) {
public boolean isAssignmentDefined(String externalAppName, String id) {
// SAM-3068 avoid looking up another tool's id
if (!StringUtils.isNumeric(id)) {
return false;
}
}

GradebookServiceHelper gbsHelper = IntegrationContextFactory.getInstance().getGradebookServiceHelper();
String toolName = gbsHelper.getAppName();
if (!StringUtils.equals(externalAppName, getAppKey()) && !StringUtils.equals(externalAppName, toolName)) {
return false;
}

if (log.isDebugEnabled()) {
log.debug("Samigo provider isAssignmentDefined: " + id);
}

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ public boolean isAssignmentDefined(String assessmentTitle,
String gradebookUId = GradebookFacade.getGradebookUId();
return g.isAssignmentDefined(gradebookUId, assessmentTitle);
}

public String getAppName()
{
// Tool name code added by Josh Holtzman
Tool tool = ToolManager.getTool("sakai.samigo");
String appName = null;

if (tool == null)
{
log.warn(
"could not get tool named sakai.samigo, " +
"so we're going to assume we're called 'Tests & Quizzes'");
appName = "Tests & Quizzes";
}
else
{
appName = tool.getTitle();
}
return appName;
}

/**
* Add a published assessment to gradebook.
Expand Down Expand Up @@ -181,23 +201,6 @@ public boolean addToGradebook(PublishedAssessmentData publishedAssessment, Long
// g.isGradebookDefined(gradebookUId));
if (g.isGradebookDefined(gradebookUId))
{

// Tool name code added by Josh Holtzman
Tool tool = ToolManager.getTool("sakai.samigo");
String appName = null;

if (tool == null)
{
log.warn(
"could not get tool named sakai.samigo, " +
"so we're going to assume we're called 'Tests & Quizzes'");
appName = "Tests & Quizzes";
}
else
{
appName = tool.getTitle();
}

String title = StringEscapeUtils.unescapeHtml(publishedAssessment.getTitle());
if(!g.isAssignmentDefined(gradebookUId, title))
{
Expand All @@ -208,7 +211,7 @@ public boolean addToGradebook(PublishedAssessmentData publishedAssessment, Long
publishedAssessment.getTotalScore().doubleValue(),
publishedAssessment.getAssessmentAccessControl().
getDueDate(),
appName, // Use the app name from sakai
getAppName(), // Use the app name from sakai
false,
categoryId);
added = true;
Expand Down

0 comments on commit c3b176a

Please sign in to comment.