Skip to content

Commit

Permalink
Revert "Revert "feat: save history in all environments""
Browse files Browse the repository at this point in the history
This reverts commit 9ba6dd1.
  • Loading branch information
NilsOveTen committed Sep 29, 2023
1 parent 9ba6dd1 commit 1e5f526
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ import org.springframework.boot.context.properties.ConfigurationProperties
data class ApplicationProperties(
val collectionBaseUri: String,
val historyServiceUri: String,
val adminServiceUri: String,
val namespace: String
val adminServiceUri: String
)
23 changes: 13 additions & 10 deletions src/main/kotlin/no/fdk/concept_catalog/service/ConceptService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,19 @@ class ConceptService(
return saveConceptsAndUpdateHistory(mapOf(Pair(patched, operations)), user, jwt).first()
}

private fun saveConceptsAndUpdateHistory(conceptsAndOperations: Map<BegrepDBO, List<JsonPatchOperation>>, user: User, jwt: Jwt) =
if (applicationProperties.namespace == "staging") {
val locations = conceptsAndOperations.map { historyService.updateHistory(it.key, it.value, user, jwt) }
try {
conceptRepository.saveAll(conceptsAndOperations.keys).map { it.withHighestVersionDTO() }
} catch (ex: Exception) {
locations.filterNotNull().forEach { historyService.removeHistoryUpdate(it, jwt) }
throw ex
}
} else conceptRepository.saveAll(conceptsAndOperations.keys).map { it.withHighestVersionDTO() }
private fun saveConceptsAndUpdateHistory(
conceptsAndOperations: Map<BegrepDBO, List<JsonPatchOperation>>,
user: User,
jwt: Jwt
): List<Begrep> {
val locations = conceptsAndOperations.map { historyService.updateHistory(it.key, it.value, user, jwt) }
try {
return conceptRepository.saveAll(conceptsAndOperations.keys).map { it.withHighestVersionDTO() }
} catch (ex: Exception) {
locations.filterNotNull().forEach { historyService.removeHistoryUpdate(it, jwt) }
throw ex
}
}

fun isPublishedAndNotValid(concept: Begrep): Boolean {
val published = getLastPublished(concept.originaltBegrep)
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ application:
collectionBaseUri: ${COLLECTION_BASE_URI:https://concept-catalog.fellesdatakatalog.digdir.no}
historyServiceUri: ${CATALOG_HISTORY_SERVICE_URI:http://localhost:9090}
adminServiceUri: ${CATALOG_ADMIN_SERVICE_URI:https://catalog-admin-service.fellesdatakatalog.digdir.no}
namespace: ${NAMESPACE:staging}

---
spring:
Expand Down

0 comments on commit 1e5f526

Please sign in to comment.