diff --git a/.github/workflows/deploy-prod&demo.yaml b/.github/workflows/deploy-prod&demo.yaml index 68c267d..91bdbbc 100644 --- a/.github/workflows/deploy-prod&demo.yaml +++ b/.github/workflows/deploy-prod&demo.yaml @@ -16,7 +16,6 @@ jobs: environment: prod secrets: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GCP_SA_DIGDIR_FDK_GCR_KEY: ${{ secrets.GCP_SA_DIGDIR_FDK_GCR_KEY }} CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} deploy-prod: diff --git a/.github/workflows/deploy-staging.yaml b/.github/workflows/deploy-staging.yaml index 9094902..01b9e48 100644 --- a/.github/workflows/deploy-staging.yaml +++ b/.github/workflows/deploy-staging.yaml @@ -18,7 +18,6 @@ jobs: environment: staging secrets: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GCP_SA_DIGDIR_FDK_GCR_KEY: ${{ secrets.GCP_SA_DIGDIR_FDK_GCR_KEY }} CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} deploy: @@ -41,5 +40,3 @@ jobs: uses: Informasjonsforvaltning/workflows/.github/workflows/build.yaml@main with: java_version: '17' - secrets: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/deploy/base/kustomization.yaml b/deploy/base/kustomization.yaml index 63767a3..11922bf 100644 --- a/deploy/base/kustomization.yaml +++ b/deploy/base/kustomization.yaml @@ -6,5 +6,5 @@ resources: - concept-catalog-service.yaml images: - name: concept-catalog - newName: eu.gcr.io/digdir-fdk-infra/concept-catalog + newName: ghcr.io/informasjonsforvaltning/concept-catalog newTag: $(GIT_COMMIT_SHA) diff --git a/src/main/kotlin/no/fdk/concept_catalog/elastic/ElasticUpdater.kt b/src/main/kotlin/no/fdk/concept_catalog/elastic/ElasticUpdater.kt index c2c582d..d04f9bc 100644 --- a/src/main/kotlin/no/fdk/concept_catalog/elastic/ElasticUpdater.kt +++ b/src/main/kotlin/no/fdk/concept_catalog/elastic/ElasticUpdater.kt @@ -26,13 +26,11 @@ class ElasticUpdater( } catch (_: Exception) { } conceptRepository.findAll() + .groupBy { concept -> concept.originaltBegrep } + .mapNotNull { pair -> pair.value.maxByOrNull { concept -> concept.versjonsnr } } .forEach { - if (it.shouldBeCurrent(currentConceptRepository.findByIdOrNull(it.originaltBegrep))) { - logger.debug("reindexing ${it.id}, ${it.ansvarligVirksomhet.id}") - currentConceptRepository.save(CurrentConcept(it)) - } else { - logger.debug("skipping not current ${it.id}, ${it.ansvarligVirksomhet.id}") - } + logger.debug("reindexing ${it.id}, ${it.ansvarligVirksomhet.id}") + currentConceptRepository.save(CurrentConcept(it)) } logger.info("finished reindexing elastic") @@ -40,11 +38,3 @@ class ElasticUpdater( } } - -fun BegrepDBO.shouldBeCurrent(current: CurrentConcept?): Boolean = - when { - current == null -> true - erPublisert && !current.erPublisert -> true - !erPublisert && current.erPublisert -> false - else -> versjonsnr > current.versjonsnr - } diff --git a/src/main/kotlin/no/fdk/concept_catalog/model/Begrep.kt b/src/main/kotlin/no/fdk/concept_catalog/model/Begrep.kt index 3450b9c..0a2c075 100644 --- a/src/main/kotlin/no/fdk/concept_catalog/model/Begrep.kt +++ b/src/main/kotlin/no/fdk/concept_catalog/model/Begrep.kt @@ -63,6 +63,7 @@ data class Begrep ( val originaltBegrep: String? = null, val versjonsnr: SemVer? = null, val erSistPublisert: Boolean = false, + val sistPublisertId: String? = null, val revisjonAvSistPublisert: Boolean = false, val revisjonAv: String? = null, val status: Status? = null, diff --git a/src/main/kotlin/no/fdk/concept_catalog/service/ChangeRequestService.kt b/src/main/kotlin/no/fdk/concept_catalog/service/ChangeRequestService.kt index 477ab5b..b1b9ef3 100644 --- a/src/main/kotlin/no/fdk/concept_catalog/service/ChangeRequestService.kt +++ b/src/main/kotlin/no/fdk/concept_catalog/service/ChangeRequestService.kt @@ -1,6 +1,5 @@ package no.fdk.concept_catalog.service -import no.fdk.concept_catalog.elastic.CurrentConceptRepository import no.fdk.concept_catalog.model.* import java.util.UUID import no.fdk.concept_catalog.repository.ChangeRequestRepository @@ -21,7 +20,6 @@ private val logger = LoggerFactory.getLogger(ChangeRequestService::class.java) class ChangeRequestService( private val changeRequestRepository: ChangeRequestRepository, private val conceptRepository: ConceptRepository, - private val currentConceptRepository: CurrentConceptRepository, private val conceptService: ConceptService, private val mapper: ObjectMapper ) { @@ -91,7 +89,6 @@ class ChangeRequestService( val conceptToUpdate = when { dbConcept == null -> createNewConcept(Virksomhet(id=catalogId), user) .updateLastChangedAndByWhom(user) - .also { currentConceptRepository.save(CurrentConcept(it)) } .let { conceptRepository.save(it) } dbConcept.erPublisert -> dbConcept.createNewRevision() .updateLastChangedAndByWhom(user) @@ -105,9 +102,6 @@ class ChangeRequestService( logger.error("update of concept failed when accepting ${changeRequest.id}, reverting acceptation", ex) changeRequest.copy(status = ChangeRequestStatus.OPEN).run { changeRequestRepository.save(this) } if (conceptToUpdate.id != dbConcept?.id) { - if (conceptToUpdate.id == conceptToUpdate.originaltBegrep) { - currentConceptRepository.delete(CurrentConcept(conceptToUpdate)) - } conceptRepository.delete(conceptToUpdate) } throw ex diff --git a/src/main/kotlin/no/fdk/concept_catalog/service/ConceptMappers.kt b/src/main/kotlin/no/fdk/concept_catalog/service/ConceptMappers.kt index 649a302..616976d 100644 --- a/src/main/kotlin/no/fdk/concept_catalog/service/ConceptMappers.kt +++ b/src/main/kotlin/no/fdk/concept_catalog/service/ConceptMappers.kt @@ -13,6 +13,7 @@ fun BegrepDBO.toDTO(highestPublishedVersion: SemVer?, highestPublishedId: String originaltBegrep, versjonsnr, erSistPublisert = isHighestPublishedVersion(highestPublishedVersion), + sistPublisertId = highestPublishedId, revisjonAvSistPublisert = isRevisionOfHighestPublishedVersion(highestPublishedId), revisjonAv, status, diff --git a/src/main/kotlin/no/fdk/concept_catalog/service/ConceptService.kt b/src/main/kotlin/no/fdk/concept_catalog/service/ConceptService.kt index 799e3ed..abd42b7 100644 --- a/src/main/kotlin/no/fdk/concept_catalog/service/ConceptService.kt +++ b/src/main/kotlin/no/fdk/concept_catalog/service/ConceptService.kt @@ -210,7 +210,6 @@ class ConceptService( val locations = conceptsAndOperations.map { historyService.updateHistory(it.key, it.value, user, jwt) } try { conceptsAndOperations.keys - .filter { it.id == it.originaltBegrep } .map { CurrentConcept(it) } .run { currentConceptRepository.saveAll(this) } return conceptRepository.saveAll(conceptsAndOperations.keys).map { it.withHighestVersionDTO() } diff --git a/src/test/kotlin/no/fdk/concept_catalog/contract/ChangeRequests.kt b/src/test/kotlin/no/fdk/concept_catalog/contract/ChangeRequests.kt index 1d9bfae..b98d120 100644 --- a/src/test/kotlin/no/fdk/concept_catalog/contract/ChangeRequests.kt +++ b/src/test/kotlin/no/fdk/concept_catalog/contract/ChangeRequests.kt @@ -436,6 +436,7 @@ class ChangeRequests : ApiTestContext() { versjonsnr = SemVer(1, 0, 2), erPublisert = false, erSistPublisert = false, + sistPublisertId = BEGREP_0.id, publiseringsTidspunkt = null, revisjonAv = BEGREP_0.id, revisjonAvSistPublisert = true, diff --git a/src/test/kotlin/no/fdk/concept_catalog/contract/PublishConcept.kt b/src/test/kotlin/no/fdk/concept_catalog/contract/PublishConcept.kt index 9fff3b6..6dfd725 100644 --- a/src/test/kotlin/no/fdk/concept_catalog/contract/PublishConcept.kt +++ b/src/test/kotlin/no/fdk/concept_catalog/contract/PublishConcept.kt @@ -112,6 +112,7 @@ class PublishConcept : ApiTestContext() { assertEquals(BEGREP_TO_BE_UPDATED.copy( erPublisert = true, erSistPublisert = true, + sistPublisertId = "id-to-be-updated", publiseringsTidspunkt = result.publiseringsTidspunkt ), result) } diff --git a/src/test/kotlin/no/fdk/concept_catalog/contract/SearchConcepts.kt b/src/test/kotlin/no/fdk/concept_catalog/contract/SearchConcepts.kt index 4175125..bf581d3 100644 --- a/src/test/kotlin/no/fdk/concept_catalog/contract/SearchConcepts.kt +++ b/src/test/kotlin/no/fdk/concept_catalog/contract/SearchConcepts.kt @@ -651,6 +651,6 @@ class SearchConcepts : ApiTestContext() { assertEquals(HttpStatus.OK.value(), rsp["status"]) val result: Paginated = mapper.readValue(rsp["body"] as String) - assertEquals(listOf(BEGREP_HAS_MULTIPLE_REVISIONS), result.hits) + assertEquals(listOf(BEGREP_UNPUBLISHED_REVISION_MULTIPLE_SECOND), result.hits) } } diff --git a/src/test/kotlin/no/fdk/concept_catalog/service/LastPublished.kt b/src/test/kotlin/no/fdk/concept_catalog/service/LastPublished.kt index 7998e23..4cfab29 100644 --- a/src/test/kotlin/no/fdk/concept_catalog/service/LastPublished.kt +++ b/src/test/kotlin/no/fdk/concept_catalog/service/LastPublished.kt @@ -53,8 +53,8 @@ class LastPublished { @Test fun `Sets revision of last published for relevant concepts`() { val newPublished = BEGREP_3.copy(id = "id3-1", versjonsnr = SemVer(1, 9, 1), revisjonAv = "id3") - val invalid = BEGREP_3.copy(id = "id3-2", versjonsnr = SemVer(2, 10, 0), revisjonAv = "id3", status = Status.GODKJENT, erPublisert = false, revisjonAvSistPublisert = false) - val ok = BEGREP_3.copy(id = "id3-3", versjonsnr = SemVer(2, 10, 0), revisjonAv = "id3-1", status = Status.UTKAST, erPublisert = false, revisjonAvSistPublisert = true) + val invalid = BEGREP_3.copy(id = "id3-2", sistPublisertId = "id3-1", versjonsnr = SemVer(2, 10, 0), revisjonAv = "id3", status = Status.GODKJENT, erPublisert = false, revisjonAvSistPublisert = false) + val ok = BEGREP_3.copy(id = "id3-3", sistPublisertId = "id3-1", versjonsnr = SemVer(2, 10, 0), revisjonAv = "id3-1", status = Status.UTKAST, erPublisert = false, revisjonAvSistPublisert = true) whenever(conceptRepository.findById("id3-2")) .thenReturn(Optional.of(invalid.toDBO())) diff --git a/src/test/kotlin/no/fdk/concept_catalog/utils/ResetElastic.kt b/src/test/kotlin/no/fdk/concept_catalog/utils/ResetElastic.kt index 6ab6109..6d1d040 100644 --- a/src/test/kotlin/no/fdk/concept_catalog/utils/ResetElastic.kt +++ b/src/test/kotlin/no/fdk/concept_catalog/utils/ResetElastic.kt @@ -1,13 +1,11 @@ package no.fdk.concept_catalog.utils import no.fdk.concept_catalog.elastic.CurrentConceptRepository -import no.fdk.concept_catalog.elastic.shouldBeCurrent import no.fdk.concept_catalog.model.BegrepDBO import no.fdk.concept_catalog.model.CurrentConcept import org.springframework.beans.factory.annotation.Autowired import org.springframework.data.mongodb.core.MongoTemplate import org.springframework.data.mongodb.core.findAll -import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Component @Component @@ -21,10 +19,9 @@ class ResetElastic { fun elasticReindex() { val concepts = conceptRepository.findAll() currentConceptRepository.deleteAll() - concepts.forEach { - if (it.shouldBeCurrent(currentConceptRepository.findByIdOrNull(it.originaltBegrep))) { - currentConceptRepository.save(CurrentConcept(it)) - } - } + concepts + .groupBy { concept -> concept.originaltBegrep } + .mapNotNull { pair -> pair.value.maxByOrNull { concept -> concept.versjonsnr } } + .forEach { currentConceptRepository.save(CurrentConcept(it)) } } } diff --git a/src/test/kotlin/no/fdk/concept_catalog/utils/TestData.kt b/src/test/kotlin/no/fdk/concept_catalog/utils/TestData.kt index 19ac572..e454a53 100644 --- a/src/test/kotlin/no/fdk/concept_catalog/utils/TestData.kt +++ b/src/test/kotlin/no/fdk/concept_catalog/utils/TestData.kt @@ -31,6 +31,7 @@ val BEGREP_0_OLD = Begrep( status = Status.PUBLISERT, statusURI = "http://publications.europa.eu/resource/authority/concept-status/DEPRECATED", erPublisert = true, + sistPublisertId = "id0", publiseringsTidspunkt = ZonedDateTime.of(2019, 1, 1, 12,0,0,0, ZoneId.of("Europe/Oslo")).toInstant(), gjeldendeRevisjon = null, anbefaltTerm = Term(navn = mapOf(Pair("nb", "old anbefaltTerm"))), @@ -64,6 +65,7 @@ val BEGREP_0 = Begrep( publiseringsTidspunkt = ZonedDateTime.of(2020, 1, 2, 12,0,0,0, ZoneId.of("Europe/Oslo")).toInstant(), gjeldendeRevisjon = null, erSistPublisert = true, + sistPublisertId = "id0", anbefaltTerm = Term(navn = mapOf(Pair("nb", "anbefaltTerm"))), tillattTerm = mapOf(Pair("nn", listOf("tillattTerm", "tillattTerm2"))), frarådetTerm = mapOf(Pair("nb", listOf("fraraadetTerm", "fraraadetTerm2", "Lorem ipsum"))), @@ -274,6 +276,7 @@ val BEGREP_4 = Begrep( statusURI = "http://publications.europa.eu/resource/authority/concept-status/CURRENT", erPublisert = true, erSistPublisert = true, + sistPublisertId = "id4", publiseringsTidspunkt = ZonedDateTime.of(2020, 1, 2, 12,0,0,0, ZoneId.of("Europe/Oslo")).toInstant(), gjeldendeRevisjon = null, anbefaltTerm = Term(navn = mapOf(Pair("en", "Begrep 4"))), @@ -303,6 +306,7 @@ val BEGREP_5 = Begrep( statusURI = "http://publications.europa.eu/resource/authority/concept-status/CURRENT", erPublisert = true, erSistPublisert = true, + sistPublisertId = "id5", publiseringsTidspunkt = ZonedDateTime.of(2020, 1, 2, 12,0,0,0, ZoneId.of("Europe/Oslo")).toInstant(), gjeldendeRevisjon = null, anbefaltTerm = Term(navn = mapOf(Pair("en", "Begrep 5"))), @@ -412,6 +416,7 @@ val BEGREP_HAS_MULTIPLE_REVISIONS = Begrep( statusURI = "http://publications.europa.eu/resource/authority/concept-status/CURRENT", erPublisert = true, erSistPublisert = true, + sistPublisertId = "id-has-multiple-revisions", publiseringsTidspunkt = ZonedDateTime.of(2020, 1, 2, 12,0,0,0, ZoneId.of("Europe/Oslo")).toInstant(), gjeldendeRevisjon = "id-unpublished-revision-multiple-first", versjonsnr = SemVer(0, 0, 1), @@ -428,6 +433,7 @@ val BEGREP_UNPUBLISHED_REVISION_MULTIPLE_FIRST = Begrep( status = Status.UTKAST, statusURI = "http://publications.europa.eu/resource/authority/concept-status/DRAFT", erPublisert = false, + sistPublisertId = "id-has-multiple-revisions", gjeldendeRevisjon = null, versjonsnr = SemVer(0, 0, 2), ansvarligVirksomhet = Virksomhet( @@ -443,8 +449,9 @@ val BEGREP_UNPUBLISHED_REVISION_MULTIPLE_SECOND = Begrep( status = Status.UTKAST, statusURI = "http://publications.europa.eu/resource/authority/concept-status/DRAFT", erPublisert = false, + sistPublisertId = "id-has-multiple-revisions", gjeldendeRevisjon = null, - versjonsnr = SemVer(0, 0, 2), + versjonsnr = SemVer(0, 0, 3), ansvarligVirksomhet = Virksomhet( id = "222222222" ),