/// <summary> /// Reindexes all content /// </summary> /// <param name="query">IndexRequest containing publication information</param> /// <returns>IndexResponse indicating success or failure</returns> /*public IndexResponse ReIndex(IndexRequest request) * { * GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering SolrIndexManager.ReIndex for TCM URI: " + * request.ItemURI); * * OperationResult result = OperationResult.Failure; * string[] schemas; * int publicationID = Convert.ToInt32(request.ItemURI); * * IndexResponse response = new IndexResponse(); * try * { * propertyConfiguration = ConfigurationManager.GetInstance().GetConfiguration(SolrServicesConstants.SCHEMA_ID_MAPPING_CONFIG) * as IPropertyConfiguration; * * schemas = propertyConfiguration.GetPropertyArray("Schema"); * * ReIndex(schemas, publicationID); * CommitToSOLR(); * result = OperationResult.Success; * } * catch (Exception ex) * { * string logString = ServiceConstants.LOG_MESSAGE + Environment.NewLine; * string itemURI = request != null ? request.ItemURI : "Request Query = NULL"; * logString = string.Concat(logString, string.Format("Item URI : {0}", itemURI), * Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); * GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, logString); * result = OperationResult.Failure; * } * response.Result = (int) result; * * GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, * "Exiting SolrIndexManager.ReIndex, Result: " + * result.ToString()); * * return response; * }*/ /// <summary> /// Adds a list of component presentation XML Documents to Solr /// </summary> /// <param name="productDocuments">List of component presentation XMLs</param> /// <returns>IndexResponse</returns> public IndexResponse AddMultipleDocumentXML(List <XmlDocument> documents) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering SolrIndexManager.UpdateProductDocuments: " + documents.Count + " documents"); OperationResult result = OperationResult.Failure; IndexResponse response = new IndexResponse(); try { documents.ForEach(document => AddDocumentXML(document)); CommitToSOLR(); result = OperationResult.Success; } catch (Exception ex) { string logString = GenericStorageExtensionServiceConstants.LOG_MESSAGE + Environment.NewLine; logString = string.Concat(logString, Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, logString); result = OperationResult.Failure; } response.Result = (int)result; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exiting SolrIndexManager.AddProductDocuments, Result: " + result.ToString()); return(response); }
/// <summary> /// This method removes all documents of the given type from a specific Solr Core /// </summary> /// <returns>IndexResponse</returns> public IndexResponse RemoveAllDocumentsOfType(string content_type) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering SolrIndexManager.RemoveAllDocumentsOfType, Content Type: " + content_type); IndexResponse response = new IndexResponse(); OperationResult result = OperationResult.Failure; try { AbstractSolrQuery query = new SolrQueryByField(GenericStorageExtensionServicesConstants.ContentType, content_type); RemoveFromSOLR(query); CommitToSOLR(); result = OperationResult.Success; } catch (Exception ex) { string logString = GenericStorageExtensionServiceConstants.LOG_MESSAGE + Environment.NewLine; logString = string.Concat(logString, string.Format("{0}{1}", ex.Message, ex.StackTrace)); GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, logString); result = OperationResult.Failure; } response.Result = (int)result; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exiting SolrIndexManager.RemoveAllDocumentsOfType, Result: " + result.ToString()); return(response); }
/// <summary> /// Creates a new Link instance and returnes this as a string /// </summary> /// <param name="title">Attribute to include in the link as string</param> /// //example<a href="..">title</a> /// <param name="tcmuri">tcmUri of the Component as string</param> /// <returns>url string</returns> public static string ComponentLinkMethod(string tcmuri) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering method TridionDataHelper.ComponentLinkMethod"); ComponentLink componentLink = null; Link link = null; int publicationID; String linkUrl = string.Empty; try { publicationID = TridionDataHelper.GetContentRepositoryId(tcmuri); GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Publication ID: " + publicationID); componentLink = new ComponentLink(publicationID); link = componentLink.GetLink(tcmuri); GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "ComponentLink: " + link); if (link.IsResolved) { linkUrl = link.Url; } GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Link URL : " + linkUrl); } catch (Exception ex) { GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace); } finally { componentLink.Dispose(); componentLink = null; link = null; } GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exiting method TridionDataHelper.ComponentLinkMethod"); return(linkUrl); }
/// <summary> /// /// </summary> /// <param name="uriList"></param> /// <returns></returns> public static List <XmlDocument> GetComponents(string[] uriList) { List <XmlDocument> componentList = null; if (uriList != null && uriList.Length > 0) { componentList = new List <XmlDocument>(); foreach (string uri in uriList) { try { XmlDocument doc = GetComponent(uri); if (doc != null) { componentList.Add(doc); } } catch (Exception ex) { //Log Warning Here and just move GenericStorageExtensionLogger.WriteLog(ELogLevel.WARN, "Error in getting component list: " + ex.Message + ex.StackTrace); } } return(componentList); } else { return(componentList); } }
/// <summary> /// GetContentRepositoryId shall return the Publication Id from TCM URI /// </summary> /// <param name="URI"></param> /// <returns></returns> public static int GetContentRepositoryId(string URI) { int contentRepositoryId; if (!string.IsNullOrEmpty(URI)) { // Todo: optimize regex expression Regex tcmURIPattern = new Regex(TCM_URI_PATTERN); Regex tcmURIComponentPattern = new Regex(TCM_URI_COMPONENT_PATTERN); if (!(tcmURIPattern.IsMatch(URI)) && !(tcmURIComponentPattern.IsMatch(URI))) { string logString = "An error has occurred. The request trace is: " + Environment.NewLine; logString = string.Concat(logString, string.Format("Invalid Item URI:{0}", URI)); GenericStorageExtensionLogger.WriteLog(ELogLevel.WARN, logString); throw new GenericStorageExtensionIndexingException(TCM_URI_INVALID_CODE, TCM_URI_INVALID_VALUE); } TCMURI uri = new TCMURI(URI); contentRepositoryId = uri.GetPublicationId(); } else { contentRepositoryId = 0; } return(contentRepositoryId); }
public GenericStorageExtensionServiceResponse <IndexResponse> RemoveDocument(GenericStorageExtensionServiceRequest <IndexRequest> query) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering into method IndexService.RemoveDocument"); GenericStorageExtensionServiceResponse <IndexResponse> serviceResponse = new GenericStorageExtensionServiceResponse <IndexResponse>(); string result = string.Empty; try { IndexResponse resultValue; SolrIndexManager indexManager = new SolrIndexManager(query.ServicePayload.LanguageInRequest); resultValue = indexManager.RemoveDocument(query.ServicePayload); serviceResponse.ServicePayload = resultValue; } catch (Exception ex) { string logString = GenericStorageExtensionServiceConstants.LOG_MESSAGE + Environment.NewLine; string request = query != null?query.ToJSONText() : "Request = NULL"; logString = string.Concat(logString, string.Format("Service Request: {0}", request), Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, logString); CatchException <IndexResponse>(ex, serviceResponse); } GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exiting from method IndexService.RemoveDocument"); return(serviceResponse); }
/// <summary> /// Removes Solr Indexes based on the query /// </summary> /// <param name="solrQuery">Solr Query</param> private void RemoveFromSOLR(AbstractSolrQuery solrQuery) { GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Entering SolrIndexManager.RemoveFromSOLR"); var solr = GetInstance <Dictionary <string, object> >(); solr.Delete(solrQuery); GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Exiting SolrIndexManager.RemoveFromSOLR"); }
public IndexResponse AddDocument(IndexRequest query) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering MI4TIndexManager.AddDocument for TCM URI: " + query.ItemURI); IndexResponse response = new IndexResponse(); OperationResult result = OperationResult.Failure; try { XmlDocument doc = new XmlDocument(); string ID = string.Empty; doc.LoadXml(Utility.UpdateContentTypeXML(Regex.Replace(query.DCP.ToString(), @"\b'\b", ""))); var bln = Deserialize <MongoDBModel>(doc); var conString = propConfiguration.GetString(GenericStorageExtensionServicesConstants.Search_URL); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "conString: " + conString); /// creating MongoClient var client = new MongoClient(conString); ///Get the database var DB = client.GetDatabase(propConfiguration.GetString(GenericStorageExtensionServicesConstants.dbName)); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "dbName: " + propConfiguration.GetString(GenericStorageExtensionServicesConstants.dbName)); ///Get the collcetion from the DB in which you want to insert the data var collection = DB.GetCollection <MongoDBModel>(propConfiguration.GetString(GenericStorageExtensionServicesConstants.tableName)); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "tableName: " + propConfiguration.GetString(GenericStorageExtensionServicesConstants.tableName)); //var filter = Builders<MongoDBModel>.Filter.Eq("ItemURI", bln.ItemURI); //var result11 = collection.Find(filter).ToListAsync(); ///Insert data in to MongoDB collection.InsertOne(bln); result = OperationResult.Success; } catch (Exception ex) { string logString = GenericStorageExtensionServiceConstants.LOG_MESSAGE + Environment.NewLine; logString = string.Concat(logString, Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, logString); result = OperationResult.Failure; } response.Result = (int)result; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exiting MI4TIndexManager.AddDocument, Result: " + result.ToString()); return(response); }
private void SetAdditionalParameters(Dictionary <string, string> parameters, ref XmlDocument xdoc) { GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Entering In SetAdditionalParameters"); foreach (KeyValuePair <string, string> parameter in parameters) { XmlElement additionalParam = xdoc.CreateElement(parameter.Key); additionalParam.InnerText = parameter.Value; xdoc.DocumentElement.AppendChild(additionalParam); } GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "End In SetAdditionalParameters"); }
/// <summary> /// This method takes Publication ID and Schema Array as input and inserts the index in Solr. /// This is used to ReIndex all the document type which are the candidates for indexing. /// </summary> /// <param name="schemaArray">Schema Array</param> /// <param name="contentRepositoryId">Content Repository ID</param> private void ReIndex(string[] schemaArray, int contentRepositoryId) { GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Entering SolrIndexManager.ReIndex"); RemoveALLFromSOLR(contentRepositoryId); foreach (string schemaID in schemaArray) { ReIndexSchema(schemaID, contentRepositoryId); } GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Exiting SolrIndexManager.ReIndex"); }
public static void HandleCustomException(Exception ex, string LogMessage) { GenericStorageExtensionIndexingException ampEx = ex as GenericStorageExtensionIndexingException; if (ampEx != null) { GenericStorageExtensionLogger.WriteLog(ELogLevel.WARN, LogMessage); } else { GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, LogMessage); } }
/// <summary> /// Adds XML document to Solr. /// Maps the content to a list of Solr documents and adds them. /// </summary> /// <param name="componentXML">XML Document containing Component Presentation</param> private void AddDocumentXML(XmlDocument componentXML) { GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Entering SolrIndexManager.AddDocumentXML"); string compXML = componentXML != null ? componentXML.InnerXml : " NULL"; GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Component XML: " + compXML); MappedContent mappedContent = ContentMapper.ContentMapper.GetMappedContent(componentXML); AddToSolr(mappedContent.MappedDocuments, mappedContent.DeleteCriteria); GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Exiting SolrIndexManager.AddDocumentXML"); }
/// <summary> /// This method indexes a Component presentation in Solr /// </summary> /// <param name="query">IndexRequest containing the component presentation</param> /// <returns>IndexResponse indicating success or failure</returns> public IndexResponse AddDocument(IndexRequest query) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering SolrIndexManager.AddDocument for TCM URI: " + query.ItemURI); IndexResponse response = new IndexResponse(); OperationResult result = OperationResult.Failure; try { XmlDocument dcpXML = new XmlDocument(); string removeWildCharDCP = string.Empty; if (!string.IsNullOrEmpty(query.DCP)) { removeWildCharDCP = Regex.Replace(query.DCP.ToString(), @"\b'[s]", ""); dcpXML.LoadXml(removeWildCharDCP); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "DCP XML before adding child element " + dcpXML); Dictionary <string, string> additionalParameters = GetAdditionalParameters(); SetAdditionalParameters(additionalParameters, ref dcpXML); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "DCP XML post adding child element " + query.DCP); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "**************************************************************** "); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "dcpXML post adding child element " + dcpXML); } AddDocumentXML(dcpXML); CommitToSOLR(); result = OperationResult.Success; } catch (Exception ex) { string logString = GenericStorageExtensionServiceConstants.LOG_MESSAGE + Environment.NewLine; logString = string.Concat(logString, Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, logString); result = OperationResult.Failure; } response.Result = (int)result; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exiting SolrIndexManager.AddDocument, Result: " + result.ToString()); return(response); }
/// <summary> /// Commits changes till now to Solr /// </summary> /// <param name="rebuild">Oprimize Solr and Rebuild SpellCheck Dictoinary</param> private void CommitToSOLR(Boolean rebuild = false) { GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Entering SolrIndexManager.CommitToSOLR, Rebuild: " + rebuild.ToString()); var solr = GetInstance <Dictionary <string, object> >(); solr.Commit(); if (rebuild) { solr.Optimize(); solr.BuildSpellCheckDictionary(); } GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Exiting SolrIndexManager.CommitToSOLR"); }
public MI4TIndexManager(string Langauge) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering MI4TIndexManager:" + Langauge); try { string MongoDBURL = propConfiguration.GetString(GenericStorageExtensionServicesConstants.Search_URL); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Mongo URL: " + MongoDBURL); } catch (Exception ex) { GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace); throw; } }
public Common.IndexService.DataContracts.IndexResponse AddDocument(IndexRequest query) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering ESI4TIndexManager.AddDocument for TCM URI: " + query.ItemURI); Common.IndexService.DataContracts.IndexResponse response = new Common.IndexService.DataContracts.IndexResponse(); OperationResult result = OperationResult.Failure; try { XmlDocument doc = new XmlDocument(); string ID = string.Empty; doc.LoadXml(Utility.UpdateContentTypeXML(Regex.Replace(query.DCP.ToString(), @"\b'\b", ""))); string jsonText = JsonConvert.SerializeXmlNode(doc); // var bln = Deserialize<Esnews>(doc); var conString = GenericStorageExtensionServicesConstants.Search_URL; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "conString: " + conString); node = new Uri(conString); settings = new ConnectionSettings(node); settings.DefaultIndex("fromelasticstoweb8"); var client = new Nest.ElasticClient(settings); var indexResponse = client.LowLevel.Index <string>("fromelasticstoweb8", "esnews", jsonText); // var responseBool = client.Index(bln); result = OperationResult.Success; } catch (Exception ex) { string logString = GenericStorageExtensionServiceConstants.LOG_MESSAGE + Environment.NewLine; logString = string.Concat(logString, Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, logString); result = OperationResult.Failure; } response.Result = (int)result; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exiting ESI4TIndexManager.AddDocument, Result: " + result.ToString()); return(response); }
/// <summary> /// Removes all content for the given Publication ID /// </summary> /// <param name="publicationID">Publication ID</param> private void RemoveALLFromSOLR(int publicationID) { GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Entering SolrIndexManager.RemoveALLFromSOLR for Publication ID: " + publicationID.ToString()); string publication = "tcm:{0}-*"; publication = string.Format(publication, publicationID.ToString()); AbstractSolrQuery query = new SolrQueryByField(GenericStorageExtensionServicesConstants.TCM_URI, publication); RemoveFromSOLR(query); GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Exiting SolrIndexManager.RemoveALLFromSOLR"); }
/// <summary> /// Singleton ESI4TIndexManager static constructor /// </summary> static GenericStorageExtensionIndexManager() { try { string ElasticIndexConfigPath = Utility.GetConfigurationValue("SearchIndexServiceConfig"); propConfiguration = ConfigurationManager.GetInstance().GetConfiguration(ElasticIndexConfigPath) as IPropertyConfiguration; GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Config Path: " + ElasticIndexConfigPath); } catch (Exception ex) { GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace); throw ex; } GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Exiting ESI4TIndexManager.ESI4TIndexManager()"); }
/// <summary> /// Instantiate SolrIndexManager for a core /// </summary> /// <param name="language"></param> public SolrIndexManager(string solr_core) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering SolrIndexManager(core) with core:" + solr_core); try { Startup.Container.Clear(); Startup.InitContainer(); string solrURL = propConfiguration.GetString(GenericStorageExtensionServicesConstants.SOLR_URL); solrURL = string.Concat(solrURL, GenericStorageExtensionServicesConstants.DELIMITER_SLASH, solr_core); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "SOLR URL: " + solrURL); Boolean instanceExistsAlready = InstanceExists(); lock (containerLock) { if (!string.IsNullOrEmpty(solrURL)) { if (!instanceExistsAlready) { try { Startup.Init <Dictionary <string, object> >(solrURL); } catch (Exception ex) { // Work Around: Need to use mutex here to resolve it properly Startup.Container.Clear(); Startup.InitContainer(); Startup.Init <Dictionary <string, object> >(solrURL); throw ex; } } } } GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Instance exists: " + instanceExistsAlready.ToString()); } catch (Exception ex) { GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace); throw ex; } GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering SolrIndexManager.SolrIndexManager(core)"); }
/// <summary> /// Singleton MI4TIndexManager static constructor /// </summary> static MI4TIndexManager() { try { string MongoDBIndexConfigPath = Utility.GetConfigurationValue("SearchIndexServiceConfig"); propConfiguration = ConfigurationManager.GetInstance().GetConfiguration(MongoDBIndexConfigPath) as IPropertyConfiguration; containerLock = new object(); GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Config Path: " + MongoDBIndexConfigPath); } catch (Exception ex) { GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace); throw ex; } GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Exiting MI4TIndexManager.MI4TIndexManager()"); }
/// <summary> /// This method removes an index from Mongo /// </summary> /// <param name="query">IndexRequest containing delete criteria</param> /// <returns>IndexResponse indicating success or failure</returns> public IndexResponse RemoveDocument(IndexRequest query) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering MI4TIndexManager.RemoveDocument for TCM URI: " + query.ItemURI); IndexResponse response = new IndexResponse(); OperationResult result = OperationResult.Failure; try { MongoServerSettings settings = new MongoServerSettings(); settings.Server = new MongoServerAddress("localhost", 27017); // Create server object to communicate with our server MongoServer server = new MongoServer(settings); MongoDatabase myDB = server.GetDatabase("customerDatabase"); MongoCollection <BsonDocument> records = myDB.GetCollection <BsonDocument>("article"); var query1 = Query.EQ("ItemURI", query.ItemURI); records.Remove(query1); result = OperationResult.Success; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exit MI4TIndexManager.RemoveDocument for TCM URI: " + query.ItemURI + " result " + result); } catch (Exception ex) { string logString = GenericStorageExtensionServiceConstants.LOG_MESSAGE + Environment.NewLine; logString = string.Concat(logString, string.Format("Item URI : {0}", query.ItemURI), Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, logString); result = OperationResult.Failure; } response.Result = (int)result; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exiting MI4TIndexManager.RemoveDocument, Result: " + result.ToString()); return(response); }
private Dictionary <string, string> GetAdditionalParameters() { GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Entering In GetAdditionalParameters"); List <string> parameters = GetParameterList(); Dictionary <string, string> additionalParameters = new Dictionary <string, string>(); foreach (string parameter in parameters) { switch (parameter) { case "lastpublisheddate": //additionalParameters.Add(parameter, DateTime.Now.ToShortDateString()); additionalParameters.Add(parameter, String.Format("{0:s}", DateTime.Now)); break; } } GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "End In GetAdditionalParameters additionalParameters " + additionalParameters); return(additionalParameters); }
private List <string> GetCDatafyAbleNodesXpath(XmlNode xnod) { XmlNodeList nodelist = xnod.SelectNodes(this.XPATH_CONTENT_TYPE_RTF_NODES); List <string> cdatafynodes = new List <string>(); if (nodelist != null && nodelist.Count > 0) { foreach (XmlNode node in nodelist) { cdatafynodes.Add(node.InnerXml); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, node.InnerXml); } } else { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "No CDATAFyable Nodes"); } return(cdatafynodes); }
/// <summary> /// Adds passed documents and deletes existing documents matching delete criteria /// </summary> /// <param name="docs">List of documents to add</param> /// <param name="dels">List of delete crileria as key-value pairs</param> private void AddToSolr(List <Dictionary <string, object> > documentsToAdd, List <KeyValuePair <string, object> > deleteCriteria) { GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Entering SolrIndexManager.AddToSolr"); var solr = ServiceLocator.Current.GetInstance <ISolrOperations <Dictionary <string, object> > >(); List <Dictionary <string, object> > deldocs = new List <Dictionary <string, object> >(); List <SolrQueryByField> deleteQueries = deleteCriteria.Select(item => new SolrQueryByField(item.Key, (string)item.Value)).ToList(); if (deleteQueries.Count > 0) { AbstractSolrQuery deleteQuery = deleteQueries[0]; foreach (SolrQueryByField dq in deleteQueries) { deleteQuery |= dq; } solr.Delete(deleteQuery); } solr.Add(documentsToAdd); GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Exiting SolrIndexManager.AddToSolr"); }
public GenericStorageExtensionServiceResponse <IndexResponse> AddDocument(GenericStorageExtensionServiceRequest <IndexRequest> query) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Enter into method IndexService.AddDocumnet()"); GenericStorageExtensionServiceResponse <IndexResponse> serviceResponse = new GenericStorageExtensionServiceResponse <IndexResponse>(); try { string language = query.ServicePayload.LanguageInRequest; IndexResponse resultValue; SolrIndexManager indexManager = new SolrIndexManager(language); resultValue = indexManager.AddDocument(query.ServicePayload); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "AddDocumnet is called publish is true"); serviceResponse.ServicePayload = resultValue; } catch (Exception ex) { serviceResponse.ServicePayload = new IndexResponse(); serviceResponse.ServicePayload.Result = 1; serviceResponse.ServicePayload.ErrorMessage = "AddDocumnet is not called ispublish is false"; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "AddDocumnet is not called ispublish is false" + ex.Message); } return(serviceResponse); }
/// <summary> /// This method removes an index from Solr /// </summary> /// <param name="query">IndexRequest containing delete criteria</param> /// <returns>IndexResponse indicating success or failure</returns> public IndexResponse RemoveDocument(IndexRequest query) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering SolrIndexManager.RemoveDocument for TCM URI: " + query.ItemURI); IndexResponse response = new IndexResponse(); OperationResult result = OperationResult.Failure; try { // To Remove element and child elements from the SOLR //AbstractSolrQuery deleteQuery = new SolrQueryByField(SolrServicesConstants.BaseParent, query.ItemURI); AbstractSolrQuery deleteQuery = new SolrQueryByField(GenericStorageExtensionServicesConstants.TCM_URI, query.ItemURI); RemoveFromSOLR(deleteQuery); CommitToSOLR(); result = OperationResult.Success; } catch (Exception ex) { string logString = GenericStorageExtensionServiceConstants.LOG_MESSAGE + Environment.NewLine; logString = string.Concat(logString, string.Format("Item URI : {0}", query.ItemURI), Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, logString); result = OperationResult.Failure; } response.Result = (int)result; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exiting SolrIndexManager.RemoveDocument, Result: " + result.ToString()); return(response); }
private static void LogException(GenericStorageExtensionIndexingException ampException) { GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, ampException.Message + ", Code " + ampException.Code); }
public Stream GetContentFromMongoDB(GenericStorageExtensionServiceRequest <SearchRequest> request) { string resultJSON = string.Empty; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering into GetContentFromMongoDB"); try { if (request != null && request.ServicePayload != null) { string MongoDBIndexConfigPath = Utility.GetConfigurationValue("IndexServiceConfig"); propConfiguration = ConfigurationManager.GetInstance().GetConfiguration(MongoDBIndexConfigPath) as IPropertyConfiguration; containerLock = new object(); string result = string.Empty; var connectionString = propConfiguration.GetString(GenericStorageExtensionServicesConstants.Search_URL); var client = new MongoClient(connectionString); var server = client.GetServer(); var database = server.GetDatabase(propConfiguration.GetString(GenericStorageExtensionServicesConstants.dbName)); var collection = database.GetCollection <MongoDBModelSearch>(propConfiguration.GetString(GenericStorageExtensionServicesConstants.tableName)); var andList = new List <IMongoQuery>(); foreach (DictionaryEntry entry in request.ServicePayload.Filters) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Reading request.ServicePayload.Filters"); switch (request.ServicePayload.QueryType.ToUpper()) { case "AND": andList.Add(Query.EQ(entry.Key.ToString(), entry.Value.ToString())); break; case "OR": andList.Add(Query.Or(Query.EQ(entry.Key.ToString(), entry.Value.ToString()))); break; default: andList.Add(Query.Not(Query.EQ(entry.Key.ToString(), entry.Value.ToString()))); break; } } var query = Query.And(andList); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Query generated"); //Map/Reduce var map = "function() {" + " for (var key in this) {" + " emit(key, { count : 1 });" + " }" + "}"; var reduce = "function(key, emits) {" + " total = 0;" + " for (var i in emits) {" + " total += emits[i].count;" + " }" + " return { count : total };" + "}"; MapReduceArgs n = new MapReduceArgs(); n.MapFunction = map; n.ReduceFunction = reduce; var mr = collection.MapReduce(n); foreach (var document in mr.GetResults()) { document.ToJson(); } GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Calling collection.FindOne(query)"); // var entity = collection.Find(query).ToListAsync(); var result1 = collection.FindAs <MongoDBModelSearch>(query); resultJSON = result1.ToJson(); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "OUTPUT: " + resultJSON); } } catch (Exception ex) { GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, "ERROR: " + ex.Message + ex.StackTrace); } return(new MemoryStream(Encoding.UTF8.GetBytes(resultJSON))); }
/// <summary> /// This method removes an index from Elastic /// </summary> /// <param name="query">IndexRequest containing delete criteria</param> /// <returns>IndexResponse indicating success or failure</returns> public Common.IndexService.DataContracts.IndexResponse RemoveDocument(IndexRequest query) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering ESI4TIndexManager.RemoveDocument for TCM URI: " + query.ItemURI); Common.IndexService.DataContracts.IndexResponse response = new Common.IndexService.DataContracts.IndexResponse(); JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = Int32.MaxValue; var webClient = new WebClient(); OperationResult result = OperationResult.Failure; try { XmlDocument doc = new XmlDocument(); string ID = query.ItemURI; string strId = "\"" + ID + "\""; var content = webClient.DownloadString(@"http://*****:*****@"\b'\b", ""))); foreach (var item in data) { var aa = item; if (aa.Key == "hits") { foreach (var item2 in aa.Value) { var aaaa = item2; if (aaaa.Key == "hits") { foreach (var item3 in aaaa.Value) { foreach (var item4 in item3) { if (item4.Key == "_id") { Id = item4.Key; idValue = item4.Value; } } } } } } } //var bln = Deserialize<Esnews>(doc); node = new Uri("http://localhost:9200"); settings = new ConnectionSettings(node); settings.DefaultIndex("fromelasticstoweb8"); var client = new Nest.ElasticClient(settings); var responseReturn = client.Delete <Esnews>(idValue, d => d .Index("fromelasticstoweb8") .Type("esnews")); result = OperationResult.Success; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exit ESI4TIndexManager.RemoveDocument for TCM URI: " + query.ItemURI + " result " + result); } catch (Exception ex) { string logString = GenericStorageExtensionServiceConstants.LOG_MESSAGE + Environment.NewLine; logString = string.Concat(logString, string.Format("Item URI : {0}", query.ItemURI), Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, logString); result = OperationResult.Failure; } response.Result = (int)result; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exiting ESI4TIndexManager.RemoveDocument, Result: " + result.ToString()); return(response); }
public static MappedContent GetMappedContent(XmlDocument componentPresentation, XmlNode xroot = null, Boolean processChild = true, ContentType contentType = null) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering Method: ContentMapper.GetMappedContent"); object target_field_value; ContentType childType; List <Dictionary <string, object> > docList = new List <Dictionary <string, object> >(); List <KeyValuePair <string, object> > deleteCriteriaList = new List <KeyValuePair <string, object> >(); Dictionary <string, object> mappedContent = new Dictionary <string, object>(); XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(componentPresentation.NameTable); AddNamespace(xmlnsManager); if (xroot == null) { xroot = componentPresentation.DocumentElement; } if (contentType == null) { contentType = new ContentType(Utility.GetContentType(componentPresentation)); } foreach (string cdatafyNodeXpath in contentType.CDATAfyNodeXpathList) { XmlNodeList nodes = xroot.SelectNodes(cdatafyNodeXpath, xmlnsManager); if (nodes != null && nodes.Count > 0) { foreach (XmlNode node in nodes) { CDatafyXMLNode(componentPresentation, node); mappedContent.Add(node.Name, node.InnerXml); GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "CDATAFYED: " + node.InnerText); } } } mappedContent.Add(GenericStorageExtensionServicesConstants.ContentType, contentType.contentTypeName); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Content Type is: " + contentType.contentTypeName); childType = contentType.child_type; foreach (ContentTypeField field in contentType.fields) { string xpath = field.cpxpath; if (field.is_constant) { target_field_value = field.default_value; } else if (field.IsAutoDateField()) { target_field_value = DateTime.Now.ToString(); } else if (field.IsCurrentPositionNumber()) { target_field_value = GetNodePosition(xroot); } else if (field.IsParentPositionNumber()) { target_field_value = GetNodePosition(xroot.ParentNode); } else if (field.is_multi_valued) { XmlNodeList nodes = xroot.SelectNodes(xpath, xmlnsManager); if (nodes == null) { // Continue mapping other fields GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Field " + field.field_name + " not found in XML - Skipping"); continue; } List <object> values = new List <object>(); foreach (XmlNode node in nodes) { values.Add(GetProcessedFieldValue(field, node, componentPresentation)); } target_field_value = values.ToArray(); } else if (field.IsMultimediaField()) { XmlNode node = xroot.SelectSingleNode(xpath, xmlnsManager); if (node == null) { // Continue mapping other fields GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Field " + field.field_name + " not found in XML - Skipping"); continue; } else { if (node.Attributes != null && node.Attributes.Count > 0 && node.Attributes["Path"] != null) { target_field_value = node.Attributes["Path"].Value; } else { target_field_value = string.Empty; } } } else { XmlNode node = xroot.SelectSingleNode(xpath, xmlnsManager); if (node == null) { // Continue mapping other fields GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Field " + field.field_name + " not found in XML - Skipping"); continue; } else { target_field_value = node.InnerText; } } GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, " " + field.target_field_name + ": " + target_field_value); mappedContent.Add(field.target_field_name, target_field_value); if (field.is_key) { KeyValuePair <string, object> deleteCriteria = new KeyValuePair <string, object>(field.target_field_name, target_field_value); deleteCriteriaList.Add(deleteCriteria); } } docList.Add(mappedContent); if ((childType != null) && processChild) { GenericStorageExtensionLogger.WriteLog(ELogLevel.DEBUG, "Mapping Child Content Type: " + childType.contentTypeName); MappedContent mappedChildContent; if (childType.is_multi_valued) { foreach (XmlNode xn in xroot.SelectNodes(childType.xpath, xmlnsManager)) { mappedChildContent = GetMappedContent(componentPresentation, xn, false, childType); docList.AddRange(mappedChildContent.MappedDocuments); deleteCriteriaList.AddRange(mappedChildContent.DeleteCriteria); } } else { mappedChildContent = GetMappedContent(componentPresentation, xroot.SelectSingleNode(childType.xpath, xmlnsManager), false, childType); docList.AddRange(mappedChildContent.MappedDocuments); deleteCriteriaList.AddRange(mappedChildContent.DeleteCriteria); } } GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exiting Method: ContentMapper.GetMappedContent"); return(new MappedContent(docList, deleteCriteriaList)); }