示例#1
0
        public CswCommaDelimitedString SelectedNodeTypeNames()
        {
            CswCommaDelimitedString NodeTypeNames = new CswCommaDelimitedString();

            foreach (string NodeTypeId in SelectedNodeTypeIds)
            {
                if (string.Empty != NodeTypeId)
                {
                    CswNbtMetaDataNodeType NodeType = _CswNbtResources.MetaData.getNodeType(CswConvert.ToInt32(NodeTypeId));
                    if (null != NodeType)
                    {
                        NodeTypeNames.Add(NodeType.getNodeTypeLatestVersion().NodeTypeName);
                    }
                }
            } // foreach(string NodeTypeId in SelectedNodeTypeIds)
            if (0 == NodeTypeNames.Count)
            {
                NodeTypeNames.Add("[none]");
            }

            // Sort alphabetically
            NodeTypeNames.Sort();

            return(NodeTypeNames);
        } // SelectedNodeTypeNames()
        private CswNbtNode _getTargetNodeForGenerator(CswNbtNode CswNbtNodeGenerator, CswPrimaryKey ParentPk, string TargetDateFilter)
        {
            CswNbtNode ReturnVal = null;

            CswNbtObjClassGenerator GeneratorNode = (CswNbtObjClassGenerator)CswNbtNodeGenerator;

            if (String.IsNullOrEmpty(GeneratorNode.TargetType.SelectedNodeTypeIds.ToString()))
            {
                throw new CswDniException(CswEnumErrorType.Error, "Invalid generator configuration", "_getTargetNodeForGenerator got a null SelectedNodeTypeIds on nodeid " + GeneratorNode.NodeId);
            }
            else
            {
                Int32 NodeTypeId = CswConvert.ToInt32(GeneratorNode.TargetType.SelectedNodeTypeIds[0]);   // case 28612 - just check the first one
                if (Int32.MinValue != NodeTypeId)
                {
                    CswNbtMetaDataNodeType ThisCreatedNodeType = _CswNbtResources.MetaData.getNodeType(NodeTypeId);
                    if (null != ThisCreatedNodeType)
                    {
                        CswNbtMetaDataNodeType    CreatedNodeType            = ThisCreatedNodeType.getNodeTypeLatestVersion();
                        CswNbtMetaDataObjectClass CreatedMetaDataObjectClass = CreatedNodeType.getObjectClass();

                        CswNbtObjClass CreatedObjClass = CswNbtObjClassFactory.makeObjClass(_CswNbtResources, CreatedMetaDataObjectClass);
                        if (!(CreatedObjClass is CswNbtPropertySetGeneratorTarget))
                        {
                            throw new CswDniException("CswNbtActGenerateNodes got an invalid object class: " + CreatedObjClass.ObjectClass.ToString());
                        }
                        CswNbtPropertySetGeneratorTarget GeneratorTarget = (CswNbtPropertySetGeneratorTarget)CreatedObjClass;

                        // CreatedForNTP is the parent or owner of the new node. Inspections created for Inspection Targets, Tasks for Equipment, etc.
                        CswNbtMetaDataNodeTypeProp CreatedForNTP = CreatedNodeType.getNodeTypePropByObjectClassProp(GeneratorTarget.ParentPropertyName);
                        CswNbtMetaDataNodeTypeProp GeneratorNTP  = CreatedNodeType.getNodeTypePropByObjectClassProp(CswNbtPropertySetGeneratorTarget.PropertyName.Generator);
                        CswNbtMetaDataNodeTypeProp DueDateNTP    = CreatedNodeType.getNodeTypePropByObjectClassProp(CswNbtPropertySetGeneratorTarget.PropertyName.DueDate);

                        CswNbtView CswNbtView = new CswNbtView(_CswNbtResources);
                        CswNbtView.ViewName = "Nodes for Generator";

                        CswNbtViewRelationship RootRelationship     = CswNbtView.AddViewRelationship(CreatedNodeType, false);
                        CswNbtViewProperty     CreatedForParentProp = CswNbtView.AddViewProperty(RootRelationship, CreatedForNTP);
                        CswNbtView.AddViewPropertyFilter(CreatedForParentProp, CswNbtFieldTypeRuleRelationship.SubFieldName.NodeID, CswEnumNbtFilterMode.Equals, ParentPk.PrimaryKey.ToString(), false);
                        CswNbtViewProperty GeneratorProp = CswNbtView.AddViewProperty(RootRelationship, GeneratorNTP);
                        CswNbtView.AddViewPropertyFilter(GeneratorProp, CswNbtFieldTypeRuleRelationship.SubFieldName.NodeID, CswEnumNbtFilterMode.Equals, CswNbtNodeGenerator.NodeId.PrimaryKey.ToString(), false);
                        CswNbtViewProperty DueDateProp = CswNbtView.AddViewProperty(RootRelationship, DueDateNTP);
                        //Case 24572
                        CswNbtView.AddViewPropertyFilter(DueDateProp, CswNbtFieldTypeRuleDateTime.SubFieldName.Value, CswEnumNbtFilterMode.Equals, TargetDateFilter, false);

                        ICswNbtTree ExistingNodesTree = _CswNbtResources.Trees.getTreeFromView(_CswNbtResources.CurrentNbtUser, CswNbtView, true, false, false);

                        if (ExistingNodesTree.getChildNodeCount() > 0)
                        {
                            ExistingNodesTree.goToNthChild(0);
                            ReturnVal = ExistingNodesTree.getNodeForCurrentPosition();
                        }
                    }
                }
            }
            return(ReturnVal);
        }//_getTargetNodeForGenerator
示例#3
0
        }         // addSingleNodeProp()

        private void _getRelationshipSecondTypeRecursive(Collection <CswNbtViewRelationship> Relationships,
                                                         Dictionary <Int32, Int32> SecondTypes)
        {
            foreach (CswNbtViewRelationship Relationship in Relationships)
            {
                if (Relationship.ChildRelationships.Count == 0)
                {
                    ICswNbtMetaDataObject MetaObj = Relationship.SecondMetaDataDefinitionObject();
                    if (MetaObj.UniqueIdFieldName == CswNbtMetaDataObjectClass.MetaDataUniqueType)
                    {
                        if (SecondTypes.Count == 0 ||
                            SecondTypes.ContainsValue(Relationship.SecondId))
                        {
                            CswNbtMetaDataObjectClass ObjClass = _CswNbtResources.MetaData.getObjectClass(MetaObj.UniqueId);
                            foreach (CswNbtMetaDataNodeType NodeType in ObjClass.getLatestVersionNodeTypes())
                            {
                                if (false == SecondTypes.ContainsKey(NodeType.NodeTypeId))
                                {
                                    SecondTypes.Add(NodeType.NodeTypeId, Relationship.SecondId);
                                }
                            }
                        }
                    }
                    else
                    {
                        CswNbtMetaDataNodeType NodeType = _CswNbtResources.MetaData.getNodeType(MetaObj.UniqueId);
                        if (null != NodeType &&
                            false == SecondTypes.ContainsKey(NodeType.getNodeTypeLatestVersion().NodeTypeId) &&
                            (SecondTypes.Count == 0 || SecondTypes.ContainsValue(NodeType.ObjectClassId)))
                        {
                            SecondTypes.Add(NodeType.getNodeTypeLatestVersion().NodeTypeId, NodeType.ObjectClassId);
                        }
                    }
                }
                else
                {
                    _getRelationshipSecondTypeRecursive(Relationship.ChildRelationships, SecondTypes);
                }
            }
        }
        public override void update()
        {
            CswNbtMetaDataNodeType LabSafetyCheckListNt = _CswNbtSchemaModTrnsctn.MetaData.getNodeType( "Lab Safety Checklist" );
            if(null != LabSafetyCheckListNt)
            {
                CswNbtMetaDataNodeType LabSafetyLatest = LabSafetyCheckListNt.getNodeTypeLatestVersion();
                foreach ( CswNbtMetaDataNodeTypeProp NodeTypeProp in LabSafetyLatest.getNodeTypeProps() )
                {
                    if(NodeTypeProp.getFieldTypeValue() == CswNbtMetaDataFieldType.NbtFieldType.Question)
                    {
                        CswCommaDelimitedString AllowedAnswers = new CswCommaDelimitedString();
                        AllowedAnswers.FromString(NodeTypeProp.ListOptions);
                        if( AllowedAnswers.Contains( "Yes", false ) )
                        {
                            NodeTypeProp.Extended = "Yes";
                        }
                    }
                }
            }

        }//Update()
        private void _trySetNodeTypeSelectDefaultValues()
        {
            //has owner and (is inspection schedule or has a view already)
            bool RequiresParentView = CswTools.IsPrimaryKey( Owner.RelatedNodeId ) &&
                            ( Node.getNodeType().getFirstVersionNodeType().NodeTypeName == InspectionGeneratorNodeTypeName ||
                            ( ParentView.ViewId != null &&
                              ParentView.ViewId.isSet() ) );

            if( RequiresParentView )
            {
                CswNbtNode OwnerNode = _CswNbtResources.Nodes.GetNode( Owner.RelatedNodeId );
                Collection<CswNbtMetaDataNodeType> MatchingInspectionTargetNts = new Collection<CswNbtMetaDataNodeType>();

                //parent is selectable and is inspection and owner is valid and (parent untouched or empty)
                bool SetDefaultParentType = ( ( false == ParentType.wasAnySubFieldModified() ||
                                                ParentType.SelectedNodeTypeIds.Count == 0 ) &&
                                                null != OwnerNode &&
                                                OwnerNode.getObjectClass().ObjectClass == CswEnumNbtObjectClass.InspectionTargetGroupClass &&
                                                ParentType.SelectMode != CswEnumNbtPropertySelectMode.Blank );
                if( SetDefaultParentType )
                {
                    ParentType.SelectedNodeTypeIds.Clear();
                    CswNbtMetaDataObjectClass InspectionTargetOc = _CswNbtResources.MetaData.getObjectClass( CswEnumNbtObjectClass.InspectionTargetClass );
                    foreach( CswNbtMetaDataNodeType InspectionTargetNt in InspectionTargetOc.getNodeTypes() )
                    {
                        if( InspectionTargetNt.IsLatestVersion() )
                        {
                            CswNbtMetaDataNodeTypeProp TargetGroupNtp = InspectionTargetNt.getNodeTypePropByObjectClassProp( CswNbtObjClassInspectionTarget.PropertyName.InspectionTargetGroup );
                            if( _fkIsValid( TargetGroupNtp ) )
                            {
                                CswNbtMetaDataNodeType InspectionTargetGroupNt = _CswNbtResources.MetaData.getNodeType( TargetGroupNtp.FKValue ).getNodeTypeLatestVersion();
                                if( null != InspectionTargetGroupNt &&
                                    false == MatchingInspectionTargetNts.Contains( InspectionTargetNt ) &&
                                    InspectionTargetGroupNt == OwnerNode.getNodeTypeLatestVersion() )
                                {
                                    MatchingInspectionTargetNts.Add( InspectionTargetNt );
                                    ParentType.SelectedNodeTypeIds.Add( InspectionTargetNt.NodeTypeId.ToString(), false, true );
                                    if( ParentType.SelectMode == CswEnumNbtPropertySelectMode.Single )
                                    {
                                        break;
                                    }
                                }
                            } // is valid FK
                        } // if( InspectionTargetNt.IsLatestVersion )
                    } // foreach( CswNbtMetaDataNodeType InspectionTargetNt in InspectionTargetOc.NodeTypes )
                } // if( SetDefaultTargetType )

                //target is selectable and (parent or target not empty) and (target untouched or empty)
                bool SetDefaultTargetType = ( ( false == TargetType.wasAnySubFieldModified() ||
                                            TargetType.SelectedNodeTypeIds.Count == 0 ) &&
                                          TargetType.SelectMode != CswEnumNbtPropertySelectMode.Blank &&
                                          ( MatchingInspectionTargetNts.Count > 0 ||
                                            TargetType.SelectedNodeTypeIds.Count > 0 ) );
                if( SetDefaultTargetType )
                {
                    if( MatchingInspectionTargetNts.Count == 0 )
                    {
                        foreach( Int32 InspectionTargetNodeTypeId in TargetType.SelectedNodeTypeIds.ToIntCollection() )
                        {
                            CswNbtMetaDataNodeType InspectionTargetNt = _CswNbtResources.MetaData.getNodeType( InspectionTargetNodeTypeId );
                            if( null != InspectionTargetNt )
                            {
                                CswNbtMetaDataNodeType LatestInspectionTargetNt = InspectionTargetNt.getNodeTypeLatestVersion();
                                if( LatestInspectionTargetNt.getObjectClass().ObjectClass == CswEnumNbtObjectClass.InspectionTargetClass &&
                                    false == MatchingInspectionTargetNts.Contains( LatestInspectionTargetNt ) )
                                {
                                    MatchingInspectionTargetNts.Add( LatestInspectionTargetNt );
                                }
                            }
                        }
                    }
                    if( MatchingInspectionTargetNts.Count > 0 )
                    {
                        TargetType.SelectedNodeTypeIds.Clear();
                        CswNbtMetaDataObjectClass InspectionDesignOc = _CswNbtResources.MetaData.getObjectClass( CswEnumNbtObjectClass.InspectionDesignClass );
                        foreach( CswNbtMetaDataNodeType InspectionDesignNt in InspectionDesignOc.getNodeTypes() )
                        {
                            if( InspectionDesignNt.IsLatestVersion() )
                            {
                                CswNbtMetaDataNodeTypeProp DesignTargetNtp = InspectionDesignNt.getNodeTypePropByObjectClassProp( CswNbtObjClassInspectionDesign.PropertyName.Target );
                                foreach( CswNbtMetaDataNodeType MatchingInspectionTargetNt in MatchingInspectionTargetNts )
                                {
                                    if( _fkIsValid( DesignTargetNtp ) && MatchingInspectionTargetNt.NodeTypeId == DesignTargetNtp.FKValue )
                                    {
                                        TargetType.SelectedNodeTypeIds.Add( InspectionDesignNt.NodeTypeId.ToString(), false, true );
                                        if( TargetType.SelectMode == CswEnumNbtPropertySelectMode.Single )
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#6
0
        /// <summary>
        /// New Filters to offer, based on Results
        /// </summary>
        public JArray FilterOptions(ICswNbtTree Tree)
        {
            JArray FiltersArr = new JArray();

            Tree.goToRoot();
            bool SingleNodeType = IsSingleNodeType();

            if (false == SingleNodeType)
            {
                // Filter on NodeTypes only
                SortedList <string, NodeTypeEntry> NodeTypeOptions = new SortedList <string, NodeTypeEntry>();
                Int32 ChildCnt = Tree.getChildNodeCount();
                for (Int32 n = 0; n < ChildCnt; n++)
                {
                    Tree.goToNthChild(n);
                    CswNbtNodeKey NodeKey = Tree.getNodeKeyForCurrentPosition();
                    if (NodeKey != null)
                    {
                        CswNbtMetaDataNodeType NodeType = _CswNbtResources.MetaData.getNodeType(NodeKey.NodeTypeId);
                        string LatestName = NodeType.getNodeTypeLatestVersion().NodeTypeName;
                        if (false == NodeTypeOptions.ContainsKey(LatestName))
                        {
                            NodeTypeOptions.Add(LatestName, new NodeTypeEntry
                            {
                                NodeType   = NodeType,
                                NodeTypeId = NodeType.NodeTypeId,
                                LatestName = LatestName,
                                Count      = 0
                            });
                        }
                        NodeTypeOptions[LatestName].Count += 1;
                    }
                    Tree.goToParentNode();
                } // for( Int32 n = 0; n < ChildCnt; n++ )

                if (NodeTypeOptions.Keys.Count == 1)
                {
                    if (false == IsSingleNodeType())
                    {
                        // If we have uniform results but no nodetype filter applied
                        // add the filter to the filters list for display
                        NodeTypeEntry      entry          = NodeTypeOptions.Values[0];
                        CswNbtSearchFilter NodeTypeFilter = makeFilter(entry.NodeType, entry.Count, false, CswEnumNbtSearchPropOrderSourceType.Unknown);
                        addFilter(NodeTypeFilter);
                    }
                    SingleNodeType = true;
                }
                else
                {
                    JArray FilterSet = new JArray();
                    FiltersArr.Add(FilterSet);

                    foreach (NodeTypeEntry entry in NodeTypeOptions.Values)
                    {
                        CswNbtSearchFilter NodeTypeFilter = makeFilter(entry.NodeType, entry.Count, true, CswEnumNbtSearchPropOrderSourceType.Unknown);
                        FilterSet.Add(NodeTypeFilter.ToJObject());
                    }
                }
            } // if( false == SingleNodeType )

            if (SingleNodeType)
            {
                // Filter on property values in the results
                Collection <Int32> FilteredPropIds = getFilteredPropIds();
                Dictionary <Int32, Dictionary <string, Int32> > PropCounts = new Dictionary <Int32, Dictionary <string, Int32> >();
                SortedSet <CswNbtSearchPropOrder.SearchOrder>   PropOrder  = new SortedSet <CswNbtSearchPropOrder.SearchOrder>();
                Int32 ChildCnt = Tree.getChildNodeCount();
                for (Int32 n = 0; n < ChildCnt; n++)
                {
                    Tree.goToNthChild(n);

                    if (0 == PropOrder.Count)
                    {
                        PropOrder = _CswNbtSearchPropOrder.getPropOrderDict(Tree.getNodeKeyForCurrentPosition());
                    }
                    Collection <CswNbtTreeNodeProp> Props = Tree.getChildNodePropsOfNode();
                    foreach (CswNbtTreeNodeProp Prop in Props)
                    {
                        CswNbtMetaDataFieldType FieldType = _CswNbtResources.MetaData.getFieldType(Prop.FieldType);
                        if (false == FilteredPropIds.Contains(Prop.NodeTypePropId) && FieldType.Searchable)
                        {
                            string Gestalt = Prop.Gestalt;
                            if (Gestalt.Length > 50)
                            {
                                Gestalt = Gestalt.Substring(0, 50);
                            }

                            if (false == PropCounts.ContainsKey(Prop.NodeTypePropId))
                            {
                                PropCounts[Prop.NodeTypePropId] = new Dictionary <string, Int32>();
                            }
                            if (false == PropCounts[Prop.NodeTypePropId].ContainsKey(Gestalt))
                            {
                                PropCounts[Prop.NodeTypePropId][Gestalt] = 0;
                            }
                            PropCounts[Prop.NodeTypePropId][Gestalt] += 1;
                        }
                    }

                    Tree.goToParentNode();
                } // for( Int32 n = 0; n < ChildCnt; n++ )

                foreach (Int32 NodeTypePropId in PropCounts.Keys.OrderBy(NodeTypePropId => PropOrder.First(Order => Order.NodeTypePropId == NodeTypePropId).Order))
                {
                    CswNbtMetaDataNodeTypeProp NodeTypeProp = _CswNbtResources.MetaData.getNodeTypePropLatestVersion(NodeTypePropId);
                    if (false == NodeTypeProp.IsUnique())    // case 27649
                    {
                        CswNbtSearchPropOrder.SearchOrder order = PropOrder.First(Order => Order.NodeTypePropId == NodeTypePropId);

                        JArray FilterSet = new JArray();
                        FiltersArr.Add(FilterSet);

                        // Sort by count descending, then alphabetically by gestalt
                        Dictionary <string, Int32> sortedDict = (from entry
                                                                 in PropCounts[NodeTypePropId]
                                                                 orderby entry.Value descending, entry.Key ascending
                                                                 select entry
                                                                 ).ToDictionary(pair => pair.Key, pair => pair.Value);
                        foreach (string Value in sortedDict.Keys)
                        {
                            Int32 Count = sortedDict[Value];
                            CswNbtSearchFilter Filter = makeFilter(NodeTypeProp, Value, Count, true, order.Source);
                            FilterSet.Add(Filter.ToJObject());
                        }
                    } // if( false == NodeTypeProp.IsUnique() )
                }     // foreach( Int32 NodeTypePropId in PropCounts.Keys.OrderBy( NodeTypePropId => PropOrder.First( Order => Order.NodeTypePropId == NodeTypePropId ).Order ) )
            }         // if( SingleNodeType )

            return(FiltersArr);
        } // FilterOptions()