Search in sources :

Example 1 with PDBusinessEntity

use of com.helger.pd.businesscard.generic.PDBusinessEntity in project phoss-directory by phax.

the class PD3APIHelper method createBusinessEntity.

@Nonnull
public static PDBusinessEntity createBusinessEntity(@Nonnull final PD3BusinessEntityType aBE) {
    ValueEnforcer.notNull(aBE, "BusinessEntity");
    final PDBusinessEntity ret = new PDBusinessEntity();
    ret.names().setAllMapped(aBE.getName(), PD3APIHelper::createName);
    ret.setCountryCode(aBE.getCountryCode());
    ret.setGeoInfo(aBE.getGeographicalInformation());
    ret.identifiers().setAllMapped(aBE.getIdentifier(), PD3APIHelper::createIdentifier);
    ret.websiteURIs().setAll(aBE.getWebsiteURI());
    ret.contacts().setAllMapped(aBE.getContact(), PD3APIHelper::createContact);
    ret.setAdditionalInfo(aBE.getAdditionalInformation());
    ret.setRegistrationDate(aBE.getRegistrationDate());
    return ret;
}
Also used : PDBusinessEntity(com.helger.pd.businesscard.generic.PDBusinessEntity) Nonnull(javax.annotation.Nonnull)

Example 2 with PDBusinessEntity

use of com.helger.pd.businesscard.generic.PDBusinessEntity in project phoss-directory by phax.

the class IndexerResourceTest method _createMockBC.

@Nonnull
private static PDExtendedBusinessCard _createMockBC(@Nonnull final IParticipantIdentifier aParticipantID) {
    final PDBusinessCard aBI = new PDBusinessCard();
    aBI.setParticipantIdentifier(new PDIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "9915:mock"));
    {
        final PDBusinessEntity aEntity = new PDBusinessEntity();
        aEntity.names().add(new PDName("Philip's mock Peppol receiver"));
        aEntity.setCountryCode("AT");
        aEntity.identifiers().add(new PDIdentifier("mock", "12345678"));
        aEntity.identifiers().add(new PDIdentifier(aParticipantID.getScheme(), aParticipantID.getValue()));
        aEntity.setAdditionalInfo("This is a mock entry for testing purposes only");
        aBI.businessEntities().add(aEntity);
    }
    {
        final PDBusinessEntity aEntity = new PDBusinessEntity();
        aEntity.names().add(new PDName("Philip's mock Peppol receiver 2"));
        aEntity.setCountryCode("NO");
        aEntity.identifiers().add(new PDIdentifier("mock", "abcdefgh"));
        aEntity.setAdditionalInfo("This is another mock entry for testing purposes only");
        aBI.businessEntities().add(aEntity);
    }
    return new PDExtendedBusinessCard(aBI, new CommonsArrayList<>(EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier()));
}
Also used : PDIdentifier(com.helger.pd.businesscard.generic.PDIdentifier) PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) PDName(com.helger.pd.businesscard.generic.PDName) PDBusinessEntity(com.helger.pd.businesscard.generic.PDBusinessEntity) PDExtendedBusinessCard(com.helger.pd.indexer.businesscard.PDExtendedBusinessCard) Nonnull(javax.annotation.Nonnull)

Example 3 with PDBusinessEntity

use of com.helger.pd.businesscard.generic.PDBusinessEntity in project phoss-directory by phax.

the class LocalHost8080FuncTest method _createMockBC.

@Nonnull
private static PDExtendedBusinessCard _createMockBC(@Nonnull final IParticipantIdentifier aParticipantID) {
    final PDBusinessCard aBI = new PDBusinessCard();
    aBI.setParticipantIdentifier(new PDIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "9915:mock"));
    {
        final PDBusinessEntity aEntity = new PDBusinessEntity();
        aEntity.names().add(new PDName("Philip's mock Peppol receiver"));
        aEntity.setCountryCode("AT");
        aEntity.identifiers().add(new PDIdentifier("mock", "12345678"));
        aEntity.identifiers().add(new PDIdentifier(aParticipantID.getScheme(), aParticipantID.getValue()));
        aEntity.setAdditionalInfo("This is a mock entry for testing purposes only");
        aBI.businessEntities().add(aEntity);
    }
    {
        final PDBusinessEntity aEntity = new PDBusinessEntity();
        aEntity.names().add(new PDName("Philip's mock Peppol receiver 2"));
        aEntity.setCountryCode("NO");
        aEntity.identifiers().add(new PDIdentifier("mock", "abcdefgh"));
        aEntity.setAdditionalInfo("This is another mock entry for testing purposes only");
        aBI.businessEntities().add(aEntity);
    }
    return new PDExtendedBusinessCard(aBI, new CommonsArrayList<>(EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier()));
}
Also used : PDIdentifier(com.helger.pd.businesscard.generic.PDIdentifier) PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) PDName(com.helger.pd.businesscard.generic.PDName) PDBusinessEntity(com.helger.pd.businesscard.generic.PDBusinessEntity) PDExtendedBusinessCard(com.helger.pd.indexer.businesscard.PDExtendedBusinessCard) Nonnull(javax.annotation.Nonnull)

Example 4 with PDBusinessEntity

use of com.helger.pd.businesscard.generic.PDBusinessEntity in project phoss-directory by phax.

the class PDStorageManagerTest method _createMockBI.

@Nonnull
private static PDExtendedBusinessCard _createMockBI(@Nonnull final IParticipantIdentifier aParticipantID) {
    final PDBusinessCard aBI = new PDBusinessCard();
    aBI.setParticipantIdentifier(new PDIdentifier(aParticipantID.getScheme(), aParticipantID.getValue()));
    {
        final PDBusinessEntity aEntity = new PDBusinessEntity();
        aEntity.setCountryCode("AT");
        aEntity.setRegistrationDate(PDTFactory.createLocalDate(2015, Month.JULY, 6));
        aEntity.names().add(new PDName("Philip's mock Peppol receiver"));
        aEntity.setGeoInfo("Vienna");
        for (int i = 0; i < 10; ++i) aEntity.identifiers().add(new PDIdentifier("scheme" + i, "value" + i));
        aEntity.websiteURIs().add("http://www.peppol.eu");
        aEntity.contacts().add(new PDContact("support", "BC name", "12345", "test@example.org"));
        aEntity.setAdditionalInfo("This is a mock entry for testing purposes only");
        aBI.businessEntities().add(aEntity);
    }
    {
        final PDBusinessEntity aEntity = new PDBusinessEntity();
        aEntity.setCountryCode("NO");
        aEntity.names().add(new PDName("Entity2a", "no"));
        aEntity.names().add(new PDName("Entity2b", "de"));
        aEntity.names().add(new PDName("Entity2c", "en"));
        aEntity.setAdditionalInfo("Mock");
        aBI.businessEntities().add(aEntity);
    }
    return new PDExtendedBusinessCard(aBI, new CommonsArrayList<>(EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30));
}
Also used : PDIdentifier(com.helger.pd.businesscard.generic.PDIdentifier) PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) PDName(com.helger.pd.businesscard.generic.PDName) PDBusinessEntity(com.helger.pd.businesscard.generic.PDBusinessEntity) PDContact(com.helger.pd.businesscard.generic.PDContact) PDExtendedBusinessCard(com.helger.pd.indexer.businesscard.PDExtendedBusinessCard) Nonnull(javax.annotation.Nonnull)

Example 5 with PDBusinessEntity

use of com.helger.pd.businesscard.generic.PDBusinessEntity in project phoss-smp by phax.

the class BusinessCardServerAPI method createBusinessCard.

@Nonnull
public ESuccess createBusinessCard(@Nonnull final String sServiceGroupID, @Nonnull final PDBusinessCard aBusinessCard, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "PUT /businesscard/" + sServiceGroupID;
    final String sAction = "createBusinessCard";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog + " ==> " + aBusinessCard);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        // Parse and validate identifier
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
        if (aServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sServiceGroupID, m_aAPIProvider.getCurrentURI());
        }
        final IParticipantIdentifier aPayloadServiceGroupID = aIdentifierFactory.createParticipantIdentifier(aBusinessCard.getParticipantIdentifier().getScheme(), aBusinessCard.getParticipantIdentifier().getValue());
        if (!aServiceGroupID.hasSameContent(aPayloadServiceGroupID)) {
            // Business identifiers must be equal
            throw new SMPBadRequestException("Participant Inconsistency. The URL points to '" + aServiceGroupID.getURIEncoded() + "' whereas the BusinessCard contains '" + aPayloadServiceGroupID.getURIEncoded() + "'", m_aAPIProvider.getCurrentURI());
        }
        // Retrieve the service group
        final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
        final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aServiceGroupID);
        if (aServiceGroup == null) {
            // No such service group (on this server)
            throw new SMPNotFoundException("Unknown serviceGroup '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
        }
        // Check credentials and verify service group is owned by provided user
        final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
        SMPUserManagerPhoton.verifyOwnership(aServiceGroupID, aSMPUser);
        final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
        if (aBusinessCardMgr == null) {
            throw new SMPBadRequestException("This SMP server does not support the BusinessCard API", m_aAPIProvider.getCurrentURI());
        }
        final ICommonsList<SMPBusinessCardEntity> aEntities = new CommonsArrayList<>();
        for (final PDBusinessEntity aEntity : aBusinessCard.businessEntities()) aEntities.add(SMPBusinessCardEntity.createFromGenericObject(aEntity));
        if (aBusinessCardMgr.createOrUpdateSMPBusinessCard(aServiceGroup.getParticipantIdentifier(), aEntities) == null) {
            if (LOGGER.isWarnEnabled())
                LOGGER.warn(sLog + " ERROR");
            STATS_COUNTER_ERROR.increment(sAction);
            return ESuccess.FAILURE;
        }
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return ESuccess.SUCCESS;
    } catch (final SMPServerException ex) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
        STATS_COUNTER_ERROR.increment(sAction);
        throw ex;
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) IUser(com.helger.photon.security.user.IUser) PDBusinessEntity(com.helger.pd.businesscard.generic.PDBusinessEntity) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Aggregations

PDBusinessEntity (com.helger.pd.businesscard.generic.PDBusinessEntity)9 Nonnull (javax.annotation.Nonnull)9 PDName (com.helger.pd.businesscard.generic.PDName)6 PDBusinessCard (com.helger.pd.businesscard.generic.PDBusinessCard)4 PDIdentifier (com.helger.pd.businesscard.generic.PDIdentifier)4 PDExtendedBusinessCard (com.helger.pd.indexer.businesscard.PDExtendedBusinessCard)3 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)2 PDContact (com.helger.pd.businesscard.generic.PDContact)2 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)1 PDField (com.helger.pd.indexer.storage.field.PDField)1 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)1 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)1 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)1 ISMPBusinessCardManager (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager)1 SMPBusinessCardEntity (com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity)1 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)1 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)1 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)1 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)1 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)1