refactor: implement stripAuditTags helper to sanitize observation text across maintenance operations
This commit is contained in:
@@ -811,7 +811,7 @@ class GoogleSheetsSyncService(
|
||||
row[headerIndices["percentualanterior"] ?: 3] = history.percentualAnterior.toString()
|
||||
row[headerIndices["percentualnovo"] ?: 4] = history.percentualNovo.toString()
|
||||
row[headerIndices["observacao"] ?: 5] = history.observacao ?: ""
|
||||
row[headerIndices["fotopath"] ?: 6] = history.fotoPath ?: ""
|
||||
row[headerIndices["fotopath"] ?: 6] = filterRemoteOnlyPhotoPaths(history.fotoPath)
|
||||
row[headerIndices["responsavel"] ?: 7] = history.recurso
|
||||
row[headerIndices["email_editor"] ?: 8] = history.emailEditor ?: ""
|
||||
row
|
||||
@@ -930,7 +930,7 @@ class GoogleSheetsSyncService(
|
||||
finding.timestamp.toString(),
|
||||
finding.responsavel,
|
||||
finding.emailEditor ?: "",
|
||||
finding.fotoPath ?: ""
|
||||
filterRemoteOnlyPhotoPaths(finding.fotoPath)
|
||||
)
|
||||
}.toMutableList()
|
||||
|
||||
@@ -948,5 +948,14 @@ class GoogleSheetsSyncService(
|
||||
Log.d(tag, "Successfully updated 'achados' sheet with ${allActiveFindings.size} active findings.")
|
||||
}
|
||||
}
|
||||
|
||||
fun filterRemoteOnlyPhotoPaths(pathStr: String?): String {
|
||||
if (pathStr.isNullOrBlank()) return ""
|
||||
return pathStr.split("|")
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotBlank() && !it.startsWith("/") }
|
||||
.distinct()
|
||||
.joinToString("|")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ class MaintenanceRepository(
|
||||
val effectiveTimestamp = customTimestampMillis ?: System.currentTimeMillis()
|
||||
|
||||
// Handle observation and photo update as an OSFinding of type OBS if filled or photo attached
|
||||
val cleanObs = observacao?.trim().takeIf { !it.isNullOrBlank() }
|
||||
val cleanObs = stripAuditTags(observacao)
|
||||
if (cleanObs != null || !fotoPath.isNullOrBlank()) {
|
||||
val obsText = cleanObs ?: "Foto anexada"
|
||||
val findingObs = OSFinding(
|
||||
@@ -97,7 +97,7 @@ class MaintenanceRepository(
|
||||
dao.insertFinding(findingObs)
|
||||
}
|
||||
|
||||
val latestObsText = cleanObs ?: currentActivity.observacoes
|
||||
val latestObsText = cleanObs ?: stripAuditTags(currentActivity.observacoes)
|
||||
|
||||
val updatedActivity = currentActivity.copy(
|
||||
percentualExecucao = novoPercentual.coerceIn(0, 100),
|
||||
@@ -151,7 +151,7 @@ class MaintenanceRepository(
|
||||
if (tipo == "OBS" && currentActivity != null) {
|
||||
dao.updateActivity(
|
||||
currentActivity.copy(
|
||||
observacoes = descricao.trim(),
|
||||
observacoes = stripAuditTags(descricao),
|
||||
synced = false,
|
||||
lastUpdated = effectiveTimestamp
|
||||
)
|
||||
@@ -196,7 +196,7 @@ class MaintenanceRepository(
|
||||
if (finding.tipo == "OBS" && currentActivity != null) {
|
||||
dao.updateActivity(
|
||||
currentActivity.copy(
|
||||
observacoes = finding.descricao.trim(),
|
||||
observacoes = stripAuditTags(finding.descricao),
|
||||
synced = false,
|
||||
lastUpdated = effectiveTimestamp
|
||||
)
|
||||
@@ -499,9 +499,10 @@ class MaintenanceRepository(
|
||||
latestLog.fotoPath ?: activity.fotoPath
|
||||
}
|
||||
val finalFotoPath = mergePreservingDeletedPhotos(localFotoPath, baseFotoPath)
|
||||
val cleanLatestObs = stripAuditTags(latestLog.observacao) ?: stripAuditTags(activity.observacoes)
|
||||
activity.copy(
|
||||
percentualExecucao = latestLog.percentualNovo,
|
||||
observacoes = latestLog.observacao ?: activity.observacoes,
|
||||
observacoes = cleanLatestObs,
|
||||
fotoPath = finalFotoPath,
|
||||
synced = true,
|
||||
lastUpdated = latestLog.timestamp
|
||||
@@ -838,6 +839,14 @@ class MaintenanceRepository(
|
||||
}
|
||||
}
|
||||
|
||||
private fun stripAuditTags(text: String?): String? {
|
||||
if (text.isNullOrBlank()) return null
|
||||
var result = text.trim()
|
||||
val regex = Regex("^(\\[[^\\]]+\\]\\s*)+")
|
||||
result = regex.replace(result, "").trim()
|
||||
return result.ifBlank { null }
|
||||
}
|
||||
|
||||
private fun extractPhotoFileName(path: String): String {
|
||||
val clean = path.trim().substringBefore("?").substringBefore("#")
|
||||
// Handle both regular slashes and URL-encoded slashes (%2F)
|
||||
|
||||
Reference in New Issue
Block a user