-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Uladzislau <[email protected]>
- Loading branch information
Showing
54 changed files
with
1,040 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...n/kotlin/eu/ibagroup/formainframe/dataops/operations/mover/names/CopyPasteNameResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 | ||
*/ | ||
package org.zowe.explorer.dataops.operations.mover.names | ||
|
||
import com.intellij.openapi.extensions.ExtensionPointName | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import org.zowe.explorer.dataops.DataOpsComponentFactory | ||
|
||
interface CopyPasteNameResolverFactory: DataOpsComponentFactory<CopyPasteNameResolver> | ||
|
||
/** | ||
* Class to represent a name resolution for conflicting situation. | ||
* @author Valiantsin Krus | ||
*/ | ||
interface CopyPasteNameResolver { | ||
companion object { | ||
@JvmField | ||
val EP = ExtensionPointName.create<CopyPasteNameResolverFactory>("org.zowe.explorer.nameResolver") | ||
} | ||
|
||
/** | ||
* Determines whether this name resolver could resolve conflict for passed files or not. | ||
* @param source source file to copy in destination folder (or folder-like entity). | ||
* @param destination folder-like entity to copy file to. | ||
* @return true if this name resolver could dot it or false otherwise. | ||
*/ | ||
fun accepts(source: VirtualFile, destination: VirtualFile): Boolean | ||
|
||
/** | ||
* Finds child in destination folder that conflicts with source file. | ||
* @param source source file to copy in destination folder (or folder-like entity). | ||
* @param destination folder-like entity to copy file to. | ||
* @return instance of conflicting child file or null if it was not found. | ||
*/ | ||
fun getConflictingChild(source: VirtualFile, destination: VirtualFile): VirtualFile? | ||
|
||
/** | ||
* Creates new name for source file to make it possible to be copied in destination folder. | ||
* @param source source file to copy in destination folder (or folder-like entity). | ||
* @param destination folder-like entity to copy file to. | ||
* @return string with new file name. | ||
*/ | ||
fun resolve(source: VirtualFile, destination: VirtualFile): String | ||
} |
37 changes: 37 additions & 0 deletions
37
...in/kotlin/eu/ibagroup/formainframe/dataops/operations/mover/names/DatasetOrDirResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 | ||
*/ | ||
package org.zowe.explorer.dataops.operations.mover.names | ||
|
||
import com.intellij.openapi.vfs.VirtualFile | ||
import org.zowe.explorer.dataops.DataOpsManager | ||
import org.zowe.explorer.dataops.attributes.RemoteDatasetAttributes | ||
|
||
class DatasetOrDirResolverFactory : CopyPasteNameResolverFactory { | ||
override fun buildComponent(dataOpsManager: DataOpsManager): CopyPasteNameResolver { | ||
return DatasetOrDirResolver(dataOpsManager) | ||
} | ||
} | ||
|
||
/** | ||
* Implementation of [CopyPasteNameResolver] for copying dataset or directory to uss or local system. | ||
* @author Valiantsin Krus | ||
*/ | ||
class DatasetOrDirResolver(val dataOpsManager: DataOpsManager): IndexedNameResolver() { | ||
override fun accepts(source: VirtualFile, destination: VirtualFile): Boolean { | ||
val sourceAttributes = dataOpsManager.tryToGetAttributes(source) | ||
val destinationAttributes = dataOpsManager.tryToGetAttributes(destination) | ||
return (source.isDirectory || sourceAttributes is RemoteDatasetAttributes) && destinationAttributes !is RemoteDatasetAttributes | ||
} | ||
|
||
|
||
override fun resolveNameWithIndex(source: VirtualFile, destination: VirtualFile, index: Int?): String { | ||
return if (index == null) source.name else "${source.name}_(${index})" | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ain/kotlin/eu/ibagroup/formainframe/dataops/operations/mover/names/DefaultNameResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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 | ||
*/ | ||
package org.zowe.explorer.dataops.operations.mover.names | ||
|
||
import com.intellij.openapi.vfs.VirtualFile | ||
|
||
/** | ||
* Implementation of [IndexedNameResolver] that is used by default (if no one other name resolver was found) | ||
* It just adds _(<index>) to the end of the file name before extension. | ||
* @author Valiantsin Krus | ||
*/ | ||
class DefaultNameResolver: IndexedNameResolver() { | ||
override fun accepts(source: VirtualFile, destination: VirtualFile): Boolean { | ||
return true | ||
} | ||
|
||
override fun resolveNameWithIndex(source: VirtualFile, destination: VirtualFile, index: Int?): String { | ||
val sourceName = source.name | ||
return if (index == null) { | ||
sourceName | ||
} else { | ||
val extension = if (sourceName.contains(".")) sourceName.substringAfterLast(".") else null | ||
val newNameWithoutExtension = "${sourceName.substringBeforeLast(".")}_(${index})" | ||
if (extension != null) "$newNameWithoutExtension.$extension" else newNameWithoutExtension | ||
} | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...ain/kotlin/eu/ibagroup/formainframe/dataops/operations/mover/names/IndexedNameResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 | ||
*/ | ||
package org.zowe.explorer.dataops.operations.mover.names | ||
|
||
import com.intellij.openapi.vfs.VirtualFile | ||
|
||
/** | ||
* Name resolver that generates new name based on the index (e.g. file_(1), file_(2) and etc.) | ||
* This is an abstract class, it only finds the necessary index but doesn't create a new name. | ||
* It could be, for example file1, file2, file3. It all depends on implementation needs. | ||
* @author Valiantsin Krus | ||
*/ | ||
abstract class IndexedNameResolver: CopyPasteNameResolver { | ||
|
||
override fun getConflictingChild(source: VirtualFile, destination: VirtualFile): VirtualFile? { | ||
val rowNameToCopy = resolveNameWithIndex(source, destination, null) | ||
return destination.children.firstOrNull { it.name == rowNameToCopy } | ||
} | ||
|
||
/** | ||
* Creates new name for a source file based on passed index. | ||
* @param source source file to copy in destination folder (or folder-like entity). | ||
* @param destination folder-like entity to copy file to. | ||
* @param index generated index to add to the source name. If it is null, then no index is needed to add. | ||
* @return new name with joined index. | ||
*/ | ||
abstract fun resolveNameWithIndex(source: VirtualFile, destination: VirtualFile, index: Int?): String | ||
|
||
override fun resolve(source: VirtualFile, destination: VirtualFile): String { | ||
var newName = resolveNameWithIndex(source, destination, null) | ||
var index = 1 | ||
while (destination.children.any { it.name == newName }) { | ||
newName = resolveNameWithIndex(source, destination, index++) | ||
} | ||
return newName | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ain/kotlin/eu/ibagroup/formainframe/dataops/operations/mover/names/NotSeqToPDSResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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 | ||
*/ | ||
package org.zowe.explorer.dataops.operations.mover.names | ||
|
||
import com.intellij.openapi.vfs.VirtualFile | ||
import org.zowe.explorer.dataops.DataOpsManager | ||
import org.zowe.explorer.dataops.attributes.RemoteDatasetAttributes | ||
|
||
class NotSeqToPDSResolverFactory : CopyPasteNameResolverFactory { | ||
override fun buildComponent(dataOpsManager: DataOpsManager): CopyPasteNameResolver { | ||
return NotSeqToPDSResolver(dataOpsManager) | ||
} | ||
} | ||
|
||
/** | ||
* Implementation of [CopyPasteNameResolver] for copying anything except of Sequential Dataset to PDS. | ||
* @author Valiantsin Krus | ||
*/ | ||
class NotSeqToPDSResolver(val dataOpsManager: DataOpsManager) : IndexedNameResolver() { | ||
override fun accepts(source: VirtualFile, destination: VirtualFile): Boolean { | ||
val sourceAttributes = dataOpsManager.tryToGetAttributes(source) | ||
val destinationAttributes = dataOpsManager.tryToGetAttributes(destination) | ||
return destinationAttributes is RemoteDatasetAttributes && | ||
sourceAttributes !is RemoteDatasetAttributes | ||
} | ||
|
||
override fun resolveNameWithIndex(source: VirtualFile, destination: VirtualFile, index: Int?): String { | ||
val memberName = source.name.filter { it.isLetterOrDigit() }.uppercase().ifEmpty { "EMPTY" } | ||
return if (index == null) memberName.take(8) else "${memberName.take(7)}$index" | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/eu/ibagroup/formainframe/dataops/operations/mover/names/SeqToPDSResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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 | ||
*/ | ||
package org.zowe.explorer.dataops.operations.mover.names | ||
|
||
import com.intellij.openapi.vfs.VirtualFile | ||
import org.zowe.explorer.dataops.DataOpsManager | ||
import org.zowe.explorer.dataops.attributes.RemoteDatasetAttributes | ||
|
||
class SeqToPDSResolverFactory : CopyPasteNameResolverFactory { | ||
override fun buildComponent(dataOpsManager: DataOpsManager): CopyPasteNameResolver { | ||
return SeqToPDSResolver(dataOpsManager) | ||
} | ||
} | ||
|
||
/** | ||
* Implementation of [CopyPasteNameResolver] for copying Sequential Dataset to PDS. | ||
* @author Valiantsin Krus | ||
*/ | ||
class SeqToPDSResolver(val dataOpsManager: DataOpsManager) : IndexedNameResolver() { | ||
override fun accepts(source: VirtualFile, destination: VirtualFile): Boolean { | ||
val sourceAttributes = dataOpsManager.tryToGetAttributes(source) | ||
val destinationAttributes = dataOpsManager.tryToGetAttributes(destination) | ||
return sourceAttributes is RemoteDatasetAttributes && | ||
!source.isDirectory && | ||
destinationAttributes is RemoteDatasetAttributes | ||
} | ||
|
||
override fun resolveNameWithIndex(source: VirtualFile, destination: VirtualFile, index: Int?): String { | ||
val lastQualifier = source.name.split(".").last() | ||
return if (index == null) lastQualifier else "${lastQualifier.take(7)}${index}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.