Skip to content

Commit

Permalink
Related documentation linking
Browse files Browse the repository at this point in the history
RISDEV-2741
  • Loading branch information
HPrinz committed Nov 23, 2023
1 parent 3e04ee8 commit 3bde26b
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fileignoreconfig:
- filename: backend/src/main/kotlin/de/bund/digitalservice/ris/norms/framework/adapter/input/restapi/controller/GetFileController.kt
checksum: f989b3c9c176b1b985c2f78ca6ca13fa1403cbb69f367ae9b1cb8ea64d5f6747
- filename: backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/JurisXmlExporterWrapperIntegrationTest.java
checksum: 9a66a60524fe18f695fa14dfc09863b30f852789981175b5b33cfdc40413a9c3
checksum: bfe9d5c92665135fd4dbc600b1cd2879acc63233e17f63fabd697ee5f9ee15b1
- filename: backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DeviatingObjectIntegrationTest.java
checksum: 2acbd31b8e6df62a898ab596cf5549f8713d7d4ef29d6d0d977b2a802e8fa6d4
- filename: backend/src/test/kotlin/unit/adapter/input/restapi/controller/GenerateNormFileControllerTest.kt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package de.bund.digitalservice.ris.caselaw.adapter.database.jpa;

import java.util.List;
import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface DatabaseRelatedDocumentationRepository
extends JpaRepository<RelatedDocumentationDTO, UUID> {
// List<RelatedDocumentationDTO> findAllByReferencedDocumentUnitId(UUID documentationUnitId);
List<RelatedDocumentationDTO> findAllByReferencedDocumentationUnitId(UUID documentationUnitId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import de.bund.digitalservice.ris.caselaw.domain.Status;
import de.bund.digitalservice.ris.caselaw.domain.court.Court;
import java.time.Instant;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
Expand All @@ -38,16 +38,20 @@ public class PostgresDocumentationUnitRepositoryImpl implements DocumentUnitRepo
private final DatabaseDocumentationOfficeRepository documentationOfficeRepository;
private final JPADatabaseKeywordRepository keywordRepository;

private final DatabaseRelatedDocumentationRepository relatedDocumentationRepository;

public PostgresDocumentationUnitRepositoryImpl(
DatabaseDocumentationUnitRepository repository,
DatabaseCourtRepository databaseCourtRepository,
DatabaseDocumentationOfficeRepository documentationOfficeRepository,
JPADatabaseKeywordRepository keywordRepository) {
JPADatabaseKeywordRepository keywordRepository,
DatabaseRelatedDocumentationRepository relatedDocumentationRepository) {

this.repository = repository;
this.databaseCourtRepository = databaseCourtRepository;
this.documentationOfficeRepository = documentationOfficeRepository;
this.keywordRepository = keywordRepository;
this.relatedDocumentationRepository = relatedDocumentationRepository;
}

@Override
Expand Down Expand Up @@ -311,14 +315,9 @@ public Page<DocumentationUnitSearchResult> searchByDocumentationUnitSearchInput(
@Override
public Map<RelatedDocumentationType, Long> getAllDocumentationUnitWhichLink(
UUID documentationUnitId) {
// TODO: activate after referenced documentation unit id in related documentation
return Collections.emptyMap();
// return
// relatedDocumentationRepository.findAllByReferencedDocumentUnitId(documentationUnitId).stream()
// .collect(Collectors.groupingBy(
// RelatedDocumentationDTO::getType,
// Collectors.counting()
// )
// );
return relatedDocumentationRepository
.findAllByReferencedDocumentationUnitId(documentationUnitId)
.stream()
.collect(Collectors.groupingBy(RelatedDocumentationDTO::getType, Collectors.counting()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class RelatedDocumentationDTO {
@Column(name = "date")
private LocalDate date;

@Column(name = "document_number", insertable = false, updatable = false)
@Column(name = "document_number")
private String documentNumber;

@ManyToOne
Expand All @@ -61,10 +61,9 @@ public abstract class RelatedDocumentationDTO {
@Column @NotNull private Integer rank;

@ManyToOne
@JoinColumn(
name = "documentation_unit_id",
referencedColumnName = "id",
updatable = false,
insertable = false)
@JoinColumn(name = "documentation_unit_id", referencedColumnName = "id")
private DocumentationUnitDTO referencedDocumentationUnit;

@Column(name = "documentation_unit_id", insertable = false, updatable = false)
private UUID referencedDocumentationUnitId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public static ActiveCitation transformToDomain(ActiveCitationDTO activeCitationD
return ActiveCitation.builder()
.uuid(activeCitationDTO.getId())
.documentNumber(activeCitationDTO.getDocumentNumber())
.documentationUnitId(activeCitationDTO.getReferencedDocumentationUnit().getId())
.documentationUnitId(
activeCitationDTO.getReferencedDocumentationUnit() == null
? null
: activeCitationDTO.getReferencedDocumentationUnit().getId())
.court(getCourtFromDTO(activeCitationDTO.getCourt()))
.fileNumber(getFileNumber(activeCitationDTO.getFileNumber()))
.documentType(getDocumentTypeFromDTO(activeCitationDTO.getDocumentType()))
Expand All @@ -49,7 +52,11 @@ public static ActiveCitationDTO transformToDTO(ActiveCitation activeCitation) {
.date(activeCitation.getDecisionDate())
.documentNumber(activeCitation.getDocumentNumber())
.referencedDocumentationUnit(
DocumentationUnitDTO.builder().id(activeCitation.getDocumentationUnitId()).build())
activeCitation.getDocumentationUnitId() == null
? null
: DocumentationUnitDTO.builder()
.id(activeCitation.getDocumentationUnitId())
.build())
.documentType(getDocumentTypeFromDomain(activeCitation.getDocumentType()))
.fileNumber(getFileNumber(activeCitation.getFileNumber()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void testSearchResultsAreDeterministic() {
String responseBody = new String(response.getResponseBody(), StandardCharsets.UTF_8);
assertThat(responseBody).isNotNull();

List<String> uuids = JsonPath.read(responseBody, "$.content[*].uuid");
List<String> uuids = JsonPath.read(responseBody, "$.content[*].documentationUnitId");
assertThat(uuids).hasSize(20);
responseUUIDs.addAll(uuids.stream().map(UUID::fromString).toList());
});
Expand All @@ -450,7 +450,7 @@ void testSearchResultsAreDeterministic() {
String responseBody = new String(response.getResponseBody(), StandardCharsets.UTF_8);
assertThat(responseBody).isNotNull();

List<String> uuids = JsonPath.read(responseBody, "$.content[*].uuid");
List<String> uuids = JsonPath.read(responseBody, "$.content[*].documentationUnitId");
List<UUID> responseUUIDs2 = uuids.stream().map(UUID::fromString).toList();

assertThat(responseUUIDs2).isEqualTo(responseUUIDs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ void testDocumentUnitIsSyncedWithModel()
PreviousDecision.builder()
.uuid(UUID.randomUUID())
.documentNumber("documentNumber")
.documentationUnitId(UUID.randomUUID())
.court(new Court(UUID.randomUUID(), "courtType", "courtPlace", "courtLabel", null))
.decisionDate(LocalDate.parse("2020-04-05"))
.dateKnown(true)
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/ActiveCitations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const activeCitations = computed({
const defaultValue = new ActiveCitation()
function decisionSummarizer(activeCitation: ActiveCitation) {
// Todo implement linked logic
if (activeCitation.hasForeignSource) {
return h("div", { class: ["flex flex-row items-center"] }, [
!activeCitation.citationType &&
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/components/InlineDecision.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ defineProps<{

<template>
<div>
<!-- Todo implement linked logic -->

<router-link
v-if="decision.hasForeignSource"
class="ds-link-01-bold underline"
Expand All @@ -25,6 +23,6 @@ defineProps<{
</button>
</router-link>

<span class="ds-label-02-reg">{{ decision.renderDecision }}</span>
<span v-else class="ds-label-02-reg">{{ decision.renderDecision }}</span>
</div>
</template>
6 changes: 3 additions & 3 deletions frontend/src/domain/activeCitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export default class ActiveCitation
{
public citationType?: CitationType

public hasForeignSource: boolean = this.documentNumber !== undefined

static requiredFields = [
"citationType",
"fileNumber",
Expand Down Expand Up @@ -40,7 +38,9 @@ export default class ActiveCitation
: []),
...(this.fileNumber ? [this.fileNumber] : []),
...(this.documentType ? [this.documentType.label] : []),
...(this.documentNumber ? [this.documentNumber] : []),
...(this.documentNumber && this.hasForeignSource
? [this.documentNumber]
: []),
].join(", ")
}

Expand Down
4 changes: 3 additions & 1 deletion frontend/src/domain/ensuingDecision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export default class EnsuingDecision
...(this.fileNumber ? [this.fileNumber] : []),
...(this.documentType ? [this.documentType?.jurisShortcut] : []),
...(this.note ? [this.note] : []),
...(this.documentNumber ? [this.documentNumber] : []),
...(this.documentNumber && this.hasForeignSource
? [this.documentNumber]
: []),
].join(", ")
}

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/domain/previousDecision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export default class PreviousDecision
...(this.dateKnown === false ? ["Datum unbekannt"] : []),
...(this.fileNumber ? [this.fileNumber] : []),
...(this.documentType ? [this.documentType?.jurisShortcut] : []),
...(this.documentNumber ? [this.documentNumber] : []),
...(this.documentNumber && this.hasForeignSource
? [this.documentNumber]
: []),
].join(", ")
}

Expand All @@ -46,7 +48,6 @@ export default class PreviousDecision
}

get isReadOnly(): boolean {
// Todo implement linked logic
return this.hasForeignSource
}

Expand Down
8 changes: 7 additions & 1 deletion frontend/src/domain/relatedDocumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export default class RelatedDocumentation {
public fileNumber?: string
public documentType?: DocumentType

get hasForeignSource(): boolean {
return this.documentNumber != null
}

constructor(data: Partial<RelatedDocumentation> = {}) {
Object.assign(this, data)
}
Expand All @@ -31,7 +35,9 @@ export default class RelatedDocumentation {
: []),
...(this.documentType ? [this.documentType.label] : []),
...(this.fileNumber ? [this.fileNumber] : []),
...(this.documentNumber ? [this.documentNumber] : []),
...(this.documentNumber && this.hasForeignSource
? [this.documentNumber]
: []),
].join(", ")
}
}
21 changes: 10 additions & 11 deletions frontend/test/components/previousDecisions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function generatePreviousDecision(options?: {
}) {
const previousDecision = new PreviousDecision({
uuid: options?.uuid ?? "123",
documentNumber: "ABC",
documentNumber: options?.documentNumber ?? undefined,
court: options?.court ?? {
type: "type1",
location: "location1",
Expand Down Expand Up @@ -307,7 +307,7 @@ describe("PreviousDecisions", () => {

expect(
screen.getByText(
"label1, 01.02.2022, test fileNumber, documentTypeShortcut1, ABC",
"label1, 01.02.2022, test fileNumber, documentTypeShortcut1",
),
).toBeInTheDocument()
const editButton = screen.getByLabelText("Eintrag bearbeiten")
Expand All @@ -330,15 +330,14 @@ describe("PreviousDecisions", () => {
).toBeInTheDocument()
})

// Todo: enable again when linking possible
// it("renders from search added active citations as non-editable list item", async () => {
// renderComponent({
// modelValue: [generatePreviousDecision()],
// })
// expect(
// screen.queryByLabelText("Eintrag bearbeiten"),
// ).not.toBeInTheDocument()
// })
it("renders from search added active citations as non-editable list item", async () => {
renderComponent({
modelValue: [generatePreviousDecision({ documentNumber: "ABC" })],
})
expect(
screen.queryByLabelText("Eintrag bearbeiten"),
).not.toBeInTheDocument()
})

it("lists search results", async () => {
const { user } = renderComponent()
Expand Down

0 comments on commit 3bde26b

Please sign in to comment.