@@ -190,16 +190,18 @@ class DatasetServiceImpl(
190190 dataset.takeUnless { it.name.isNullOrBlank() }
191191 ? : throw IllegalArgumentException (" Name cannot be null or blank" )
192192
193+ val datasetSourceType = dataset.sourceType
193194 dataset.takeUnless {
194- dataset.sourceType in listOf (DatasetSourceType .ADT , DatasetSourceType .AzureStorage ) &&
195+ datasetSourceType in listOf (DatasetSourceType .ADT , DatasetSourceType .AzureStorage ) &&
195196 dataset.source == null
196197 }
197198 ? : throw IllegalArgumentException (
198199 " Source cannot be null for source type 'ADT' or 'Storage'" )
199200
200201 var twingraphId: String? = null
201202
202- if (dataset.sourceType != null && useGraphModule) {
203+ if (datasetSourceType == DatasetSourceType .Twincache && useGraphModule) {
204+
203205 twingraphId = idGenerator.generate(" twingraph" )
204206 val twincacheConnector = getCreateTwincacheConnector()
205207 dataset.connector =
@@ -208,17 +210,11 @@ class DatasetServiceImpl(
208210 parametersValues = mutableMapOf (TWINCACHE_NAME to twingraphId))
209211 }
210212
211- dataset.takeUnless { it.connector == null || dataset.connector!! .id.isNullOrBlank() }
212- ? : throw IllegalArgumentException (" Connector or its ID cannot be null or blank" )
213-
214- val existingConnector = connectorService.findConnectorById(dataset.connector!! .id!! )
215- logger.debug(" Found connector: {}" , existingConnector)
216-
217213 val createdDataset =
218214 dataset.copy(
219215 id = idGenerator.generate(" dataset" ),
220216 twingraphId = twingraphId,
221- sourceType = dataset.sourceType ? : DatasetSourceType .None ,
217+ sourceType = datasetSourceType ? : DatasetSourceType .None ,
222218 source = dataset.source ? : SourceInfo (" none" ),
223219 main = dataset.main ? : true ,
224220 creationDate = Instant .now().toEpochMilli(),
@@ -227,9 +223,15 @@ class DatasetServiceImpl(
227223 ownerId = getCurrentAuthenticatedUserName(csmPlatformProperties),
228224 organizationId = organizationId)
229225 createdDataset.setRbac(csmRbac.initSecurity(dataset.getRbac()))
230- createdDataset.connector!! .apply {
231- name = existingConnector.name
232- version = existingConnector.version
226+
227+ if (dataset.connector != null && ! dataset.connector!! .id.isNullOrBlank()) {
228+ val existingConnector = connectorService.findConnectorById(dataset.connector!! .id!! )
229+ logger.debug(" Found connector: {}" , existingConnector)
230+
231+ createdDataset.connector!! .apply {
232+ name = existingConnector.name
233+ version = existingConnector.version
234+ }
233235 }
234236
235237 return datasetRepository.save(createdDataset)
0 commit comments