Skip to content

Commit

Permalink
Merge branch 'feature/IJMP-1732-Working-sets-and-masks-deletions' int…
Browse files Browse the repository at this point in the history
…o 'release/v2.1.0'

IJMP-1732-Working-sets-and-masks-deletions

See merge request ijmp/for-mainframe!583
  • Loading branch information
ATsikhamirau committed Sep 24, 2024
2 parents 07d8d18 + 878be97 commit 399f9f9
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.ui.showYesNoDialog
import eu.ibagroup.formainframe.explorer.JesWorkingSetImpl
import eu.ibagroup.formainframe.explorer.ui.JesExplorerView
import eu.ibagroup.formainframe.explorer.ui.JesFilterNode
import eu.ibagroup.formainframe.explorer.ui.JesWsNode
import eu.ibagroup.formainframe.explorer.ui.getExplorerView
import eu.ibagroup.formainframe.explorer.ui.*
import eu.ibagroup.formainframe.utils.performUnitsDeletionBasedOnSelection
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty

/**
* Action class for delete JES node action (working set or filter)
Expand All @@ -40,39 +39,18 @@ class DeleteJesNodeAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val view = e.getExplorerView<JesExplorerView>() ?: return
val selected = view.mySelectedNodesData
// Delete selected JES working sets
selected
.map { it.node }
.filterIsInstance<JesWsNode>()
.forEach {
if (
showYesNoDialog(
title = "Deletion of JES Working Set ${it.unit.name}",
message = "Do you want to delete this JES Working Set from configs? Note: all data under it will be untouched",
project = e.project,
icon = AllIcons.General.QuestionDialog
)
) {
view.explorer.disposeUnit(it.unit as JesWorkingSetImpl)
}
}
// Delete selected job filters
selected
.map { it.node }
.filterIsInstance<JesFilterNode>()
.filter { view.explorer.isUnitPresented(it.unit) }
.forEach {
if (
showYesNoDialog(
title = "Deletion Of Jobs Filter",
message = "Do you want to delete this jobs filter with ${it.value} from configs? Note: all data under the filter will be untouched",
project = e.project,
icon = AllIcons.General.QuestionDialog
)
) {
it.unit.removeFilter(it.value)
}
}

// Find items to delete (working set node or filter node)
val suitableToDelete = selected.map { it.node }
.filter { node -> node is JesWsNode || node is JesFilterNode }

val (workingSetsToDelete, selectedFilters) = suitableToDelete.partition { node -> node is JesWsNode }
val jesFiltersToDelete = selectedFilters.filter { jesFilter -> !workingSetsToDelete.contains(jesFilter.parent) }

// Delete working sets and filters that do not belong to them
(workingSetsToDelete + jesFiltersToDelete).ifNotEmpty {
performUnitsDeletionBasedOnSelection(e.project, null, view)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ import eu.ibagroup.formainframe.explorer.FilesWorkingSet
import eu.ibagroup.formainframe.telemetry.NotificationsService
import eu.ibagroup.formainframe.utils.getMinimalCommonParents
import eu.ibagroup.formainframe.utils.getParentsChain
import eu.ibagroup.formainframe.utils.performUnitsDeletionBasedOnSelection
import eu.ibagroup.formainframe.vfs.MFVirtualFile
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
import java.awt.Toolkit
import java.awt.datatransfer.DataFlavor
import java.awt.datatransfer.Transferable
Expand Down Expand Up @@ -440,63 +442,20 @@ class FileExplorerView(
/** Deletes files corresponding to the selected nodes data. */
override fun deleteElement(dataContext: DataContext) {
val selected = mySelectedNodesData
selected.map { it.node }
.filterIsInstance<FilesWorkingSetNode>()
.forEach {
if (
showYesNoDialog(
title = "Deletion of Working Set ${it.unit.name}",
message = "Do you want to delete this Working Set from configs? Note: all data under it will be untouched",
project = project,
icon = AllIcons.General.QuestionDialog
)
) {
explorer.disposeUnit(it.unit as FilesWorkingSet)
}
}
selected.map { it.node }
.filterIsInstance<DSMaskNode>()
.filter { explorer.isUnitPresented(it.unit) }
.forEach {
if (
showYesNoDialog(
title = "Deletion of DS Mask ${it.value.mask}",
message = "Do you want to delete this mask from configs? Note: all data sets under it will be untouched",
project = project,
icon = AllIcons.General.QuestionDialog
)
) {
it.cleanCache(
recursively = true,
cleanFetchProviderCache = true,
cleanBatchedQuery = true,
sendTopic = false
)
it.unit.removeMask(it.value)
}
}
selected.map { it.node }
.filterIsInstance<UssDirNode>()
.filter { it.isUssMask && explorer.isUnitPresented(it.unit) }
.forEach {
val node = it
if (
showYesNoDialog(
title = "Deletion of Uss Path Root ${node.value.path}",
message = "Do you want to delete this USS path root from configs? Note: all files under it will be untouched",
project = project,
icon = AllIcons.General.QuestionDialog
)
) {
node.cleanCache(
recursively = true,
cleanFetchProviderCache = true,
cleanBatchedQuery = true,
sendTopic = false
)
node.unit.removeUssPath(node.value)
}
}

// Find items to delete (working set node or dataset mask node or USS mask node)
val suitableToDelete = selected.map { it.node }
.filter { node -> node is FilesWorkingSetNode || node is DSMaskNode || (node is UssDirNode && node.isUssMask) }

val (workingSetsToDelete, selectedMasks) = suitableToDelete.partition { node -> node is FilesWorkingSetNode }
val masksToDelete = selectedMasks.filter { mask -> !workingSetsToDelete.contains(mask.parent) }

// Delete working sets and masks that do not belong to them
(workingSetsToDelete + masksToDelete).ifNotEmpty {
performUnitsDeletionBasedOnSelection(project, this@FileExplorerView, null)
}

// perform files deletion
val nodeAndFilePairs = optimizeDeletion(selected)
if (nodeAndFilePairs.isNotEmpty()) {
val files = nodeAndFilePairs.map { it.second }.toSet().toList()
Expand Down
82 changes: 82 additions & 0 deletions src/main/kotlin/eu/ibagroup/formainframe/utils/explorerUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2020-2024 IBA Group.
*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBA Group 2020
* Contributors:
* IBA Group
* Zowe Community
*/
package eu.ibagroup.formainframe.utils

import com.intellij.icons.AllIcons
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.showYesNoDialog
import eu.ibagroup.formainframe.explorer.FilesWorkingSet
import eu.ibagroup.formainframe.explorer.JesWorkingSetImpl
import eu.ibagroup.formainframe.explorer.ui.*

/**
* Function is used to perform units deletion based on current selection
* Function accepts only:
* Files Working Set nodes
* Dataset Mask nodes
* Uss Directory Root nodes (isUssMask = true)
* JES Working Set nodes
* JES Filter nodes
* @param project
* @param fileExplorerView
* @param jesExplorerView
* @receiver List of filtered nodes by type, e.g. List<DSMaskNode> dsMasksToDelete
*/
fun <T : ExplorerTreeNode<*, *>> List<T>.performUnitsDeletionBasedOnSelection(
project: Project?,
fileExplorerView: FileExplorerView?,
jesExplorerView: JesExplorerView?
) {
var unitTypes = when (first()) {
is FilesWorkingSetNode -> "File Working Set(s)"
is DSMaskNode -> "Dataset Mask(s)"
is UssDirNode -> "Uss Root Path(s)"
is JesWsNode -> "JES Working Set(s)"
else -> "Job Filter(s)"
}
// Change the header and body of the dialog in case both JesWsNode's and JesFilter's are present in receiver list
unitTypes =
if (this.filterIsInstance<JesWsNode>().isNotEmpty() && this.filterIsInstance<JesWsNode>().size != this.size)
"Jes Working Set(s) and Jes Filter(s)"
else unitTypes

if (showYesNoDialog(
title = "Confirm $unitTypes Deletion",
message = "Do you want to delete selected $unitTypes from config? Note: all data under it(them) will be untouched",
project = project,
icon = AllIcons.General.QuestionDialog
)
) {
forEach {
when (val node: T = it) {
is FilesWorkingSetNode -> fileExplorerView?.explorer?.disposeUnit(node.unit as FilesWorkingSet)
is DSMaskNode, is UssDirNode -> {
(node as FileFetchNode<*,*,*,*,*,*>).cleanCache(
recursively = true,
cleanFetchProviderCache = true,
cleanBatchedQuery = true,
sendTopic = false
)
}
}
when (val node: T = it) {
is DSMaskNode -> node.unit.removeMask(node.value)
is UssDirNode -> node.unit.removeUssPath(node.value)
is JesWsNode -> jesExplorerView?.explorer?.disposeUnit(node.unit as JesWorkingSetImpl)
is JesFilterNode -> node.unit.removeFilter(node.value)
}
}
}
}
Loading

0 comments on commit 399f9f9

Please sign in to comment.