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

feat(Gate): add endpoint for confidence criteria stats #700

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
import org.eclipse.tractusx.bpdm.common.model.StageType
import org.eclipse.tractusx.bpdm.gate.api.model.response.StatsAddressTypesResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.StatsConfidenceCriteriaResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.StatsSharingStatesResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.StatsStagesResponse
import org.springframework.http.MediaType
Expand Down Expand Up @@ -67,4 +68,15 @@ interface StatsApi {
@GetExchange("/{stage}/address-types")
fun countAddressTypes(@PathVariable("stage") stage: StageType): StatsAddressTypesResponse

@Operation
@ApiResponses(
value = [
ApiResponse(responseCode = "200")
]
)
@GetMapping("/confidence-criteria")
@GetExchange("/confidence-criteria")
fun getConfidenceCriteriaStats(): StatsConfidenceCriteriaResponse


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.bpdm.gate.api.model.response

data class StatsConfidenceCriteriaResponse(
val numberOfBusinessPartnersAverage: Float,
val uniqueTotal: Long,
val sharedByOwnerTotal: Long,
val checkedByExternalDataSourceTotal: Long,
val confidenceLevelAverage: Float
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package org.eclipse.tractusx.bpdm.gate.controller
import org.eclipse.tractusx.bpdm.common.model.StageType
import org.eclipse.tractusx.bpdm.gate.api.StatsApi
import org.eclipse.tractusx.bpdm.gate.api.model.response.StatsAddressTypesResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.StatsConfidenceCriteriaResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.StatsSharingStatesResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.StatsStagesResponse
import org.eclipse.tractusx.bpdm.gate.service.StatsService
Expand All @@ -42,4 +43,8 @@ class StatsController(
override fun countAddressTypes(stage: StageType): StatsAddressTypesResponse {
return statsService.countAddressTypes(stage)
}

override fun getConfidenceCriteriaStats(): StatsConfidenceCriteriaResponse {
return statsService.getConfidenceCriteriaStats()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ interface BusinessPartnerRepository : JpaRepository<BusinessPartner, Long>, Crud
val stage: StageType
val count: Int
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.bpdm.gate.repository.generic

import org.eclipse.tractusx.bpdm.gate.entity.generic.ConfidenceCriteria
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.CrudRepository

interface ConfidenceCriteriaRepository : JpaRepository<ConfidenceCriteria, Long>, CrudRepository<ConfidenceCriteria, Long> {

@Query("SELECT AVG(c.numberOfBusinessPartners) FROM ConfidenceCriteria AS c")
fun averageNumberOfBusinessPartners(): Float?

@Query("SELECT COUNT(c.numberOfBusinessPartners) FROM ConfidenceCriteria AS c WHERE c.numberOfBusinessPartners <= 1")
fun countUnique(): Long?

@Query("SELECT COUNT(c.sharedByOwner) FROM ConfidenceCriteria AS c")
fun countSharedByOwner(): Long?

@Query("SELECT COUNT(c.checkedByExternalDataSource) FROM ConfidenceCriteria AS c")
fun countCheckedByExternalDataSource(): Long?

@Query("SELECT AVG(c.confidenceLevel) FROM ConfidenceCriteria AS c")
fun averageConfidenceLevel(): Float?

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,22 @@ import org.eclipse.tractusx.bpdm.common.dto.AddressType
import org.eclipse.tractusx.bpdm.common.model.StageType
import org.eclipse.tractusx.bpdm.gate.api.model.SharingStateType
import org.eclipse.tractusx.bpdm.gate.api.model.response.StatsAddressTypesResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.StatsConfidenceCriteriaResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.StatsSharingStatesResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.StatsStagesResponse
import org.eclipse.tractusx.bpdm.gate.repository.SharingStateRepository
import org.eclipse.tractusx.bpdm.gate.repository.generic.BusinessPartnerRepository
import org.eclipse.tractusx.bpdm.gate.repository.generic.ConfidenceCriteriaRepository
import org.eclipse.tractusx.bpdm.gate.repository.generic.PostalAddressRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class StatsService(
private val sharingStateRepository: SharingStateRepository,
private val businessPartnerRepository: BusinessPartnerRepository,
private val postalAddressRepository: PostalAddressRepository
private val postalAddressRepository: PostalAddressRepository,
private val confidenceCriteriaRepository: ConfidenceCriteriaRepository
) {

fun countSharingStates(): StatsSharingStatesResponse {
Expand Down Expand Up @@ -72,5 +76,16 @@ class StatsService(
)
}

@Transactional
fun getConfidenceCriteriaStats(): StatsConfidenceCriteriaResponse {
return StatsConfidenceCriteriaResponse(
numberOfBusinessPartnersAverage = confidenceCriteriaRepository.averageNumberOfBusinessPartners() ?: 0F,
uniqueTotal = confidenceCriteriaRepository.countUnique() ?: 0L,
sharedByOwnerTotal = confidenceCriteriaRepository.countSharedByOwner() ?: 0L,
checkedByExternalDataSourceTotal = confidenceCriteriaRepository.countCheckedByExternalDataSource() ?: 0L,
confidenceLevelAverage = confidenceCriteriaRepository.averageConfidenceLevel() ?: 0F
)
}


}
Loading