Skip to content

Commit

Permalink
SCORM SCO-168: improve over quota message to include defined quota (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
bjones86 authored and ern committed Apr 11, 2024
1 parent 17aaef5 commit aa6566a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

import java.io.InputStream;
import java.util.List;
import org.sakaiproject.exception.IdInvalidException;
import org.sakaiproject.exception.IdLengthException;
import org.sakaiproject.exception.IdUniquenessException;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.OverQuotaException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.exception.ServerOverloadException;

import org.sakaiproject.scorm.exceptions.InvalidArchiveException;
import org.sakaiproject.scorm.exceptions.ResourceNotDeletedException;
Expand All @@ -40,7 +47,8 @@ public interface ScormResourceService

public List<Archive> getUnvalidatedArchives() throws ResourceStorageException;

public String putArchive(InputStream stream, String name, String mimeType, boolean isHidden, int priority) throws ResourceStorageException;
public String putArchive(InputStream stream, String name, String mimeType, boolean isHidden, int priority) throws PermissionException, IdUniquenessException, IdLengthException,
IdInvalidException, IdUnusedException, OverQuotaException, ServerOverloadException;

public void removeResources(String collectionId) throws ResourceNotDeletedException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.entity.api.ResourcePropertiesEdit;
import org.sakaiproject.event.api.NotificationService;
import org.sakaiproject.exception.IdInvalidException;
import org.sakaiproject.exception.IdLengthException;
import org.sakaiproject.exception.IdUniquenessException;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.IdUsedException;
import org.sakaiproject.exception.InUseException;
import org.sakaiproject.exception.OverQuotaException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.exception.ServerOverloadException;
import org.sakaiproject.exception.TypeException;
Expand Down Expand Up @@ -553,7 +557,8 @@ protected String newItem(String uuid, ZipInputStream zipStream, ZipEntry entry)
}

@Override
public String putArchive(InputStream stream, String name, String mimeType, boolean isHidden, int priority) throws ResourceStorageException
public String putArchive(InputStream stream, String name, String mimeType, boolean isHidden, int priority) throws PermissionException, IdUniquenessException, IdLengthException,
IdInvalidException, IdUnusedException, OverQuotaException, ServerOverloadException
{
String collectionId = getRootDirectoryPath();
String fileName = name;
Expand Down Expand Up @@ -587,7 +592,7 @@ public String putArchive(InputStream stream, String name, String mimeType, boole
log.error("Failed to place resources in Sakai content repository", e);
}

throw new ResourceStorageException(e);
throw e;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

import static org.sakaiproject.scorm.api.ScormConstants.*;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.content.api.ContentCollection;
import org.sakaiproject.content.api.ContentHostingService;
import org.sakaiproject.event.api.NotificationService;
import org.sakaiproject.exception.IdInvalidException;
import org.sakaiproject.exception.IdLengthException;
Expand All @@ -61,6 +63,9 @@ public class UploadPage extends ConsoleBasePage
@SpringBean( name = "org.sakaiproject.scorm.service.api.ScormResourceService" )
ScormResourceService resourceService;

@SpringBean( name="org.sakaiproject.content.api.ContentHostingService" )
ContentHostingService contentHostingService;

@Override
protected void onInitialize()
{
Expand Down Expand Up @@ -135,6 +140,7 @@ protected void onSubmit( AjaxRequestTarget target )
{
for( FileUpload upload : uploads )
{
String resourceId = "";
try
{
// Check if file size exceeds allowed threshold - defined in sakai.properties as "content.upload.max", measured in megabytes
Expand All @@ -146,7 +152,7 @@ protected void onSubmit( AjaxRequestTarget target )
return;
}

String resourceId = resourceService.putArchive( upload.getInputStream(), upload.getClientFileName(), upload.getContentType(), false, NotificationService.NOTI_NONE );
resourceId = resourceService.putArchive( upload.getInputStream(), upload.getClientFileName(), upload.getContentType(), false, NotificationService.NOTI_NONE );
int status = contentService.storeAndValidate( resourceId, false, serverConfigurationService.getString( "scorm.zip.encoding", "UTF-8" ) );

if( status == VALIDATION_SUCCESS )
Expand All @@ -161,6 +167,20 @@ protected void onSubmit( AjaxRequestTarget target )
onError( target );
}
}
catch( OverQuotaException e )
{
int quotaInMB = 20;
try
{
ContentCollection collection = contentHostingService.getCollection( resourceId );
long collectionQuota = contentHostingService.getQuota( collection ); // size in kb
quotaInMB = (int) collectionQuota / 1024;
}
catch( Exception ex ) { /* ignore */ }

error( MessageFormat.format( getString( "upload.OverQuotaException" ), quotaInMB ) );
log.error( "File puts user over quota: {}", upload.getClientFileName() );
}
catch( Exception e )
{
handleException(e, upload.getClientFileName());
Expand Down Expand Up @@ -206,10 +226,6 @@ else if( ex instanceof IdInvalidException )
{
errorKey = "upload.IdInvalidException";
}
else if( ex instanceof OverQuotaException )
{
errorKey = "upload.OverQuotaException";
}
else if( ex instanceof PermissionException )
{
errorKey = "upload.PermissionException";
Expand All @@ -218,7 +234,7 @@ else if( ex instanceof PermissionException )
// Generate the user facing error message, and print info to logs
error( getLocalizer().getString( errorKey, UploadPage.this ) );
log.error( "Failed to upload file: {}", fileName );
log.debug( "Exception occured while uploading module", ex);
log.debug( "Exception occured while uploading module", ex );
}

private String getNotification( int status )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ upload.IdUnusedException = There is a problem with the resources collection or i
upload.IdUniquenessException = A resource of this name already exists under the same collection.
upload.IdLengthException = The resource name provided is too long.
upload.IdInvalidException = The resource name provided is not valid.
upload.OverQuotaException = You have exceeded your quota or there is no more space remaining for this resource.
upload.OverQuotaException = You have exceeded your quota of {0} megabytes, or there is no more space remaining for this resource.
upload.PermissionException = You do not have permission to add this resource at this time.

validate.no.file = No Content Package was selected, or an invalid path was provided.
Expand Down

0 comments on commit aa6566a

Please sign in to comment.