Search in sources :

Example 46 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-directory by phax.

the class SMPBusinessCardProvider method getBusinessCardBDXR1.

@Nullable
@VisibleForTesting
PDExtendedBusinessCard getBusinessCardBDXR1(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final BDXRClientReadOnly aSMPClient, @Nonnull final HttpClientSettings aHCS) {
    LOGGER.info("Querying BusinessCard for '" + aParticipantID.getURIEncoded() + "' from OASIS BDXR SMP v1 '" + aSMPClient.getSMPHostURI() + "'");
    // First query the service group
    com.helger.xsds.bdxr.smp1.ServiceGroupType aServiceGroup;
    try {
        aServiceGroup = aSMPClient.getServiceGroupOrNull(aParticipantID);
    } catch (final SMPClientException ex) {
        LOGGER.error("Error querying SMP for ServiceGroup of '" + aParticipantID.getURIEncoded() + "'", ex);
        return null;
    }
    // If the service group is present, try querying the business card
    final PDBusinessCard aBusinessCard;
    try (final HttpClientManager aHCM = HttpClientManager.create(aHCS)) {
        // Use the optional business card API
        final HttpGet aRequest = new HttpGet(aSMPClient.getSMPHostURI() + "businesscard/" + aParticipantID.getURIPercentEncoded());
        aBusinessCard = aHCM.execute(aRequest, new PDSMPHttpResponseHandlerBusinessCard());
    } catch (final IOException ex) {
        if ((ex instanceof HttpResponseException && ((HttpResponseException) ex).getStatusCode() == CHttp.HTTP_NOT_FOUND) || ex instanceof UnknownHostException) {
            LOGGER.warn("No BusinessCard available for '" + aParticipantID.getURIEncoded() + "' - not in configured SMK/SML? - " + ex.getMessage());
        } else
            LOGGER.error("Error querying SMP for BusinessCard of '" + aParticipantID.getURIEncoded() + "'", ex);
        return null;
    }
    if (aBusinessCard == null) {
        // No extension present - no need to try again
        LOGGER.warn("Failed to get SMP BusinessCard of " + aParticipantID.getURIEncoded());
        return null;
    }
    // Query all document types
    final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
    final ICommonsList<IDocumentTypeIdentifier> aDocumentTypeIDs = BDXRClientReadOnly.getAllDocumentTypes(aServiceGroup, aIdentifierFactory, UNHANDLED_HREF_HANDLER);
    return new PDExtendedBusinessCard(aBusinessCard, aDocumentTypeIDs);
}
Also used : PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) UnknownHostException(java.net.UnknownHostException) HttpGet(org.apache.http.client.methods.HttpGet) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) HttpClientManager(com.helger.httpclient.HttpClientManager) SMPClientException(com.helger.smpclient.exception.SMPClientException) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) VisibleForTesting(com.helger.commons.annotation.VisibleForTesting) Nullable(javax.annotation.Nullable)

Example 47 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-directory by phax.

the class IndexerResource method checkParticipantExistence.

@GET
@Path("{participantID}")
public Response checkParticipantExistence(@Context @Nonnull final HttpServletRequest aHttpServletRequest, @PathParam("participantID") @Nonnull final String sParticipantID) throws IOException {
    final String sLogPrefix = "[checkParticipantExistence] ";
    final ClientCertificateValidationResult aResult = _checkClientCertificate(aHttpServletRequest, sLogPrefix);
    if (aResult.isFailure())
        return Response.status(Response.Status.FORBIDDEN).build();
    final String sRealParticipantID = _unifyPID(sParticipantID);
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLogPrefix + "'" + sRealParticipantID + "'");
    // Parse identifier
    final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
    final IParticipantIdentifier aPI = aIdentifierFactory.parseParticipantIdentifier(sRealParticipantID);
    if (aPI == null)
        if (LOGGER.isErrorEnabled())
            LOGGER.error(sLogPrefix + "Failed to parse participant identifier '" + sRealParticipantID + "'");
    // Queue for handling
    if (!PDMetaManager.getStorageMgr().containsEntry(aPI))
        return Response.status(Response.Status.NOT_FOUND).build();
    // And done
    return Response.noContent().build();
}
Also used : IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ClientCertificateValidationResult(com.helger.pd.indexer.clientcert.ClientCertificateValidationResult) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 48 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-directory by phax.

the class PDQueryManager method getDocumentTypeIDLuceneQuery.

@Nullable
public static Query getDocumentTypeIDLuceneQuery(@Nonnull @Nonempty final String sQueryString) {
    ValueEnforcer.notEmpty(sQueryString, "QueryString");
    ValueEnforcer.notEmpty(sQueryString.trim(), "QueryString trimmed");
    final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
    // No casing here!
    final IDocumentTypeIdentifier aDTI = aIdentifierFactory.parseDocumentTypeIdentifier(sQueryString);
    if (aDTI == null) {
        LOGGER.warn("Failed to convert '" + sQueryString + "' to document type ID!");
        return null;
    }
    final Query aQuery = new TermQuery(PDField.DOCTYPE_ID.getExactMatchTerm(aDTI));
    return aQuery;
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) Nullable(javax.annotation.Nullable)

Example 49 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project peppol-commons by phax.

the class PeppolParticipantIdentifierTest method testHasDefaultScheme.

@Test
public void testHasDefaultScheme() {
    final IIdentifierFactory aIF = PeppolIdentifierFactory.INSTANCE;
    assertTrue(aIF.createParticipantIdentifierWithDefaultScheme("abc").hasScheme(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME));
    assertFalse(new PeppolParticipantIdentifier("dummy-actorid-upis", "abc").hasDefaultScheme());
}
Also used : IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) Test(org.junit.Test)

Example 50 with IIdentifierFactory

use of com.helger.peppolid.factory.IIdentifierFactory in project peppol-commons by phax.

the class PeppolParticipantIdentifierTest method testURIStuff.

@Test
public void testURIStuff() {
    final IIdentifierFactory aIF = PeppolIdentifierFactory.INSTANCE;
    final IParticipantIdentifier aID1 = new PeppolParticipantIdentifier("scheme-actorid-test", "value1");
    assertEquals("scheme-actorid-test::value1", aID1.getURIEncoded());
    assertEquals("scheme-actorid-test%3A%3Avalue1", aID1.getURIPercentEncoded());
    final IParticipantIdentifier aID2 = aIF.parseParticipantIdentifier("scheme-actorid-test::value1");
    assertTrue(aID1.hasSameContent(aID2));
    assertNull(aIF.parseParticipantIdentifier("scheme1"));
    assertNull(aIF.parseParticipantIdentifier(null));
    assertNull(aIF.parseParticipantIdentifier(""));
    assertNotNull(aIF.parseParticipantIdentifier("any-actorid-dummy::9908:976098897"));
    assertNotNull(aIF.parseParticipantIdentifier("any-actorid-dummy::9908:976098897 "));
    assertNotNull(aIF.parseParticipantIdentifier("any-actorid-dummy::990:976098897"));
    assertNotNull(aIF.parseParticipantIdentifier("any-actorid-dummy::990976098897"));
    assertNotNull(aIF.parseParticipantIdentifier("any-actorid-dummy::9909:976098896"));
    assertNotNull(aIF.parseParticipantIdentifier("any-actorid-dummy::9908:976098896"));
    assertNull(aIF.parseParticipantIdentifier("any-actorid-dummythatiswaytoolongforwhatisexpected::9908:976098896"));
    assertNotNull(aIF.parseParticipantIdentifier("any-actorid-dummy::" + VALUE_MAX_LENGTH));
    assertNull(aIF.parseParticipantIdentifier("any-actorid-dummy::" + VALUE_MAX_LENGTH_PLUS_1));
    assertNull(aIF.parseParticipantIdentifier("any-actorid-dummy:9908:976098896"));
    assertNull(aIF.parseParticipantIdentifier("any-actorid-dummy9908:976098896"));
}
Also used : IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Aggregations

IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)84 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)57 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)34 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)33 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)30 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)22 IUser (com.helger.photon.security.user.IUser)20 Nonnull (javax.annotation.Nonnull)19 Test (org.junit.Test)19 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)17 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)16 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)15 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)13 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)13 HCNodeList (com.helger.html.hc.impl.HCNodeList)11 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)11 Locale (java.util.Locale)11 Nullable (javax.annotation.Nullable)11 HCEdit (com.helger.html.hc.html.forms.HCEdit)10 RequestField (com.helger.photon.core.form.RequestField)10