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;
}
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);
}
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);
}
Aggregations