Search in sources :

Example 26 with EChange

use of com.helger.commons.state.EChange in project phase4 by phax.

the class PModeManagerInMemory method updatePMode.

@Nonnull
public EChange updatePMode(@Nonnull final IPMode aNewPMode) {
    ValueEnforcer.notNull(aNewPMode, "PMode");
    _validatePMode(aNewPMode);
    final PMode aExistingPMode = getOfID(aNewPMode.getID());
    if (aExistingPMode == null || aExistingPMode.isDeleted())
        return EChange.UNCHANGED;
    m_aRWLock.writeLock().lock();
    try {
        EChange eChange = EChange.UNCHANGED;
        eChange = eChange.or(aExistingPMode.setInitiator(aNewPMode.getInitiator()));
        eChange = eChange.or(aExistingPMode.setResponder(aNewPMode.getResponder()));
        eChange = eChange.or(aExistingPMode.setAgreement(aNewPMode.getAgreement()));
        eChange = eChange.or(aExistingPMode.setMEP(aNewPMode.getMEP()));
        eChange = eChange.or(aExistingPMode.setMEPBinding(aNewPMode.getMEPBinding()));
        eChange = eChange.or(aExistingPMode.setLeg1(aNewPMode.getLeg1()));
        eChange = eChange.or(aExistingPMode.setLeg2(aNewPMode.getLeg2()));
        eChange = eChange.or(aExistingPMode.setPayloadService(aNewPMode.getPayloadService()));
        eChange = eChange.or(aExistingPMode.setReceptionAwareness(aNewPMode.getReceptionAwareness()));
        if (eChange.isUnchanged())
            return EChange.UNCHANGED;
        BusinessObjectHelper.setLastModificationNow(aExistingPMode);
    } finally {
        m_aRWLock.writeLock().unlock();
    }
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Updated PMode with ID '" + aNewPMode.getID() + "'");
    return EChange.CHANGED;
}
Also used : EChange(com.helger.commons.state.EChange) Nonnull(javax.annotation.Nonnull)

Example 27 with EChange

use of com.helger.commons.state.EChange in project phoss-smp by phax.

the class SMPServerAPI method deleteServiceGroup.

@Nonnull
public EChange deleteServiceGroup(@Nonnull final String sPathServiceGroupID, final boolean bDeleteInSML, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "DELETE /" + sPathServiceGroupID + (bDeleteInSML ? "" : CSMPServer.LOG_SUFFIX_NO_SML_INTERACTION);
    final String sAction = "deleteServiceGroup";
    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 EChange eDeleted = aServiceGroupMgr.deleteSMPServiceGroup(aPathServiceGroupID, bDeleteInSML);
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return eDeleted;
    } 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) 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) Nonnull(javax.annotation.Nonnull)

Example 28 with EChange

use of com.helger.commons.state.EChange 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)

Example 29 with EChange

use of com.helger.commons.state.EChange in project phoss-smp by phax.

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

Example 30 with EChange

use of com.helger.commons.state.EChange 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)

Aggregations

EChange (com.helger.commons.state.EChange)50 Nonnull (javax.annotation.Nonnull)42 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)9 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)9 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)9 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)7 CommonsHashMap (com.helger.commons.collection.impl.CommonsHashMap)6 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)6 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)6 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)6 ESuccess (com.helger.commons.state.ESuccess)5 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)5 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)5 IUser (com.helger.photon.security.user.IUser)5 Map (java.util.Map)5 ReturnsMutableObject (com.helger.commons.annotation.ReturnsMutableObject)4 CallbackList (com.helger.commons.callback.CallbackList)4 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)4 ICommonsList (com.helger.commons.collection.impl.ICommonsList)4 MutableBoolean (com.helger.commons.mutable.MutableBoolean)4