private void traverseGenericsPopulatingSubRootMaps(ClarifyGenericMapEntry parentGenericMap) { if (parentGenericMap.ClarifyGeneric.Count < 1) { return; } var childSubRootMaps = parentGenericMap.ChildGenericMaps.Where(map => map.IsNewRoot()).ToArray(); foreach (var childGenericMap in childSubRootMaps) { var parentKeyField = childGenericMap.NewRoot.ParentKeyField; var subRootGeneric = childGenericMap.ClarifyGeneric; var rootKeyField = childGenericMap.NewRoot.RootKeyField; if (_schema.IsIntegerField(parentGenericMap.ClarifyGeneric.TableName, parentKeyField)) { var parentIds = parentGenericMap.ClarifyGeneric.Rows.Cast <ClarifyDataRow>().Select(row => Convert.ToInt32(row[parentKeyField])).ToArray(); subRootGeneric.Filter.AddFilter(FilterType.IsIn(rootKeyField, parentIds)); } else { var parentIds = parentGenericMap.ClarifyGeneric.Rows.Cast <ClarifyDataRow>().Select(row => row[parentKeyField].ToString()).ToArray(); subRootGeneric.Filter.AddFilter(FilterType.IsIn(rootKeyField, parentIds)); } subRootGeneric.Query(); traverseGenericsPopulatingSubRootMaps(childGenericMap); } parentGenericMap.ChildGenericMaps.Where(map => !map.IsNewRoot()).Each(traverseGenericsPopulatingSubRootMaps); }
public void Visit(BeginAdHocRelation beginAdHocRelation) { validateAdhocRelation(beginAdHocRelation); var parentClarifyGenericMap = _genericStack.Peek(); parentClarifyGenericMap.ClarifyGeneric.DataFields.Add(beginAdHocRelation.FromTableField); var tableGeneric = parentClarifyGenericMap.ClarifyGeneric.DataSet.CreateGeneric(beginAdHocRelation.ToTableName); tableGeneric.DataFields.Add(beginAdHocRelation.ToTableFieldName); var subRootInformation = new SubRootInformation { ParentKeyField = beginAdHocRelation.FromTableField, RootKeyField = beginAdHocRelation.ToTableFieldName }; var clarifyGenericMap = new ClarifyGenericMapEntry { ClarifyGeneric = tableGeneric, Model = _modelStack.Peek(), NewRoot = subRootInformation }; parentClarifyGenericMap.AddChildGenericMap(clarifyGenericMap); _genericStack.Push(clarifyGenericMap); }
private ModelData[] createDtosForMap(WorkflowObject workflowObject, ClarifyGenericMapEntry genericMap, IEnumerable <ClarifyDataRow> records) { var rows = new List <ModelData>(); foreach (var record in records) { var row = new ModelData { Name = genericMap.Model.ModelName, Entity = genericMap.Entity }; populateDTOForGenericRecord(genericMap, record, row); genericMap.Tags.Each(_ => row.AddTag(_)); var cancellationPolicies = genericMap .Transforms .OfType <ConfiguredCancellationPolicy>() .ToList(); var shouldAdd = !cancellationPolicies.Any() || (cancellationPolicies.Any() && cancellationPolicies.All(_ => !(bool)_.Execute(row, _services))); if (shouldAdd) { var actCode = row.Get <int>("type"); row["activityName"] = _listCache.GetLocalizedTitleByRank("Activity Name", actCode); row["isChild"] = workflowObject.IsChild; row["entity"] = workflowObject.Type; rows.Add(row); } } return(rows.ToArray()); }
public void Visit(BeginMappedProperty instruction, Func <ClarifyGenericMapEntry, ClarifyDataRow, bool> condition) { executeInstruction(() => { var parentClarifyGenericMap = _genericStack.Peek(); var key = instruction.Key.Resolve(_services).ToString(); var childModel = new ModelInformation { ModelName = key, ParentProperty = key, AllowEmpty = instruction.AllowEmpty }; var clarifyGenericMap = new ClarifyGenericMapEntry { ClarifyGeneric = parentClarifyGenericMap.ClarifyGeneric, Model = childModel, Condition = condition }; parentClarifyGenericMap.AddChildGenericMap(clarifyGenericMap); _genericStack.Push(clarifyGenericMap); _modelStack.Push(childModel); }); }
public void Visit(BeginAdHocRelation instruction) { //validateAdhocRelation(beginAdHocRelation); var parentClarifyGenericMap = _genericStack.Peek(); parentClarifyGenericMap.ClarifyGeneric.DataFields.Add(instruction.FromTableField.Resolve(_services).ToString()); var tableGeneric = parentClarifyGenericMap.ClarifyGeneric.DataSet.CreateGeneric(instruction.ToTableName.Resolve(_services).ToString()); tableGeneric.DataFields.Add(instruction.ToTableFieldName.Resolve(_services).ToString()); var subRootInformation = new SubRootInformation { ParentKeyField = instruction.FromTableField.Resolve(_services).ToString(), RootKeyField = instruction.ToTableFieldName.Resolve(_services).ToString() }; var model = _modelStack.Peek(); var clarifyGenericMap = new ClarifyGenericMapEntry { ClarifyGeneric = tableGeneric, Model = new ModelInformation { ModelName = model.ModelName, ParentProperty = model.ParentProperty, IsCollection = model.IsCollection }, NewRoot = subRootInformation }; parentClarifyGenericMap.AddChildGenericMap(clarifyGenericMap); _genericStack.Push(clarifyGenericMap); }
private ModelData assembleWithIdentifier(ModelMap map, string identifier, ClarifyGenericMapEntry rootGenericMap) { var identifierFieldName = findIdentifierFieldName(map, rootGenericMap); var filter = FilterType.Equals(identifierFieldName, identifier); return(assembleWithFilter(filter, rootGenericMap, null).Models.FirstOrDefault()); }
private MODEL assembleWithIdentifier(int identifier, ClarifyGenericMapEntry rootGenericMap) { var identifierFieldName = GetIdentifierFieldName(rootGenericMap); var filter = FilterType.Equals(identifierFieldName, identifier); return(assembleWithFilter(filter, rootGenericMap, null).Models.FirstOrDefault()); }
private void populateDTOWithRelatedGenericRecords(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, ModelData model) { var childMapsForDtoType = genericMap.ChildGenericMaps.Where(child => model.Name == child.Model.ModelName).ToArray(); populateSubRootMaps(model, childMapsForDtoType, record); populateBasedOnRelatedGenerics(model, childMapsForDtoType, record); }
private void populateDTOForGenericRecord(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, object dto) { populateDTOWithFieldValues(genericMap, record, dto); populateDTOWithRelatedGenericRecords(genericMap, record, dto); populateDTOWithRelatedDTOs(genericMap, record, dto); }
private void populateDTOWithRelatedGenericRecords(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, object dto) { var childMapsForDtoType = genericMap.ChildGenericMaps.Where(child => dto.GetType() == child.Model.ModelType).ToArray(); populateSubRootMaps(dto, childMapsForDtoType, record); populateBasedOnRelatedGenerics(dto, childMapsForDtoType, record); }
public void Visit(BeginView instruction) { var rootGeneric = DataSet.CreateGeneric(instruction.ViewName); var clarifyGenericMap = new ClarifyGenericMapEntry { ClarifyGeneric = rootGeneric, Model = _modelStack.Peek() }; _genericStack.Push(clarifyGenericMap); }
public void Visit(BeginView beginView) { var rootGeneric = DataSet.CreateGeneric(beginView.TableName); var clarifyGenericMap = new ClarifyGenericMapEntry { ClarifyGeneric = rootGeneric, Model = _modelStack.Peek() }; _genericStack.Push(clarifyGenericMap); }
private static string findIdentifierFieldName(ModelMap map, ClarifyGenericMapEntry rootGenericMap) { var identifierFieldName = rootGenericMap.GetIdentifierFieldName(); if (identifierFieldName == null) { throw new DovetailMappingException(1003, "Map \"{0}\" does not have an identifying field defined.", map.Name); } return(identifierFieldName); }
private static string GetIdentifierFieldName(ClarifyGenericMapEntry rootGenericMap) { var identifierFieldName = rootGenericMap.GetIdentifierFieldName(); if (identifierFieldName == null) { throw new DovetailMappingException(1003, "Map for type {0} does not have an identifying field defined.", typeof(MODEL).Name); } return(identifierFieldName); }
public void Visit(BeginRelation beginRelation) { var parentClarifyGenericMap = _genericStack.Peek(); var relationGeneric = parentClarifyGenericMap.ClarifyGeneric.Traverse(beginRelation.RelationName); var clarifyGenericMap = new ClarifyGenericMapEntry { ClarifyGeneric = relationGeneric, Model = _modelStack.Peek() }; parentClarifyGenericMap.AddChildGenericMap(clarifyGenericMap); _genericStack.Push(clarifyGenericMap); }
private void populateDTOForGenericRecord(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, ModelData dto) { populateDTOWithFieldValues(genericMap, record, dto); populateDTOWithRelatedGenericRecords(genericMap, record, dto); populateDTOWithRelatedDTOs(genericMap, record, dto); foreach (var transform in genericMap.Transforms) { transform.Execute(dto, _services); } }
private PaginationResult <MODEL> assembleWithSortOverrides(ClarifyGenericMapEntry rootGenericMap, IPaginationRequest paginationRequest) { if (FieldSortMapOverrides.Any()) //override map sort with our own { rootGenericMap.ClarifyGeneric.ClearSorts(); foreach (var f in FieldSortMapOverrides) { rootGenericMap.ClarifyGeneric.AppendSort(f.FieldName, f.IsAscending); } } return(assemble(rootGenericMap, paginationRequest)); }
private void populateDTOForGenericRecord(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, ModelData dto) { populateDTOWithFieldValues(genericMap, record, dto); populateDTOWithRelatedGenericRecords(genericMap, record, dto); populateDTOWithRelatedDTOs(genericMap, record, dto); foreach (var transform in genericMap.Transforms.Where(_ => !(_ is ConfiguredCancellationPolicy) && _.ShouldExecute(dto))) { transform.Execute(dto, _services); } }
private MODEL[] createDtosForMap(ClarifyGenericMapEntry genericMap, IEnumerable <ClarifyDataRow> records) { var dtos = new List <MODEL>(); foreach (var record in records) { var dto = FastYetSimpleTypeActivator.CreateInstance(genericMap.Model.ModelType); populateDTOForGenericRecord(genericMap, record, dto); dtos.Add((MODEL)dto); } return(dtos.ToArray()); }
public void Visit(BeginModelMap instruction) { _modelStack.Push(new ModelInformation { ModelName = instruction.Name }); var clarifyGenericMap = new ClarifyGenericMapEntry { ClarifyGeneric = _rootGeneric, Model = _modelStack.Peek() }; _genericStack.Push(clarifyGenericMap); }
private PaginationResult assemble(WorkflowObject workflowObject, ClarifyGenericMapEntry rootGenericMap) { var result = new PaginationResult(); var rootClarifyGeneric = rootGenericMap.ClarifyGeneric; rootClarifyGeneric.DataSet.Query(rootClarifyGeneric); traverseGenericsPopulatingSubRootMaps(rootGenericMap); var records = rootGenericMap.ClarifyGeneric.DataRows(); result.Models = createDtosForMap(workflowObject, rootGenericMap, records); return(result); }
public void Visit(BeginRelation instruction) { var parentClarifyGenericMap = _genericStack.Peek(); var relationGeneric = parentClarifyGenericMap.ClarifyGeneric.Traverse(instruction.RelationName.Resolve(_services).ToString()); var model = _modelStack.Peek(); var clarifyGenericMap = new ClarifyGenericMapEntry { ClarifyGeneric = relationGeneric, Model = new ModelInformation { ModelName = model.ModelName, ParentProperty = model.ParentProperty, IsCollection = model.IsCollection } }; parentClarifyGenericMap.AddChildGenericMap(clarifyGenericMap); _genericStack.Push(clarifyGenericMap); }
private void populateDTOWithRelatedDTOs(ClarifyGenericMapEntry parentGenericMap, ClarifyDataRow parentRecord, object parentDto) { var childMapsForChildDtos = parentGenericMap.ChildGenericMaps.Where(child => parentDto.GetType() != child.Model.ModelType); foreach (var childMap in childMapsForChildDtos) { var parentProperty = new SingleProperty(childMap.Model.ParentProperty); var childModelType = childMap.Model.ModelType; if (typeof(IEnumerable).IsAssignableFrom(parentProperty.PropertyType)) { var propertyDTOs = new ArrayList(); foreach (var childRecord in parentRecord.RelatedRows(childMap.ClarifyGeneric)) { var propertyDTO = FastYetSimpleTypeActivator.CreateInstance(childModelType); populateDTOForGenericRecord(childMap, childRecord, propertyDTO); propertyDTOs.Add(propertyDTO); } parentProperty.SetValue(parentDto, propertyDTOs.ToArray(childModelType)); } else //dto is not enumerable just get the first child row { var relatedChildRows = parentRecord.RelatedRows(childMap.ClarifyGeneric); if (relatedChildRows.Any()) { var propertyDTO = FastYetSimpleTypeActivator.CreateInstance(childModelType); var childRecord = relatedChildRows.First(); populateDTOForGenericRecord(childMap, childRecord, propertyDTO); parentProperty.SetValue(parentDto, propertyDTO); } else { parentProperty.SetValue(parentDto, null); } } } }
private void populateDTOWithFieldValues(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, object dto) { foreach (var fieldMap in genericMap.FieldMaps) { if (fieldMap.Property == null) { continue; } var propertyValue = GetFieldValueForRecord(fieldMap, record); if (propertyValue is string && fieldMap.ShouldEncode) { propertyValue = _outputEncoder.Encode((string)propertyValue); } if (fieldMap.Property.PropertyType == typeof(int)) { propertyValue = Convert.ToInt32(propertyValue); } if (fieldMap.Property.PropertyType == typeof(DateTime)) { var dateTime = Convert.ToDateTime(propertyValue); var utcDateTime = new DateTime(dateTime.Ticks, DateTimeKind.Utc); propertyValue = utcDateTime; } try { fieldMap.Property.SetValue(dto, propertyValue, null); } catch (Exception ex) { throw new ApplicationException("Could not set property on type {0}. Field: {1}".ToFormat(dto.GetType().Name, fieldMap.ToString()), ex); } } }
public void Visit(BeginMappedProperty instruction) { var parentClarifyGenericMap = _genericStack.Peek(); var key = instruction.Key.Resolve(_services).ToString(); var childModel = new ModelInformation { ModelName = key, ParentProperty = key, AllowEmpty = instruction.AllowEmpty }; var clarifyGenericMap = new ClarifyGenericMapEntry { ClarifyGeneric = parentClarifyGenericMap.ClarifyGeneric, Model = childModel }; parentClarifyGenericMap.AddChildGenericMap(clarifyGenericMap); _genericStack.Push(clarifyGenericMap); _modelStack.Push(childModel); }
private PaginationResult <MODEL> assemble(ClarifyGenericMapEntry rootGenericMap, IPaginationRequest paginationRequest) { var result = new PaginationResult <MODEL>(); var rootClarifyGeneric = rootGenericMap.ClarifyGeneric; //setup SDK generic for PaginationRequest if necessary if (paginationRequest != null) { result.CurrentPage = paginationRequest.CurrentPage; result.PageSize = paginationRequest.PageSize; rootClarifyGeneric.MaximumRows = 1; //hack! what if query has only one result? rootClarifyGeneric.MaximumRowsExceeded += (sender, args) => { args.RowsToReturn = paginationRequest.CurrentPage * paginationRequest.PageSize; result.TotalRecordCount = args.TotalPossibleRows; }; } rootClarifyGeneric.DataSet.Query(rootClarifyGeneric); traverseGenericsPopulatingSubRootMaps(rootGenericMap); var records = rootGenericMap.ClarifyGeneric.DataRows(); //take the results and constrain them to the requested page if (paginationRequest != null) { var startRow = (paginationRequest.CurrentPage - 1) * paginationRequest.PageSize; records = records.Skip(startRow).Take(paginationRequest.PageSize); } result.Models = createDtosForMap(rootGenericMap, records); return(result); }
private void populateDTOWithFieldValues(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, object dto) { foreach (var fieldMap in genericMap.FieldMaps) { if (fieldMap.Property == null) { continue; } var propertyValue = GetFieldValueForRecord(fieldMap, record); if (propertyValue is string && fieldMap.ShouldEncode) { propertyValue = _assemblerResultEncoder.Encode((string)propertyValue); } if (fieldMap.Property.PropertyType == typeof(int)) { propertyValue = Convert.ToInt32(propertyValue); } //if(fieldMap.Property.PropertyType == typeof(DateTime)) //{ // propertyValue = _timezoneService.ConvertToUserTimeZone(Convert.ToDateTime(propertyValue)); //} try { fieldMap.Property.SetValue(dto, propertyValue, null); } catch (Exception ex) { throw new ApplicationException("Could not set property on type {0}. Field: {1}".ToFormat(dto.GetType().Name, fieldMap.ToString()), ex); } } }
private ModelData[] createDtosForMap(ClarifyGenericMapEntry genericMap, IEnumerable <ClarifyDataRow> records) { var rows = new List <ModelData>(); foreach (var record in records) { var row = new ModelData { Name = genericMap.Model.ModelName, Entity = genericMap.Entity }; populateDTOForGenericRecord(genericMap, record, row); genericMap.Tags.Each(_ => row.AddTag(_)); if (!row.Has("entity") && genericMap.Entity.IsNotEmpty()) { row["entity"] = genericMap.Entity; } rows.Add(row); } return(rows.ToArray()); }
private void populateDTOWithFieldValues(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, ModelData model) { populateDataWithFieldValues(genericMap.FieldMaps, record, model); populateDataWithFieldValues(genericMap.Model.FieldMaps, record, model); }
private PaginationResult <MODEL> assembleWithFilter(Filter filter, ClarifyGenericMapEntry rootGenericMap, IPaginationRequest paginationRequest) { rootGenericMap.ClarifyGeneric.Filter.AddFilter(filter); return(assembleWithSortOverrides(rootGenericMap, paginationRequest)); }