You are not logged in. Click here to log in.

codeBeamer ALM

Search In Project

Search inClear

Tags:  not added yet

File Upload Listener

Overview

This page is created in order to describe how to add listener into the Listener API which runs after the file uploaded but before it's save. This feature is designed to post process any uploaded file e.g.: scan for viruses.

Version

The feature is available from codeBeamer version 9.5.0

Dependencies

For build and implementation the following dependencies or versions should be used:

  1. cb.jar: provided version from the installer
  2. Java version: 1.8
  3. Spring version: 3.2.11.RELEASE

All dependencies should be marked as provided.

Implementation

Create new listener

  1. Create a new java class
  2. Create spring managed bean by
    • Apply @org.springframework.stereotype.Component annotation on class level
      OR
    • Add the following xml snippet to the my-applicationContext.xm file
      <bean id="<unique_bean_name>" class="<full_qualified_name_of_class>" />
  3. Implement com.intland.codebeamer.event.FileUploadListener interface
    1. Implement fileUploaded(FileUploadEventData event) method

The event object contains the following information

  1. user - the initiator who uploaded the file
  2. source - the uploaded file

Processing

If the listener finds any problem with the uploaded file, throwing com.intland.codebeamer.event.util.VetoException will interrupt the file uploading process and the exception message will be shown to the user.

Integration

The created listener class should be compiled and added to the CLASSPATH of codeBeamer (for example under /install_dir/tomcat/webapps/cb/WEB-INF/classes) and must be re-started.

Example implementation

import com.intland.codebeamer.event.FileUploadEventData;
import com.intland.codebeamer.event.FileUploadListener;
import com.intland.codebeamer.event.util.VetoException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

@Component
public class ExampleFileUploadListener implements FileUploadListener {
   private static final Logger logger = Logger.getLogger(ExampleFileUploadListener.class);

   @Override
   public void fileUploaded(FileUploadEventData event) throws VetoException {
      logger.info("File upload post processing");
      boolean postProcessSuccess = true;

      //do post processing and store the result in postProcessSuccess

      if(!postProcessSuccess) {
          throw new VetoException("Custom error message");
      }
   }
}