Search in sources :

Example 16 with ISMLInfo

use of com.helger.peppol.sml.ISMLInfo in project phoss-directory by phax.

the class AbstractPageSecureReIndex method showSelectedObject.

@Override
protected void showSelectedObject(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final IReIndexWorkItem aSelectedObject) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ISMPURLProvider aURLProvider = PDServerConfiguration.getURLProvider();
    final IIndexerWorkItem aWorkItem = aSelectedObject.getWorkItem();
    final IParticipantIdentifier aParticipantID = aWorkItem.getParticipantID();
    final BootstrapViewForm aViewForm = aNodeList.addAndReturnChild(new BootstrapViewForm());
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Creation datetime").setCtrl(PDTToString.getAsString(aWorkItem.getCreationDateTime(), aDisplayLocale)));
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Participant ID").setCtrl(aParticipantID.getURIEncoded()));
    final String sBCSuffix = "/businesscard/" + aParticipantID.getURIPercentEncoded();
    {
        final HCNodeList aURLs = new HCNodeList();
        for (final ISMLInfo aSMLInfo : PDPMetaManager.getSMLInfoMgr().getAll()) {
            if (aURLs.hasChildren())
                aURLs.addChild(div("or"));
            try {
                aURLs.addChild(div(HCA.createLinkedWebsite(aURLProvider.getSMPURIOfParticipant(aParticipantID, aSMLInfo).toString() + sBCSuffix)));
            } catch (final SMPDNSResolutionException ex) {
                // Non existing participant!
                aURLs.addChild(div(aParticipantID.getURIPercentEncoded() + " on " + aSMLInfo.getDisplayName() + " @ " + sBCSuffix + " [" + ex.getMessage() + "]"));
            }
        }
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Business Card URL").setCtrl(aURLs));
    }
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Action type").setCtrl(aWorkItem.getType().getDisplayName()));
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Owner").setCtrl(aWorkItem.getOwnerID()));
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Requesting host").setCtrl(aWorkItem.getRequestingHost()));
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Retries so far").setCtrl(Integer.toString(aSelectedObject.getRetryCount())));
    if (aSelectedObject.hasPreviousRetryDT())
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Previous retry").setCtrl(PDTToString.getAsString(aSelectedObject.getPreviousRetryDT(), aDisplayLocale)));
    if (!m_bDeadIndex)
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Next retry").setCtrl(PDTToString.getAsString(aSelectedObject.getNextRetryDT(), aDisplayLocale)));
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Last retry").setCtrl(PDTToString.getAsString(aSelectedObject.getMaxRetryDT(), aDisplayLocale)));
}
Also used : Locale(java.util.Locale) IIndexerWorkItem(com.helger.pd.indexer.index.IIndexerWorkItem) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMLInfo(com.helger.peppol.sml.ISMLInfo) ISMPURLProvider(com.helger.smpclient.url.ISMPURLProvider) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) PDTToString(com.helger.commons.datetime.PDTToString) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) SMPDNSResolutionException(com.helger.smpclient.url.SMPDNSResolutionException) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 17 with ISMLInfo

use of com.helger.peppol.sml.ISMLInfo in project phoss-directory by phax.

the class PageSecureIndexImport method fillContent.

@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
    final FormErrorList aFormErrors = new FormErrorList();
    {
        final IPDBusinessCardProvider aBCProv = PDMetaManager.getBusinessCardProvider();
        if (aBCProv instanceof SMPBusinessCardProvider) {
            final SMPBusinessCardProvider aSMPBCProv = (SMPBusinessCardProvider) aBCProv;
            if (aSMPBCProv.isFixedSMP()) {
                aNodeList.addChild(info("Fixed SMP URI " + aSMPBCProv.getFixedSMPURI() + " is used."));
            } else {
                aNodeList.addChild(info("The following SMLs are crawled for entries: " + StringHelper.getImplodedMapped(", ", aSMPBCProv.getAllSMLsToUse(), ISMLInfo::getDisplayName)));
            }
        }
    }
    final boolean bIsFormSubmitted = aWPEC.hasAction(CPageParam.ACTION_PERFORM);
    if (bIsFormSubmitted) {
        final IFileItem aFile = aWPEC.params().getAsFileItem(FIELD_FILE);
        if (aFile == null || StringHelper.hasNoText(aFile.getName()))
            aFormErrors.addFieldError(FIELD_FILE, "No file was selected");
        if (aFormErrors.isEmpty()) {
            final HCNodeList aResultNL = new HCNodeList();
            final SAXReaderSettings aSettings = new SAXReaderSettings();
            aSettings.setFeatureValues(EXMLParserFeature.AVOID_DOS_SETTINGS);
            final CollectingSAXErrorHandler aErrorHandler = new CollectingSAXErrorHandler();
            aSettings.setErrorHandler(aErrorHandler);
            final ICommonsList<IParticipantIdentifier> aQueued = new CommonsArrayList<>();
            final ICommonsList<IParticipantIdentifier> aNotQueued = new CommonsArrayList<>();
            aSettings.setContentHandler(new DefaultHandler() {

                @Override
                public void startElement(final String sURI, final String sLocalName, final String sQName, final Attributes aAttributes) throws SAXException {
                    if (sQName.equals("participant")) {
                        final String sScheme = aAttributes.getValue("scheme");
                        final String sValue = aAttributes.getValue("value");
                        final IParticipantIdentifier aParticipantID = aIdentifierFactory.createParticipantIdentifier(sScheme, sValue);
                        if (aParticipantID != null) {
                            if (PDMetaManager.getIndexerMgr().queueWorkItem(aParticipantID, EIndexerWorkItemType.CREATE_UPDATE, "import-triggered", PDIndexerManager.HOST_LOCALHOST).isChanged()) {
                                aQueued.add(aParticipantID);
                            } else {
                                aNotQueued.add(aParticipantID);
                            }
                        } else
                            LOGGER.error("Failed to convert '" + sScheme + "' and '" + sValue + "' to a participant identifier");
                    }
                }
            });
            LOGGER.info("Importing participant IDs from '" + aFile.getNameSecure() + "'");
            final ESuccess eSuccess = SAXReader.readXMLSAX(new FileItemResource(aFile), aSettings);
            LOGGER.info("Finished reading XML file. Queued " + aQueued.size() + "; not queued: " + aNotQueued.size() + "; errors: " + aErrorHandler.getErrorList().size());
            // Some things may have been queued even in case of error
            if (aQueued.isNotEmpty()) {
                final HCUL aUL = new HCUL();
                for (final IParticipantIdentifier aPI : aQueued) aUL.addItem(aPI.getURIEncoded());
                aResultNL.addChild(success(div("The following identifiers were successfully queued for indexing:")).addChild(aUL));
            }
            if (aNotQueued.isNotEmpty()) {
                final HCUL aUL = new HCUL();
                for (final IParticipantIdentifier aPI : aNotQueued) aUL.addItem(aPI.getURIEncoded());
                aResultNL.addChild(warn(div("The following identifiers could not be queued (because they are already in the queue):")).addChild(aUL));
            }
            if (eSuccess.isFailure()) {
                final HCUL aUL = new HCUL();
                for (final IError aError : aErrorHandler.getErrorList()) {
                    final String sMsg = aError.getAsString(AppCommonUI.DEFAULT_LOCALE);
                    LOGGER.error("  " + sMsg);
                    aUL.addItem(sMsg);
                }
                aResultNL.addChild(error(div("Error parsing provided XML:")).addChild(aUL));
            }
            aWPEC.postRedirectGetInternal(aResultNL);
        }
    }
    final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormFileUploadSelf(aWPEC, bIsFormSubmitted));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Import file").setCtrl(new BootstrapFileUpload(FIELD_FILE, aDisplayLocale)).setHelpText("Select a file that was created from a full XML export to index of all them manually.").setErrorList(aFormErrors.getListOfField(FIELD_FILE)));
    final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
    aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
    aToolbar.addSubmitButton("Import all", EDefaultIcon.YES);
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) CollectingSAXErrorHandler(com.helger.xml.sax.CollectingSAXErrorHandler) ISMLInfo(com.helger.peppol.sml.ISMLInfo) FormErrorList(com.helger.photon.core.form.FormErrorList) Attributes(org.xml.sax.Attributes) SAXReaderSettings(com.helger.xml.serialize.read.SAXReaderSettings) SAXException(org.xml.sax.SAXException) BootstrapFileUpload(com.helger.photon.bootstrap4.uictrls.ext.BootstrapFileUpload) IFileItem(com.helger.web.fileupload.IFileItem) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) SMPBusinessCardProvider(com.helger.pd.indexer.businesscard.SMPBusinessCardProvider) ESuccess(com.helger.commons.state.ESuccess) IError(com.helger.commons.error.IError) FileItemResource(com.helger.web.fileupload.FileItemResource) DefaultHandler(org.xml.sax.helpers.DefaultHandler) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) IPDBusinessCardProvider(com.helger.pd.indexer.businesscard.IPDBusinessCardProvider) HCUL(com.helger.html.hc.html.grouping.HCUL) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 18 with ISMLInfo

use of com.helger.peppol.sml.ISMLInfo in project phoss-smp by phax.

the class SMLInfoManagerMongoDBTest method testConversion.

@Test
public void testConversion() {
    final ISMLInfo aInfo = new SMLInfo("displayName", "DNSZone", "https://url/url", true);
    final Document aSrc = SMLInfoManagerMongoDB.toBson(aInfo);
    assertNotNull(aSrc);
    final ISMLInfo aSrc2 = SMLInfoManagerMongoDB.toDomain(aSrc);
    assertNotNull(aSrc2);
    assertEquals(aInfo, aSrc2);
}
Also used : ISMLInfo(com.helger.peppol.sml.ISMLInfo) ISMLInfo(com.helger.peppol.sml.ISMLInfo) SMLInfo(com.helger.peppol.sml.SMLInfo) Document(org.bson.Document) Test(org.junit.Test)

Example 19 with ISMLInfo

use of com.helger.peppol.sml.ISMLInfo in project phoss-smp by phax.

the class SMPSettingsManagerMongoDBTest method testBasic.

@Test
public void testBasic() {
    final ISMLInfoManager aSMLInfoMgr = SMPMetaManager.getSMLInfoMgr();
    final ISMLInfo aSMLInfo = aSMLInfoMgr.createSMLInfo("bla", "foo", "http://bar", true);
    assertNotNull(aSMLInfo);
    try (final SMPSettingsManagerMongoDB aMgr = new SMPSettingsManagerMongoDB()) {
        final ISMPSettings aSettings = aMgr.getSettings();
        assertNotNull(aSettings);
        aMgr.updateSettings(true, true, true, true, "v1", true, true, aSMLInfo.getID());
        assertTrue(aSettings.isRESTWritableAPIDisabled());
        assertTrue(aSettings.isDirectoryIntegrationRequired());
        assertTrue(aSettings.isDirectoryIntegrationEnabled());
        assertTrue(aSettings.isDirectoryIntegrationAutoUpdate());
        assertEquals("v1", aSettings.getDirectoryHostName());
        assertTrue(aSettings.isSMLRequired());
        assertTrue(aSettings.isSMLEnabled());
        assertEquals(aSMLInfo, aSettings.getSMLInfo());
        aMgr.updateSettings(false, false, false, false, "v2", false, false, aSMLInfo.getID());
        assertFalse(aSettings.isRESTWritableAPIDisabled());
        assertFalse(aSettings.isDirectoryIntegrationRequired());
        assertFalse(aSettings.isDirectoryIntegrationEnabled());
        assertFalse(aSettings.isDirectoryIntegrationAutoUpdate());
        assertEquals("v2", aSettings.getDirectoryHostName());
        assertFalse(aSettings.isSMLRequired());
        assertFalse(aSettings.isSMLEnabled());
        assertEquals(aSMLInfo, aSettings.getSMLInfo());
    } finally {
        aSMLInfoMgr.deleteSMLInfo(aSMLInfo.getID());
    }
}
Also used : ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) ISMLInfo(com.helger.peppol.sml.ISMLInfo) ISMLInfoManager(com.helger.phoss.smp.domain.sml.ISMLInfoManager) Test(org.junit.Test)

Example 20 with ISMLInfo

use of com.helger.peppol.sml.ISMLInfo in project phoss-smp by phax.

the class SMLInfoManagerMongoDB method createSMLInfo.

@Nonnull
public ISMLInfo createSMLInfo(@Nonnull @Nonempty final String sDisplayName, @Nonnull @Nonempty final String sDNSZone, @Nonnull @Nonempty final String sManagementServiceURL, final boolean bClientCertificateRequired) {
    final SMLInfo aSMLInfo = new SMLInfo(sDisplayName, sDNSZone, sManagementServiceURL, bClientCertificateRequired);
    if (!getCollection().insertOne(toBson(aSMLInfo)).wasAcknowledged())
        throw new IllegalStateException("Failed to insert into MongoDB Collection");
    AuditHelper.onAuditCreateSuccess(SMLInfo.OT, aSMLInfo.getID(), sDisplayName, sDNSZone, sManagementServiceURL, Boolean.valueOf(bClientCertificateRequired));
    return aSMLInfo;
}
Also used : SMLInfo(com.helger.peppol.sml.SMLInfo) ISMLInfo(com.helger.peppol.sml.ISMLInfo) Nonnull(javax.annotation.Nonnull)

Aggregations

ISMLInfo (com.helger.peppol.sml.ISMLInfo)29 HCNodeList (com.helger.html.hc.impl.HCNodeList)11 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)9 SMLInfo (com.helger.peppol.sml.SMLInfo)7 Locale (java.util.Locale)7 Nonnull (javax.annotation.Nonnull)6 Test (org.junit.Test)6 ISMPSettings (com.helger.phoss.smp.settings.ISMPSettings)5 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)5 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)5 UnknownHostException (java.net.UnknownHostException)5 ManageParticipantIdentifierServiceCaller (com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller)4 PDTToString (com.helger.commons.datetime.PDTToString)3 HCA (com.helger.html.hc.html.textlevel.HCA)3 ManageServiceMetadataServiceCaller (com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller)3 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)3 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)3 FormErrorList (com.helger.photon.core.form.FormErrorList)3 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)3 CMimeType (com.helger.commons.mime.CMimeType)2