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

Fix/issue 794 review code of returned data #813

Closed
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 @@ -7,8 +7,6 @@ import net.adoptium.api.v3.Pagination.maxPageSize
import net.adoptium.api.v3.dataSources.APIDataStore
import net.adoptium.api.v3.dataSources.SortMethod
import net.adoptium.api.v3.dataSources.SortOrder
import net.adoptium.api.v3.filters.BinaryFilter
import net.adoptium.api.v3.filters.ReleaseFilter
import net.adoptium.api.v3.models.Architecture
import net.adoptium.api.v3.models.BinaryAssetView
import net.adoptium.api.v3.models.CLib
Expand Down Expand Up @@ -43,6 +41,9 @@ import jakarta.ws.rs.core.Context
import jakarta.ws.rs.core.MediaType
import jakarta.ws.rs.core.Response
import jakarta.ws.rs.core.UriInfo
import net.adoptium.api.v3.filters.VersionRangeFilter
import net.adoptium.api.v3.parser.FailedToParse
import net.adoptium.api.v3.parser.maven.InvalidVersionSpecificationException

@Tag(name = "Assets")
@Path("/v3/assets/")
Expand Down Expand Up @@ -150,23 +151,26 @@ constructor(
showPageCount: Boolean?,

@Context
uriInfo: UriInfo,
uriInfo: UriInfo
): Response {
val order = sortOrder ?: SortOrder.DESC
val releaseSortMethod = sortMethod ?: SortMethod.DEFAULT
val vendorNonNull = vendor ?: Vendor.getDefault()
// check if this version repository exists
val repos = apiDataStore.getAdoptRepos().getFeatureRelease(version!!) ?: throw NotFoundException()

val releaseFilter = ReleaseFilter(releaseType = release_type, featureVersion = version, vendor = vendorNonNull, jvm_impl = jvm_impl)
val binaryFilter = BinaryFilter(os, arch, image_type, jvm_impl, heap_size, project, before, cLib)
val repos = apiDataStore.getAdoptRepos().getFeatureRelease(version!!)

if (repos == null) {
throw NotFoundException()
}

val releases = apiDataStore
.getAdoptRepos()
.getFilteredReleases(version, releaseFilter, binaryFilter, order, releaseSortMethod)
val releases = releaseEndpoint.getFeatureReleasesAssets(
release_type,
version,
os,
arch,
image_type,
cLib,
jvm_impl,
heap_size,
vendor,
project,
before,
sortOrder,
sortMethod
)

return getResponseForPage(uriInfo, pageSize, page, releases, showPageCount ?: false)
}
Expand Down Expand Up @@ -233,18 +237,18 @@ constructor(
throw BadRequestException("Must provide a vendor")
}

val releaseFilter = ReleaseFilter(vendor = vendor, releaseName = releaseName.trim(), jvm_impl = jvm_impl)
val binaryFilter = BinaryFilter(os, arch, image_type, jvm_impl, heap_size, project, null, cLib)

val releases = apiDataStore
.getAdoptRepos()
.getFilteredReleases(
releaseFilter,
binaryFilter,
SortOrder.DESC,
SortMethod.DEFAULT
)
.toList()
val releases = releaseEndpoint.getReleaseNameAssets(
vendor,
releaseName,
os,
arch,
image_type,
cLib,
jvm_impl,
heap_size,
project
)
.toList()

return when {
releases.isEmpty() -> {
Expand All @@ -256,7 +260,7 @@ constructor(
}

else -> {
releases[0]
releases.first
}
}
}
Expand Down Expand Up @@ -357,12 +361,20 @@ constructor(
semver: Boolean?,

@Context
uriInfo: UriInfo,
uriInfo: UriInfo
): Response {
val releases = releaseEndpoint.getReleases(
val range = try {
VersionRangeFilter(version, semver ?: false)
} catch (e: InvalidVersionSpecificationException) {
throw BadRequestException("Invalid version range", e)
} catch (e: FailedToParse) {
throw BadRequestException("Invalid version string", e)
}

val releases = releaseEndpoint.getVersionAssets(
range,
sortOrder,
sortMethod,
version,
release_type,
vendor,
lts,
Expand All @@ -372,9 +384,9 @@ constructor(
jvm_impl,
heap_size,
project,
cLib,
semver
cLib
)

return getResponseForPage(uriInfo, pageSize, page, releases, showPageCount ?: false)
}

Expand All @@ -389,7 +401,6 @@ constructor(
@Path("/latest/{feature_version}/{jvm_impl}")
@Operation(summary = "Returns list of latest assets for the given feature version and jvm impl", operationId = "getLatestAssets")
fun getLatestAssets(

@Parameter(
name = "feature_version", description = OpenApiDocs.FEATURE_RELEASE, required = true,
schema = Schema(defaultValue = "8", type = SchemaType.INTEGER)
Expand All @@ -415,15 +426,16 @@ constructor(

@Parameter(name = "image_type", description = "Image Type", required = false)
@QueryParam("image_type")
image_type: ImageType?,

): List<BinaryAssetView> {
val binaryVendor = vendor ?: Vendor.getDefault()
val releaseFilter = ReleaseFilter(ReleaseType.ga, featureVersion = version, vendor = binaryVendor, jvm_impl = jvm_impl)
val binaryFilter = BinaryFilter(os, arch, image_type, jvm_impl, null, null)
val releases = apiDataStore
.getAdoptRepos()
.getFilteredReleases(version, releaseFilter, binaryFilter, SortOrder.ASC, SortMethod.DEFAULT)
image_type: ImageType?
): List<BinaryAssetView> {
val releases = releaseEndpoint.getLatestAssets(
version,
jvm_impl,
vendor,
os,
arch,
image_type
)

return releases
.flatMap { release ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package net.adoptium.api.v3.routes

import jakarta.enterprise.context.ApplicationScoped
import jakarta.inject.Inject
import jakarta.ws.rs.BadRequestException
import net.adoptium.api.v3.dataSources.APIDataStore
import net.adoptium.api.v3.dataSources.SortMethod
import net.adoptium.api.v3.dataSources.SortOrder
Expand All @@ -11,6 +10,7 @@ import net.adoptium.api.v3.filters.ReleaseFilter
import net.adoptium.api.v3.filters.VersionRangeFilter
import net.adoptium.api.v3.models.Architecture
import net.adoptium.api.v3.models.CLib
import net.adoptium.api.v3.models.DateTime
import net.adoptium.api.v3.models.HeapSize
import net.adoptium.api.v3.models.ImageType
import net.adoptium.api.v3.models.JvmImpl
Expand All @@ -19,19 +19,63 @@ import net.adoptium.api.v3.models.Project
import net.adoptium.api.v3.models.Release
import net.adoptium.api.v3.models.ReleaseType
import net.adoptium.api.v3.models.Vendor
import net.adoptium.api.v3.parser.FailedToParse
import net.adoptium.api.v3.parser.maven.InvalidVersionSpecificationException

@ApplicationScoped
class ReleaseEndpoint
@Inject
constructor(
private val apiDataStore: APIDataStore
) {
fun getReleases(
fun getFeatureReleasesAssets(
release_type: ReleaseType?,
version: Int,
os: OperatingSystem?,
arch: Architecture?,
image_type: ImageType?,
cLib: CLib?,
jvm_impl: JvmImpl?,
heap_size: HeapSize?,
vendor: Vendor?,
project: Project?,
before: DateTime?,
sortOrder: SortOrder?,
sortMethod: SortMethod?
): Sequence<Release> {
val order = sortOrder ?: SortOrder.DESC
val releaseSortMethod = sortMethod ?: SortMethod.DEFAULT
val vendorNonNull = vendor ?: Vendor.getDefault()

val releaseFilter = ReleaseFilter(releaseType = release_type, featureVersion = version, vendor = vendorNonNull, jvm_impl = jvm_impl)
val binaryFilter = BinaryFilter(os, arch, image_type, jvm_impl, heap_size, project, before, cLib)

return apiDataStore
.getAdoptRepos()
.getFilteredReleases(version, releaseFilter, binaryFilter, order, releaseSortMethod)
}

fun getReleaseNameAssets(
vendor: Vendor,
releaseName: String,
os: OperatingSystem?,
arch: Architecture?,
image_type: ImageType?,
cLib: CLib?,
jvm_impl: JvmImpl?,
heap_size: HeapSize?,
project: Project?
): Sequence<Release> {
val releaseFilter = ReleaseFilter(vendor = vendor, releaseName = releaseName.trim(), jvm_impl = jvm_impl)
val binaryFilter = BinaryFilter(os, arch, image_type, jvm_impl, heap_size, project, null, cLib)

return apiDataStore
.getAdoptRepos()
.getFilteredReleases(releaseFilter, binaryFilter, SortOrder.DESC, SortMethod.DEFAULT)
}

fun getVersionAssets(
versionRangeFilter: VersionRangeFilter,
sortOrder: SortOrder?,
sortMethod: SortMethod?,
version: String?,
release_type: ReleaseType?,
vendor: Vendor?,
lts: Boolean?,
Expand All @@ -41,26 +85,35 @@ constructor(
jvm_impl: JvmImpl?,
heap_size: HeapSize?,
project: Project?,
cLib: CLib?,
semver: Boolean?
cLib: CLib?
): Sequence<Release> {
val order = sortOrder ?: SortOrder.DESC
val vendorNonNull = vendor ?: Vendor.getDefault()
val releaseSortMethod = sortMethod ?: SortMethod.DEFAULT

val range = try {
VersionRangeFilter(version, semver ?: false)
} catch (e: InvalidVersionSpecificationException) {
throw BadRequestException("Invalid version range", e)
} catch (e: FailedToParse) {
throw BadRequestException("Invalid version string", e)
}

val releaseFilter = ReleaseFilter(releaseType = release_type, vendor = vendorNonNull, versionRange = range, lts = lts, jvm_impl = jvm_impl)
val releaseFilter = ReleaseFilter(releaseType = release_type, vendor = vendorNonNull, versionRange = versionRangeFilter, lts = lts, jvm_impl = jvm_impl)
val binaryFilter = BinaryFilter(os = os, arch = arch, imageType = image_type, jvmImpl = jvm_impl, heapSize = heap_size, project = project, cLib = cLib)

return apiDataStore
.getAdoptRepos()
.getFilteredReleases(releaseFilter, binaryFilter, order, releaseSortMethod)
}

fun getLatestAssets(
version: Int,
jvm_impl: JvmImpl,
vendor: Vendor?,
os: OperatingSystem?,
arch: Architecture?,
image_type: ImageType?
): Sequence<Release> {
val binaryVendor = vendor ?: Vendor.getDefault()

val releaseFilter = ReleaseFilter(ReleaseType.ga, featureVersion = version, vendor = binaryVendor, jvm_impl = jvm_impl)
val binaryFilter = BinaryFilter(os, arch, image_type, jvm_impl, null, null)

return apiDataStore
.getAdoptRepos()
.getFilteredReleases(version, releaseFilter, binaryFilter, SortOrder.ASC, SortMethod.DEFAULT)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.eclipse.microprofile.openapi.annotations.responses.APIResponses
import org.eclipse.microprofile.openapi.annotations.tags.Tag
import jakarta.enterprise.context.ApplicationScoped
import jakarta.inject.Inject
import jakarta.ws.rs.BadRequestException
import jakarta.ws.rs.GET
import jakarta.ws.rs.Path
import jakarta.ws.rs.Produces
Expand All @@ -36,6 +37,9 @@ import jakarta.ws.rs.core.Context
import jakarta.ws.rs.core.MediaType
import jakarta.ws.rs.core.Response
import jakarta.ws.rs.core.UriInfo
import net.adoptium.api.v3.filters.VersionRangeFilter
import net.adoptium.api.v3.parser.FailedToParse
import net.adoptium.api.v3.parser.maven.InvalidVersionSpecificationException

@Tag(name = "Release Info")
@Path("/v3/info")
Expand Down Expand Up @@ -134,10 +138,18 @@ constructor(
@Context
uriInfo: UriInfo,
): Response {
val releases = releaseEndpoint.getReleases(
val range = try {
VersionRangeFilter(version, semver ?: false)
} catch (e: InvalidVersionSpecificationException) {
throw BadRequestException("Invalid version range", e)
} catch (e: FailedToParse) {
throw BadRequestException("Invalid version string", e)
}

val releases = releaseEndpoint.getVersionAssets(
range,
sortOrder,
sortMethod,
version,
release_type,
vendor,
lts,
Expand All @@ -147,8 +159,7 @@ constructor(
jvm_impl,
heap_size,
project,
cLib,
semver
cLib
)
.map { it.release_name }
.distinct()
Expand Down Expand Up @@ -245,10 +256,18 @@ constructor(
@Context
uriInfo: UriInfo,
): Response {
val releases = releaseEndpoint.getReleases(
val range = try {
VersionRangeFilter(version, semver ?: false)
} catch (e: InvalidVersionSpecificationException) {
throw BadRequestException("Invalid version range", e)
} catch (e: FailedToParse) {
throw BadRequestException("Invalid version string", e)
}

val releases = releaseEndpoint.getVersionAssets(
range,
sortOrder,
sortMethod,
version,
release_type,
vendor,
lts,
Expand All @@ -258,8 +277,7 @@ constructor(
jvm_impl,
heap_size,
project,
cLib,
semver
cLib
)
.map { it.version_data }
.distinct()
Expand Down
Loading