Skip to content

Commit

Permalink
SAK-46139 - Assignments - submitted content should be queued when con…
Browse files Browse the repository at this point in the history
…tent-review is enabled on an existing assignment (sakaiproject#9724)
  • Loading branch information
bbailla2 authored Sep 1, 2021
1 parent 6f4cd8f commit a537b97
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.sakaiproject.assignment.api.model.Assignment;
import org.sakaiproject.assignment.api.model.AssignmentSubmission;
import org.sakaiproject.assignment.api.model.AssignmentSubmissionSubmitter;
import org.sakaiproject.content.api.ContentResource;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.EntityProducer;
import org.sakaiproject.entity.api.Reference;
Expand Down Expand Up @@ -782,6 +783,11 @@ public String getDeepLinkWithPermissions(String context, String assignmentId, bo
*/
public boolean isContentReviewVisibleForSubmission(AssignmentSubmission submission);

/**
* Gets all attachments in the submission that are acceptable to the content review service
*/
public List<ContentResource> getAllAcceptableAttachments(AssignmentSubmission submission);

/**
* Get an assignment that is linked with a gradebook item
* @param context the context (site id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3775,6 +3775,7 @@ public void postReviewableSubmissionAttachments(AssignmentSubmission submission)
}
}

@Transactional
public String createContentReviewAssignment(Assignment assignment, String assignmentRef, Instant openTime, Instant dueTime, Instant closeTime) {
Map<String, Object> opts = new HashMap<>();
Map<String, String> p = assignment.getProperties();
Expand Down Expand Up @@ -4563,9 +4564,10 @@ public boolean isContentReviewVisibleForSubmission(AssignmentSubmission submissi
}

/**
* Gets all attachments in the submission that are acceptable to the content review service
* {@inheritDoc}
*/
private List<ContentResource> getAllAcceptableAttachments(AssignmentSubmission s) {
@Override
public List<ContentResource> getAllAcceptableAttachments(AssignmentSubmission s) {
List<ContentResource> attachments = new ArrayList<>();
for (String attachment : s.getAttachments()) {
Reference attachmentRef = entityManager.newReference(attachment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6476,12 +6476,15 @@ private void post_save_submission(RunData data, boolean post) {
}

// SAK-26322 - add inline as an attachment for the content review service
if (post && a.getContentReview()) {
if (post) {
if (!isHtmlEmpty(text)) {
/* prepares a file representing the inline content;
* needed whether or not content review is used - it will be queued retroactively if we enable content review on the assignment in the future */
prepareInlineForContentReview(text, submission, state, u);
}

// Check if we need to post the attachments
if (!submission.getAttachments().isEmpty()) {
if (a.getContentReview() && !submission.getAttachments().isEmpty()) {
assignmentService.postReviewableSubmissionAttachments(submission);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.sakaiproject.assignment.api.AssignmentService;
import org.sakaiproject.assignment.api.model.Assignment;
import org.sakaiproject.content.api.ContentHostingService;
import org.sakaiproject.content.api.ContentResource;
Expand All @@ -53,7 +52,6 @@
import org.sakaiproject.contentreview.exception.TransientSubmissionException;
import org.sakaiproject.contentreview.service.BaseContentReviewService;
import org.sakaiproject.contentreview.service.ContentReviewQueueService;
import org.sakaiproject.entity.api.EntityManager;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.entitybroker.EntityReference;
import org.sakaiproject.exception.IdUnusedException;
Expand Down Expand Up @@ -192,8 +190,6 @@ public static CompilatioError find(int faultCodeInt) {
@Setter protected ToolManager toolManager;
@Setter protected UserDirectoryService userDirectoryService;
@Setter protected ContentHostingService contentHostingService;
@Setter protected EntityManager entityManager;
@Setter protected AssignmentService assignmentService;
@Setter protected CompilatioAccountConnection compilatioConn;
@Setter protected CompilatioContentValidator compilatioContentValidator;
@Setter protected ContentReviewSiteAdvisor siteAdvisor;
Expand Down
4 changes: 4 additions & 0 deletions content-review/impl/service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
</parent>

<dependencies>
<dependency>
<groupId>org.sakaiproject.assignment</groupId>
<artifactId>sakai-assignment-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,31 @@

import java.time.Instant;
import java.io.StringReader;
import java.util.List;
import java.util.Optional;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.sakaiproject.assignment.api.AssignmentService;
import org.sakaiproject.assignment.api.model.Assignment;
import org.sakaiproject.assignment.api.model.AssignmentSubmission;
import org.sakaiproject.assignment.api.model.AssignmentSubmissionSubmitter;
import org.sakaiproject.content.api.ContentResource;
import org.sakaiproject.contentreview.exception.SubmissionException;
import org.sakaiproject.contentreview.exception.TransientSubmissionException;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.contentreview.dao.ContentReviewConstants;
import org.sakaiproject.contentreview.dao.ContentReviewItem;
import org.sakaiproject.contentreview.exception.ContentReviewProviderException;
import org.sakaiproject.contentreview.exception.QueueException;
import org.sakaiproject.contentreview.exception.ReportException;
import org.sakaiproject.entity.api.EntityManager;
import org.sakaiproject.entity.api.EntityPropertyNotDefinedException;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.entity.api.ResourcePropertiesEdit;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.user.api.PreferencesEdit;
import org.sakaiproject.user.api.PreferencesService;
import org.sakaiproject.util.ResourceLoader;
Expand All @@ -42,7 +55,11 @@

@Slf4j
public abstract class BaseContentReviewService implements ContentReviewService{


@Setter
protected AssignmentService assignmentService;
@Setter
protected EntityManager entityManager;
@Setter
protected PreferencesService preferencesService;
@Setter
Expand Down Expand Up @@ -114,6 +131,50 @@ public void updateUserEULATimestamp(String userId) {
log.error(e.getMessage(), e);
}
}

@Override
public void createAssignment(final String contextId, final String taskId, final Map opts)
throws SubmissionException, TransientSubmissionException {
queueAllSubmissionsForAssignment(taskId);
}

protected void queueAllSubmissionsForAssignment(final String taskId) {
try {
Assignment assignment;
try {
// Assume it's from the Assignments tool, support can be added to other tools in the future if there is a need to integrate with content-review
assignment = assignmentService.getAssignment(entityManager.newReference(taskId));
}
catch (IdUnusedException | PermissionException e) {
return;
}

Set<AssignmentSubmission> submissions = assignmentService.getSubmissions(assignment);
if (submissions != null) {
submissions.stream().filter(AssignmentSubmission::getSubmitted).forEach(sub -> {
List<ContentResource> attachments = assignmentService.getAllAcceptableAttachments(sub);
if (!attachments.isEmpty()) {
Optional<AssignmentSubmissionSubmitter> submitter = assignmentService.getSubmissionSubmittee(sub);
if (!submitter.isPresent() && allowSubmissionsOnBehalf()) {
submitter = sub.getSubmitters().stream().findAny();
}
if (submitter.isPresent()) {
try {
queueContent(submitter.get().getSubmitter(), assignment.getContext(), taskId, attachments);
}
catch (QueueException e) {
// Already queued most likely
}
}
}
});
}
}
catch (Exception e)
{
log.error("Unknown excpetion queueing submissions for assessment " + taskId, e);
}
}

@Override
public String getReviewReport(String contentId, String assignmentRef, String userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.sakaiproject.assignment.api.AssignmentConstants;
import org.sakaiproject.assignment.api.AssignmentService;
import org.sakaiproject.assignment.api.model.Assignment;
import org.sakaiproject.assignment.api.model.AssignmentSubmission;
import org.sakaiproject.assignment.api.model.AssignmentSubmissionSubmitter;
Expand All @@ -74,7 +73,6 @@
import org.sakaiproject.contentreview.exception.TransientSubmissionException;
import org.sakaiproject.contentreview.service.BaseContentReviewService;
import org.sakaiproject.contentreview.service.ContentReviewQueueService;
import org.sakaiproject.entity.api.EntityManager;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.PermissionException;
Expand Down Expand Up @@ -105,15 +103,9 @@ public class ContentReviewServiceTurnitinOC extends BaseContentReviewService {
@Setter
private UserDirectoryService userDirectoryService;

@Setter
private EntityManager entityManager;

@Setter
private SecurityService securityService;

@Setter
private AssignmentService assignmentService;

@Setter
private SiteService siteService;

Expand Down Expand Up @@ -489,12 +481,6 @@ public void syncRosters() {
// Auto-generated method stub
}

@Override
public void createAssignment(final String contextId, final String assignmentRef, final Map opts)
throws SubmissionException, TransientSubmissionException {
// Auto-generated method stub
}

public List<ContentReviewItem> getAllContentReviewItems(String siteId, String taskId)
throws QueueException, SubmissionException, ReportException {
return crqs.getContentReviewItems(getProviderId(), siteId, taskId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import org.sakaiproject.contentreview.service.ContentReviewQueueService;
import org.sakaiproject.contentreview.turnitin.util.TurnitinAPIUtil;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.EntityManager;
import org.sakaiproject.entity.api.EntityProducer;
import org.sakaiproject.entity.api.Reference;
import org.sakaiproject.entity.api.ResourceProperties;
Expand Down Expand Up @@ -217,9 +216,6 @@ public class TurnitinReviewServiceImpl extends BaseContentReviewService {
@Setter
private TurnitinAccountConnection turnitinConn;

@Setter
private EntityManager entityManager;

@Setter
private ContentHostingService contentHostingService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.sakaiproject.contentreview.service.BaseContentReviewService;
import org.sakaiproject.contentreview.service.ContentReviewQueueService;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.EntityManager;
import org.sakaiproject.entity.api.EntityProducer;
import org.sakaiproject.entity.api.Reference;
import org.sakaiproject.entity.api.ResourceProperties;
Expand Down Expand Up @@ -93,9 +92,6 @@ public class ContentReviewServiceVeriCite extends BaseContentReviewService {
@Setter
private UserDirectoryService userDirectoryService;

@Setter
private EntityManager entityManager;

@Setter
private SecurityService securityService;

Expand Down
2 changes: 0 additions & 2 deletions content-review/pack/src/webapp/WEB-INF/compilatio.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
<property name="toolManager" ref="org.sakaiproject.tool.api.ToolManager" />
<property name="userDirectoryService" ref="org.sakaiproject.user.api.UserDirectoryService" />
<property name="contentHostingService" ref="org.sakaiproject.content.api.ContentHostingService" />
<property name="entityManager" ref="org.sakaiproject.entity.api.EntityManager" />
<property name="assignmentService" ref="org.sakaiproject.assignment.api.AssignmentService" />
<property name="compilatioContentValidator" ref="org.sakaiproject.contentreview.compilatio.CompilatioContentValidator" />
<property name="compilatioConn" ref="org.sakaiproject.contentreview.compilatio.CompilatioAccountConnection" />
<property name="siteAdvisor" ref="org.sakaiproject.contentreview.service.ContentReviewSiteAdvisor" />
Expand Down
2 changes: 2 additions & 0 deletions content-review/pack/src/webapp/WEB-INF/components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<bean id="org.sakaiproject.contentreview.service.BaseContentReviewService"
class="org.sakaiproject.contentreview.service.BaseContentReviewService"
abstract="true">
<property name="assignmentService" ref="org.sakaiproject.assignment.api.AssignmentService" />
<property name="entityManager" ref="org.sakaiproject.entity.api.EntityManager" />
<property name="preferencesService" ref="org.sakaiproject.user.api.PreferencesService" />
<property name="serverConfigurationService" ref="org.sakaiproject.component.api.ServerConfigurationService" />
</bean>
Expand Down
2 changes: 0 additions & 2 deletions content-review/pack/src/webapp/WEB-INF/turnitin-oc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
parent="org.sakaiproject.contentreview.service.BaseContentReviewService"
init-method="init" lazy-init="true">
<property name="userDirectoryService" ref="org.sakaiproject.user.api.UserDirectoryService" />
<property name="entityManager" ref="org.sakaiproject.entity.api.EntityManager" />
<property name="sessionManager" ref="org.sakaiproject.tool.api.SessionManager" />
<property name="securityService" ref="org.sakaiproject.authz.api.SecurityService" />
<property name="assignmentService" ref="org.sakaiproject.assignment.api.AssignmentService" />
<property name="siteService" ref="org.sakaiproject.site.api.SiteService" />
<property name="crqs" ref="org.sakaiproject.contentreview.service.ContentReviewQueueService" />
<property name="contentHostingService" ref="org.sakaiproject.content.api.ContentHostingService" />
Expand Down
1 change: 0 additions & 1 deletion content-review/pack/src/webapp/WEB-INF/turnitin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<property name="toolManager" ref="org.sakaiproject.tool.api.ToolManager" />
<property name="userDirectoryService" ref="org.sakaiproject.user.api.UserDirectoryService" />
<property name="contentHostingService" ref="org.sakaiproject.content.api.ContentHostingService" />
<property name="entityManager" ref="org.sakaiproject.entity.api.EntityManager" />
<property name="sakaiPersonManager" ref="org.sakaiproject.api.common.edu.person.SakaiPersonManager" />
<property name="turnitinContentValidator" ref="org.sakaiproject.contentreview.turnitin.TurnitinContentValidator" />
<property name="siteService" ref="org.sakaiproject.site.api.SiteService" />
Expand Down
1 change: 0 additions & 1 deletion content-review/pack/src/webapp/WEB-INF/vericite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
parent="org.sakaiproject.contentreview.service.BaseContentReviewService"
init-method="init" lazy-init="true">
<property name="userDirectoryService" ref="org.sakaiproject.user.api.UserDirectoryService" />
<property name="entityManager" ref="org.sakaiproject.entity.api.EntityManager" />
<property name="securityService" ref="org.sakaiproject.authz.api.SecurityService" />
<property name="siteService" ref="org.sakaiproject.site.api.SiteService" />
<property name="crqs" ref="org.sakaiproject.contentreview.service.ContentReviewQueueService" />
Expand Down

0 comments on commit a537b97

Please sign in to comment.