fix_bridge.ps1 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Read auxiliary controller URLs
  2. $auxDir = "fs-saas-company\src\main\java\com\fs\company\controller\company"
  3. $bridgeFile = "fs-saas-company\src\main\java\com\fs\company\controller\bridge\CompanyBridgeController.java"
  4. $auxUrls = @{}
  5. Get-ChildItem $auxDir -Filter "*Auxiliary*.java" | ForEach-Object {
  6. $content = Get-Content $_.FullName -Raw
  7. $matches = [regex]::Matches($content, '@GetMapping(?:\s*\(\s*\{([^}]+)\}\s*\)|\s*\(\s*"([^"]+)"\s*\))')
  8. foreach ($m in $matches) {
  9. $paths = if ($m.Groups[1].Success) { $m.Groups[1].Value } else { $m.Groups[2].Value }
  10. $pathList = $paths -split ',' | ForEach-Object { $_.Trim().Trim('"').Trim() } | Where-Object { $_ }
  11. foreach ($p in $pathList) { $auxUrls[$p] = $true }
  12. }
  13. }
  14. Write-Host "Auxiliary URLs: $($auxUrls.Count)"
  15. # Read bridge controller
  16. $lines = Get-Content $bridgeFile
  17. $output = [System.Collections.ArrayList]::new()
  18. $skipMode = $false
  19. $methodBraceCount = 0
  20. $i = 0
  21. while ($i -lt $lines.Count) {
  22. $line = $lines[$i]
  23. # Check for mapping annotations
  24. if ($line -match '@(GetMapping|PostMapping|PutMapping|DeleteMapping)') {
  25. # Extract all paths from this annotation (may span multiple lines)
  26. $annotationText = $line
  27. $startIdx = $i
  28. # Check if annotation spans multiple lines (no closing paren on this line)
  29. while ($annotationText -notmatch '\)' -and ($i + 1) -lt $lines.Count) {
  30. $i++
  31. $annotationText += " " + $lines[$i]
  32. }
  33. # Extract paths
  34. $paths = @()
  35. $pathMatches = [regex]::Matches($annotationText, '"([^"]+)"')
  36. foreach ($pm in $pathMatches) {
  37. $paths += $pm.Groups[1].Value
  38. }
  39. # Check for conflicts
  40. $hasConflict = $false
  41. foreach ($p in $paths) {
  42. if ($auxUrls.ContainsKey($p)) {
  43. $hasConflict = $true
  44. break
  45. }
  46. }
  47. if ($hasConflict) {
  48. # Skip this entire method - find the method body and skip it
  49. # Move forward until we find the method body (look for opening brace)
  50. while ($i -lt $lines.Count -and $lines[$i] -notmatch '\{') { $i++ }
  51. if ($i -lt $lines.Count) {
  52. # Count braces to find end of method
  53. $braceCount = 0
  54. $started = $false
  55. while ($i -lt $lines.Count) {
  56. $currentLine = $lines[$i]
  57. for ($c = 0; $c -lt $currentLine.Length; $c++) {
  58. if ($currentLine[$c] -eq '{') { $braceCount++; $started = $true }
  59. if ($currentLine[$c] -eq '}') { $braceCount-- }
  60. }
  61. $i++
  62. if ($started -and $braceCount -le 0) { break }
  63. }
  64. }
  65. continue
  66. }
  67. }
  68. $output.Add($line) | Out-Null
  69. $i++
  70. }
  71. # Replace safeListFromTable calls with empty data return
  72. $newOutput = [System.Collections.ArrayList]::new()
  73. foreach ($line in $output) {
  74. $newLine = $line
  75. if ($newLine -match 'safeListFromTable\(') {
  76. $newLine = $newLine -replace 'safeListFromTable\("[^"]+"\)', 'getDataTable(new java.util.ArrayList<>())'
  77. }
  78. $newOutput.Add($newLine) | Out-Null
  79. }
  80. # Remove GenericTableMapper import and field
  81. $finalOutput = [System.Collections.ArrayList]::new()
  82. $skipGenericImport = $false
  83. foreach ($line in $newOutput) {
  84. if ($line -match 'import com\.fs\.hisStore\.mapper\.GenericTableMapper') { continue }
  85. if ($line -match 'private GenericTableMapper genericTableMapper') { continue }
  86. # Remove the safeListFromTable method
  87. if ($line -match 'private TableDataInfo safeListFromTable') {
  88. # Skip until closing brace
  89. continue
  90. }
  91. $finalOutput.Add($line) | Out-Null
  92. }
  93. # Write output
  94. $result = $finalOutput -join "`n"
  95. [System.IO.File]::WriteAllText((Resolve-Path $bridgeFile).Path, $result, [System.Text.UTF8Encoding]::new($false))
  96. Write-Host "Output lines: $($finalOutput.Count)"