Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods for normelis to norm #919

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void rewriteFbrExpression(Norm norm) {
final LocalDate verkuendungsDate = LocalDate.parse(fRBRExpression.getFBRDate(), formatter);

final DokumentExpressionEli expressionEli = DokumentExpressionEli.fromWorkEli(
norm.getWorkEli(),
norm.getRegelungstext1().getWorkEli(),
verkuendungsDate,
fRBRExpression.getFRBRVersionNumber().orElseThrow(),
fRBRExpression.getFRBRlanguage().orElseThrow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli;
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentManifestationEli;
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentWorkEli;
import de.bund.digitalservice.ris.norms.domain.entity.eli.NormExpressionEli;
import de.bund.digitalservice.ris.norms.domain.entity.eli.NormManifestationEli;
import de.bund.digitalservice.ris.norms.domain.entity.eli.NormWorkEli;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -54,28 +56,52 @@ public Document getDocument() {
*
* @return The work Eli
*/
public DokumentWorkEli getWorkEli() {
return getRegelungstext1().getWorkEli();
public NormWorkEli getWorkEli() {
return getRegelungstext1().getWorkEli().asNormEli();
}

/**
* Returns the expression Eli of the {@link Norm}.
*
* @return The expression Eli
* @deprecated use {@link #getNormExpressionEli()} instead
*/
@Deprecated(forRemoval = true)
public DokumentExpressionEli getExpressionEli() {
return getRegelungstext1().getExpressionEli();
}

/**
* Returns the expression Eli of the {@link Norm}.
*
* @return The expression Eli
*/
// TODO: (Malte Laukötter, 2025-01-17) rename to getExpressionEli once the deprecated method is removed.
public NormExpressionEli getNormExpressionEli() {
return getExpressionEli().asNormEli();
}

/**
* Returns the manifestation Eli of the {@link Norm}.
*
* @return The manifestation Eli
* @deprecated use {@link #getNormManifestationEli()} instead
*/
@Deprecated(forRemoval = true)
public DokumentManifestationEli getManifestationEli() {
return getRegelungstext1().getManifestationEli();
}

/**
* Returns the expression Eli of the {@link Norm}.
*
* @return The expression Eli
*/
// TODO: (Malte Laukötter, 2025-01-17) rename to getManifestationEli once the deprecated method is removed.
public NormManifestationEli getNormManifestationEli() {
return getManifestationEli().asNormEli();
}

/**
* Returns the current version GUID as {@link UUID} from the {@link Norm}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ public static Norm loadNormFromDisk(final String fileName, boolean validated) {
return ldmlDeValidator.parseAndValidate(loadFile(fileName));
}

return Norm
.builder()
.regelungstexte(Set.of(new Regelungstext(XmlMapper.toDocument(loadFile(fileName)))))
.build();
return Norm.builder().regelungstexte(Set.of(loadRegelungstextFromDisk(fileName))).build();
}

public static Regelungstext loadRegelungstextFromDisk(final String fileName) {
return new Regelungstext(XmlMapper.toDocument(loadFile(fileName)));
}

public static String loadTextFromDisk(final String fileName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli;
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentWorkEli;
import de.bund.digitalservice.ris.norms.domain.entity.eli.NormExpressionEli;
import de.bund.digitalservice.ris.norms.domain.entity.eli.NormManifestationEli;
import de.bund.digitalservice.ris.norms.domain.entity.eli.NormWorkEli;
import de.bund.digitalservice.ris.norms.utils.NodeCreator;
import de.bund.digitalservice.ris.norms.utils.NodeParser;
import de.bund.digitalservice.ris.norms.utils.XmlMapper;
Expand Down Expand Up @@ -38,6 +40,21 @@ void getExpressionEli() {
assertThat(actualEli).isEqualTo(expectedEli);
}

@Test
void getNormExpressionEli() {
// given
Norm norm = Fixtures.loadNormFromDisk("SimpleNorm.xml");
NormExpressionEli expectedEli = NormExpressionEli.fromString(
"eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu"
);

// when
var actualEli = norm.getNormExpressionEli();

// then
assertThat(actualEli).isEqualTo(expectedEli);
}

@Test
void getWorkEli() {
// given
Expand All @@ -47,8 +64,22 @@ void getWorkEli() {
var actualEli = norm.getWorkEli();

// then
assertThat(actualEli)
.isEqualTo(DokumentWorkEli.fromString("eli/bund/bgbl-1/1964/s593/regelungstext-1"));
assertThat(actualEli).isEqualTo(NormWorkEli.fromString("eli/bund/bgbl-1/1964/s593"));
}

@Test
void getManifestationEli() {
// given
Norm norm = Fixtures.loadNormFromDisk("SimpleNorm.xml");
NormManifestationEli expectedEli = NormManifestationEli.fromString(
"eli/bund/bgbl-1/1964/s593/1964-08-05/1/deu/1964-08-05"
);

// when
var actualEli = norm.getNormManifestationEli();

// then
assertThat(actualEli).isEqualTo(expectedEli);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.bund.digitalservice.ris.norms.domain.entity;

import static org.assertj.core.api.Assertions.assertThat;

import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentWorkEli;
import org.junit.jupiter.api.Test;

class RegelungstextTest {

@Test
void getWorkEli() {
// given
Regelungstext regelungstext = Fixtures.loadRegelungstextFromDisk("SimpleNorm.xml");

// when
var actualEli = regelungstext.getWorkEli();

// then
assertThat(actualEli)
.isEqualTo(DokumentWorkEli.fromString("eli/bund/bgbl-1/1964/s593/regelungstext-1"));
}
}
Loading