Search in sources :

Example 16 with ISMPRedirect

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;
}
Also used : SMPRedirect(com.helger.phoss.smp.domain.redirect.SMPRedirect) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) Nonnull(javax.annotation.Nonnull)

Example 17 with ISMPRedirect

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;
}
Also used : SMPRedirect(com.helger.phoss.smp.domain.redirect.SMPRedirect) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) Nonnull(javax.annotation.Nonnull)

Example 18 with ISMPRedirect

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;
}
Also used : RegistrationHookException(com.helger.phoss.smp.smlhook.RegistrationHookException) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) SMPSMLException(com.helger.phoss.smp.exception.SMPSMLException) IRegistrationHook(com.helger.phoss.smp.smlhook.IRegistrationHook) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup) Nonnull(javax.annotation.Nonnull)

Example 19 with ISMPRedirect

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);
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) IUser(com.helger.photon.security.user.IUser) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 20 with ISMPRedirect

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);
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) IUser(com.helger.photon.security.user.IUser) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Aggregations

ISMPRedirect (com.helger.phoss.smp.domain.redirect.ISMPRedirect)21 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)13 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)12 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)12 Nonnull (javax.annotation.Nonnull)11 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)8 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)8 SMPRedirect (com.helger.phoss.smp.domain.redirect.SMPRedirect)7 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)7 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)7 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)7 IUser (com.helger.photon.security.user.IUser)7 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)5 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)5 ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)4 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)3 DBResultRow (com.helger.db.jdbc.executor.DBResultRow)3 Test (org.junit.Test)3 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)2 EChange (com.helger.commons.state.EChange)2