public async Task Create(CreatePublicationRequest request)
        {
            var exists = await Exists(request.ArticleId, request.Language, request.Publication.Publisher);

            if (exists)
            {
                throw new DuplicateKeyException(ExceptionCodes.PUBLICATION_ALREADY_EXISTS, $"Publication with language '{request.Language}' and published by '{request.Publication.Publisher}' already exists");
            }

            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.Language))
                    ),
            };

            await _dbContext.GetGenericArticlesCollection().UpdateOneAsync(
                Builders <BsonDocument> .Filter.And(matchConditions),
                Builders <BsonDocument> .Update.Push(
                    $"{BsonPropertyHelper.GetPropertyName<ArticleEntity>(f => f.Translations)}.$.{BsonPropertyHelper.GetPropertyName<TranslationEntity>(f => f.Publications)}",
                    _mapper.Map <PublicationEntity>(request.Publication)
                    ),
                new UpdateOptions {
                IsUpsert = false
            }
                );
        }
        public async Task AddPublishDate(CreatePublicationRequest request)
        {
            var httpContent = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");

            using (var httpResponse = await _client.PostAsync($"api/v1/publication", httpContent))
            {
                var contentResponse = await httpResponse.Content.ReadAsStringAsync();

                if (httpResponse.StatusCode != HttpStatusCode.OK)
                {
                    throw new Exception($"Error creating publication for article id {request.ArticleId}: {contentResponse}");
                }
            }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            CreatePublicationRequest request;

            try
            {
                request = new CreatePublicationRequest
                {
                    CreatePublicationDetails = CreatePublicationDetails,
                    OpcRetryToken            = OpcRetryToken,
                    OpcRequestId             = OpcRequestId
                };

                response = client.CreatePublication(request).GetAwaiter().GetResult();
                WriteOutput(response, response.Publication);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
Ejemplo n.º 4
0
        public async Task Create(CreatePublicationRequest request)
        {
            request.ValidateAndThrow();

            await _publicationService.Create(request);
        }