Search in sources :

Example 46 with IDocumentTypeIdentifier

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

the class PDStoredBusinessEntity method getAsSearchResultJsonObject.

@Nonnull
public static IJsonObject getAsSearchResultJsonObject(@Nonnull @Nonempty final ICommonsList<PDStoredBusinessEntity> aDocs) {
    ValueEnforcer.notEmptyNoNullValue(aDocs, "Docs");
    final PDStoredBusinessEntity aFirst = aDocs.getFirst();
    final IJsonObject ret = new JsonObject();
    ret.addJson("participantID", _getIDAsJson(aFirst.m_aParticipantID.getScheme(), aFirst.m_aParticipantID.getValue()));
    // Add the items retrieved from SMP as well
    final IJsonArray aDocTypes = new JsonArray();
    for (final IDocumentTypeIdentifier aDocTypeID : aFirst.m_aDocumentTypeIDs) aDocTypes.add(_getIDAsJson(aDocTypeID.getScheme(), aDocTypeID.getValue()));
    if (aDocTypes.isNotEmpty())
        ret.addJson("docTypes", aDocTypes);
    final IJsonArray aEntities = new JsonArray();
    for (final PDStoredBusinessEntity aDoc : aDocs) {
        final IJsonObject aEntity = new JsonObject();
        // Multilingual names
        final IJsonArray aMLNames = new JsonArray();
        for (final PDStoredMLName aName : aDoc.m_aNames) aMLNames.add(_getMLNameAsJson(aName.getName(), aName.getLanguageCode()));
        if (aMLNames.isNotEmpty())
            aEntity.addJson("name", aMLNames);
        aEntity.add("countryCode", aDoc.m_sCountryCode);
        if (StringHelper.hasText(aDoc.m_sGeoInfo))
            aEntity.add("geoInfo", aDoc.m_sGeoInfo);
        final IJsonArray aIDs = new JsonArray();
        for (final PDStoredIdentifier aID : aDoc.m_aIdentifiers) aIDs.add(_getIDAsJson(aID.getScheme(), aID.getValue()));
        if (aIDs.isNotEmpty())
            aEntity.addJson("identifiers", aIDs);
        final IJsonArray aWebsites = new JsonArray();
        for (final String sWebsite : aDoc.m_aWebsiteURIs) aWebsites.add(sWebsite);
        if (aWebsites.isNotEmpty())
            aEntity.addJson("websites", aWebsites);
        final IJsonArray aContacts = new JsonArray();
        for (final PDStoredContact aContact : aDoc.m_aContacts) aContacts.add(new JsonObject().addIfNotNull("type", aContact.getType()).addIfNotNull("name", aContact.getName()).addIfNotNull("phone", aContact.getPhone()).addIfNotNull("email", aContact.getEmail()));
        if (aContacts.isNotEmpty())
            aEntity.addJson("contacts", aContacts);
        if (StringHelper.hasText(aDoc.m_sAdditionalInformation))
            aEntity.add("additionalInfo", aDoc.m_sAdditionalInformation);
        if (aDoc.m_aRegistrationDate != null)
            aEntity.add("regDate", PDTWebDateHelper.getAsStringXSD(aDoc.m_aRegistrationDate));
        aEntities.add(aEntity);
    }
    ret.addJson("entities", aEntities);
    return ret;
}
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) Nonnull(javax.annotation.Nonnull)

Example 47 with IDocumentTypeIdentifier

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

the class PDExtendedBusinessCard method of.

@Nonnull
public static PDExtendedBusinessCard of(@Nonnull final IJsonObject aJson) {
    final PDBusinessCard aBC = PDBusinessCard.of(aJson.getAsObject("businesscard"));
    final ICommonsList<IDocumentTypeIdentifier> aDocTypes = CommonsArrayList.createFiltered(aJson.getAsArray("doctypes"), (Predicate<IJson>) IJson::isObject, x -> new SimpleDocumentTypeIdentifier(x.getAsObject().getAsString("scheme"), x.getAsObject().getAsString("value")));
    return new PDExtendedBusinessCard(aBC, aDocTypes);
}
Also used : PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IJson(com.helger.json.IJson) Nonnull(javax.annotation.Nonnull)

Example 48 with IDocumentTypeIdentifier

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

the class SMPBusinessCardProvider method getBusinessCardBDXR2.

@Nullable
@VisibleForTesting
PDExtendedBusinessCard getBusinessCardBDXR2(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final BDXR2ClientReadOnly aSMPClient, @Nonnull final HttpClientSettings aHCS) {
    LOGGER.info("Querying BusinessCard for '" + aParticipantID.getURIEncoded() + "' from OASIS BDXR SMP v2 '" + aSMPClient.getSMPHostURI() + "'");
    // First query the service group
    com.helger.xsds.bdxr.smp2.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
        // TODO is the path "bdxr-smp-2" needed? Well, the PD is not yet
        // specified for this SMP type....
        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 = BDXR2ClientReadOnly.getAllDocumentTypes(aServiceGroup, aIdentifierFactory);
    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 49 with IDocumentTypeIdentifier

use of com.helger.peppolid.IDocumentTypeIdentifier 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 50 with IDocumentTypeIdentifier

use of com.helger.peppolid.IDocumentTypeIdentifier 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)

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