Skip to content

Commit

Permalink
Merge pull request #861 from digitalservicebund/simplify-bill-to-act
Browse files Browse the repository at this point in the history
Simplify bill to act
  • Loading branch information
malte-laukoetter authored Jan 7, 2025
2 parents 61cde71 + 7325607 commit 2a947e3
Show file tree
Hide file tree
Showing 18 changed files with 767 additions and 477 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package de.bund.digitalservice.ris.norms.domain.entity;

import de.bund.digitalservice.ris.norms.utils.NodeCreator;
import de.bund.digitalservice.ris.norms.utils.NodeParser;
import java.time.LocalDate;
import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/** Class representing a akn:eventRef. */
Expand All @@ -16,6 +18,45 @@ public class EventRef {

private final Node node;

/**
* Creates a new akn:eventRef element and appends it to the given node.
* @param parentNode the node under which a new {@link EventRef} should be created.
* @return the newly created {@link EventRef}
*/
public static EventRef createAndAppend(Node parentNode) {
final var element = NodeCreator.createElementWithEidAndGuid("akn:eventRef", parentNode);
element.setAttribute("source", "attributsemantik-noch-undefiniert");
return new EventRef(element);
}

/**
* Set the date of the akn:eventRef
* @param date the date of the event
*/
public void setDate(String date) {
((Element) node).setAttribute("date", date);
}

/**
* Set the refersTo attribute of the akn:eventRef
* @param refersTo the value for the attribute
*/
public void setRefersTo(String refersTo) {
((Element) node).setAttribute("refersTo", refersTo);
}

/**
* Set the type attribute of the akn:eventRef
* @param type the value for the attribute
*/
public void setType(String type) {
((Element) node).setAttribute("type", type);
}

/**
* Get the eId of the element.
* @return the eId
*/
public EId getEid() {
return EId.fromMandatoryNode(node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ public void setFRBRaliasPreviousVersionId(final UUID uuid) {

// FRBR metadata needs to be in the correct order, so we're inserting it before the author, which is the
// element that has to follow the aliases in a valid document.
final var author = NodeParser.getMandatoryNodeFromExpression("./FRBRauthor", getNode());
getNode().insertBefore(newElement, author);
getNode().insertBefore(newElement, getFRBRAuthorNode());

return newElement;
})
Expand Down Expand Up @@ -164,8 +163,7 @@ public void setFRBRaliasNextVersionId(final UUID uuid) {

// FRBR metadata needs to be in the correct order, so we're inserting it before the author, which is the
// element that has to follow the aliases in a valid document.
final var author = NodeParser.getMandatoryNodeFromExpression("./FRBRauthor", getNode());
getNode().insertBefore(nextVersionAlias, author);
getNode().insertBefore(nextVersionAlias, getFRBRAuthorNode());

return nextVersionAlias;
})
Expand All @@ -183,4 +181,25 @@ public void deleteAliasNextVersionId() {
.getNodeFromExpression("./FRBRalias[@name='nachfolgende-version-id']", getNode())
.ifPresent(node -> node.getParentNode().removeChild(node));
}

/**
* Returns a FRBRlanguage as {@link String}.
*
* @return The FRBRlanguage
*/
public Optional<String> getFRBRlanguage() {
return NodeParser.getValueFromExpression("./FRBRlanguage/@language", getNode());
}

private Element getFRBRAuthorNode() {
return (Element) NodeParser.getMandatoryNodeFromExpression("./FRBRauthor", getNode());
}

/**
* Set the value of the FRBRauthor element (this contains the URI of the author of the document)
* @param author the uri identifying the author of the document
*/
public void setFRBRAuthor(final String author) {
getFRBRAuthorNode().setAttribute("href", author);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Optional;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/** Class representing the akn:FRBRWork */
Expand Down Expand Up @@ -53,6 +54,30 @@ public Optional<String> getFRBRname() {
);
}

/**
* Set the value of the FRBRname element (this contains the agent publishing the norm)
* @param name the name of the agent
*/
public void setFRBRName(final String name) {
final Element fRBRName = (Element) NodeParser.getMandatoryNodeFromExpression(
"./FRBRname",
getNode()
);
fRBRName.setAttribute("value", name);
}

/**
* Set the value of the FRBRauthor element (this contains the URI of the author of the document)
* @param author the uri identifying the author of the document
*/
public void setFRBRAuthor(final String author) {
final Element fRBRAuthor = (Element) NodeParser.getMandatoryNodeFromExpression(
"./FRBRauthor",
getNode()
);
fRBRAuthor.setAttribute("href", author);
}

/**
* Returns a FRBRnumber as {@link String} from the FRBRWork in a {@link Norm}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ public List<EventRef> getEventRefs() {
.map(EventRef::new)
.toList();
}

/**
* Add a new akn:eventRef element to this element.
* @return the newly created {@link EventRef}
*/
public EventRef addEventRef() {
return EventRef.createAndAppend(getNode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public TemporalData getOrCreateTemporalData() {
} catch (final MandatoryNodeNotFoundException e) {
final var newElement = NodeCreator.createElementWithEidAndGuid("akn:temporalData", node);
newElement.setAttribute(SOURCE_ATTIBUTE, ATTRIBUTSEMANTIK_NOCH_UNDEFINIERT);
node.insertBefore(newElement, getOrCreateProprietary().getNode());
return new TemporalData(newElement);
}
}
Expand All @@ -88,6 +89,22 @@ public Lifecycle getLifecycle() {
return new Lifecycle(NodeParser.getMandatoryNodeFromExpression("./lifecycle", node));
}

/**
* Gets the akn:lifecycle element of the norm, or creates it if it does not yet exist.
*
* @return the akn:lifecycle element of the norm
*/
public Lifecycle getOrCreateLifecycle() {
try {
return getLifecycle();
} catch (final MandatoryNodeNotFoundException e) {
final var newElement = NodeCreator.createElementWithEidAndGuid("akn:lifecycle", node);
newElement.setAttribute(SOURCE_ATTIBUTE, ATTRIBUTSEMANTIK_NOCH_UNDEFINIERT);
node.insertBefore(newElement, getOrCreateProprietary().getNode());
return new Lifecycle(newElement);
}
}

/**
* Returns a {@link Analysis} instance from the {@link Meta}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.bund.digitalservice.ris.norms.domain.entity;

import de.bund.digitalservice.ris.norms.utils.NodeCreator;
import de.bund.digitalservice.ris.norms.utils.NodeParser;
import java.util.Optional;
import lombok.Builder;
Expand All @@ -22,7 +23,9 @@ public MetadatenDe(final Node node) {
public enum Metadata implements MetadataInterface {
FNA("./fna"),
ART("./art"),
TYP("./typ");
TYP("./typ"),
GESTA("./gesta"),
FASSUNG("./fassung");

private final String xpath;

Expand All @@ -45,6 +48,19 @@ public Optional<String> getFna() {
return NodeParser.getValueFromExpression(Metadata.FNA.xpath, getNode());
}

/**
* Sets the FNA ("Fundstellennachweis A") of the norm.
*
* @param fna the new FNA
*/
public void setFna(final String fna) {
var fnaNode = NodeParser
.getNodeFromExpression(Metadata.FNA.xpath, getNode())
.orElseGet(() -> NodeCreator.createElement(getNamespace(), "fna", getNode()));

fnaNode.setTextContent(fna);
}

/**
* Returns the Art ("Art der Norm") of the norm.
*
Expand All @@ -62,4 +78,48 @@ public Optional<String> getArt() {
public Optional<String> getTyp() {
return NodeParser.getValueFromExpression(Metadata.TYP.xpath, getNode());
}

/**
* Returns the type GESTA of the document.
*
* @return Gesta or empty if it doesn't exist.
*/
public Optional<String> getGesta() {
return NodeParser.getValueFromExpression(Metadata.GESTA.xpath, getNode());
}

/**
* Sets the GESTA of the norm.
*
* @param gesta the new gesta value
*/
public void setGesta(final String gesta) {
var node = NodeParser
.getNodeFromExpression(Metadata.GESTA.xpath, getNode())
.orElseGet(() -> NodeCreator.createElement(getNamespace(), "gesta", getNode()));

node.setTextContent(gesta);
}

/**
* Returns the fassung of the document.
*
* @return Fassung or empty if it doesn't exist.
*/
public Optional<String> getFassung() {
return NodeParser.getValueFromExpression(Metadata.FASSUNG.xpath, getNode());
}

/**
* Sets the fassung of the norm.
*
* @param fassung the new fassung value
*/
public void setFassung(final String fassung) {
var node = NodeParser
.getNodeFromExpression(Metadata.FASSUNG.xpath, getNode())
.orElseGet(() -> NodeCreator.createElement(getNamespace(), "fassung", getNode()));

node.setTextContent(fassung);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import de.bund.digitalservice.ris.norms.domain.entity.eli.ExpressionEli;
import de.bund.digitalservice.ris.norms.domain.entity.eli.ManifestationEli;
import de.bund.digitalservice.ris.norms.domain.entity.eli.WorkEli;
import de.bund.digitalservice.ris.norms.utils.NodeCreator;
import de.bund.digitalservice.ris.norms.utils.NodeParser;
import de.bund.digitalservice.ris.norms.utils.XmlMapper;
import java.time.LocalDate;
Expand All @@ -16,7 +15,6 @@
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
Expand Down Expand Up @@ -235,33 +233,19 @@ public Optional<String> getStartDateForEventRef(String eId) {
*/
public TemporalGroup addTimeBoundary(LocalDate date, EventRefType eventRefType) {
// Create new eventRef node
final Node livecycle = getTimeBoundaries().getLast().getEventRef().getNode().getParentNode();
final Element eventRef = NodeCreator.createElementWithEidAndGuid("akn:eventRef", livecycle);
eventRef.setAttribute("date", date.toString());
eventRef.setAttribute("source", "attributsemantik-noch-undefiniert");
eventRef.setAttribute("type", eventRefType.getValue());
eventRef.setAttribute("refersTo", "inkrafttreten");

// Create new temporalGroup node
final TemporalData temporalData = getMeta().getTemporalData();
final Element temporalGroup = NodeCreator.createElementWithEidAndGuid(
"akn:temporalGroup",
temporalData.getNode()
final EventRef eventRef = getMeta().getLifecycle().addEventRef();
eventRef.setDate(date.toString());
eventRef.setRefersTo("inkrafttreten");
eventRef.setType(eventRefType.getValue());

final TemporalGroup temporalGroup = getMeta().getTemporalData().addTemporalGroup();
final TimeInterval timeInterval = temporalGroup.getOrCreateTimeInterval();
timeInterval.setStart(
new Href.Builder().setEId(eventRef.getEid().value()).buildInternalReference()
);
timeInterval.setRefersTo("geltungszeit");

// Create new timeInterval node
final Element timeInterval = NodeCreator.createElementWithEidAndGuid(
"akn:timeInterval",
temporalGroup
);
timeInterval.setAttribute("refersTo", "geltungszeit");
final var eventRefEId = eventRef.getAttribute("eId");
timeInterval.setAttribute(
"start",
new Href.Builder().setEId(eventRefEId).buildInternalReference().value()
);

return new TemporalGroup(temporalGroup);
return temporalGroup;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ public List<TemporalGroup> getTemporalGroups() {
.map(TemporalGroup::new)
.toList();
}

/**
* Add a new akn:temporalGroup element to this element.
* @return the newly created {@link TemporalGroup}
*/
public TemporalGroup addTemporalGroup() {
return TemporalGroup.createAndAppend(getNode());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.bund.digitalservice.ris.norms.domain.entity;

import de.bund.digitalservice.ris.norms.utils.NodeCreator;
import de.bund.digitalservice.ris.norms.utils.NodeParser;
import java.util.NoSuchElementException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
Expand All @@ -14,6 +16,17 @@ public class TemporalGroup {

private final Node node;

/**
* Creates a new akn:temporalGroup element and appends it to the given node.
* @param parentNode the node under which a new {@link TemporalGroup} should be created.
* @return the newly created {@link TemporalGroup}
*/
public static TemporalGroup createAndAppend(Node parentNode) {
return new TemporalGroup(
NodeCreator.createElementWithEidAndGuid("akn:temporalGroup", parentNode)
);
}

/**
* Returns the eId of the TemporalGroup as {@link String}.
*
Expand All @@ -34,4 +47,17 @@ public TimeInterval getTimeInterval() {
.map(TimeInterval::new)
.orElseThrow();
}

/**
* Returns the {@link TimeInterval} instance for this akn:temporalGroup. If no time interval exists a new one is created.
*
* @return the TimeInterval
*/
public TimeInterval getOrCreateTimeInterval() {
try {
return getTimeInterval();
} catch (NoSuchElementException e) {
return TimeInterval.createAndAppend(getNode());
}
}
}
Loading

0 comments on commit 2a947e3

Please sign in to comment.