Skip to content

Commit

Permalink
#1112 | CCv2: Filter out Environments by Status
Browse files Browse the repository at this point in the history
  • Loading branch information
mlytvyn authored May 11, 2024
1 parent 0fe3a40 commit 7c936e1
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .run/Run IDE - Community.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->

<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run IDE with Plugin" type="GradleRunConfiguration" factoryName="Gradle">
<configuration default="false" name="Run IDE - Community" type="GradleRunConfiguration" factoryName="Gradle">
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
<ExternalSystemSettings>
<option name="executionName" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Run IDE - Ultimate.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->

<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run IDE with Plugin" type="GradleRunConfiguration" factoryName="Gradle">
<configuration default="false" name="Run IDE - Ultimate" type="GradleRunConfiguration" factoryName="Gradle">
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
<ExternalSystemSettings>
<option name="executionName" />
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Sort environments by type and name [#1109](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1109)
- Added a browser link to Build name [#1110](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1110)
- Added a browser link to Deployment code [#1111](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1111)
- Filter out Environments by Status [#1112](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1112)

### `Project Import` enhancements
- Loading backoffice sources provided by SAP on project import [#1096](https://github.com/epam/sap-commerce-intellij-idea-plugin/issues/1096)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,28 @@
<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2OpenSettingsAction"/>
<separator/>

<group id="ccv2.actionGroup.build.show"
text="View Options"
<group text="View Options"
popup="true"
icon="AllIcons.Actions.Show">
<separator text="Show Builds With Status"/>
<separator text="Show With Status"/>
<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2ShowSuccessBuildsAction"/>
<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2ShowScheduledBuildsAction"/>
<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2ShowBuildingBuildsAction"/>
<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2ShowFailedBuildsAction"/>
<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2ShowDeletedBuildsAction"/>
<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2ShowUnknownBuildsAction"/>

<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2ShowProvisioningEnvironmentsAction"/>
<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2ShowAvailableEnvironmentsAction"/>
<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2ShowTerminatingEnvironmentsAction"/>
<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2ShowTerminatedEnvironmentsAction"/>
</group>
<separator/>

<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2FetchEnvironmentsAction"/>
<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2FetchDeploymentsAction"/>
<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2FetchBuildsAction"/>

<action class="com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2CreateBuildAction"/>
</group>
</actions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ object HybrisConstants {
const val PLATFORM_VERSION_5_0 = "5.0"
const val PLATFORM_VERSION_5_2 = "5.2"

const val CCV2_API_V1 = "https://portalrotapi.hana.ondemand.com/v1"
const val CCV2_MANIFEST_NAME = "manifest.json"
const val CCV2_CORE_CUSTOMIZE_NAME = "core-customize"
const val CCV2_DATAHUB_NAME = "datahub"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.intellij.idea.plugin.hybris.settings

import com.intellij.idea.plugin.hybris.tools.ccv2.dto.CCv2BuildStatus
import com.intellij.idea.plugin.hybris.tools.ccv2.dto.CCv2EnvironmentStatus
import com.intellij.openapi.components.BaseState
import com.intellij.util.xmlb.annotations.Tag
import java.util.*
Expand All @@ -42,5 +43,15 @@ class DeveloperSettings : BaseState() {
}

data class CCv2Settings(
var hideBuildStatuses: EnumSet<CCv2BuildStatus> = EnumSet.of(CCv2BuildStatus.DELETED),
var showBuildStatuses: EnumSet<CCv2BuildStatus> = EnumSet.of(
CCv2BuildStatus.BUILDING,
CCv2BuildStatus.SUCCESS,
CCv2BuildStatus.FAIL,
CCv2BuildStatus.SCHEDULED,
CCv2BuildStatus.UNKNOWN
),
var showEnvironmentStatuses: EnumSet<CCv2EnvironmentStatus> = EnumSet.of(
CCv2EnvironmentStatus.PROVISIONING,
CCv2EnvironmentStatus.AVAILABLE,
),
)
10 changes: 7 additions & 3 deletions src/com/intellij/idea/plugin/hybris/tools/ccv2/CCv2Service.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class CCv2Service(val project: Project, private val coroutineScope: CoroutineSco
onStartCallback.invoke()
if (sendEvents) project.messageBus.syncPublisher(TOPIC_ENVIRONMENT).onFetchingStarted(subscriptions)

val ccv2Settings = DeveloperSettingsComponent.getInstance(project).state.ccv2Settings
val statuses = ccv2Settings.showEnvironmentStatuses
.map { it.name }

coroutineScope.launch {
withBackgroundProgress(project, "Fetching CCv2 Environments...", true) {
val ccv2Token = getCCv2Token()
Expand All @@ -67,7 +71,7 @@ class CCv2Service(val project: Project, private val coroutineScope: CoroutineSco

var environments = sortedMapOf<CCv2Subscription, Collection<CCv2Environment>>()
try {
environments = CCv2Strategy.getInstance().fetchEnvironments(ccv2Token, subscriptions)
environments = CCv2Strategy.getInstance().fetchEnvironments(ccv2Token, subscriptions, statuses)
} catch (e: SocketTimeoutException) {
notifyOnTimeout()
} catch (e: RuntimeException) {
Expand Down Expand Up @@ -113,8 +117,8 @@ class CCv2Service(val project: Project, private val coroutineScope: CoroutineSco
project.messageBus.syncPublisher(TOPIC_BUILDS).onFetchingStarted(subscriptions)

val ccv2Settings = DeveloperSettingsComponent.getInstance(project).state.ccv2Settings

val statusNot = ccv2Settings.hideBuildStatuses
val statusNot = CCv2BuildStatus.entries
.filterNot { ccv2Settings.showBuildStatuses.contains(it) }
.map { it.name }

coroutineScope.launch {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* This file is part of "SAP Commerce Developers Toolset" plugin for IntelliJ IDEA.
* Copyright (C) 2019-2024 EPAM Systems <[email protected]> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.intellij.idea.plugin.hybris.tools.ccv2.actions

import com.intellij.idea.plugin.hybris.settings.CCv2Settings
import com.intellij.idea.plugin.hybris.settings.components.DeveloperSettingsComponent
import com.intellij.idea.plugin.hybris.toolwindow.ccv2.CCv2Tab
import com.intellij.idea.plugin.hybris.toolwindow.ccv2.CCv2View
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.ToggleAction
import java.util.*
import javax.swing.Icon

abstract class AbstractCCv2ShowWithStatusAction<T : Enum<T>>(
private val tab: CCv2Tab,
private val status: T,
text: String,
icon: Icon
) : ToggleAction(text, null, icon) {

override fun getActionUpdateThread() = ActionUpdateThread.BGT
override fun isSelected(e: AnActionEvent) = getCCv2Settings(e)
?.let { getStatuses(it) }
?.contains(status)
?: false

override fun setSelected(e: AnActionEvent, state: Boolean) {
getCCv2Settings(e)
?.let { getStatuses(it) }
?.let {
if (state) it.add(status)
else it.remove(status)
}
}

override fun update(e: AnActionEvent) {
super.update(e)
e.presentation.isVisible = e.project
?.let { CCv2View.getActiveTab(it) == tab }
?: false
}

protected abstract fun getStatuses(settings: CCv2Settings): EnumSet<T>?

private fun getCCv2Settings(e: AnActionEvent) = e.project
?.let { DeveloperSettingsComponent.getInstance(it).state.ccv2Settings }
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@
package com.intellij.idea.plugin.hybris.tools.ccv2.actions

import com.intellij.idea.plugin.hybris.common.utils.HybrisIcons
import com.intellij.idea.plugin.hybris.settings.CCv2Settings
import com.intellij.idea.plugin.hybris.settings.CCv2Subscription
import com.intellij.idea.plugin.hybris.settings.components.DeveloperSettingsComponent
import com.intellij.idea.plugin.hybris.tools.ccv2.CCv2Service
import com.intellij.idea.plugin.hybris.tools.ccv2.dto.CCv2Build
import com.intellij.idea.plugin.hybris.tools.ccv2.dto.CCv2BuildStatus
import com.intellij.idea.plugin.hybris.tools.ccv2.ui.CCv2CreateBuildDialog
import com.intellij.idea.plugin.hybris.tools.ccv2.ui.CCv2DeployBuildDialog
import com.intellij.idea.plugin.hybris.toolwindow.ccv2.CCv2Tab
import com.intellij.idea.plugin.hybris.toolwindow.ccv2.CCv2View
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DataKey
import com.intellij.openapi.actionSystem.ToggleAction
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.project.Project
Expand Down Expand Up @@ -150,36 +147,19 @@ class CCv2DownloadBuildLogsAction(
override fun isEnabled() = !processing && super.isEnabled()
}

abstract class CCv2ShowBuildWithStatusAction(private val buildStatus: CCv2BuildStatus) : ToggleAction("${buildStatus.title}", null, buildStatus.icon) {

override fun getActionUpdateThread() = ActionUpdateThread.BGT
override fun isSelected(e: AnActionEvent): Boolean = getCCv2Settings(e)
?.hideBuildStatuses
?.let { !it.contains(buildStatus) }
?: false

override fun setSelected(e: AnActionEvent, state: Boolean) {
getCCv2Settings(e)
?.let {
if (state) it.hideBuildStatuses.remove(buildStatus)
else it.hideBuildStatuses.add(buildStatus)
}
}

override fun update(e: AnActionEvent) {
super.update(e)
e.presentation.isVisible = e.project
?.let { CCv2View.getActiveTab(it) == CCv2Tab.BUILDS }
?: false
}
abstract class AbstractCCv2ShowBuildWithStatusAction(status: CCv2BuildStatus): AbstractCCv2ShowWithStatusAction<CCv2BuildStatus>(
CCv2Tab.BUILDS,
status,
status.title,
status.icon
) {

private fun getCCv2Settings(e: AnActionEvent) = e.project
?.let { DeveloperSettingsComponent.getInstance(it).state.ccv2Settings }
override fun getStatuses(settings: CCv2Settings) = settings.showBuildStatuses
}

class CCv2ShowDeletedBuildsAction : CCv2ShowBuildWithStatusAction(CCv2BuildStatus.DELETED)
class CCv2ShowFailedBuildsAction : CCv2ShowBuildWithStatusAction(CCv2BuildStatus.FAIL)
class CCv2ShowUnknownBuildsAction : CCv2ShowBuildWithStatusAction(CCv2BuildStatus.UNKNOWN)
class CCv2ShowScheduledBuildsAction : CCv2ShowBuildWithStatusAction(CCv2BuildStatus.SCHEDULED)
class CCv2ShowBuildingBuildsAction : CCv2ShowBuildWithStatusAction(CCv2BuildStatus.BUILDING)
class CCv2ShowSuccessBuildsAction : CCv2ShowBuildWithStatusAction(CCv2BuildStatus.SUCCESS)
class CCv2ShowDeletedBuildsAction : AbstractCCv2ShowBuildWithStatusAction(CCv2BuildStatus.DELETED)
class CCv2ShowFailedBuildsAction : AbstractCCv2ShowBuildWithStatusAction(CCv2BuildStatus.FAIL)
class CCv2ShowUnknownBuildsAction : AbstractCCv2ShowBuildWithStatusAction(CCv2BuildStatus.UNKNOWN)
class CCv2ShowScheduledBuildsAction : AbstractCCv2ShowBuildWithStatusAction(CCv2BuildStatus.SCHEDULED)
class CCv2ShowBuildingBuildsAction : AbstractCCv2ShowBuildWithStatusAction(CCv2BuildStatus.BUILDING)
class CCv2ShowSuccessBuildsAction : AbstractCCv2ShowBuildWithStatusAction(CCv2BuildStatus.SUCCESS)
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
package com.intellij.idea.plugin.hybris.tools.ccv2.actions

import com.intellij.idea.plugin.hybris.common.utils.HybrisIcons
import com.intellij.idea.plugin.hybris.settings.CCv2Settings
import com.intellij.idea.plugin.hybris.tools.ccv2.CCv2Service
import com.intellij.idea.plugin.hybris.tools.ccv2.dto.CCv2Environment
import com.intellij.idea.plugin.hybris.tools.ccv2.dto.CCv2EnvironmentStatus
import com.intellij.idea.plugin.hybris.toolwindow.ccv2.CCv2Tab

class CCv2FetchEnvironmentsAction : AbstractCCv2FetchAction<CCv2Environment>(
Expand All @@ -32,3 +34,17 @@ class CCv2FetchEnvironmentsAction : AbstractCCv2FetchAction<CCv2Environment>(
}
)

abstract class AbstractCCv2ShowEnvironmentWithStatusAction(status: CCv2EnvironmentStatus) : AbstractCCv2ShowWithStatusAction<CCv2EnvironmentStatus>(
CCv2Tab.ENVIRONMENTS,
status,
status.title,
status.icon
) {

override fun getStatuses(settings: CCv2Settings) = settings.showEnvironmentStatuses
}

class CCv2ShowProvisioningEnvironmentsAction : AbstractCCv2ShowEnvironmentWithStatusAction(CCv2EnvironmentStatus.PROVISIONING)
class CCv2ShowAvailableEnvironmentsAction : AbstractCCv2ShowEnvironmentWithStatusAction(CCv2EnvironmentStatus.AVAILABLE)
class CCv2ShowTerminatingEnvironmentsAction : AbstractCCv2ShowEnvironmentWithStatusAction(CCv2EnvironmentStatus.TERMINATING)
class CCv2ShowTerminatedEnvironmentsAction : AbstractCCv2ShowEnvironmentWithStatusAction(CCv2EnvironmentStatus.TERMINATED)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

package com.intellij.idea.plugin.hybris.tools.ccv2.dto

import com.intellij.idea.plugin.hybris.ccv2.model.EnvironmentDetailDTO
import com.intellij.idea.plugin.hybris.ccv2.model.EnvironmentDetailV1DTO
import com.intellij.idea.plugin.hybris.ccv2.model.EnvironmentHealthV1DTO
import com.intellij.idea.plugin.hybris.common.utils.HybrisIcons
import javax.swing.Icon

Expand All @@ -36,6 +39,36 @@ data class CCv2Environment(
) : CCv2DTO, Comparable<CCv2Environment> {

override fun compareTo(other: CCv2Environment) = name.compareTo(other.name)

companion object {

fun map(
environment: EnvironmentDetailDTO,
deploymentStatus: Boolean,
v1Environment: EnvironmentDetailV1DTO?,
v1EnvironmentHealth: EnvironmentHealthV1DTO?
): CCv2Environment {
val status = CCv2EnvironmentStatus.tryValueOf(environment.status)
val code = environment.code

val link = if (v1Environment != null && status == CCv2EnvironmentStatus.AVAILABLE)
"https://portal.commerce.ondemand.com/subscription/${environment.subscriptionCode}/applications/commerce-cloud/environments/$code"
else null

return CCv2Environment(
code = code ?: "N/A",
name = environment.name ?: "N/A",
status = status,
type = CCv2EnvironmentType.tryValueOf(environment.type),
deploymentStatus = CCv2DeploymentStatusEnum.tryValueOf(environment.deploymentStatus),
deploymentAllowed = deploymentStatus && (status == CCv2EnvironmentStatus.AVAILABLE || status == CCv2EnvironmentStatus.READY_FOR_DEPLOYMENT),
dynatraceLink = v1Environment?.dynatraceUrl,
loggingLink = v1Environment?.loggingUrl?.let { "$it/app/discover" },
problems = v1EnvironmentHealth?.problems,
link = link
)
}
}
}

enum class CCv2EnvironmentType(val title: String, val icon: Icon) {
Expand Down
Loading

0 comments on commit 7c936e1

Please sign in to comment.