Esempio n. 1
0
        }     // _addOptionsRecurse()

        private CswNbtView _getView(NodeSelect.Request Request)
        {
            CswNbtView Ret = null;

            try
            {
                if (null != Request.ViewId && Request.ViewId.isSet())
                {
                    Ret = _CswNbtResources.ViewSelect.restoreView(Request.ViewId);
                }
                if (null != Request.SessionViewId && Request.SessionViewId.isSet())
                {
                    Ret = _CswNbtResources.ViewSelect.getSessionView(Request.SessionViewId);
                }
            }
            catch (CswDniException)
            {
                Ret = null;
            }
            return(Ret);
        }
Esempio n. 2
0
        public NodeSelect.Response getNodes(NodeSelect.Request Request)
        {
            NodeSelect.Response Ret = new NodeSelect.Response();

            Ret.CanAdd        = true;
            Ret.UseSearch     = false;
            Ret.NodeTypeId    = Request.NodeTypeId;
            Ret.ObjectClassId = Request.ObjectClassId;
            Ret.PropertySetId = Request.PropertySetId;

            CswNbtMetaDataObjectClass MetaDataObjectClass = null;
            // case 25956
            Collection <Int32> NodeTypeIds = new Collection <Int32>();

            // If we have a view, use it
            CswNbtView View = _getView(Request);

            if (null != View)
            {
                if (Request.PropertySetId > 0)
                {
                    CswNbtMetaDataPropertySet PropSet = _CswNbtResources.MetaData.getPropertySet(Request.PropertySetId);
                    foreach (CswNbtMetaDataObjectClass OC in PropSet.getObjectClasses())
                    {
                        foreach (CswNbtMetaDataNodeType NT in OC.getNodeTypes())
                        {
                            NodeTypeIds.Add(NT.NodeTypeId);
                        }
                    }
                }
                else
                {
                    // Absent a MetaDataObject ID,
                    // the safest assumption is that we want all nodes of the same Object Class at the lowest level of the View,
                    // using the relationships defined on the View, of course.
                    Dictionary <Int32, Int32> LowestLevelNodeTypes = _getRelationshipSecondType(View);
                    foreach (KeyValuePair <int, int> KeyValuePair in LowestLevelNodeTypes)
                    {
                        NodeTypeIds.Add(KeyValuePair.Key);
                        CswNbtMetaDataNodeType NodeType = _CswNbtResources.MetaData.getNodeType(KeyValuePair.Key);

                        Ret.CanAdd = Ret.CanAdd ||
                                     _CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Create,
                                                                         NodeType);
                    }
                    Ret.ObjectClassId   = LowestLevelNodeTypes.FirstOrDefault().Value;
                    MetaDataObjectClass = _CswNbtResources.MetaData.getObjectClass(Ret.ObjectClassId);
                }
            }


            // If we don't have a view, make one
            if (null == View)
            {
                if (Request.NodeTypeId > 0)
                {
                    CswNbtMetaDataNodeType MetaDataNodeType = _CswNbtResources.MetaData.getNodeType(Request.NodeTypeId);
                    if (null != MetaDataNodeType)
                    {
                        MetaDataObjectClass = MetaDataNodeType.getObjectClass();
                        NodeTypeIds.Add(MetaDataNodeType.NodeTypeId);
                        View = new CswNbtView(_CswNbtResources);
                        View.AddViewRelationship(MetaDataNodeType, IncludeDefaultFilters: true);

                        Ret.NodeTypeId = MetaDataNodeType.NodeTypeId;
                        Ret.CanAdd     = _CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Create, MetaDataNodeType);
                    }
                }
                else
                {
                    if (Request.ObjectClassId > 0)
                    {
                        MetaDataObjectClass = _CswNbtResources.MetaData.getObjectClass(Request.ObjectClassId);
                    }
                    else if (Request.ObjectClass != CswNbtResources.UnknownEnum)
                    {
                        MetaDataObjectClass = _CswNbtResources.MetaData.getObjectClass(Request.ObjectClass);
                    }

                    if (null != MetaDataObjectClass)
                    {
                        Ret.ObjectClassId = MetaDataObjectClass.ObjectClassId;

                        View = new CswNbtView(_CswNbtResources);
                        CswNbtViewRelationship Relationship = View.AddViewRelationship(MetaDataObjectClass, IncludeDefaultFilters: true);

                        if (false == string.IsNullOrEmpty(Request.RelatedToObjectClass) &&
                            CswTools.IsPrimaryKey(Request.RelatedNodeId))
                        {
                            CswEnumNbtObjectClass RealRelatedObjectClass = Request.RelatedToObjectClass;

                            CswNbtNode RelatedNode = _CswNbtResources.Nodes[Request.RelatedNodeId];
                            if (null != RelatedNode)
                            {
                                if (RelatedNode.ObjClass.ObjectClass.ObjectClass == RealRelatedObjectClass)
                                {
                                    Collection <CswNbtMetaDataObjectClassProp> RelatedProps = new Collection <CswNbtMetaDataObjectClassProp>();
                                    CswNbtMetaDataObjectClass MetaRelatedObjectClass        = _CswNbtResources.MetaData.getObjectClass(RealRelatedObjectClass);
                                    Ret.RelatedObjectClassId = MetaRelatedObjectClass.ObjectClassId;
                                    foreach (CswNbtMetaDataObjectClassProp OcProp in
                                             from _OcProp
                                             in MetaDataObjectClass.getObjectClassProps()
                                             where
                                             _OcProp.getFieldTypeValue() ==
                                             CswEnumNbtFieldType.Relationship &&
                                             //_OcProp.FKType == NbtViewRelatedIdType.ObjectClassId.ToString() &&
                                             //_OcProp.FKValue == MetaRelatedObjectClass.ObjectClassId
                                             _OcProp.FkMatches(MetaRelatedObjectClass)
                                             select _OcProp)
                                    {
                                        RelatedProps.Add(OcProp);
                                    }

                                    if (RelatedProps.Any())
                                    {
                                        foreach (CswNbtMetaDataObjectClassProp RelationshipProp in RelatedProps)
                                        {
                                            View.AddViewPropertyAndFilter(Relationship, RelationshipProp,
                                                                          SubFieldName:
                                                                          CswNbtFieldTypeRuleRelationship.SubFieldName.NodeID,
                                                                          Value:
                                                                          Request.RelatedNodeId.PrimaryKey.ToString());
                                        }
                                    }
                                }
                            }
                        }


                        Ret.CanAdd = MetaDataObjectClass.getLatestVersionNodeTypes()
                                     .Aggregate(false,
                                                (current, NodeType) =>
                                                current ||
                                                _CswNbtResources.Permit.canNodeType(
                                                    CswEnumNbtNodeTypePermission.Create, NodeType));
                    }
                    else
                    {
                        Ret.CanAdd = false;
                    }
                }
            }

            if (null != View)
            {
                Ret.Nodes     = getOptions(View, NodeTypeIds, Ret.ObjectClassId);
                Ret.UseSearch = Ret.UseSearch || Ret.Nodes.Count >= _SearchThreshold;
            }

            return(Ret);
        }