KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > dav > server > webservice > ReportService


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  *
19  * Created: 29-Nov-2004 by jejking
20  * Version: $Revision: 1.5 $
21  * Last Updated: $Date: 2005/01/13 15:20:20 $
22  */

23 package org.openharmonise.dav.server.webservice;
24
25 import java.util.logging.*;
26
27 import org.openharmonise.commons.dsi.*;
28 import org.openharmonise.dav.server.utils.*;
29 import org.openharmonise.rm.commands.*;
30 import org.openharmonise.rm.commands.CommandException;
31 import org.openharmonise.rm.dsi.DataStoreInterfaceFactory;
32 import org.openharmonise.rm.factory.*;
33 import org.openharmonise.rm.publishing.*;
34 import org.openharmonise.rm.resources.audit.XMLAuditResource;
35 import org.openharmonise.rm.resources.users.User;
36 import org.openharmonise.rm.security.authentication.*;
37
38
39 /**
40  * Web service for the reports stuff.
41  *
42  * @author Fidel Viegas
43  * @version $Revision: 1.5 $
44  *
45  */

46 public class ReportService {
47     
48     static AbstractDataStoreInterface dbinterf = null;
49
50     /**
51      * Logger for this class
52      */

53     private static final Logger m_logger = Logger.getLogger(ReportService.class
54             .getName());
55
56     static {
57         try {
58             // get the data store interface
59
dbinterf = DataStoreInterfaceFactory.getDataStoreInterface();
60         } catch (DataStoreException e) {
61             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
62         }
63     }
64
65     /**
66      *
67      */

68     public ReportService() {
69         super();
70     }
71
72     /**
73      * This method executes a query, generates a report and retuns the path to
74      * that report.
75      *
76      * @param sPath
77      * @param sUserName
78      * @param sPassword
79      * @return
80      */

81     public static String JavaDoc executeQuery(String JavaDoc sPath, String JavaDoc sUserName,
82             String JavaDoc sPassword) {
83         String JavaDoc sResult = ""; // if there was an error this will be the return
84
// value
85

86         try {
87             //User user = new User(dbinterf, sUserName, sPassword);
88
UserAuthenticator authenticator = UserAuthenticatorFactory.getAuthenticator();
89             User user = authenticator.getUser(sUserName, sPassword);
90             State state = new State(dbinterf, user);
91
92             XMLAuditResource queryResource = (XMLAuditResource) HarmoniseObjectFactory
93                     .instantiatePublishableObject(dbinterf,
94                             XMLAuditResource.class.getName(), HarmoniseNameResolver
95                                     .getRealPath(sPath));
96
97             CmdGenerateReport cmd = new CmdGenerateReport();
98             cmd.setCommandObject(queryResource);
99             cmd.setDataStoreInteface(dbinterf);
100             cmd.setState(state);
101
102             sResult = (String JavaDoc) HarmoniseNameResolver.getDAVPath(
103                     XMLAuditResource.class, (String JavaDoc) cmd.execute(null)); // execute
104
// the
105
// command
106
} catch (HarmoniseFactoryException e) {
107             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
108         } catch (StateException e) {
109             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
110         } catch(InvalidCommandException e) {
111             m_logger.log(Level.INFO, "Invalid command called: "
112                     + sUserName
113                     + " can not execute report generation commmand");
114         } catch (CommandException e) {
115             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
116         } catch (NameResolverException e) {
117             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
118         } catch (NullPointerException JavaDoc e) {
119             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
120         }
121         catch (UserAuthenticationException e) {
122             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
123         }
124
125         return sResult;
126     }
127 }
128
Popular Tags