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;
}
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()));
}
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()));
}
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));
}
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;
}
}
Aggregations