public void Delete(CswNbtResource Return, CswNbtAPIGenericRequest GenericRequest) { if (hasPermission(GenericRequest, Return)) { try { CswNbtNode DoomedNode = _CswNbtResources.Nodes.GetNode(GenericRequest.NodeId); if (null != DoomedNode && GenericRequest.MetaDataName == DoomedNode.getNodeType().NodeTypeName) { DoomedNode.delete(); Return.Status = HttpStatusCode.OK; } else { Return.Status = HttpStatusCode.NotFound; } } catch (Exception) { Return.Status = HttpStatusCode.InternalServerError; } } else { Return.Status = HttpStatusCode.Forbidden; } }
} // update() private void _fixBadScheudlesAndTasks() { ICswNbtTree BadSchedulesTree = _CswNbtSchemaModTrnsctn.getTreeFromView( _getBadSchedulesAndTasksView(), false ); BadSchedulesTree.goToRoot(); for( int i = 0; i < BadSchedulesTree.getChildNodeCount(); i++ ) { BadSchedulesTree.goToNthChild( i ); CswNbtObjClassGenerator ScheduleNode = BadSchedulesTree.getNodeForCurrentPosition(); int TargetTypeId = ScheduleNode.NodeTypeId == AssemblyScheduleNT.NodeTypeId ? AssemblyTaskNT.NodeTypeId : EquipmentTaskNT.NodeTypeId; ScheduleNode.TargetType.SelectedNodeTypeIds.Clear(); ScheduleNode.TargetType.SelectedNodeTypeIds.Add( CswConvert.ToString( TargetTypeId ) ); ScheduleNode.postChanges( false ); for( int j = 0; j < BadSchedulesTree.getChildNodeCount(); j++ ) { BadSchedulesTree.goToNthChild( j ); CswNbtNode OldTaskNode = BadSchedulesTree.getNodeForCurrentPosition(); CswNbtObjClassTask NewTaskNode = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( TargetTypeId, CswEnumNbtMakeNodeOperation.WriteNode ); NewTaskNode.Node.copyPropertyValues( OldTaskNode ); NewTaskNode.Owner.RelatedNodeId = ScheduleNode.Owner.RelatedNodeId; OldTaskNode.delete(); NewTaskNode.postChanges( false ); BadSchedulesTree.goToParentNode(); } BadSchedulesTree.goToParentNode(); } }
}//getExistingNodes() public static void deleteExistingNodes(ICswResources CswResources, CswNbtImportWcf.DltExistingNodesReturn Ret, object EmptyObject) { // In this case, we need to create a new instance of CswNbtResources // so that we can delete all nodes (including MLM nodes) CswNbtResources _CswNbtResources = CswNbtResourcesFactory.makeCswNbtResources(CswEnumAppType.Nbt, CswEnumSetupMode.NbtWeb, false); //ExcludeDisabledModules needs to be false _CswNbtResources.AccessId = CswResources.AccessId; _CswNbtResources.InitCurrentUser = _initUser; Collection <CswNbtImportWcf.DltExistingNodesReturn.DltExistingNodesReturnData.DoomedNode> DoomedNodes = _retriveDoomedNodes(_CswNbtResources); foreach (CswNbtImportWcf.DltExistingNodesReturn.DltExistingNodesReturnData.DoomedNode DoomedNode in DoomedNodes) { try { CswPrimaryKey NodePrimeKey = new CswPrimaryKey(); NodePrimeKey.FromString("nodes_" + DoomedNode.NodeId); CswNbtNode CurrentNode = _CswNbtResources.Nodes[NodePrimeKey]; if (null != CurrentNode) { CurrentNode.delete(true, true, false); } } catch (Exception exception) { throw new CswDniException(CswEnumErrorType.Error, "Error deleting node: ", exception.Message); } } _CswNbtResources.finalize(); Ret.Data.DeleteSuccessful = true; }
private void _deleteNode(string NodePk) { CswPrimaryKey DeleteNodePk = new CswPrimaryKey(); DeleteNodePk.FromString(NodePk); if (Int32.MinValue != DeleteNodePk.PrimaryKey) { CswNbtNode DeleteNode = _CswNbtResources.Nodes[DeleteNodePk]; if (DeleteNode != null) { DeleteNode.delete(); } } }
internal void DeleteTestNodes() { List <Int32> TestNodePKs = _getNodesAboveHighWaterMark(); TestNodePKs.Sort(); TestNodePKs.Reverse(); foreach (Int32 NodePK in TestNodePKs) { CswPrimaryKey NodeId = new CswPrimaryKey("nodes", NodePK); CswNbtNode Node = _CswNbtResources.Nodes[NodeId]; if (null != Node) { Node.delete(DeleteAllRequiredRelatedNodes: true, OverridePermissions: true); } } }
private bool _DeleteNode(CswPrimaryKey NodePk, CswNbtResources NbtResources, out string NodeName, bool DeleteAllRequiredRelatedNodes = false) { bool ret = false; NodeName = ""; CswNbtNode NodeToDelete = NbtResources.Nodes[NodePk]; if (null != NodeToDelete) { CswNbtMetaDataNodeType NodeType = NodeToDelete.getNodeType(); NodeName = NodeType.NodeTypeName + ": " + NodeToDelete.NodeName; NodeToDelete.delete(DeleteAllRequiredRelatedNodes: DeleteAllRequiredRelatedNodes); ret = true; } return(ret); }
public override void update() { CswNbtMetaDataObjectClass SDSOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass(CswEnumNbtObjectClass.SDSDocumentClass); CswNbtMetaDataObjectClassProp MaterialOCP = SDSOC.getObjectClassProp(CswNbtObjClassSDSDocument.PropertyName.Owner); CswNbtView OrphanedSDSDocsView = _CswNbtSchemaModTrnsctn.makeView(); CswNbtViewRelationship RootVR = OrphanedSDSDocsView.AddViewRelationship(SDSOC, false); OrphanedSDSDocsView.AddViewPropertyAndFilter(RootVR, MaterialOCP, null, CswEnumNbtSubFieldName.NodeID, false, CswEnumNbtFilterMode.Null); ICswNbtTree OrphanedSDSDocsTree = _CswNbtSchemaModTrnsctn.getTreeFromView(OrphanedSDSDocsView, false); for (int i = 0; i < OrphanedSDSDocsTree.getChildNodeCount(); i++) { OrphanedSDSDocsTree.goToNthChild(i); CswNbtNode OrphanedSDSDoc = OrphanedSDSDocsTree.getNodeForCurrentPosition(); OrphanedSDSDoc.delete(false, true, false); OrphanedSDSDocsTree.goToParentNode(); } }
}//getTreeViewOfFutureNodes() public void deleteExistingFutureNodes(CswNbtNode GeneratorNode) { CswNbtView FutureNodesView = getTreeViewOfFutureNodes(new CswNbtNode[] { GeneratorNode }); ICswNbtTree TargetNodeTree = _CswNbtResources.Trees.getTreeFromView(_CswNbtResources.CurrentNbtUser, FutureNodesView, true, false, false); TargetNodeTree.goToRoot(); if (TargetNodeTree.getChildNodeCount() > 0) { TargetNodeTree.goToNthChild(0); //go to Generator node int TotalNodes = TargetNodeTree.getChildNodeCount(); if (TotalNodes > 0) { for (int idx = 0; idx < TotalNodes; idx++) { TargetNodeTree.goToNthChild(idx); CswNbtNode CurrentNode = TargetNodeTree.getNodeForCurrentPosition(); CurrentNode.delete(); TargetNodeTree.goToParentNode(); } } //if we have nodes } //if we got a Generator node }
public void threadCallBack(ICswResources CswResources) { _LogicRunStatus = CswEnumScheduleLogicRunStatus.Running; CswNbtResources CurrentSchemaResources = (CswNbtResources)CswResources; CurrentSchemaResources.AuditContext = "Scheduler Task: " + RuleName; if (CswEnumScheduleLogicRunStatus.Stopping != _LogicRunStatus) { try { if (null == _MasterSchemaResources) { _MasterSchemaResources = _getMasterSchemaResources((CswNbtResources)CswResources); } if (null != _MasterSchemaResources) { if (_StaleDataExists) { //The higher level classes that CswSessions is used require http reponse and request objects, //so we have to use th bare CswSessions class directly. CswSessionsFactory CswSessionsFactory = new CswSessionsFactory(CswEnumAppType.Nbt, _MasterSchemaResources.SetupVbls, _MasterSchemaResources.CswDbCfgInfo, _MasterSchemaResources.CswLogger); CswSessions CswSessions = CswSessionsFactory.make(CswEnumSessionsStorageType.DbStorage, _MasterSchemaResources); //We must get and delete the session data from the master schema, //but delete expired temp nodes from the current schema CswTableSelect SessionListSelect = _MasterSchemaResources.makeCswTableSelect("delete_expired_sessionlist_records", "sessionlist"); DataTable SessionListTable = SessionListSelect.getTable(_SessionListWhere(CurrentSchemaResources.AccessId)); CswNbtSessionDataMgr CswNbtSessionDataMgr = new CswNbtSessionDataMgr(CurrentSchemaResources); foreach (DataRow CurrentRow in SessionListTable.Rows) { //Step # 1: Remove stranded temp nodes in the _current_ schema using session id we got from master schema session list string CurrentSessionId = CurrentRow["sessionid"].ToString(); CswNbtSessionDataMgr.removeAllSessionData(CurrentSessionId); //Step # 2: Remove Session Record from master schema //If our session management code were organized differently, we would be calling //CswSessionManager::clearSession() instead of rolloing our own here. In the future //CswSessionManager::clearSession() could acquire functionality that we would miss. //Moreover, it calls an OnDeathenticate() event that is passsed in from //CswSessionResourcesNbt. Using the aforementioned chain of classes here would be //problematic because of said classes deep-endencies on, for example, various http //classes. So, if we add something in one place that the other place should also be //doing, we'll have to add it manually. CswSessionsListEntry CswSessionsListEntry = new CswSessionsListEntry(CurrentSessionId); CswSessions.remove(CswSessionsListEntry); } //iterate session records //Case 30266 - remove all rows in the current schema's session_data with no corresponding session id in the master schema's SessionList CswTableUpdate DoomedSessionDataTU = CurrentSchemaResources.makeCswTableUpdate("purge_doomed_session_data", "session_data"); DataTable DoomedSessionDataDT = DoomedSessionDataTU.getTable(_getMasterSessionIdsWhere()); foreach (DataRow DoomedRow in DoomedSessionDataDT.Rows) { DoomedRow.Delete(); } DoomedSessionDataTU.update(DoomedSessionDataDT); //case 31415 - there are still temp nodes hanging around, this should kill anything with a sessionid that has previously expired CswArbitrarySelect SelectOrphanedNodes = CurrentSchemaResources.makeCswArbitrarySelect("orphaned_nodeids", "select nodeid from nodes n left outer join sessionlist s on n.sessionid=s.sessionid where istemp=1 and s.sessionid is null"); foreach (DataRow Row in SelectOrphanedNodes.getTable().Rows) { CswPrimaryKey NodeId = new CswPrimaryKey("nodes", CswConvert.ToInt32(Row["nodeid"])); if (CswTools.IsPrimaryKey(NodeId)) { CswNbtNode TempNode = CurrentSchemaResources.Nodes[NodeId]; if (null != TempNode) { TempNode.delete(true, true); } } } //for each node with an inactive sessionid } //_StaleDataExists _CswScheduleLogicDetail.StatusMessage = "Completed without error"; _LogicRunStatus = CswEnumScheduleLogicRunStatus.Succeeded; //last line } else { CswResources.CswLogger.reportError(new CswDniException("Unable to process sessionlist records: The master schmea resource object is null")); } }//try catch (Exception Exception) { _CswScheduleLogicDetail.StatusMessage = "CswScheduleLogicNbtPurgeSessionData exception: " + Exception.Message + "; " + Exception.StackTrace; CurrentSchemaResources.logError(new CswDniException(_CswScheduleLogicDetail.StatusMessage)); _LogicRunStatus = CswEnumScheduleLogicRunStatus.Failed; }//catch finally { _StaleDataExists = false; _MasterSchemaResources.release(); //These must be marked null so that they get garbage collected _MasterSchemaResources = null; } } //if we're not shutting down } //threadCallBack()
public void updateDemoData( List<string> node_ids_convert_to_non_demo, List<string> view_ids_convert_to_non_demo, List<string> node_ids_remove, List<string> view_ids_remove, List<string> Errors ) { //***************** //just in case: converto-to-non-demo takes precendence over delete? foreach( string CurrentViewId in view_ids_convert_to_non_demo ) { if( view_ids_remove.Contains( CurrentViewId ) ) { view_ids_remove.Remove( CurrentViewId ); } } foreach( string CurrentnodeId in node_ids_convert_to_non_demo ) { if( node_ids_remove.Contains( CurrentnodeId ) ) { node_ids_remove.Remove( CurrentnodeId ); } } //********************** // Views if( view_ids_convert_to_non_demo.Count > 0 ) { CswCommaDelimitedString ViewIdsToConvert = new CswCommaDelimitedString(); ViewIdsToConvert.FromArray( view_ids_convert_to_non_demo.ToArray() ); try { CswTableUpdate ConvertViewsToNonDemoUpdate = _CswNbtResources.makeCswTableUpdate( "update_views_to_non_demo", "node_views" ); DataTable ViewsTable = ConvertViewsToNonDemoUpdate.getTable( " where nodeviewid in (" + ViewIdsToConvert.ToString() + ")" ); foreach( DataRow CurrentRow in ViewsTable.Rows ) { CurrentRow["isdemo"] = CswConvert.ToDbVal( false ); } ConvertViewsToNonDemoUpdate.update( ViewsTable ); } catch( Exception Exception ) { Errors.Add( "Error converting demo views " + ViewIdsToConvert.ToString() + " to non-demo: " + Exception.Message ); } }//if we have view to udpate if( view_ids_remove.Count > 0 ) { CswCommaDelimitedString ViewIdsToRemove = new CswCommaDelimitedString(); ViewIdsToRemove.FromArray( view_ids_remove.ToArray() ); try { CswTableUpdate ConvertViewsToNonDemoUpdate = _CswNbtResources.makeCswTableUpdate( "delete_demo_views", "node_views" ); string WhereClause = " where nodeviewid in (" + ViewIdsToRemove.ToString() + ")"; DataTable ViewsTable = ConvertViewsToNonDemoUpdate.getTable( WhereClause ); foreach( DataRow CurrentRow in ViewsTable.Rows ) { CurrentRow.Delete(); } ConvertViewsToNonDemoUpdate.update( ViewsTable ); } catch( Exception Exception ) { Errors.Add( "Error removing demo views " + ViewIdsToRemove.ToString() + " : " + Exception.Message ); } }//if we have view to udpate //*************************************************************** // ***** Nodes //********************** if( node_ids_convert_to_non_demo.Count > 0 ) { CswDelimitedString NodesIdsToconvert = new CswCommaDelimitedString(); NodesIdsToconvert.FromArray( node_ids_convert_to_non_demo.ToArray() ); try { CswTableUpdate ConvertNodesToNonDemoUpdate = _CswNbtResources.makeCswTableUpdate( "update_Nodes_to_non_demo", "nodes" ); DataTable NodesTable = ConvertNodesToNonDemoUpdate.getTable( " where Nodeid in (" + NodesIdsToconvert + ")" ); foreach( DataRow CurrentRow in NodesTable.Rows ) { CurrentRow["isdemo"] = CswConvert.ToDbVal( false ); } ConvertNodesToNonDemoUpdate.update( NodesTable ); } catch( Exception Exception ) { Errors.Add( "Error converting nodes " + NodesIdsToconvert.ToString() + " to non-demo: " + Exception.Message ); } }//if we have nodes to convert if( node_ids_remove.Count > 0 ) { foreach( string NodeIdToRemove in node_ids_remove ) { try { CswPrimaryKey NodePrimeKey = new CswPrimaryKey(); NodePrimeKey.FromString( "nodes_" + NodeIdToRemove ); CswNbtNode CurrentNode = _CswNbtResources.Nodes[NodePrimeKey]; if( null != CurrentNode ) { CurrentNode.delete(); } } catch( Exception Exception ) { string Error = "Error removing nodes to non-demo: " + Exception.Message; Errors.Add( Error ); } }//iterate node ids to remove }//if we have nodes to delete }//updateDemoData()
} // _applyMergeChoicesToNode() public CswNbtView finishMerge(MergeInfoData Choices) { CswNbtView view = new CswNbtView(_CswNbtResources); CswNbtNode firstMergedNode = null; foreach (MergeInfoData.MergeInfoNodePair nodePair in Choices.NodePairs) { // Remove the temp node CswNbtNode NodeTemp = _CswNbtResources.Nodes[nodePair.NodeTempId]; if (null != NodeTemp) { NodeTemp.delete(DeleteAllRequiredRelatedNodes: false, OverridePermissions: true, ValidateRequiredRelationships: false); } // Merge Node1 into Node2, and delete Node1 CswNbtNode Node1 = _CswNbtResources.Nodes[nodePair.Node1Id]; CswNbtNode Node2 = _CswNbtResources.Nodes[nodePair.Node2Id]; if (null != Node1 && null != Node2) { // Store the first node merged to return if (null == firstMergedNode) { firstMergedNode = Node2; } // Apply the merge to Node2 _applyMergeChoicesToNode(Choices, nodePair, Node2); Node2.postChanges(ForceUpdate: false, IsCopy: false, OverrideUniqueValidation: true); // Update any references to point to node2 foreach (MergeInfoData.MergeInfoNodeReference Ref in nodePair.NodeReferences) { CswNbtNode refNode = _CswNbtResources.Nodes[Ref.NodeId]; if (refNode.Properties[Ref.NodeTypePropId].getFieldTypeValue() == CswEnumNbtFieldType.UserSelect) { // Special case: UserSelect refNode.Properties[Ref.NodeTypePropId].AsUserSelect.RemoveUser(Node1.NodeId); refNode.Properties[Ref.NodeTypePropId].AsUserSelect.AddUser(Node2.NodeId); refNode.Properties[Ref.NodeTypePropId].AsUserSelect.SyncGestalt(); } else { // Node Reference refNode.Properties[Ref.NodeTypePropId].AsNodeReference.ReferencedNodeId = Node2.NodeId; refNode.Properties[Ref.NodeTypePropId].AsNodeReference.RefreshNodeName(); } refNode.postChanges(ForceUpdate: false, IsCopy: false, OverrideUniqueValidation: true); } // Delete merged node 1 Node1.delete(DeleteAllRequiredRelatedNodes: false, OverridePermissions: true, ValidateRequiredRelationships: false); } // if( null != Node1 && null != Node2 ) } // foreach( MergeInfoData.MergeInfoNodePair nodePair in Choices.NodePairs ) // Return a view of the first merged node if (null != firstMergedNode) { view = firstMergedNode.getViewOfNode(includeDefaultFilters: false); } return(view); } // finishMerge()
public override void update() { // CISPro Report Group (created in CswUpdateSchema_02H_28562C) should only be accessible to CISPro roles CswNbtMetaDataObjectClass ReportGroupOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswEnumNbtObjectClass.ReportGroupClass ); CswNbtMetaDataObjectClass PermissionOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswEnumNbtObjectClass.ReportGroupPermissionClass ); CswNbtMetaDataObjectClass RoleOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswEnumNbtObjectClass.RoleClass ); CswNbtMetaDataObjectClassProp GroupNameOCP = ReportGroupOC.getObjectClassProp( CswNbtObjClassReportGroup.PropertyName.Name ); CswNbtMetaDataObjectClassProp PermissionGroupOCP = PermissionOC.getObjectClassProp( CswNbtObjClassReportGroupPermission.PropertyName.PermissionGroup ); CswNbtMetaDataObjectClassProp RoleNameOCP = RoleOC.getObjectClassProp( CswNbtObjClassRole.PropertyName.Name ); // Delete existing (default) permissions CswNbtView View = _CswNbtSchemaModTrnsctn.makeView(); CswNbtViewRelationship Rel1 = View.AddViewRelationship( ReportGroupOC, false ); View.AddViewPropertyAndFilter( Rel1, GroupNameOCP, Value: "CISPro Report Group", FilterMode: CswEnumNbtFilterMode.Equals ); CswNbtViewRelationship Rel2 = View.AddViewRelationship( Rel1, CswEnumNbtViewPropOwnerType.Second, PermissionGroupOCP, false ); ICswNbtTree results = _CswNbtSchemaModTrnsctn.getTreeFromView( View, true ); CswNbtObjClassReportGroup CISProGroup = null; for( Int32 g = 0; g < results.getChildNodeCount(); g++ ) { results.goToNthChild( g ); CISProGroup = results.getNodeForCurrentPosition(); for( Int32 p = 0; p < results.getChildNodeCount(); p++ ) { results.goToNthChild( p ); CswNbtNode PermNode = results.getNodeForCurrentPosition(); PermNode.delete( false, true ); results.goToParentNode(); } results.goToParentNode(); } // for( Int32 g = 0; g < results.getChildNodeCount(); g++ ) if( null != CISProGroup ) { // Get all cispro roles CswNbtView rolesView = _CswNbtSchemaModTrnsctn.makeView(); CswNbtViewRelationship parent = rolesView.AddViewRelationship( RoleOC, false ); rolesView.AddViewPropertyAndFilter( parent, MetaDataProp: RoleNameOCP, SubFieldName: CswEnumNbtSubFieldName.Text, FilterMode: CswEnumNbtFilterMode.Contains, Value: "cispro" ); rolesView.AddViewPropertyAndFilter( parent, Conjunction: CswEnumNbtFilterConjunction.Or, MetaDataProp: RoleNameOCP, SubFieldName: CswEnumNbtSubFieldName.Text, FilterMode: CswEnumNbtFilterMode.Equals, Value: "Administrator" ); rolesView.AddViewPropertyAndFilter( parent, Conjunction: CswEnumNbtFilterConjunction.Or, MetaDataProp: RoleNameOCP, SubFieldName: CswEnumNbtSubFieldName.Text, FilterMode: CswEnumNbtFilterMode.Equals, Value: CswNbtObjClassRole.ChemSWAdminRoleName ); ICswNbtTree rolesTree = _CswNbtSchemaModTrnsctn.getTreeFromView( rolesView, true ); Collection<CswPrimaryKey> CISProRoleIds = new Collection<CswPrimaryKey>(); for( int i = 0; i < rolesTree.getChildNodeCount(); i++ ) { rolesTree.goToNthChild( i ); CISProRoleIds.Add( rolesTree.getNodeIdForCurrentPosition() ); rolesTree.goToParentNode(); } // Grant permission to all cispro roles CswNbtMetaDataNodeType PermissionNT = PermissionOC.FirstNodeType; if( null != PermissionNT ) { foreach( CswPrimaryKey RoleId in CISProRoleIds ) { _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( PermissionNT.NodeTypeId, delegate( CswNbtNode NewNode ) { CswNbtPropertySetPermission NewPermission = NewNode; NewPermission.ApplyToAllRoles.Checked = CswEnumTristate.False; NewPermission.ApplyToAllWorkUnits.Checked = CswEnumTristate.True; NewPermission.PermissionGroup.RelatedNodeId = CISProGroup.NodeId; NewPermission.View.Checked = CswEnumTristate.True; NewPermission.Edit.Checked = CswEnumTristate.True; NewPermission.Role.RelatedNodeId = RoleId; } ); } } } // if( null != CISProGroup ) } // update()