use of com.helger.phoss.smp.smlhook.IRegistrationHook in project phoss-smp by phax.
the class SMPServiceGroupManagerXML 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() + ", " + bDeleteInSML + ")");
final String sServiceGroupID = SMPServiceGroup.createSMPServiceGroupID(aParticipantID);
final SMPServiceGroup aSMPServiceGroup = getOfID(sServiceGroupID);
if (aSMPServiceGroup == null) {
AuditHelper.onAuditDeleteFailure(SMPServiceGroup.OT, aParticipantID, "no-such-id");
if (LOGGER.isDebugEnabled())
LOGGER.debug("deleteSMPServiceGroup - failure");
throw new SMPNotFoundException("No such service group '" + aParticipantID.getURIEncoded() + "'");
}
// Delete in SML - throws exception in case of error
final IRegistrationHook aHook = RegistrationHookFactory.getInstance();
if (bDeleteInSML)
try {
aHook.deleteServiceGroup(aParticipantID);
} catch (final RegistrationHookException ex) {
throw new SMPSMLException("Failed to delete '" + aParticipantID.getURIEncoded() + "' in SML", ex);
}
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
ICommonsList<ISMPRedirect> aOldRedirects = null;
ICommonsList<ISMPServiceInformation> aOldServiceInformation = null;
m_aRWLock.writeLock().lock();
try {
if (internalDeleteItem(aSMPServiceGroup.getID()) == null) {
AuditHelper.onAuditDeleteFailure(SMPServiceGroup.OT, aSMPServiceGroup.getID(), "no-such-id");
if (LOGGER.isDebugEnabled())
LOGGER.debug("deleteSMPServiceGroup - failure");
// Restore in SML again
if (bDeleteInSML) {
try {
aHook.undoDeleteServiceGroup(aParticipantID);
} catch (final RegistrationHookException ex2) {
LOGGER.error("Failed to undoDeleteServiceGroup (" + aParticipantID.getURIEncoded() + ")", ex2);
}
}
return EChange.UNCHANGED;
}
// Remember all redirects (in case of an error) and delete them
aOldRedirects = aRedirectMgr.getAllSMPRedirectsOfServiceGroup(aSMPServiceGroup);
aRedirectMgr.deleteAllSMPRedirectsOfServiceGroup(aSMPServiceGroup);
// Remember all service information (in case of an error) and delete them
aOldServiceInformation = aServiceInfoMgr.getAllSMPServiceInformationOfServiceGroup(aSMPServiceGroup);
aServiceInfoMgr.deleteAllSMPServiceInformationOfServiceGroup(aSMPServiceGroup);
} catch (final RuntimeException ex) {
// Try to rollback the actions
if (!containsWithID(aSMPServiceGroup.getID()))
internalCreateItem(aSMPServiceGroup);
// Restore redirects (if any)
if (aOldRedirects != null)
for (final ISMPRedirect aOldRedirect : aOldRedirects) {
// ignore return value - we cannot do anything anyway
aRedirectMgr.createOrUpdateSMPRedirect(aSMPServiceGroup, aOldRedirect.getDocumentTypeIdentifier(), aOldRedirect.getTargetHref(), aOldRedirect.getSubjectUniqueIdentifier(), aOldRedirect.getCertificate(), aOldRedirect.getExtensionsAsString());
}
// Restore service information (if any)
if (aOldServiceInformation != null)
for (final ISMPServiceInformation aOldServiceInfo : aOldServiceInformation) {
// ignore return value - we cannot do anything anyway
aServiceInfoMgr.mergeSMPServiceInformation(aOldServiceInfo);
}
// An error occurred - restore in SML again
try {
aHook.undoDeleteServiceGroup(aParticipantID);
} catch (final RegistrationHookException ex2) {
LOGGER.error("Failed to undoDeleteServiceGroup (" + aParticipantID.getURIEncoded() + ")", ex2);
}
throw ex;
} finally {
m_aRWLock.writeLock().unlock();
}
AuditHelper.onAuditDeleteSuccess(SMPServiceGroup.OT, aSMPServiceGroup.getID(), Boolean.valueOf(bDeleteInSML));
if (LOGGER.isDebugEnabled())
LOGGER.debug("deleteSMPServiceGroup - success");
m_aCBs.forEach(x -> x.onSMPServiceGroupDeleted(aParticipantID, bDeleteInSML));
return EChange.CHANGED;
}
Aggregations