long fullStartTime = System.currentTimeMillis();
// Open a socket to ingest, and to the response stream to get the post result
try
{
ContentStreamUpdateRequest contentStreamUpdateRequest = new ContentStreamUpdateRequest(postUpdateAction);
ModifiableSolrParams out = new ModifiableSolrParams();
// Write the id field
writeField(out,LITERAL+idAttributeName,documentURI);
// Write the rest of the attributes
if (modifiedDateAttributeName != null)
{
Date date = document.getModifiedDate();
if (date != null)
// Write value
writeField(out,LITERAL+modifiedDateAttributeName,DateParser.formatISO8601Date(date));
}
if (createdDateAttributeName != null)
{
Date date = document.getCreatedDate();
if (date != null)
// Write value
writeField(out,LITERAL+createdDateAttributeName,DateParser.formatISO8601Date(date));
}
if (indexedDateAttributeName != null)
{
Date date = document.getIndexingDate();
if (date != null)
// Write value
writeField(out,LITERAL+indexedDateAttributeName,DateParser.formatISO8601Date(date));
}
if (fileNameAttributeName != null)
{
String fileName = document.getFileName();
if (fileName != null)
writeField(out,LITERAL+fileNameAttributeName,fileName);
}
if (mimeTypeAttributeName != null)
{
String mimeType = document.getMimeType();
if (mimeType != null)
writeField(out,LITERAL+mimeTypeAttributeName,mimeType);
}
// Write the access token information
writeACLs(out,"share",shareAcls,shareDenyAcls);
writeACLs(out,"document",acls,denyAcls);
// Write the arguments
for (String name : arguments.keySet())
{
List<String> values = arguments.get(name);
writeField(out,name,values);
}
// Write the metadata, each in a field by itself
Iterator<String> iter = document.getFields();
while (iter.hasNext())
{
String fieldName = iter.next();
List<String> mapping = sourceTargets.get(fieldName);
if(mapping != null) {
for(String newFieldName : mapping) {
if(newFieldName != null && !newFieldName.isEmpty()) {
if (newFieldName.toLowerCase(Locale.ROOT).equals(idAttributeName.toLowerCase(Locale.ROOT))) {
newFieldName = ID_METADATA;
}
String[] values = document.getFieldAsStrings(fieldName);
writeField(out,LITERAL+newFieldName,values);
}
}
} else {
String newFieldName = fieldName;
if (!newFieldName.isEmpty()) {
if (newFieldName.toLowerCase(Locale.ROOT).equals(idAttributeName.toLowerCase(Locale.ROOT))) {
newFieldName = ID_METADATA;
}
String[] values = document.getFieldAsStrings(fieldName);
writeField(out,LITERAL+newFieldName,values);
}
}
}
// These are unnecessary now in the case of non-solrcloud setups, because we overrode the SolrJ posting method to use multipart.
//writeField(out,LITERAL+"stream_size",String.valueOf(length));
//writeField(out,LITERAL+"stream_name",document.getFileName());
// General hint for Tika
if (document.getFileName() != null)
writeField(out,"resource.name",document.getFileName());
// Write the commitWithin parameter
if (commitWithin != null)
writeField(out,COMMITWITHIN_METADATA,commitWithin);
contentStreamUpdateRequest.setParams(out);
contentStreamUpdateRequest.addContentStream(new RepositoryDocumentStream(is,length,contentType,contentName));
// Fire off the request.
// Note: I need to know whether the document has been permanently rejected or not, but we currently have
// no means to determine that. Analysis of SolrServerExceptions that have been thrown is likely needed.
try
{
readFromDocumentStreamYet = true;
UpdateResponse response = contentStreamUpdateRequest.process(solrServer);
// Successful completion
activityStart = new Long(fullStartTime);
activityBytes = new Long(length);
activityCode = "OK";