Search in sources :

Example 6 with SMPInternalErrorException

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

the class SMPServiceGroupManagerJDBC method deleteSMPServiceGroup.

@Nonnull
public EChange deleteSMPServiceGroup(@Nonnull final IParticipantIdentifier aParticipantID, final boolean bDeleteInSML) throws SMPServerException {
    ValueEnforcer.notNull(aParticipantID, "ParticipantID");
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("deleteSMPServiceGroup (" + aParticipantID.getURIEncoded() + ")");
    final IRegistrationHook aHook = RegistrationHookFactory.getInstance();
    final MutableBoolean aDeletedServiceGroupInSML = new MutableBoolean(false);
    final Wrapper<EChange> aWrappedChange = new Wrapper<>(EChange.UNCHANGED);
    final Wrapper<Exception> aCaughtException = new Wrapper<>();
    final DBExecutor aExecutor = newExecutor();
    final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
        // Check if the passed service group ID is already in use
        final SMPServiceGroup aDBServiceGroup = getSMPServiceGroupOfID(aParticipantID);
        if (aDBServiceGroup == null)
            throw new SMPNotFoundException("The service group with ID " + aParticipantID.getURIEncoded() + " does not exist!");
        if (bDeleteInSML) {
            // Delete in SML - and remember that
            // throws exception in case of error
            aHook.deleteServiceGroup(aParticipantID);
            aDeletedServiceGroupInSML.set(true);
        }
        final long nCount = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_service_group" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue()));
        if (nCount != 1)
            throw new IllegalStateException("Failed to delete service group");
        aWrappedChange.set(EChange.CHANGED);
    }, aCaughtException::set);
    if (eSuccess.isFailure()) {
        // Error writing to the DB
        if (bDeleteInSML && aDeletedServiceGroupInSML.booleanValue()) {
            // Undo deletion in SML!
            try {
                aHook.undoDeleteServiceGroup(aParticipantID);
            } catch (final RegistrationHookException ex) {
                LOGGER.error("Failed to undoDeleteServiceGroup (" + aParticipantID.getURIEncoded() + ")", ex);
            }
        }
    }
    if (aCaughtException.isSet()) {
        AuditHelper.onAuditDeleteFailure(SMPServiceGroup.OT, aParticipantID.getURIEncoded(), "database-error");
        final Exception ex = aCaughtException.get();
        if (ex instanceof SMPServerException)
            throw (SMPServerException) ex;
        if (ex instanceof RegistrationHookException)
            throw new SMPSMLException("Failed to delete '" + aParticipantID.getURIEncoded() + "' in SML", ex);
        throw new SMPInternalErrorException("Failed to delete ServiceGroup '" + aParticipantID.getURIEncoded() + "'", ex);
    }
    final EChange eChange = aWrappedChange.get();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("deleteSMPServiceGroup succeeded. Change=" + eChange.isChanged());
    if (eChange.isChanged()) {
        AuditHelper.onAuditDeleteSuccess(SMPServiceGroup.OT, aParticipantID.getURIEncoded());
        if (m_aCache != null)
            m_aCache.remove(aParticipantID.getURIEncoded());
        m_aCBs.forEach(x -> x.onSMPServiceGroupDeleted(aParticipantID, bDeleteInSML));
    }
    return eChange;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) Wrapper(com.helger.commons.wrapper.Wrapper) RegistrationHookException(com.helger.phoss.smp.smlhook.RegistrationHookException) MutableBoolean(com.helger.commons.mutable.MutableBoolean) SMPInternalErrorException(com.helger.phoss.smp.exception.SMPInternalErrorException) SMPSMLException(com.helger.phoss.smp.exception.SMPSMLException) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) RegistrationHookException(com.helger.phoss.smp.smlhook.RegistrationHookException) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) SMPSMLException(com.helger.phoss.smp.exception.SMPSMLException) IRegistrationHook(com.helger.phoss.smp.smlhook.IRegistrationHook) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) SMPInternalErrorException(com.helger.phoss.smp.exception.SMPInternalErrorException) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) EChange(com.helger.commons.state.EChange) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Example 7 with SMPInternalErrorException

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

the class APIExecutorServiceGroupGet method invokeAPI.

public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
    final String sPathServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
    final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sPathServiceGroupID);
    final byte[] aBytes;
    switch(SMPServerConfiguration.getRESTType()) {
        case PEPPOL:
            {
                final com.helger.xsds.peppol.smp1.ServiceGroupType ret = new SMPServerAPI(aDataProvider).getServiceGroup(sPathServiceGroupID);
                aBytes = new SMPMarshallerServiceGroupType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
                break;
            }
        case OASIS_BDXR_V1:
            {
                final com.helger.xsds.bdxr.smp1.ServiceGroupType ret = new BDXR1ServerAPI(aDataProvider).getServiceGroup(sPathServiceGroupID);
                aBytes = new BDXR1MarshallerServiceGroupType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
                break;
            }
        default:
            throw new UnsupportedOperationException("Unsupported REST type specified!");
    }
    if (aBytes == null) {
        // Internal error serializing the payload
        throw new SMPInternalErrorException("Failed to convert the returned ServiceGroup to XML");
    }
    aUnifiedResponse.setContent(aBytes).setMimeType(CMimeType.TEXT_XML).setCharset(XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
}
Also used : SMPServerAPI(com.helger.phoss.smp.restapi.SMPServerAPI) BDXR1MarshallerServiceGroupType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType) SMPMarshallerServiceGroupType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupType) BDXR1ServerAPI(com.helger.phoss.smp.restapi.BDXR1ServerAPI) SMPInternalErrorException(com.helger.phoss.smp.exception.SMPInternalErrorException) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) SMPMarshallerServiceGroupType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupType) BDXR1MarshallerServiceGroupType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupType)

Example 8 with SMPInternalErrorException

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

the class APIExecutorUserListGet method invokeAPI.

public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
    final String sPathUserID = aPathVariables.get(SMPRestFilter.PARAM_USER_ID);
    // No service group available
    final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, null);
    final BasicAuthClientCredentials aCredentials = getMandatoryAuth(aRequestScope.headers());
    final byte[] aBytes;
    switch(SMPServerConfiguration.getRESTType()) {
        case PEPPOL:
            {
                // Unspecified extension
                final com.helger.xsds.peppol.smp1.ServiceGroupReferenceListType ret = new SMPServerAPI(aDataProvider).getServiceGroupReferenceList(sPathUserID, aCredentials);
                aBytes = new SMPMarshallerServiceGroupReferenceListType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
                break;
            }
        case OASIS_BDXR_V1:
            {
                // Unspecified extension
                final com.helger.xsds.bdxr.smp1.ServiceGroupReferenceListType ret = new BDXR1ServerAPI(aDataProvider).getServiceGroupReferenceList(sPathUserID, aCredentials);
                aBytes = new BDXR1MarshallerServiceGroupReferenceListType(XML_SCHEMA_VALIDATION).getAsBytes(ret);
                break;
            }
        default:
            throw new UnsupportedOperationException("Unsupported REST type specified!");
    }
    if (aBytes == null) {
        // Internal error serializing the payload
        throw new SMPInternalErrorException("Failed to convert the returned CompleteServiceGroup to XML");
    }
    aUnifiedResponse.setContent(aBytes).setMimeType(CMimeType.TEXT_XML);
}
Also used : SMPServerAPI(com.helger.phoss.smp.restapi.SMPServerAPI) SMPMarshallerServiceGroupReferenceListType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupReferenceListType) BDXR1MarshallerServiceGroupReferenceListType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupReferenceListType) SMPMarshallerServiceGroupReferenceListType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceGroupReferenceListType) BDXR1ServerAPI(com.helger.phoss.smp.restapi.BDXR1ServerAPI) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPInternalErrorException(com.helger.phoss.smp.exception.SMPInternalErrorException) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) BDXR1MarshallerServiceGroupReferenceListType(com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerServiceGroupReferenceListType)

Aggregations

SMPInternalErrorException (com.helger.phoss.smp.exception.SMPInternalErrorException)8 ISMPServerAPIDataProvider (com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider)5 SMPSMLException (com.helger.phoss.smp.exception.SMPSMLException)4 BDXR1ServerAPI (com.helger.phoss.smp.restapi.BDXR1ServerAPI)4 SMPServerAPI (com.helger.phoss.smp.restapi.SMPServerAPI)4 MutableBoolean (com.helger.commons.mutable.MutableBoolean)3 ESuccess (com.helger.commons.state.ESuccess)3 Wrapper (com.helger.commons.wrapper.Wrapper)3 ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)3 DBExecutor (com.helger.db.jdbc.executor.DBExecutor)3 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)3 SMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup)3 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)3 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)3 IRegistrationHook (com.helger.phoss.smp.smlhook.IRegistrationHook)3 RegistrationHookException (com.helger.phoss.smp.smlhook.RegistrationHookException)3 EChange (com.helger.commons.state.EChange)2 BasicAuthClientCredentials (com.helger.http.basicauth.BasicAuthClientCredentials)2 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)2 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)2