Beispiel #1
0
        private static void ProcessStructuredProperty(GQLPluginManager myPluginManager, 
            IGraphDB myGraphDB,
            SecurityToken mySecurityToken,
            Int64 myTransactionToken,
            IVertexType vertexType,
            AAttributeAssignOrUpdate aAttributeDefinition,
            ref RequestInsertVertex result)
        {
            #region AttributeAssignOrUpdateValue

            if (aAttributeDefinition is AttributeAssignOrUpdateValue)
            {
                var value = aAttributeDefinition as AttributeAssignOrUpdateValue;

                result.AddUnknownProperty(value.AttributeIDChain.ContentString, value.Value);

                return;
            }

            #endregion

            #region AttributeAssignOrUpdateList

            if (aAttributeDefinition is AttributeAssignOrUpdateList)
            {
                var value = aAttributeDefinition as AttributeAssignOrUpdateList;

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

                        #region set

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

                        IAttributeDefinition attribute = vertexType.GetAttributeDefinition(aAttributeDefinition
                                                                                            .AttributeIDChain
                                                                                            .ContentString);

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

                        foreach (var aTupleElement in (TupleDefinition)value.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");
                            }
                        }

                        result.AddEdge(edgeDefinition);

                        #endregion)

                        return;
                    case CollectionType.List:

                        #region list

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

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

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

                        result.AddStructuredProperty(aAttributeDefinition.AttributeIDChain.ContentString, listWrapper);

                        #endregion)

                        return;
                    case CollectionType.SetOfUUIDs:

                        #region SetOfUUIDs

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

                        foreach (var aTupleElement in ((VertexTypeVertexIDCollectionNode)value.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.AddEdge(anotheredgeDefinition);

                        #endregion

                        return;
                    default:
                        return;
                }

            }

            #endregion

            #region SetRefNode

            if (aAttributeDefinition is AttributeAssignOrUpdateSetRef)
            {
                var value = aAttributeDefinition as AttributeAssignOrUpdateSetRef;

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

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

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

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

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

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

                    #endregion
                }
                else
                {
                    #region expression

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

                    foreach (var aTupleElement in value.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.AddEdge(edgeDefinition);

                return;
            }

            #endregion
        }
Beispiel #2
0
        public static RequestInsertVertex MakeRequestInsertVertex(String myVertexTypeName, ServiceInsertPayload myPayload)
        {
            RequestInsertVertex Request = new RequestInsertVertex(myVertexTypeName);

            if(!String.IsNullOrEmpty(myPayload.Comment))
                Request.SetComment(myPayload.Comment);

            if(!String.IsNullOrEmpty(myPayload.Edition))
                Request.SetEdition(myPayload.Edition);

            if (myPayload.UUID != null)
                Request.SetUUID(myPayload.UUID.Value);

            if (myPayload.StructuredProperties != null)
            {
                foreach (var toInsert in myPayload.StructuredProperties)
                {
                    Request.AddStructuredProperty(toInsert.PropertyName, toInsert.PropertyValue as IComparable);
                }
            }

            if (myPayload.UnstructuredProperties != null)
            {
                foreach (var toInsert in myPayload.UnstructuredProperties)
                {
                    Request.AddUnstructuredProperty(toInsert.PropertyName, toInsert.PropertyValue);
                }
            }

            if (myPayload.Edges != null)
            {
                foreach (var Edge in myPayload.Edges)
                {
                    Request.AddEdge(Edge.ToEdgePredefinition());
                }
            }

            return Request;
        }