public string GetHeaders(ListStr lHeaders) { if (conf.overrideHeaders) { return(conf.lCustomHeaders.ToStr(conf.separator)); } return(lHeaders.ToStr(conf.separator)); }
/// <summary> /// List all custom properties available for mappings /// </summary> /// <param name="l">List of properties</param> protected override void AddPropertyNamesToList(ListStr l) { //add custom properties (slack.channel.*) of channel for Log 20 l.Add(channel.EltKeys(), "slack.channel."); //add custom properties (slack.message.*) of message for Log 20 l.Add(file.EltKeys(), "slack.file."); //default properties base.AddPropertyNamesToList(l); }
/// <summary> /// Constructor to reconstruct a comment object based on the content of the index. /// </summary> /// <param name="cursor">The cursor from which to retrieve the comment data</param> /// <param name="currentUserId">Current user requesting this comment</param> public Comment(Cursor cursor, string currentUserId) { commentid = cursor.GetColumn("id"); docid = cursor.GetColumn("docid"); message = cursor.GetColumn("message"); userid = cursor.GetColumn("userid"); username = cursor.GetColumn("username"); creation = Sys.ToDat(cursor.GetColumn("creation")); // Dates in the index are UTC dates! modified = Sys.ToDat(cursor.GetColumn("modified")); likes = ListStr.ListFromStr(cursor.GetColumn("likes"), ';'); likedByUser = likes.Contains(currentUserId); replyto = cursor.GetColumn("replyto") ?? ""; deleted = Sys.ToBoo(cursor.GetColumn("deleted")); }
/// <summary> /// Constructor to initialize a new comment based on its minimal required inputs /// Other fields like the comment id and dates are initialized based on those inputs. /// </summary> /// <param name="docid">id of the document to which the comment is attached</param> /// <param name="message">textual content of the comment</param> /// <param name="user">principal of the author of the comment</param> /// <param name="replyto">optional id of the parent comment, if this is a reply</param> public Comment(string docid, string message, CCPrincipal user, string replyto) { creation = Dat.ToUtc(DateTime.Now); commentid = $"{docid}|{Str.Md5(user.UserId + creation.ToBinary())}"; this.docid = docid; this.message = message; userid = user.UserId; username = user.FullName; if (Str.IsEmpty(username)) { username = user.Name; } modified = creation; likes = new ListStr(); likedByUser = false; this.replyto = replyto; deleted = false; }
/// <summary> /// Get the number of comments for a given document or multiple documents /// at once if a list of ids is provided /// </summary> /// <param name="client"></param> /// <param name="docid"></param> private void Count(EngineClient client, string docid) { ListStr docids = Method.JsonRequest.ValueListStr("docids"); if (docids != null && docids.Count > 0) { var sep = dynamicSeparator("=", docids.ToStr(' ')); // Since document ids potentially contains ';', we have to look for a custom separator dynamically var sql = $"SELECT DISTRIBUTION('docid,SEPARATOR=\"{sep}\"') AS ids FROM {indexname} WHERE {Sql.In("docid", docids)} LIMIT 1"; Cursor cursor = client.ExecCursor(sql); if (cursor != null) { // Write JSON var counts = Json.NewObject(); var pairs = cursor.GetAttribute("ids").Split(new [] { sep }, StringSplitOptions.None); foreach (var pair in pairs) { int i = pair.LastIndexOf(';'); counts.Set(pair.Substring(0, i), int.Parse(pair.Substring(i + 1))); } JsonResponse.Set("counts", counts); } else { throw new Exception("Cursor is null!"); } } else { var sql = $"SELECT id FROM {indexname} WHERE docid={Str.SqlValue(docid)} ORDER BY modified LIMIT 1"; Cursor cursor = client.ExecCursor(sql); if (cursor != null) { // Write JSON JsonResponse.Set("count", cursor.TotalRowCount); } else { throw new Exception("Cursor is null!"); } } }
public override Return OnExecute() { string indexes; HashSet <string> hsMD5 = new HashSet <string>(); int emptyLinesCount = 0; int duplicatesLinesCount = 0; int writtenLinesCount = 0; int rowProcessed = 0; ListStr lHeaders = new ListStr(); EngineClient _client = null; Sinequa.Engine.Client.Cursor _cursor = null; //do not use StreamWriter in a using statement. In simulate mode the file is not created so this will trigger an exception. StreamWriter sw = null; try { _client = EngineClientsPool.FromPoolByIndexList(conf.listIndexes, out indexes, conf.engine, false); } catch (Exception ex) { Sys.LogError("Cannot get Engine Client from pool for indexes [" + conf.listIndexes + "]"); Sys.LogError(ex); return(Return.Error); } Sys.Log("Using Engine client [" + _client.Name + "]"); try { Sys.Log("Execute query [" + conf.GetSQL() + "]"); _cursor = _client.ExecCursor(conf.GetSQL()); if (_cursor == null) { Sys.LogError("Cannot get cursor for query [" + conf.GetSQL() + "]"); return(Return.Error); } DocExportIndexToCsv doc = new DocExportIndexToCsv(this, _cursor, conf.dColumnColumnAlias); var context = new IDocContext { Doc = doc }; Sys.Log("Query processingtime [" + _cursor.GetAttribute("processingtime") + "]"); Sys.Log("Query row count [" + _cursor.TotalRowCount + "]"); int globalTimer = Sys.TimerStart(); if (!conf.simulate) { sw = new StreamWriter(conf.destinationFilePath, false, Encoding.UTF8); } int localTimer = Sys.TimerStart(); while (!_cursor.End()) { rowProcessed++; if (rowProcessed % logStatsEveryNRows == 0) { Sys.Log("----------------------------------------------------"); Sys.Log("Number of rows processed [" + rowProcessed + "] "); Sys.Log("Number of lines exported [" + writtenLinesCount + "] "); Sys.Log("Number of empty lines removed [" + emptyLinesCount + "] "); Sys.Log("Number of duplicated lines removed [" + duplicatesLinesCount + "] "); Sys.Log("Processing [" + logStatsEveryNRows + "] rows in [", Sys.TimerGetText(Sys.TickDuration(localTimer)), "]"); localTimer = Sys.TimerStart(); } ListStr l = new ListStr(); bool isEmpty = true; for (int i = 0; i < _cursor.ColumnCount; i++) { if (conf.addHeaders && rowProcessed == 1) //headers { string header = _cursor.GetColumnName(i); if (conf.useDblQuote) { header = "\"" + header + "\""; } lHeaders.Add(header); } string colValue = Str.Empty; //cursor column match column mapping column name ? if (conf.lColumnMapping.Exists(x => Str.EQNC(x.columnName, _cursor.GetColumnName(i)))) { //get all matching column mapping for current column List <ColumnMapping> lColumnMapping = conf.lColumnMapping.FindAll(x => Str.EQNC(x.columnName, _cursor.GetColumnName(i))); foreach (ColumnMapping columnMapping in lColumnMapping) { if (columnMapping.slectionQuery.IsSelected(context, doc)) //match selection query ? if so, apply value pattern { Sys.Log2(40, "Column [" + columnMapping.columnName + "] match selection query [" + columnMapping.slectionQuery.Sql + "]"); colValue = IDocHelper.GetValue(context, doc, columnMapping.valueExpression); Sys.Log2(40, "Column [" + columnMapping.columnName + "] use value pattern [" + columnMapping.valueExpression + "] = [" + colValue + "]"); break; //stop mapping when selection query match } else { Sys.Log2(40, "Column [" + columnMapping.columnName + "] don't match selection query [" + columnMapping.slectionQuery.Sql + "]"); continue; //go to next expression } } } //no column mapping, get value from cursor else { colValue = _cursor.GetColumn(i); } if (!Str.IsEmpty(colValue)) { isEmpty = false; } if (conf.useReplaceSeparator) { colValue = colValue.Replace(conf.separator, conf.replaceSeparator); //replace separator in values } if (conf.useDblQuote) { colValue = "\"" + colValue + "\""; //use double quote } l.Add(colValue); } string line = l.ToStr(conf.separator); if (conf.removeDuplicates) //remove duplicates { string MD5 = Str.Md5(line); if (!hsMD5.Add(MD5)) { duplicatesLinesCount++; _cursor.MoveNext(); continue; } } if (conf.removeEmptyLines && isEmpty) //remove empty lines { emptyLinesCount++; _cursor.MoveNext(); continue; } writtenLinesCount++; if (conf.simulate) //simulate, add headers and line into logs { if (conf.addHeaders && rowProcessed == 1) { Sys.Log(GetHeaders(lHeaders)); // write headers } Sys.Log(line); //write line if (writtenLinesCount >= conf.simulateCount) { break; } } else { if (conf.addHeaders && rowProcessed == 1) { sw.WriteLine(GetHeaders(lHeaders)); // write headers } sw.WriteLine(line); //write line } _cursor.MoveNext(); } if (sw != null) { sw.Close(); //dispose stream writer } Sys.Log("----------------------------------------------------"); if (conf.removeEmptyLines) { Sys.Log("Number of empty lines removed [" + emptyLinesCount + "]"); } if (conf.removeDuplicates) { Sys.Log("Number of duplicated lines removed [" + duplicatesLinesCount + "]"); } Sys.Log("[" + writtenLinesCount + "] lines exported into file [" + conf.destinationFilePath + "]"); Sys.Log("Processing [" + rowProcessed + "] rows in [", Sys.TimerGetText(Sys.TickDuration(globalTimer)), "]"); } catch (Exception ex) { Sys.LogError("Select index Cursor error : ", ex); try { if (_client != null) { EngineClientsPool.ToPool(_client); } } catch (Exception exe) { Sys.LogError("EngineClientsPool ToPool : ", exe); Sys.Log(exe.StackTrace); } } finally { try { if (_cursor != null) { _cursor.Close(); } } catch (Exception ex) { Sys.LogError("Close cursor error : ", ex); Sys.Log(ex.StackTrace); } EngineClientsPool.ToPool(_client); } return(base.OnExecute()); }
public bool LoadConfig() { string value = Str.Empty; string dataTag = Str.Empty; Sys.Log2(20, "----------------------------------------------------"); Sys.Log2(20, "Load configuration"); Sys.Log2(20, "----------------------------------------------------"); if (_XMLConf == null) { Sys.LogError("Cannot read configuration"); return(false); } //index list dataTag = "CMD_INDEX_LIST"; if (!DatatagExist(dataTag)) { return(false); } listIndexes = CC.Current.Indexes.CleanAliasList(_XMLConf.Value(dataTag, Str.Empty)); if (String.IsNullOrEmpty(listIndexes)) { Sys.LogError("Invalid configuration property: index list is empty"); return(false); } //list columns dataTag = "CMD_SELECT"; if (!DatatagExist(dataTag)) { return(false); } value = _XMLConf.Value(dataTag, "*"); //if only one index and index type is audit => do not resolve column aliases CCIndex idx = CC.Current.Indexes.Get(listIndexes); isAuditIndex = idx != null && (idx.IndexType == CCIndexType.Audit || idx.IndexType == CCIndexType.AuditReplicated) ? true : false; ListStr lcolunmOrColumnAlias = ListStr.ListFromStr(value, ','); foreach (string s in lcolunmOrColumnAlias) { string colunmOrColumnAlias = s.Trim(); if (!isAuditIndex) { dColumnColumnAlias.Add(colunmOrColumnAlias, CC.Current.Global.ResolveColumn(colunmOrColumnAlias)); } else { dColumnColumnAlias.Add(colunmOrColumnAlias, colunmOrColumnAlias); } } //where clause dataTag = "CMD_WHERE"; if (!DatatagExist(dataTag)) { return(false); } whereCluase = _XMLConf.Value(dataTag, ""); whereCluase = IDocHelper.GetValuePattern(_ctxt, whereCluase); //group by dataTag = "CMD_GROUPBY"; if (!DatatagExist(dataTag)) { return(false); } grouBy = _XMLConf.Value(dataTag, ""); //order by dataTag = "CMD_ORDERBY"; if (!DatatagExist(dataTag)) { return(false); } orderBy = _XMLConf.Value(dataTag, ""); //count dataTag = "CMD_COUNT"; if (!DatatagExist(dataTag)) { return(false); } count = _XMLConf.ValueInt(dataTag, -1); //Engine dataTag = "CMD_ENGINE"; if (!DatatagExist(dataTag)) { return(false); } engine = CC.Current.Engines.CleanAlias(_XMLConf.Value(dataTag, "")); //add headers dataTag = "CMD_HEADERS"; if (!DatatagExist(dataTag)) { return(false); } addHeaders = _XMLConf.ValueBoo(dataTag, false); //Field separator dataTag = "CMD_SEPARATOR"; if (!DatatagExist(dataTag)) { return(false); } separator = _XMLConf.ValueChar(dataTag, ','); //override headers dataTag = "CMD_HEADERS_OVERRIDE"; if (!DatatagExist(dataTag)) { return(false); } overrideHeaders = _XMLConf.ValueBoo(dataTag, false); //custom headers dataTag = "CMD_HEADERS_CUSTOM"; if (!DatatagExist(dataTag)) { return(false); } string sCustomHeaders = _XMLConf.Value(dataTag, ""); if (addHeaders && overrideHeaders) //check override header has same number of elements than select statement { lCustomHeaders = ListStr.ListFromStr2(sCustomHeaders, separator); if (lCustomHeaders.Count != dColumnColumnAlias.Count) { Sys.LogError("Override headers does not have the same number of elements as select statement"); return(false); } } //use replace separator dataTag = "CMD_USE_REPLACE"; if (!DatatagExist(dataTag)) { return(false); } useReplaceSeparator = _XMLConf.ValueBoo(dataTag, false); //Replace separator in values dataTag = "CMD_SEPARATOR_REPLACE"; if (!DatatagExist(dataTag)) { return(false); } replaceSeparator = _XMLConf.ValueChar(dataTag, '/'); //Enclose fields in double quote dataTag = "CMD_DBL_QUOTES"; if (!DatatagExist(dataTag)) { return(false); } useDblQuote = _XMLConf.ValueBoo(dataTag, false); //Destination file path dataTag = "CMD_FILE_PATH"; if (!DatatagExist(dataTag)) { return(false); } destinationFilePath = CC.Current.EnvVars.Resolve(_XMLConf.Value(dataTag, "")); destinationFilePath = IDocHelper.GetValuePattern(_ctxt, destinationFilePath); if (Str.IsEmpty(destinationFilePath)) { Sys.LogError("Export file path is empty"); return(false); } //Remove duplicate lines dataTag = "CMD_DEDUPLICATE"; if (!DatatagExist(dataTag)) { return(false); } removeDuplicates = _XMLConf.ValueBoo(dataTag, false); //Remove empty lines dataTag = "CMD_REMOVE_EMPTY_LINES"; if (!DatatagExist(dataTag)) { return(false); } removeEmptyLines = _XMLConf.ValueBoo(dataTag, false); //Enable simulate mode dataTag = "CMD_SIMULATE"; if (!DatatagExist(dataTag)) { return(false); } simulate = _XMLConf.ValueBoo(dataTag, false); //Simulate count dataTag = "CMD_NB_LINE_SIMULATE"; if (!DatatagExist(dataTag)) { return(false); } simulateCount = _XMLConf.ValueInt(dataTag, 1000); //Mapping Grid - do not check if DatatagExist - grid is optionnal dataTag = "CMD_MAPPING"; ListOf <XDoc> mappingGridElts = _XMLConf.EltList("CMD_MAPPING"); for (int i = 0; i < mappingGridElts.Count; i++) { XDoc mappingElt = mappingGridElts.Get(i); string columnOrAliasColumn = mappingElt.Value("Column"); if (String.IsNullOrEmpty(columnOrAliasColumn) || String.IsNullOrWhiteSpace(columnOrAliasColumn)) { Sys.LogError("Column Mapping - Column cannot be empty"); return(false); } string val = mappingElt.Value("Value"); if (String.IsNullOrEmpty(val) || String.IsNullOrWhiteSpace(val)) { Sys.LogError("Column Mapping - Value Pattern cannot be empty for column [" + columnOrAliasColumn + "]"); return(false); } string squery = mappingElt.Value("SelectionQuery"); SelectionQuery selectionQuery = SelectionQuery.FromStr(squery, out string errorMessage); if (!Str.IsEmpty(errorMessage)) { Sys.LogError("Column Mapping - Invalid selection query [" + squery + "] for column [" + columnOrAliasColumn + "] - ", errorMessage); return(false); } if (!dColumnColumnAlias.TryGetValue(columnOrAliasColumn, out string columnName)) { columnName = null; } ColumnMapping columnMapping = new ColumnMapping(columnName, columnOrAliasColumn, val, selectionQuery); lColumnMapping.AddUnique(columnMapping); } Sys.Log2(20, "Load configuration OK"); LogConfig(); return(true); }
// es-4959 - new syntax for security clause -- called iff (Sys.SecurityInEngine() == true) -- // _RightsAsSqlStrXb ::= CHECKACLS('AccessLists="accesslist1,accesslist2,...", DeniedLists="deniedlist1,..."{%F%}') FOR('identity1',...) OPTIONAL('opt_identity1',...) VIRTUAL('virt_identity1',...) // where {%F%} is the placeholder for ",FieldRightsAsTextPartWeights="true"" // when Query.RespectFieldPermissions or Session.Profile.RespectFieldPermissions are true private static string RightsAsSqlStrXb(string userId, ListStr otherIdentities, ListStr otherVirtualIdentities) { if (Str.IsEmpty(userId)) { return(null); } int deniedcount = CC.Current.Global.DeniedListCount; int accesscount = CC.Current.Global.AccessListCount; if (accesscount + deniedcount == 0) { return(null); } StringBuilder sb = new StringBuilder(); sb.Append("CHECKACLS('"); if (accesscount > 0) { sb.Append("accesslists=\""); // accesslist1,accesslist2... for (int accessindex = 1; accessindex <= accesscount; accessindex++) { if (accessindex > 1) { sb.Append(','); } sb.Append("accesslist"); sb.Append(Sys.ToStr(accessindex)); } sb.Append('"'); } if (deniedcount > 0) { if (accesscount > 0) { sb.Append(','); } sb.Append("deniedlists=\""); // deniedlist1,deniedlist2... for (int deniedindex = 1; deniedindex <= deniedcount; deniedindex++) { if (deniedindex > 1) { sb.Append(','); } sb.Append("deniedlist"); sb.Append(Sys.ToStr(deniedindex)); } sb.Append('"'); } //sb.Append("{%F%}"); // either ",FieldRightsAsTextPartWeights=\"true\"" or "" // add userId.... (required) ; es-5480 - quote ids with Str.SqlValue() sb.Append("') FOR ("); sb.Append(Str.SqlValue(userId)); sb.Append(")"); // add other identities (optional) .... int nOptional = ListStr.GetCount(otherIdentities); if (nOptional > 0) { sb.Append(" OPTIONAL("); sb.Append(Str.SqlValue(otherIdentities)); sb.Append(')'); } // add virtualIdentities ... int nVirtual = otherVirtualIdentities?.Count ?? 0; if (nVirtual > 0) { sb.Append(" VIRTUAL("); sb.Append(Str.SqlValue(otherVirtualIdentities)); sb.Append(')'); } return(sb.ToString()); }
// Load Peran private void listBoxControl2_SelectedIndexChanged(object sender, EventArgs e) { if (OnAddRole) { return; } if (listBoxControl2.SelectedIndex == 0) { groupControl2.Text = "Peran Baru :"; textEdit4.Text = string.Empty; checkEdit4.Checked = true; checkEdit5.Checked = false; simpleButton3.Enabled = false; foreach (UserSelection pu in ListUser) { pu.Select = false; } UserGrid.RefreshDataSource(); CurrentRole = string.Empty; dateEdit3.DateTime = DateTime.Today; dateEdit4.DateTime = DateTime.Today; //if (sender == null || XtraMessageBox.Show( // "Masukkan Data Hak Akses Peran Lama ke Peran Baru ?", // "Konfirmasi Penyalinan Data Hak Akses ke Peran Baru", // MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) foreach (clsModule mdl in ListModule.Values) { mdl.Ma.Variables.Clear(); mdl.Node.SetValue(treeListColumn2, string.Empty); foreach (List <string> ListStr in mdl.ListKey.Values) { ListStr.Clear(); } } textEdit4.Focus(); } else { simpleButton3.Enabled = true; groupControl2.Text = "Edit Peran"; Role Role = BaseSecurity.CurrentLogin.Admin.Role .QueryRole(listBoxControl2.Text); if (Role == null) { XtraMessageBox.Show(string.Concat("Peran ", listBoxControl2.Text, " sudah dihapus dari database !"), "Error Baca Peran", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); RemoveSelectedRole(); } else { textEdit4.Text = Role.RoleName; checkEdit4.Checked = Role.IsActive; checkEdit5.Checked = Role.UseDateLimit; dateEdit4.DateTime = Role.StartDate; dateEdit3.DateTime = Role.EndDate; foreach (UserSelection s in ListUser) { s.Select = Role.ListUser.IndexOf(s.UserName) >= 0; } UserGrid.RefreshDataSource(); CurrentRole = Role.RoleName; treeList1.BeginUpdate(); foreach (clsModule mdl in ListModule.Values) { mdl.Ma.Variables.Clear(); mdl.Node.SetValue(treeListColumn2, string.Empty); } // Isi Variabel... IDataReader Rdr = BaseSecurity.CurrentLogin.Admin .RoleModule.OpenDataReader(Role.RoleName); try { clsModule mdl; while (Rdr.Read()) { if (ListModule.TryGetValue(Rdr.GetString(0), out mdl)) { BaseUtility.String2Dictionary(Rdr.GetString(1), mdl.Ma.Variables); mdl.Node.SetValue(treeListColumn2, mdl.Ma.ToString()); mdl.AllDocumentData = Rdr.GetBoolean(2); } } } finally { Rdr.Close(); treeList1.EndUpdate(); } foreach (clsModule mdl in ListModule.Values) { foreach (List <string> ListStr in mdl.ListKey.Values) { ListStr.Clear(); } foreach (ModuleDataField mdf in mdl.Ma.ListDataField) { Rdr = BaseSecurity.CurrentLogin.Admin.RoleModule.GetListDocumentVariable( Role.RoleName, mdl.Ma.ModuleName, mdf.DataFieldName); try { List <string> ListKey = mdl.ListKey[mdf.DataFieldName]; ListKey.Clear(); while (Rdr.Read()) { ListKey.Add((string)Rdr[0]); } } finally { Rdr.Close(); } } } } } }