Beispiel #1
0
        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;
        }
Beispiel #2
0
        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;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Reads an edge information from the GraphML File and inserts
        /// the edge in the GraphDB by altering the existing source vertex.
        /// 
        /// Currently only the "weight" attribute will be considered and
        /// has to be annotated correctly (see class documentation).
        /// </summary>
        /// <param name='myReader'>
        /// XmlReader
        /// </param>
        private void ReadEdge(XmlReader myReader)
        {
            #region read edge data

            var sourceID = ReadVertexID(myReader, GraphMLTokens.SOURCE);
            var targetID = ReadVertexID(myReader, GraphMLTokens.TARGET);

            if(!_VertexIDMapper.ContainsKey(sourceID) || !_VertexIDMapper.ContainsKey(targetID))
            {
                throw new InvalidDataException(String.Format(
                    "Source or Target vertexID for edge ({0},{1}) doesn't exist",
                    sourceID,
                    targetID));
            }

            // get the weight
            var edgeWeight = ReadEdgeWeight(myReader);

            #endregion

            #region create edge (update vertex)

            var hyperEdge = new EdgePredefinition(_EdgeTypeName);
            hyperEdge.AddEdge(new EdgePredefinition()
                .AddVertexID(_VertexTypeName, _VertexIDMapper[targetID])
                .AddUnknownProperty(
                    GraphMLTokens.EDGE_WEIGHT,
                    Convert.ChangeType(edgeWeight, typeof(String), CultureInfo.GetCultureInfo("en-us"))
                ));

            var requestUpdate = new RequestUpdate(new RequestGetVertices(_VertexTypeName, new List<long>() { _VertexIDMapper[sourceID] }));
            requestUpdate.AddElementsToCollection(_EdgeTypeName, hyperEdge);

            // process the update
            _GraphDB.Update<IEnumerable<IVertex>>(
                _SecurityToken,
                _TransactionToken,
                requestUpdate,
                (stats, v) => v
                );

            _EdgeCount++;

            #endregion
        }