001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: *
019: * Created: 29-Nov-2004 by jejking
020: * Version: $Revision: 1.5 $
021: * Last Updated: $Date: 2005/01/13 15:20:20 $
022: */
023: package org.openharmonise.dav.server.webservice;
024:
025: import java.util.logging.*;
026:
027: import org.openharmonise.commons.dsi.*;
028: import org.openharmonise.dav.server.utils.*;
029: import org.openharmonise.rm.commands.*;
030: import org.openharmonise.rm.commands.CommandException;
031: import org.openharmonise.rm.dsi.DataStoreInterfaceFactory;
032: import org.openharmonise.rm.factory.*;
033: import org.openharmonise.rm.publishing.*;
034: import org.openharmonise.rm.resources.audit.XMLAuditResource;
035: import org.openharmonise.rm.resources.users.User;
036: import org.openharmonise.rm.security.authentication.*;
037:
038: /**
039: * Web service for the reports stuff.
040: *
041: * @author Fidel Viegas
042: * @version $Revision: 1.5 $
043: *
044: */
045: public class ReportService {
046:
047: static AbstractDataStoreInterface dbinterf = null;
048:
049: /**
050: * Logger for this class
051: */
052: private static final Logger m_logger = Logger
053: .getLogger(ReportService.class.getName());
054:
055: static {
056: try {
057: // get the data store interface
058: dbinterf = DataStoreInterfaceFactory
059: .getDataStoreInterface();
060: } catch (DataStoreException e) {
061: m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
062: }
063: }
064:
065: /**
066: *
067: */
068: public ReportService() {
069: super ();
070: }
071:
072: /**
073: * This method executes a query, generates a report and retuns the path to
074: * that report.
075: *
076: * @param sPath
077: * @param sUserName
078: * @param sPassword
079: * @return
080: */
081: public static String executeQuery(String sPath, String sUserName,
082: String sPassword) {
083: String sResult = ""; // if there was an error this will be the return
084: // value
085:
086: try {
087: //User user = new User(dbinterf, sUserName, sPassword);
088: UserAuthenticator authenticator = UserAuthenticatorFactory
089: .getAuthenticator();
090: User user = authenticator.getUser(sUserName, sPassword);
091: State state = new State(dbinterf, user);
092:
093: XMLAuditResource queryResource = (XMLAuditResource) HarmoniseObjectFactory
094: .instantiatePublishableObject(dbinterf,
095: XMLAuditResource.class.getName(),
096: HarmoniseNameResolver.getRealPath(sPath));
097:
098: CmdGenerateReport cmd = new CmdGenerateReport();
099: cmd.setCommandObject(queryResource);
100: cmd.setDataStoreInteface(dbinterf);
101: cmd.setState(state);
102:
103: sResult = (String) HarmoniseNameResolver.getDAVPath(
104: XMLAuditResource.class, (String) cmd.execute(null)); // execute
105: // the
106: // command
107: } catch (HarmoniseFactoryException e) {
108: m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
109: } catch (StateException e) {
110: m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
111: } catch (InvalidCommandException e) {
112: m_logger.log(Level.INFO, "Invalid command called: "
113: + sUserName
114: + " can not execute report generation commmand");
115: } catch (CommandException e) {
116: m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
117: } catch (NameResolverException e) {
118: m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
119: } catch (NullPointerException e) {
120: m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
121: } catch (UserAuthenticationException e) {
122: m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
123: }
124:
125: return sResult;
126: }
127: }
|