private List <string> GetAvailableRecordIdentifiers(ESSearchResponse esResponse) { IEnumerable <IGrouping <string, string> > groupedTypes = esResponse.SearchResult.Hits.GroupBy(x => x.Type, x => x.Id); List <string> availableRecordIdentifiers = new List <string>(); Stopwatch sw = new Stopwatch(); sw.Start(); foreach (var groupedType in groupedTypes) { var condition = PrepareRightsCondition(esResponse, groupedType.Key, groupedType.ToList()); if (_userConnection.EntitySchemaManager.FindInstanceByName(condition.Key) == null || condition.Value.Count == 0) { _log.InfoFormat("Instance of entity with name {0} was not found while checking record permisiions.", condition.Key); continue; } var esq = new EntitySchemaQuery(_userConnection.EntitySchemaManager, condition.Key); esq.PrimaryQueryColumn.IsAlwaysSelect = true; foreach (string column in _userConnection.DBSecurityEngine.GetSchemaSignificantColumns(condition.Key)) { if (esq.RootSchema.Columns.FindByName(column) != null) { esq.AddColumn(column); } } esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, esq.PrimaryQueryColumn.Name, condition.Value)); EntityCollection collection = esq.GetEntityCollection(_userConnection); AppendAvailableRecordIds(availableRecordIdentifiers, collection, groupedType.Key, esResponse); } sw.Stop(); _metricReporter.Report(new SearchMetric { Duration = sw.ElapsedMilliseconds, Source = SearchSource.Bpm }); return(availableRecordIdentifiers); }
public string AddFoldersQueueItems(List <object> folderIds, string entitySchemaName, Guid queueId) { List <String> emptyParameters = new List <String>(); if (folderIds.IsNullOrEmpty()) { emptyParameters.Add("folderIds"); } if (entitySchemaName.IsNullOrEmpty()) { emptyParameters.Add("entitySchemaName"); } if (queueId.IsEmpty()) { emptyParameters.Add("queueId"); } if (!emptyParameters.IsNullOrEmpty()) { string message = string.Format(new LocalizableString("Terrasoft.Common", "Exception.ArgumentNullOrEmpty"), StringUtilities.Concat(emptyParameters)); var emptyParametersResult = new { addedEntitiesCount = 0, errorMessages = message }; return(ServiceStackTextHelper.Serialize(emptyParametersResult)); } UserConnection userConnection = (UserConnection)HttpContext.Current.Session["UserConnection"]; EntitySchemaManager entitySchemaManager = userConnection.EntitySchemaManager; var esq = new EntitySchemaQuery(entitySchemaManager, entitySchemaName + "Folder"); esq.PrimaryQueryColumn.IsVisible = true; esq.AddColumn("SearchData"); esq.AddColumn("FolderType"); esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "Id", folderIds)); Terrasoft.Core.Entities.EntityCollection entities = esq.GetEntityCollection(userConnection); var addedEntitiesCount = 0; StringBuilder errorMessages = new StringBuilder(); foreach (Entity entity in entities) { try { addedEntitiesCount = addedEntitiesCount + AddFolderEntityQueueItems(userConnection, entity, entitySchemaName, queueId); } catch (Exception e) { errorMessages.AppendLine(e.Message); } } var result = new { addedEntitiesCount = addedEntitiesCount, errorMessages = errorMessages.ToString() }; return(ServiceStackTextHelper.Serialize(result)); }
public ConfigurationServiceResponse SubscribeContact(Guid contactId, Guid entityId, Guid entitySchemaUId) { var response = new ConfigurationServiceResponse(); object[] contactIds = new object[] { contactId }; CoreEntityCollection sysAdminUnits = GetSysAdminUnits(contactIds); try { foreach (SysAdminUnit sysAdminUnit in sysAdminUnits) { InnerSubscribeUser(sysAdminUnit.Id, entityId, entitySchemaUId); break; } } catch (Exception e) { response.Exception = e; } return(response); }
private SelectQueryResponse GetVisaData(Select entitiesSelect) { Dictionary <string, string> serverToClientColumnNameMap = GetColumnNameMap(entitiesSelect); var collection = new EntityCollection(_userConnection, _baseVisaSchema); using (DBExecutor dbExecutor = _userConnection.EnsureDBConnection()) { using (IDataReader dataReader = entitiesSelect.ExecuteReader(dbExecutor)) { collection.Load(dataReader); } } var convertedEntities = QueryExtension.GetEntityCollection(collection, serverToClientColumnNameMap); Dictionary <string, object> config = QueryExtension.GetColumnConfig(_baseVisaESQ, serverToClientColumnNameMap); SelectQueryResponse response = new SelectQueryResponse { Rows = convertedEntities, RowsAffected = convertedEntities.Count, RowConfig = config }; return(response); }
private Dictionary <Guid, Guid> GetSysModuleEntityPageTypes() { var result = new Dictionary <Guid, Guid>(); var esq = new EntitySchemaQuery(EntitySchemaManager, "SysModuleEntity") { IgnoreDisplayValues = true, UseAdminRights = false, UseLocalization = false }; esq.AddColumn("SysEntitySchemaUId"); esq.AddColumn("TypeColumnUId"); EntityCollection entityCollection = esq.GetEntityCollection(UserConnection); entityCollection.ForEach(e => { var sysEntitySchemaUId = e.GetTypedColumnValue <Guid>("SysEntitySchemaUId"); var typeColumnUId = e.GetTypedColumnValue <Guid>("TypeColumnUId"); result[sysEntitySchemaUId] = typeColumnUId; }); return(result); }
/// <summary> /// Returns value of the result parameter. /// </summary> /// <returns></returns> public virtual Guid GetResultParameter() { if (string.IsNullOrEmpty(DecisionalColumnMetaPath)) { return(Guid.Empty); } Guid resultParameterId = Guid.Empty; var entitySchema = UserConnection.EntitySchemaManager.GetInstanceByUId(ObjectSchemaId); var columnSchema = entitySchema.GetSchemaColumnByMetaPath(DecisionalColumnMetaPath); var esq = new EntitySchemaQuery(entitySchema) { UseAdminRights = false }; var column = esq.AddColumn(columnSchema.Name); esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "Id", RecordId)); CoreEntityCollection resultCollection = esq.GetEntityCollection(UserConnection); if (resultCollection.Count != 0) { resultParameterId = resultCollection.First.Value.GetTypedColumnValue <Guid>(column.ValueQueryAlias); } return(resultParameterId); }
public SelectQueryResponse GetEntities(RequestOptions requestOptions) { Select selectFromProviders = GetSelectFromProviders(); if (selectFromProviders == null) { return(new SelectQueryResponse { Rows = null, RowsAffected = 0, RowConfig = null }); } Select entitiesSelect = WrapSelect(selectFromProviders); ApplyOptions(ref entitiesSelect, requestOptions); Dictionary <string, string> serverToClientColumnNameMap = GetColumnNameMap(entitiesSelect); CoreEntitySchema baseVisaSchema = GetExtendedBaseVisaEntitySchema(); EntitySchemaQuery baseVisaESQ = GetExtendedBaseVisaESQ(baseVisaSchema); Terrasoft.Core.Entities.EntityCollection collection = new Terrasoft.Core.Entities.EntityCollection(_userConnection, baseVisaSchema); using (DBExecutor dbExecutor = _userConnection.EnsureDBConnection()) { using (IDataReader dataReader = entitiesSelect.ExecuteReader(dbExecutor)) { collection.Load(dataReader); } } var convertedEntities = QueryExtension.GetEntityCollection(collection, serverToClientColumnNameMap); Dictionary <string, object> config = QueryExtension.GetColumnConfig(baseVisaESQ, serverToClientColumnNameMap); SelectQueryResponse response = new SelectQueryResponse { Rows = convertedEntities, RowsAffected = convertedEntities.Count, RowConfig = config }; return(response); }
private void AppendAvailableRecordIds(List <string> availableRecordIdentifiers, EntityCollection rightsCollection, string entityName, ESSearchResponse esResponse) { if (GetIsFileEntity(entityName)) { var availableIds = rightsCollection.Select(e => e.PrimaryColumnValue.ToString().ToLower()); try { EntitySchema fileSchema = _userConnection.EntitySchemaManager.FindInstanceByName(entityName); var parentColumnName = entityName.Replace(FileEntityNameSuffix, ""); var column = fileSchema.Columns.FindByName(parentColumnName); if (column != null) { var masterPrimaryColumnAlias = GlobalSearchColumnUtils.GetPrimaryColumnAlias(column, entityName); var availableFileHits = _userConnection.DBSecurityEngine.GetSchemaUseMasterRecordRights(entityName) ? esResponse.SearchResult.Hits.Where( x => x.Type == entityName && availableIds.Contains(x.Id.ToLower())).ToList() : esResponse.SearchResult.Hits.Where( x => x.Source.ContainsKey(masterPrimaryColumnAlias) && x.Type == entityName && availableIds.Contains(x.Source[masterPrimaryColumnAlias].ToLower())).ToList(); availableRecordIdentifiers.AddRange(availableFileHits.Select(x => x.Id.ToLower())); } } catch (Exception ex) { _log.ErrorFormat(@"Entity name: {0}, Identifiers: {1} Exception: {2}" , entityName, string.Join(", ", availableIds), ex.Message); } return; } availableRecordIdentifiers.AddRange(rightsCollection .Select(e => e.PrimaryColumnValue.ToString().ToLower())); }