Search in sources :

Example 1 with ServiceGroupReferenceListType

use of com.helger.xsds.peppol.smp1.ServiceGroupReferenceListType in project peppol-commons by phax.

the class SMPClientTest method testGetServiceGroupReferenceList.

@Test
public void testGetServiceGroupReferenceList() throws SMPClientException {
    final SMPClient aSMPClient = new SMPClient(SMP_URI);
    final ServiceGroupReferenceListType aServiceGroupReferenceList = aSMPClient.getServiceGroupReferenceList(SMP_USERNAME, SMP_CREDENTIALS);
    assertNotNull(aServiceGroupReferenceList);
    for (final ServiceGroupReferenceType aServiceGroupReference : aServiceGroupReferenceList.getServiceGroupReference()) {
        final CompleteServiceGroupType aCSG = aSMPClient.getCompleteServiceGroup(aServiceGroupReference.getHref());
        assertNotNull(aCSG);
    }
}
Also used : CompleteServiceGroupType(com.helger.xsds.peppol.smp1.CompleteServiceGroupType) ServiceGroupReferenceListType(com.helger.xsds.peppol.smp1.ServiceGroupReferenceListType) ServiceGroupReferenceType(com.helger.xsds.peppol.smp1.ServiceGroupReferenceType) Test(org.junit.Test)

Example 2 with ServiceGroupReferenceListType

use of com.helger.xsds.peppol.smp1.ServiceGroupReferenceListType in project peppol-commons by phax.

the class MainSMPServiceGroupReferenceList method main.

public static void main(final String[] args) throws Exception {
    final URI SMP_URI = MockSMPClientConfig.getSMPURI();
    final BasicAuthClientCredentials SMP_CREDENTIALS = MockSMPClientConfig.getSMPCredentials();
    final String SMP_USERNAME = MockSMPClientConfig.getSMPUserName();
    // The main SMP client
    final SMPClient aClient = new SMPClient(SMP_URI);
    // Get the service group reference list
    final ServiceGroupReferenceListType aServiceGroupReferenceList = aClient.getServiceGroupReferenceListOrNull(SMP_USERNAME, SMP_CREDENTIALS);
    if (aServiceGroupReferenceList == null)
        LOGGER.error("Failed to get complete service group for " + SMP_USERNAME);
    else {
        LOGGER.info("All service groups owned by " + SMP_USERNAME + ":");
        for (final ServiceGroupReferenceType aServiceGroupReference : aServiceGroupReferenceList.getServiceGroupReference()) LOGGER.info("  " + aServiceGroupReference.getHref());
    }
    LOGGER.info("Done");
}
Also used : BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPClient(com.helger.smpclient.peppol.SMPClient) ServiceGroupReferenceListType(com.helger.xsds.peppol.smp1.ServiceGroupReferenceListType) ServiceGroupReferenceType(com.helger.xsds.peppol.smp1.ServiceGroupReferenceType) URI(java.net.URI)

Example 3 with ServiceGroupReferenceListType

use of com.helger.xsds.peppol.smp1.ServiceGroupReferenceListType in project phoss-smp by phax.

the class SMPServerAPI method getServiceGroupReferenceList.

@Nonnull
public ServiceGroupReferenceListType getServiceGroupReferenceList(@Nonnull final String sPathUserID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "GET /list/" + sPathUserID;
    final String sAction = "getServiceGroupReferenceList";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        if (!aCredentials.getUserName().equals(sPathUserID)) {
            throw new SMPUnauthorizedException("URL user name '" + sPathUserID + "' does not match HTTP Basic Auth user name '" + aCredentials.getUserName() + "'", m_aAPIDataProvider.getCurrentURI());
        }
        final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
        final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
        final ICommonsList<ISMPServiceGroup> aServiceGroups = aSGMgr.getAllSMPServiceGroupsOfOwner(aSMPUser.getID());
        final ServiceGroupReferenceListType aRefList = new ServiceGroupReferenceListType();
        for (final ISMPServiceGroup aServiceGroup : aServiceGroups) {
            final String sHref = m_aAPIDataProvider.getServiceGroupHref(aServiceGroup.getParticipantIdentifier());
            final ServiceGroupReferenceType aServGroupRefType = new ServiceGroupReferenceType();
            aServGroupRefType.setHref(sHref);
            aRefList.addServiceGroupReference(aServGroupRefType);
        }
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return aRefList;
    } 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) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) ServiceGroupReferenceListType(com.helger.xsds.peppol.smp1.ServiceGroupReferenceListType) IUser(com.helger.photon.security.user.IUser) ServiceGroupReferenceType(com.helger.xsds.peppol.smp1.ServiceGroupReferenceType) SMPUnauthorizedException(com.helger.phoss.smp.exception.SMPUnauthorizedException) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Example 4 with ServiceGroupReferenceListType

use of com.helger.xsds.peppol.smp1.ServiceGroupReferenceListType in project phoss-smp by phax.

the class BDXR1ServerAPI method getServiceGroupReferenceList.

@Nonnull
public ServiceGroupReferenceListType getServiceGroupReferenceList(@Nonnull final String sPathUserID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "GET /list/" + sPathUserID;
    final String sAction = "getServiceGroupReferenceList";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        if (!aCredentials.getUserName().equals(sPathUserID)) {
            throw new SMPUnauthorizedException("URL user name '" + sPathUserID + "' does not match HTTP Basic Auth user name '" + aCredentials.getUserName() + "'", m_aAPIDataProvider.getCurrentURI());
        }
        final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
        final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
        final ICommonsList<ISMPServiceGroup> aServiceGroups = aSGMgr.getAllSMPServiceGroupsOfOwner(aSMPUser.getID());
        final ServiceGroupReferenceListType aRefList = new ServiceGroupReferenceListType();
        for (final ISMPServiceGroup aServiceGroup : aServiceGroups) {
            final String sHref = m_aAPIDataProvider.getServiceGroupHref(aServiceGroup.getParticipantIdentifier());
            final ServiceGroupReferenceType aServGroupRefType = new ServiceGroupReferenceType();
            aServGroupRefType.setHref(sHref);
            aRefList.addServiceGroupReference(aServGroupRefType);
        }
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return aRefList;
    } 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) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) ServiceGroupReferenceListType(com.helger.xsds.bdxr.smp1.ServiceGroupReferenceListType) IUser(com.helger.photon.security.user.IUser) ServiceGroupReferenceType(com.helger.xsds.bdxr.smp1.ServiceGroupReferenceType) SMPUnauthorizedException(com.helger.phoss.smp.exception.SMPUnauthorizedException) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Aggregations

ServiceGroupReferenceListType (com.helger.xsds.peppol.smp1.ServiceGroupReferenceListType)3 ServiceGroupReferenceType (com.helger.xsds.peppol.smp1.ServiceGroupReferenceType)3 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)2 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)2 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)2 SMPUnauthorizedException (com.helger.phoss.smp.exception.SMPUnauthorizedException)2 IUser (com.helger.photon.security.user.IUser)2 Nonnull (javax.annotation.Nonnull)2 BasicAuthClientCredentials (com.helger.http.basicauth.BasicAuthClientCredentials)1 SMPClient (com.helger.smpclient.peppol.SMPClient)1 ServiceGroupReferenceListType (com.helger.xsds.bdxr.smp1.ServiceGroupReferenceListType)1 ServiceGroupReferenceType (com.helger.xsds.bdxr.smp1.ServiceGroupReferenceType)1 CompleteServiceGroupType (com.helger.xsds.peppol.smp1.CompleteServiceGroupType)1 URI (java.net.URI)1 Test (org.junit.Test)1