use of com.helger.phoss.smp.domain.redirect.ISMPRedirect in project phoss-smp by phax.
the class SMPRedirectManagerXML method deleteSMPRedirect.
@Nonnull
public EChange deleteSMPRedirect(@Nullable final ISMPRedirect aSMPRedirect) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("deleteSMPRedirect (" + aSMPRedirect + ")");
if (aSMPRedirect == null) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("deleteSMPRedirect - failure");
return EChange.UNCHANGED;
}
m_aRWLock.writeLock().lock();
try {
final SMPRedirect aRealRedirect = internalDeleteItem(aSMPRedirect.getID());
if (aRealRedirect == null) {
AuditHelper.onAuditDeleteFailure(SMPRedirect.OT, aSMPRedirect.getID(), "no-such-id");
if (LOGGER.isDebugEnabled())
LOGGER.debug("deleteSMPRedirect - failure");
return EChange.UNCHANGED;
}
} finally {
m_aRWLock.writeLock().unlock();
}
m_aCallbacks.forEach(x -> x.onSMPRedirectDeleted(aSMPRedirect));
AuditHelper.onAuditDeleteSuccess(SMPRedirect.OT, aSMPRedirect.getID(), aSMPRedirect.getServiceGroupID(), aSMPRedirect.getDocumentTypeIdentifier().getURIEncoded());
if (LOGGER.isDebugEnabled())
LOGGER.debug("deleteSMPRedirect - success");
return EChange.CHANGED;
}
use of com.helger.phoss.smp.domain.redirect.ISMPRedirect in project phoss-smp by phax.
the class SMPRedirectManagerXML method createOrUpdateSMPRedirect.
@Nonnull
public ISMPRedirect createOrUpdateSMPRedirect(@Nonnull final ISMPServiceGroup aServiceGroup, @Nonnull final IDocumentTypeIdentifier aDocumentTypeIdentifier, @Nonnull @Nonempty final String sTargetHref, @Nonnull @Nonempty final String sSubjectUniqueIdentifier, @Nullable final X509Certificate aCertificate, @Nullable final String sExtension) {
ValueEnforcer.notNull(aServiceGroup, "ServiceGroup");
ValueEnforcer.notNull(aDocumentTypeIdentifier, "DocumentTypeIdentifier");
if (LOGGER.isDebugEnabled())
LOGGER.debug("createOrUpdateSMPRedirect (" + aServiceGroup + ", " + aDocumentTypeIdentifier + ", " + sTargetHref + ", " + sSubjectUniqueIdentifier + ", " + aCertificate + ", " + (StringHelper.hasText(sExtension) ? "with extension" : "without extension") + ")");
final ISMPRedirect aOldRedirect = getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDocumentTypeIdentifier);
SMPRedirect aNewRedirect;
if (aOldRedirect == null) {
// Create new ID
aNewRedirect = new SMPRedirect(aServiceGroup, aDocumentTypeIdentifier, sTargetHref, sSubjectUniqueIdentifier, aCertificate, sExtension);
_createSMPRedirect(aNewRedirect);
if (LOGGER.isDebugEnabled())
LOGGER.debug("createOrUpdateSMPRedirect - success - created");
m_aCallbacks.forEach(x -> x.onSMPRedirectCreated(aNewRedirect));
} else {
// Reuse old ID
aNewRedirect = new SMPRedirect(aServiceGroup, aDocumentTypeIdentifier, sTargetHref, sSubjectUniqueIdentifier, aCertificate, sExtension);
_updateSMPRedirect(aNewRedirect);
if (LOGGER.isDebugEnabled())
LOGGER.debug("createOrUpdateSMPRedirect - success - updated");
m_aCallbacks.forEach(x -> x.onSMPRedirectUpdated(aNewRedirect));
}
return aNewRedirect;
}
use of com.helger.phoss.smp.domain.redirect.ISMPRedirect 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;
}
use of com.helger.phoss.smp.domain.redirect.ISMPRedirect in project phoss-smp by phax.
the class SMPRedirectManagerXMLTest method testRedirectBasic.
@Test
public void testRedirectBasic() throws SMPServerException {
// Ensure the user is present
final IUser aTestUser = PhotonSecurityManager.getUserMgr().getUserOfID(CSecurity.USER_ADMINISTRATOR_ID);
assertNotNull(aTestUser);
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
assertEquals(0, aRedirectMgr.getSMPRedirectCount());
// Delete existing service group
final IParticipantIdentifier aPI = aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:dummy");
aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI, true);
final ISMPServiceGroup aSG = aServiceGroupMgr.createSMPServiceGroup(aTestUser.getID(), aPI, null, true);
assertNotNull(aSG);
try {
final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "doctype4711");
final ISMPRedirect aRedirect = aRedirectMgr.createOrUpdateSMPRedirect(aSG, aDocTypeID, "bla", "foo", null, "<ext/>");
assertNotNull(aRedirect);
assertSame(aSG, aRedirect.getServiceGroup());
assertEquals(aDocTypeID, aRedirect.getDocumentTypeIdentifier());
assertEquals("bla", aRedirect.getTargetHref());
assertEquals("foo", aRedirect.getSubjectUniqueIdentifier());
assertNull(aRedirect.getCertificate());
assertEquals("<ext />", aRedirect.getFirstExtensionXML().trim());
XMLTestHelper.testMicroTypeConversion(aRedirect);
} finally {
aServiceGroupMgr.deleteSMPServiceGroup(aPI, true);
}
}
use of com.helger.phoss.smp.domain.redirect.ISMPRedirect in project phoss-smp by phax.
the class SMPRedirectManagerXMLTest method testRedirectUpperCaseSG.
@Test
public void testRedirectUpperCaseSG() throws SMPServerException {
// Ensure the user is present
final IUser aTestUser = PhotonSecurityManager.getUserMgr().getUserOfID(CSecurity.USER_ADMINISTRATOR_ID);
assertNotNull(aTestUser);
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
assertFalse(aIdentifierFactory.isParticipantIdentifierCaseInsensitive("bla-sch-eme"));
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
assertEquals(0, aRedirectMgr.getSMPRedirectCount());
// Delete existing service group
final IParticipantIdentifier aPI = aIdentifierFactory.createParticipantIdentifier("bla-sch-eme", "0088:UpperCase");
assertNotNull(aPI);
aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI, true);
final ISMPServiceGroup aSG = aServiceGroupMgr.createSMPServiceGroup(aTestUser.getID(), aPI, null, true);
assertNotNull(aSG);
try {
final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "DocType4711");
final ISMPRedirect aRedirect = aRedirectMgr.createOrUpdateSMPRedirect(aSG, aDocTypeID, "bla", "foo", null, "<ext/>");
assertNotNull(aRedirect);
assertSame(aSG, aRedirect.getServiceGroup());
assertEquals(aDocTypeID, aRedirect.getDocumentTypeIdentifier());
assertEquals("bla", aRedirect.getTargetHref());
assertEquals("foo", aRedirect.getSubjectUniqueIdentifier());
assertNull(aRedirect.getCertificate());
assertEquals("<ext />", aRedirect.getFirstExtensionXML().trim());
XMLTestHelper.testMicroTypeConversion(aRedirect);
} finally {
aServiceGroupMgr.deleteSMPServiceGroup(aPI, true);
}
}
Aggregations