Search in sources :

Example 61 with IDocumentTypeIdentifier

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

the class SMPServerAPI 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.getAsJAXBObjectPeppol();
        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.getAsJAXBObjectPeppol();
            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.peppol.smp1.CompleteServiceGroupType) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.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.peppol.smp1.ServiceMetadataReferenceType) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) CompleteServiceGroupType(com.helger.xsds.peppol.smp1.CompleteServiceGroupType) SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) ServiceMetadataType(com.helger.xsds.peppol.smp1.ServiceMetadataType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Example 62 with IDocumentTypeIdentifier

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

the class SMPServerAPI 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 Peppol mode
            final X509Certificate aCertificate = null;
            if (aRedirectMgr.createOrUpdateSMPRedirect(aPathServiceGroup, aPathDocTypeID, aServiceMetadata.getRedirect().getHref(), aServiceMetadata.getRedirect().getCertificateUID(), aCertificate, SMPExtensionConverter.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(), W3CEndpointReferenceHelper.getAddress(aJAXBEndpoint.getEndpointReference()), aJAXBEndpoint.isRequireBusinessLevelSignature(), aJAXBEndpoint.getMinimumAuthenticationLevel(), aJAXBEndpoint.getServiceActivationDate(), aJAXBEndpoint.getServiceExpirationDate(), aJAXBEndpoint.getCertificate(), aJAXBEndpoint.getServiceDescription(), aJAXBEndpoint.getTechnicalContactUrl(), aJAXBEndpoint.getTechnicalInformationUrl(), SMPExtensionConverter.convertToString(aJAXBEndpoint.getExtension()));
                    aEndpoints.add(aEndpoint);
                }
                final SMPProcess aProcess = new SMPProcess(SimpleProcessIdentifier.wrap(aJAXBProcess.getProcessIdentifier()), aEndpoints, SMPExtensionConverter.convertToString(aJAXBProcess.getExtension()));
                aProcesses.add(aProcess);
            }
            final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
            final String sExtensionXML = SMPExtensionConverter.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.peppol.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.peppol.smp1.ProcessType) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) IUser(com.helger.photon.security.user.IUser) ProcessListType(com.helger.xsds.peppol.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 63 with IDocumentTypeIdentifier

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

the class SMPServerAPI method getServiceGroup.

@Nonnull
public ServiceGroupType getServiceGroup(final String sPathServiceGroupID) throws SMPServerException {
    final String sLog = LOG_PREFIX + "GET /" + sPathServiceGroupID;
    final String sAction = "getServiceGroup";
    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();
        // Retrieve the service group
        final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
        if (aServiceGroup == null) {
            // No such service group
            throw new SMPNotFoundException("Unknown Service Group '" + sPathServiceGroupID + "'", m_aAPIDataProvider.getCurrentURI());
        }
        // Then add the service metadata references
        final ServiceGroupType aSG = aServiceGroup.getAsJAXBObjectPeppol();
        final ServiceMetadataReferenceCollectionType aCollectionType = 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));
                aCollectionType.addServiceMetadataReference(aMetadataReference);
            }
        }
        aSG.setServiceMetadataReferenceCollection(aCollectionType);
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return aSG;
    } 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) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.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.peppol.smp1.ServiceMetadataReferenceType) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) CompleteServiceGroupType(com.helger.xsds.peppol.smp1.CompleteServiceGroupType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Example 64 with IDocumentTypeIdentifier

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

the class BDXR1ServerAPI method getServiceGroup.

@Nonnull
public ServiceGroupType getServiceGroup(final String sPathServiceGroupID) throws SMPServerException {
    final String sLog = LOG_PREFIX + "GET /" + sPathServiceGroupID;
    final String sAction = "getServiceGroup";
    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();
        // Retrieve the service group
        final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
        if (aServiceGroup == null) {
            // No such service group
            throw new SMPNotFoundException("Unknown Service Group '" + sPathServiceGroupID + "'", m_aAPIDataProvider.getCurrentURI());
        }
        // Then add the service metadata references
        final ServiceGroupType aSG = aServiceGroup.getAsJAXBObjectBDXR1();
        final ServiceMetadataReferenceCollectionType aCollectionType = 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));
                aCollectionType.addServiceMetadataReference(aMetadataReference);
            }
        }
        aSG.setServiceMetadataReferenceCollection(aCollectionType);
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return aSG;
    } 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) 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) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Example 65 with IDocumentTypeIdentifier

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

the class BDXR1ServerAPI 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)

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