Search in sources :

Example 1 with PD3BusinessCardType

use of com.helger.pd.businesscard.v3.PD3BusinessCardType in project phoss-smp by phax.

the class SMPBusinessCard method getAsJAXBObject.

@Nonnull
public PD3BusinessCardType getAsJAXBObject() {
    final PD3BusinessCardType ret = new PD3BusinessCardType();
    ret.setParticipantIdentifier(PD3APIHelper.createIdentifier(m_aParticipantID.getScheme(), m_aParticipantID.getValue()));
    for (final SMPBusinessCardEntity aItem : m_aEntities) ret.addBusinessEntity(aItem.getAsJAXBObject());
    return ret;
}
Also used : PD3BusinessCardType(com.helger.pd.businesscard.v3.PD3BusinessCardType) Nonnull(javax.annotation.Nonnull)

Example 2 with PD3BusinessCardType

use of com.helger.pd.businesscard.v3.PD3BusinessCardType in project phoss-smp by phax.

the class BusinessCardInterfaceTest method testGetCreateV1GetDeleteGet.

@Test
public void testGetCreateV1GetDeleteGet() {
    final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
    assertNotNull(aSGMgr);
    final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr();
    assertNotNull(aBCMgr);
    final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:tester");
    final String sPI = aPI.getURIEncoded();
    final ServiceGroupType aSG = new ServiceGroupType();
    aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI));
    aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
    final WebTarget aTarget = ClientBuilder.newClient().target(m_aRule.getFullURL());
    Response aResponseMsg;
    try {
        // Create SG
        aResponseMsg = _addCredentials(aTarget.path(sPI).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get SG - must work
        assertNotNull(aTarget.path(sPI).request().get(ServiceGroupType.class));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI));
        // Get BC - not existing
        aResponseMsg = aTarget.path("businesscard").path(sPI).request().get();
        _testResponseJerseyClient(aResponseMsg, 404);
        // Create BC with some entities
        final PD1BusinessCardType aBC = new PD1BusinessCardType();
        aBC.setParticipantIdentifier(PD1APIHelper.createIdentifier(aPI.getScheme(), aPI.getValue()));
        PD1BusinessEntityType aBE = new PD1BusinessEntityType();
        aBE.setName("BusinessEntity1");
        aBE.setCountryCode("AT");
        aBE.setGeographicalInformation("Vienna");
        aBC.addBusinessEntity(aBE);
        aBE = new PD1BusinessEntityType();
        aBE.setName("BusinessEntity2");
        aBE.setCountryCode("DE");
        aBE.setGeographicalInformation("Berlin");
        aBC.addBusinessEntity(aBE);
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC1ObjFactory.createBusinessCard(aBC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get BC - must work (always V3)
        PD3BusinessCardType aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
        assertNotNull(aReadBC);
        assertEquals(2, aReadBC.getBusinessEntityCount());
        ISMPBusinessCard aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
        assertNotNull(aGetBC);
        // Update BC - add entity
        aBE = new PD1BusinessEntityType();
        aBE.setName("BusinessEntity3");
        aBE.setCountryCode("SE");
        aBE.setGeographicalInformation("Stockholm");
        aBC.addBusinessEntity(aBE);
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC1ObjFactory.createBusinessCard(aBC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get BC - must work (always V3)
        aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
        assertNotNull(aReadBC);
        assertEquals(3, aReadBC.getBusinessEntityCount());
        aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
        assertNotNull(aGetBC);
    } finally {
        // Delete Business Card
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).delete();
        _testResponseJerseyClient(aResponseMsg, 200, 404);
        // must be deleted
        _testResponseJerseyClient(aTarget.path("businesscard").path(sPI).request().get(), 404);
        assertNull(aBCMgr.getSMPBusinessCardOfID(aPI));
        // Delete service Group
        aResponseMsg = _addCredentials(aTarget.path(sPI).request()).delete();
        _testResponseJerseyClient(aResponseMsg, 200, 404);
        // must be deleted
        _testResponseJerseyClient(aTarget.path(sPI).request().get(), 404);
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI));
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) PD1BusinessEntityType(com.helger.pd.businesscard.v1.PD1BusinessEntityType) PD1BusinessCardType(com.helger.pd.businesscard.v1.PD1BusinessCardType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) Response(javax.ws.rs.core.Response) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) PD3BusinessCardType(com.helger.pd.businesscard.v3.PD3BusinessCardType) WebTarget(javax.ws.rs.client.WebTarget) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 3 with PD3BusinessCardType

use of com.helger.pd.businesscard.v3.PD3BusinessCardType in project phoss-smp by phax.

the class BusinessCardInterfaceTest method testGetCreateV3GetDeleteGet.

@Test
public void testGetCreateV3GetDeleteGet() {
    final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
    assertNotNull(aSGMgr);
    final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr();
    assertNotNull(aBCMgr);
    final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:tester");
    final String sPI = aPI.getURIEncoded();
    final ServiceGroupType aSG = new ServiceGroupType();
    aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI));
    aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
    final WebTarget aTarget = ClientBuilder.newClient().target(m_aRule.getFullURL());
    Response aResponseMsg;
    try {
        // Create SG
        aResponseMsg = _addCredentials(aTarget.path(sPI).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get SG - must work
        assertNotNull(aTarget.path(sPI).request().get(ServiceGroupType.class));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI));
        // Get BC - not existing
        aResponseMsg = aTarget.path("businesscard").path(sPI).request().get();
        _testResponseJerseyClient(aResponseMsg, 404);
        // Create BC with some entities
        final PD3BusinessCardType aBC = new PD3BusinessCardType();
        aBC.setParticipantIdentifier(PD3APIHelper.createIdentifier(aPI.getScheme(), aPI.getValue()));
        PD3BusinessEntityType aBE = new PD3BusinessEntityType();
        aBE.addName(PD3APIHelper.createName("BusinessEntity1", null));
        aBE.setCountryCode("AT");
        aBE.setGeographicalInformation("Vienna");
        aBC.addBusinessEntity(aBE);
        aBE = new PD3BusinessEntityType();
        aBE.addName(PD3APIHelper.createName("BusinessEntity2", null));
        aBE.setCountryCode("DE");
        aBE.setGeographicalInformation("Berlin");
        aBC.addBusinessEntity(aBE);
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC3ObjFactory.createBusinessCard(aBC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get BC - must work (always V3)
        PD3BusinessCardType aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
        assertNotNull(aReadBC);
        assertEquals(2, aReadBC.getBusinessEntityCount());
        ISMPBusinessCard aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
        assertNotNull(aGetBC);
        // Update BC - add entity
        aBE = new PD3BusinessEntityType();
        aBE.addName(PD3APIHelper.createName("BusinessEntity3", null));
        aBE.setCountryCode("SE");
        aBE.setGeographicalInformation("Stockholm");
        aBC.addBusinessEntity(aBE);
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC3ObjFactory.createBusinessCard(aBC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get BC - must work (always V3)
        aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
        assertNotNull(aReadBC);
        assertEquals(3, aReadBC.getBusinessEntityCount());
        aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
        assertNotNull(aGetBC);
    } finally {
        // Delete Business Card
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).delete();
        _testResponseJerseyClient(aResponseMsg, 200, 404);
        // must be deleted
        _testResponseJerseyClient(aTarget.path("businesscard").path(sPI).request().get(), 404);
        assertNull(aBCMgr.getSMPBusinessCardOfID(aPI));
        // Delete service Group
        aResponseMsg = _addCredentials(aTarget.path(sPI).request()).delete();
        _testResponseJerseyClient(aResponseMsg, 200, 404);
        // must be deleted
        _testResponseJerseyClient(aTarget.path(sPI).request().get(), 404);
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI));
    }
}
Also used : Response(javax.ws.rs.core.Response) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) PD3BusinessCardType(com.helger.pd.businesscard.v3.PD3BusinessCardType) PD3BusinessEntityType(com.helger.pd.businesscard.v3.PD3BusinessEntityType) WebTarget(javax.ws.rs.client.WebTarget) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 4 with PD3BusinessCardType

use of com.helger.pd.businesscard.v3.PD3BusinessCardType in project phoss-smp by phax.

the class BusinessCardInterfaceTest method testGetCreateV2GetDeleteGet.

@Test
public void testGetCreateV2GetDeleteGet() {
    final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
    assertNotNull(aSGMgr);
    final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr();
    assertNotNull(aBCMgr);
    final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:tester");
    final String sPI = aPI.getURIEncoded();
    final ServiceGroupType aSG = new ServiceGroupType();
    aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI));
    aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
    final WebTarget aTarget = ClientBuilder.newClient().target(m_aRule.getFullURL());
    Response aResponseMsg;
    try {
        // Create SG
        aResponseMsg = _addCredentials(aTarget.path(sPI).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get SG - must work
        assertNotNull(aTarget.path(sPI).request().get(ServiceGroupType.class));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI));
        // Get BC - not existing
        aResponseMsg = aTarget.path("businesscard").path(sPI).request().get();
        _testResponseJerseyClient(aResponseMsg, 404);
        // Create BC with some entities
        final PD2BusinessCardType aBC = new PD2BusinessCardType();
        aBC.setParticipantIdentifier(PD2APIHelper.createIdentifier(aPI.getScheme(), aPI.getValue()));
        PD2BusinessEntityType aBE = new PD2BusinessEntityType();
        aBE.setName("BusinessEntity1");
        aBE.setCountryCode("AT");
        aBE.setGeographicalInformation("Vienna");
        aBC.addBusinessEntity(aBE);
        aBE = new PD2BusinessEntityType();
        aBE.setName("BusinessEntity2");
        aBE.setCountryCode("DE");
        aBE.setGeographicalInformation("Berlin");
        aBC.addBusinessEntity(aBE);
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC2ObjFactory.createBusinessCard(aBC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get BC - must work (always V3)
        PD3BusinessCardType aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
        assertNotNull(aReadBC);
        assertEquals(2, aReadBC.getBusinessEntityCount());
        ISMPBusinessCard aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
        assertNotNull(aGetBC);
        // Update BC - add entity
        aBE = new PD2BusinessEntityType();
        aBE.setName("BusinessEntity3");
        aBE.setCountryCode("SE");
        aBE.setGeographicalInformation("Stockholm");
        aBC.addBusinessEntity(aBE);
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC2ObjFactory.createBusinessCard(aBC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get BC - must work (always V3)
        aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
        assertNotNull(aReadBC);
        assertEquals(3, aReadBC.getBusinessEntityCount());
        aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
        assertNotNull(aGetBC);
    } finally {
        // Delete Business Card
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).delete();
        _testResponseJerseyClient(aResponseMsg, 200, 404);
        // must be deleted
        _testResponseJerseyClient(aTarget.path("businesscard").path(sPI).request().get(), 404);
        assertNull(aBCMgr.getSMPBusinessCardOfID(aPI));
        // Delete service Group
        aResponseMsg = _addCredentials(aTarget.path(sPI).request()).delete();
        _testResponseJerseyClient(aResponseMsg, 200, 404);
        // must be deleted
        _testResponseJerseyClient(aTarget.path(sPI).request().get(), 404);
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI));
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) Response(javax.ws.rs.core.Response) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) PD2BusinessEntityType(com.helger.pd.businesscard.v2.PD2BusinessEntityType) PD3BusinessCardType(com.helger.pd.businesscard.v3.PD3BusinessCardType) WebTarget(javax.ws.rs.client.WebTarget) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) PD2BusinessCardType(com.helger.pd.businesscard.v2.PD2BusinessCardType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 5 with PD3BusinessCardType

use of com.helger.pd.businesscard.v3.PD3BusinessCardType in project phoss-smp by phax.

the class APIExecutorBusinessCardGet method invokeAPI.

public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
    final String sServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
    final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sServiceGroupID);
    if (!SMPMetaManager.getSettings().isDirectoryIntegrationEnabled()) {
        // PD integration is disabled
        throw new SMPPreconditionFailedException("The " + SMPWebAppConfiguration.getDirectoryName() + " integration is disabled. getBusinessCard will not be executed", aDataProvider.getCurrentURI());
    }
    // getBusinessCard throws an exception if non is found
    final PD3BusinessCardType ret = new BusinessCardServerAPI(aDataProvider).getBusinessCard(sServiceGroupID);
    final byte[] aBytes = new PD3BusinessCardMarshaller().getAsBytes(ret);
    aUnifiedResponse.setContent(aBytes).setMimeType(CMimeType.TEXT_XML).setCharset(XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
}
Also used : SMPPreconditionFailedException(com.helger.phoss.smp.exception.SMPPreconditionFailedException) PD3BusinessCardType(com.helger.pd.businesscard.v3.PD3BusinessCardType) BusinessCardServerAPI(com.helger.phoss.smp.restapi.BusinessCardServerAPI) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) PD3BusinessCardMarshaller(com.helger.pd.businesscard.v3.PD3BusinessCardMarshaller)

Aggregations

PD3BusinessCardType (com.helger.pd.businesscard.v3.PD3BusinessCardType)5 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)3 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)3 ISMPBusinessCard (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard)3 ISMPBusinessCardManager (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager)3 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)3 ServiceGroupType (com.helger.xsds.peppol.smp1.ServiceGroupType)3 ServiceMetadataReferenceCollectionType (com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType)3 WebTarget (javax.ws.rs.client.WebTarget)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 PD1BusinessCardType (com.helger.pd.businesscard.v1.PD1BusinessCardType)1 PD1BusinessEntityType (com.helger.pd.businesscard.v1.PD1BusinessEntityType)1 PD2BusinessCardType (com.helger.pd.businesscard.v2.PD2BusinessCardType)1 PD2BusinessEntityType (com.helger.pd.businesscard.v2.PD2BusinessEntityType)1 PD3BusinessCardMarshaller (com.helger.pd.businesscard.v3.PD3BusinessCardMarshaller)1 PD3BusinessEntityType (com.helger.pd.businesscard.v3.PD3BusinessEntityType)1 SMPPreconditionFailedException (com.helger.phoss.smp.exception.SMPPreconditionFailedException)1 BusinessCardServerAPI (com.helger.phoss.smp.restapi.BusinessCardServerAPI)1 ISMPServerAPIDataProvider (com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider)1