<commit_before>/**********************************************************************************
* $URL$
* $Id$
***********************************************************************************
*
* Copyright (c) 2004-2005 The Regents of the University of Michigan, Trustees of Indiana University,
*                  Board of Trustees of the Leland Stanford, Jr., University, and The MIT Corporation
*
* Licensed under the Educational Community License Version 1.0 (the "License");
* By obtaining, using and/or copying this Original Work, you agree that you have read,
* understand, and will comply with the terms and conditions of the Educational Community License.
* You may obtain a copy of the License at:
*
*      http://cvs.sakaiproject.org/licenses/license_1_0.html
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**********************************************************************************/

package org.sakaiproject.tool.assessment.ui.listener.delivery;

import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.sakaiproject.tool.assessment.ui.bean.delivery.DeliveryBean;
import org.sakaiproject.tool.assessment.ui.listener.util.ContextUtil;
import javax.faces.component.UIOutput;
import javax.faces.event.FacesEvent;

/**
 * <p>Title: Samigo</p>
 * <p>Purpose:  When student makes a recording for an audio question type
 * the audio recorder applet makes a copy of the local recording and posts it
 * to a special servlet,
 * @see org.sakaiproject.tool.assessment.ui.servlet.delivery.UploadAudioMediaServlet,
 *  that copies it to a designated file on the server.
 * When that student then posts the answer by pressing the Update button, the
 * actual grading record is made.
 * </p>
 * <p>Description: Sakai Assessment Manager</p>
 * <p>Copyright: Copyright (c) 2004 Sakai Project</p>
 * <p>Organization: Sakai Project</p>
 * @author <NAME>
 * @version $Id$
 */

public class AudioUploadActionListener implements ActionListener
{
  private static Log log = LogFactory.getLog(AudioUploadActionListener.class);
  private static ContextUtil cu;

  /**
   * ACTION.
   * @param ae the action event triggering the processAction method
   * @throws AbortProcessingException
   */
  public void processAction(ActionEvent ae) throws
    AbortProcessingException
  {
    log.info("AudioUploadActionListener.processAction() ");

    try {
      // get managed bean
      DeliveryBean delivery = (DeliveryBean) cu.lookupBean("delivery");

      // look for the correct file upload path information
      String audioMediaUploadPath = getAudioMediaUploadPath(ae);
      log.info("audioMediaUploadPath: " + audioMediaUploadPath);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  /**
   * Get audio media upload path from the event's component tree.
   * @param ae  the event
   * @return
   */
  private String getAudioMediaUploadPath(FacesEvent ae)
  {
    String audioMediaUploadPath = null;

    // now find what component fired the event
    UIComponent component = ae.getComponent();
    // get the subview containing the audio question
    UIComponent parent = component.getParent();

    // get the its peer components from the parent
    List peers = parent.getChildren();

    // look for the correct file upload path information
    // held in the value of the component 'audioMediaUploadPath'
    // we are printing debugging code for now.
    for (int i = 0; i < peers.size(); i++)
    {
      UIComponent peer = (UIComponent) peers.get(i);

      if ("audioMediaUploadPath".equals(peer.getId()) && peer instanceof UIOutput)
      {
        audioMediaUploadPath = "" + ((UIOutput) peer).getValue();
        log.info("FOUND: Component " + i +
                 " peer.getId(): " + peer.getId()+
                 " peer.getValue(): " + audioMediaUploadPath );
        break;
      }
    }

    return audioMediaUploadPath;
  }

}
<commit_msg>SAK-1894: Added audio to item grading.<commit_after>/**********************************************************************************
* $URL$
* $Id$
***********************************************************************************
*
* Copyright (c) 2004-2005 The Regents of the University of Michigan, Trustees of Indiana University,
*                  Board of Trustees of the Leland Stanford, Jr., University, and The MIT Corporation
*
* Licensed under the Educational Community License Version 1.0 (the "License");
* By obtaining, using and/or copying this Original Work, you agree that you have read,
* understand, and will comply with the terms and conditions of the Educational Community License.
* You may obtain a copy of the License at:
*
*      http://cvs.sakaiproject.org/licenses/license_1_0.html
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**********************************************************************************/

package org.sakaiproject.tool.assessment.ui.listener.delivery;

import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.sakaiproject.tool.assessment.ui.bean.delivery.DeliveryBean;
import org.sakaiproject.tool.assessment.ui.listener.util.ContextUtil;
import javax.faces.component.UIOutput;
import javax.faces.event.FacesEvent;

/**
 * <p>Title: Samigo</p>
 * <p>Purpose:  When student makes a recording for an audio question type
 * the audio recorder applet makes a copy of the local recording and posts it
 * to a special servlet,
 * @see org.sakaiproject.tool.assessment.ui.servlet.delivery.UploadAudioMediaServlet,
 *  that copies it to a designated file on the server.
 * When that student then posts the answer by pressing the Update button, the
 * actual grading record is made.
 * </p>
 * <p>Description: Sakai Assessment Manager</p>
 * <p>Copyright: Copyright (c) 2004 Sakai Project</p>
 * <p>Organization: Sakai Project</p>
 * @author <NAME>
 * @version $Id$
 */

public class AudioUploadActionListener implements ActionListener
{
  private static Log log = LogFactory.getLog(AudioUploadActionListener.class);
  private static ContextUtil cu;

  /**
   * ACTION. add audio recording to item grading
   * @param ae the action event triggering the processAction method
   * @throws AbortProcessingException
   */
  public void processAction(ActionEvent ae) throws
    AbortProcessingException
  {
    log.info("AudioUploadActionListener.processAction() ");

    try {
      // get managed bean
      DeliveryBean delivery = (DeliveryBean) cu.lookupBean("delivery");

      // look for the correct file upload path information
      String audioMediaUploadPath = getAudioMediaUploadPath(ae);
      log.info("audioMediaUploadPath: " + audioMediaUploadPath);

      // now use utility method to fetch the file
      delivery.addMediaToItemGrading(audioMediaUploadPath);
      log.info("delivery.addMediaToItemGrading(audioMediaUploadPath)");


    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  /**
   * Get audio media upload path from the event's component tree.
   * @param ae  the event
   * @return
   */
  private String getAudioMediaUploadPath(FacesEvent ae)
  {
    String audioMediaUploadPath = null;

    // now find what component fired the event
    UIComponent component = ae.getComponent();
    // get the subview containing the audio question
    UIComponent parent = component.getParent();

    // get the its peer components from the parent
    List peers = parent.getChildren();

    // look for the correct file upload path information
    // held in the value of the component 'audioMediaUploadPath'
    for (int i = 0; i < peers.size(); i++)
    {
      UIComponent peer = (UIComponent) peers.get(i);

      if ("audioMediaUploadPath".equals(peer.getId()) && peer instanceof UIOutput)
      {
        audioMediaUploadPath = "" + ((UIOutput) peer).getValue();
        log.info("FOUND: Component " + i +
                 " peer.getId(): " + peer.getId()+
                 " peer.getValue(): " + audioMediaUploadPath );
        break;
      }
    }

    return audioMediaUploadPath;
  }

}

{'fraction_non_alphanumeric': 0.13933189655172415, 'fraction_numerical': 0.004094827586206897, 'mean_word_length': 3.882167280378748, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2567729', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2407, 'n_words': 854}