KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > search > HarmoniseReIndexer


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, 2005.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  *
19  * Created: 14-Jan-2005 by jejking
20  * Version: $Revision: 1.2 $
21  * Last Updated: $Date: 2005/01/17 16:40:32 $
22  */

23 package org.openharmonise.rm.search;
24
25 import java.io.*;
26 import java.util.*;
27 import java.util.logging.*;
28
29 import org.openharmonise.commons.dsi.*;
30 import org.openharmonise.rm.*;
31 import org.openharmonise.rm.config.*;
32 import org.openharmonise.rm.dsi.*;
33 import org.openharmonise.rm.resources.*;
34 import org.openharmonise.rm.resources.content.*;
35 import org.openharmonise.rm.resources.metadata.properties.*;
36 import org.openharmonise.rm.resources.metadata.values.*;
37 import org.openharmonise.rm.resources.users.*;
38
39
40 /**
41  * Simple class to remake an index for Harmonise Server.
42  *
43  * @author John King
44  */

45 public class HarmoniseReIndexer {
46
47     private static Logger logger = Logger.getLogger(HarmoniseReIndexer.class.getName());
48     private AbstractDataStoreInterface m_dbintrf;
49     
50     public HarmoniseReIndexer() {
51         try {
52             this.m_dbintrf = DataStoreInterfaceFactory.getDataStoreInterface();
53         }
54         catch (DataStoreException e) {
55             // TODO Auto-generated catch block
56
e.printStackTrace();
57         }
58     }
59     
60     public HarmoniseReIndexer(String JavaDoc sDSIclass,
61         String JavaDoc sDriver,
62         String JavaDoc sURL,
63         String JavaDoc sUsr,
64         String JavaDoc sPwd) {
65         
66         try {
67             DatabaseSettings.createDatabaseSettings(sUsr, sPwd, sURL, sDriver, sDSIclass);
68             this.m_dbintrf = DataStoreInterfaceFactory.getDataStoreInterface();
69         }
70         catch (ConfigException e) {
71             // TODO Auto-generated catch block
72
e.printStackTrace();
73         }
74         catch (DataStoreException e) {
75             // TODO Auto-generated catch block
76
e.printStackTrace();
77         }
78     }
79     
80     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
81        HarmoniseReIndexer app = new HarmoniseReIndexer(args[0], args[1], args[2], args[3], args[4]);
82        app.execute(args);
83     }
84
85     public String JavaDoc execute(String JavaDoc[] sArgs) throws Exception JavaDoc {
86         
87         String JavaDoc index_loc = ConfigSettings.getProperty("INDEX_LOCATION");
88         
89         File index_dir = new File(index_loc);
90         if(index_dir.exists() && index_dir.isDirectory()) {
91             File[] children = index_dir.listFiles();
92             
93             for (int i = 0; i < children.length; i++) {
94                 File tmpFile = children[i];
95                 System.err.println("Deleting file: " + tmpFile.getAbsolutePath() + "\n");
96                 tmpFile.delete();
97             }
98         }
99         
100         Section section = new Section(m_dbintrf);
101         System.err.println("Processing Sections\n");
102         processType(section);
103         Value value = new Value(m_dbintrf);
104         System.err.println("Processing Values\n");
105         processType(value);
106         ValueGroup valueGroup = new ValueGroup(m_dbintrf);
107         System.err.println("Processing ValueGroups\n");
108         processType(valueGroup);
109         Property property = new Property(m_dbintrf);
110         System.err.println("Processing Properties\n");
111         processType(property);
112         PropertyGroup propertyGroup = new PropertyGroup(m_dbintrf);
113         System.err.println("Processing PropertyGroups\n");
114         processType(propertyGroup);
115         User user = new User(m_dbintrf);
116         System.err.println("Processing Users\n");
117         processType(user);
118         UserGroup userGroup = new UserGroup(m_dbintrf);
119         System.err.println("Processing UserGroups\n");
120         processType(userGroup);
121         Document doc = new Document(m_dbintrf);
122         System.err.println("processing Documents\n");
123         processType(doc);
124         Asset asset = new Asset(m_dbintrf);
125         System.err.println("processing Assets\n");
126         processType(asset);
127         return null;
128     }
129
130     private void processType(DataStoreObject dso) {
131         try {
132             HarmoniseIndexer indexer = HarmoniseIndexer.getInstance();
133             Search search = new Search(m_dbintrf);
134             search.setSearchType(dso);
135             List l = search.executeSearch();
136             Iterator vectorIt = l.iterator();
137             while (vectorIt.hasNext()) {
138                 indexer.indexObject((AbstractObject) vectorIt.next());
139             }
140         }
141         catch (DataStoreException e) {
142             e.printStackTrace();
143             System.exit(2);
144         } catch (SearchException e) {
145             e.printStackTrace();
146             System.exit(3);
147         } catch (HarmoniseIndexerException e) {
148             e.printStackTrace();
149             System.exit(4);
150         } catch (DataAccessException e) {
151             e.printStackTrace();
152             System.exit(5);
153         }
154             
155     }
156 }
157
Popular Tags