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["percentualanterior"] ?: 3] = history.percentualAnterior.toString()
|
||||||
row[headerIndices["percentualnovo"] ?: 4] = history.percentualNovo.toString()
|
row[headerIndices["percentualnovo"] ?: 4] = history.percentualNovo.toString()
|
||||||
row[headerIndices["observacao"] ?: 5] = history.observacao ?: ""
|
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["responsavel"] ?: 7] = history.recurso
|
||||||
row[headerIndices["email_editor"] ?: 8] = history.emailEditor ?: ""
|
row[headerIndices["email_editor"] ?: 8] = history.emailEditor ?: ""
|
||||||
row
|
row
|
||||||
@@ -930,7 +930,7 @@ class GoogleSheetsSyncService(
|
|||||||
finding.timestamp.toString(),
|
finding.timestamp.toString(),
|
||||||
finding.responsavel,
|
finding.responsavel,
|
||||||
finding.emailEditor ?: "",
|
finding.emailEditor ?: "",
|
||||||
finding.fotoPath ?: ""
|
filterRemoteOnlyPhotoPaths(finding.fotoPath)
|
||||||
)
|
)
|
||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
|
|
||||||
@@ -948,5 +948,14 @@ class GoogleSheetsSyncService(
|
|||||||
Log.d(tag, "Successfully updated 'achados' sheet with ${allActiveFindings.size} active findings.")
|
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()
|
val effectiveTimestamp = customTimestampMillis ?: System.currentTimeMillis()
|
||||||
|
|
||||||
// Handle observation and photo update as an OSFinding of type OBS if filled or photo attached
|
// 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()) {
|
if (cleanObs != null || !fotoPath.isNullOrBlank()) {
|
||||||
val obsText = cleanObs ?: "Foto anexada"
|
val obsText = cleanObs ?: "Foto anexada"
|
||||||
val findingObs = OSFinding(
|
val findingObs = OSFinding(
|
||||||
@@ -97,7 +97,7 @@ class MaintenanceRepository(
|
|||||||
dao.insertFinding(findingObs)
|
dao.insertFinding(findingObs)
|
||||||
}
|
}
|
||||||
|
|
||||||
val latestObsText = cleanObs ?: currentActivity.observacoes
|
val latestObsText = cleanObs ?: stripAuditTags(currentActivity.observacoes)
|
||||||
|
|
||||||
val updatedActivity = currentActivity.copy(
|
val updatedActivity = currentActivity.copy(
|
||||||
percentualExecucao = novoPercentual.coerceIn(0, 100),
|
percentualExecucao = novoPercentual.coerceIn(0, 100),
|
||||||
@@ -151,7 +151,7 @@ class MaintenanceRepository(
|
|||||||
if (tipo == "OBS" && currentActivity != null) {
|
if (tipo == "OBS" && currentActivity != null) {
|
||||||
dao.updateActivity(
|
dao.updateActivity(
|
||||||
currentActivity.copy(
|
currentActivity.copy(
|
||||||
observacoes = descricao.trim(),
|
observacoes = stripAuditTags(descricao),
|
||||||
synced = false,
|
synced = false,
|
||||||
lastUpdated = effectiveTimestamp
|
lastUpdated = effectiveTimestamp
|
||||||
)
|
)
|
||||||
@@ -196,7 +196,7 @@ class MaintenanceRepository(
|
|||||||
if (finding.tipo == "OBS" && currentActivity != null) {
|
if (finding.tipo == "OBS" && currentActivity != null) {
|
||||||
dao.updateActivity(
|
dao.updateActivity(
|
||||||
currentActivity.copy(
|
currentActivity.copy(
|
||||||
observacoes = finding.descricao.trim(),
|
observacoes = stripAuditTags(finding.descricao),
|
||||||
synced = false,
|
synced = false,
|
||||||
lastUpdated = effectiveTimestamp
|
lastUpdated = effectiveTimestamp
|
||||||
)
|
)
|
||||||
@@ -499,9 +499,10 @@ class MaintenanceRepository(
|
|||||||
latestLog.fotoPath ?: activity.fotoPath
|
latestLog.fotoPath ?: activity.fotoPath
|
||||||
}
|
}
|
||||||
val finalFotoPath = mergePreservingDeletedPhotos(localFotoPath, baseFotoPath)
|
val finalFotoPath = mergePreservingDeletedPhotos(localFotoPath, baseFotoPath)
|
||||||
|
val cleanLatestObs = stripAuditTags(latestLog.observacao) ?: stripAuditTags(activity.observacoes)
|
||||||
activity.copy(
|
activity.copy(
|
||||||
percentualExecucao = latestLog.percentualNovo,
|
percentualExecucao = latestLog.percentualNovo,
|
||||||
observacoes = latestLog.observacao ?: activity.observacoes,
|
observacoes = cleanLatestObs,
|
||||||
fotoPath = finalFotoPath,
|
fotoPath = finalFotoPath,
|
||||||
synced = true,
|
synced = true,
|
||||||
lastUpdated = latestLog.timestamp
|
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 {
|
private fun extractPhotoFileName(path: String): String {
|
||||||
val clean = path.trim().substringBefore("?").substringBefore("#")
|
val clean = path.trim().substringBefore("?").substringBefore("#")
|
||||||
// Handle both regular slashes and URL-encoded slashes (%2F)
|
// Handle both regular slashes and URL-encoded slashes (%2F)
|
||||||
|
|||||||
Reference in New Issue
Block a user