Review Board 1.7.22


String search and replace getMetadata("UUID with getMetadata("CAS.ProductId

Review Request #4709 - Created April 12, 2012 and submitted

Thomas Bennett
OODT-440
Reviewers
oodt
bfoster, mattmann, pramirez, sherylj
oodt
String search and replace getMetadata("UUID with getMetadata("CAS.ProductId
Unit test pass
Works on my installed OODT ditribution

Diff revision 2 (Latest)

1 2
1 2

  1. trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java: Loading...
trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java
Revision 1306745 New Change
[20] 47 lines
[+20]
48
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
48
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
49
import org.apache.solr.common.SolrInputDocument;
49
import org.apache.solr.common.SolrInputDocument;
50
import org.apache.solr.core.CoreContainer;
50
import org.apache.solr.core.CoreContainer;
51

    
   
51

   
52
//OODT imports
52
//OODT imports

    
   
53
import org.apache.oodt.cas.filemgr.metadata.CoreMetKeys;
53
import org.apache.oodt.cas.filemgr.structs.Product;
54
import org.apache.oodt.cas.filemgr.structs.Product;
54
import org.apache.oodt.cas.filemgr.structs.ProductType;
55
import org.apache.oodt.cas.filemgr.structs.ProductType;
55
import org.apache.oodt.cas.filemgr.structs.exceptions.CatalogException;
56
import org.apache.oodt.cas.filemgr.structs.exceptions.CatalogException;
56
import org.apache.oodt.cas.filemgr.structs.exceptions.ConnectionException;
57
import org.apache.oodt.cas.filemgr.structs.exceptions.ConnectionException;
57
import org.apache.oodt.cas.filemgr.structs.exceptions.RepositoryManagerException;
58
import org.apache.oodt.cas.filemgr.structs.exceptions.RepositoryManagerException;
[+20] [20] 116 lines
[+20] [+] private SolrInputDocument getSolrDocument(Metadata metadata) {
174
      throws InstantiationException, FileNotFoundException, IOException,
175
      throws InstantiationException, FileNotFoundException, IOException,
175
      SolrServerException {
176
      SolrServerException {
176
    SerializableMetadata metadata = new SerializableMetadata("UTF-8", false);
177
    SerializableMetadata metadata = new SerializableMetadata("UTF-8", false);
177
    metadata.loadMetadataFromXmlStream(new FileInputStream(file));
178
    metadata.loadMetadataFromXmlStream(new FileInputStream(file));
178
    if (delete) {
179
    if (delete) {
179
      server.deleteById(metadata.getMetadata("uuid"));
180
      server.deleteById(metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
180
    }
181
    }
181
    server.add(this.getSolrDocument(metadata));
182
    server.add(this.getSolrDocument(metadata));
182
  }
183
  }
183

    
   
184

   
184
  public void indexAll(boolean delete) throws SolrServerException {
185
  public void indexAll(boolean delete) throws SolrServerException {
[+20] [20] 14 lines
[+20] private SolrInputDocument getSolrDocument(Metadata metadata) {
199
            LOG.info("Looking up metadata for ProductId "
200
            LOG.info("Looking up metadata for ProductId "
200
                + product.getProductId());
201
                + product.getProductId());
201
            Metadata metadata = fmClient.getMetadata(product);
202
            Metadata metadata = fmClient.getMetadata(product);
202
            if (metadata != null) {
203
            if (metadata != null) {
203
              LOG.info("Found metadata for product ID "
204
              LOG.info("Found metadata for product ID "
204
                  + metadata.getMetadata("CAS.ProductId"));
205
                  + metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
205
            } else {
206
            } else {
206
              LOG.info("Could not find metadata for product "
207
              LOG.info("Could not find metadata for product "
207
                  + product.getProductId());
208
                  + product.getProductId());
208
            }
209
            }
209
            if (metadata.getMetadata("UUID") != null) {
210
            if (metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID) != null) {
210
              if (metadata.getMetadata("Deleted") == null
211
              if (metadata.getMetadata("Deleted") == null
211
                  || !"true".equals(metadata.getMetadata("Deleted"))) {
212
                  || !"true".equals(metadata.getMetadata("Deleted"))) {
212
                try {
213
                try {
213
                  server.add(this.getSolrDocument(metadata));
214
                  server.add(this.getSolrDocument(metadata));
214
                  server.commit();
215
                  server.commit();
215
                  LOG.info("Indexed " + metadata.getMetadata("UUID"));
216
                  LOG.info("Indexed " + metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
216
                } catch (Exception e) {
217
                } catch (Exception e) {
217
                  LOG.severe("Could not index " + metadata.getMetadata("UUID")
218
                  LOG.severe("Could not index " + metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID)
218
                      + " " + e.getMessage());
219
                      + " " + e.getMessage());
219
                }
220
                }
220
              } else {
221
              } else {
221
                LOG.info("Skipping Deleted: " + metadata.getMetadata("UUID"));
222
                LOG.info("Skipping Deleted: " + metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
222
              }
223
              }
223
            }
224
            }
224
          }
225
          }
225
        } else {
226
        } else {
226
          LOG.info("Ignoring product type " + type.getName());
227
          LOG.info("Ignoring product type " + type.getName());
[+20] [20] 193 lines
  1. trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java: Loading...