Skip to content

Commit

Permalink
SAK-40523 - Samigo: Cannot save assessment work from URL takes (sakai…
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Pellicer authored and ern committed Oct 30, 2018
1 parent e990774 commit a3f2b0b
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 314 deletions.
158 changes: 0 additions & 158 deletions samigo/samigo-app/src/java/com/corejsf/UploadFilter.java

This file was deleted.

12 changes: 8 additions & 4 deletions samigo/samigo-app/src/java/com/corejsf/UploadRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
import org.apache.commons.fileupload.FileItem;
import lombok.extern.slf4j.Slf4j;

import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.component.api.ServerConfigurationService;

@Slf4j
public class UploadRenderer extends Renderer {

Expand Down Expand Up @@ -81,9 +84,10 @@ public void decode(FacesContext context, UIComponent component){
// check if file > maxSize allowed
log.debug("clientId ="+ clientId);
log.debug("fileItem ="+ item);
// if (item!=null) log.debug("***UploadRender: fileItem size ="+ item.getSize());
Long maxSize = (Long)((ServletContext)external.getContext()).getAttribute("FILEUPLOAD_SIZE_MAX");
// RU - typo. Stanford agrees, so this should be FINR

ServerConfigurationService serverConfigurationService = ComponentManager.get(ServerConfigurationService.class);
Long maxSize = Long.valueOf(serverConfigurationService.getString("samigo.sizeMax", "40960"));

if (item!=null && item.getSize()/1000 > maxSize.intValue()){
((ServletContext)external.getContext()).setAttribute("TEMP_FILEUPLOAD_SIZE", Long.valueOf(item.getSize()/1000));
((EditableValueHolder) component).setSubmittedValue("SizeTooBig:" + item.getName());
Expand All @@ -95,7 +99,7 @@ public void decode(FacesContext context, UIComponent component){
if (binding != null) target = binding.getValue(context);
else target = component.getAttributes().get("target");

String repositoryPath = (String)((ServletContext)external.getContext()).getAttribute("FILEUPLOAD_REPOSITORY_PATH");
String repositoryPath = serverConfigurationService.getString("samigo.answerUploadRepositoryPath", "${sakai.home}/samigo/answerUploadRepositoryPath/");
log.debug("****"+repositoryPath);
if (target != null){
File dir = new File(repositoryPath+target.toString()); //directory where file would be saved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ public boolean mediaIsValid()
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext external = context.getExternalContext();
Long fileSize = (Long)((ServletContext)external.getContext()).getAttribute("TEMP_FILEUPLOAD_SIZE");
Long maxSize = (Long)((ServletContext)external.getContext()).getAttribute("FILEUPLOAD_SIZE_MAX");
Long maxSize = Long.valueOf(ServerConfigurationService.getString("samigo.sizeMax", "40960"));

((ServletContext)external.getContext()).removeAttribute("TEMP_FILEUPLOAD_SIZE");
if (fileSize!=null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2688,7 +2688,7 @@ public boolean mediaIsValid()
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext external = context.getExternalContext();
Long fileSize = (Long)((ServletContext)external.getContext()).getAttribute("TEMP_FILEUPLOAD_SIZE");
Long maxSize = (Long)((ServletContext)external.getContext()).getAttribute("FILEUPLOAD_SIZE_MAX");
Long maxSize = Long.valueOf(ServerConfigurationService.getInt("samigo.sizeMax", 40960));

((ServletContext)external.getContext()).removeAttribute("TEMP_FILEUPLOAD_SIZE");
if (fileSize!=null){
Expand Down Expand Up @@ -2976,10 +2976,7 @@ public void setAgentAccessString(String agentString)
}

public boolean getSaveToDb(){
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext external = context.getExternalContext();
String saveToDb = (String)((ServletContext)external.getContext()).getAttribute("FILEUPLOAD_SAVE_MEDIA_TO_DB");
return ("true").equals(saveToDb);
return ServerConfigurationService.getBoolean("samigo.saveMediaToDb", true);
}

public void attachToItemContentBean(ItemGradingData itemGradingData, String questionId){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,9 @@ public void importAssessment(ValueChangeEvent e)
String uploadFile = (String) e.getNewValue();

if (uploadFile!= null && uploadFile.startsWith("SizeTooBig:")) {
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext external = context.getExternalContext();
String paramValue = ((Long)((ServletContext)external.getContext()).getAttribute("FILEUPLOAD_SIZE_MAX")).toString();
Long sizeMax = null;
float sizeMax_float = 0f;
if (paramValue != null) {
sizeMax = Long.parseLong(paramValue);
sizeMax_float = sizeMax.floatValue()/1024;
}
int sizeMax_int = Math.round(sizeMax_float);
Long sizeMax = Long.valueOf(ServerConfigurationService.getString("samigo.sizeMax", "40960"));
ResourceLoader rb =new ResourceLoader("org.sakaiproject.tool.assessment.bundle.AuthorImportExport");
String sizeTooBigMessage = MessageFormat.format(rb.getString("import_size_too_big"), uploadFile.substring(11), sizeMax_int);
String sizeTooBigMessage = MessageFormat.format(rb.getString("import_size_too_big"), uploadFile.substring(11), Math.round(sizeMax.floatValue()/1024));
FacesMessage message = new FacesMessage(sizeTooBigMessage);
FacesContext.getCurrentInstance().addMessage(null, message);
// remove unsuccessful file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.commons.lang3.StringUtils;

import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.rubrics.logic.RubricsConstants;
import org.sakaiproject.rubrics.logic.RubricsService;
import org.sakaiproject.tool.assessment.data.dao.assessment.AssessmentAccessControl;
Expand Down Expand Up @@ -177,16 +178,9 @@ else if (DeliveryBean.REVIEW_ASSESSMENT == action || DeliveryBean.TAKE_ASSESSMEN
// protocol = http://servername:8080/; deliverAudioRecording.jsp needs it
delivery.setProtocol(ContextUtil.getProtocol());

FacesContext context = FacesContext.getCurrentInstance();
ExternalContext external = context.getExternalContext();
String paramValue = ((Long)((ServletContext)external.getContext()).getAttribute("FILEUPLOAD_SIZE_MAX")).toString();
Long sizeMax = null;
float sizeMax_float = 0f;
if (paramValue != null) {
sizeMax = Long.parseLong(paramValue);
sizeMax_float = sizeMax.floatValue()/1024;
}
delivery.setFileUploadSizeMax(Math.round(sizeMax_float));
ServerConfigurationService serverConfigurationService = ComponentManager.get(ServerConfigurationService.class);
Long sizeMax = Long.valueOf(serverConfigurationService.getInt("samigo.sizeMax", 40960));
delivery.setFileUploadSizeMax(Math.round(sizeMax.floatValue()/1024));
delivery.setPublishedAssessment(pub);

// populate backing bean from published assessment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;

import org.apache.commons.lang3.StringUtils;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.site.api.Group;
import org.sakaiproject.site.cover.SiteService;
Expand Down Expand Up @@ -88,7 +88,7 @@ public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String alias = req.getParameter("id");
if ((alias==null) ||("").equals(alias)){
if (StringUtils.isEmpty(alias)) {
log.warn("The published URL you have entered is incorrect. id is missing. Please check in Published Settings.");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

import lombok.extern.slf4j.Slf4j;

import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.tool.assessment.data.dao.grading.AssessmentGradingData;
import org.sakaiproject.tool.assessment.data.dao.grading.ItemGradingData;
import org.sakaiproject.tool.assessment.data.dao.grading.MediaData;
Expand Down Expand Up @@ -90,8 +92,9 @@ public void doPost(HttpServletRequest req, HttpServletResponse res)
{
boolean mediaIsValid = true;
ServletContext context = super.getServletContext();
String repositoryPath = (String)context.getAttribute("FILEUPLOAD_REPOSITORY_PATH");
String saveToDb = (String)context.getAttribute("FILEUPLOAD_SAVE_MEDIA_TO_DB");
ServerConfigurationService serverConfigurationService = ComponentManager.get(ServerConfigurationService.class);
String repositoryPath = serverConfigurationService.getString("samigo.answerUploadRepositoryPath", "${sakai.home}/samigo/answerUploadRepositoryPath/");
String saveToDb = serverConfigurationService.getString("samigo.saveMediaToDb", "true");

log.debug("req content length ="+req.getContentLength());
log.debug("req content type ="+req.getContentType());
Expand Down
Loading

0 comments on commit a3f2b0b

Please sign in to comment.