Search in sources :

Example 11 with IDocumentTypeIdentifier

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"));
}
Also used : IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) Test(org.junit.Test)

Example 12 with IDocumentTypeIdentifier

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));
}
Also used : IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) Test(org.junit.Test)

Example 13 with IDocumentTypeIdentifier

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));
}
Also used : IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) Test(org.junit.Test)

Example 14 with IDocumentTypeIdentifier

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;
}
Also used : JsonArray(com.helger.json.JsonArray) IJsonArray(com.helger.json.IJsonArray) IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IJsonArray(com.helger.json.IJsonArray) Map(java.util.Map) Nonnull(javax.annotation.Nonnull)

Example 15 with IDocumentTypeIdentifier

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);
}
Also used : ESuccess(com.helger.commons.state.ESuccess) Wrapper(com.helger.commons.wrapper.Wrapper) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull)

Aggregations

IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)89 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)62 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)36 Nonnull (javax.annotation.Nonnull)36 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)32 Test (org.junit.Test)30 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)27 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)20 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)19 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)18 IProcessIdentifier (com.helger.peppolid.IProcessIdentifier)18 ICommonsList (com.helger.commons.collection.impl.ICommonsList)16 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)16 Nullable (javax.annotation.Nullable)13 ESuccess (com.helger.commons.state.ESuccess)11 StringHelper (com.helger.commons.string.StringHelper)11 SimpleDocumentTypeIdentifier (com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier)11 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)11 ISMPProcess (com.helger.phoss.smp.domain.serviceinfo.ISMPProcess)11 ISMPRedirect (com.helger.phoss.smp.domain.redirect.ISMPRedirect)10