Skip to content

Commit

Permalink
Extend manifestation eli to support different formats
Browse files Browse the repository at this point in the history
RISDEV-0000
  • Loading branch information
malte-laukoetter committed Dec 18, 2024
1 parent 9b3b033 commit f389edf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ private void rewriteFbrManifestation(Document document) {
expressionEli.getVersion(),
expressionEli.getLanguage(),
verkuendungsDate,
expressionEli.getSubtype()
expressionEli.getSubtype(),
"xml"
);
fRBRManifestationThis.setAttribute(VALUE, manifestationEli.toString());
fRBRManifestationUri.setAttribute(VALUE, manifestationEli.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public CreateNewExpressionResult createNewExpression(Norm norm, LocalDate date)
date,
newExpression.getExpressionEli().getLanguage()
);
var newManifestationEli = ManifestationEli.fromExpressionEli(newExpressionEli, LocalDate.now());
var newManifestationEli = ManifestationEli.fromExpressionEli(
newExpressionEli,
LocalDate.now(),
"xml"
);
setNewExpressionMetadata(newExpression, newExpressionEli);
setNewManifestationMetadata(newExpression, newManifestationEli);

Expand Down Expand Up @@ -85,7 +89,8 @@ public Norm createNewManifestation(Norm norm, LocalDate pointInTimeManifestation
var newManifestation = new Norm(norm);
var newManifestationEli = ManifestationEli.fromExpressionEli(
newManifestation.getExpressionEli(),
pointInTimeManifestation
pointInTimeManifestation,
"xml"
);
setNewManifestationMetadata(newManifestation, newManifestationEli);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* European legislation identifier on manifestation level
*
* <p>This class can be used to extract the eli from a path that includes a section like
* "/eli/bund/{agent}/{year}/{naturalIdentifier}/{pointInTime}/{version}/{language}/{pointInTimeManifestation}/{subtype}.xml".
* "/eli/bund/{agent}/{year}/{naturalIdentifier}/{pointInTime}/{version}/{language}/{pointInTimeManifestation}/{subtype}.{fileExtension}".
*/
@Getter
@Setter
Expand All @@ -31,6 +31,7 @@ public final class ManifestationEli implements Eli {
private String language;
private LocalDate pointInTimeManifestation;
private String subtype;
private String format = "xml";

public ManifestationEli(
String agent,
Expand All @@ -39,9 +40,10 @@ public ManifestationEli(
LocalDate pointInTime,
Integer version,
String language,
String subtype
String subtype,
String format
) {
this(agent, year, naturalIdentifier, pointInTime, version, language, null, subtype);
this(agent, year, naturalIdentifier, pointInTime, version, language, null, subtype, format);
}

/**
Expand All @@ -56,26 +58,28 @@ public boolean hasPointInTimeManifestation() {
@Override
public String toString() {
if (!hasPointInTimeManifestation()) {
return "eli/bund/%s/%s/%s/%s/%d/%s/%s.xml".formatted(
return "eli/bund/%s/%s/%s/%s/%d/%s/%s.%s".formatted(
getAgent(),
getYear(),
getNaturalIdentifier(),
getPointInTime().format(DateTimeFormatter.ISO_LOCAL_DATE),
getVersion(),
getLanguage(),
getSubtype()
getSubtype(),
getFormat()
);
}

return "eli/bund/%s/%s/%s/%s/%d/%s/%s/%s.xml".formatted(
return "eli/bund/%s/%s/%s/%s/%d/%s/%s/%s.%s".formatted(
getAgent(),
getYear(),
getNaturalIdentifier(),
getPointInTime().format(DateTimeFormatter.ISO_LOCAL_DATE),
getVersion(),
getLanguage(),
getPointInTimeManifestation().format(DateTimeFormatter.ISO_LOCAL_DATE),
getSubtype()
getSubtype(),
getFormat()
);
}

Expand Down Expand Up @@ -106,7 +110,8 @@ public ManifestationEli withoutPointInTimeManifestation() {
getPointInTime(),
getVersion(),
getLanguage(),
getSubtype()
getSubtype(),
getFormat()
);
}

Expand Down Expand Up @@ -145,7 +150,7 @@ public WorkEli asWorkEli() {
public static ManifestationEli fromString(String manifestationEli) {
Matcher matcher = Pattern
.compile(
"eli/bund/(?<agent>[^/]+)/(?<year>[^/]+)/(?<naturalIdentifier>[^/]+)/(?<pointInTime>[^/]+)/(?<version>[^/]+)/(?<language>[^/]+)(/(?<pointInTimeManifestation>[^/.]+))?/(?<subtype>[^/.]+)\\.xml"
"eli/bund/(?<agent>[^/]+)/(?<year>[^/]+)/(?<naturalIdentifier>[^/]+)/(?<pointInTime>[^/]+)/(?<version>[^/]+)/(?<language>[^/]+)(/(?<pointInTimeManifestation>[^/.]+))?/(?<subtype>[^/.]+)\\.(?<format>[^/.]+)"
)
.matcher(manifestationEli);

Expand All @@ -166,7 +171,8 @@ public static ManifestationEli fromString(String manifestationEli) {
matcher.group("pointInTimeManifestation"),
DateTimeFormatter.ISO_LOCAL_DATE
),
matcher.group("subtype")
matcher.group("subtype"),
matcher.group("format")
);
}

Expand All @@ -175,11 +181,13 @@ public static ManifestationEli fromString(String manifestationEli) {
*
* @param expressionEli the expression eli to use as a base
* @param pointInTimeManifestation the date the manifestation was created
* @param format the file extension used by this manifestation
* @return the eli
*/
public static ManifestationEli fromExpressionEli(
ExpressionEli expressionEli,
LocalDate pointInTimeManifestation
LocalDate pointInTimeManifestation,
String format
) {
return new ManifestationEli(
expressionEli.getAgent(),
Expand All @@ -189,7 +197,8 @@ public static ManifestationEli fromExpressionEli(
expressionEli.getVersion(),
expressionEli.getLanguage(),
pointInTimeManifestation,
expressionEli.getSubtype()
expressionEli.getSubtype(),
format
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void itShouldBeCorrectWithPointInTimeManifestation() {
assertThat(eli.getLanguage()).isEqualTo("deu");
assertThat(eli.getPointInTimeManifestation()).isEqualTo("2021-03-03");
assertThat(eli.getSubtype()).isEqualTo("regelungstext-1");
assertThat(eli.getFormat()).isEqualTo("xml");
}

@Test
Expand All @@ -102,6 +103,7 @@ void itShouldBeCorrectWithoutPointInTimeManifestation() {
assertThat(eli.getLanguage()).isEqualTo("deu");
assertThat(eli.getPointInTimeManifestation()).isNull();
assertThat(eli.getSubtype()).isEqualTo("regelungstext-1");
assertThat(eli.getFormat()).isEqualTo("xml");
}
}

Expand Down Expand Up @@ -150,7 +152,8 @@ class fromExpressionEli {
void itShouldCreateFromExpressionEliAndPointInTimeManifestation() {
var eli = ManifestationEli.fromExpressionEli(
ExpressionEli.fromString("eli/bund/bgbl-1/2021/s4/2021-03-01/1/deu/regelungstext-1"),
LocalDate.parse("2022-01-01")
LocalDate.parse("2022-01-01"),
"xml"
);
assertThat(eli)
.hasToString("eli/bund/bgbl-1/2021/s4/2021-03-01/1/deu/2022-01-01/regelungstext-1.xml");
Expand Down

0 comments on commit f389edf

Please sign in to comment.