Skip to content

Commit 16b2fc2

Browse files
apply corrections from pull request feedbacks
1 parent ebe6471 commit 16b2fc2

File tree

8 files changed

+170
-166
lines changed

8 files changed

+170
-166
lines changed

doc/Models/Workspace.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
| **ownerId** | **String** | the user id which own this workspace. set by the API from Authentification service receved id | [default to null] |
1515
| **solution** | [**WorkspaceSolution**](WorkspaceSolution.md) | | [default to null] |
1616
| **webApp** | [**WorkspaceWebApp**](WorkspaceWebApp.md) | | [optional] [default to null] |
17-
| **sendInputToDataWarehouse** | **Boolean** | default setting for all Scenarios and Run Templates to set whether or not the Dataset values and the input parameters values are send to the DataWarehouse prior to the ScenarioRun | [optional] [default to null] |
18-
| **useDedicatedEventHubNamespace** | **Boolean** | Set this property to true to use a dedicated Azure Event Hub Namespace for this Workspace. The Event Hub Namespace must be named \\'<organization_id\\>-<workspace_id\\>\\' (in lower case). This Namespace must also contain two Event Hubs named \\'probesmeasures\\' and \\'scenariorun\\'. | [optional] [default to false] |
19-
| **dedicatedEventHubSasKeyName** | **String** | the Dedicated Event Hub SAS key name, default to RootManageSharedAccessKey. Ask you DevOps Team to add the associated value to your Workspace Secret | [optional] [default to null] |
20-
| **dedicatedEventHubAuthenticationStrategy** | **String** | the Event Hub authentication strategy, SHARED_ACCESS_POLICY or TENANT_CLIENT_CREDENTIALS. Default to the one defined for the tenant. | [optional] [default to null] |
21-
| **sendScenarioRunToEventHub** | **Boolean** | default setting for all Scenarios and Run Templates to set whether or not the ScenarioRun is send to the Event Hub | [optional] [default to true] |
22-
| **sendScenarioMetadataToEventHub** | **Boolean** | Set this property to false to not send scenario metada to Azure Event Hub Namespace for this Workspace. The Event Hub Namespace must be named \\'<organization_id\\>-<workspace_id\\>\\' (in lower case). This Namespace must also contain two Event Hubs named \\'scenariometadata\\' and \\'scenariorunmetadata\\'. | [optional] [default to false] |
2317
| **datasetCopy** | **Boolean** | Activate the copy of dataset on scenario creation, meaning that each scenario created in this workspace will make this copy. when false, scenario use directly the dataset specified. | [optional] [default to true] |
2418
| **security** | [**WorkspaceSecurity**](WorkspaceSecurity.md) | | [default to null] |
2519

doc/Models/WorkspaceCreateRequest.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
| **tags** | **List** | the list of tags | [optional] [default to null] |
1111
| **solution** | [**WorkspaceSolution**](WorkspaceSolution.md) | | [default to null] |
1212
| **webApp** | [**WorkspaceWebApp**](WorkspaceWebApp.md) | | [optional] [default to null] |
13-
| **sendInputToDataWarehouse** | **Boolean** | default setting for all Scenarios and Run Templates to set whether or not the Dataset values and the input parameters values are send to the DataWarehouse prior to the ScenarioRun | [optional] [default to null] |
14-
| **useDedicatedEventHubNamespace** | **Boolean** | Set this property to true to use a dedicated Azure Event Hub Namespace for this Workspace. | [optional] [default to false] |
15-
| **dedicatedEventHubSasKeyName** | **String** | the Dedicated Event Hub SAS key name, default to RootManageSharedAccessKey | [optional] [default to null] |
16-
| **dedicatedEventHubAuthenticationStrategy** | **String** | the Event Hub authentication strategy | [optional] [default to null] |
17-
| **sendScenarioRunToEventHub** | **Boolean** | default setting for all Scenarios and Run Templates | [optional] [default to true] |
18-
| **sendScenarioMetadataToEventHub** | **Boolean** | Set this property to false to not send scenario metada | [optional] [default to false] |
1913
| **datasetCopy** | **Boolean** | Activate the copy of dataset on scenario creation | [optional] [default to true] |
2014
| **security** | [**WorkspaceSecurity**](WorkspaceSecurity.md) | | [optional] [default to null] |
2115

doc/Models/WorkspaceUpdateRequest.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@
33

44
| Name | Type | Description | Notes |
55
|------------ | ------------- | ------------- | -------------|
6-
| **key** | **String** | technical key for resource name convention and version grouping. Must be unique | [default to null] |
7-
| **name** | **String** | Workspace name | [default to null] |
6+
| **key** | **String** | technical key for resource name convention and version grouping. Must be unique | [optional] [default to null] |
7+
| **name** | **String** | Workspace name | [optional] [default to null] |
88
| **description** | **String** | the Workspace description | [optional] [default to null] |
99
| **tags** | **List** | the list of tags | [optional] [default to null] |
1010
| **solution** | [**WorkspaceSolution**](WorkspaceSolution.md) | | [optional] [default to null] |
1111
| **webApp** | [**WorkspaceWebApp**](WorkspaceWebApp.md) | | [optional] [default to null] |
12-
| **sendInputToDataWarehouse** | **Boolean** | default setting for all Scenarios and Run Templates | [optional] [default to null] |
13-
| **useDedicatedEventHubNamespace** | **Boolean** | Set this property to true to use a dedicated Azure Event Hub Namespace | [optional] [default to null] |
14-
| **dedicatedEventHubSasKeyName** | **String** | the Dedicated Event Hub SAS key name | [optional] [default to null] |
15-
| **dedicatedEventHubAuthenticationStrategy** | **String** | the Event Hub authentication strategy | [optional] [default to null] |
16-
| **sendScenarioRunToEventHub** | **Boolean** | default setting for all Scenarios and Run Templates | [optional] [default to null] |
17-
| **sendScenarioMetadataToEventHub** | **Boolean** | Set this property to false to not send scenario metadata | [optional] [default to null] |
1812
| **datasetCopy** | **Boolean** | Activate the copy of dataset on scenario creation | [optional] [default to null] |
1913

2014
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

openapi/plantuml/schemas.plantuml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -496,12 +496,6 @@ entity Workspace {
496496
* ownerId: String
497497
* solution: WorkspaceSolution
498498
webApp: WorkspaceWebApp
499-
sendInputToDataWarehouse: Boolean
500-
useDedicatedEventHubNamespace: Boolean
501-
dedicatedEventHubSasKeyName: String
502-
dedicatedEventHubAuthenticationStrategy: String
503-
sendScenarioRunToEventHub: Boolean
504-
sendScenarioMetadataToEventHub: Boolean
505499
datasetCopy: Boolean
506500
* security: WorkspaceSecurity
507501
}
@@ -519,12 +513,6 @@ entity WorkspaceCreateRequest {
519513
tags: List<String>
520514
* solution: WorkspaceSolution
521515
webApp: WorkspaceWebApp
522-
sendInputToDataWarehouse: Boolean
523-
useDedicatedEventHubNamespace: Boolean
524-
dedicatedEventHubSasKeyName: String
525-
dedicatedEventHubAuthenticationStrategy: String
526-
sendScenarioRunToEventHub: Boolean
527-
sendScenarioMetadataToEventHub: Boolean
528516
datasetCopy: Boolean
529517
security: WorkspaceSecurity
530518
}
@@ -549,18 +537,12 @@ entity WorkspaceSolution {
549537
}
550538

551539
entity WorkspaceUpdateRequest {
552-
* key: String
553-
* name: String
540+
key: String
541+
name: String
554542
description: String
555543
tags: List<String>
556544
solution: WorkspaceSolution
557545
webApp: WorkspaceWebApp
558-
sendInputToDataWarehouse: Boolean
559-
useDedicatedEventHubNamespace: Boolean
560-
dedicatedEventHubSasKeyName: String
561-
dedicatedEventHubAuthenticationStrategy: String
562-
sendScenarioRunToEventHub: Boolean
563-
sendScenarioMetadataToEventHub: Boolean
564546
datasetCopy: Boolean
565547
}
566548

run/src/test/kotlin/com/cosmotech/run/ContainerFactoryTests.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,6 @@ class ContainerFactoryTests {
249249
}
250250

251251
private fun getWorkspace(
252-
dedicatedEventHubNamespace: Boolean? = null,
253-
sendToScenarioRun: Boolean? = true,
254-
sasAuthentication: String? = null,
255-
sasName: String? = null
256252
): Workspace {
257253
return Workspace(
258254
id = "Workspaceid",
@@ -266,10 +262,6 @@ class ContainerFactoryTests {
266262
WorkspaceSolution(
267263
solutionId = "1",
268264
),
269-
useDedicatedEventHubNamespace = dedicatedEventHubNamespace,
270-
sendScenarioRunToEventHub = sendToScenarioRun,
271-
dedicatedEventHubAuthenticationStrategy = sasAuthentication,
272-
dedicatedEventHubSasKeyName = sasName,
273265
security = WorkspaceSecurity(default = ROLE_ADMIN, accessControlList = mutableListOf())
274266
)
275267
}

workspace/src/integrationTest/kotlin/com/cosmotech/workspace/service/WorkspaceServiceIntegrationTest.kt

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import com.cosmotech.workspace.domain.WorkspaceRole
3939
import com.cosmotech.workspace.domain.WorkspaceSecurity
4040
import com.cosmotech.workspace.domain.WorkspaceSolution
4141
import com.cosmotech.workspace.domain.WorkspaceUpdateRequest
42+
import com.cosmotech.workspace.domain.WorkspaceWebApp
4243
import com.redis.om.spring.RediSearchIndexer
4344
import io.mockk.every
4445
import io.mockk.junit5.MockKExtension
@@ -489,6 +490,148 @@ class WorkspaceServiceIntegrationTest : CsmRedisTestBase() {
489490
}
490491
}
491492

493+
@Test
494+
fun `assert createWorkspace take all infos in considerations`(){
495+
val workspaceToCreate = Workspace(
496+
id = "id",
497+
organizationId = organizationSaved.id,
498+
key = "key",
499+
name = "name",
500+
ownerId = "ownerId",
501+
solution = WorkspaceSolution(solutionSaved.id!!),
502+
description = "description",
503+
linkedDatasetIdList = null,
504+
version = "1.0.0",
505+
tags = mutableListOf("tag1", "tag2"),
506+
webApp = WorkspaceWebApp(url = "url"),
507+
datasetCopy = true,
508+
security = WorkspaceSecurity(
509+
default = ROLE_NONE,
510+
accessControlList = mutableListOf(WorkspaceAccessControl("id", ROLE_ADMIN))),
511+
)
512+
val workspaceCreateRequest = WorkspaceCreateRequest(
513+
key = workspaceToCreate.key,
514+
name = workspaceToCreate.name,
515+
solution = workspaceToCreate.solution,
516+
description = workspaceToCreate.description,
517+
version = workspaceToCreate.version,
518+
tags = workspaceToCreate.tags,
519+
webApp = workspaceToCreate.webApp,
520+
datasetCopy = workspaceToCreate.datasetCopy,
521+
security = workspaceToCreate.security
522+
)
523+
524+
workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspaceCreateRequest)
525+
526+
workspaceToCreate.id = workspaceSaved.id
527+
workspaceToCreate.ownerId = workspaceSaved.ownerId
528+
assertEquals(workspaceToCreate, workspaceSaved)
529+
}
530+
531+
@Test
532+
fun `assert updateWorkspace take all infos in considerations`() {
533+
var workspaceToCreate = Workspace(
534+
id = "id",
535+
organizationId = organizationSaved.id,
536+
key = "key",
537+
name = "name",
538+
ownerId = "ownerId",
539+
solution = WorkspaceSolution(solutionSaved.id!!),
540+
description = "description",
541+
linkedDatasetIdList = null,
542+
version = "1.0.0",
543+
tags = mutableListOf("tag1", "tag2"),
544+
webApp = WorkspaceWebApp(url = "url"),
545+
datasetCopy = true,
546+
security = WorkspaceSecurity(
547+
default = ROLE_ADMIN,
548+
accessControlList = mutableListOf(WorkspaceAccessControl("id", ROLE_ADMIN))),
549+
)
550+
val workspaceCreateRequest = WorkspaceCreateRequest(
551+
key = workspaceToCreate.key,
552+
name = workspaceToCreate.name,
553+
solution = workspaceToCreate.solution,
554+
description = workspaceToCreate.description,
555+
version = workspaceToCreate.version,
556+
tags = workspaceToCreate.tags,
557+
webApp = workspaceToCreate.webApp,
558+
datasetCopy = workspaceToCreate.datasetCopy,
559+
security = workspaceToCreate.security
560+
)
561+
workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspaceCreateRequest)
562+
solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution)
563+
val workspaceUpdateRequest = WorkspaceUpdateRequest(
564+
key = "new key",
565+
name = "new name",
566+
solution = WorkspaceSolution(solutionSaved.id!!),
567+
description = "new description",
568+
tags = mutableListOf("newTag1", "newTag2"),
569+
webApp = WorkspaceWebApp(url = "new url"),
570+
datasetCopy = false,
571+
)
572+
workspaceToCreate = workspaceToCreate.copy(
573+
id = workspaceSaved.id,
574+
key = workspaceUpdateRequest.key!!,
575+
name = workspaceUpdateRequest.name!!,
576+
ownerId = workspaceSaved.ownerId,
577+
solution = workspaceUpdateRequest.solution!!,
578+
description = workspaceUpdateRequest.description,
579+
tags = workspaceUpdateRequest.tags,
580+
webApp = workspaceUpdateRequest.webApp,
581+
datasetCopy = workspaceUpdateRequest.datasetCopy
582+
)
583+
584+
workspaceSaved = workspaceApiService.updateWorkspace(organizationSaved.id, workspaceSaved.id, workspaceUpdateRequest)
585+
586+
assertEquals(workspaceToCreate, workspaceSaved)
587+
}
588+
589+
@Test
590+
fun `test updateWorkspace apply only specified changes`() {
591+
val workspace = makeWorkspaceCreateRequest()
592+
workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace)
593+
594+
workspaceSaved = workspaceApiService.updateWorkspace(
595+
organizationSaved.id,
596+
workspaceSaved.id,
597+
WorkspaceUpdateRequest(
598+
key = "new_key"
599+
)
600+
)
601+
assertEquals("new_key", workspaceSaved.key)
602+
assertEquals(workspace.name, workspaceSaved.name)
603+
assertEquals(workspace.solution, workspaceSaved.solution)
604+
assertEquals(workspace.security, workspaceSaved.security)
605+
}
606+
607+
@Test
608+
fun `test createWorkspace and updateWorkspace with only required parameters`() {
609+
logger.info("should create workspace with only required parameters")
610+
val minimalRequest = WorkspaceCreateRequest(
611+
key = "minimal-key",
612+
name = "Minimal Workspace",
613+
solution = WorkspaceSolution(solutionSaved.id!!)
614+
)
615+
val createdWorkspace = workspaceApiService.createWorkspace(organizationSaved.id, minimalRequest)
616+
assertEquals("minimal-key", createdWorkspace.key)
617+
assertEquals("Minimal Workspace", createdWorkspace.name)
618+
assertEquals(solutionSaved.id, createdWorkspace.solution.solutionId)
619+
assertNull(createdWorkspace.description)
620+
assertNull(createdWorkspace.webApp)
621+
622+
logger.info("should update workspace with only required parameters")
623+
val updatedWorkspace = workspaceApiService.updateWorkspace(
624+
organizationSaved.id,
625+
createdWorkspace.id,
626+
WorkspaceUpdateRequest(key = "updated-key", name = "Updated Workspace")
627+
)
628+
assertEquals("updated-key", updatedWorkspace.key)
629+
assertEquals("Updated Workspace", updatedWorkspace.name)
630+
assertEquals(createdWorkspace.solution, updatedWorkspace.solution)
631+
assertEquals(createdWorkspace.description, updatedWorkspace.description)
632+
assertEquals(createdWorkspace.webApp, updatedWorkspace.webApp)
633+
}
634+
492635
fun makeOrganizationCreateRequest(
493636
id: String,
494637
userName: String = CONNECTED_ADMIN_USER,

workspace/src/main/kotlin/com/cosmotech/workspace/service/WorkspaceServiceImpl.kt

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.cosmotech.api.security.coroutine.SecurityCoroutineContext
2828
import com.cosmotech.api.utils.ResourceScanner
2929
import com.cosmotech.api.utils.compareToAndMutateIfNeeded
3030
import com.cosmotech.api.utils.constructPageRequest
31+
import com.cosmotech.api.utils.convertToMap
3132
import com.cosmotech.api.utils.findAllPaginated
3233
import com.cosmotech.api.utils.getCurrentAccountIdentifier
3334
import com.cosmotech.api.utils.getCurrentAuthenticatedUserName
@@ -116,22 +117,28 @@ internal class WorkspaceServiceImpl(
116117
override fun createWorkspace(organizationId: String, workspaceCreateRequest: WorkspaceCreateRequest): Workspace {
117118
organizationService.getVerifiedOrganization(
118119
organizationId, listOf(PERMISSION_READ, PERMISSION_CREATE_CHILDREN))
119-
// Validate Solution ID
120-
workspaceCreateRequest.solution.solutionId.let { solutionService.findSolutionById(organizationId, it) }
121120

121+
// Validate Solution ID
122+
workspaceCreateRequest.solution.solutionId.let { solutionService.findSolutionById(organizationId, it) }
122123

123124
val workspaceId = idGenerator.generate("workspace")
124125
val security = csmRbac.initSecurity(
125126
workspaceCreateRequest.security.toGenericSecurity(workspaceId)).toResourceSecurity()
126127
val createdWorkspace =
127128
Workspace(
128-
id = workspaceId,
129-
organizationId = organizationId,
130-
ownerId = getCurrentAuthenticatedUserName(csmPlatformProperties),
131-
key = workspaceCreateRequest.key,
132-
name = workspaceCreateRequest.name,
133-
solution = workspaceCreateRequest.solution,
134-
security = security)
129+
id = workspaceId,
130+
organizationId = organizationId,
131+
ownerId = getCurrentAuthenticatedUserName(csmPlatformProperties),
132+
key = workspaceCreateRequest.key,
133+
name = workspaceCreateRequest.name,
134+
solution = workspaceCreateRequest.solution,
135+
security = security,
136+
version = workspaceCreateRequest.version,
137+
tags = workspaceCreateRequest.tags,
138+
description = workspaceCreateRequest.description,
139+
webApp = workspaceCreateRequest.webApp,
140+
datasetCopy = workspaceCreateRequest.datasetCopy,
141+
)
135142

136143
return workspaceRepository.save(createdWorkspace)
137144
}
@@ -148,23 +155,18 @@ internal class WorkspaceServiceImpl(
148155
): Workspace {
149156
val existingWorkspace = this.getVerifiedWorkspace(organizationId, workspaceId, PERMISSION_WRITE)
150157
// Security cannot be changed by updateWorkspace
158+
151159
val updatedWorkspace = Workspace(
152-
key = workspaceUpdateRequest.key,
153-
name = workspaceUpdateRequest.name,
160+
key = workspaceUpdateRequest.key ?: existingWorkspace.key,
161+
name = workspaceUpdateRequest.name ?: existingWorkspace.name,
154162
solution = workspaceUpdateRequest.solution ?: existingWorkspace.solution,
155163
id = existingWorkspace.id,
156164
organizationId = organizationId,
157-
description = workspaceUpdateRequest.description ?: "",
158-
tags = workspaceUpdateRequest.tags,
165+
description = workspaceUpdateRequest.description ?: existingWorkspace.description,
166+
tags = workspaceUpdateRequest.tags ?: existingWorkspace.tags,
159167
ownerId = existingWorkspace.ownerId,
160-
webApp = workspaceUpdateRequest.webApp,
161-
sendInputToDataWarehouse = workspaceUpdateRequest.sendInputToDataWarehouse,
162-
useDedicatedEventHubNamespace = workspaceUpdateRequest.useDedicatedEventHubNamespace,
163-
dedicatedEventHubSasKeyName = workspaceUpdateRequest.dedicatedEventHubSasKeyName,
164-
dedicatedEventHubAuthenticationStrategy = workspaceUpdateRequest.dedicatedEventHubAuthenticationStrategy,
165-
sendScenarioRunToEventHub = workspaceUpdateRequest.sendScenarioRunToEventHub,
166-
sendScenarioMetadataToEventHub = workspaceUpdateRequest.sendScenarioMetadataToEventHub,
167-
datasetCopy = workspaceUpdateRequest.datasetCopy,
168+
webApp = workspaceUpdateRequest.webApp ?: existingWorkspace.webApp,
169+
datasetCopy = workspaceUpdateRequest.datasetCopy ?: existingWorkspace.datasetCopy,
168170
security = existingWorkspace.security
169171
)
170172

0 commit comments

Comments
 (0)