Skip to content

Commit

Permalink
TII-269 - TurnitinOC - implement isAcceptableContent (sakaiproject#6974)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbailla2 authored and bjones86 committed May 31, 2019
1 parent cf2d100 commit 2461ef8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 27 deletions.
40 changes: 20 additions & 20 deletions content-review/impl/turnitin-oc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,34 @@ assignment.useContentReview=true
# default: false
# turnitin.oc.skip.delays=false
# turnitin.accept.all.files (Optional)
# turnitin.oc.accept.all.files (Optional)
# If true, any file type will be accepted by Sakai. Invalid file types will still be rejected by Turnitin.
# default: false
# example: turnitin.accept.all.files=false
# example: turnitin.oc.accept.all.files=false
# turnitin.acceptable.file.extensions (Optional)
# Allows you to customize the set of file extensions that Sakai will allow you to submit to Turnitin. Invalid file types will still be rejected by Turnitin. This list must match the list set for turnitin.acceptable.mime.types and turnitin.acceptable.file.types
# turnitin.oc.acceptable.file.extensions (Optional)
# Allows you to customize the set of file extensions that Sakai will allow you to submit to Turnitin. Invalid file types will still be rejected by Turnitin. This list must match the list set for turnitin.oc.acceptable.mime.types and turnitin.oc.acceptable.file.types
# default: A hard coded list of mime types
# example: turnitin.acceptable.file.extensions.count=3
# turnitin.acceptable.file.extensions.1=.pdf
# turnitin.acceptable.file.extensions.2=.docx
# turnitin.acceptable.file.extensions.3=.txt
# example: turnitin.oc.acceptable.file.extensions.count=3
# turnitin.oc.acceptable.file.extensions.1=.pdf
# turnitin.oc.acceptable.file.extensions.2=.docx
# turnitin.oc.acceptable.file.extensions.3=.txt
# turnitin.acceptable.mime.types (Optional)
# Allows you to customize the set of file extensions that Sakai will allow you to submit to Turnitin. Invalid file types will still be rejected by Turnitin. This list must match the list set for turnitin.acceptable.file.extensions and turnitin.acceptable.file.types
# turnitin.oc.acceptable.mime.types (Optional)
# Allows you to customize the set of file extensions that Sakai will allow you to submit to Turnitin. Invalid file types will still be rejected by Turnitin. This list must match the list set for turnitin.oc.acceptable.file.extensions and turnitin.oc.acceptable.file.types
# default: A hard coded list of mime types
# example: turnitin.acceptable.mime.types.count=3
# turnitin.acceptable.mime.types.1=application/pdf
# turnitin.acceptable.mime.types.2=application/msword
# turnitin.acceptable.mime.types.3=text/plain
# example: turnitin.oc.acceptable.mime.types.count=3
# turnitin.oc.acceptable.mime.types.1=application/pdf
# turnitin.oc.acceptable.mime.types.2=application/msword
# turnitin.oc.acceptable.mime.types.3=text/plain
# turnitin.acceptable.file.types (Optional)
# Allows you to customize the set of file extensions that Sakai will allow you to submit to Turnitin. Invalid file types will still be rejected by Turnitin. This list must match the list set for turnitin.acceptable.file.extensions and turnitin.acceptable.mime.types
# turnitin.oc.acceptable.file.types (Optional)
# Allows you to customize the set of file extensions that Sakai will allow you to submit to Turnitin. Invalid file types will still be rejected by Turnitin. This list must match the list set for turnitin.oc.acceptable.file.extensions and turnitin.oc.acceptable.mime.types
# default: A hard coded list of file type descriptions
# example: turnitin.acceptable.file.types.count=3
# turnitin.acceptable.file.types.1=PDF
# turnitin.acceptable.file.types.2=Word Doc
# turnitin.acceptable.file.types.3=Rich Text
# example: turnitin.oc.acceptable.file.types.count=3
# turnitin.oc.acceptable.file.types.1=PDF
# turnitin.oc.acceptable.file.types.2=Word Doc
# turnitin.oc.acceptable.file.types.3=Rich Text
# turnitin.option.exclude_bibliographic (Optional)
# Allows you to show or hide the "exclude bibliography" option when creating an assignment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,13 @@ private enum AUTO_EXCLUDE_SELF_MATCHING_SCOPE{
};

// Sakai.properties overriding the arrays above
private final String PROP_ACCEPT_ALL_FILES = "turnitin.accept.all.files";
private final String PROP_ACCEPT_ALL_FILES = "turnitin.oc.accept.all.files";

private final String PROP_ACCEPTABLE_FILE_EXTENSIONS = "turnitin.acceptable.file.extensions";
private final String PROP_ACCEPTABLE_MIME_TYPES = "turnitin.acceptable.mime.types";
private final String PROP_ACCEPTABLE_FILE_EXTENSIONS = "turnitin.oc.acceptable.file.extensions";
private final String PROP_ACCEPTABLE_MIME_TYPES = "turnitin.oc.acceptable.mime.types";

// A list of the displayable file types (ie. "Microsoft Word", "WordPerfect document", "Postscript", etc.)
private final String PROP_ACCEPTABLE_FILE_TYPES = "turnitin.acceptable.file.types";
private final String PROP_ACCEPTABLE_FILE_TYPES = "turnitin.oc.acceptable.file.types";

private final String KEY_FILE_TYPE_PREFIX = "file.type";

Expand Down Expand Up @@ -585,9 +585,30 @@ public Integer getProviderId() {
return Math.abs("TurnitinOC".hashCode());
}

public boolean isAcceptableContent(ContentResource arg0) {
// TODO: what does TII accept?
return true;
public boolean isAcceptableContent(ContentResource resource) {
if (serverConfigurationService.getBoolean(PROP_ACCEPT_ALL_FILES, false)) {
return true;
}

String mime = resource.getContentType();

// Check the mime type
Map<String, SortedSet<String>> acceptableExtensionsToMimeTypes = getAcceptableExtensionsToMimeTypes();
if (acceptableExtensionsToMimeTypes.values().stream().anyMatch(set -> set.contains(mime))) {
return true;
}

// Check the file extension
ResourceProperties resourceProperties = resource.getProperties();
String fileName = resourceProperties.getProperty(resourceProperties.getNamePropDisplayName());
if (fileName.indexOf(".") > 0) {
String extension = fileName.substring(fileName.lastIndexOf("."));
if (acceptableExtensionsToMimeTypes.containsKey(extension)) {
return true;
}
}

return false;
}

public boolean isSiteAcceptable(Site arg0) {
Expand Down

0 comments on commit 2461ef8

Please sign in to comment.