public void RunConversion(Dictionary <MongoDB.Bson.ObjectId, Guid> entryObjectIdToGuidMappings)
        {
            var commentsWithIds = new List <KeyValuePair <string, LfComment> >();

            foreach (LfComment comment in _conn.GetComments(_project))
            {
                Guid guid;
                // LfMergeBridge wants lex entry GUIDs (passed along in comment.Regarding.TargetGuid), not Mongo ObjectIds like comment.EntryRef contains.
                if (comment.EntryRef != null && entryObjectIdToGuidMappings.TryGetValue(comment.EntryRef, out guid))
                {
                    comment.Regarding.TargetGuid = guid.ToString();
                }
                commentsWithIds.Add(new KeyValuePair <string, LfComment>(comment.Id.ToString(), comment));
            }
            string allCommentsJson = JsonConvert.SerializeObject(commentsWithIds);
            string bridgeOutput;

            CallLfMergeBridge(allCommentsJson, out bridgeOutput);
            // LfMergeBridge returns two lists of IDs (comment IDs or reply IDs) that need to have their GUIDs updated in Mongo.
            string commentGuidMappingsStr = GetPrefixedStringFromLfMergeBridgeOutput(bridgeOutput, "New comment ID->Guid mappings: ");
            string replyGuidMappingsStr   = GetPrefixedStringFromLfMergeBridgeOutput(bridgeOutput, "New reply ID->Guid mappings: ");
            Dictionary <string, Guid> commentIdToGuidMappings = ParseGuidMappings(commentGuidMappingsStr);
            Dictionary <string, Guid> uniqIdToGuidMappings    = ParseGuidMappings(replyGuidMappingsStr);

            _conn.SetCommentGuids(_project, commentIdToGuidMappings);
            _conn.SetCommentReplyGuids(_project, uniqIdToGuidMappings);
        }
Exemplo n.º 2
0
        public void RunConversion()
        {
            LfProjectConfig config       = _factory.Create(_project).Config;
            FieldLists      fieldConfigs = FieldListsForEntryAndSensesAndExamples(config);

            var    fixedComments   = new List <LfComment>(_conn.GetComments(_project));
            string allCommentsJson = JsonConvert.SerializeObject(fixedComments);
            // _logger.Debug("Doing Lcm->Mongo direction. The json for ALL comments from Mongo would be: {0}", allCommentsJson);
            // _logger.Debug("Doing Lcm->Mongo direction. About to call LfMergeBridge with that JSON...");
            string bridgeOutput;

            if (CallLfMergeBridge(allCommentsJson, out bridgeOutput))
            {
                string           newCommentsStr      = ConvertMongoToLcmComments.GetPrefixedStringFromLfMergeBridgeOutput(bridgeOutput, "New comments not yet in LF: ");
                string           newRepliesStr       = ConvertMongoToLcmComments.GetPrefixedStringFromLfMergeBridgeOutput(bridgeOutput, "New replies on comments already in LF: ");
                string           newStatusChangesStr = ConvertMongoToLcmComments.GetPrefixedStringFromLfMergeBridgeOutput(bridgeOutput, "New status changes on comments already in LF: ");
                List <LfComment> comments            = JsonConvert.DeserializeObject <List <LfComment> >(newCommentsStr);
                List <Tuple <string, List <LfCommentReply> > >         replies       = JsonConvert.DeserializeObject <List <Tuple <string, List <LfCommentReply> > > >(newRepliesStr);
                List <KeyValuePair <string, Tuple <string, string> > > statusChanges = JsonConvert.DeserializeObject <List <KeyValuePair <string, Tuple <string, string> > > >(newStatusChangesStr);

                foreach (LfComment comment in comments)
                {
                    // LfMergeBridge only sets the Guid in comment.Regarding, and leaves it to the LfMerge side to set the rest of the fields meaningfully
                    if (comment.Regarding != null)
                    {
                        Guid guid;
                        if (Guid.TryParse(comment.Regarding.TargetGuid ?? "", out guid))
                        {
                            // The GUID in Chorus notes MIGHT be an entry, or it might be a sense or an example sentence.
                            // We want to handle these three cases differently -- see FromTargetGuid below.
                            comment.Regarding = FromTargetGuid(guid, fieldConfigs);
                        }
                    }
                    // _logger.Debug("Comment by {6} regarding field {0} (containing {1}) of word {2} (GUID {7}, meaning {3}) has content {4}{5} and status {8} (GUID {9})",
                    //  comment.Regarding.FieldNameForDisplay,
                    //  comment.Regarding.FieldValue,
                    //  comment.Regarding.Word,
                    //  comment.Regarding.Meaning,
                    //  comment.Content,
                    //  comment.Replies.Count <= 0 ? "" : " and replies [" + String.Join(", ", comment.Replies.Select(reply => "\"" + reply.Content + "\"")) + "]",
                    //  comment.AuthorNameAlternate ?? "<null>",
                    //  comment.Regarding.TargetGuid,
                    //  comment.Status,
                    //  comment.StatusGuid
                    //  );
                }
                _conn.UpdateComments(_project, comments);
                _conn.UpdateReplies(_project, replies);
                _conn.UpdateCommentStatuses(_project, statusChanges);
            }
            else
            {
                // Failure, which has already been logged so we don't need to log it again
            }
        }
Exemplo n.º 3
0
        public void RunConversion(Dictionary <MongoDB.Bson.ObjectId, Guid> entryObjectIdToGuidMappings)
        {
            var commentsWithIds = new List <KeyValuePair <string, LfComment> >();

            foreach (var comment in _conn.GetComments(_project))
            {
                Guid guid;
                // LfMergeBridge wants lex entry GUIDs (passed along in comment.Regarding.TargetGuid), not Mongo ObjectIds like comment.EntryRef contains.
                if (comment.EntryRef != null &&
                    entryObjectIdToGuidMappings.TryGetValue(comment.EntryRef, out guid))
                {
                    comment.Regarding.TargetGuid = guid.ToString();

                    // LF-186
                    if (string.IsNullOrEmpty(comment.Regarding.Word))
                    {
                        var lexeme = GetLexEntry(comment.EntryRef).Lexeme.FirstNonEmptyString();
                        var field  = comment.Regarding.FieldNameForDisplay;
                        var ws     = comment.Regarding.InputSystemAbbreviation;
                        var value  = string.IsNullOrEmpty(comment.Regarding.FieldValue)
                                                        ? ""
                                                        : string.Format(" \"{0}\"", comment.Regarding.FieldValue);
                        comment.Regarding.Word = string.Format("{0} ({1} - {2}{3})", lexeme,
                                                               field, ws, value);
                    }
                }

                commentsWithIds.Add(new KeyValuePair <string, LfComment>(comment.Id.ToString(), comment));
            }
            string allCommentsJson = JsonConvert.SerializeObject(commentsWithIds);
            string bridgeOutput;

            CallLfMergeBridge(allCommentsJson, out bridgeOutput);
            // LfMergeBridge returns two lists of IDs (comment IDs or reply IDs) that need to have their GUIDs updated in Mongo.
            string commentGuidMappingsStr = GetPrefixedStringFromLfMergeBridgeOutput(bridgeOutput, "New comment ID->Guid mappings: ");
            string replyGuidMappingsStr   = GetPrefixedStringFromLfMergeBridgeOutput(bridgeOutput, "New reply ID->Guid mappings: ");
            Dictionary <string, Guid> commentIdToGuidMappings = ParseGuidMappings(commentGuidMappingsStr);
            Dictionary <string, Guid> uniqIdToGuidMappings    = ParseGuidMappings(replyGuidMappingsStr);

            _conn.SetCommentGuids(_project, commentIdToGuidMappings);
            _conn.SetCommentReplyGuids(_project, uniqIdToGuidMappings);
        }