ReportService.java :  » Content-Management-System » harmonise » org » openharmonise » dav » server » webservice » Java Open Source

Java Open Source » Content Management System » harmonise 
harmonise » org » openharmonise » dav » server » webservice » ReportService.java
/*
 * The contents of this file are subject to the 
 * Mozilla Public License Version 1.1 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
 * See the License for the specific language governing rights and 
 * limitations under the License.
 *
 * The Initial Developer of the Original Code is Simulacra Media Ltd.
 * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
 *
 * All Rights Reserved.
 *
 * Contributor(s):
 * 
 * Created: 29-Nov-2004 by jejking
 * Version: $Revision: 1.5 $
 * Last Updated: $Date: 2005/01/13 15:20:20 $
 */
package org.openharmonise.dav.server.webservice;

import java.util.logging.*;

import org.openharmonise.commons.dsi.*;
import org.openharmonise.dav.server.utils.*;
import org.openharmonise.rm.commands.*;
import org.openharmonise.rm.commands.CommandException;
import org.openharmonise.rm.dsi.DataStoreInterfaceFactory;
import org.openharmonise.rm.factory.*;
import org.openharmonise.rm.publishing.*;
import org.openharmonise.rm.resources.audit.XMLAuditResource;
import org.openharmonise.rm.resources.users.User;
import org.openharmonise.rm.security.authentication.*;


/**
 * Web service for the reports stuff.
 * 
 * @author Fidel Viegas
 * @version $Revision: 1.5 $
 *  
 */
public class ReportService {
    
  static AbstractDataStoreInterface dbinterf = null;

  /**
   * Logger for this class
   */
  private static final Logger m_logger = Logger.getLogger(ReportService.class
      .getName());

  static {
    try {
      // get the data store interface
      dbinterf = DataStoreInterfaceFactory.getDataStoreInterface();
    } catch (DataStoreException e) {
      m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
    }
  }

  /**
   *  
   */
  public ReportService() {
    super();
  }

  /**
   * This method executes a query, generates a report and retuns the path to
   * that report.
   * 
   * @param sPath
   * @param sUserName
   * @param sPassword
   * @return
   */
  public static String executeQuery(String sPath, String sUserName,
      String sPassword) {
    String sResult = ""; // if there was an error this will be the return
               // value

    try {
      //User user = new User(dbinterf, sUserName, sPassword);
        UserAuthenticator authenticator = UserAuthenticatorFactory.getAuthenticator();
        User user = authenticator.getUser(sUserName, sPassword);
      State state = new State(dbinterf, user);

      XMLAuditResource queryResource = (XMLAuditResource) HarmoniseObjectFactory
          .instantiatePublishableObject(dbinterf,
              XMLAuditResource.class.getName(), HarmoniseNameResolver
                  .getRealPath(sPath));

      CmdGenerateReport cmd = new CmdGenerateReport();
      cmd.setCommandObject(queryResource);
      cmd.setDataStoreInteface(dbinterf);
      cmd.setState(state);

      sResult = (String) HarmoniseNameResolver.getDAVPath(
          XMLAuditResource.class, (String) cmd.execute(null)); // execute
                                   // the
                                   // command
    } catch (HarmoniseFactoryException e) {
      m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
    } catch (StateException e) {
      m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
    } catch(InvalidCommandException e) {
      m_logger.log(Level.INFO, "Invalid command called: " 
          + sUserName 
          + " can not execute report generation commmand");
    } catch (CommandException e) {
      m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
    } catch (NameResolverException e) {
      m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
    } catch (NullPointerException e) {
      m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
    }
        catch (UserAuthenticationException e) {
            m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
        }

    return sResult;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.