Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add provided connectors to dashboard #147

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ please see [changelog_updates.md](docs/dev/changelog_updates.md).

#### Patch

- Fixed provided connectors' statuses missing on the dashboard ([#138](https://github.com/sovity/authority-portal/issues/138))

### Known issues

### Deployment Migration Notes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import de.sovity.authorityportal.db.jooq.enums.ComponentType
import de.sovity.authorityportal.db.jooq.tables.records.ComponentDowntimesRecord
import de.sovity.authorityportal.web.services.ComponentStatusService
import de.sovity.authorityportal.web.services.ConnectorMetadataService
import de.sovity.authorityportal.web.services.ConnectorService
import de.sovity.authorityportal.web.thirdparty.broker.model.AuthorityPortalConnectorInfo
import de.sovity.authorityportal.web.thirdparty.broker.model.ConnectorOnlineStatus.DEAD
import de.sovity.authorityportal.web.thirdparty.broker.model.ConnectorOnlineStatus.OFFLINE
import de.sovity.authorityportal.web.thirdparty.broker.model.ConnectorOnlineStatus.ONLINE
import de.sovity.authorityportal.web.thirdparty.uptimekuma.model.toDto
import de.sovity.authorityportal.web.utils.idmanagement.DataspaceComponentIdUtils
import jakarta.enterprise.context.ApplicationScoped
import jakarta.inject.Inject
import org.jooq.DSLContext
Expand All @@ -45,6 +47,12 @@ class ComponentStatusApiService {
@Inject
lateinit var componentStatusService: ComponentStatusService

@Inject
lateinit var connectorService: ConnectorService

@Inject
lateinit var dataspaceComponentIdUtils: DataspaceComponentIdUtils

@Inject
lateinit var dsl: DSLContext

Expand All @@ -58,10 +66,15 @@ class ComponentStatusApiService {
}

fun getComponentsStatusForMdsId(environmentId: String, mdsId: String): ComponentStatusOverview {
val connectorMetadata = connectorMetadataService.getConnectorInfoByMdsId(mdsId, environmentId)
jridderbusch marked this conversation as resolved.
Show resolved Hide resolved
val connectorMetadata = connectorMetadataService.getConnectorInfoByEnvironment(environmentId)
val providedConnectorIds = connectorService.getProvidedConnectorsByMdsId(mdsId, environmentId).map { it.connectorId }
val filteredMetadata = connectorMetadata.filter {
dataspaceComponentIdUtils.toMdsId(it.participantId) == mdsId
|| it.participantId in providedConnectorIds
}

val unknownConnectorCount = getNumberOfUnknownConnectors(connectorMetadata, environmentId, mdsId)
val connectorStatusCount = countConnectorStatuses(connectorMetadata, unknownConnectorCount)
val unknownConnectorCount = getNumberOfUnknownConnectors(filteredMetadata, environmentId, mdsId)
val connectorStatusCount = countConnectorStatuses(filteredMetadata, unknownConnectorCount)

return buildComponenStatusOverview(connectorStatusCount, environmentId)
}
Expand Down Expand Up @@ -165,10 +178,13 @@ class ComponentStatusApiService {

val conditions = mutableListOf(
c.ENVIRONMENT.eq(environmentId),
DSL.or(c.ENDPOINT_URL.isNull, c.ENDPOINT_URL.notIn(connectorMetadata.map { it.connectorEndpoint }))
DSL.or(
c.ENDPOINT_URL.isNull,
c.ENDPOINT_URL.notIn(connectorMetadata.map { it.connectorEndpoint })
)
)
if (mdsId != null) {
conditions += c.MDS_ID.eq(mdsId)
conditions += DSL.or(c.MDS_ID.eq(mdsId), c.PROVIDER_MDS_ID.eq(mdsId))
}

return dsl.selectCount().from(c).where(conditions).fetchSingle().value1()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ class ConnectorMetadataService {
fun getConnectorInfoByEnvironment(environmentId: String): List<AuthorityPortalConnectorInfo> =
getByEnvironment(environmentId).connectorInfos

fun getConnectorInfoByMdsId(mdsId: String, environmentId: String): List<AuthorityPortalConnectorInfo> =
getByEnvironment(environmentId).getByMdsId(mdsId)

fun getTotalDataOffersByMdsId(mdsId: String, environmentId: String): Int =
getByEnvironment(environmentId).getByMdsId(mdsId).sumOf { it.dataOfferCount }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ class ConnectorService {
.fetchOneInto(ConnectorDetailRs::class.java)
}

fun getProvidedConnectorsByMdsId(mdsId: String, environment: String): List<ConnectorRecord> {
val c = Tables.CONNECTOR

return dsl.selectFrom(c)
.where(
c.TYPE.eq(ConnectorType.PROVIDED),
c.PROVIDER_MDS_ID.eq(mdsId),
c.ENVIRONMENT.eq(environment)
)
.fetch()
}

fun updateConnectorsCreator(newCreatedBy: String, oldCreatedBy: String) {
val c = Tables.CONNECTOR
dsl.update(c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class DataspaceComponentIdUtils {
return dataspaceComponentId
}

fun toMdsId(dataspaceComponentId: String): String {
return dataspaceComponentId.substringBefore(".")
}

private fun getDataspaceComponentIdCandidate(mdsId: String): String {
val prefix = "$mdsId.C"
val identifier = idUtils.randomIdentifier(dataspaceComponentIdLength)
Expand Down
Loading