LongTextIproFullTextBuilder
using kCura.WinEDDS.Exporters;
using Relativity.DataExchange.Export.VolumeManagerV2.Download;
using Relativity.DataExchange.Export.VolumeManagerV2.Metadata.Text;
using Relativity.DataExchange.Io;
using Relativity.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Relativity.DataExchange.Export.VolumeManagerV2.Repository
{
public class LongTextIproFullTextBuilder : ILongTextBuilder
{
private readonly LongTextHelper _longTextHelper;
private readonly ILog _logger;
public LongTextIproFullTextBuilder(LongTextHelper longTextHelper, ILog logger)
{
_longTextHelper = longTextHelper;
_logger = logger;
}
public IList<LongText> CreateLongText(ObjectExportInfo artifact, CancellationToken cancellationToken)
{
_logger.LogVerbose("Attempting to create LongText for IPRO Full text.", Array.Empty<object>());
if (cancellationToken.IsCancellationRequested)
return Enumerable.Empty<LongText>().ToList();
if (_longTextHelper.IsTextTooLong(artifact, "ExtractedText"))
return CreateTooLongTextForIpro(artifact).InList();
return CreateLongTextForIpro(artifact).InList();
}
private LongText CreateTooLongTextForIpro(ObjectExportInfo artifact)
{
_logger.LogVerbose("Creating LongText for IPRO Full text with missing value.", Array.Empty<object>());
string tempFileName = TempFileBuilder.GetTempFileName("rel-long-text");
int fieldArtifactId = _longTextHelper.GetFieldArtifactId("ExtractedText");
LongTextExportRequest exportRequest = LongTextExportRequest.CreateRequestForFullText(artifact, fieldArtifactId, tempFileName);
return LongText.CreateFromMissingValue(artifact.ArtifactID, fieldArtifactId, exportRequest, Encoding.Unicode, artifact.LongTextLength);
}
private LongText CreateLongTextForIpro(ObjectExportInfo artifact)
{
_logger.LogVerbose("Creating LongText for IPRO Full text with existing value.", Array.Empty<object>());
string textFromField = _longTextHelper.GetTextFromField(artifact, "ExtractedText");
int fieldArtifactId = _longTextHelper.GetFieldArtifactId("ExtractedText");
return LongText.CreateFromExistingValue(artifact.ArtifactID, fieldArtifactId, textFromField);
}
}
}