skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Thursday, September 20, 2012

Static file auto approver

Posted by Admin at 12:44 PM – 0 comments
 

This is a lisener that automatically approve a static file when created / updated.


import com.vignette.as.client.exception.ApplicationException;
import com.vignette.as.client.exception.AuthorizationException;
import com.vignette.as.client.exception.ValidationException;
import com.vignette.as.config.ConfigUtil;
import com.vignette.as.config.component.AppSvcsComponent;
import com.vignette.as.server.event.AsDeploymentEvent;
import com.vignette.as.server.event.AsEvent;
import com.vignette.as.server.event.AsFileDeploymentEvent;
import com.vignette.as.server.event.IAsEventListener;
import com.vignette.config.client.common.ConfigException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;


public class StaticFileApprover implements IAsEventListener {
    
    private final static String APPROVED = "approved";
    private final static String APPSVCS_DATASOURCE = AppSvcsComponent.APPSVCS_RESOURCE_MNEMONIC;
    
    
    /**
     * Constructor StaticFileApprover.
     */

    public StaticFileApprover() {
    }
    
    /**
     * Processes, or consumes, events of interest.
     *
     * @param event the event.
     * @throws ApplicationException   thrown if application errors occur when an
     *                                AsEvent is processed.
     * @throws AuthorizationException thrown if security errors occur when an
     *                                AsEvent is processed.
     * @throws ValidationException    thrown if validation errors occur when an
     *                                AsEvent is processed.
     */
    public void consume(AsEvent event) throws ApplicationException, AuthorizationException, ValidationException {
        try {
            if (event.getClass() == com.vignette.as.server.event.AsFileDeploymentEvent.class) {
                if (event.getType().equals(AsDeploymentEvent.FILE_CREATE)) {
                    System.out.println("*******StaticFileApprover - Post Persistence Create Event is triggered.");
                    processEvent((AsFileDeploymentEvent)event);
                } else if (event.getType().equals(AsDeploymentEvent.FILE_UPDATE)) {
                    processEvent((AsFileDeploymentEvent)event);
                }
            }
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }
    
    private void processEvent(AsFileDeploymentEvent event) throws  ApplicationException, AuthorizationException, ValidationException {
        Connection conn = null;
        PreparedStatement stmt = null;
        try {
            StringBuffer sql = new StringBuffer();
            sql.append("UPDATE vgnAsMoMetaData SET status= ?");
            sql.append(" WHERE contentMgmtId = ?");
            conn = ConfigUtil.getJDBCConnection(APPSVCS_DATASOURCE);
            stmt = conn.prepareStatement(sql.toString());
            stmt.setString(1, APPROVED);
            stmt.setString(2, event.getManagedObjectVCMRef().getId());
            stmt.executeUpdate();
            System.out.println(new java.util.Date() + "*******StaticFileApprover - File Approved. File Path = '" + event.getFilePath() + "'.");
        } catch (ConfigException configExc) {
            System.out.println(new java.util.Date() + " **********StaticFileApprover: ConfigException: " + configExc);
        } catch (SQLException sqlExc) {
            System.out.println("*******StaticFileApprover: SQLException: "+sqlExc.toString());
            System.out.println(new java.util.Date() + "******** StaticFileApprover: SQLException: " + sqlExc);
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (Throwable t) {
                    System.out.println("********StaticFileApprover: SQLException: "+t);
                    System.out.println(new java.util.Date() + " *******StaticFileApprover: Error closing PreparedStatement: " + t);
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (Throwable t) {
                    System.out.println(new java.util.Date() + " **********StaticFileApprover: Error closing Connection: " + t);
                }
            }
        }
    }
    
    /**
     * Returns the priority of the event handler.
     *
     * @return Integer number representing the event handler priority.
     * @see com.vignette.as.server.event.IAsEventListener
     */
    public int getPriority() {
        return IAsEventListener.HIGH_PRIORITY;
    }
    
}



Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger