/// <summary> /// Persists changes to LuceneController without running validation checks. /// </summary> /// <param name="DocData"></param> /// <param name="DocSubmittedByEmail"></param> /// <param name="RelayUrl"></param> /// <param name="SubmittedDate"></param> /// <param name="DocKeys"></param> /// <param name="DocTitle"></param> /// <returns></returns> public LightDoc Import(Stream DocData) { LightDoc _LightDoc = SubmitStream(DocData, WindowsIdentity.GetCurrent() .Name); string TargetDocName = _LightDoc.GetTargetDocName(), TargetDocVer = _LightDoc.GetTargetDocVer(); //#if !FAST Version existingVersion; // DOCREVs are only submitted via Text, there is no need to worry about them enter the system in another fusion. if (_LightDoc.DocTypeName == EmbededInterpreter.MY_ONLY_DOC_NAME) { // if the DocRev submitted supersedes the current or this is no current.. if (!Version.TryParse(TemplateController.Instance.TopDocRev(TargetDocName), out existingVersion) || Version.Parse(TargetDocVer) >= existingVersion) { // if there is no representation of this DocRev as a directory in the file system (as this trumps the submitted one no matter what if (Directory.Exists(FilesystemTemplateController.GetDocDirectoryPath(TargetDocName))) { // notice the true parameter value to clear the cache as well as assert we have the correct DocRev in the system now if (TemplateController.Instance.TopDocRev(TargetDocName, true) != TargetDocVer) { throw new PocosImportException(); } } } } return(_LightDoc); }
public LightDoc SubmitText(string DocData, string DocSubmittedByEmail, string RelayUrl = null, bool?DocStatus = null, DateTime?SubmittedDate = null, Dictionary <string, string> DocKeys = null, string DocTitle = null) { BaseDoc _BaseDoc = DocInterpreter.Instance.Read(DocData, true); DocProcessingInstructions _DocProcessingInstructions = DocInterpreter.Instance.ReadDocPI(DocData); string DocSrc; Dictionary <LightDoc, object> _DocSubmissions = new Dictionary <LightDoc, object>(); Document _Document = GetDoc(_BaseDoc.DocTypeName, _BaseDoc.GetDocId()); if (_Document != null) { if (_DocProcessingInstructions.DocChecksum == int.Parse(_Document.Get(Parm.DocChecksum))) { if (!_DocProcessingInstructions.IsDocRev()) { throw new NoChangesSinceLastSubmitException(); } else { return(_BaseDoc.ToLightDoc()); } } if (!_DocProcessingInstructions.IsDocRev()) { if ((_Document.Get(Parm.DocStatus) ?? bool.FalseString) == bool.TrueString) { throw new NoOverwriteOfPreviouslyApproveException(); } } _DocSubmissions = _Document.AsDocSubmissions(); } LightDoc _LightDoc = _BaseDoc.ToLightDoc(); _LightDoc.DocSubmitDate = DateTime.Now; _LightDoc.DocIsBinary = false; _DocSubmissions.Add(_LightDoc, DocData); using (StandardAnalyzer _StandardAnalyzer = new StandardAnalyzer(LUCENE_VERSION)) using (IndexWriter _CurrentIndexWriter = new IndexWriter(FSDirectory.Open(DirectoryPath), _StandardAnalyzer, CreateNeeded(), IndexWriter.MaxFieldLength.UNLIMITED)) { if (_DocSubmissions.Count > 1) { _CurrentIndexWriter.UpdateDocument(_BaseDoc.docTermFromBaseDoc(), _DocSubmissions.AsDocument()); } else { _CurrentIndexWriter.AddDocument(_DocSubmissions.AsDocument()); } _CurrentIndexWriter.Commit(); } return(_LightDoc); }
public override LightDoc SubmitText(string DocData, string DocSubmittedByEmail, string RelayUrl = null, bool?DocStatus = null, DateTime?SubmittedDate = null, Dictionary <string, string> DocKeys = null, string DocTitle = null) { // validate the content against it's XSD if it's being "approved" as good captured information for the organization // now is a good time to do this as the exception we want the user to see first would have hacazd there chance DocInterpreter.Instance.Validate(DocData); DocData = ProcessPI(DocData, DocSubmittedByEmail, DocStatus, SubmittedDate, DocKeys, DocTitle); LightDoc _LightDoc = LuceneController.SubmitText(DocData, DocSubmittedByEmail, RelayUrl, DocStatus, SubmittedDate, DocKeys, DocTitle); return(_LightDoc); }
/// <summary> /// useful to understand what a LightDoc for a DocRev's principle "Target Doc Type Name" is actually represents. /// </summary> /// <param name="lightdoc">LightDoc for a DocRev document</param> /// <returns> /// for IDocRev_Gen2's: TargetDocTypeVer, IDocRev_Gen2's: DocTypeVer, null if we are not dealing with a DocRev /// LightDoc listing item /// </returns> public static string GetTargetDocVer(this LightDoc lightdoc) { Dictionary <string, string> _DocKeys = lightdoc.GetDocKeys(); return(_DocKeys.ContainsKey(Properties.Resources.TargetDocTypeVerKey) ? _DocKeys[Properties.Resources.TargetDocTypeVerKey] : _DocKeys.ContainsKey("DocTypeVer") ? _DocKeys["DocTypeVer"] : null); }
/// <summary> /// useful to understand what a LightDoc for a DocRev's principle "Target Doc Type Name" is actually represents. /// </summary> /// <param name="lightdoc">LightDoc for a DocRev document</param> /// <returns> /// for IDocRev_Gen2's: TargetDocTypeVer, IDocRev_Gen2's: DocTypeVer, anything not actually a DocRev /// representative will simple be the DocTypeName /// </returns> public static string GetTargetDocName(this LightDoc lightdoc) { Dictionary <string, string> _DocKeys = lightdoc.GetDocKeys(); return(_DocKeys.ContainsKey(Properties.Resources.TargetDocTypeNameKey) ? _DocKeys[Properties.Resources.TargetDocTypeNameKey] : _DocKeys.ContainsKey("DocTypeName") ? _DocKeys["DocTypeName"] : lightdoc.DocTypeName); }
public static Document AsDocument(this Dictionary <LightDoc, object> _DocSubmissions) { LightDoc _LightDoc = _DocSubmissions.Keys.Last(); BaseDoc _BaseDoc = _LightDoc.DocIsBinary ? DocInterpreter.Instance.Read(_DocSubmissions.Values.OfType <byte[]>().Last(), true) : DocInterpreter.Instance.Read(_DocSubmissions.Values.OfType <string>().Last(), true); Term _Term = _BaseDoc.docTermFromBaseDoc(); Document _Document = new Document(); // TODO:convert the Submissions to a real non-datacontracted property _Document.Add(new Field(Parm.Submissions, Compressor.Compress(_DocSubmissions), Field.Store.YES)); // BUG:For what ever reason, NOT_ANALYZED_NO_NORMS does not allow UpdateDocument to work properly; never executing DeleteDocument spawning duplicates _Document.Add(new Field(_Term.Field, _Term.Text, Field.Store.NO, Field.Index.NOT_ANALYZED)); // DocTypeName will always be skipped over by GetFormObjectMappedProperties when it's dropping default valued fields _Document.Add(new Field(Parm.DocTypeName, _LightDoc.DocTypeName, Field.Store.YES, Field.Index.NOT_ANALYZED)); // searches items returned will in reverse chronological order _Document.Add(new Field(Parm.LogSequenceNumber, string.Format("{0}", _LightDoc.LogSequenceNumber), Field.Store.YES, Field.Index.NOT_ANALYZED)); // Don't compress this field as it will slow down query results returned _Document.Add( new Field( Parm.LightDoc, _LightDoc.ToBytes(), Field.Store.YES)); //TODO:Find a more elegant way of making the documents DocKeys searchable. Currently they are simply concatenated to the DocData _Document.Add( new Field(Parm.DocData, string.Format(@"{0}\n\r{1}", _Term.Text, JsonConvert.SerializeObject( _BaseDoc, Formatting.Indented, new JsonSerializerSettings { ContractResolver = ShouldSerializeContractResolver.Instance, DefaultValueHandling = DefaultValueHandling.Ignore })), Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS)); // Add individual doc keys foreach (KeyValuePair <string, string> _DocKey in _BaseDoc.DocKeys) { _Document.Add(new Field(_DocKey.Key, _DocKey.Value, Field.Store.NO, Field.Index.NOT_ANALYZED)); } //TODO:Be selective about the column store like Raven does. Record if there is a query filter against it, only then should it be broken out as a field foreach (PropertyInfo p in _BaseDoc .GetFormObjectMappedProperties(true) .Where(m => _Document.GetFieldable(m.Name) == null && m.DeclaringType != typeof(DocProcessingInstructions) && m.DeclaringType != typeof(DocTerm) && m.PropertyType != typeof(Byte[]))) { _Document.Add( new Field( p.Name, string.Format("{0}", p.GetValue(_BaseDoc, null)), (p.Name == Parm.DocChecksum || p.Name == Parm.DocStatus) ? Field.Store.YES : Field.Store.NO, Field.Index.NOT_ANALYZED)); } return(_Document); }
public LightDoc Submit(string DocData, string DocSubmittedBy, string RelayUrl = null, bool?DocStatus = null, DateTime?SubmittedDate = null, Dictionary <string, string> DocKeys = null, string DocTitle = null) { if (SubmittedDate != null) { throw new NotImplementedException("SubmittedDate can't be specified explicitly in submit method as it's not implemented yet"); } BaseDoc _BaseDoc = DocInterpreter.Instance.Read(DocData, true); DocProcessingInstructions _DocProcessingInstructions = DocInterpreter.Instance.ReadDocPI(DocData); _DocProcessingInstructions.DocStatus = DocStatus ?? _BaseDoc.DocStatus ?? false; _DocProcessingInstructions.DocTitle = DocTitle ?? _BaseDoc.DocTitle; _DocProcessingInstructions.DocIdKeys = DocKeys ?? _BaseDoc.DocIdKeys; string DocSrc; Document _Document = GetDoc(out DocSrc, _BaseDoc.DocTypeName, _BaseDoc.DocId, RelayUrl); Dictionary <LightDoc, string> _DocSubmissions = new Dictionary <LightDoc, string>(); if (_Document != null) { if (_DocProcessingInstructions.DocChecksum == int.Parse(_Document.Get(Parm.DocChecksum))) { throw new NoChangesSinceLastSubmitException(); } if ((_Document.Get(Parm.DocStatus) ?? bool.FalseString) == bool.TrueString) { throw new NoOverwriteOfPreviouslyApproveException(); } _DocSubmissions = _Document.AsDocSubmissions(); _DocProcessingInstructions.DocTitle = _DocSubmissions.Keys.First().DocTitle; } LightDoc _LightDoc = _BaseDoc.ToLightDoc(); _LightDoc.DocSubmitDate = DateTime.Now; // adjust PI before adding this submission; in particular, the DocChecksum was recalculated within the scope of this method // to reflect what is really being submitted. when additional submissions occur there after they will be compared to this // current submission checksum to see if there are any changes to persist _DocSubmissions.Add( _LightDoc, DocInterpreter.Instance.WritePI(DocData, _DocProcessingInstructions)); using (StandardAnalyzer _StandardAnalyzer = new StandardAnalyzer(LUCENE_VERSION)) using (IndexWriter _CurrentIndexWriter = new IndexWriter(FSDirectory.Open(DirectoryPath), _StandardAnalyzer, CreateNeeded(), IndexWriter.MaxFieldLength.UNLIMITED)) { if (_DocSubmissions.Count > 1) { _CurrentIndexWriter.UpdateDocument( _BaseDoc.docTermFromBaseDoc(), _DocSubmissions.AsDocument()); } else { _CurrentIndexWriter.AddDocument( _DocSubmissions.AsDocument()); } _CurrentIndexWriter.Commit(); } return(_LightDoc); }
public static Dictionary <string, string> GetDocKeys(this LightDoc lightdoc) { return(DocKeyEncrypter.DocIdToKeys(lightdoc.DocId)); }