internal ServiceUpdateChangeset(RequestUpdate myRequestUpdate)
        {
            this.Comment = myRequestUpdate.UpdatedComment;
            this.Edition = myRequestUpdate.UpdatedEdition;

            this.AddedElementsToCollectionProperties = new Dictionary<string,List<object>>();
            foreach(var item in myRequestUpdate.AddedElementsToCollectionProperties)
                this.AddedElementsToCollectionProperties.Add(item.Key, item.Value.Select(x => (object)x).ToList());

            this.RemovedElementsFromCollectionProperties = new Dictionary<string,List<object>>();
            foreach(var item in myRequestUpdate.RemovedElementsFromCollectionProperties)
                this.RemovedElementsFromCollectionProperties.Add(item.Key, item.Value.Select(x => (object)x).ToList());

            this.AddedElementsToCollectionEdges = new Dictionary<string,ServiceEdgePredefinition>();
            foreach (var item in myRequestUpdate.AddedElementsToCollectionEdges)
                this.AddedElementsToCollectionEdges.Add(item.Key, new ServiceEdgePredefinition(item.Value));

            this.RemovedElementsFromCollectionEdges = new Dictionary<string,ServiceEdgePredefinition>();
            foreach (var item in myRequestUpdate.RemovedElementsFromCollectionEdges)
                this.RemovedElementsFromCollectionEdges.Add(item.Key, new ServiceEdgePredefinition(item.Value));

            this.UpdatedUnstructuredProperties = myRequestUpdate.UpdatedUnstructuredProperties.ToDictionary(k => k.Key, v => v.Value);
            this.UpdatedStructuredProperties = myRequestUpdate.UpdatedStructuredProperties.ToDictionary(k => k.Key, v => (object)v.Value);

            this.UpdatedOutgoingEdges = myRequestUpdate.UpdateOutgoingEdges.Select(x => new ServiceEdgePredefinition(x)).ToList();
            this.UpdateOutgoingEdgesProperties = myRequestUpdate.UpdateOutgoingEdgesProperties.Select(x => new ServiceSingleEdgeUpdateDefinition(x)).ToList();

            this.UpdatedUnknownProperties = myRequestUpdate.UpdatedUnknownProperties.ToDictionary(k => k.Key, v => v.Value);
            this.RemovedAttributes = myRequestUpdate.RemovedAttributes;
        }
        internal ServiceUpdateChangeset(RequestUpdate myRequestUpdate)
        {
            this.VertexTypeName = myRequestUpdate.GetVerticesRequest.VertexTypeName;
            this.VertexTypeID = myRequestUpdate.GetVerticesRequest.VertexTypeID;
            this.VertexIDs = myRequestUpdate.GetVerticesRequest.VertexIDs.ToList();
            this.Expression = (myRequestUpdate.GetVerticesRequest.Expression == null) ? null : ConvertHelper.ToServiceExpression(myRequestUpdate.GetVerticesRequest.Expression);

            this.Comment = myRequestUpdate.UpdatedComment;
            this.Edition = myRequestUpdate.UpdatedEdition;

            if (myRequestUpdate.AddedElementsToCollectionProperties != null)
            {
                this.AddedElementsToCollectionProperties = new Dictionary<string, List<object>>();
                foreach (var item in myRequestUpdate.AddedElementsToCollectionProperties)
                    this.AddedElementsToCollectionProperties.Add(item.Key, item.Value.Select(x => (object)x).ToList());
            }

            if (myRequestUpdate.RemovedElementsFromCollectionProperties != null)
            {
                this.RemovedElementsFromCollectionProperties = new Dictionary<string, List<object>>();
                foreach (var item in myRequestUpdate.RemovedElementsFromCollectionProperties)
                    this.RemovedElementsFromCollectionProperties.Add(item.Key, item.Value.Select(x => (object)x).ToList());
            }

            if (myRequestUpdate.AddedElementsToCollectionEdges != null)
            {
                this.AddedElementsToCollectionEdges = new Dictionary<string, ServiceEdgePredefinition>();
                foreach (var item in myRequestUpdate.AddedElementsToCollectionEdges)
                    this.AddedElementsToCollectionEdges.Add(item.Key, new ServiceEdgePredefinition(item.Value));
            }

            if (myRequestUpdate.RemovedElementsFromCollectionEdges != null)
            {
                this.RemovedElementsFromCollectionEdges = new Dictionary<string, ServiceEdgePredefinition>();
                foreach (var item in myRequestUpdate.RemovedElementsFromCollectionEdges)
                    this.RemovedElementsFromCollectionEdges.Add(item.Key, new ServiceEdgePredefinition(item.Value));
            }
            

            this.UpdatedUnstructuredProperties = (myRequestUpdate.UpdatedUnstructuredProperties == null)
                ? null : myRequestUpdate.UpdatedUnstructuredProperties.ToDictionary(k => k.Key, v => v.Value);
            this.UpdatedStructuredProperties = (myRequestUpdate.UpdatedStructuredProperties == null)
                ? null : myRequestUpdate.UpdatedStructuredProperties.ToDictionary(k => k.Key, v => (object)v.Value);

            this.UpdatedOutgoingEdges = (myRequestUpdate.UpdateOutgoingEdges == null)
                ? null : myRequestUpdate.UpdateOutgoingEdges.Select(x => new ServiceEdgePredefinition(x)).ToList();
            this.UpdateOutgoingEdgesProperties = (myRequestUpdate.UpdateOutgoingEdgesProperties == null)
                ? null : myRequestUpdate.UpdateOutgoingEdgesProperties.Select(x => new ServiceSingleEdgeUpdateDefinition(x)).ToList();

            this.UpdatedUnknownProperties = (myRequestUpdate.UpdatedUnknownProperties == null)
                ? null : myRequestUpdate.UpdatedUnknownProperties.ToDictionary(k => k.Key, v => v.Value);
            this.RemovedAttributes = myRequestUpdate.RemovedAttributes;
        }
Example #3
0
 private void ProcessUpdate(IVertexType vertexType, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken, AAttributeAssignOrUpdateOrRemove aUpdate, ref RequestUpdate result)
 {
     if (aUpdate is AttributeAssignOrUpdateValue)
     {
         ProcessAttributeAssignOrUpdateValue((AttributeAssignOrUpdateValue)aUpdate, ref result);
     }
     else if (aUpdate is AttributeAssignOrUpdateList)
     {
         ProcessAttributeAssignOrUpdateList(vertexType, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, (AttributeAssignOrUpdateList)aUpdate, ref result);
     }
     else if (aUpdate is AttributeAssignOrUpdateSetRef)
     {
         ProcessAttributeAssignOrUpdateSetRef(vertexType, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, (AttributeAssignOrUpdateSetRef)aUpdate, ref result);
     }
     else if (aUpdate is AttributeRemove)
     {
         foreach (var aToBeRemovedAttribute in ((AttributeRemove)aUpdate).ToBeRemovedAttributes)
         {
             result.RemoveAttribute(aToBeRemovedAttribute);
         }
     }
     else if (aUpdate is AttributeRemoveList)
     {
         ProcessAttributeRemoveList(vertexType, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, (AttributeRemoveList)aUpdate, ref result);
     }
     else
     {
         throw new NotImplementedQLException("");
     }
 }
Example #4
0
 private void ProcessListOfUpdates(IVertexType vertexType, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken, ref RequestUpdate result)
 {
     foreach (var aUpdate in _listOfUpdates)
     {
         ProcessUpdate(vertexType, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, aUpdate, ref result);
     }
 }
Example #5
0
        private void ProcessAttributeRemoveList(IVertexType vertexType, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken, AttributeRemoveList attributeRemoveList, ref RequestUpdate result)
        {
            if (attributeRemoveList.TupleDefinition is VertexTypeVertexIDCollectionNode)
            {
                #region setofUUIDs

                var edgedef = new EdgePredefinition(attributeRemoveList.AttributeName);

                List<EdgePredefinition> toBeRemovedEdges = new List<EdgePredefinition>();

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

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

                        edgedef.AddEdge(innerEdge);
                    }
                }

                result.RemoveElementsFromCollection(attributeRemoveList.AttributeName, edgedef);

                #endregion
            }
            else if (attributeRemoveList.TupleDefinition is TupleDefinition)
            {
                if (((TupleDefinition)attributeRemoveList.TupleDefinition).All(_ => _.Value is ValueDefinition))
                {
                    #region base-set

                    //has to be list of comparables
                    ListCollectionWrapper listWrapper = new ListCollectionWrapper();
                    Type myRequestedType;
                    if (vertexType.HasProperty(attributeRemoveList.AttributeIDChain.ContentString))
                    {
                        myRequestedType = ((IPropertyDefinition)vertexType.GetAttributeDefinition(attributeRemoveList.AttributeIDChain.ContentString)).BaseType;
                    }
                    else
                    {
                        myRequestedType = typeof(String);
                    }

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

                    result.RemoveElementsFromCollection(attributeRemoveList.AttributeIDChain.ContentString, listWrapper);

                    #endregion
                }
                else
                {
                    #region binaryExpression

                    Dictionary<String, EdgePredefinition> toBeRemovedEdges = new Dictionary<String, EdgePredefinition>();

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

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

                            IAttributeDefinition attribute = vertexType.GetAttributeDefinition(attributeRemoveList.AttributeName);

                            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));
                            }

                            EdgePredefinition outValue = null;

                            if (toBeRemovedEdges.TryGetValue(attributeRemoveList.AttributeName, out outValue))
                            {
                                foreach (var aVertex in vertexIDs)
                                {
                                    outValue.AddEdge(new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID));
                                }
                            }
                            else
                            {
                                EdgePredefinition edge = new EdgePredefinition(attributeRemoveList.AttributeName);

                                foreach (var aVertex in vertexIDs)
                                {
                                    edge.AddEdge(new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID));
                                }

                                toBeRemovedEdges.Add(attributeRemoveList.AttributeName, edge);
                            }

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

                    foreach (var item in toBeRemovedEdges)
                    {
                        result.RemoveElementsFromCollection(item.Key, item.Value);
                    }

                    #endregion
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Example #6
0
 private void ProcessAttributeAssignOrUpdateValue(AttributeAssignOrUpdateValue attributeAssignOrUpdateValue, ref RequestUpdate result)
 {
     result.UpdateUnknownProperty(attributeAssignOrUpdateValue.AttributeIDChain.ContentString , attributeAssignOrUpdateValue.Value);
 }
Example #7
0
        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
        }
Example #8
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;
            }
        }
Example #9
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
        }
Example #10
0
 public IEnumerable<IVertex> UpdateVertices(RequestUpdate myUpdate, TransactionToken myTransaction, SecurityToken mySecurity)
 {
     return null;
 }
Example #11
0
 /// <summary>
 /// Updates a set of vertices and returns them.
 /// </summary>
 /// <param name="myUpdate">The request that represents the update.</param>
 /// <param name="Int64">A transaction token for this operation.</param>
 /// <param name="SecurityToken">A security token for this operation.</param>
 /// <returns>The updated vertivess.</returns>
 public abstract IEnumerable<IVertex> UpdateVertices(RequestUpdate myUpdate, Int64 myTransaction, SecurityToken mySecurity);
Example #12
0
 public static RequestUpdate MakeRequestUpdateBinary(Int64 myVertexTypeID, Int64 myVertexID, String myPropertyName, Stream myStream)
 {
     var idList = new List<Int64>();
     idList.Add(myVertexID);
     var Request = new RequestUpdate(new RequestGetVertices(myVertexTypeID, idList));
     Request.UpdateBinaryProperty(myPropertyName, myStream);
     return Request;
 }
Example #13
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;
        }
Example #14
0
        public TResult Update <TResult>(sones.Library.Commons.Security.SecurityToken mySecurityToken, long myTransactionID, sones.GraphDB.Request.RequestUpdate myRequestUpdate, sones.GraphDB.Request.Converter.UpdateResultConverter <TResult> myOutputconverter)
        {
            Stopwatch RunningTime = Stopwatch.StartNew();
            var       svcVertices = _GraphDSService.Update(
                mySecurityToken,
                myTransactionID,
                new ServiceUpdateChangeset(myRequestUpdate));
            var vertices = svcVertices.Select(x => new RemoteVertex(x, this));

            RunningTime.Stop();
            return(myOutputconverter(new RequestStatistics(new TimeSpan(RunningTime.ElapsedTicks)), vertices));
        }
Example #15
0
        private Tuple<long?, String, VertexUpdateDefinition> CreateVertexUpdateDefinition(
                                                                IVertex myVertex,
                                                                IVertexType myVertexType,
                                                                RequestUpdate myUpdate,
                                                                IPropertyProvider myPropertyCopy,
                                                                Int64 myTransaction,
                                                                SecurityToken mySecurity)
        {

            #region get removes

            List<long> toBeDeletedSingle = null;
            List<long> toBeDeletedHyper = null;
            List<long> toBeDeletedStructured = null;
            List<String> toBeDeletedUnstructured = null;
            List<long> toBeDeletedBinaries = null;

            if (myUpdate.RemovedAttributes != null)
            {
                #region remove each defined attribute

                foreach (var name in myUpdate.RemovedAttributes)
                {
                    if (myVertexType.HasAttribute(name))
                    {
                        var attr = myVertexType.GetAttributeDefinition(name);

                        switch (attr.Kind)
                        {
                            case AttributeType.Property:

                                if ((attr as IPropertyDefinition).IsMandatory)
                                    throw new MandatoryConstraintViolationException(attr.Name);

                                toBeDeletedStructured = toBeDeletedStructured ?? new List<long>();
                                toBeDeletedStructured.Add(attr.ID);
                                break;

                            case AttributeType.BinaryProperty:
                                toBeDeletedBinaries = toBeDeletedBinaries ?? new List<long>();
                                toBeDeletedBinaries.Add(attr.ID);
                                break;

                            case AttributeType.IncomingEdge:
                                //TODO: a better exception here.
                                throw new Exception("The edges on an incoming edge attribute can not be removed.");

                            case AttributeType.OutgoingEdge:
                                switch ((attr as IOutgoingEdgeDefinition).Multiplicity)
                                {
                                    case EdgeMultiplicity.HyperEdge:
                                    case EdgeMultiplicity.MultiEdge:
                                        toBeDeletedHyper = toBeDeletedHyper ?? new List<long>();
                                        toBeDeletedHyper.Add(attr.ID);
                                        break;
                                    case EdgeMultiplicity.SingleEdge:
                                        toBeDeletedSingle = toBeDeletedSingle ?? new List<long>();
                                        toBeDeletedSingle.Add(attr.ID);
                                        break;
                                    default:
                                        //TODO a better exception here
                                        throw new Exception("The enumeration EdgeMultiplicity was changed, but not this switch statement.");
                                }
                                break;

                            default:
                                //TODO: a better exception here.
                                throw new Exception("The enumeration AttributeType was updated, but not this switch statement.");
                        }
                    }
                    else
                    {
                        toBeDeletedUnstructured = toBeDeletedUnstructured ?? new List<String>();
                        toBeDeletedUnstructured.Add(name);
                    }
                }

                #endregion
            }

            if (myUpdate.RemovedUnstructuredProperties != null)
            {
                #region remove each unstructured property

                foreach (var name in myUpdate.RemovedUnstructuredProperties)
                {
                    if ((myVertexType.HasAttribute(name)) && (myVertexType.GetAttributeDefinition(name).Kind == AttributeType.Property))
                    {
                        toBeDeletedUnstructured = toBeDeletedUnstructured ?? new List<String>();
                        toBeDeletedUnstructured.Add(name);
                    }
                }

                #endregion
            }

            #endregion

            #region get update definitions

            IDictionary<Int64, HyperEdgeUpdateDefinition> toBeUpdatedHyper = null;
            IDictionary<Int64, SingleEdgeUpdateDefinition> toBeUpdatedSingle = null;
            IDictionary<Int64, IComparable> toBeUpdatedStructured = null;
            IDictionary<String, Object> toBeUpdatedUnstructured = null;
            IDictionary<Int64, StreamAddDefinition> toBeUpdatedBinaries = null;
            long? revision = null;
            string edition = myUpdate.UpdatedEdition;
            string comment = myUpdate.UpdatedComment;

            #region property copy things

            if (myPropertyCopy.StructuredProperties != null)
            {
                toBeUpdatedStructured = new Dictionary<long, IComparable>();
                foreach (var prop in myPropertyCopy.StructuredProperties)
                {
                    var propDef = myVertexType.GetPropertyDefinition(prop.Key);
                    CheckPropertyType(myVertexType.Name, prop.Value, propDef);
                    toBeUpdatedStructured.Add(propDef.ID, prop.Value);
                }
            }

            toBeUpdatedUnstructured = myPropertyCopy.UnstructuredProperties;

            #endregion

            #region binary properties
            if (myUpdate.UpdatedBinaryProperties != null)
            {
                foreach (var prop in myUpdate.UpdatedBinaryProperties)
                {
                    var propDef = myVertexType.GetBinaryPropertyDefinition(prop.Key);

                    toBeUpdatedBinaries = toBeUpdatedBinaries ?? new Dictionary<long, StreamAddDefinition>();
                    toBeUpdatedBinaries.Add(propDef.ID, new StreamAddDefinition(propDef.ID, prop.Value));
                }
            }
            #endregion

            #region collections

            if (myUpdate.AddedElementsToCollectionProperties != null || myUpdate.RemovedElementsFromCollectionProperties != null)
            {
                if (myUpdate.AddedElementsToCollectionProperties != null && myUpdate.RemovedElementsFromCollectionProperties != null)
                {
                    var keys = myUpdate.AddedElementsToCollectionProperties.Keys.Intersect(myUpdate.RemovedElementsFromCollectionProperties.Keys);
                    if (keys.CountIsGreater(0))
                    {
                        //TOTO a better exception here
                        throw new Exception("You can not add and remove items simultaneously on a collection attribute.");
                    }

                    if (myUpdate.AddedElementsToCollectionProperties != null)
                    {
                        foreach (var added in myUpdate.AddedElementsToCollectionProperties)
                        {
                            var propDef = myVertexType.GetPropertyDefinition(added.Key);

                            var hasValue = (propDef == null)
                                ? myVertex.HasUnstructuredProperty(added.Key)
                                : myVertex.HasProperty(propDef.ID);

                            //if it is not ICollectionWrapper something wrong with deserialization
                            var extractedValue = (!hasValue)
                                ? null
                                : (propDef == null)
                                    ? myVertex.GetUnstructuredProperty<ICollectionWrapper>(added.Key)
                                    : (ICollectionWrapper)propDef.GetValue(myVertex);

                            PropertyMultiplicity mult;
                            if (propDef != null)
                            {
                                //check types only for structured properties
                                foreach (var element in added.Value)
                                {
                                    CheckPropertyType(myVertexType.Name, element, propDef);
                                }
                                mult = propDef.Multiplicity;
                            }
                            else
                                mult = (added.Value is SetCollectionWrapper)
                                    ? PropertyMultiplicity.Set
                                    : PropertyMultiplicity.List;


                            var newValue = CreateNewCollectionWrapper(
                                (hasValue)
                                    ? extractedValue.Union(added.Value)
                                    : added.Value,
                                 mult);

                            if (propDef == null)
                            {
                                toBeUpdatedUnstructured = toBeUpdatedUnstructured ?? new Dictionary<String, object>();
                                toBeUpdatedUnstructured.Add(added.Key, newValue);
                            }
                            else
                            {
                                toBeUpdatedStructured = toBeUpdatedStructured ?? new Dictionary<long, IComparable>();
                                toBeUpdatedStructured.Add(propDef.ID, newValue);
                            }

                        }
                    }
                    if (myUpdate.RemovedElementsFromCollectionProperties != null)
                    {
                        foreach (var remove in myUpdate.RemovedElementsFromCollectionProperties)
                        {
                            var propDef = myVertexType.GetPropertyDefinition(remove.Key);

                            var hasValue = (propDef == null)
                                ? myVertex.HasUnstructuredProperty(remove.Key)
                                : myVertex.HasProperty(propDef.ID);

                            //no value, nothing to remove
                            if (!hasValue)
                                continue;

                            //if it is not ICollectionWrapper something wrong with deserialization
                            var extractedValue = (propDef == null)
                                ? myVertex.GetUnstructuredProperty<ICollectionWrapper>(remove.Key)
                                : (ICollectionWrapper)propDef.GetValue(myVertex);

                            PropertyMultiplicity mult = (propDef != null)
                                ? propDef.Multiplicity
                                : (extractedValue is SetCollectionWrapper)
                                    ? PropertyMultiplicity.Set
                                    : PropertyMultiplicity.List;

                            var newValue = CreateNewCollectionWrapper(extractedValue.Except(remove.Value), mult);

                            toBeUpdatedStructured.Add(propDef.ID, newValue);

                            if (propDef == null)
                            {
                                toBeUpdatedUnstructured = toBeUpdatedUnstructured ?? new Dictionary<String, object>();
                                toBeUpdatedUnstructured.Add(remove.Key, newValue);
                            }
                            else
                            {
                                toBeUpdatedStructured = toBeUpdatedStructured ?? new Dictionary<long, IComparable>();
                                toBeUpdatedStructured.Add(propDef.ID, newValue);
                            }

                        }
                    }
                }
            }

            #endregion

            #region extract vertex properties
            #region will be ignored
            long vertexID = 0L;
            long creationDate = 0L;
            long modificationDate = 0L;
            #endregion

            ExtractVertexProperties(ref edition, ref revision, ref comment, ref vertexID, ref creationDate, ref modificationDate, toBeUpdatedStructured);
            #endregion

            #region edge magic

            if (myUpdate.AddedElementsToCollectionEdges != null ||
                myUpdate.RemovedElementsFromCollectionEdges != null ||
                myUpdate.UpdateOutgoingEdges != null ||
                myUpdate.UpdateOutgoingEdgesProperties != null)
            {
                VertexInformation source = new VertexInformation(myVertex.VertexTypeID, myVertex.VertexID);

                #region update outgoing edges

                if (myUpdate.UpdateOutgoingEdges != null)
                {
                    foreach (var edge in myUpdate.UpdateOutgoingEdges)
                    {
                        var edgeDef = myVertexType.GetOutgoingEdgeDefinition(edge.EdgeName);

                        switch (edgeDef.Multiplicity)
                        {
                            case EdgeMultiplicity.SingleEdge:
                                {
                                    #region SingleEdge
                                    var targets = GetResultingVertexIDs(myTransaction, mySecurity, edge, edgeDef.TargetVertexType);
                                    if (targets == null || !targets.CountIsGreater(0))
                                    {
                                        toBeDeletedSingle = toBeDeletedSingle ?? new List<long>();
                                        toBeDeletedSingle.Add(edgeDef.ID);
                                    }
                                    else if (targets.CountIsGreater(1))
                                    {
                                        throw new Exception("Single edge can not have more than one target.");
                                    }
                                    else
                                    {
                                        ConvertUnknownProperties(edge, edgeDef.EdgeType);
                                        var structured = CreateStructuredUpdate(edge.StructuredProperties, edgeDef.EdgeType);
                                        var unstructured = CreateUnstructuredUpdate(edge.UnstructuredProperties);

                                        toBeUpdatedSingle = toBeUpdatedSingle ?? new Dictionary<long, SingleEdgeUpdateDefinition>();

                                        toBeUpdatedSingle.Add(edgeDef.ID,
                                                                new SingleEdgeUpdateDefinition(source,
                                                                                                targets.First(),
                                                                                                edgeDef.EdgeType.ID,
                                                                                                edge.Comment,
                                                                                                structured,
                                                                                                unstructured));
                                    }
                                    #endregion
                                }
                                break;

                            case EdgeMultiplicity.MultiEdge:
                                {
                                    #region MultiEdge
                                    // Why deleting the edge instances ???
                                    // they will never be inserted inside the update !!!
                                    // After delete the update will be needless because the edges are deleted !!!

                                    //List<SingleEdgeDeleteDefinition> internSingleDelete = null;
                                    //if (myVertex.HasOutgoingEdge(edgeDef.ID))
                                    //{
                                    //    internSingleDelete = new List<SingleEdgeDeleteDefinition>();
                                    //    foreach (var edgeInstance in myVertex.GetOutgoingHyperEdge(edgeDef.ID).GetTargetVertices())
                                    //    {
                                    //        internSingleDelete.Add(
                                    //            new SingleEdgeDeleteDefinition(source,
                                    //                                            new VertexInformation(edgeInstance.VertexTypeID,
                                    //                                                                    edgeInstance.VertexID)));
                                    //    }
                                    //}

                                    List<SingleEdgeUpdateDefinition> internSingleUpdate = null;
                                    var targets = GetResultingVertexIDs(myTransaction, mySecurity, edge, edgeDef.TargetVertexType);

                                    if (targets != null)
                                    {
                                        foreach (var target in targets)
                                        {
                                            internSingleUpdate = internSingleUpdate ?? new List<SingleEdgeUpdateDefinition>();
                                            internSingleUpdate.Add(new SingleEdgeUpdateDefinition(source, target, edgeDef.InnerEdgeType.ID));
                                        }
                                    }
                                    if (edge.ContainedEdges != null)
                                    {
                                        foreach (var innerEdge in edge.ContainedEdges)
                                        {
                                            targets = GetResultingVertexIDs(myTransaction, mySecurity, innerEdge, edgeDef.TargetVertexType);
                                            if (targets != null && targets.CountIsGreater(0))
                                            {
                                                ConvertUnknownProperties(innerEdge, edgeDef.InnerEdgeType);
                                                var structured = CreateStructuredUpdate(innerEdge.StructuredProperties, edgeDef.InnerEdgeType);
                                                var unstructured = CreateUnstructuredUpdate(innerEdge.UnstructuredProperties);

                                                foreach (var target in targets)
                                                {
                                                    internSingleUpdate = internSingleUpdate ?? new List<SingleEdgeUpdateDefinition>();

                                                    internSingleUpdate.Add(
                                                        new SingleEdgeUpdateDefinition(source,
                                                                                        target,
                                                                                        edgeDef.InnerEdgeType.ID,
                                                                                        innerEdge.Comment,
                                                                                        structured,
                                                                                        unstructured));
                                                }
                                            }

                                        }
                                    }
                                    ConvertUnknownProperties(edge, edgeDef.EdgeType);
                                    var outerStructured = CreateStructuredUpdate(edge.StructuredProperties, edgeDef.EdgeType);
                                    var outerUnstructured = CreateUnstructuredUpdate(edge.UnstructuredProperties);

                                    toBeUpdatedHyper = toBeUpdatedHyper ?? new Dictionary<long, HyperEdgeUpdateDefinition>();

                                    toBeUpdatedHyper.Add(edgeDef.ID,
                                                            new HyperEdgeUpdateDefinition(edgeDef.EdgeType.ID,
                                                                                            edge.Comment,
                                                                                            outerStructured,
                                                                                            outerUnstructured,
                                                                                            null,//internSingleDelete,
                                                                                            internSingleUpdate));
                                    #endregion
                                }
                                break;

                            case EdgeMultiplicity.HyperEdge:
                                break;

                            default:
                                throw new Exception("The enumeration EdgeMultiplicity was changed, but not this switch statement.");
                        }
                    }
                }

                #endregion

                #region update outgoing edges properties

                if (myUpdate.UpdateOutgoingEdgesProperties != null)
                {
                    foreach (var edge in myUpdate.UpdateOutgoingEdgesProperties)
                    {
                        var edgeDef = myVertexType
                                        .GetOutgoingEdgeDefinitions(true)
                                        .Where(_ => _.ID.Equals(edge.EdgeTypeID) ||
                                                _.InnerEdgeType.ID.Equals(edge.EdgeTypeID)).FirstOrDefault();

                        switch (edgeDef.Multiplicity)
                        {
                            case EdgeMultiplicity.SingleEdge:
                                {
                                    #region SingleEdge
                                    //var targets = GetResultingVertexIDs(myTransaction, mySecurity, edge, edgeDef.TargetVertexType);

                                    //if (targets == null || !targets.CountIsGreater(0))
                                    //{
                                    //    toBeDeletedSingle = toBeDeletedSingle ?? new List<long>();
                                    //    toBeDeletedSingle.Add(edgeDef.ID);
                                    //}
                                    //else if (targets.CountIsGreater(1))
                                    //{
                                    //    throw new Exception("Single edge can not have more than one target.");
                                    //}
                                    //else
                                    //{
                                    //    ConvertUnknownProperties(edge, edgeDef.EdgeType);
                                    //    var structured = CreateStructuredUpdate(edge.StructuredProperties, edgeDef.EdgeType);
                                    //    var unstructured = CreateUnstructuredUpdate(edge.UnstructuredProperties);

                                    //    toBeUpdatedSingle = toBeUpdatedSingle ?? new Dictionary<long, SingleEdgeUpdateDefinition>();

                                    //    toBeUpdatedSingle.Add(edgeDef.ID,
                                    //                            new SingleEdgeUpdateDefinition(source,
                                    //                                                            targets.First(),
                                    //                                                            edgeDef.EdgeType.ID,
                                    //                                                            edge.Comment,
                                    //                                                            structured,
                                    //                                                            unstructured));
                                    //}
                                    #endregion
                                }
                                break;

                            case EdgeMultiplicity.MultiEdge:
                                {
                                    #region MultiEdge
                                    List<SingleEdgeUpdateDefinition> internSingleUpdate = null;

                                    var targets =
                                        myVertex
                                        .GetOutgoingEdge(edgeDef.ID)
                                        .GetTargetVertices()
                                        .Select(_ => new VertexInformation(_.VertexTypeID,
                                                                            _.VertexID));

                                    if (targets != null && targets.CountIsGreater(0))
                                    {
                                        var structured = edge.UpdatedStructuredProperties;
                                        var unstructured = edge.UpdatedUnstructuredProperties;

                                        foreach (var target in targets)
                                        {
                                            internSingleUpdate = internSingleUpdate ?? new List<SingleEdgeUpdateDefinition>();

                                            internSingleUpdate.Add(
                                                new SingleEdgeUpdateDefinition(source,
                                                                                target,
                                                                                edgeDef.InnerEdgeType.ID,
                                                                                edge.CommentUpdate,
                                                                                structured,
                                                                                unstructured));
                                        }
                                    }

                                    toBeUpdatedHyper = toBeUpdatedHyper ??
                                                        new Dictionary<long, HyperEdgeUpdateDefinition>();

                                    if (toBeUpdatedHyper.ContainsKey(edgeDef.ID))
                                    {
                                        var temp = toBeUpdatedHyper[edgeDef.ID];
                                        toBeUpdatedHyper.Remove(edgeDef.ID);
                                        toBeUpdatedHyper.Add(edgeDef.ID,
                                                            MergeToBeAddedHyperEdgeUpdates(temp,
                                                                                            internSingleUpdate));
                                    }
                                    else
                                        toBeUpdatedHyper.Add(edgeDef.ID,
                                                                new HyperEdgeUpdateDefinition(edgeDef.EdgeType.ID,
                                                                                                null,
                                                                                                null,
                                                                                                null,
                                                                                                null,
                                                                                                internSingleUpdate));

                                    #endregion
                                }
                                break;

                            case EdgeMultiplicity.HyperEdge:
                                break;

                            default:
                                throw new Exception("The enumeration EdgeMultiplicity was changed, but not this switch statement.");
                        }
                    }
                }

                #endregion

                #region update AddedElementsToCollectionEdges

                if (myUpdate.AddedElementsToCollectionEdges != null)
                {
                    foreach (var hyperEdge in myUpdate.AddedElementsToCollectionEdges)
                    {
                        var edgeDef = myVertexType.GetOutgoingEdgeDefinition(hyperEdge.Key);

                        if (edgeDef == null)
                            //TODO a better exception here
                            throw new Exception("edge attribute not defined.");

                        if (edgeDef.Multiplicity == EdgeMultiplicity.SingleEdge)
                            //TODO a better exception here
                            throw new Exception("Add edges is only defined on hyper/multi edges.");

                        var edgeTypeID = edgeDef.ID;
                        StructuredPropertiesUpdate structuredUpdate;
                        UnstructuredPropertiesUpdate unstructuredUpdate;
                        IEnumerable<SingleEdgeUpdateDefinition> singleUpdate;

                        CheckIfToBeAddedElementAlreadyExist(myVertex, 
                                                            edgeDef, 
                                                            hyperEdge.Value,
                                                            myTransaction,
                                                            mySecurity);

                        CreateSingleEdgeUpdateDefinitions(source,
                                                            myTransaction,
                                                            mySecurity,
                                                            hyperEdge.Value,
                                                            edgeDef,
                                                            out structuredUpdate,
                                                            out unstructuredUpdate,
                                                            out singleUpdate);

                        toBeUpdatedHyper = toBeUpdatedHyper ?? new Dictionary<long, HyperEdgeUpdateDefinition>();

                        toBeUpdatedHyper.Add(edgeTypeID, new HyperEdgeUpdateDefinition(edgeTypeID, null, structuredUpdate, unstructuredUpdate, null, singleUpdate));
                    }
                }

                #endregion

                #region update RemovedElementsFromCollectionEdges

                if (myUpdate.RemovedElementsFromCollectionEdges != null)
                {
                    foreach (var hyperEdge in myUpdate.RemovedElementsFromCollectionEdges)
                    {
                        var edgeDef = myVertexType.GetOutgoingEdgeDefinition(hyperEdge.Key);

                        if (edgeDef == null)
                            //TODO a better exception here
                            throw new Exception("Edge attribute not defined.");

                        if (edgeDef.Multiplicity == EdgeMultiplicity.SingleEdge)
                            //TODO a better exception here
                            throw new Exception("Removing edges is only defined on hyper/multi edges.");

                        var edgeTypeID = edgeDef.ID;

                        var del = CreateSingleEdgeDeleteDefinitions(source, myTransaction, mySecurity, hyperEdge.Value, edgeDef);

                        toBeUpdatedHyper = toBeUpdatedHyper ?? new Dictionary<long, HyperEdgeUpdateDefinition>();
                        toBeUpdatedHyper.Add(edgeTypeID, new HyperEdgeUpdateDefinition(edgeTypeID, null, null, null, del, null));

                    }
                }

                #endregion
            }

            #endregion

            #region create updates

            var updateSingle = (toBeUpdatedSingle != null || toBeDeletedSingle != null)
                ? new SingleEdgeUpdate(toBeUpdatedSingle, toBeDeletedSingle)
                : null;

            var updateHyper = (toBeUpdatedHyper != null || toBeDeletedHyper != null)
                ? new HyperEdgeUpdate(toBeUpdatedHyper, toBeDeletedHyper)
                : null;

            var updateStructured = (toBeUpdatedStructured != null || toBeDeletedStructured != null)
                ? new StructuredPropertiesUpdate(toBeUpdatedStructured, toBeDeletedStructured)
                : null;

            var updateUnstructured = (toBeUpdatedUnstructured != null || toBeDeletedUnstructured != null)
                ? new UnstructuredPropertiesUpdate(toBeUpdatedUnstructured, toBeDeletedUnstructured)
                : null;

            var updateBinaries = (toBeUpdatedBinaries != null || toBeDeletedBinaries != null)
                ? new BinaryPropertiesUpdate(toBeUpdatedBinaries, toBeDeletedBinaries)
                : null;

            #endregion

            return Tuple.Create(revision,
                                edition,
                                new VertexUpdateDefinition(comment,
                                                            updateStructured,
                                                            updateUnstructured,
                                                            updateBinaries,
                                                            updateSingle,
                                                            updateHyper));
        }
Example #16
0
        public override IEnumerable<IVertex> UpdateVertices(RequestUpdate myUpdate,
                                                            Int64 myTransaction,
                                                            SecurityToken mySecurity)
        {
            var toBeUpdated = GetVertices(myUpdate.GetVerticesRequest, myTransaction, mySecurity);

            var groupedByTypeID = toBeUpdated.GroupBy(_ => _.VertexTypeID);

            if (groupedByTypeID.CountIsGreater(0))
            {
                Dictionary<IVertex, Tuple<long?, String, VertexUpdateDefinition>> updates =
                    new Dictionary<IVertex, Tuple<long?, String, VertexUpdateDefinition>>();

                foreach (var group in groupedByTypeID)
                {
                    var vertexType = _vertexTypeManager
                                        .ExecuteManager
                                        .GetType(group.Key, myTransaction, mySecurity);

                    //we copy each property in property provider, 
                    //because an unknown property can be a structured at one type but unstructured at the other.
                    //this must be refactored:
                    //idea cancel IPropertyProvider. Change ConvertUnknownProperties to fill the dictionaries directly.
                    PropertyCopy copy = new PropertyCopy(myUpdate);
                    ConvertUnknownProperties(copy, vertexType);

                    if (copy.StructuredProperties != null)
                    {
                        var toBeUpdatedStructuredNames = copy.StructuredProperties.Select(_ => _.Key).ToArray();

                        foreach (var uniqueIndex in vertexType.GetUniqueDefinitions(false))
                        {
                            //if the unique index is defined on a property that will be updated
                            if (uniqueIndex.UniquePropertyDefinitions.Any(_ => toBeUpdatedStructuredNames.Contains(_.Name)))
                            {
                                //the list of property names, that can make an update of multiple vertices on unique properties unique again.

                                var uniquemaker = uniqueIndex.UniquePropertyDefinitions.Select(_ => _.Name).Except(toBeUpdatedStructuredNames);
                                if (!uniquemaker.CountIsGreater(0) && group.CountIsGreater(0))
                                    throw new IndexUniqueConstrainViolationException(vertexType.Name, String.Join(", ", uniquemaker));
                            }
                        }

                        var toBeUpdatedUniques = vertexType
                                                    .GetUniqueDefinitions(true)
                                                    .Where(_ => _.UniquePropertyDefinitions.Any(__ => toBeUpdatedStructuredNames.Contains(__.Name)));
                    }

                    foreach (var vertex in group)
                    {

                        //var toBeUpdatedIndices = (copy.StructuredProperties != null)
                        //                            ? copy.StructuredProperties.ToDictionary(_ => _.Key, _ => vertexType.GetPropertyDefinition(_.Key).InIndices)
                        //                            : null;

                        var update = CreateVertexUpdateDefinition(vertex, vertexType, myUpdate, copy, myTransaction, mySecurity);

                        updates.Add(vertex, update);
                    }
                }

                //force execution
                return ExecuteUpdates(groupedByTypeID, updates, myTransaction, mySecurity);
            }

            return Enumerable.Empty<IVertex>();
        }
Example #17
0
        private RequestUpdate GenerateUpdateRequest(IGraphDB myGraphDB, GQLPluginManager myPluginManager, SecurityToken mySecurityToken, TransactionToken myTransactionToken)
        {
            IEnumerable<IVertex> toBeupdatedVertices = null;
            //prepare
            var vertexType = myGraphDB.GetVertexType<IVertexType>(
                mySecurityToken,
                myTransactionToken,
                new RequestGetVertexType(_TypeName),
                (stats, vtype) => vtype);

            if (_vertexIDs == null)
            {
                if (_WhereExpression != null)
                {
                    //validate
                    _WhereExpression.Validate(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, vertexType);

                    //calculate
                    var expressionGraph = _WhereExpression.Calculon(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, new CommonUsageGraph(myGraphDB, mySecurityToken, myTransactionToken), false);

                    //extract

                    toBeupdatedVertices = expressionGraph.Select(new LevelKey(vertexType.ID, myGraphDB, mySecurityToken, myTransactionToken), null, true);
                }
                else
                {
                    toBeupdatedVertices = myGraphDB.GetVertices<IEnumerable<IVertex>>(
                        mySecurityToken,
                        myTransactionToken,
                        new RequestGetVertices(vertexType.ID),
                        (stats, vertices) => vertices);
                }

            }
            else
            {
                toBeupdatedVertices = _vertexIDs;
            }

            var result = new RequestUpdate(new RequestGetVertices(vertexType.ID, toBeupdatedVertices.Select(_ => _.VertexID) , false));

            ProcessListOfUpdates(vertexType, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, ref result);

            return result;
        }