Skip to content

Commit

Permalink
Category import (#2448)
Browse files Browse the repository at this point in the history
* Refactor category import

RISDEV-5888

* Add spacing for error modal

RISDEV-5888

* Add active citations to category import

RISDEV-5888

* Add tests

RISDEV-5888

* Add tests for duplication

RISDEV-5888
  • Loading branch information
leonie-koch authored Dec 24, 2024
1 parent 51da7ec commit 51b3e88
Show file tree
Hide file tree
Showing 11 changed files with 386 additions and 464 deletions.
34 changes: 34 additions & 0 deletions backend/src/main/resources/db-scripts/seed/R__seeding_testdata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -965,3 +965,37 @@ VALUES
WHERE abbreviation = 'BGB'
)
);

INSERT INTO
incremental_migration.related_documentation (id, dtype, document_number, documentation_unit_id, citation_type_id, referenced_documentation_unit_id, court_id, date)
VALUES
(
gen_random_uuid (),
'caselaw_active_citation',
'YYTestDoc0013',
(
SELECT id
FROM incremental_migration.documentation_unit
WHERE document_number = 'YYTestDoc0013'
),
(
SELECT id
FROM incremental_migration.citation_type
WHERE abbreviation = 'Änderung'
),
(
SELECT id
FROM incremental_migration.documentation_unit
WHERE document_number = 'YYTestDoc0012'
),
(
SELECT documentation_unit.court_id
FROM incremental_migration.documentation_unit
WHERE document_number = 'YYTestDoc0012'
),
(
SELECT documentation_unit.decision_date
FROM incremental_migration.documentation_unit
WHERE document_number = 'YYTestDoc0012'
)
);
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const hasKeywords = computed(
label="Schlagwörter"
:should-show-button="!hasKeywords"
>
<KeyWords @reset="slotProps.reset" />
<KeyWords data-testid="keywords" @reset="slotProps.reset" />
</CategoryWrapper>
<FieldsOfLaw />
<Norms />
<ActiveCitations />
<FieldsOfLaw data-testid="fieldsOfLaw" />
<Norms data-testid="norms" />
<ActiveCitations data-testid="activeCitations" />
<OtherCategories />
</div>
</template>
182 changes: 168 additions & 14 deletions frontend/src/components/category-import/CategoryImport.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
<script setup lang="ts">
import { ref, toRaw, computed, watch } from "vue"
import { RouterLink } from "vue-router"
import ImportListCategories from "@/components/category-import/ImportListCategories.vue"
import SingleCategory from "@/components/category-import/SingleCategory.vue"
import IconBadge from "@/components/IconBadge.vue"
import InputField from "@/components/input/InputField.vue"
import TextButton from "@/components/input/TextButton.vue"
import TextInput from "@/components/input/TextInput.vue"
import { useStatusBadge } from "@/composables/useStatusBadge"
import { useValidationStore } from "@/composables/useValidationStore"
import DocumentUnit from "@/domain/documentUnit"
import NormReference from "@/domain/normReference"
import SingleNorm from "@/domain/singleNorm"
import documentUnitService from "@/services/documentUnitService"
import { useDocumentUnitStore } from "@/stores/documentUnitStore"
import BaselineArrowOutward from "~icons/ic/baseline-arrow-outward"
import IconSearch from "~icons/ic/baseline-search"
const props = defineProps<{
documentNumber?: string
}>()
const store = useDocumentUnitStore()
const validationStore = useValidationStore<keyof typeof labels>()
const documentNumber = ref<string>(props.documentNumber ?? "")
const documentUnitToImport = ref<DocumentUnit | undefined>(undefined)
Expand All @@ -40,6 +45,155 @@ async function searchForDocumentUnit() {
errorMessage.value = "Keine Dokumentationseinheit gefunden."
}
}
const labels = {
keywords: "Schlagwörter",
fieldsOfLaw: "Sachgebiete",
norms: "Normen",
activeCitations: "Aktivzitierung",
}
// Handle import logic
const handleImport = async (key: keyof typeof labels) => {
validationStore.reset()
switch (key) {
case "keywords":
importKeywords()
break
case "fieldsOfLaw":
importFieldsOfLaw()
break
case "norms":
importNorms()
break
case "activeCitations":
importActiveCitations()
break
}
const updateResponse = await store.updateDocumentUnit()
if (updateResponse.error) {
validationStore.add("Fehler beim Speichern der " + labels[key], key) // add an errormessage to the validationstore field with the key
} else {
scrollToCategory(key)
}
}
function importKeywords() {
const source = documentUnitToImport.value?.contentRelatedIndexing.keywords
if (!source) return
const targetKeywords = store.documentUnit!.contentRelatedIndexing.keywords
if (targetKeywords) {
const uniqueImportableKeywords = source.filter(
(keyword) => !targetKeywords.includes(keyword),
)
targetKeywords.push(...uniqueImportableKeywords)
} else {
store.documentUnit!.contentRelatedIndexing.keywords = [...source]
}
}
function importFieldsOfLaw() {
const source = documentUnitToImport.value?.contentRelatedIndexing.fieldsOfLaw
if (!source) return
const targetFieldsOfLaw =
store.documentUnit!.contentRelatedIndexing.fieldsOfLaw
if (targetFieldsOfLaw) {
const uniqueImportableFieldsOfLaw = source.filter(
(fieldOfLaw) =>
!targetFieldsOfLaw.find(
(entry) => entry.identifier === fieldOfLaw.identifier,
),
)
targetFieldsOfLaw.push(...uniqueImportableFieldsOfLaw)
} else {
store.documentUnit!.contentRelatedIndexing.fieldsOfLaw = [...source]
}
}
function importNorms() {
const source = documentUnitToImport.value?.contentRelatedIndexing.norms
if (!source) return
const targetNorms = store.documentUnit!.contentRelatedIndexing.norms
if (targetNorms) {
source.forEach((importableNorm) => {
const existingWithAbbreviation = targetNorms.find(
(existing) =>
existing.normAbbreviation?.abbreviation ===
importableNorm.normAbbreviation?.abbreviation,
)
if (existingWithAbbreviation) {
//import single norms into existing norm reference
const singleNorms = existingWithAbbreviation?.singleNorms
if (singleNorms && importableNorm.singleNorms) {
importableNorm.singleNorms
.filter(
(importableSingleNorm) =>
!singleNorms.some(
(singleNorm) =>
singleNorm.singleNorm === importableSingleNorm.singleNorm,
),
)
.map((importableSingleNorm) => {
singleNorms.push(
new SingleNorm({
...(importableSingleNorm as SingleNorm),
id: undefined,
}),
)
})
}
} else {
// import entire norm reference
importableNorm.singleNorms?.forEach(
(singleNorm) => (singleNorm.id = undefined),
)
targetNorms.push(
new NormReference({ ...(importableNorm as NormReference) }),
)
}
})
}
}
function importActiveCitations() {
const source =
documentUnitToImport.value?.contentRelatedIndexing.activeCitations
if (!source) return
const targetActiveCitations =
store.documentUnit!.contentRelatedIndexing.activeCitations
if (targetActiveCitations) {
// consider as duplicate, if real reference found with same docnumber and citation
const uniqueImportableFieldsOfLaw = source.filter(
(activeCitation) =>
!targetActiveCitations.find(
(entry) =>
entry.documentNumber === activeCitation.documentNumber &&
entry.citationType?.uuid === activeCitation.citationType?.uuid,
),
)
targetActiveCitations.push(...uniqueImportableFieldsOfLaw)
} else {
store.documentUnit!.contentRelatedIndexing.activeCitations = [...source]
}
}
function scrollToCategory(key: string) {
const element = document.getElementById(key)
if (element) {
const headerOffset = 80
const offsetPosition =
element.getBoundingClientRect().top + window.scrollY - headerOffset
window.scrollTo({ top: offsetPosition, behavior: "smooth" })
}
}
watch(
() => props.documentNumber,
async () => {
Expand Down Expand Up @@ -114,19 +268,19 @@ watch(
<BaselineArrowOutward class="mb-4 inline w-24" />
</RouterLink>
</span>

<ImportListCategories
v-if="documentUnitToImport.contentRelatedIndexing"
:importable-fields-of-law="
documentUnitToImport.contentRelatedIndexing.fieldsOfLaw
"
:importable-keywords="
documentUnitToImport.contentRelatedIndexing.keywords
"
:importable-norms="
documentUnitToImport.contentRelatedIndexing.norms as NormReference[]
"
/>
<div v-for="(value, key) in labels" :key="key">
<SingleCategory
:error-message="validationStore.getByField(key)"
:handle-import="() => handleImport(key)"
:has-content="
!!(
documentUnitToImport.contentRelatedIndexing[key] &&
documentUnitToImport.contentRelatedIndexing[key].length > 0
)
"
:label="value"
/>
</div>
</div>
</div>
</template>
58 changes: 0 additions & 58 deletions frontend/src/components/category-import/ImportCategoryItem.vue

This file was deleted.

Loading

0 comments on commit 51b3e88

Please sign in to comment.