Skip to content

Commit

Permalink
Support for schemeID in SBDH. Minor fixes related to data model.
Browse files Browse the repository at this point in the history
  • Loading branch information
klakegg committed Dec 15, 2017
1 parent 866ff10 commit 3415329
Show file tree
Hide file tree
Showing 35 changed files with 285 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,4 @@ public interface SimpleIdentifier {

String getIdentifier();

@Deprecated
String getValue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class AbstractQualifiedIdentifier implements QualifiedIdentifier

public AbstractQualifiedIdentifier(String identifier, Scheme scheme) {
this.scheme = scheme;
this.identifier = identifier;
this.identifier = identifier == null ? null : identifier.trim();
}

@Override
Expand All @@ -48,7 +48,6 @@ public String getIdentifier() {

@Override
public String urlencoded() {
return ModelUtils.urlencode("%s::%s", scheme.getValue(), identifier);
return ModelUtils.urlencode("%s::%s", scheme.getIdentifier(), identifier);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,14 @@ public abstract class AbstractSimpleIdentifier implements SimpleIdentifier {
protected final String value;

protected AbstractSimpleIdentifier(String value) {
this.value = value;
this.value = value == null ? null : value.trim();
}

@Override
public String getIdentifier() {
return value;
}

@Override
public String getValue() {
return value;
}

@Override
public String toString() {
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class ProcessIdentifier extends AbstractQualifiedIdentifier implements Se

public static final Scheme DEFAULT_SCHEME = Scheme.of("cenbii-procid-ubl");

public static final ProcessIdentifier NO_PROCESS =
ProcessIdentifier.of("bdx:noprocess", Scheme.of("bdx-procid-transport"));

public static ProcessIdentifier of(String identifier) {
return new ProcessIdentifier(identifier, DEFAULT_SCHEME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void simpleParse() throws Exception {
.parse("qualifier::identifier");

Assert.assertEquals(documentTypeIdentifier.getIdentifier(), "identifier");
Assert.assertEquals(documentTypeIdentifier.getScheme().getValue(), "qualifier");
Assert.assertEquals(documentTypeIdentifier.getScheme().getIdentifier(), "qualifier");

try {
DocumentTypeIdentifier.parse("value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void simpleParse() throws Exception {
.parse("qualifier::identifier");

Assert.assertEquals(participantIdentifier.getIdentifier(), "identifier");
Assert.assertEquals(participantIdentifier.getScheme().getValue(), "qualifier");
Assert.assertEquals(participantIdentifier.getScheme().getIdentifier(), "qualifier");

try {
ParticipantIdentifier.parse("value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void simpleParse() throws Exception {
.parse("qualifier::identifier");

Assert.assertEquals(processIdentifier.getIdentifier(), "identifier");
Assert.assertEquals(processIdentifier.getScheme().getValue(), "qualifier");
Assert.assertEquals(processIdentifier.getScheme().getIdentifier(), "qualifier");

try {
ProcessIdentifier.parse("value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class SchemeTest {
@Test
public void simple() {
Scheme schema = Scheme.of("SCHEME");
Assert.assertEquals(schema.getValue(), "SCHEME");
Assert.assertEquals(schema.getIdentifier(), "SCHEME");
Assert.assertEquals(schema.toString(), "SCHEME");
Assert.assertNotNull(schema.hashCode());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class TransportProfileTest {
@Test
public void simple() {
Assert.assertTrue(TransportProfile.AS2_1_0.toString().contains("as2"));
Assert.assertTrue(TransportProfile.AS2_1_0.toString().contains(TransportProfile.AS2_1_0.getValue()));
Assert.assertTrue(TransportProfile.AS2_1_0.toString().contains(TransportProfile.AS2_1_0.getIdentifier()));

Assert.assertTrue(TransportProfile.AS2_1_0.equals(TransportProfile.AS2_1_0));
Assert.assertFalse(TransportProfile.AS2_1_0.equals(TransportProfile.AS4));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void action() throws Exception {
public static AttributedElectronicAddressType createElectronicAddressType(ParticipantIdentifier participant) {
AttributedElectronicAddressType o = new AttributedElectronicAddressType();
o.setValue(participant.getIdentifier());
o.setScheme(participant.getScheme().getValue());
o.setScheme(participant.getScheme().getIdentifier());

return o;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class TestResourcesTest {


public static Logger log = LoggerFactory.getLogger(TestResourcesTest.class);
public static final Logger LOGGER = LoggerFactory.getLogger(TestResourcesTest.class);

/** Attempts to retrieve the private key held in our test keystore */
@Test
Expand All @@ -59,15 +59,15 @@ public void loadMimeMessage() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mimeMessage.writeTo(baos);

log.debug("Size of baos: " + baos.size());
log.debug("Size of mime message:" + mimeMessage.getSize());
LOGGER.debug("Size of baos: " + baos.size());
LOGGER.debug("Size of mime message:" + mimeMessage.getSize());

InputStream rawInputStream = mimeMessage.getRawInputStream();
int counter = 0;
while (rawInputStream.read() >= 0) {
counter++;
}
log.debug("Size of raw input stream " + counter);
LOGGER.debug("Size of raw input stream " + counter);

// Headers are not part of the MIME message itself, the are however part of the MimeMessage object:
//
Expand All @@ -83,7 +83,7 @@ public void loadMimeMessage() throws Exception {
Enumeration allHeaderLines = mimeMessage.getAllHeaderLines();
while (allHeaderLines.hasMoreElements()) {
String s = (String) allHeaderLines.nextElement();
log.debug(s);
LOGGER.debug(s);
}
}
}
5 changes: 2 additions & 3 deletions peppol-icd/src/main/java/no/difi/vefa/peppol/icd/Icds.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ public IcdIdentifier parse(String icd, String identifier) throws PeppolParsingEx

public Icd findBySchemeAndCode(Scheme scheme, String code) {
for (Icd v : values)
if (v.getCode().equals(code))
if (v.getScheme().equals(scheme))
return v;
if (v.getCode().equals(code) && v.getScheme().equals(scheme))
return v;

throw new IllegalArgumentException(String.format("Value '%s::%s' is not valid ICD.", scheme, code));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,19 @@ public Scheme getScheme() {
return SCHEME;
}

public static Icd valueOfIcd(String icd) {
public static Icd findByCode(String icd) {
for (PeppolIcd v : values())
if (v.code.equals(icd))
return v;

throw new IllegalArgumentException(String.format("Value '%s' is not valid ICD.", icd));
}

public static Icd findByIdentifier(String icd) {
for (PeppolIcd v : values())
if (v.identifier.equals(icd))
return v;

throw new IllegalArgumentException(String.format("Identifier '%s' is not valid ICD.", icd));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public void simple() {
Assert.assertNotNull(PeppolIcd.valueOf("NO_ORGNR"));
Assert.assertNotNull(PeppolIcd.valueOf("NO_ORGNR").getScheme());

Assert.assertEquals(PeppolIcd.valueOfIcd("9908"), PeppolIcd.NO_ORGNR);
Assert.assertEquals(PeppolIcd.findByCode("9908"), PeppolIcd.NO_ORGNR);
}

@Test(expectedExceptions = IllegalArgumentException.class)
public void exceptionOnUnknownCode() {
PeppolIcd.valueOfIcd("invalid");
PeppolIcd.findByCode("invalid");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

public class Bdxr201407Reader implements MetadataReader {

private static Logger logger = LoggerFactory.getLogger(Bdxr201407Reader.class);
private static final Logger LOGGER = LoggerFactory.getLogger(Bdxr201407Reader.class);

public static final String NAMESPACE = "http://docs.oasis-open.org/bdxr/ns/SMP/2014/07";

Expand Down Expand Up @@ -96,7 +96,7 @@ public List<DocumentTypeIdentifier> parseDocumentIdentifiers(FetcherResponse fet
documentTypeIdentifiers.add(DocumentTypeIdentifierWithUri.of(
parts[1], Scheme.of(parts[0]), URI.create(reference.getHref())));
} catch (ArrayIndexOutOfBoundsException e) {
logger.warn("Unable to parse '{}'.", hrefDocumentTypeIdentifier);
LOGGER.warn("Unable to parse '{}'.", hrefDocumentTypeIdentifier);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

public class Bdxr201605Reader implements MetadataReader {

private static Logger logger = LoggerFactory.getLogger(Bdxr201605Reader.class);
private static final Logger LOGGER = LoggerFactory.getLogger(Bdxr201605Reader.class);

public static final String NAMESPACE = "http://docs.oasis-open.org/bdxr/ns/SMP/2016/05";

Expand Down Expand Up @@ -96,7 +96,7 @@ public List<DocumentTypeIdentifier> parseDocumentIdentifiers(FetcherResponse fet
documentTypeIdentifiers.add(DocumentTypeIdentifierWithUri.of(
parts[1], Scheme.of(parts[0]), URI.create(reference.getHref())));
} catch (ArrayIndexOutOfBoundsException e) {
logger.warn("Unable to parse '{}'.", hrefDocumentTypeIdentifier);
LOGGER.warn("Unable to parse '{}'.", hrefDocumentTypeIdentifier);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

public class BusdoxReader implements MetadataReader {

private static Logger logger = LoggerFactory.getLogger(BusdoxReader.class);
private static final Logger LOGGER = LoggerFactory.getLogger(BusdoxReader.class);

public static final String NAMESPACE = "http://busdox.org/serviceMetadata/publishing/1.0/";

Expand Down Expand Up @@ -98,7 +98,7 @@ public List<DocumentTypeIdentifier> parseDocumentIdentifiers(FetcherResponse fet
documentTypeIdentifiers.add(DocumentTypeIdentifierWithUri.of(
parts[1], Scheme.of(parts[0]), URI.create(reference.getHref())));
} catch (ArrayIndexOutOfBoundsException e) {
logger.warn("Unable to parse '{}'.", hrefDocumentTypeIdentifier);
LOGGER.warn("Unable to parse '{}'.", hrefDocumentTypeIdentifier);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ public String generate(ParticipantIdentifier participantIdentifier) throws Looku
}

return String.format("%s%s.%s.%s",
prefix, receiverHash, participantIdentifier.getScheme().getValue(), hostname);
prefix, receiverHash, participantIdentifier.getScheme().getIdentifier(), hostname);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@

public class XmlUtils {

private static Logger logger = LoggerFactory.getLogger(XmlUtils.class);
private static final Logger LOGGER = LoggerFactory.getLogger(XmlUtils.class);

private static final Pattern rootTagPattern =
private static final Pattern ROOT_TAG_PATTERN =
Pattern.compile("<(\\w*:{0,1}[^<?|^<!]*)>", Pattern.MULTILINE);

private static final Pattern namespacePattern =
private static final Pattern NAMESPACE_PATTERN =
Pattern.compile("xmlns:{0,1}([A-Za-z0-9]*)\\w*=\\w*\"(.+?)\"", Pattern.MULTILINE);

public static String extractRootNamespace(String xmlContent) {
Matcher matcher = rootTagPattern.matcher(xmlContent);
Matcher matcher = ROOT_TAG_PATTERN.matcher(xmlContent);
if (matcher.find()) {
String rootElement = matcher.group(1).trim();
logger.debug("Root element: {}", rootElement);
LOGGER.debug("Root element: {}", rootElement);
String rootNs = rootElement.split(" ", 2)[0].contains(":") ?
rootElement.substring(0, rootElement.indexOf(":")) : "";
logger.debug("Namespace: {}", rootNs);
LOGGER.debug("Namespace: {}", rootNs);

Matcher nsMatcher = namespacePattern.matcher(rootElement);
Matcher nsMatcher = NAMESPACE_PATTERN.matcher(rootElement);
while (nsMatcher.find()) {
logger.debug(nsMatcher.group(0));
LOGGER.debug(nsMatcher.group(0));

if (nsMatcher.group(1).equals(rootNs)) {
return nsMatcher.group(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

public class Bdxr201407ReaderTest {

private static Logger logger = LoggerFactory.getLogger(Bdxr201407ReaderTest.class);
private static final Logger LOGGER = LoggerFactory.getLogger(Bdxr201407ReaderTest.class);

private MetadataReader reader = new Bdxr201407Reader();

Expand All @@ -48,7 +48,7 @@ public void documentIdentifers() throws Exception {
assertEquals(result.size(), 7);

for (DocumentTypeIdentifier documentTypeIdentifier : result)
logger.debug("{}", documentTypeIdentifier);
LOGGER.debug("{}", documentTypeIdentifier);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

public class Bdxr201605ReaderTest {

private static Logger logger = LoggerFactory.getLogger(Bdxr201605ReaderTest.class);
private static final Logger LOGGER = LoggerFactory.getLogger(Bdxr201605ReaderTest.class);

private MetadataReader reader = new Bdxr201605Reader();

Expand All @@ -48,7 +48,7 @@ public void documentIdentifers() throws Exception {
assertEquals(result.size(), 7);

for (DocumentTypeIdentifier documentTypeIdentifier : result)
logger.debug("{}", documentTypeIdentifier);
LOGGER.debug("{}", documentTypeIdentifier);
}

@Test(enabled = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

public class BusdoxReaderTest {

private static Logger logger = LoggerFactory.getLogger(BusdoxReaderTest.class);
private static final Logger LOGGER = LoggerFactory.getLogger(BusdoxReaderTest.class);

private MetadataReader reader = new BusdoxReader();

Expand All @@ -48,7 +48,7 @@ public void documentIdentifers() throws Exception {
assertEquals(result.size(), 7);

for (DocumentTypeIdentifier documentTypeIdentifier : result)
logger.debug("{}", documentTypeIdentifier);
LOGGER.debug("{}", documentTypeIdentifier);
}

@Test
Expand Down Expand Up @@ -82,7 +82,7 @@ public void documentIdentifersDocsLogistics() throws Exception {
assertEquals(result.size(), 25);

for (DocumentTypeIdentifier documentTypeIdentifier : result)
logger.debug("{}", documentTypeIdentifier);
LOGGER.debug("{}", documentTypeIdentifier);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public class MultiReaderTest {

private static Logger logger = LoggerFactory.getLogger(MultiReaderTest.class);
private static final Logger LOGGER = LoggerFactory.getLogger(MultiReaderTest.class);

private MetadataReader reader = new MultiReader();

Expand All @@ -49,7 +49,7 @@ public void busdoxDocumentIdentifers() throws Exception {
assertEquals(result.size(), 7);

for (DocumentTypeIdentifier documentTypeIdentifier : result)
logger.debug("{}", documentTypeIdentifier);
LOGGER.debug("{}", documentTypeIdentifier);
}

@Test
Expand All @@ -60,7 +60,7 @@ public void bdxr201407DocumentIdentifers() throws Exception {
assertEquals(result.size(), 7);

for (DocumentTypeIdentifier documentTypeIdentifier : result)
logger.debug("{}", documentTypeIdentifier);
LOGGER.debug("{}", documentTypeIdentifier);
}

@Test
Expand All @@ -71,7 +71,7 @@ public void bdxr201605DocumentIdentifers() throws Exception {
assertEquals(result.size(), 7);

for (DocumentTypeIdentifier documentTypeIdentifier : result)
logger.debug("{}", documentTypeIdentifier);
LOGGER.debug("{}", documentTypeIdentifier);
}

@Test
Expand Down
Loading

0 comments on commit 3415329

Please sign in to comment.