public async Task Update(UpdateTranslationRequest request)
        {
            var exists = await Exists(request.ArticleId, request.Translation.Language);

            if (!exists)
            {
                throw new DuplicateKeyException(ExceptionCodes.TRANSLATION_NOT_FOUND, $"Translation with language '{request.Translation.Language}' not found", null, (int)System.Net.HttpStatusCode.NotFound);
            }

            var matchConditions = new FilterDefinition <BsonDocument>[]
            {
                new BsonDocument(
                    "_id",
                    new ObjectId(request.ArticleId)
                    ),
                new BsonDocument(
                    BsonPropertyHelper.GetPropertyName <ArticleEntity>(f => f.Translations),
                    new BsonDocument("$elemMatch", new BsonDocument(BsonPropertyHelper.GetPropertyName <TranslationEntity>(f => f.Language), request.Translation.Language))
                    ),
            };

            var updateDefinition = new BsonDocument(
                "$set", new BsonDocument
            {
                { $"{BsonPropertyHelper.GetPropertyName<ArticleEntity>(f => f.Translations)}.$.{BsonPropertyHelper.GetPropertyName<TranslationEntity>(f => f.Title)}", NormalizeNull(request.Translation.Title) },
                { $"{BsonPropertyHelper.GetPropertyName<ArticleEntity>(f => f.Translations)}.$.{BsonPropertyHelper.GetPropertyName<TranslationEntity>(f => f.Subtitle)}", NormalizeNull(request.Translation.Subtitle) },
                { $"{BsonPropertyHelper.GetPropertyName<ArticleEntity>(f => f.Translations)}.$.{BsonPropertyHelper.GetPropertyName<TranslationEntity>(f => f.Summary)}", NormalizeNull(request.Translation.Summary) },
                { $"{BsonPropertyHelper.GetPropertyName<ArticleEntity>(f => f.Translations)}.$.{BsonPropertyHelper.GetPropertyName<TranslationEntity>(f => f.Date)}", request.Translation.Date },
                { $"{BsonPropertyHelper.GetPropertyName<ArticleEntity>(f => f.Translations)}.$.{BsonPropertyHelper.GetPropertyName<TranslationEntity>(f => f.ReviewedBy)}", NormalizeNull(request.Translation.ReviewedBy) },
                { $"{BsonPropertyHelper.GetPropertyName<ArticleEntity>(f => f.Translations)}.$.{BsonPropertyHelper.GetPropertyName<TranslationEntity>(f => f.Status)}", NormalizeNull(request.Translation.Status) },
                { $"{BsonPropertyHelper.GetPropertyName<ArticleEntity>(f => f.Translations)}.$.{BsonPropertyHelper.GetPropertyName<TranslationEntity>(f => f.TranslatedBy)}", NormalizeNull(request.Translation.TranslatedBy) },
            }
                );

            await _dbContext.GetGenericArticlesCollection().UpdateOneAsync(
                Builders <BsonDocument> .Filter.And(matchConditions),
                updateDefinition
                );
        }
Exemplo n.º 2
0
        private static void Submissions(OAuthAuthenticationStrategy auth)
        {
            var client = new SubmissionApiClient <SampleOriginalAssetKey, SampleCustomTranslationRequestData, SampleTargetAssetKey, SampleCustomSubmissionData>(auth, projectId, "1e65ee5c-2555-4fd4-8305-56228ee3a0dd");

            var itemId = Guid.NewGuid().ToString();

            // List translation requests
            var query = new Dictionary <string, string>();

            query.Add("state", "In Progress|Translated|Completed");
            foreach (var s in client.GetPage(query, 100, 0).items)
            {
                Console.WriteLine(s.translationRequestUid + " " + s.translationSubmissions.Count() + " " + s.fileUri);
                foreach (var sub in s.translationSubmissions)
                {
                    Console.WriteLine("  " + sub.state + sub.targetLocaleId);
                }
            }

            // Sample code to process items in bulk
            foreach (var item in client.GetAll(string.Empty, string.Empty))
            {
                var r = new UpdateTranslationRequest <SampleOriginalAssetKey, SampleCustomTranslationRequestData, SampleTargetAssetKey, SampleCustomSubmissionData>();
                if (item.translationSubmissions == null || item.translationSubmissions.Where(x => x.state != "Deleted").Count() == 0)
                {
                    continue;
                }

                r.translationSubmissions = new List <UpdateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData> >();
                foreach (TranslationSubmission <SampleTargetAssetKey, SampleCustomSubmissionData> s in item.translationSubmissions)
                {
                    r.translationSubmissions.Add(new UpdateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData>
                    {
                        translationSubmissionUid = s.translationSubmissionUid,
                        state = "Deleted"
                    });
                }

                var ur = client.UpdateTranslationRequest(r, item.translationRequestUid);
            }

            var singleRequest = client.Get("27c4b81d8d52");

            // Create translation request
            var createTranslationRequest = new CreateTranslationRequest <SampleOriginalAssetKey, SampleCustomTranslationRequestData>();

            createTranslationRequest.contentHash      = Guid.NewGuid().ToString().Substring(0, 32);
            createTranslationRequest.fileUri          = Guid.NewGuid().ToString();
            createTranslationRequest.originalAssetKey = new SampleOriginalAssetKey()
            {
                Key = itemId
            };
            createTranslationRequest.originalLocaleId   = "en";
            createTranslationRequest.title              = "test";
            createTranslationRequest.customOriginalData = new SampleCustomTranslationRequestData()
            {
                ItemId = itemId, Path = "content/home"
            };

            var request = client.CreateTranslationRequest(createTranslationRequest);

            // Search submissions
            var searchResult = client.GetPage("originalAssetKey.Key", itemId, 100, 0);

            searchResult = client.GetPage("translationRequestUid", "2e3b50ec4de3", 100, 0);

            query = new Dictionary <string, string>();
            query.Add("state", "Translated|Completed");
            query.Add("customTranslationData", "{\"MediaContent\": false }");
            // query.Add("customOriginalData", "{\"Path\": \"/sitecore/content/Home/Team/Chris-Castle\" }");
            searchResult = client.GetPage(query, 100, 0);

            // Create subsmission
            var submission = new CreateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData>();

            submission.state          = "Deleted";
            submission.submitterName  = "test";
            submission.targetLocaleId = "ru-RU";
            submission.targetAssetKey = new SampleTargetAssetKey()
            {
                Key = Guid.NewGuid().ToString()
            };
            submission.customTranslationData = new SampleCustomSubmissionData()
            {
                Revision = Guid.NewGuid().ToString(), Locked = false, MediaContent = false
            };

            request = client.CreateSubmission(request.translationRequestUid, new List <CreateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData> >()
            {
                submission
            });

            // Update submission
            var updateRequest = new UpdateTranslationRequest <SampleOriginalAssetKey, SampleCustomTranslationRequestData, SampleTargetAssetKey, SampleCustomSubmissionData>();

            updateRequest.customOriginalData      = request.customOriginalData;
            updateRequest.customOriginalData.Path = "newpath";
            updateRequest.translationSubmissions  = new List <UpdateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData> > {
                new UpdateSubmissionRequest <SampleTargetAssetKey, SampleCustomSubmissionData> {
                    translationSubmissionUid = request.translationSubmissions[0].translationSubmissionUid,
                    state            = "In Progress",
                    lastExportedDate = DateTime.UtcNow
                }
            };

            var updatedRequest = client.UpdateTranslationRequest(updateRequest, request.translationRequestUid);

            // List translation requests
            foreach (var s in client.GetAll("state", "In Progress"))
            {
                Console.WriteLine(s.translationRequestUid + " " + s.translationSubmissions.Count() + " " + s.fileUri);
            }
        }
Exemplo n.º 3
0
        public virtual TranslationRequest <TOriginalKey, TCustomRequest, TTargetKey, TCustomSubmission> UpdateTranslationRequest(UpdateTranslationRequest <TOriginalKey, TCustomRequest, TTargetKey, TCustomSubmission> request, string translationRequestUid)
        {
            var uriBuilder = this.GetRequestStringBuilder(string.Format(UpdateSubmissionUrl, projectId, bucketName, translationRequestUid));
            var response   = ExecutePutRequest(uriBuilder, request, auth);

            return(JsonConvert.DeserializeObject <TranslationRequest <TOriginalKey, TCustomRequest, TTargetKey, TCustomSubmission> >(response["response"]["data"].ToString()));
        }
        public async Task Update(UpdateTranslationRequest request)
        {
            request.ValidateAndThrow();

            await _translationService.Update(request);
        }