Skip to content

Commit

Permalink
IJMP-2145 Indexes have been added to zowe connections names
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsiaryna Tsytsenia authored and Katsiaryna Tsytsenia committed Jan 14, 2025
1 parent c3b53ad commit 10066e3
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 573 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,37 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService
}

/**
* Returns Zowe connection name
* Returns base Zowe connection name
*/
fun getZoweConnectionName(myProject: Project?, type: ZoweConfigType, profileName: String = "zosmf"): String {
private fun getBaseZoweConnectionName(
myProject: Project?,
type: ZoweConfigType,
profileName: String = "zosmf"
): String {
return if (type == ZoweConfigType.LOCAL)
"${ZOWE_PROJECT_PREFIX}${type}-${profileName}/${myProject?.name}"
else
"${ZOWE_PROJECT_PREFIX}${type}-${profileName}"
}

/**
* Returns Zowe connection name
*/
fun getZoweConnectionName(myProject: Project?, type: ZoweConfigType, profileName: String = "zosmf"): String {
val configCrudable = ConfigService.getService().crudable
val allConnections = configCrudable.getAll<ConnectionConfig>().toList()
val allConnectionsNames: MutableList<String> = allConnections.map { it.name }.toMutableList()
val connectionNameBase = getBaseZoweConnectionName(myProject, type, profileName)
var connectionName = connectionNameBase

var index = 1
while (allConnectionsNames.contains(connectionName)) {
connectionName = connectionNameBase.plus(index.toString())
index++
}
return connectionName
}

/**
* Returns path to Zowe configuration file
*/
Expand Down Expand Up @@ -155,7 +177,7 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService
val zoweConnectionList = configCrudable.find<ConnectionConfig> {
val pattern =
if (type == ZoweConfigType.LOCAL) {
Regex("^(" + ZOWE_PROJECT_PREFIX + type + "-).*(/" + myProject.name + ")$")
Regex("^(" + ZOWE_PROJECT_PREFIX + type + "-).*(/" + myProject.name + ")\\d*$")
} else {
Regex("^(" + ZOWE_PROJECT_PREFIX + type + "-).*")
}
Expand All @@ -169,12 +191,12 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService
* @return ConnectionConfig instance related to zowe config if it exists or null otherwise.
*/
private fun findExistingConnection(type: ZoweConfigType, profileName: String): ConnectionConfig? {
val zoweConnectionList = configCrudable
.find<ConnectionConfig> {
it.name == getZoweConnectionName(myProject, type, profileName)
&& it.zoweConfigPath == getZoweConfigLocation(myProject, type)
}
.collect(Collectors.toList())
val zoweConnectionList = configCrudable.find<ConnectionConfig> {
it.name.startsWith(
getBaseZoweConnectionName(myProject, type, profileName)
)
&& it.zoweConfigPath == getZoweConfigLocation(myProject, type)
}.collect(Collectors.toList())
return if (zoweConnectionList.isEmpty()) null else zoweConnectionList[0]
}

Expand All @@ -194,9 +216,7 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService
* @return Nothing.
*/
private fun notifyUiOnConnectionFailure(title: String, content: String, type: ZoweConfigType) {
NotificationGroupManager
.getInstance()
.getNotificationGroup(EXPLORER_NOTIFICATION_GROUP_ID)
NotificationGroupManager.getInstance().getNotificationGroup(EXPLORER_NOTIFICATION_GROUP_ID)
.createNotification(title, content, NotificationType.ERROR)
.apply {
addAction(object : DumbAwareAction("Add Anyway") {
Expand Down Expand Up @@ -283,6 +303,7 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService
sendTopic(topic).onConfigSaved(zoweConfig, zosmfConnection)
}
}

} catch (e: Exception) {
NotificationsService.errorNotification(e, project = myProject, custTitle="Error with Zowe config file")
}
Expand All @@ -298,7 +319,10 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService
val username = zosmfConnection.user
val password = zosmfConnection.password
val zoweConnection = findExistingConnection(type, zosmfConnection.profileName)
?.let { zosmfConnection.toConnectionConfig(it.uuid, it.zVersion, type = type) }
?.let { oldConn ->
zosmfConnection.toConnectionConfig(oldConn.uuid, oldConn.zVersion, type = type)
.also { newConn -> newConn.name = oldConn.name }
}
?: zosmfConnection.toConnectionConfig(UUID.randomUUID().toString(), type = type)
CredentialService.getService().setCredentials(zoweConnection.uuid, username, password)
return zoweConnection
Expand Down Expand Up @@ -471,7 +495,7 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService
*/
override fun getZoweConfigState(scanProject: Boolean, type: ZoweConfigType): ZoweConfigState {
if (scanProject) {
scanForZoweConfig(type)
scanForZoweConfig(type)
}
val zoweConfig = if (type == ZoweConfigType.LOCAL)
localZoweConfig ?: return ZoweConfigState.NOT_EXISTS
Expand All @@ -493,6 +517,7 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService
val newConnection = newConnectionList[0].toConnectionConfig(
existingConnection.uuid, existingConnection.zVersion, existingConnection.owner, type = type
)
newConnection.name = existingConnection.name
val zoweUsername = zosConnection.user
val zowePassword = zosConnection.password
if (
Expand Down
Loading

0 comments on commit 10066e3

Please sign in to comment.