*/
private void addStashDocumentToSOLRIndex(String solrLocation,
Pointer... pointers) throws SSAFSolrException
{
// Establish Connection
SolrServer server = new SolrConnection().getSolrServer(solrLocation);
// Create List of SolrInputDocuments Object
List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
// Iterate through pointers
for (Pointer pointer : pointers)
{
// Create SolrInputDocument Object
SolrInputDocument doc = new SolrInputDocument();
// Get values from Pointer Values into local Variables
String recordUri = pointer.getRecordUri();
String stashFilePath = pointer.getStashFilepath();
String stashType = pointer.getStashType();
XMLGregorianCalendar stashDate = pointer.getStashDatetime();
String pointerFilePath = pointer.getPointerFilepath();
PointerItems pointerItems = pointer.getPointerItems();
// Perform Mandatory Check
VarUtil.checkNonblankString("recordUri", recordUri);
VarUtil.checkNonblankString("stashFilePath", stashFilePath);
VarUtil.checkNonblankString("stashType", stashType);
VarUtil.checkNonNullObject("stashDate", stashDate);
VarUtil.checkNonblankString("pointerFilePath", pointerFilePath);
VarUtil.checkNonNullObject("ponterItems", pointerItems);
// Add local Variables values to SolrInputDocument
doc.addField("record_uri", recordUri);
doc.addField("stash_filepath", stashFilePath);
doc.addField("stash_type", stashType);
doc.addField("stash_date", stashDate);
doc.addField("pointer_filepath", pointerFilePath);
List<PointerItem> pointerItemList = pointerItems.getPointerItem();
// Get Pointer Items and add to SolrInputDocument
for (PointerItem pointerItem : pointerItemList)
{
SSAFSolrFieldTypeEnum fieldType =
fieldMapping.get(pointerItem.getItemName());
Boolean isIndexed = null;
if (fieldType != null)
{
isIndexed = fieldType.isIndexed();
}
if (isIndexed == null)
{
throw new SSAFSolrException("Pointer item, "
+ pointerItem.getItemName()
+ ", is not defined in semantics");
}
if (Boolean.valueOf(isIndexed))
{
DataType dataType =
DataType.fromValue(fieldType.getDataType());
String fieldName =
pointerItem.getItemName() + "_" + dataType.value();
String pointerValue = "";
switch (dataType)
{
case STRING:
pointerValue =
pointerItem.getItemValue().toLowerCase();
break;
case DATE:
// Assuming the coming in date is of format YYYY-MM-DD,
// we concatenate the string
// with T00:00:00Z.
pointerValue =
pointerItem.getItemValue().concat(DATE_SUFFIX);
break;
default:
pointerValue = pointerItem.getItemValue();
break;
}
doc.addField(fieldName, pointerValue);
}
}
docs.add(doc);
}
// Add Docs to Server & Commit
// Records will not be stored into Index until commit is performed.
try
{
for (Pointer pointer : pointers)
{
SolrDocument solrDocument = ssafSearchImpl.searchWithRecordUri(
solrLocation, pointer.getRecordUri() );
if (solrDocument != null)
{
String pointerFilePath = (String) solrDocument
.get( "pointer_filepath" );
deleteFile( pointerFilePath );
String stashFilePath = (String) solrDocument
.get( "stash_filepath" );
deleteFile( stashFilePath );
}
}
server.add(docs);
server.commit();
}
catch (SolrServerException e)
{
log.error("Unable to Stash pointers", e);
e.printStackTrace();