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, 2005.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: *
019: * Created: 14-Jan-2005 by jejking
020: * Version: $Revision: 1.2 $
021: * Last Updated: $Date: 2005/01/17 16:40:32 $
022: */
023: package org.openharmonise.rm.search;
024:
025: import java.io.*;
026: import java.util.*;
027: import java.util.logging.*;
028:
029: import org.openharmonise.commons.dsi.*;
030: import org.openharmonise.rm.*;
031: import org.openharmonise.rm.config.*;
032: import org.openharmonise.rm.dsi.*;
033: import org.openharmonise.rm.resources.*;
034: import org.openharmonise.rm.resources.content.*;
035: import org.openharmonise.rm.resources.metadata.properties.*;
036: import org.openharmonise.rm.resources.metadata.values.*;
037: import org.openharmonise.rm.resources.users.*;
038:
039: /**
040: * Simple class to remake an index for Harmonise Server.
041: *
042: * @author John King
043: */
044: public class HarmoniseReIndexer {
045:
046: private static Logger logger = Logger
047: .getLogger(HarmoniseReIndexer.class.getName());
048: private AbstractDataStoreInterface m_dbintrf;
049:
050: public HarmoniseReIndexer() {
051: try {
052: this .m_dbintrf = DataStoreInterfaceFactory
053: .getDataStoreInterface();
054: } catch (DataStoreException e) {
055: // TODO Auto-generated catch block
056: e.printStackTrace();
057: }
058: }
059:
060: public HarmoniseReIndexer(String sDSIclass, String sDriver,
061: String sURL, String sUsr, String sPwd) {
062:
063: try {
064: DatabaseSettings.createDatabaseSettings(sUsr, sPwd, sURL,
065: sDriver, sDSIclass);
066: this .m_dbintrf = DataStoreInterfaceFactory
067: .getDataStoreInterface();
068: } catch (ConfigException e) {
069: // TODO Auto-generated catch block
070: e.printStackTrace();
071: } catch (DataStoreException e) {
072: // TODO Auto-generated catch block
073: e.printStackTrace();
074: }
075: }
076:
077: public static void main(String[] args) throws Exception {
078: HarmoniseReIndexer app = new HarmoniseReIndexer(args[0],
079: args[1], args[2], args[3], args[4]);
080: app.execute(args);
081: }
082:
083: public String execute(String[] sArgs) throws Exception {
084:
085: String index_loc = ConfigSettings.getProperty("INDEX_LOCATION");
086:
087: File index_dir = new File(index_loc);
088: if (index_dir.exists() && index_dir.isDirectory()) {
089: File[] children = index_dir.listFiles();
090:
091: for (int i = 0; i < children.length; i++) {
092: File tmpFile = children[i];
093: System.err.println("Deleting file: "
094: + tmpFile.getAbsolutePath() + "\n");
095: tmpFile.delete();
096: }
097: }
098:
099: Section section = new Section(m_dbintrf);
100: System.err.println("Processing Sections\n");
101: processType(section);
102: Value value = new Value(m_dbintrf);
103: System.err.println("Processing Values\n");
104: processType(value);
105: ValueGroup valueGroup = new ValueGroup(m_dbintrf);
106: System.err.println("Processing ValueGroups\n");
107: processType(valueGroup);
108: Property property = new Property(m_dbintrf);
109: System.err.println("Processing Properties\n");
110: processType(property);
111: PropertyGroup propertyGroup = new PropertyGroup(m_dbintrf);
112: System.err.println("Processing PropertyGroups\n");
113: processType(propertyGroup);
114: User user = new User(m_dbintrf);
115: System.err.println("Processing Users\n");
116: processType(user);
117: UserGroup userGroup = new UserGroup(m_dbintrf);
118: System.err.println("Processing UserGroups\n");
119: processType(userGroup);
120: Document doc = new Document(m_dbintrf);
121: System.err.println("processing Documents\n");
122: processType(doc);
123: Asset asset = new Asset(m_dbintrf);
124: System.err.println("processing Assets\n");
125: processType(asset);
126: return null;
127: }
128:
129: private void processType(DataStoreObject dso) {
130: try {
131: HarmoniseIndexer indexer = HarmoniseIndexer.getInstance();
132: Search search = new Search(m_dbintrf);
133: search.setSearchType(dso);
134: List l = search.executeSearch();
135: Iterator vectorIt = l.iterator();
136: while (vectorIt.hasNext()) {
137: indexer.indexObject((AbstractObject) vectorIt.next());
138: }
139: } catch (DataStoreException e) {
140: e.printStackTrace();
141: System.exit(2);
142: } catch (SearchException e) {
143: e.printStackTrace();
144: System.exit(3);
145: } catch (HarmoniseIndexerException e) {
146: e.printStackTrace();
147: System.exit(4);
148: } catch (DataAccessException e) {
149: e.printStackTrace();
150: System.exit(5);
151: }
152:
153: }
154: }
|