Search in sources :

Example 66 with IDocumentTypeIdentifier

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

the class BDXR1ServerAPI method getCompleteServiceGroup.

@Nonnull
public CompleteServiceGroupType getCompleteServiceGroup(final String sPathServiceGroupID) throws SMPServerException {
    final String sLog = LOG_PREFIX + "GET /complete/" + sPathServiceGroupID;
    final String sAction = "getCompleteServiceGroup";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
        if (aPathServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
        }
        final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
        final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
        final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
        if (aServiceGroup == null) {
            // No such service group
            throw new SMPNotFoundException("Unknown Service Group ID '" + sPathServiceGroupID + "'", m_aAPIDataProvider.getCurrentURI());
        }
        // Then add the service metadata references
        final ServiceMetadataReferenceCollectionType aRefCollection = new ServiceMetadataReferenceCollectionType();
        for (final IDocumentTypeIdentifier aDocTypeID : aServiceInfoMgr.getAllSMPDocumentTypesOfServiceGroup(aServiceGroup)) {
            // Ignore all service information without endpoints
            final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID);
            if (aServiceInfo != null && aServiceInfo.getTotalEndpointCount() > 0) {
                final ServiceMetadataReferenceType aMetadataReference = new ServiceMetadataReferenceType();
                aMetadataReference.setHref(m_aAPIDataProvider.getServiceMetadataReferenceHref(aPathServiceGroupID, aDocTypeID));
                aRefCollection.addServiceMetadataReference(aMetadataReference);
            }
        }
        final ServiceGroupType aSG = aServiceGroup.getAsJAXBObjectBDXR1();
        aSG.setServiceMetadataReferenceCollection(aRefCollection);
        // a CompleteSG may be empty
        final CompleteServiceGroupType aCompleteServiceGroup = new CompleteServiceGroupType();
        aCompleteServiceGroup.setServiceGroup(aSG);
        for (final ISMPServiceInformation aServiceInfo : aServiceInfoMgr.getAllSMPServiceInformationOfServiceGroup(aServiceGroup)) {
            final ServiceMetadataType aSM = aServiceInfo.getAsJAXBObjectBDXR1();
            if (aSM != null)
                aCompleteServiceGroup.addServiceMetadata(aSM);
        }
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return aCompleteServiceGroup;
    } catch (final SMPServerException ex) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
        STATS_COUNTER_ERROR.increment(sAction);
        throw ex;
    }
}
Also used : CompleteServiceGroupType(com.helger.xsds.bdxr.smp1.CompleteServiceGroupType) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.bdxr.smp1.ServiceMetadataReferenceCollectionType) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ServiceMetadataReferenceType(com.helger.xsds.bdxr.smp1.ServiceMetadataReferenceType) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ServiceGroupType(com.helger.xsds.bdxr.smp1.ServiceGroupType) CompleteServiceGroupType(com.helger.xsds.bdxr.smp1.CompleteServiceGroupType) SignedServiceMetadataType(com.helger.xsds.bdxr.smp1.SignedServiceMetadataType) ServiceMetadataType(com.helger.xsds.bdxr.smp1.ServiceMetadataType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Example 67 with IDocumentTypeIdentifier

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

the class BDXR1ServerAPI method saveServiceRegistration.

@Nonnull
public ESuccess saveServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocumentTypeID, @Nonnull final ServiceMetadataType aServiceMetadata, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "PUT /" + sPathServiceGroupID + "/services/" + sPathDocumentTypeID;
    final String sAction = "saveServiceRegistration";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog + " ==> " + aServiceMetadata);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        // Parse provided identifiers
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
        if (aPathServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
        }
        final IDocumentTypeIdentifier aPathDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sPathDocumentTypeID);
        if (aPathDocTypeID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseDocType(sPathDocumentTypeID, m_aAPIDataProvider.getCurrentURI());
        }
        // May be null for a Redirect!
        final ServiceInformationType aServiceInformation = aServiceMetadata.getServiceInformation();
        if (aServiceInformation != null) {
            // metadata (body) must equal path
            if (aServiceInformation.getParticipantIdentifier() == null) {
                throw new SMPBadRequestException("Save Service Metadata has inconsistent values.\n" + "Service Information Participant ID: <none>\n" + "URL Parameter value: '" + aPathServiceGroupID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
            }
            final IParticipantIdentifier aPayloadServiceGroupID;
            if (aServiceInformation.getParticipantIdentifier() == null) {
                // Can happen when tampering with the input data
                aPayloadServiceGroupID = null;
            } else {
                aPayloadServiceGroupID = aIdentifierFactory.createParticipantIdentifier(aServiceInformation.getParticipantIdentifier().getScheme(), aServiceInformation.getParticipantIdentifier().getValue());
            }
            if (!aPathServiceGroupID.hasSameContent(aPayloadServiceGroupID)) {
                // Participant ID in URL must match the one in XML structure
                throw new SMPBadRequestException("Save Service Metadata was called with inconsistent values.\n" + "Service Infoformation Participant ID: " + (aPayloadServiceGroupID == null ? "<none>" : "'" + aPayloadServiceGroupID.getURIEncoded() + "'") + "\n" + "URL parameter value: '" + aPathServiceGroupID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
            }
            if (aServiceInformation.getDocumentIdentifier() == null) {
                throw new SMPBadRequestException("Save Service Metadata was called with inconsistent values.\n" + "Service Information Document Type ID: <none>\n" + "URL parameter value: '" + aPathDocTypeID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
            }
            final IDocumentTypeIdentifier aPayloadDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(aServiceInformation.getDocumentIdentifier().getScheme(), aServiceInformation.getDocumentIdentifier().getValue());
            if (!aPathDocTypeID.hasSameContent(aPayloadDocTypeID)) {
                // Document type ID in URL must match the one in XML structure
                throw new SMPBadRequestException("Save Service Metadata was called with inconsistent values.\n" + "Service Information Document Type ID: '" + aPayloadDocTypeID.getURIEncoded() + "'\n" + "URL parameter value: '" + aPathDocTypeID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
            }
        }
        // Main save
        final IUser aDataUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
        SMPUserManagerPhoton.verifyOwnership(aPathServiceGroupID, aDataUser);
        final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
        final ISMPServiceGroup aPathServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
        if (aPathServiceGroup == null) {
            // Service group not found
            throw new SMPNotFoundException("Service Group '" + sPathServiceGroupID + "' is not on this SMP", m_aAPIDataProvider.getCurrentURI());
        }
        if (aServiceMetadata.getRedirect() != null) {
            // Handle redirect
            final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
            // not available in OASIS BDXR SMP v1 mode
            final X509Certificate aCertificate = null;
            if (aRedirectMgr.createOrUpdateSMPRedirect(aPathServiceGroup, aPathDocTypeID, aServiceMetadata.getRedirect().getHref(), aServiceMetadata.getRedirect().getCertificateUID(), aCertificate, BDXR1ExtensionConverter.convertToString(aServiceMetadata.getRedirect().getExtension())) == null) {
                if (LOGGER.isErrorEnabled())
                    LOGGER.error(sLog + " - ERROR - Redirect");
                STATS_COUNTER_ERROR.increment(sAction);
                return ESuccess.FAILURE;
            }
            if (LOGGER.isInfoEnabled())
                LOGGER.info(sLog + " SUCCESS - Redirect");
        } else if (aServiceInformation != null) {
            // Handle service information
            final ProcessListType aJAXBProcesses = aServiceInformation.getProcessList();
            final ICommonsList<SMPProcess> aProcesses = new CommonsArrayList<>();
            for (final ProcessType aJAXBProcess : aJAXBProcesses.getProcess()) {
                final ICommonsList<SMPEndpoint> aEndpoints = new CommonsArrayList<>();
                for (final EndpointType aJAXBEndpoint : aJAXBProcess.getServiceEndpointList().getEndpoint()) {
                    final SMPEndpoint aEndpoint = new SMPEndpoint(aJAXBEndpoint.getTransportProfile(), aJAXBEndpoint.getEndpointURI(), BooleanHelper.getBooleanValue(aJAXBEndpoint.isRequireBusinessLevelSignature(), false), aJAXBEndpoint.getMinimumAuthenticationLevel(), aJAXBEndpoint.getServiceActivationDate(), aJAXBEndpoint.getServiceExpirationDate(), Base64.encodeBytes(aJAXBEndpoint.getCertificate()), aJAXBEndpoint.getServiceDescription(), aJAXBEndpoint.getTechnicalContactUrl(), aJAXBEndpoint.getTechnicalInformationUrl(), BDXR1ExtensionConverter.convertToString(aJAXBEndpoint.getExtension()));
                    aEndpoints.add(aEndpoint);
                }
                final SMPProcess aProcess = new SMPProcess(SimpleProcessIdentifier.wrap(aJAXBProcess.getProcessIdentifier()), aEndpoints, BDXR1ExtensionConverter.convertToString(aJAXBProcess.getExtension()));
                aProcesses.add(aProcess);
            }
            final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
            final String sExtensionXML = BDXR1ExtensionConverter.convertToString(aServiceInformation.getExtension());
            if (aServiceInfoMgr.mergeSMPServiceInformation(new SMPServiceInformation(aPathServiceGroup, aPathDocTypeID, aProcesses, sExtensionXML)).isFailure()) {
                if (LOGGER.isErrorEnabled())
                    LOGGER.error(sLog + " - ERROR - ServiceInformation");
                STATS_COUNTER_ERROR.increment(sAction);
                return ESuccess.FAILURE;
            }
            if (LOGGER.isInfoEnabled())
                LOGGER.info(sLog + " SUCCESS - ServiceInformation");
        } else {
            throw new SMPBadRequestException("Save Service Metadata was called with neither a Redirect nor a ServiceInformation", m_aAPIDataProvider.getCurrentURI());
        }
        if (false)
            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) ICommonsList(com.helger.commons.collection.impl.ICommonsList) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) ServiceInformationType(com.helger.xsds.bdxr.smp1.ServiceInformationType) X509Certificate(java.security.cert.X509Certificate) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ProcessType(com.helger.xsds.bdxr.smp1.ProcessType) EndpointType(com.helger.xsds.bdxr.smp1.EndpointType) IUser(com.helger.photon.security.user.IUser) ProcessListType(com.helger.xsds.bdxr.smp1.ProcessListType) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Example 68 with IDocumentTypeIdentifier

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

the class SMPServerAPI method deleteServiceRegistration.

public void deleteServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocTypeID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "DELETE /" + sPathServiceGroupID + "/services/" + sPathDocTypeID;
    final String sAction = "deleteServiceRegistration";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
        if (aPathServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
        }
        final IDocumentTypeIdentifier aPathDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sPathDocTypeID);
        if (aPathDocTypeID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseDocType(sPathDocTypeID, m_aAPIDataProvider.getCurrentURI());
        }
        final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
        SMPUserManagerPhoton.verifyOwnership(aPathServiceGroupID, aSMPUser);
        final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
        final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
        if (aServiceGroup == null) {
            throw new SMPNotFoundException("Service Group '" + sPathServiceGroupID + "' is not on this SMP", m_aAPIDataProvider.getCurrentURI());
        }
        final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
        final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aPathDocTypeID);
        if (aServiceInfo != null) {
            // Handle service information
            final EChange eChange = aServiceInfoMgr.deleteSMPServiceInformation(aServiceInfo);
            if (eChange.isUnchanged()) {
                // Most likely an internal error or an inconsistency
                throw new SMPNotFoundException("serviceInformation(" + aPathServiceGroupID.getURIEncoded() + ", " + aPathDocTypeID.getURIEncoded() + ")", m_aAPIDataProvider.getCurrentURI());
            }
            if (LOGGER.isInfoEnabled())
                LOGGER.info(sLog + " SUCCESS - ServiceInformation");
            STATS_COUNTER_SUCCESS.increment(sAction);
        } else {
            // No Service Info, so should be a redirect
            final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
            final ISMPRedirect aRedirect = aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aPathDocTypeID);
            if (aRedirect != null) {
                // Handle redirect
                final EChange eChange = aRedirectMgr.deleteSMPRedirect(aRedirect);
                if (eChange.isUnchanged()) {
                    // Most likely an internal error or an inconsistency
                    throw new SMPNotFoundException("redirect(" + aPathServiceGroupID.getURIEncoded() + ", " + aPathDocTypeID.getURIEncoded() + ")", m_aAPIDataProvider.getCurrentURI());
                }
                if (LOGGER.isInfoEnabled())
                    LOGGER.info(sLog + " SUCCESS - Redirect");
                STATS_COUNTER_SUCCESS.increment(sAction);
            } else {
                // Neither redirect nor endpoint found
                throw new SMPNotFoundException("service(" + sPathServiceGroupID + "," + sPathDocTypeID + ")", m_aAPIDataProvider.getCurrentURI());
            }
        }
    } 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) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) IUser(com.helger.photon.security.user.IUser) EChange(com.helger.commons.state.EChange) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException)

Example 69 with IDocumentTypeIdentifier

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

the class MainReadFromFileBDXR1 method main.

public static void main(final String[] args) throws Throwable {
    final SMPServerRESTTestRule aRule = new SMPServerRESTTestRule(ClassPathResource.getAsFile("test-smp-server-xml-bdxr1.properties").getAbsolutePath());
    aRule.before();
    try {
        final String sServerBasePath = aRule.getFullURL();
        final StopWatch aSWOverall = StopWatch.createdStarted();
        // These values must match the values in the test file
        final IParticipantIdentifier aParticipantID = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
        final IDocumentTypeIdentifier aDocTypeID = PeppolIdentifierFactory.INSTANCE.createDocumentTypeIdentifierWithDefaultScheme("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1");
        // Delete existing ServiceGroup (if exists)
        {
            final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path(aParticipantID.getURIEncoded()).queryParam("delete-in-sml", Boolean.FALSE).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).delete();
            _testResponseJerseyClient(aResponseMsg, 200, 404);
        }
        {
            // Create a new ServiceGroup
            final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path(aParticipantID.getURIEncoded()).queryParam("create-in-sml", Boolean.FALSE).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(new File("src/test/resources/rest-files/bdxr1-service-group.xml")));
            _testResponseJerseyClient(aResponseMsg, 200);
        }
        {
            // Add endpoint
            final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path(aParticipantID.getURIEncoded()).path("services").path(aDocTypeID.getURIEncoded()).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(new File("src/test/resources/rest-files/bdxr1-service-metadata.xml")));
            _testResponseJerseyClient(aResponseMsg, 200);
        }
        {
            // Add Business Card - no other format
            final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path("businesscard").path(aParticipantID.getURIEncoded()).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(new File("src/test/resources/rest-files/peppol-business-card-v3.xml")));
            _testResponseJerseyClient(aResponseMsg, 200);
        }
        aSWOverall.stop();
        LOGGER.info("Overall process took " + aSWOverall.getMillis() + " ms or " + aSWOverall.getDuration());
    } finally {
        aRule.after();
    }
}
Also used : Response(javax.ws.rs.core.Response) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) File(java.io.File) SMPServerRESTTestRule(com.helger.phoss.smp.mock.SMPServerRESTTestRule) StopWatch(com.helger.commons.timing.StopWatch) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 70 with IDocumentTypeIdentifier

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

the class ServiceMetadataInterfaceTest method testRemoveAllContentOfServiceGroup.

@Test
public void testRemoveAllContentOfServiceGroup() {
    // Lower case
    final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
    final String sPI_LC = aPI_LC.getURIEncoded();
    final IDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
    final String sDT = aDT.getURIEncoded();
    final ServiceGroupType aSG = new ServiceGroupType();
    aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
    aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
    final ServiceMetadataType aSM = new ServiceMetadataType();
    aSM.setRedirect(_createRedirect());
    final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPRedirectManager aSRMgr = SMPMetaManager.getRedirectMgr();
    final WebTarget aTarget = ClientBuilder.newClient().target(m_aRule.getFullURL());
    Response aResponseMsg;
    _testResponseJerseyClient(aTarget.path(sPI_LC).request().get(), 404);
    try {
        // PUT ServiceGroup
        aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // GET ServiceGroup
        assertNotNull(aTarget.path(sPI_LC).request().get(ServiceGroupType.class));
        final ISMPServiceGroup aServiceGroup = aSGMgr.getSMPServiceGroupOfID(aPI_LC);
        assertNotNull(aServiceGroup);
        try {
            // PUT 1 ServiceInformation
            aResponseMsg = _addCredentials(aTarget.path(sPI_LC).path("services").path(sDT).request()).put(Entity.xml(m_aObjFactory.createServiceMetadata(aSM)));
            _testResponseJerseyClient(aResponseMsg, 200);
            assertNotNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
            // DELETE 1 Redirect
            aResponseMsg = _addCredentials(aTarget.path(sPI_LC).path("services").request()).delete();
            _testResponseJerseyClient(aResponseMsg, 200);
            assertNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
        } finally {
            // DELETE 2 Redirect
            aResponseMsg = _addCredentials(aTarget.path(sPI_LC).path("services").request()).delete();
            _testResponseJerseyClient(aResponseMsg, 200, 404);
            assertNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
        }
        assertNotNull(aTarget.path(sPI_LC).request().get(ServiceGroupType.class));
    } finally {
        // DELETE ServiceGroup
        aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).delete();
        _testResponseJerseyClient(aResponseMsg, 200, 404);
        _testResponseJerseyClient(aTarget.path(sPI_LC).request().get(), 404);
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
    }
}
Also used : Response(javax.ws.rs.core.Response) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) WebTarget(javax.ws.rs.client.WebTarget) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) ServiceMetadataType(com.helger.xsds.peppol.smp1.ServiceMetadataType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

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