예제 #1
0
        } //ctor Ntp

        public CswViewBuilderProp(CswNbtMetaDataObjectClassProp ObjectClassProp)
        {
            CswNbtMetaDataObjectClass oc = ObjectClassProp.getObjectClass();

            if (null != oc)
            {
                OwnerName = oc.ObjectClass.Value;
            }
            FieldType = ObjectClassProp.getFieldTypeValue();
            setObjectClassPropListOptions(ObjectClassProp);
            RelatedIdType = CswEnumNbtViewRelatedIdType.NodeTypeId;
            MetaDataPropNameWithQuestionNo = ObjectClassProp.PropNameWithQuestionNo;
            MetaDataPropId   = ObjectClassProp.ObjectClassPropId;
            MetaDataPropName = ObjectClassProp.PropName;
            MetaDataTypeName = ObjectClassProp.getObjectClass().ObjectClass.ToString();
            FieldTypeRule    = ObjectClassProp.getFieldTypeRule();
            Type             = CswEnumNbtViewPropType.ObjectClassPropId;
            PropName         = MetaDataPropName;
            AssociatedPropIds.Add(MetaDataPropId.ToString());
        } //ctor Ntp
        /// <summary>
        /// Returns true if the relationship is invalid
        /// </summary>
        private bool _isInvalidRelationship(CswEnumNbtViewRelatedIdType RelatedIdType, Int32 FkValue, CswEnumNbtViewPropIdType inValuePropType, Int32 inValuePropId)
        {
            bool RetIsInvalid = false;

            //if( RelatedIdType == NbtViewRelatedIdType.NodeTypeId )
            //{
            //    CswNbtMetaDataNodeType FkRelationshipTargetNt = _CswNbtFieldResources.CswNbtResources.MetaData.getNodeType( FkValue );
            //    RetIsInvalid = ( null == FkRelationshipTargetNt );
            //    if( false == RetIsInvalid )
            //    {
            //        CswNbtMetaDataNodeTypeProp ValueNtp = _CswNbtFieldResources.CswNbtResources.MetaData.getNodeTypeProp( inValuePropId );
            //        RetIsInvalid = ( null == ValueNtp ||
            //                         _CswNbtFieldResources.CswNbtResources.MetaData.getNodeTypeFirstVersion( ValueNtp.NodeTypeId ) != FkRelationshipTargetNt.getFirstVersionNodeType() );
            //    }
            //}
            //else if( RelatedIdType == NbtViewRelatedIdType.ObjectClassId )
            //{
            //    CswNbtMetaDataObjectClass FkRelationshipTargetOc = _CswNbtFieldResources.CswNbtResources.MetaData.getObjectClass( FkValue );
            //    RetIsInvalid = ( null == FkRelationshipTargetOc );

            //    if( false == RetIsInvalid )
            //    {
            //        CswNbtMetaDataObjectClassProp ValueOcp = _CswNbtFieldResources.CswNbtResources.MetaData.getObjectClassProp( inValuePropId );
            //        RetIsInvalid = ( null == ValueOcp || ( ValueOcp.getObjectClass().ObjectClass != FkRelationshipTargetOc.ObjectClass ) );
            //    }
            //}
            //else if( RelatedIdType == NbtViewRelatedIdType.PropertySetId )
            //{
            //    CswNbtMetaDataPropertySet FkRelationshipTargetPs = _CswNbtFieldResources.CswNbtResources.MetaData.getPropertySet( FkValue );
            //    RetIsInvalid = ( null == FkRelationshipTargetPs );

            //    if( false == RetIsInvalid )
            //    {
            //        CswNbtMetaDataObjectClassProp ValueOcp = _CswNbtFieldResources.CswNbtResources.MetaData.getObjectClassProp( inValuePropId );
            //        RetIsInvalid = ( null == ValueOcp ||
            //                         null == ValueOcp.getObjectClass().getPropertySet() ||
            //                         ValueOcp.getObjectClass().getPropertySet().Name != FkRelationshipTargetPs.Name );
            //    }
            //}

            if (inValuePropType == CswEnumNbtViewPropIdType.NodeTypePropId)
            {
                CswNbtMetaDataNodeTypeProp ValuePropNTP = _CswNbtFieldResources.CswNbtResources.MetaData.getNodeTypeProp(inValuePropId);
                RetIsInvalid = false == (CswNbtViewRelationship.Matches(_CswNbtFieldResources.CswNbtResources, RelatedIdType, FkValue, ValuePropNTP.getNodeType()));
            }
            else if (inValuePropType == CswEnumNbtViewPropIdType.ObjectClassPropId)
            {
                CswNbtMetaDataObjectClassProp ValuePropOCP = _CswNbtFieldResources.CswNbtResources.MetaData.getObjectClassProp(inValuePropId);
                RetIsInvalid = false == (CswNbtViewRelationship.Matches(_CswNbtFieldResources.CswNbtResources, RelatedIdType, FkValue, ValuePropOCP.getObjectClass()));
            }

            return(RetIsInvalid);
        }
예제 #3
0
        }             // _getOptions()

        #endregion Relationship Properties and Functions

        #region Serialization

        public override void ToJSON(JObject ParentObject)
        {
            bool allowAdd = false;

            ParentObject["nodetypeid"]    = string.Empty;
            ParentObject["objectclassid"] = string.Empty;

            if (RelationshipType == CswEnumNbtViewPropIdType.NodeTypePropId)
            {
                CswNbtMetaDataNodeTypeProp RelationshipNTP = _CswNbtResources.MetaData.getNodeTypeProp(RelationshipId);
                CswNbtMetaDataNodeType     RelationshipNT  = RelationshipNTP.getNodeType();
                if (null != RelationshipNT)
                {
                    ParentObject["nodetypeid"] = RelationshipNT.NodeTypeId;
                    CswNbtMetaDataObjectClass RelationshipOC = RelationshipNT.getObjectClass();
                    if (null != RelationshipOC)
                    {
                        ParentObject["objectclassid"] = RelationshipOC.ObjectClassId;
                        allowAdd = (RelationshipOC.CanAdd &&
                                    _CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Create, RelationshipNT));
                    }
                }
            }
            else if (RelationshipType == CswEnumNbtViewPropIdType.ObjectClassPropId)
            {
                CswNbtMetaDataObjectClassProp RelationshipOCP = _CswNbtResources.MetaData.getObjectClassProp(RelationshipId);
                CswNbtMetaDataObjectClass     RelationshipOC  = RelationshipOCP.getObjectClass();
                if (null != RelationshipOC)
                {
                    ParentObject["objectclassid"] = RelationshipOC.ObjectClassId;
                    allowAdd = RelationshipOC.CanAdd;
                    if (allowAdd)
                    {
                        foreach (CswNbtMetaDataNodeType NodeType in RelationshipOC.getLatestVersionNodeTypes())
                        {
                            allowAdd = _CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Create, NodeType);
                            if (allowAdd)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            ParentObject["allowadd"] = allowAdd;

            JArray JOptions = new JArray();

            ParentObject["options"]         = JOptions;
            ParentObject["relatednodeid"]   = string.Empty;
            ParentObject["relatednodename"] = string.Empty;

            Dictionary <CswPrimaryKey, string> Options = _getOptions();
            CswPrimaryKey SelectedNodeId = null;

            if (null != SetSelected)
            {
                SelectedNodeId = SetSelected();
            }
            bool first = true;

            foreach (CswPrimaryKey NodePk in Options.Keys)
            {
                if (first || (null != NodePk && NodePk == SelectedNodeId))
                {
                    // Choose first option by default
                    ParentObject["relatednodeid"]   = NodePk.ToString();
                    ParentObject["relatednodename"] = Options[NodePk];
                    first = false;
                }
                if (NodePk != null && NodePk.PrimaryKey != Int32.MinValue)
                {
                    JObject JOption = new JObject();
                    JOption["id"]    = NodePk.ToString();
                    JOption["value"] = Options[NodePk];
                    JOptions.Add(JOption);
                }
            }
        } // ToJson()