Overview
The AssessmentServiceAPI is the main interface for managing assessments (tests and quizzes) in Samigo, Sakai’s Tests & Quizzes tool. This service provides methods for creating, updating, and managing assessments and their components.
Package: org.sakaiproject.tool.assessment.shared.api.assessment
Source: /samigo/samigo-api/src/java/org/sakaiproject/tool/assessment/shared/api/assessment/AssessmentServiceAPI.java
Assessment Management
getAssessment
Retrieve an assessment by its ID.
public AssessmentIfc getAssessment(String assessmentId);
The unique identifier of the assessment
Returns: The AssessmentIfc object representing the assessment
Example:
AssessmentIfc assessment = assessmentService.getAssessment("123");
System.out.println("Title: " + assessment.getTitle());
System.out.println("Description: " + assessment.getDescription());
getBasicInfoOfAnAssessment
Retrieve only basic information about an assessment (more efficient than full retrieval).
public AssessmentIfc getBasicInfoOfAnAssessment(String assessmentId);
Returns: The AssessmentIfc with basic information only
Example:
AssessmentIfc basicInfo = assessmentService.getBasicInfoOfAnAssessment("123");
System.out.println("Title: " + basicInfo.getTitle());
// Other properties may not be loaded
createAssessment
Create a new assessment.
public AssessmentIfc createAssessment(
String title,
String description,
String typeId,
String templateId
);
The assessment description
The template ID to use for the assessment
Returns: The newly created AssessmentIfc object
Example:
AssessmentIfc assessment = assessmentService.createAssessment(
"Midterm Exam",
"Comprehensive midterm examination",
"1", // Quiz type
"1" // Default template
);
createAssessmentWithoutDefaultSection
Create an assessment without automatically creating a default section.
public AssessmentIfc createAssessmentWithoutDefaultSection(
String title,
String description,
String typeId,
String templateId
);
The assessment description
Returns: The newly created AssessmentIfc without a default section
saveAssessment
Save changes to an assessment.
public void saveAssessment(AssessmentIfc assessment);
Example:
AssessmentIfc assessment = assessmentService.getAssessment("123");
assessment.setTitle("Updated Title");
assessment.setDescription("Updated description");
assessmentService.saveAssessment(assessment);
update
Update an assessment (alternative to saveAssessment).
public void update(AssessmentIfc assessment);
removeAssessment
Remove an assessment.
public void removeAssessment(String assessmentId);
The ID of the assessment to remove
Example:
assessmentService.removeAssessment("123");
Assessment Retrieval
getAllAssessments
Get all assessments with specified ordering.
public List getAllAssessments(String orderBy);
The field to order by (e.g., “title”, “lastModifiedDate”)
Returns: List of all AssessmentIfc objects
getAllActiveAssessments
Get all active (published) assessments.
public List getAllActiveAssessments(String orderBy);
Returns: List of active AssessmentIfc objects
Example:
List<AssessmentIfc> activeAssessments =
assessmentService.getAllActiveAssessments("title");
for (AssessmentIfc assessment : activeAssessments) {
System.out.println(assessment.getTitle());
}
getBasicInfoOfAllActiveAssessments
Get basic information for all active assessments.
public List getBasicInfoOfAllActiveAssessments(String orderBy);
public List getBasicInfoOfAllActiveAssessments(String orderBy, boolean ascending);
Sort order (true for ascending, false for descending)
Returns: List of AssessmentIfc objects with basic information
getSettingsOfAllActiveAssessments
Get settings for all active assessments.
public List getSettingsOfAllActiveAssessments(String orderBy);
Returns: List with assessment settings information
getAllAssessments (Paginated)
Get assessments with pagination.
public List getAllAssessments(int pageSize, int pageNumber, String orderBy);
Number of assessments per page
The page number (0-based)
Returns: List of AssessmentIfc objects for the specified page
Example:
// Get first page with 10 assessments
List<AssessmentIfc> page1 = assessmentService.getAllAssessments(10, 0, "title");
// Get second page
List<AssessmentIfc> page2 = assessmentService.getAllAssessments(10, 1, "title");
Section Management
addSection
Add a new section to an assessment.
public SectionDataIfc addSection(String assessmentId);
The ID of the assessment to add the section to
Returns: The newly created SectionDataIfc object
Example:
SectionDataIfc section = assessmentService.addSection("123");
section.setTitle("Part 1: Multiple Choice");
section.setDescription("Answer all questions");
assessmentService.saveOrUpdateSection(section);
getSection
Retrieve a section by its ID.
public SectionDataIfc getSection(String sectionId);
Returns: The SectionDataIfc object
saveOrUpdateSection
Save or update a section.
public void saveOrUpdateSection(SectionDataIfc section);
The section to save or update
removeSection
Remove a section from an assessment.
public void removeSection(String sectionId);
The ID of the section to remove
Example:
assessmentService.removeSection("section456");
moveAllItems
Move all items from one section to another.
public void moveAllItems(String sourceSectionId, String destSectionId);
The destination section ID
Example:
// Move all questions from section1 to section2
assessmentService.moveAllItems("section1", "section2");
removeAllItems
Remove all items from a section.
public void removeAllItems(String sourceSectionId);
The section ID to remove all items from
Question/Item Management
getQuestionSize
Get the number of questions in an assessment.
public int getQuestionSize(String assessmentId);
Returns: The number of questions in the assessment
Example:
int questionCount = assessmentService.getQuestionSize("123");
System.out.println("This assessment has " + questionCount + " questions");
Template Management
getAssessmentTemplate
Retrieve an assessment template.
public AssessmentTemplateIfc getAssessmentTemplate(String assessmentTemplateId);
Returns: The AssessmentTemplateIfc object
getAllAssessmentTemplates
Get all assessment templates.
public List getAllAssessmentTemplates();
Returns: List of all AssessmentTemplateIfc objects
getAllActiveAssessmentTemplates
Get all active assessment templates.
public List getAllActiveAssessmentTemplates();
Returns: List of active AssessmentTemplateIfc objects
getTitleOfAllActiveAssessmentTemplates
Get titles of all active templates.
public List getTitleOfAllActiveAssessmentTemplates();
Returns: List of template titles
getBasicInfoOfAllActiveAssessmentTemplates
Get basic information for all active templates.
public List getBasicInfoOfAllActiveAssessmentTemplates(String orderBy);
Returns: List of template basic information
save (Template)
Save a template.
public void save(AssessmentTemplateIfc template);
template
AssessmentTemplateIfc
required
The template to save
deleteAssessmentTemplate
Delete an assessment template.
public void deleteAssessmentTemplate(Long assessmentId);
The template ID to delete
Complete Example
import org.sakaiproject.tool.assessment.shared.api.assessment.*;
import org.sakaiproject.tool.assessment.data.ifc.assessment.*;
import java.util.List;
public class SamigoExample {
private AssessmentServiceAPI assessmentService;
public void createQuizExample() {
// Create a new quiz
AssessmentIfc quiz = assessmentService.createAssessment(
"Week 1 Quiz",
"Quiz covering week 1 material",
"1", // Quiz type
"1" // Default template
);
// Add a section
SectionDataIfc section1 = assessmentService.addSection(quiz.getAssessmentId().toString());
section1.setTitle("Multiple Choice Questions");
section1.setDescription("Choose the best answer");
assessmentService.saveOrUpdateSection(section1);
// Add another section
SectionDataIfc section2 = assessmentService.addSection(quiz.getAssessmentId().toString());
section2.setTitle("True/False Questions");
assessmentService.saveOrUpdateSection(section2);
// Save the quiz
assessmentService.saveAssessment(quiz);
System.out.println("Quiz created with ID: " + quiz.getAssessmentId());
System.out.println("Number of questions: " +
assessmentService.getQuestionSize(quiz.getAssessmentId().toString()));
}
public void listActiveAssessments() {
List<AssessmentIfc> assessments =
assessmentService.getAllActiveAssessments("title");
System.out.println("Active Assessments:");
for (AssessmentIfc assessment : assessments) {
System.out.println("- " + assessment.getTitle());
System.out.println(" Questions: " +
assessmentService.getQuestionSize(
assessment.getAssessmentId().toString()
));
}
}
public void manageSections(String assessmentId) {
// Get assessment
AssessmentIfc assessment = assessmentService.getAssessment(assessmentId);
// Add a new section
SectionDataIfc newSection = assessmentService.addSection(assessmentId);
newSection.setTitle("Bonus Questions");
assessmentService.saveOrUpdateSection(newSection);
// Move items between sections (if needed)
// assessmentService.moveAllItems("oldSectionId", newSection.getSectionId().toString());
// Save assessment
assessmentService.saveAssessment(assessment);
}
public void copyAssessment(String sourceAssessmentId) {
// Get source assessment
AssessmentIfc source = assessmentService.getAssessment(sourceAssessmentId);
// Create new assessment with similar properties
AssessmentIfc copy = assessmentService.createAssessment(
source.getTitle() + " (Copy)",
source.getDescription(),
source.getTypeId().toString(),
"1" // Use default template
);
// Copy would need to iterate through sections and items
// This is simplified - actual implementation would copy all content
assessmentService.saveAssessment(copy);
System.out.println("Created copy with ID: " + copy.getAssessmentId());
}
}
The Samigo API includes several related service interfaces:
- ItemServiceAPI - Managing individual questions/items
- PublishedAssessmentServiceAPI - Managing published assessments
- SectionServiceAPI - Section-specific operations
- GradingServiceAPI - Grading and scoring operations
- QuestionPoolServiceAPI - Question pool management
See Also