This repository has been archived by the owner on May 25, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add intergration for frontent api analyser
- Loading branch information
Showing
4 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...code/src/main/kotlin/com/thoughtworks/archguard/scanner/sourcecode/ContainerRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.thoughtworks.archguard.scanner.sourcecode | ||
|
||
import com.thoughtworks.archguard.scanner.sourcecode.frontend.ContainerDemand | ||
import com.thoughtworks.archguard.scanner.sourcecode.frontend.ContainerService | ||
import infrastructure.SourceBatch | ||
import java.util.HashMap | ||
|
||
class ContainerRepository(systemId: String, language: String, workspace: String) { | ||
private val batch: SourceBatch = SourceBatch() | ||
private val batchStep = 100 | ||
private val systemId: String | ||
private val language: String | ||
private val workspace: String | ||
|
||
init { | ||
this.systemId = systemId | ||
this.language = language | ||
this.workspace = workspace | ||
} | ||
|
||
fun saveContainerServices(services: Array<ContainerService>) { | ||
val serviceId = saveMainServices() | ||
services.forEach { service -> | ||
service.demands.map { saveDemand(it, serviceId) }.toTypedArray() | ||
} | ||
} | ||
|
||
private fun saveMainServices(): String { | ||
val time: String = ClassRepository.currentTime | ||
val serviceId = ClassRepository.generateId() | ||
val values: MutableMap<String, String> = HashMap() | ||
|
||
values["id"] = serviceId | ||
values["updated_at"] = time | ||
values["created_at"] = time | ||
|
||
batch.add("container_service", values) | ||
return serviceId | ||
} | ||
|
||
private fun saveDemand(demand: ContainerDemand, serviceId: String): String { | ||
val time: String = ClassRepository.currentTime | ||
val demandId = ClassRepository.generateId() | ||
val values: MutableMap<String, String> = HashMap() | ||
|
||
values["id"] = demandId | ||
|
||
values["target_http_method"] = demand.target_http_method | ||
values["target_url"] = demand.target_url | ||
values["source_method"] = demand.source_caller | ||
values["service_id"] = serviceId | ||
values["updated_at"] = time | ||
values["created_at"] = time | ||
|
||
batch.add("container_demand", values) | ||
return demandId | ||
} | ||
|
||
fun close() { | ||
batch.execute() | ||
batch.close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters