Enhance code quality

This commit is contained in:
Daniel Luckas
2025-07-17 15:51:20 +02:00
parent 7ebaf3af8a
commit 2243f8ce6f
9 changed files with 135 additions and 98 deletions

View File

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableContact;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.Set;
/***
* a named contact person in an organisation
@@ -111,50 +112,52 @@ public class Contact implements IZUGFeRDExportableContact {
for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
//nodes.item(i).getTextContent())) {
Node currentItemNode = nodes.item(nodeIndex);
if (currentItemNode.getLocalName() != null) {
String localName = currentItemNode.getLocalName();
if (localName != null) {
if (currentItemNode.getLocalName().equals("PersonName")/*CII*/||currentItemNode.getLocalName().equals("Name")/*UBL*/) {
if (currentItemNode.getFirstChild()!=null) {
Set<String> nameElements = Set.of("PersonName"/*CII*/, "Name"/*UBL*/);
if (localName != null && nameElements.contains(localName)
&& currentItemNode.getFirstChild()!=null) {
setName(currentItemNode.getFirstChild().getNodeValue());
}
}
if (currentItemNode.getLocalName().equals("TelephoneUniversalCommunication")) { /*CII*/
if (localName.equals("TelephoneUniversalCommunication")) { /*CII*/
NodeList tel = currentItemNode.getChildNodes();
for (int telChildIndex = 0; telChildIndex < tel.getLength(); telChildIndex++) {
if (tel.item(telChildIndex).getLocalName() != null) {
if (tel.item(telChildIndex).getLocalName().equals("CompleteNumber")) {
String telLocalName = tel.item(telChildIndex).getLocalName();
if (telLocalName != null && telLocalName.equals("CompleteNumber")) {
setPhone(tel.item(telChildIndex).getTextContent());
}
}
}
} else if (currentItemNode.getLocalName().equals("Telephone")) { /* UBL */
} else if (localName.equals("Telephone")) { /* UBL */
setPhone(currentItemNode.getTextContent());
}
// CII: only for Extended profile
if (currentItemNode.getLocalName().equals("FaxUniversalCommunication")) { /* CII */
if (localName.equals("FaxUniversalCommunication")) { /* CII */
NodeList fax = currentItemNode.getChildNodes();
for (int faxChildIndex = 0; faxChildIndex < fax.getLength(); faxChildIndex++) {
if (fax.item(faxChildIndex).getLocalName() != null) {
if (fax.item(faxChildIndex).getLocalName().equals("CompleteNumber")) {
String faxLocalName = fax.item(faxChildIndex).getLocalName();
if (faxLocalName != null && faxLocalName.equals("CompleteNumber")) {
setFax(fax.item(faxChildIndex).getTextContent());
}
}
}
} else if (currentItemNode.getLocalName().equals("Telefax")) { /* UBL */
} else if (localName.equals("Telefax")) { /* UBL */
setFax(currentItemNode.getTextContent());
}
if (currentItemNode.getLocalName().equals("EmailURIUniversalCommunication")) { /* CII */
if (localName.equals("EmailURIUniversalCommunication")) { /* CII */
NodeList email = currentItemNode.getChildNodes();
for (int emailChildIndex = 0; emailChildIndex < email.getLength(); emailChildIndex++) {
if (email.item(emailChildIndex).getLocalName() != null) {
if (email.item(emailChildIndex).getLocalName().equals("URIID")) {
String emailLocalName = email.item(emailChildIndex).getLocalName();
if (emailLocalName != null && emailLocalName.equals("URIID")) {
setEMail(email.item(emailChildIndex).getTextContent());
}
}
}
} else if (currentItemNode.getLocalName().equals("ElectronicMail")) { /* UBL */
} else if (localName.equals("ElectronicMail")) { /* UBL */
setEMail(currentItemNode.getTextContent());
}
}

View File

@@ -2,7 +2,7 @@ package org.mustangproject;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -163,7 +163,9 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
NodeList taxSchemechilds = partyTaxScheme.item(partyTaxSchemeIndex).getChildNodes();
for (int taxSchemechildsIndex = 0; taxSchemechildsIndex < taxSchemechilds.getLength(); taxSchemechildsIndex++) {
if (taxSchemechilds.item(taxSchemechildsIndex).getLocalName() != null) {
if (taxSchemechilds.item(taxSchemechildsIndex).getTextContent().equals("FC") || (taxSchemechilds.item(taxSchemechildsIndex).getTextContent().equals("NOVAT"))) {
Set<String> taxSchemeTypes = Set.of("FC", "NOVAT");
String textContent = taxSchemechilds.item(taxSchemechildsIndex).getTextContent();
if (textContent != null && taxSchemeTypes.contains(textContent)) {
setTaxID(CompanyId);
} else {
setVATID(CompanyId);

View File

@@ -41,9 +41,9 @@ public class Profile {
* @return the XMP name string of the profile
*/
public String getXMPName() {
if (name.equals("BASICWL")) {
if ("BASICWL".equals(name)) {
return "BASIC WL";
} else if (name.equals("EN16931")) {
} else if ("EN16931".equals(name)) {
return "EN 16931";
} else {
return name;

View File

@@ -33,9 +33,9 @@ import java.util.Arrays;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.dom4j.Document;
@@ -721,9 +721,8 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
}
}
}
if (DocumentCodeTypeConstants.CORRECTEDINVOICE.equals(trans.getDocumentCode())
|| DocumentCodeTypeConstants.CREDITNOTE.equals(trans.getDocumentCode())
) {
if (trans.getDocumentCode() != null
&& Set.of(DocumentCodeTypeConstants.CORRECTEDINVOICE, DocumentCodeTypeConstants.CREDITNOTE).contains(trans.getDocumentCode())) {
hasDueDate = false;
}

View File

@@ -225,7 +225,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
* @return the filename of the file to be embedded
*/
public String getFilenameForVersion(int ver, Profile profile) {
if (profile.getName().equals("XRECHNUNG")) {
if ("XRECHNUNG".equals(profile.getName())) {
return "xrechnung.xml";
}
if (isFacturX) {

View File

@@ -560,7 +560,7 @@ public class ZUGFeRDInvoiceImporter {
}
zpp.addNotes(includedNotes);
String rootNode = extractString("local-name(/*)");
if (rootNode.equals("Invoice") || rootNode.equals("CreditNote")) {
if (rootNode != null && Set.of("Invoice", "CreditNote").contains(rootNode)) {
// UBL...
// //*[local-name()="Invoice" or local-name()="CreditNote"]
number = extractString("/*[local-name()=\"Invoice\" or local-name()=\"CreditNote\"]/*[local-name()=\"ID\"]").trim();