use of com.helger.peppolid.IDocumentTypeIdentifier in project peppol-commons by phax.
the class PeppolDocumentTypeIdentifierTest method testURIStuff.
@Test
public void testURIStuff() {
final IIdentifierFactory aIF = PeppolIdentifierFactory.INSTANCE;
final IDocumentTypeIdentifier aID1 = new PeppolDocumentTypeIdentifier("scheme1", "value1");
assertEquals("scheme1::value1", aID1.getURIEncoded());
assertEquals("scheme1%3A%3Avalue1", aID1.getURIPercentEncoded());
final IDocumentTypeIdentifier aID2 = aIF.parseDocumentTypeIdentifier("scheme1::value1");
assertEquals(aID1, aID2);
assertNull(aIF.parseDocumentTypeIdentifier(null));
assertNull(aIF.parseDocumentTypeIdentifier(""));
assertNull(aIF.parseDocumentTypeIdentifier("scheme1"));
assertNotNull(aIF.parseDocumentTypeIdentifier("doctype::invoice"));
assertNotNull(aIF.parseDocumentTypeIdentifier("doctype::order "));
assertNull(aIF.parseDocumentTypeIdentifier("doctypethatiswaytoolongforwhatisexpected::order"));
assertNull(aIF.parseDocumentTypeIdentifier("doctype::" + StringHelper.getRepeated('a', PeppolIdentifierHelper.MAX_DOCUMENT_TYPE_VALUE_LENGTH + 1)));
assertNull(aIF.parseDocumentTypeIdentifier("doctype:order"));
assertNull(aIF.parseDocumentTypeIdentifier("doctypeorder"));
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project peppol-commons by phax.
the class BDXR1IdentifierFactoryTest method testDocTypeIDCaseSensitive.
@Test
public void testDocTypeIDCaseSensitive() {
final BDXR1IdentifierFactory aIF = BDXR1IdentifierFactory.INSTANCE;
// Different scheme - handle case sensitive
final String sScheme = "cs-doctype-scheme";
final IDocumentTypeIdentifier aID1 = aIF.createDocumentTypeIdentifier(sScheme, "abc");
assertEquals(sScheme, aID1.getScheme());
assertEquals("abc", aID1.getValue());
// Value is NOT lower cased internally
final IDocumentTypeIdentifier aID2 = aIF.createDocumentTypeIdentifier(sScheme, "ABC");
assertEquals(sScheme, aID2.getScheme());
assertEquals("ABC", aID2.getValue());
assertFalse(aID1.hasSameContent(aID2));
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project peppol-commons by phax.
the class BDXR1IdentifierFactoryTest method testDocTypeIDCaseInsensitive.
@Test
public void testDocTypeIDCaseInsensitive() {
final BDXR1IdentifierFactory aIF = BDXR1IdentifierFactory.INSTANCE;
final String sScheme = CBDXR1Identifier.DEFAULT_DOCUMENT_TYPE_IDENTIFIER_SCHEME;
final IDocumentTypeIdentifier aID1 = aIF.createDocumentTypeIdentifier(sScheme, "abc");
assertEquals(sScheme, aID1.getScheme());
assertEquals("abc", aID1.getValue());
// Value is lower cased internally
final IDocumentTypeIdentifier aID2 = aIF.createDocumentTypeIdentifier(sScheme, "ABC");
assertEquals(sScheme, aID2.getScheme());
assertEquals("abc", aID2.getValue());
assertTrue(aID1.hasSameContent(aID2));
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project peppol-commons by phax.
the class SMPJsonResponse method convert.
@Nonnull
public static IJsonObject convert(@Nonnull final ESMPAPIType eSMPAPIType, @Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final Map<String, String> aSGHrefs, @Nonnull final IIdentifierFactory aIF) {
ValueEnforcer.notNull(eSMPAPIType, "SMPAPIType");
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
ValueEnforcer.notNull(aSGHrefs, "SGHrefs");
ValueEnforcer.notNull(aIF, "IF");
final IJsonObject aJson = new JsonObject();
aJson.add(JSON_SMPTYPE, eSMPAPIType.getID());
aJson.add(JSON_PARTICIPANT_ID, aParticipantID.getURIEncoded());
final String sPathStart = "/" + aParticipantID.getURIEncoded() + '/' + BDXRClientReadOnly.URL_PART_SERVICES + '/';
final IJsonArray aURLsArray = new JsonArray();
// Show all ServiceGroup hrefs
for (final Map.Entry<String, String> aEntry : aSGHrefs.entrySet()) {
final String sHref = aEntry.getKey();
final String sOriginalHref = aEntry.getValue();
final IJsonObject aUrlEntry = new JsonObject().add(JSON_HREF, sOriginalHref);
// Should be case insensitive "indexOf" here
final int nPathStart = sHref.toLowerCase(Locale.US).indexOf(sPathStart.toLowerCase(Locale.US));
if (nPathStart >= 0) {
final String sDocType = sHref.substring(nPathStart + sPathStart.length());
aUrlEntry.add(JSON_DOCUMENT_TYPE_ID, sDocType);
final IDocumentTypeIdentifier aDocType = aIF.parseDocumentTypeIdentifier(sDocType);
if (aDocType == null) {
aUrlEntry.add(JSON_ERROR, "The document type ID could not be interpreted as a structured document type!");
}
} else {
aUrlEntry.add(JSON_ERROR, "Contained href does not match the rules. Expected path part: '" + sPathStart + "'");
}
aURLsArray.add(aUrlEntry);
}
aJson.addJson(JSON_URLS, aURLsArray);
return aJson;
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-smp by phax.
the class SMPServiceInformationManagerJDBC method deleteSMPProcess.
@Nonnull
public EChange deleteSMPProcess(@Nullable final ISMPServiceInformation aSMPServiceInformation, @Nullable final ISMPProcess aProcess) {
if (aSMPServiceInformation == null || aProcess == null)
return EChange.UNCHANGED;
final Wrapper<Long> ret = new Wrapper<>(Long.valueOf(0));
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
final IParticipantIdentifier aPID = aSMPServiceInformation.getServiceGroup().getParticipantIdentifier();
final IDocumentTypeIdentifier aDocTypeID = aSMPServiceInformation.getDocumentTypeIdentifier();
final IProcessIdentifier aProcessID = aProcess.getProcessIdentifier();
final long nCountEP = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_endpoint" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=? AND processIdentifierType=? AND processIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue(), aProcessID.getScheme(), aProcessID.getValue()));
final long nCountProc = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_process" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=? AND processIdentifierType=? AND processIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue(), aProcessID.getScheme(), aProcessID.getValue()));
ret.set(Long.valueOf(nCountEP + nCountProc));
});
if (eSuccess.isFailure())
return EChange.UNCHANGED;
return EChange.valueOf(ret.get().longValue() > 0);
}
Aggregations