Beispiel #1
0
        private void FillAddQuery(SingleQuery path,
                                  JToken value,
                                  ModelElementObjectBase classDescription,
                                  IList <ModelElementObjectBase> allClassDescriptions)
        {
            var children = classDescription.Children.ToList();

            var pivot = ParserHelper.GetPivot(ParserHelper.TreeNodeTypeToPivot[classDescription.ModelElementType]);

            foreach (var property in pivot.GetAllCommonProperties())
            {
                var propertyToken = value[property];
                if (propertyToken != null)
                {
                    if (propertyToken.Type == JTokenType.Null)
                    {
                        continue;
                    }

                    path.AddArgument(
                        x => x.ArgumentSubjectQuery  = SingleQuery.InitiateQuery().AddProperty(property),
                        x => x.ArgumentValueConstant = propertyToken.ToPrimitiveObject());
                }
            }

            foreach (var propertyDescription in children.Where(x => x.ModelElementType == TreeNodeType.Vx))
            {
                var propertyToken = value[propertyDescription.DisplayText];
                if (propertyToken != null && propertyToken.Type != JTokenType.Null)
                {
                    //todo: composite vx

                    var vxTypeDescription = allClassDescriptions.FirstOrDefault(x => x.ModelDefinitionId == propertyDescription.LinkedModelDefinitionId);

                    if (vxTypeDescription != null)
                    {
                        throw new InvalidOperationException("Vx must not be a complex object for addition");
                    }

                    path.AddArgument(
                        x => x.ArgumentSubjectQuery = SingleQuery.InitiateQuery()
                                                      .AddProperty("vx")
                                                      .SetPivot(PivotType.Value, propertyDescription.Code),
                        x => x.ArgumentValueConstant = propertyToken.ToPrimitiveObject());
                }
            }

            foreach (var propertyDescription in children.Where(x => x.ModelElementType == TreeNodeType.Md))
            {
                var arrayPropertyToken = value[propertyDescription.DisplayText] as JArray;

                if (arrayPropertyToken != null)
                {
                    foreach (var propertyToken in arrayPropertyToken)
                    {
                        var add = SingleQuery.InitiateQuery()
                                  .AddCollection("md")
                                  .SetPivot(PivotType.MasterData, propertyDescription.Code, (string)propertyToken["capacity"])
                                  .MethodAdd()
                                  .AddArgument(
                            x => x.ArgumentSubjectQuery  = SingleQuery.InitiateQuery().AddProperty("id"),
                            x => x.ArgumentValueConstant = (string)propertyToken["id"]);

                        path.AddArgument(x => x.ArgumentValueQuery = add);
                    }
                }
            }

            foreach (var propertyDescription in children.Where(x => x.ModelElementType == TreeNodeType.Ae))
            {
                var aeTypeDescription  = allClassDescriptions.FirstOrDefault(x => x.ModelDefinitionId == propertyDescription.LinkedViewModelId);
                var arrayPropertyToken = value[propertyDescription.DisplayText] as JArray;

                if (aeTypeDescription != null && arrayPropertyToken != null)
                {
                    foreach (var propertyToken in arrayPropertyToken)
                    {
                        var add = SingleQuery.InitiateQuery()
                                  .AddCollection("ae")
                                  .SetPivot(PivotType.Attributes, propertyDescription.Code)
                                  .MethodAdd();

                        aeTypeDescription = new ModelElementObjectBase(aeTypeDescription);
                        aeTypeDescription.ModelElementType = TreeNodeType.Ae;

                        FillAddQuery(add, propertyToken, aeTypeDescription, allClassDescriptions);

                        path.AddArgument(x => x.ArgumentValueQuery = add);
                    }
                }
            }

            foreach (var propertyDescription in children.Where(x => x.ModelElementType == TreeNodeType.Ts))
            {
                var eeTypeDescription = allClassDescriptions.FirstOrDefault(x => x.ModelDefinitionId == propertyDescription.LinkedModelDefinitionId);
                var propertyToken     = value[propertyDescription.DisplayText];

                if (eeTypeDescription != null && propertyToken != null)
                {
                    var add = path.MakeCopy()
                              .MethodAdd()
                              .SetPivot(PivotType.Task, propertyDescription.Code, (string)propertyToken["code"]);

                    FillSetQuery(add, propertyToken, eeTypeDescription, allClassDescriptions, false);

                    path.AddArgument(x => x.ArgumentValueQuery = add);
                }
            }
        }
Beispiel #2
0
        /// <summary> Generates queries for modification info </summary>
        /// <param name="singleQuery"></param>
        /// <param name="modificationInfo"></param>
        /// <param name="isTransactionCreation"></param>
        /// <returns></returns>
        public static List <SingleQuery> GetModificationInfoQueries(this SingleQuery singleQuery, JToken modificationInfo, bool isTransactionCreation)
        {
            var result = new List <SingleQuery>();

            var addMethodNodes = singleQuery.NodesList.Where(x => x.MethodType == QueryMethodType.Add).ToList();
            var setMethodNodes = singleQuery.NodesList.Where(x => x.MethodType == QueryMethodType.Set).ToList();

            foreach (var methodNode in setMethodNodes)
            {
                for (var queryNodeItem = singleQuery.NodesList.First; queryNodeItem.Value != methodNode; queryNodeItem = queryNodeItem.Next)
                {
                    var queryNode      = queryNodeItem.Value;
                    var newSingleQuery = singleQuery.MakeCopyUntil(queryNode);
                    newSingleQuery.AddMethod(QueryMethodType.Set)
                    .AddArgument(x => x.ArgumentSubjectQuery  = SingleQuery.CreateQuery.AddProperty(ObjectHelper.UpdatedInfoPropName),
                                 x => x.ArgumentValueConstant = modificationInfo.ToString());

                    if (isTransactionCreation)
                    {
                        newSingleQuery
                        .AddArgument(x => x.ArgumentSubjectQuery  = SingleQuery.CreateQuery.AddProperty(ObjectHelper.CreatedInfoPropName),
                                     x => x.ArgumentValueConstant = modificationInfo.ToString());
                    }

                    result.Add(newSingleQuery);
                }
            }

            foreach (var methodNode in addMethodNodes)
            {
                foreach (var queryNode in singleQuery.NodesList)
                {
                    SingleQuery newSingleQuery = null;
                    if (queryNode == methodNode)
                    {
                        var id =
                            methodNode.Arguments.Where(
                                x => x.ArgumentSubjectQuery.NodesList.Last.Value.Name == ObjectHelper.IdPropName)
                            .Select(x => x.ArgumentValueConstant)
                            .SingleOrDefault();

                        // Somehow Id is empty or absent...
                        if (id == null)
                        {
                            continue;
                        }

                        newSingleQuery = singleQuery.MakeCopyUntil(queryNode, false);

                        var pivotData = methodNode.PivotData;
                        newSingleQuery.AddCollection(pivotData.PivotDefinition.Type.ToString())
                        .SetPivot(pivotData.PivotDefinition.Type, pivotData.MainValue, pivotData.SecondaryValues.ToArray());

                        newSingleQuery.AddCriteriaGroup(CriteriaAppendType.And)
                        .AddCriteria(SingleQuery.CreateQuery.AddProperty(ObjectHelper.IdPropName), CriteriaComparator.Eq, id);

                        newSingleQuery.AddMethod(QueryMethodType.Set)
                        .AddArgument(x => x.ArgumentSubjectQuery  = SingleQuery.CreateQuery.AddProperty(ObjectHelper.CreatedInfoPropName),
                                     x => x.ArgumentValueConstant = modificationInfo.ToString());

                        result.Add(newSingleQuery);
                        break;
                    }

                    newSingleQuery = singleQuery.MakeCopyUntil(queryNode);
                    newSingleQuery.AddMethod(QueryMethodType.Set)
                    .AddArgument(x => x.ArgumentSubjectQuery  = SingleQuery.CreateQuery.AddProperty(ObjectHelper.UpdatedInfoPropName),
                                 x => x.ArgumentValueConstant = modificationInfo.ToString());

                    if (isTransactionCreation)
                    {
                        newSingleQuery
                        .AddArgument(x => x.ArgumentSubjectQuery  = SingleQuery.CreateQuery.AddProperty(ObjectHelper.CreatedInfoPropName),
                                     x => x.ArgumentValueConstant = modificationInfo.ToString());
                    }

                    result.Add(newSingleQuery);
                }
            }

            return(result);
        }