Skip to content

Commit 8c1cdb9

Browse files
committed
feat(fossid-webapp)!: Add a function to list all projects
The function wraps the `list_projects` action of the FossID API which returns a list of all projects the user has access to. This information is relevant for some use cases, e.g. gathering statistics or cleaning up old scans. In the response of this function, the `creationDate` property for projects is not filled out. Therefore, make it nullable; it is currently not used elsewhere in ORT. Signed-off-by: Oliver Heger <[email protected]>
1 parent f469d5b commit 8c1cdb9

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

clients/fossid-webapp/src/main/kotlin/Extensions.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ suspend fun FossIdRestService.getProject(user: String, apiKey: String, projectCo
9292
PostRequestBody("get_information", PROJECT_GROUP, user, apiKey, mapOf("project_code" to projectCode))
9393
)
9494

95+
/**
96+
* Get all projects available in this instance.
97+
*
98+
* The HTTP request is sent with [user] and [apiKey] as credentials.
99+
*/
100+
suspend fun FossIdRestService.listProjects(user: String, apiKey: String) =
101+
listProjects(
102+
PostRequestBody("list_projects", PROJECT_GROUP, user, apiKey, emptyMap())
103+
)
104+
95105
/**
96106
* Get the scan for the given [scanCode].
97107
*

clients/fossid-webapp/src/main/kotlin/FossIdRestService.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ interface FossIdRestService {
264264
@POST("api.php")
265265
suspend fun getProject(@Body body: PostRequestBody): PolymorphicDataResponseBody<Project>
266266

267+
@POST("api.php")
268+
suspend fun listProjects(@Body body: PostRequestBody): PolymorphicResponseBody<Project>
269+
267270
@POST("api.php")
268271
suspend fun getScan(@Body body: PostRequestBody): PolymorphicDataResponseBody<Scan>
269272

clients/fossid-webapp/src/main/kotlin/model/Project.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ data class Project(
4545
val isArchived: Boolean?,
4646

4747
val jiraProjectKey: String?,
48-
val creationDate: String,
48+
val creationDate: String?,
4949
val dateLimitDate: String?
5050
)

clients/fossid-webapp/src/test/kotlin/FossIdClientReturnTypeTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.github.tomakehurst.wiremock.core.WireMockConfiguration
2424

2525
import io.kotest.core.spec.style.StringSpec
2626
import io.kotest.matchers.collections.beEmpty
27+
import io.kotest.matchers.collections.shouldHaveSize
2728
import io.kotest.matchers.maps.shouldContainValue
2829
import io.kotest.matchers.nulls.shouldNotBeNull
2930
import io.kotest.matchers.should
@@ -350,4 +351,13 @@ class FossIdClientReturnTypeTest : StringSpec({
350351
message shouldBe "User is not found or API key is incorrect"
351352
}
352353
}
354+
355+
"Projects can be listed" {
356+
service.listProjects("", "") shouldNotBeNull {
357+
data shouldNotBeNull {
358+
this shouldHaveSize 2
359+
first().projectName shouldBe "TestProject1"
360+
}
361+
}
362+
}
353363
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"id" : "d235bf75-7318-44bd-8801-27359f923e32",
3+
"name" : "apiphp",
4+
"request" : {
5+
"url" : "/api.php",
6+
"method" : "POST",
7+
"bodyPatterns" : [ {
8+
"equalToJson" : "{\"action\":\"list_projects\",\"group\":\"projects\",\"data\":{\"username\":\"\",\"key\":\"\"}}",
9+
"ignoreArrayOrder" : true,
10+
"ignoreExtraElements" : true
11+
} ]
12+
},
13+
"response" : {
14+
"status" : 200,
15+
"body" : "{\"operation\":\"projects_list_projects\",\"status\":\"1\",\"data\": [ { \"id\": \"404\", \"creator\": \"23\", \"project_code\": \"project_1\", \"project_name\": \"TestProject1\", \"limit_date\": null, \"product_code\": \"\", \"product_name\": \"TestProduct1\", \"description\": \"A test project\", \"comment\": \"\", \"is_archived\": \"0\", \"jira_project_key\": \"\", \"created\": \"2023-01-24 15:52:35\", \"updated\": \"2024-03-24 17:36:58\", \"scans\": null, \"policy_rules\": null, \"warnings\": null }, { \"id\": \"426\", \"creator\": \"226\", \"project_code\": \"test_semver4j\", \"project_name\": \"test_semver4j\", \"limit_date\": null, \"product_code\": \"\", \"product_name\": \"\", \"description\": \"\", \"comment\": \"Created by ORT\", \"is_archived\": \"0\", \"jira_project_key\": \"\", \"created\": \"2022-03-09 15:51:31\", \"updated\": null, \"scans\": \"2\", \"policy_rules\": null, \"warnings\": null }]}",
16+
"headers" : {
17+
"Content-Type" : "text/html; charset=UTF-8",
18+
"Date" : "Thu, 03 Dec 2020 08:03:42 GMT",
19+
"Server" : "Apache/2.4.38 (Debian)",
20+
"Vary" : "Accept-Encoding"
21+
}
22+
},
23+
"uuid" : "d235bf75-7318-44bd-8801-27359f923e32",
24+
"persistent" : true,
25+
"insertionIndex" : 1
26+
}

0 commit comments

Comments
 (0)