Search in sources :

Example 21 with SMPServerException

use of com.helger.phoss.smp.exception.SMPServerException in project phoss-smp by phax.

the class BusinessCardServerAPI method deleteBusinessCard.

/**
 * Delete an existing business card.
 *
 * @param sServiceGroupID
 *        The service group (participant) ID.
 * @param aCredentials
 *        The credentials to be used. May not be <code>null</code>.
 * @throws SMPServerException
 *         In case of error
 * @since 5.0.2
 */
public void deleteBusinessCard(@Nonnull final String sServiceGroupID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "DELETE /businesscard/" + sServiceGroupID;
    final String sAction = "deleteBusinessCard";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
        if (aServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sServiceGroupID, m_aAPIProvider.getCurrentURI());
        }
        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 Business Card API", m_aAPIProvider.getCurrentURI());
        }
        final ISMPBusinessCard aBusinessCard = aBusinessCardMgr.getSMPBusinessCardOfID(aServiceGroupID);
        if (aBusinessCard == null) {
            // No such business card
            throw new SMPNotFoundException("No Business Card assigned to Service Group '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
        }
        aBusinessCardMgr.deleteSMPBusinessCard(aBusinessCard);
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
    } catch (final SMPServerException ex) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
        STATS_COUNTER_ERROR.increment(sAction);
        throw ex;
    }
}
Also used : ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) IUser(com.helger.photon.security.user.IUser) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException)

Example 22 with SMPServerException

use of com.helger.phoss.smp.exception.SMPServerException in project phoss-smp by phax.

the class BusinessCardServerAPI method getBusinessCard.

@Nonnull
public PD3BusinessCardType getBusinessCard(final String sServiceGroupID) throws SMPServerException {
    final String sLog = LOG_PREFIX + "GET /businesscard/" + sServiceGroupID;
    final String sAction = "getBusinessCard";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
        if (aServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sServiceGroupID, m_aAPIProvider.getCurrentURI());
        }
        final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
        final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aServiceGroupID);
        if (aServiceGroup == null) {
            // No such service group
            throw new SMPNotFoundException("Unknown Service Group '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
        }
        final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
        if (aBusinessCardMgr == null) {
            throw new SMPBadRequestException("This SMP server does not support the Business Card API", m_aAPIProvider.getCurrentURI());
        }
        final ISMPBusinessCard aBusinessCard = aBusinessCardMgr.getSMPBusinessCardOfServiceGroup(aServiceGroup);
        if (aBusinessCard == null) {
            // No such business card
            throw new SMPNotFoundException("No Business Card assigned to Service Group '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
        }
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return aBusinessCard.getAsJAXBObject();
    } catch (final SMPServerException ex) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
        STATS_COUNTER_ERROR.increment(sAction);
        throw ex;
    }
}
Also used : ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Example 23 with SMPServerException

use of com.helger.phoss.smp.exception.SMPServerException in project phoss-smp by phax.

the class SMPServerAPI method saveServiceGroup.

public void saveServiceGroup(@Nonnull final String sPathServiceGroupID, @Nonnull final ServiceGroupType aServiceGroup, final boolean bCreateInSML, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "PUT /" + sPathServiceGroupID + (bCreateInSML ? "" : CSMPServer.LOG_SUFFIX_NO_SML_INTERACTION);
    final String sAction = "saveServiceGroup";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog + " ==> " + aServiceGroup);
    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());
        }
        // Parse the content of the payload with the same identifier factory to
        // ensure same case sensitivity
        final IParticipantIdentifier aPayloadServiceGroupID;
        if (aServiceGroup.getParticipantIdentifier() == null) {
            // Can happen when tampering with the input data
            aPayloadServiceGroupID = null;
        } else {
            aPayloadServiceGroupID = aIdentifierFactory.createParticipantIdentifier(aServiceGroup.getParticipantIdentifier().getScheme(), aServiceGroup.getParticipantIdentifier().getValue());
        }
        if (!aPathServiceGroupID.hasSameContent(aPayloadServiceGroupID)) {
            // Business identifiers must be equal
            throw new SMPBadRequestException("Service Group Inconsistency. The URL points to '" + aPathServiceGroupID.getURIEncoded() + "' whereas the Service Group contains " + (aPayloadServiceGroupID == null ? "<none>" : "'" + aPayloadServiceGroupID.getURIEncoded() + "'"), m_aAPIDataProvider.getCurrentURI());
        }
        final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
        final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
        final String sExtension = SMPExtensionConverter.convertToString(aServiceGroup.getExtension());
        if (aServiceGroupMgr.containsSMPServiceGroupWithID(aPathServiceGroupID))
            aServiceGroupMgr.updateSMPServiceGroup(aPathServiceGroupID, aSMPUser.getID(), sExtension);
        else
            aServiceGroupMgr.createSMPServiceGroup(aSMPUser.getID(), aPathServiceGroupID, sExtension, bCreateInSML);
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
    } 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) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) IUser(com.helger.photon.security.user.IUser) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException)

Example 24 with SMPServerException

use of com.helger.phoss.smp.exception.SMPServerException 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 25 with SMPServerException

use of com.helger.phoss.smp.exception.SMPServerException in project phoss-smp by phax.

the class SMPServerAPI method deleteServiceRegistrations.

public void deleteServiceRegistrations(@Nonnull final String sPathServiceGroupID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "DELETE /" + sPathServiceGroupID + "/services/";
    final String sAction = "deleteServiceRegistrations";
    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 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();
        EChange eChange = aServiceInfoMgr.deleteAllSMPServiceInformationOfServiceGroup(aServiceGroup);
        final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
        eChange = eChange.or(aRedirectMgr.deleteAllSMPRedirectsOfServiceGroup(aServiceGroup));
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS - " + eChange);
        STATS_COUNTER_SUCCESS.increment(sAction);
    } 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) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) 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

SMPServerException (com.helger.phoss.smp.exception.SMPServerException)28 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)24 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)23 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)22 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)22 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)18 Nonnull (javax.annotation.Nonnull)18 IUser (com.helger.photon.security.user.IUser)17 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)13 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)11 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)10 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)9 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)9 EChange (com.helger.commons.state.EChange)8 ISMPRedirect (com.helger.phoss.smp.domain.redirect.ISMPRedirect)5 ICommonsList (com.helger.commons.collection.impl.ICommonsList)4 ISMPBusinessCardManager (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager)4 RegistrationHookException (com.helger.phoss.smp.smlhook.RegistrationHookException)4 MutableBoolean (com.helger.commons.mutable.MutableBoolean)3 ESuccess (com.helger.commons.state.ESuccess)3