1 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 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 e.printStackTrace(); 57 } 58 } 59 60 public HarmoniseReIndexer(String sDSIclass, 61 String sDriver, 62 String sURL, 63 String sUsr, 64 String sPwd) { 65 66 try { 67 DatabaseSettings.createDatabaseSettings(sUsr, sPwd, sURL, sDriver, sDSIclass); 68 this.m_dbintrf = DataStoreInterfaceFactory.getDataStoreInterface(); 69 } 70 catch (ConfigException e) { 71 e.printStackTrace(); 73 } 74 catch (DataStoreException e) { 75 e.printStackTrace(); 77 } 78 } 79 80 public static void main(String [] args) throws Exception { 81 HarmoniseReIndexer app = new HarmoniseReIndexer(args[0], args[1], args[2], args[3], args[4]); 82 app.execute(args); 83 } 84 85 public String execute(String [] sArgs) throws Exception { 86 87 String 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 |