Search in sources :

Example 26 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.

the class SMPServiceInformationManagerXML method deleteSMPServiceInformation.

@Nonnull
public EChange deleteSMPServiceInformation(@Nullable final ISMPServiceInformation aSMPServiceInformation) {
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("deleteSMPServiceInformation (" + aSMPServiceInformation + ")");
    if (aSMPServiceInformation == null) {
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("deleteSMPServiceInformation - failure");
        return EChange.UNCHANGED;
    }
    m_aRWLock.writeLock().lock();
    try {
        final SMPServiceInformation aRealServiceInformation = internalDeleteItem(aSMPServiceInformation.getID());
        if (aRealServiceInformation == null) {
            AuditHelper.onAuditDeleteFailure(SMPServiceInformation.OT, aSMPServiceInformation.getID(), "no-such-id");
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("deleteSMPServiceInformation - failure");
            return EChange.UNCHANGED;
        }
    } finally {
        m_aRWLock.writeLock().unlock();
    }
    AuditHelper.onAuditDeleteSuccess(SMPServiceInformation.OT, aSMPServiceInformation.getID());
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("deleteSMPServiceInformation - success");
    m_aCBs.forEach(x -> x.onSMPServiceInformationDeleted(aSMPServiceInformation));
    return EChange.CHANGED;
}
Also used : SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) Nonnull(javax.annotation.Nonnull)

Example 27 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.

the class SMPServiceInformationManagerXML method mergeSMPServiceInformation.

@Nonnull
public ESuccess mergeSMPServiceInformation(@Nonnull final ISMPServiceInformation aSMPServiceInformationObj) {
    final SMPServiceInformation aSMPServiceInformation = (SMPServiceInformation) aSMPServiceInformationObj;
    ValueEnforcer.notNull(aSMPServiceInformation, "ServiceInformation");
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("mergeSMPServiceInformation (" + aSMPServiceInformationObj + ")");
    // Check for an update
    boolean bChangeExisting = false;
    final SMPServiceInformation aOldInformation = (SMPServiceInformation) getSMPServiceInformationOfServiceGroupAndDocumentType(aSMPServiceInformation.getServiceGroup(), aSMPServiceInformation.getDocumentTypeIdentifier());
    if (aOldInformation != null) {
        // This is not true for the REST API
        if (EqualsHelper.identityEqual(aOldInformation, aSMPServiceInformation))
            bChangeExisting = true;
    }
    if (bChangeExisting) {
        // Edit existing
        m_aRWLock.writeLocked(() -> {
            internalUpdateItem(aOldInformation);
        });
        AuditHelper.onAuditModifySuccess(SMPServiceInformation.OT, "set-all", aOldInformation.getID(), aOldInformation.getServiceGroupID(), aOldInformation.getDocumentTypeIdentifier().getURIEncoded(), aOldInformation.getAllProcesses(), aOldInformation.getExtensionsAsString());
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("mergeSMPServiceInformation - success - updated");
        m_aCBs.forEach(x -> x.onSMPServiceInformationUpdated(aSMPServiceInformation));
    } else {
        // (Optionally delete the old one and) create the new one
        boolean bRemovedOld = false;
        m_aRWLock.writeLock().lock();
        try {
            if (aOldInformation != null) {
                // Delete only if present
                final SMPServiceInformation aDeletedInformation = internalDeleteItem(aOldInformation.getID());
                bRemovedOld = EqualsHelper.identityEqual(aDeletedInformation, aOldInformation);
            }
            internalCreateItem(aSMPServiceInformation);
        } finally {
            m_aRWLock.writeLock().unlock();
        }
        if (bRemovedOld) {
            AuditHelper.onAuditDeleteSuccess(SMPServiceInformation.OT, aOldInformation.getID(), aOldInformation.getServiceGroupID(), aOldInformation.getDocumentTypeIdentifier().getURIEncoded());
        } else if (aOldInformation != null) {
            AuditHelper.onAuditDeleteFailure(SMPServiceInformation.OT, aOldInformation.getID(), aOldInformation.getServiceGroupID(), aOldInformation.getDocumentTypeIdentifier().getURIEncoded());
        }
        AuditHelper.onAuditCreateSuccess(SMPServiceInformation.OT, aSMPServiceInformation.getID(), aSMPServiceInformation.getServiceGroupID(), aSMPServiceInformation.getDocumentTypeIdentifier().getURIEncoded(), aSMPServiceInformation.getAllProcesses(), aSMPServiceInformation.getExtensionsAsString());
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("mergeSMPServiceInformation - success - created");
        if (aOldInformation != null)
            m_aCBs.forEach(x -> x.onSMPServiceInformationUpdated(aSMPServiceInformation));
        else
            m_aCBs.forEach(x -> x.onSMPServiceInformationCreated(aSMPServiceInformation));
    }
    return ESuccess.SUCCESS;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) Nonnegative(javax.annotation.Nonnegative) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) LoggerFactory(org.slf4j.LoggerFactory) EChange(com.helger.commons.state.EChange) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) AbstractPhotonMapBasedWALDAO(com.helger.photon.app.dao.AbstractPhotonMapBasedWALDAO) CallbackList(com.helger.commons.callback.CallbackList) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) Nonempty(com.helger.commons.annotation.Nonempty) ISMPServiceInformationCallback(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) StringHelper(com.helger.commons.string.StringHelper) DAOException(com.helger.dao.DAOException) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) EqualsHelper(com.helger.commons.equals.EqualsHelper) ValueEnforcer(com.helger.commons.ValueEnforcer) AuditHelper(com.helger.photon.audit.AuditHelper) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ReturnsMutableObject(com.helger.commons.annotation.ReturnsMutableObject) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) Nonnull(javax.annotation.Nonnull)

Example 28 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.

the class SMPServiceInformationManagerXMLTest method testServiceRegistration.

@Test
public void testServiceRegistration() 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 ISMPServiceInformationManager aServiceInformationMgr = SMPMetaManager.getServiceInformationMgr();
    assertEquals(0, aServiceInformationMgr.getSMPServiceInformationCount());
    // 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 XMLOffsetDateTime aStartDT = PDTFactory.getCurrentXMLOffsetDateTime();
        final XMLOffsetDateTime aEndDT = aStartDT.plusYears(1);
        final IProcessIdentifier aProcessID = aIdentifierFactory.createProcessIdentifier(PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME, "testproc");
        final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "testdoctype");
        {
            // Create a new service information
            final SMPEndpoint aEP = new SMPEndpoint("tp", "http://localhost/as2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />");
            final SMPProcess aProcess = new SMPProcess(aProcessID, new CommonsArrayList<>(aEP), "<extproc />");
            assertTrue(aServiceInformationMgr.mergeSMPServiceInformation(new SMPServiceInformation(aSG, aDocTypeID, new CommonsArrayList<>(aProcess), "<extsi />")).isSuccess());
            assertEquals(1, aServiceInformationMgr.getSMPServiceInformationCount());
            assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getProcessCount());
            assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getEndpointCount());
        }
        {
            // Replace endpoint URL with equal transport profile -> replace
            final ISMPServiceInformation aSI = aServiceInformationMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aSG, aDocTypeID);
            assertNotNull(aSI);
            final ISMPProcess aProcess = aSI.getProcessOfID(aProcessID);
            assertNotNull(aProcess);
            aProcess.setEndpoint(new SMPEndpoint("tp", "http://localhost/as2-ver2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />"));
            assertTrue(aServiceInformationMgr.mergeSMPServiceInformation(aSI).isSuccess());
            assertEquals(1, aServiceInformationMgr.getSMPServiceInformationCount());
            assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getProcessCount());
            assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getEndpointCount());
            assertEquals("http://localhost/as2-ver2", CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getAllEndpoints().get(0).getEndpointReference());
        }
        {
            // Add endpoint with different transport profile -> added to existing
            // process
            final ISMPServiceInformation aSI = aServiceInformationMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aSG, aDocTypeID);
            assertNotNull(aSI);
            final ISMPProcess aProcess = aSI.getProcessOfID(aProcessID);
            assertNotNull(aProcess);
            aProcess.addEndpoint(new SMPEndpoint("tp2", "http://localhost/as2-tp2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />"));
            assertTrue(aServiceInformationMgr.mergeSMPServiceInformation(aSI).isSuccess());
            assertEquals(1, aServiceInformationMgr.getSMPServiceInformationCount());
            assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getProcessCount());
            assertEquals(2, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getEndpointCount());
        }
        {
            // Add endpoint with different process - add to existing
            // serviceGroup+docType part
            final ISMPServiceInformation aSI = aServiceInformationMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aSG, aDocTypeID);
            assertNotNull(aSI);
            final SMPEndpoint aEP = new SMPEndpoint("tp", "http://localhost/as2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />");
            aSI.addProcess(new SMPProcess(PeppolIdentifierFactory.INSTANCE.createProcessIdentifierWithDefaultScheme("testproc2"), new CommonsArrayList<>(aEP), "<extproc />"));
            assertTrue(aServiceInformationMgr.mergeSMPServiceInformation(aSI).isSuccess());
            assertEquals(1, aServiceInformationMgr.getSMPServiceInformationCount());
            assertEquals(2, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getProcessCount());
            assertEquals(2, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getEndpointCount());
            assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(1).getEndpointCount());
        }
    } finally {
        aServiceGroupMgr.deleteSMPServiceGroup(aPI, true);
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) IUser(com.helger.photon.security.user.IUser) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 29 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.

the class PageSecureEndpointChangeCertificate method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    boolean bShowList = true;
    final ICommonsMap<String, ICommonsList<ISMPEndpoint>> aEndpointsGroupedPerURL = new CommonsHashMap<>();
    final ICommonsMap<String, ICommonsSet<ISMPServiceGroup>> aServiceGroupsGroupedPerURL = new CommonsHashMap<>();
    final ICommonsList<ISMPServiceInformation> aAllSIs = aServiceInfoMgr.getAllSMPServiceInformation();
    int nTotalEndpointCount = 0;
    for (final ISMPServiceInformation aSI : aAllSIs) {
        final ISMPServiceGroup aSG = aSI.getServiceGroup();
        for (final ISMPProcess aProcess : aSI.getAllProcesses()) for (final ISMPEndpoint aEndpoint : aProcess.getAllEndpoints()) {
            final String sUnifiedCertificate = _getUnifiedCert(aEndpoint.getCertificate());
            aEndpointsGroupedPerURL.computeIfAbsent(sUnifiedCertificate, k -> new CommonsArrayList<>()).add(aEndpoint);
            aServiceGroupsGroupedPerURL.computeIfAbsent(sUnifiedCertificate, k -> new CommonsHashSet<>()).add(aSG);
            ++nTotalEndpointCount;
        }
    }
    {
        final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
        aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
        aNodeList.addChild(aToolbar);
        final int nCount = BulkChangeCertificate.getRunningJobCount();
        if (nCount > 0) {
            aNodeList.addChild(warn((nCount == 1 ? "1 bulk change is" : nCount + " bulk changes are") + " currently running in the background"));
        }
    }
    if (aWPEC.hasAction(CPageParam.ACTION_EDIT)) {
        bShowList = false;
        final FormErrorList aFormErrors = new FormErrorList();
        final String sOldUnifiedCert = _getUnifiedCert(aWPEC.params().getAsString(FIELD_OLD_CERTIFICATE));
        if (aWPEC.hasSubAction(CPageParam.ACTION_SAVE)) {
            final String sNewCert = aWPEC.params().getAsString(FIELD_NEW_CERTIFICATE);
            final String sNewUnifiedCert = _getUnifiedCert(sNewCert);
            if (StringHelper.hasNoText(sOldUnifiedCert))
                aFormErrors.addFieldInfo(FIELD_OLD_CERTIFICATE, "An old certificate must be provided");
            else {
                final String sErrorDetails = _getCertificateParsingError(sOldUnifiedCert);
                if (sErrorDetails != null)
                    aFormErrors.addFieldInfo(FIELD_OLD_CERTIFICATE, "The old certificate is invalid: " + sErrorDetails);
            }
            if (StringHelper.hasNoText(sNewUnifiedCert))
                aFormErrors.addFieldError(FIELD_NEW_CERTIFICATE, "A new certificate must be provided");
            else {
                final String sErrorDetails = _getCertificateParsingError(sNewUnifiedCert);
                if (sErrorDetails != null)
                    aFormErrors.addFieldError(FIELD_NEW_CERTIFICATE, "The new certificate is invalid: " + sErrorDetails);
                else if (sNewUnifiedCert.equals(sOldUnifiedCert))
                    aFormErrors.addFieldError(FIELD_NEW_CERTIFICATE, "The new certificate is identical to the old certificate");
            }
            // Validate parameters
            if (aFormErrors.containsNoError()) {
                PhotonWorkerPool.getInstance().run("BulkChangeCertificate", new BulkChangeCertificate(aAllSIs, aDisplayLocale, sOldUnifiedCert, sNewCert));
                aWPEC.postRedirectGetInternal(success().addChildren(div("The bulk change of the endpoint certificate to"), _getCertificateDisplay(sNewUnifiedCert, aDisplayLocale), div("is now running in the background. Please manually refresh the page to see the update.")));
            }
        }
        final ICommonsSet<ISMPServiceGroup> aServiceGroups = aServiceGroupsGroupedPerURL.get(sOldUnifiedCert);
        final int nSGCount = CollectionHelper.getSize(aServiceGroups);
        final int nEPCount = CollectionHelper.getSize(aEndpointsGroupedPerURL.get(sOldUnifiedCert));
        aNodeList.addChild(info("The selected old certificate is currently used in " + nEPCount + " " + (nEPCount == 1 ? "endpoint" : "endpoints") + " of " + nSGCount + " " + (nSGCount == 1 ? "service group" : "service groups") + "."));
        // Show edit screen
        final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
        aForm.addChild(new HCHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_EDIT));
        aForm.addChild(new HCHiddenField(CPageParam.PARAM_SUBACTION, CPageParam.ACTION_SAVE));
        aForm.addChild(new HCHiddenField(FIELD_OLD_CERTIFICATE, sOldUnifiedCert));
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Old certificate").setCtrl(_getCertificateDisplay(sOldUnifiedCert, aDisplayLocale)).setHelpText("The old certificate that is to be changed in all matching endpoints").setErrorList(aFormErrors.getListOfField(FIELD_OLD_CERTIFICATE)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("New certificate").setCtrl(new HCTextArea(new RequestField(FIELD_NEW_CERTIFICATE, sOldUnifiedCert)).setRows(10)).setHelpText("The new certificate that is used instead").setErrorList(aFormErrors.getListOfField(FIELD_NEW_CERTIFICATE)));
        final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(getUIHandler().createToolbar(aWPEC));
        aToolbar.addSubmitButton("Save changes", EDefaultIcon.SAVE);
        aToolbar.addButtonCancel(aDisplayLocale);
    }
    if (bShowList) {
        aNodeList.addChild(info().addChildren(div("This page lets you change the certificates of multiple endpoints at once. This is e.g. helpful when the old certificate expired."), div("Currently " + (nTotalEndpointCount == 1 ? "1 endpoint is" : nTotalEndpointCount + " endpoints are") + " registered.")));
        final HCTable aTable = new HCTable(new DTCol("Certificate").setInitialSorting(ESortOrder.ASCENDING), new DTCol("Service Group Count").setDisplayType(EDTColType.INT, aDisplayLocale), new DTCol("Endpoint Count").setDisplayType(EDTColType.INT, aDisplayLocale), new BootstrapDTColAction(aDisplayLocale)).setID(getID());
        aEndpointsGroupedPerURL.forEach((sCert, aEndpoints) -> {
            final HCRow aRow = aTable.addBodyRow();
            aRow.addCell(_getCertificateDisplay(sCert, aDisplayLocale));
            final int nSGCount = CollectionHelper.getSize(aServiceGroupsGroupedPerURL.get(sCert));
            aRow.addCell(Integer.toString(nSGCount));
            aRow.addCell(Integer.toString(aEndpoints.size()));
            final ISimpleURL aEditURL = aWPEC.getSelfHref().add(CPageParam.PARAM_ACTION, CPageParam.ACTION_EDIT).add(FIELD_OLD_CERTIFICATE, sCert);
            aRow.addCell(new HCA(aEditURL).setTitle("Change all endpoints using this certificate").addChild(EDefaultIcon.EDIT.getAsNode()));
        });
        final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
        aNodeList.addChild(aTable).addChild(aDataTables);
    }
}
Also used : Locale(java.util.Locale) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCNodeList(com.helger.html.hc.impl.HCNodeList) FormErrorList(com.helger.photon.core.form.FormErrorList) HCRow(com.helger.html.hc.html.tabular.HCRow) PDTToString(com.helger.commons.datetime.PDTToString) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) DataTables(com.helger.photon.uictrls.datatables.DataTables) RequestField(com.helger.photon.core.form.RequestField) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) HCHiddenField(com.helger.html.hc.html.forms.HCHiddenField) HCTextArea(com.helger.html.hc.html.forms.HCTextArea) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) HCA(com.helger.html.hc.html.textlevel.HCA) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) HCTable(com.helger.html.hc.html.tabular.HCTable) ICommonsSet(com.helger.commons.collection.impl.ICommonsSet) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup)

Example 30 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.

the class SMPWebAppListener method initManagers.

@Override
protected void initManagers() {
    {
        LOGGER.info("Init of ConfigurationFileManager");
        final ConfigurationFileManager aCFM = ConfigurationFileManager.getInstance();
        aCFM.registerConfigurationFile(new ConfigurationFile(new ClassPathResource("log4j2.xml")).setDescription("Log4J2 configuration").setSyntaxHighlightLanguage(EConfigurationFileSyntax.XML));
        aCFM.registerConfigurationFile(new ConfigurationFile(SMPWebAppConfiguration.getSettingsResource()).setDescription("SMP web application configuration").setSyntaxHighlightLanguage(EConfigurationFileSyntax.PROPERTIES));
        final IReadableResource aConfigRes = SMPServerConfiguration.getConfigFile().getReadResource();
        if (aConfigRes != null) {
            aCFM.registerConfigurationFile(new ConfigurationFile(aConfigRes).setDescription("SMP server configuration").setSyntaxHighlightLanguage(EConfigurationFileSyntax.PROPERTIES));
        }
        aCFM.registerAll(PDClientConfiguration.getConfig());
    }
    {
        LOGGER.info("Init of Directory client stuff");
        // If the SMP settings change, the PD client must be re-created
        SMPMetaManager.getSettingsMgr().callbacks().add(x -> PDClientProvider.getInstance().resetPDClient());
        // Callback on BusinessCard manager - if something happens, notify PD
        // server
        final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
        if (aBusinessCardMgr != null) {
            aBusinessCardMgr.bcCallbacks().add(new ISMPBusinessCardCallback() {

                public void onSMPBusinessCardCreatedOrUpdated(@Nonnull final ISMPBusinessCard aBusinessCard) {
                    final ISMPSettings aSettings = SMPMetaManager.getSettings();
                    if (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate()) {
                        // Notify PD server: add
                        PDClientProvider.getInstance().getPDClient().addServiceGroupToIndex(aBusinessCard.getParticipantIdentifier());
                    }
                }

                public void onSMPBusinessCardDeleted(@Nonnull final ISMPBusinessCard aBusinessCard) {
                    final ISMPSettings aSettings = SMPMetaManager.getSettings();
                    if (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate()) {
                        // Notify PD server: delete
                        PDClientProvider.getInstance().getPDClient().deleteServiceGroupFromIndex(aBusinessCard.getParticipantIdentifier());
                    }
                }
            });
            // If a service information is create, updated or deleted, also update
            // Business Card at PD
            SMPMetaManager.getServiceInformationMgr().serviceInformationCallbacks().add(new ISMPServiceInformationCallback() {

                @Override
                public void onSMPServiceInformationCreated(@Nonnull final ISMPServiceInformation aServiceInformation) {
                    final ISMPSettings aSettings = SMPMetaManager.getSettings();
                    if (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate()) {
                        // Only if a business card is present
                        if (aBusinessCardMgr.containsSMPBusinessCardOfServiceGroup(aServiceInformation.getServiceGroup())) {
                            // Notify PD server: update
                            PDClientProvider.getInstance().getPDClient().addServiceGroupToIndex(aServiceInformation.getServiceGroup().getParticipantIdentifier());
                        }
                    }
                }

                @Override
                public void onSMPServiceInformationUpdated(@Nonnull final ISMPServiceInformation aServiceInformation) {
                    onSMPServiceInformationCreated(aServiceInformation);
                }

                @Override
                public void onSMPServiceInformationDeleted(@Nonnull final ISMPServiceInformation aServiceInformation) {
                    onSMPServiceInformationCreated(aServiceInformation);
                }
            });
        }
    }
    {
        LOGGER.info("Init of HTTP and Proxy settings");
        // Register global proxy servers
        ProxySelectorProxySettingsManager.setAsDefault(true);
        final IProxySettings aProxyHttp = SMPServerConfiguration.getAsHttpProxySettings();
        if (aProxyHttp != null) {
            // Register a handler that returns the "http" proxy, if an "http" URL is
            // requested
            ProxySettingsManager.registerProvider((sProtocol, sHost, nPort) -> "http".equals(sProtocol) ? new CommonsArrayList<>(aProxyHttp) : null);
        }
        final IProxySettings aProxyHttps = SMPServerConfiguration.getAsHttpsProxySettings();
        if (aProxyHttps != null) {
            // Register a handler that returns the "https" proxy, if an "https" URL
            // is
            // requested
            ProxySettingsManager.registerProvider((sProtocol, sHost, nPort) -> "https".equals(sProtocol) ? new CommonsArrayList<>(aProxyHttps) : null);
        }
    }
    // Special http client config
    BasePageUtilsHttpClient.HttpClientConfigRegistry.register(new HttpClientConfig("directoryclient", "Directory client settings", PDHttpClientSettings::new));
    LOGGER.info("Finished init of managers");
}
Also used : CSMPServer(com.helger.phoss.smp.CSMPServer) PDClientProvider(com.helger.phoss.smp.app.PDClientProvider) PDTConfig(com.helger.commons.datetime.PDTConfig) ILocaleManager(com.helger.photon.core.locale.ILocaleManager) ProxySelectorProxySettingsManager(com.helger.network.proxy.ProxySelectorProxySettingsManager) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) LoggerFactory(org.slf4j.LoggerFactory) PDClientConfiguration(com.helger.pd.client.PDClientConfiguration) SLF4JBridgeHandler(org.slf4j.bridge.SLF4JBridgeHandler) CApplicationID(com.helger.photon.core.appid.CApplicationID) PDTFactory(com.helger.commons.datetime.PDTFactory) SMPCommonUI(com.helger.phoss.smp.ui.SMPCommonUI) UnifiedResponseDefaultSettings(com.helger.servlet.response.UnifiedResponseDefaultSettings) TimeZone(java.util.TimeZone) ConfigurationFile(com.helger.photon.core.configfile.ConfigurationFile) IReadableResource(com.helger.commons.io.resource.IReadableResource) OffsetDateTime(java.time.OffsetDateTime) IProxySettings(com.helger.network.proxy.settings.IProxySettings) InitializationException(com.helger.commons.exception.InitializationException) IAjaxRegistry(com.helger.photon.ajax.IAjaxRegistry) RegExHelper(com.helger.commons.regex.RegExHelper) RequestTrackerSettings(com.helger.xservlet.requesttrack.RequestTrackerSettings) SMPWebAppConfiguration(com.helger.phoss.smp.app.SMPWebAppConfiguration) WSHelper(com.helger.wsclient.WSHelper) ProxySettingsManager(com.helger.network.proxy.settings.ProxySettingsManager) ServletContextPathHolder(com.helger.servlet.ServletContextPathHolder) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) MenuPublic(com.helger.phoss.smp.ui.pub.MenuPublic) PhotonGlobalState(com.helger.photon.core.appid.PhotonGlobalState) SMPSecurity(com.helger.phoss.smp.app.SMPSecurity) RequestParameterManager(com.helger.photon.core.requestparam.RequestParameterManager) WebAppListenerBootstrap(com.helger.photon.bootstrap4.servlet.WebAppListenerBootstrap) IPrivilegedAction(com.helger.commons.lang.priviledged.IPrivilegedAction) ISMPServiceInformationCallback(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback) GlobalDebug(com.helger.commons.debug.GlobalDebug) Nonnull(javax.annotation.Nonnull) ConfigurationFileManager(com.helger.photon.core.configfile.ConfigurationFileManager) Nullable(javax.annotation.Nullable) ArrayHelper(com.helger.commons.collection.ArrayHelper) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) BasePageUtilsHttpClient(com.helger.photon.bootstrap4.pages.utils.BasePageUtilsHttpClient) StringHelper(com.helger.commons.string.StringHelper) SMPMetaManager(com.helger.phoss.smp.domain.SMPMetaManager) MenuSecure(com.helger.phoss.smp.ui.secure.MenuSecure) RequestParameterHandlerURLPathNamed(com.helger.photon.core.requestparam.RequestParameterHandlerURLPathNamed) CAjax(com.helger.phoss.smp.ui.ajax.CAjax) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) PDHttpClientSettings(com.helger.pd.client.PDHttpClientSettings) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) SMPServerConfiguration(com.helger.phoss.smp.SMPServerConfiguration) ISMPBusinessCardCallback(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardCallback) HttpClientConfig(com.helger.photon.bootstrap4.pages.utils.BasePageUtilsHttpClient.HttpClientConfig) ServletContext(javax.servlet.ServletContext) EConfigurationFileSyntax(com.helger.photon.core.configfile.EConfigurationFileSyntax) MenuTree(com.helger.photon.core.menu.MenuTree) ISMPBusinessCardCallback(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardCallback) HttpClientConfig(com.helger.photon.bootstrap4.pages.utils.BasePageUtilsHttpClient.HttpClientConfig) ConfigurationFileManager(com.helger.photon.core.configfile.ConfigurationFileManager) Nonnull(javax.annotation.Nonnull) IReadableResource(com.helger.commons.io.resource.IReadableResource) ISMPServiceInformationCallback(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) IProxySettings(com.helger.network.proxy.settings.IProxySettings) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) ConfigurationFile(com.helger.photon.core.configfile.ConfigurationFile)

Aggregations

ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)31 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)27 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)27 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)20 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)20 Nonnull (javax.annotation.Nonnull)20 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)17 ISMPProcess (com.helger.phoss.smp.domain.serviceinfo.ISMPProcess)16 ISMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint)15 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)14 ICommonsList (com.helger.commons.collection.impl.ICommonsList)13 SMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation)12 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)11 IProcessIdentifier (com.helger.peppolid.IProcessIdentifier)11 SMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint)11 EChange (com.helger.commons.state.EChange)10 ValueEnforcer (com.helger.commons.ValueEnforcer)9 StringHelper (com.helger.commons.string.StringHelper)9 ISMPTransportProfile (com.helger.peppol.smp.ISMPTransportProfile)9 ISMPServiceInformationCallback (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback)9