forked from kstateome/canvas-api
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from Elonso95/retrieve_multiple_assignment_sub…
…missions Added new function to call canvas service 'List submissions for multiple assignments' from the Submission API
- Loading branch information
Showing
6 changed files
with
333 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
src/main/java/edu/ksu/canvas/requestOptions/GetMultipleSubmissionsOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
package edu.ksu.canvas.requestOptions; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import edu.ksu.canvas.requestOptions.BaseOptions; | ||
import edu.ksu.canvas.requestOptions.GetSubmissionsOptions.Include; | ||
|
||
public class GetMultipleSubmissionsOptions extends BaseOptions { | ||
|
||
private String canvasId; | ||
|
||
/** | ||
* Construct options class with required parameters to retrieve a list of multiple Submissions from courses or sections | ||
* @param canvasId The Course or Section ID, depending on which API is being targeted. | ||
*/ | ||
public GetMultipleSubmissionsOptions(final String canvasId) { | ||
this.canvasId = canvasId; | ||
} | ||
|
||
|
||
/** | ||
* Filter the list of submissions by the given student ids.. | ||
* @param ids List of ids to filter submissions by | ||
* @return This object to allow adding more options | ||
*/ | ||
public GetMultipleSubmissionsOptions studentIds(final List<String> ids) { | ||
optionsMap.put("student_ids[]", ids); | ||
return this; | ||
} | ||
|
||
/** | ||
* Optionally include more information with the returned assignment Submission objects. | ||
* @param includes List of optional includes | ||
* @return This object to allow adding more options | ||
*/ | ||
public GetMultipleSubmissionsOptions includes(final List<Include> includes) { | ||
addEnumList("include[]", includes); | ||
return this; | ||
} | ||
|
||
/** | ||
* List of assignments to return submissions for. | ||
* If none are given, submissions for all assignments are returned. | ||
* @param ids List of ids to filter submissions by | ||
* @return This object to allow adding more options | ||
*/ | ||
public GetMultipleSubmissionsOptions assignmentIds(final List<String> ids) { | ||
optionsMap.put("assignment_ids[]", ids); | ||
return this; | ||
} | ||
|
||
/** | ||
* When set to true, response will be grouped by student groups. | ||
* Only valid for Submission lists, not individual submission queries. | ||
* @param grouped Whether to group submissions by student group | ||
* @return This object to allow adding more options | ||
*/ | ||
public GetMultipleSubmissionsOptions grouped(Boolean grouped) { | ||
addSingleItem("grouped", Boolean.toString(grouped)); | ||
return this; | ||
} | ||
|
||
/** | ||
* If this argument is set to true, the response will only include submissions for assignments | ||
* that have the post_to_sis flag set to true and user enrollments that were added through sis. | ||
* @param postToSis Whether to include submissions that have the flag active | ||
* @return This object to allow adding more options | ||
*/ | ||
public GetMultipleSubmissionsOptions postToSis(Boolean postToSis) { | ||
addSingleItem("post_to_sis", Boolean.toString(postToSis)); | ||
return this; | ||
} | ||
|
||
/** | ||
* If this argument is set, the response will only include submissions that were submitted | ||
* after the specified date_time. | ||
* This will exclude submissions that do not have a submitted_at which will exclude unsubmitted submissions | ||
* @param submittedSince date to get submissions after | ||
* @return This object to allow adding more options | ||
*/ | ||
public GetMultipleSubmissionsOptions submittedSince(Date submittedSince) { | ||
addSingleItem("submitted_since", submittedSince.toString()); | ||
return this; | ||
} | ||
|
||
/** | ||
* If this argument is set, the response will only include submissions that were graded | ||
* after the specified date_time. | ||
* This will exclude submissions that have not been graded. | ||
* @param gradedSince date to get submissions graded after | ||
* @return This object to allow adding more options | ||
*/ | ||
public GetMultipleSubmissionsOptions gradedSince(Date gradedSince) { | ||
addSingleItem("graded_since", gradedSince.toString()); | ||
return this; | ||
} | ||
|
||
/** | ||
* The id of the grading period in which submissions are being requested | ||
* (Requires grading periods to exist on the account) | ||
* @param gradingPeriodId the grading period for the submissions | ||
* @return This object to allow adding more options | ||
*/ | ||
public GetMultipleSubmissionsOptions gradingPeriodId(Integer gradingPeriodId) { | ||
addSingleItem("grading_period_id", gradingPeriodId.toString()); | ||
return this; | ||
} | ||
|
||
/** | ||
* | ||
* The current status of the submission | ||
* @param workflowState the status to get the submissions | ||
* @return This object to allow adding more options | ||
*/ | ||
public GetMultipleSubmissionsOptions workflowState(String workflowState) { | ||
addSingleItem("workflow_state", workflowState); | ||
return this; | ||
} | ||
|
||
/** | ||
* | ||
* The current state of the enrollments. | ||
* If omitted will include all enrollments that are not deleted. | ||
* @param enrollmentState the state of the enrollment to get submissions | ||
* @return This object to allow adding more options | ||
*/ | ||
public GetMultipleSubmissionsOptions enrollmentState(String enrollmentState) { | ||
addSingleItem("enrollment_state", enrollmentState); | ||
return this; | ||
} | ||
|
||
/** | ||
* If omitted it is set to true. When set to false it will ignore the effective state of the student enrollments | ||
* and use the workflow_state for the enrollments. | ||
* The argument is ignored unless enrollment_state argument is also passed. | ||
* @param stateBasedOnDate the state of the enrollment to get submissions | ||
* @return This object to allow adding more options | ||
*/ | ||
public GetMultipleSubmissionsOptions stateBasedOnDate(Boolean stateBasedOnDate) { | ||
addSingleItem("state_based_on_date", stateBasedOnDate.toString()); | ||
return this; | ||
} | ||
|
||
/** | ||
* The order submissions will be returned in. | ||
* Defaults to “id”. Doesn't affect results for “grouped” mode. | ||
* @param order the order indicated | ||
* @return This object to allow adding more options | ||
*/ | ||
public GetMultipleSubmissionsOptions order(String order) { | ||
addSingleItem("order", order); | ||
return this; | ||
} | ||
|
||
/** | ||
* Determines whether ordered results are returned in ascending or descending order. | ||
* Defaults to “ascending”. | ||
* Doesn't affect results for “grouped” mode. | ||
* @param orderDirection "ascending" or "descending" | ||
* @return This object to allow adding more options | ||
*/ | ||
public GetMultipleSubmissionsOptions orderDirection(String orderDirection) { | ||
addSingleItem("order_direction", orderDirection); | ||
return this; | ||
} | ||
|
||
|
||
public String getCanvasId() { | ||
return canvasId; | ||
} | ||
|
||
|
||
public void setCanvasId(String canvasId) { | ||
this.canvasId = canvasId; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/test/java/edu/ksu/canvas/tests/submission/SubmissionUTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package edu.ksu.canvas.tests.submission; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import edu.ksu.canvas.CanvasTestBase; | ||
import edu.ksu.canvas.impl.SubmissionImpl; | ||
import edu.ksu.canvas.interfaces.SubmissionReader; | ||
import edu.ksu.canvas.model.assignment.Submission; | ||
import edu.ksu.canvas.net.FakeRestClient; | ||
import edu.ksu.canvas.net.Response; | ||
import edu.ksu.canvas.requestOptions.GetMultipleSubmissionsOptions; | ||
|
||
public class SubmissionUTest extends CanvasTestBase { | ||
@Autowired | ||
private FakeRestClient fakeRestClient; | ||
private SubmissionReader submissionReader; | ||
|
||
@Before | ||
public void setupData() { | ||
submissionReader = new SubmissionImpl(baseUrl, apiVersion, SOME_OAUTH_TOKEN, fakeRestClient, SOME_CONNECT_TIMEOUT, | ||
SOME_READ_TIMEOUT, DEFAULT_PAGINATION_PAGE_SIZE, false); | ||
} | ||
|
||
@Test | ||
public void testGetCourseSubmissionMultipleAssignments() throws Exception { | ||
String someCourseId = "123456"; | ||
Response notErroredResponse = new Response(); | ||
notErroredResponse.setErrorHappened(false); | ||
notErroredResponse.setResponseCode(200); | ||
String url = baseUrl + "/api/v1/courses/" + someCourseId + "/students/submissions"; | ||
fakeRestClient.addSuccessResponse(url, "SampleJson/submission/SubmissionList.json"); | ||
|
||
List<Submission> submissions = submissionReader.getCourseSubmissionMultipleAssignments(new GetMultipleSubmissionsOptions(someCourseId)); | ||
Assert.assertEquals(2, submissions.size()); | ||
Assert.assertTrue(submissions.stream().map(Submission::getGrade).filter("A-"::equals).findFirst().isPresent()); | ||
Assert.assertTrue(submissions.stream().map(Submission::getGrade).filter("B-"::equals).findFirst().isPresent()); | ||
} | ||
} |
Oops, something went wrong.