コード例 #1
0
ファイル: UpdateNode.cs プロジェクト: loubo/sones
        private void ProcessAttributeAssignOrUpdateList(IVertexType vertexType, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken, AttributeAssignOrUpdateList attributeAssignOrUpdateList, ref RequestUpdate result)
        {
            Type myRequestedType;

            switch (attributeAssignOrUpdateList.CollectionDefinition.CollectionType)
            {
                case CollectionType.Set:

                    #region set

                    if (((TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition).All(_ => _.Value is ValueDefinition))
                    {
                        #region base-set

                        //has to be list of comparables
                        SetCollectionWrapper setWrapper = new SetCollectionWrapper();

                        if (vertexType.HasProperty(attributeAssignOrUpdateList.AttributeIDChain.ContentString))
                        {
                            myRequestedType = ((IPropertyDefinition)vertexType.GetAttributeDefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString)).BaseType;
                        }
                        else
                        {
                            myRequestedType = typeof(String);
                        }

                        foreach (var aTupleElement in (TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition)
                        {
                            setWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType));
                        }

                        result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, setWrapper);

                        #endregion
                    }
                    else
                    {
                        #region edge-set

                        EdgePredefinition edgeDefinition = new EdgePredefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString);

                        if (!vertexType.HasAttribute(attributeAssignOrUpdateList.AttributeIDChain.ContentString))
                        {
                            throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.", vertexType.Name, attributeAssignOrUpdateList.AttributeIDChain.ContentString));
                        }

                        IAttributeDefinition attribute =  vertexType.GetAttributeDefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString);
                        foreach (var aTupleElement in (TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition)
                        {

                            if (aTupleElement.Value is BinaryExpressionDefinition)
                            {
                                #region BinaryExpressionDefinition

                                var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                                foreach (var aVertex in ProcessBinaryExpression(
                                    (BinaryExpressionDefinition)aTupleElement.Value,
                                    myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType))
                                {
                                    var inneredge = new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID);

                                    foreach (var aStructuredProperty in aTupleElement.Parameters)
                                    {
                                        inneredge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                                    }

                                    edgeDefinition.AddEdge(inneredge);
                                }

                                #endregion
                            }
                            else
                            {
                                throw new NotImplementedQLException("TODO");
                            }
                        }

                        if (attributeAssignOrUpdateList.Assign)
                        {
                            result.UpdateEdge(edgeDefinition);
                        }
                        else
                        {
                            result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, edgeDefinition);
                        }

                        #endregion
                    }
                    #endregion

                    return;
                case CollectionType.List:

                    #region list

                    //has to be list of comparables
                    ListCollectionWrapper listWrapper = new ListCollectionWrapper();

                    if (vertexType.HasProperty(attributeAssignOrUpdateList.AttributeIDChain.ContentString))
                    {
                        myRequestedType = ((IPropertyDefinition)vertexType.GetAttributeDefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString)).BaseType;
                    }
                    else
                    {
                        myRequestedType = typeof(String);
                    }

                    foreach (var aTupleElement in (TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition)
                    {
                        listWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType));
                    }

                    result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, listWrapper);

                    #endregion

                    return;
                case CollectionType.SetOfUUIDs:

                    #region SetOfUUIDs

                    EdgePredefinition anotheredgeDefinition = new EdgePredefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString);

                    foreach (var aTupleElement in ((VertexTypeVertexIDCollectionNode)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition).Elements)
                    {
                        foreach (var aVertexIDTuple in aTupleElement.VertexIDs)
                        {
                            var innerEdge = new EdgePredefinition();

                            foreach (var aStructuredProperty in aVertexIDTuple.Item2)
                            {
                                innerEdge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                            }

                            innerEdge.AddVertexID(aTupleElement.ReferencedVertexTypeName, aVertexIDTuple.Item1);

                            anotheredgeDefinition.AddEdge(innerEdge);
                        }
                    }

                    result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, anotheredgeDefinition);

                    #endregion

                    return;
                default:
                    return;
            }
        }
コード例 #2
0
ファイル: UpdateNode.cs プロジェクト: loubo/sones
        private void ProcessAttributeAssignOrUpdateSetRef(IVertexType vertexType, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken, AttributeAssignOrUpdateSetRef attributeAssignOrUpdateSetRef, ref RequestUpdate result)
        {
            #region SetRefNode

            var edgeDefinition = new EdgePredefinition(attributeAssignOrUpdateSetRef.AttributeIDChain.ContentString);

            if (attributeAssignOrUpdateSetRef.SetRefDefinition.IsREFUUID)
            {
                #region direct vertex ids

                foreach (var aTupleElement in attributeAssignOrUpdateSetRef.SetRefDefinition.TupleDefinition)
                {
                    if (aTupleElement.Value is ValueDefinition)
                    {
                        #region ValueDefinition

                        foreach (var aProperty in aTupleElement.Parameters)
                        {
                            edgeDefinition.AddUnknownProperty(aProperty.Key, aProperty.Value);
                        }

                        edgeDefinition.AddVertexID(
                            attributeAssignOrUpdateSetRef.SetRefDefinition.ReferencedVertexType,
                            Convert.ToInt64(((ValueDefinition)aTupleElement.Value).Value));

                        #endregion
                    }
                    else
                    {
                        throw new NotImplementedQLException("TODO");
                    }
                }

                result.UpdateEdge(edgeDefinition);

                #endregion
            }
            else
            {
                #region expression

                if (!vertexType.HasAttribute(attributeAssignOrUpdateSetRef.AttributeIDChain.ContentString))
                {
                    throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.", vertexType.Name, attributeAssignOrUpdateSetRef.AttributeIDChain.ContentString));
                }
                IAttributeDefinition attribute = vertexType.GetAttributeDefinition(attributeAssignOrUpdateSetRef.AttributeIDChain.ContentString);

                foreach (var aTupleElement in attributeAssignOrUpdateSetRef.SetRefDefinition.TupleDefinition)
                {
                    if (aTupleElement.Value is BinaryExpressionDefinition)
                    {
                        #region BinaryExpressionDefinition

                        var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                        var vertexIDs = ProcessBinaryExpression(
                            (BinaryExpressionDefinition)aTupleElement.Value,
                            myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType).ToList();

                        if (vertexIDs.Count > 1)
                        {
                            throw new ReferenceAssignmentExpectedException(String.Format("It is not possible to create a single edge pointing to {0} vertices", vertexIDs.Count));
                        }

                        var inneredge = new EdgePredefinition();

                        foreach (var aStructuredProperty in aTupleElement.Parameters)
                        {
                            edgeDefinition.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                        }

                        edgeDefinition.AddVertexID(vertexIDs.FirstOrDefault().VertexTypeID, vertexIDs.FirstOrDefault().VertexID);

                        #endregion
                    }
                    else
                    {
                        throw new NotImplementedQLException("");
                    }
                }

                #endregion

                result.UpdateEdge(edgeDefinition);

                return;
            }

            #endregion
        }
コード例 #3
0
ファイル: ServiceRequestFactory.cs プロジェクト: cosh/sones
        public static RequestUpdate MakeRequestUpdate(ServiceUpdateChangeset myUpdateChangeset)
        {
            #region PreRequest

            RequestGetVertices PreRequest = null;
            if (myUpdateChangeset.Expression == null)
            {
                if (myUpdateChangeset.VertexTypeName != null)
                {
                    PreRequest = MakeRequestGetVertices(myUpdateChangeset.VertexTypeName, myUpdateChangeset.VertexIDs);
                }
                else
                {
                    PreRequest = MakeRequestGetVertices(myUpdateChangeset.VertexTypeID, myUpdateChangeset.VertexIDs);
                }
            }
            else
            {
                PreRequest = MakeRequestGetVertices(myUpdateChangeset.Expression);
            }

            RequestUpdate Request = new RequestUpdate(PreRequest);

            if (!String.IsNullOrEmpty(myUpdateChangeset.Comment))
                Request.UpdateComment(myUpdateChangeset.Comment);

            if (!String.IsNullOrEmpty(myUpdateChangeset.Edition))
                Request.UpdateEdition(myUpdateChangeset.Edition);

            #endregion

            #region element collection

            if (myUpdateChangeset.AddedElementsToCollectionProperties != null)
            {
                foreach (var element in myUpdateChangeset.AddedElementsToCollectionProperties)
                {
                    Request.AddElementsToCollection(element.Key, element.Value);
                }
            }

            if (myUpdateChangeset.RemovedElementsFromCollectionProperties != null)
            {
                foreach (var element in myUpdateChangeset.RemovedElementsFromCollectionProperties)
                {
                    Request.RemoveElementsFromCollection(element.Key, element.Value);
                }
            }

            if (myUpdateChangeset.AddedElementsToCollectionEdges != null)
            {
                foreach (var element in myUpdateChangeset.AddedElementsToCollectionEdges)
                {
                    Request.AddElementsToCollection(element.Key, element.Value.ToEdgePredefinition());
                }
            }

            if (myUpdateChangeset.RemovedElementsFromCollectionEdges != null)
            {
                foreach (var element in myUpdateChangeset.RemovedElementsFromCollectionEdges)
                {
                    Request.RemoveElementsFromCollection(element.Key, element.Value.ToEdgePredefinition());
                }
            }

            #endregion

            #region Properties

            if (myUpdateChangeset.UpdatedStructuredProperties != null)
            {
                foreach (var item in myUpdateChangeset.UpdatedStructuredProperties)
                {
                    Request.UpdateStructuredProperty(item.Key, item.Value);
                }
            }

            if (myUpdateChangeset.UpdatedUnstructuredProperties != null)
            {
                foreach (var item in myUpdateChangeset.UpdatedUnstructuredProperties)
                {
                    Request.UpdateUnstructuredProperty(item.Key, item.Value);
                }
            }

            if (myUpdateChangeset.UpdatedUnknownProperties != null)
            {
                foreach (var item in myUpdateChangeset.UpdatedUnknownProperties)
                {
                    Request.UpdateUnknownProperty(item.Key, item.Value);
                }
            }

            #endregion

            #region Update Edges

            if (myUpdateChangeset.UpdatedOutgoingEdges != null)
            {
                foreach (var Edge in myUpdateChangeset.UpdatedOutgoingEdges)
                {
                    Request.UpdateEdge(Edge.ToEdgePredefinition());
                }
            }

            if (myUpdateChangeset.UpdateOutgoingEdgesProperties != null)
            {
                foreach (var Edge in myUpdateChangeset.UpdateOutgoingEdgesProperties)
                {
                    Request.UpdateEdge(Edge.ToSingleEdgeUpdateDefinition());
                }
            }

            #endregion

            if (myUpdateChangeset.RemovedAttributes != null)
            {
                foreach (var item in myUpdateChangeset.RemovedAttributes)
                {
                    Request.RemoveAttribute(item);
                }
            }

            return Request;
        }