Skip to content

Commit

Permalink
added more setter methods (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoika committed Dec 27, 2024
1 parent d02705e commit ed82e0d
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,13 @@ public EInvoiceModel(Document doc) {
// this();
tradeParties = new LinkedHashSet<>();
tradeLineItems = new LinkedHashSet<>();

if (doc != null) {
this.doc = doc;
root = doc.getDocumentElement();
if (getRoot() != null) {
setNameSpaces();
parseContent();
}

}
}

Expand All @@ -98,6 +96,8 @@ public String getId() {
return id;
}

public abstract void setId(String value);

public LocalDate getIssueDateTime() {
return issueDateTime;
}
Expand All @@ -114,10 +114,22 @@ public BigDecimal getGrandTotalAmount() {
return grandTotalAmount;
}

public abstract void setGrandTotalAmount(BigDecimal value);

public void setGrandTotalAmount(Double value) {
setGrandTotalAmount(BigDecimal.valueOf(value));
}

public BigDecimal getTaxTotalAmount() {
return taxTotalAmount;
}

public abstract void setTaxTotalAmount(BigDecimal value);

public void setTaxTotalAmount(Double value) {
setTaxTotalAmount(BigDecimal.valueOf(value));
}

public BigDecimal getNetTotalAmount() {
return netTotalAmount;
}
Expand All @@ -128,12 +140,6 @@ public void setNetTotalAmount(Double value) {
setNetTotalAmount(BigDecimal.valueOf(value));
}

public abstract void setGrandTotalAmount(BigDecimal value);

public void setGrandTotalAmount(Double value) {
setGrandTotalAmount(BigDecimal.valueOf(value));
}

/**
* Returns all trade parties
*
Expand Down Expand Up @@ -289,7 +295,7 @@ public Set<Element> findChildNodesByName(Element parent, EInvoiceNS ns, String n
* @return - Child Element matching the given node name. If no nodes were found,
* the method returns null
*/
public Element findChildNodeByName(Element parent, EInvoiceNS ns, String nodeName) {
public Element findChildNode(Element parent, EInvoiceNS ns, String nodeName) {
Set<Element> elementList = findChildNodesByName(parent, ns, nodeName);
if (elementList.iterator().hasNext()) {
// return first element
Expand All @@ -311,33 +317,45 @@ public Element findChildNodeByName(Element parent, EInvoiceNS ns, String nodeNam
* @return - Child Element matching the given node name. If no nodes were found,
* the method returns null
*/
public Element findOrCreateChildNodeByName(Element parent, EInvoiceNS ns, String nodeName) {
public Element findOrCreateChildNode(Element parent, EInvoiceNS ns, String nodeName) {
Set<Element> elementList = findChildNodesByName(parent, ns, nodeName);
if (elementList.iterator().hasNext()) {
// return first element
return elementList.iterator().next();
} else {
// no child elements with the given name found
// create one
Element element = getDoc().createElement(getPrefix(ns) + nodeName);
parent.appendChild(element);
return element;
return createChildNode(parent, ns, nodeName);
}
}

/**
* This helper method creates a new child node by name from a given parent
* node.
*
* @param parent
* @param nodeName
* @return - Child Element matching the given node name. If no nodes were found,
* the method returns null
*/
public Element createChildNode(Element parent, EInvoiceNS ns, String nodeName) {
Element element = getDoc().createElement(getPrefix(ns) + nodeName);
parent.appendChild(element);
return element;
}

/**
* Helper method to update or create an element with a given value
*
* @return - updated Element
*/
public void updateElementValue(Element parent, EInvoiceNS nameSpace, String elementName, String value) {
public Element updateElementValue(Element parent, EInvoiceNS nameSpace, String elementName, String value) {
if (value == null) {
return;
}
Element element = findChildNodeByName(parent, nameSpace, elementName);
if (element == null) {
element = getDoc().createElement(getPrefix(nameSpace) + elementName);
parent.appendChild(element);
return null;
}
Element element = findOrCreateChildNode(parent, nameSpace, elementName);
element.setTextContent(value);
return element;
}

/**
Expand Down
Loading

0 comments on commit ed82e0d

Please sign in to comment.