Exemple #1
0
        public static RequestAlterVertexType MakeRequestAlterVertexType(ServiceVertexType myVertexType, ServiceAlterVertexChangeset myChangeset)
        {
            var Request = new RequestAlterVertexType(myVertexType.Name);

            #region Add Attributes

            if (myChangeset.ToBeAddedProperties != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedProperties)
                {
                    Request.AddProperty(toAdd.ToPropertyPredefinition());
                }
            }

            if (myChangeset.ToBeAddedIncomingEdges != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedIncomingEdges)
                {
                    Request.AddIncomingEdge(toAdd.ToIncomingEdgePredefinition());
                }
            }

            if (myChangeset.ToBeAddedOutgoingEdges != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedOutgoingEdges)
                {
                    Request.AddOutgoingEdge(toAdd.ToOutgoingEdgePredefinition());
                }
            }

            if (myChangeset.ToBeAddedUniques != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedUniques)
                {
                    Request.AddUnique(toAdd.ToUniquePredefinition());
                }
            }

            if (myChangeset.ToBeAddedMandatories != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedMandatories)
                {
                    Request.AddMandatory(toAdd.ToMandatoryPredefinition());
                }
            }

            if (myChangeset.ToBeAddedIndices != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedIndices)
                {
                    Request.AddIndex(toAdd.ToIndexPredefinition());
                }
            }

            #endregion

            #region Remove Attributes

            if (myChangeset.ToBeRemovedProperties != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedProperties)
                {
                    Request.RemoveProperty(toDel);
                }
            }

            if (myChangeset.ToBeRemovedIncomingEdges != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedIncomingEdges)
                {
                    Request.RemoveIncomingEdge(toDel);
                }
            }

            if (myChangeset.ToBeRemovedOutgoingEdges != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedOutgoingEdges)
                {
                    Request.RemoveOutgoingEdge(toDel);
                }
            }

            if (myChangeset.ToBeRemovedUniques != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedUniques)
                {
                    Request.RemoveUnique(toDel);
                }
            }

            if (myChangeset.ToBeRemovedMandatories != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedMandatories)
                {
                    Request.RemoveMandatory(toDel);
                }
            }

            if (myChangeset.ToBeRemovedIndices != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedIndices)
                {
                    Request.RemoveIndex(toDel.Key, toDel.Value);
                }
            }

            #endregion

            #region define / undefine

            if (myChangeset.ToBeDefinedAttributes != null)
            {
                foreach (var toDefine in myChangeset.ToBeDefinedAttributes)
                {
                    Request.DefineAttribute(toDefine.ToUnknownAttributePredefinition());
                }
            }

            if (myChangeset.ToBeUndefinedAttributes != null)
            {
                foreach (var toUndefine in myChangeset.ToBeUndefinedAttributes)
                {
                    Request.UndefineAttribute(toUndefine);
                }
            }

            #endregion

            #region Rename Task

            if (myChangeset.ToBeRenamedProperties != null)
            {
                foreach (var toRename in myChangeset.ToBeRenamedProperties)
                {
                    Request.RenameAttribute(toRename.Key, toRename.Value);
                }
            }

            #endregion

            if (myChangeset.Comment != null)
                Request.SetComment(myChangeset.Comment);

            if (myChangeset.NewTypeName != null)
                Request.RenameType(myChangeset.NewTypeName);

            //todo add unknown attribute

            return Request;
        }
        public override IVertexType AlterVertexType(RequestAlterVertexType myAlterVertexTypeRequest, SecurityToken mySecurityToken, TransactionToken myTransactionToken)
        {
            var vertexType =  _vertexTypeManager.GetVertexType(myAlterVertexTypeRequest.VertexTypeName, myTransactionToken, mySecurityToken);

            if (myAlterVertexTypeRequest.ToBeAddedUnknownAttributes != null)
            {
                var toBeConverted = myAlterVertexTypeRequest.ToBeAddedUnknownAttributes.ToArray();
                foreach (var unknown in toBeConverted)
                {
                    if (BinaryPropertyPredefinition.TypeName.Equals(unknown.AttributeType))
                    {
                        var prop = ConvertUnknownToBinaryProperty(unknown);

                        myAlterVertexTypeRequest.AddBinaryProperty(prop);
                    }
                    else if (IsBaseType(unknown.AttributeType))
                    {
                        var prop = ConvertUnknownToProperty(unknown);

                        myAlterVertexTypeRequest.AddProperty(prop);
                    }
                    else if (unknown.AttributeType.Contains(IncomingEdgePredefinition.TypeSeparator))
                    {
                        var prop = ConvertUnknownToIncomingEdge(unknown);
                        myAlterVertexTypeRequest.AddIncomingEdge(prop);
                    }
                    else
                    {
                        var prop = ConvertUnknownToOutgoingEdge(unknown);
                        myAlterVertexTypeRequest.AddOutgoingEdge(prop);
                    }
                }
                myAlterVertexTypeRequest.ResetUnknown();
            }

            if (myAlterVertexTypeRequest.ToBeRemovedUnknownAttributes != null)
            {
                foreach (var unknownProp in myAlterVertexTypeRequest.ToBeRemovedUnknownAttributes)
                {
                    var attrDef = vertexType.GetAttributeDefinition(unknownProp);
                    if (attrDef == null)
                        throw new VertexAttributeIsNotDefinedException(unknownProp);

                    switch (attrDef.Kind)
                    {
                        case AttributeType.Property:
                            myAlterVertexTypeRequest.RemoveProperty(unknownProp);
                            break;
                        case AttributeType.OutgoingEdge:
                            myAlterVertexTypeRequest.RemoveOutgoingEdge(unknownProp);
                            break;
                        case AttributeType.IncomingEdge:
                            myAlterVertexTypeRequest.RemoveIncomingEdge(unknownProp);
                            break;
                        case AttributeType.BinaryProperty:
                            myAlterVertexTypeRequest.RemoveBinaryProperty(unknownProp);
                            break;
                        default:
                            throw new Exception("The enumeration AttributeType was changed, but not this switch statement.");
                    }
                }
                myAlterVertexTypeRequest.ClearToBeRemovedUnknownAttributes();
            }

            #region checks

            CheckToBeAddedAttributes(myAlterVertexTypeRequest, vertexType);
            CheckToBeRemovedAttributes(myAlterVertexTypeRequest, vertexType);
            CheckToBeRenamedAttributes(myAlterVertexTypeRequest, vertexType);
            CheckNewVertexTypeName(myAlterVertexTypeRequest.AlteredVertexTypeName, mySecurityToken, myTransactionToken);
            CheckToBeAddedMandatory(myAlterVertexTypeRequest, vertexType);
            CheckToBeAddedUniques(myAlterVertexTypeRequest, vertexType);
            CheckToBeRemovedMandatoryAndUnique(myAlterVertexTypeRequest.ToBeRemovedMandatories, myAlterVertexTypeRequest.ToBeRemovedUniques, vertexType);
            CheckToBeAddedIndices(myAlterVertexTypeRequest.ToBeAddedIndices, vertexType);
            CheckToBeRemovedIndices(myAlterVertexTypeRequest.ToBeRemovedIndices, vertexType);

            #endregion

            return null;
        }