Skip to content

Commit

Permalink
Merge pull request #5 from NASA-PDS/i2
Browse files Browse the repository at this point in the history
Adds `package_id` to created Solr documents
  • Loading branch information
jordanpadams authored Sep 26, 2023
2 parents 9e18bc5 + 5392d31 commit 6af505c
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,32 @@ public boolean publishFile(FileInfo fi) throws Exception
ContentStreamUpdateRequest req = new ContentStreamUpdateRequest(endPoint);
req.addFile(file, "application/octet-stream");
req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
NamedList<Object> resp = solrClient.request(req);

Object error = resp.get("error");
if(error != null)

try
{
log.warning("Blob: " + blobName + ": " + error.toString());
}

NamedList<Object> resp = solrClient.request(req);
Object error = resp.get("error");
if(error != null)
{
log.warning("Blob: " + blobName + ": " + error.toString());
}
}
catch (HttpSolrClient.RemoteSolrException ex)
{
// For some reason, RemoteSolrException is a sublcass of RuntimeException, even though
// that's typically for unchecked exceptions of failures in the JVM itself, hence a
// separate `catch` here.
return false;
}
catch (RuntimeException ex)
{
throw ex;
}
catch (Exception ex)
{
return false;
}

return true;
}

Expand All @@ -94,18 +112,37 @@ public List<String> getResourceIds(String dataSetId) throws Exception
query.add("fl", "identifier");
query.add("rows", "100");

QueryResponse resp = solrClient.query(PDS_COLLECTION, query);
SolrDocumentList res = resp.getResults();

for(SolrDocument doc: res)
try
{
Object obj = doc.getFirstValue("identifier");
if(obj != null)
QueryResponse resp = solrClient.query(PDS_COLLECTION, query);
SolrDocumentList res = resp.getResults();

for(SolrDocument doc: res)
{
ids.add(obj.toString());
Object obj = doc.getFirstValue("identifier");
if(obj != null)
{
ids.add(obj.toString());
}
}

}

catch (HttpSolrClient.RemoteSolrException ex)
{
// For some reason, RemoteSolrException is a sublcass of RuntimeException, even though
// that's typically for unchecked exceptions of failures in the JVM itself, hence a
// separate `catch` here.
return ids;
}
catch (RuntimeException ex)
{
throw ex;
}
catch (Exception ex)
{
// Ignore
}

return ids;
}

Expand All @@ -117,9 +154,28 @@ private boolean md5Exists(FileInfo fi) throws Exception
String md5 = fi.md5.startsWith("0") ? fi.md5.substring(1) : fi.md5;

SolrQuery query = new SolrQuery("md5:\"" + md5 + "\"");
QueryResponse resp = solrClient.query(FILE_COLLECTION, query);
SolrDocumentList res = resp.getResults();
return res.getNumFound() > 0;
try
{
QueryResponse resp = solrClient.query(FILE_COLLECTION, query);
SolrDocumentList res = resp.getResults();
return res.getNumFound() > 0;
}
catch (HttpSolrClient.RemoteSolrException ex)
{
// For some reason, RemoteSolrException is a sublcass of RuntimeException, even though
// that's typically for unchecked exceptions of failures in the JVM itself, hence a
// separate `catch` here.
return false;
}
catch (RuntimeException ex)
{
throw ex;
}
catch (Exception ex)
{
// Ignore
}
return false;
}


Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gov/nasa/pds/citool/search/DocWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.FileWriter;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang.StringEscapeUtils;

Expand Down Expand Up @@ -44,6 +45,7 @@ public void close() throws Exception
public void write(Map<String, List<String>> fields) throws Exception
{
writer.write("<doc>\n");
writer.write("<field name=\"package_id\">" + UUID.randomUUID().toString() + "</field>\n");

for(Map.Entry<String, List<String>> field: fields.entrySet())
{
Expand Down

0 comments on commit 6af505c

Please sign in to comment.