Skip to content

Commit fc53339

Browse files
committed
GH-292 Configs rework
Signed-off-by: Uladzislau <[email protected]>
1 parent 3e397bb commit fc53339

File tree

69 files changed

+4739
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+4739
-180
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ tasks {
255255

256256
testLogging {
257257
events("passed", "skipped", "failed")
258+
// showStandardStreams = true
258259
}
259260

260261
// ignoreFailures = true

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ junit-platform = "1.11.3"
66
junit-jupiter = "5.11.3"
77
remoterobot = "0.11.23"
88
okhttp3 = "4.12.0"
9-
mockk = "1.13.12"
9+
mockk = "1.13.16"
1010
kotest = "5.9.1"
1111
jgrapht = "1.5.2"
1212
keytar = "1.0.0"

src/main/kotlin/org/zowe/explorer/config/ConfigSandboxImpl.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.zowe.explorer.utils.crudable.EntityWithUuid
2323
import org.zowe.explorer.utils.crudable.ReloadableEventHandler
2424
import org.zowe.explorer.utils.isThe
2525
import org.zowe.explorer.utils.isTheSameAs
26+
import org.zowe.explorer.v3.state.config.migration.performOldConfigStorageMigration
2627

2728
/** Stateful class to represent the plugin configs sandbox */
2829
data class SandboxState(
@@ -148,6 +149,7 @@ class ConfigSandboxImpl : ConfigSandbox {
148149
}
149150
} else {
150151
ConfigService.getService().crudable.replaceGracefully(clazz, list.stream())
152+
performOldConfigStorageMigration()
151153
}
152154
}
153155
}
@@ -157,10 +159,6 @@ class ConfigSandboxImpl : ConfigSandbox {
157159
/** Fetch the config service values to the config sandbox for each config class */
158160
override fun fetch() {
159161
synchronized(stateLock) {
160-
// rollbackSandbox<ConnectionConfig>()
161-
// rollbackSandbox<FilesWorkingSetConfig>()
162-
// rollbackSandbox<JesWorkingSetConfig>()
163-
// rollbackSandbox<Credentials>()
164162
ConfigService.getService()
165163
.getRegisteredConfigClasses()
166164
.forEach {
@@ -176,7 +174,6 @@ class ConfigSandboxImpl : ConfigSandbox {
176174
* Triggers the onReload event when the rollback is finished
177175
* @param clazz the class of configs to rollback in the config sandbox
178176
*/
179-
@Suppress("UNCHECKED_CAST")
180177
override fun <T> rollback(clazz: Class<out T>) {
181178
synchronized(stateLock) {
182179
val current = if (clazz.isThe<Credentials>()) {
@@ -196,6 +193,7 @@ class ConfigSandboxImpl : ConfigSandbox {
196193
listOfNotNull(classToList(clazz, state), classToList(clazz, initialState))
197194
.forEach { list ->
198195
list.clear()
196+
@Suppress("UNCHECKED_CAST")
199197
list.addAll(
200198
current
201199
.map { it.clone(clazz) }

src/main/kotlin/org/zowe/explorer/config/ConfigServiceImpl.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ import com.intellij.util.xmlb.XmlSerializerUtil
2020
import com.jetbrains.rd.util.UUID
2121
import org.zowe.explorer.config.connect.Credentials
2222
import org.zowe.explorer.utils.castOrNull
23-
import org.zowe.explorer.utils.crudable.AddFilter
24-
import org.zowe.explorer.utils.crudable.ConcurrentCrudable
25-
import org.zowe.explorer.utils.crudable.Crudable
26-
import org.zowe.explorer.utils.crudable.CrudableLists
27-
import org.zowe.explorer.utils.crudable.SimpleReadWriteAdapter
28-
import org.zowe.explorer.utils.crudable.UpdateFilter
23+
import org.zowe.explorer.utils.crudable.*
2924
import org.zowe.explorer.utils.loadConfigClass
3025
import org.zowe.explorer.utils.runIfTrue
3126
import java.time.Duration

src/main/kotlin/org/zowe/explorer/config/ConfigStartupActivity.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,34 @@ package org.zowe.explorer.config
1616

1717
import com.intellij.openapi.project.Project
1818
import com.intellij.openapi.startup.ProjectActivity
19+
import org.zowe.explorer.v3.state.config.cache.ConfigCacheService
20+
import org.zowe.explorer.v3.state.config.migration.performOldConfigStorageMigration
21+
import org.zowe.explorer.v3.state.settings.OtherSettingsService
22+
import org.zowe.explorer.v3.state.storage.StableStorage
23+
import org.zowe.explorer.v3.state.storage.StorageService
1924

2025
/**
21-
* Activity to prepare configs.
22-
* @author Valiantsin Krus.
26+
* Activity to prepare config services before the project startup.
27+
* Will load [StorageService] and [ConfigCacheService],
28+
* together with the previously saved configs from the related XML file.
29+
*
30+
* DEPRECATED: (The next functionality will be deleted in the future)
31+
* Will load [ConfigService] together with the previously saved configs from the related XML file
2332
*/
2433
class ConfigStartupActivity : ProjectActivity {
25-
26-
/** Registers all config classes and migrate configs to state v2. */
34+
@OptIn(StableStorage::class)
2735
override suspend fun execute(project: Project) {
2836
ConfigService.getService().apply {
2937
registerAllConfigClasses()
3038
}
39+
// The next line is needed to initialize subscriptions to storage service events.
40+
// WARNING: it is necessary to initialize the cache service together with the storage service!
41+
ConfigCacheService.getService()
42+
// The next line is needed to initialize subscriptions to storage service events.
43+
// WARNING: it is necessary to initialize the other settings service together with the storage service!
44+
OtherSettingsService.getService()
45+
StorageService.getService().registerConfigTypes()
46+
47+
performOldConfigStorageMigration()
3148
}
3249
}

src/main/kotlin/org/zowe/explorer/explorer/actions/RenameAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import org.zowe.explorer.v3.operations.OperationsService
3030
import org.zowe.explorer.v3.operations.RenameOperationData
3131
import org.zowe.explorer.vfs.MFVirtualFile
3232

33-
typealias ConnectionConfigNew = org.zowe.explorer.v3.ConnectionConfig
33+
typealias ConnectionConfigNew = org.zowe.explorer.v3.ConnectionConfigOldStruct
3434
typealias UssRequesterNew = org.zowe.explorer.v3.UssRequester<ConnectionConfigNew>
3535

3636
/**

src/main/kotlin/org/zowe/explorer/utils/crudable/SimpleReadWriteAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock
1919

2020
/**
2121
* Class that implements abstract read/write lock adapter class.
22-
* Triggers reentrant read/write lock on read or write lock
22+
* Triggers reentrant read/write lock on read/write lock getter
2323
*/
2424
class SimpleReadWriteAdapter : ReadWriteLocksAdapter() {
2525

src/main/kotlin/org/zowe/explorer/v3/ConnectionConfig.kt renamed to src/main/kotlin/org/zowe/explorer/v3/ConnectionConfigOldStruct.kt

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,26 @@
1515
package org.zowe.explorer.v3
1616

1717
import org.zowe.explorer.utils.crudable.annotations.Column
18+
import org.zowe.explorer.v3.state.config.Config
19+
import org.zowe.explorer.v3.state.config.ConfigType
1820
import org.zowe.kotlinsdk.annotations.ZVersion
1921

22+
// TODO: tags
23+
// TODO: clarify abstraction
2024
/**
2125
* Connection config based class. Could be used as a basic connection config representation or as a base for other
2226
* connection config type
23-
* @param uuid the unique UUID of the entity
2427
* @param name the name of the connection config
2528
* @param url the URL for the connection config
2629
* @param isAllowSelfSigned to indicate whether it is allowed to use self-signed certificates during a connection
2730
* @param zVersion the version of the z/OS being used for the connection
2831
* @param owner the actual USS user related to the USS user provided in the connection to work with in the USS part
2932
*/
30-
open class ConnectionConfig(
33+
open class ConnectionConfigOldStruct(
3134
uuid: String = EMPTY_ID,
3235
@Column var name: String = "",
3336
@Column var url: String = "",
3437
@Column var isAllowSelfSigned: Boolean = true,
3538
@Column var zVersion: ZVersion = ZVersion.ZOS_2_3,
3639
@Column var owner: String = ""
37-
) : EntityWithUuid(uuid) {
38-
39-
override fun equals(other: Any?): Boolean {
40-
if (this === other) return true
41-
if (javaClass != other?.javaClass) return false
42-
if (!super.equals(other)) return false
43-
44-
other as ConnectionConfig
45-
46-
if (name != other.name) return false
47-
if (url != other.url) return false
48-
if (isAllowSelfSigned != other.isAllowSelfSigned) return false
49-
if (zVersion != other.zVersion) return false
50-
if (owner != other.owner) return false
51-
52-
return true
53-
}
54-
55-
override fun hashCode(): Int {
56-
var result = super.hashCode()
57-
result = 31 * result + name.hashCode()
58-
result = 31 * result + url.hashCode()
59-
result = 31 * result + isAllowSelfSigned.hashCode()
60-
result = 31 * result + zVersion.hashCode()
61-
result = 31 * result + owner.hashCode()
62-
return result
63-
}
64-
65-
override fun toString(): String {
66-
return "ConnectionConfig(name='$name', url='$url', isAllowSelfSigned=$isAllowSelfSigned, zVersion=$zVersion, owner=$owner)"
67-
}
68-
69-
}
40+
) : Config(uuid, configType = ConfigType.HTTP_CONNECTION_CONFIG_V1)

src/main/kotlin/org/zowe/explorer/v3/EntityWithUuid.kt

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,26 @@
1313
*/
1414
package org.zowe.explorer.v3
1515

16-
import org.zowe.explorer.utils.crudable.annotations.Column
16+
import com.intellij.util.xmlb.annotations.Attribute
17+
import java.util.*
1718

1819
/**
1920
* Class that represents an entity with UUID
20-
* @param uuid the UUID of the entity
21+
* @property uuid the UUID of the entity
2122
*/
22-
abstract class EntityWithUuid(@Column(unique = true) var uuid: String = EMPTY_ID) {
23+
abstract class EntityWithUuid(
24+
@get:Attribute
25+
var uuid: String = EMPTY_ID
26+
) {
2327

24-
companion object {
25-
const val EMPTY_ID = ""
26-
}
27-
28-
override fun hashCode(): Int {
29-
return uuid.hashCode()
28+
init {
29+
if (uuid == EMPTY_ID) {
30+
uuid = UUID.randomUUID().toString()
31+
}
3032
}
3133

32-
override fun equals(other: Any?): Boolean {
33-
if (this === other) return true
34-
if (other == null || javaClass != other.javaClass) return false
35-
val that = other as EntityWithUuid
36-
return uuid == that.uuid
37-
}
38-
39-
override fun toString(): String {
40-
return "EntityWithUuid{uuid='$uuid'}"
34+
companion object {
35+
const val EMPTY_ID = ""
4136
}
4237

4338
}

src/main/kotlin/org/zowe/explorer/v3/Requester.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ package org.zowe.explorer.v3
1818
* Interface to track requests origins. Represents the elements that requested a related data
1919
* @property connectionConfig the related connection config
2020
*/
21-
interface Requester<ConnectionConfigType : ConnectionConfig> {
21+
interface Requester<ConnectionConfigType : ConnectionConfigOldStruct> {
2222
val connectionConfig: ConnectionConfigType
2323
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2024 IBA Group.
3+
*
4+
* This program and the accompanying materials are made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* IBA Group
12+
* Zowe Community
13+
*/
14+
15+
package org.zowe.explorer.v3
16+
17+
/**
18+
* Supported schemes for a mainframe connection
19+
* @param scheme a scheme string representation
20+
*/
21+
enum class SupportedSchemes(val scheme: String) {
22+
HTTP("http"),
23+
HTTPS("https"),
24+
UNSUPPORTED("unsupported scheme");
25+
26+
companion object {
27+
operator fun invoke(scheme: String): SupportedSchemes {
28+
return entries.find { it.scheme == scheme } ?: UNSUPPORTED
29+
}
30+
}
31+
32+
override fun toString(): String {
33+
return scheme
34+
}
35+
}

src/main/kotlin/org/zowe/explorer/v3/UssRequester.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
package org.zowe.explorer.v3
1616

1717
/** Class to track USS requests origins */
18-
class UssRequester<ConnectionConfigType : ConnectionConfig>(
18+
class UssRequester<ConnectionConfigType : ConnectionConfigOldStruct>(
1919
override val connectionConfig: ConnectionConfigType
2020
) : Requester<ConnectionConfigType>

src/main/kotlin/org/zowe/explorer/v3/operations/OperationData.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414

1515
package org.zowe.explorer.v3.operations
1616

17-
import org.zowe.explorer.v3.ConnectionConfig
17+
import org.zowe.explorer.v3.ConnectionConfigOldStruct
1818
import org.zowe.explorer.v3.Requester
1919

2020
/**
2121
* Interface to describe an operation data
2222
* @property resultClass the result class of the result that should be returned after an operation execution
2323
* @property origin the exact operation requester to distinguish the source of the operation request
2424
*/
25-
interface OperationData<Result, ConnectionConfigType : ConnectionConfig> {
25+
interface OperationData<Result, ConnectionConfigType : ConnectionConfigOldStruct> {
2626
val resultClass: Class<out Result>
2727
val origin: Requester<ConnectionConfigType>?
2828
}

src/main/kotlin/org/zowe/explorer/v3/operations/OperationRunner.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ package org.zowe.explorer.v3.operations
1616

1717
import com.intellij.openapi.progress.DumbProgressIndicator
1818
import com.intellij.openapi.progress.ProgressIndicator
19-
import org.zowe.explorer.v3.ConnectionConfig
19+
import org.zowe.explorer.v3.ConnectionConfigOldStruct
2020

2121
/**
2222
* Base abstract class to represent operation runner
2323
* @property operationDataClass the operation class supported by the operation runner
2424
* @property resultClass the result class of the operation
2525
*/
26-
abstract class OperationRunner<R : Any, C : ConnectionConfig, O : OperationData<R, C>> {
26+
abstract class OperationRunner<R : Any, C : ConnectionConfigOldStruct, O : OperationData<R, C>> {
2727

2828
abstract val operationDataClass: Class<out OperationData<*, *>>
2929

0 commit comments

Comments
 (0)