private static void ExportNlm(INlmExportService exportService, ArticleItem articleItem, PublicationType pubType) { // Generate NLM XML, and retrieve the validation result var result = exportService.ExportNlm(articleItem, ExportType.Manual, pubType); if (!result.ExportSuccessful) { // NLM Export failed SheerResponse.Alert( "The article did not pass NLM validation and has not been exported. Please check the fields and try again."); return; } SheerResponse.Alert("The article passed NLM validation and exported successfully."); }
public string ReExport(string articleNumber) { try { //Use the NlmExportService to reExport the NLM feed ExportResult result = _nlmExportService.ExportNlm(_searcher.GetArticleByNumber(articleNumber), ExportType.Manual, PublicationType.Ecorrected); if (result.ExportSuccessful) { return(string.Empty); } else { return(result.Exception.ToString()); } } catch (Exception ex) { Sitecore.Diagnostics.Log.Error("Error while ReExporting Article Nlm: " + ex.ToString(), this.GetType()); return(ex.ToString()); } }
protected override void Run(PublishItemContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } try { _logger.Debug("Export to NLM started on Publish. Context.Action = [" + context.Action + "]."); var itemId = context.ItemId; var sourceItem = context.VersionToPublish ?? context.PublishOptions.SourceDatabase.GetItem(itemId); var targetItem = context.PublishOptions.TargetDatabase.GetItem(itemId); // Check if the current item is actually an Article item if (sourceItem == null || sourceItem.TemplateID != IArticleConstants.TemplateId) { _logger.Debug($"Skipping NLM export for item (not an article): '{itemId}'"); return; } switch (context.Action) { // Handle 'Delete' Publish case PublishAction.DeleteTargetItem: { var database = _serviceFactory(context.PublishOptions.TargetDatabase); var article = database.Cast <ArticleItem>(targetItem); // Export a _del.xml file _exportService.DeleteNlm(article); _logger.Info($"Exported NLM delete for article: '{itemId}'"); } break; // Handle 'New Version' Publish case PublishAction.PublishVersion: { var database = _serviceFactory(context.PublishOptions.SourceDatabase); var article = database.Cast <ArticleItem>(sourceItem); var isFirstScheduledPublishForItem = !_publishHistory.Find(sourceItem.ID.Guid).Any(); // Check if the current article is migrated content. If so, don't generate NLM if (!string.IsNullOrEmpty(article.Legacy_Article_Number)) { _logger.Info($"Skipping NLM export for article {article.Article_Number} (article is a legacy PMBI article {article.Legacy_Article_Number}): article ID - '{itemId}'"); return; } if (!string.IsNullOrEmpty(article.Escenic_ID)) { _logger.Info($"Skipping NLM export for article {article.Article_Number} (article is legacy Escenic article {article.Escenic_ID}): article ID - '{itemId}'"); return; } if (!isFirstScheduledPublishForItem) { _logger.Info($"Skipping NLM export for item (article already published via Scheduled Publishing): '{itemId}'"); return; } // Export the article as an NLM file _exportService.ExportNlm(article, ExportType.Scheduled); context.AddMessage($"NLM export of article '{itemId}' was successful."); } break; } _logger.Debug("Export to NLM ended on Publish."); } catch (Exception ex) { _logger.Error($"Unexpected error occurred while exporting Article ID {context.ItemId} on publish.", ex); } }