Search in sources :

Example 1 with ISMLInfoManager

use of com.helger.phoss.smp.domain.sml.ISMLInfoManager in project phoss-smp by phax.

the class PageSecureSMLConfiguration method showListOfExistingObjects.

@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMLInfoManager aSMLInfoMgr = SMPMetaManager.getSMLInfoMgr();
    aNodeList.addChild(info("This page lets you create custom SML configurations that can be used for registration."));
    final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
    aToolbar.addButton("Create new SML configuration", createCreateURL(aWPEC), EDefaultIcon.NEW);
    aNodeList.addChild(aToolbar);
    final HCTable aTable = new HCTable(new DTCol("Name").setInitialSorting(ESortOrder.ASCENDING), new DTCol("DNS Zone"), new DTCol("Management Service URL"), new DTCol("Client Cert?"), new BootstrapDTColAction(aDisplayLocale)).setID(getID());
    for (final ISMLInfo aCurObject : aSMLInfoMgr.getAllSMLInfos()) {
        final ISimpleURL aViewLink = createViewURL(aWPEC, aCurObject);
        final HCRow aRow = aTable.addBodyRow();
        aRow.addCell(new HCA(aViewLink).addChild(aCurObject.getDisplayName()));
        aRow.addCell(aCurObject.getDNSZone());
        aRow.addCell(aCurObject.getManagementServiceURL());
        aRow.addCell(EPhotonCoreText.getYesOrNo(aCurObject.isClientCertificateRequired(), aDisplayLocale));
        aRow.addCell(createEditLink(aWPEC, aCurObject, "Edit " + aCurObject.getID()), new HCTextNode(" "), createCopyLink(aWPEC, aCurObject, "Copy " + aCurObject.getID()), new HCTextNode(" "), isActionAllowed(aWPEC, EWebPageFormAction.DELETE, aCurObject) ? createDeleteLink(aWPEC, aCurObject, "Delete " + aCurObject.getDisplayName()) : createEmptyAction());
    }
    final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
    aNodeList.addChild(aTable).addChild(aDataTables);
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMLInfo(com.helger.peppol.sml.ISMLInfo) HCA(com.helger.html.hc.html.textlevel.HCA) HCRow(com.helger.html.hc.html.tabular.HCRow) HCTable(com.helger.html.hc.html.tabular.HCTable) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) ISMLInfoManager(com.helger.phoss.smp.domain.sml.ISMLInfoManager) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) HCTextNode(com.helger.html.hc.impl.HCTextNode) DataTables(com.helger.photon.uictrls.datatables.DataTables) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables)

Example 2 with ISMLInfoManager

use of com.helger.phoss.smp.domain.sml.ISMLInfoManager in project phoss-smp by phax.

the class PageSecureSMLConfiguration method validateAndSaveInputParameters.

@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMLInfo aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
    final boolean bEdit = eFormAction.isEdit();
    final ISMLInfoManager aSMLInfoMgr = SMPMetaManager.getSMLInfoMgr();
    final String sDisplayName = aWPEC.params().getAsString(FIELD_DISPLAY_NAME);
    final String sDNSZone = aWPEC.params().getAsString(FIELD_DNS_ZONE);
    final String sManagementAddressURL = aWPEC.params().getAsString(FIELD_MANAGEMENT_ADDRESS_URL);
    final boolean bClientCertificateRequired = aWPEC.params().isCheckBoxChecked(FIELD_CLIENT_CERTIFICATE_REQUIRED, DEFAULT_CLIENT_CERTIFICATE_REQUIRED);
    // validations
    if (StringHelper.hasNoText(sDisplayName))
        aFormErrors.addFieldError(FIELD_DISPLAY_NAME, "The SML configuration name must not be empty!");
    if (StringHelper.hasNoText(sDNSZone))
        aFormErrors.addFieldError(FIELD_DNS_ZONE, "The DNS Zone must not be empty!");
    if (StringHelper.hasNoText(sManagementAddressURL))
        aFormErrors.addFieldError(FIELD_MANAGEMENT_ADDRESS_URL, "The Management Address URL must not be empty!");
    else {
        final URL aURL = URLHelper.getAsURL(sManagementAddressURL);
        if (aURL == null)
            aFormErrors.addFieldError(FIELD_MANAGEMENT_ADDRESS_URL, "The Management Address URL is not a valid URL!");
        else if (!"https".equals(aURL.getProtocol()) && !"http".equals(aURL.getProtocol()))
            aFormErrors.addFieldError(FIELD_MANAGEMENT_ADDRESS_URL, "The Management Address URL should only be use the 'http' or the 'https' protocol!");
    }
    if (aFormErrors.isEmpty()) {
        // Lowercase with the US locale - not display locale specific
        final String sDNSZoneLC = sDNSZone.toLowerCase(Locale.US);
        if (bEdit) {
            aSMLInfoMgr.updateSMLInfo(aSelectedObject.getID(), sDisplayName, sDNSZoneLC, sManagementAddressURL, bClientCertificateRequired);
            aWPEC.postRedirectGetInternal(success("The SML configuration '" + sDisplayName + "' was successfully edited."));
        } else {
            aSMLInfoMgr.createSMLInfo(sDisplayName, sDNSZoneLC, sManagementAddressURL, bClientCertificateRequired);
            aWPEC.postRedirectGetInternal(success("The new SML configuration '" + sDisplayName + "' was successfully created."));
        }
    }
}
Also used : ISMLInfoManager(com.helger.phoss.smp.domain.sml.ISMLInfoManager) URL(java.net.URL) ISimpleURL(com.helger.commons.url.ISimpleURL)

Example 3 with ISMLInfoManager

use of com.helger.phoss.smp.domain.sml.ISMLInfoManager 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)

Aggregations

ISMLInfoManager (com.helger.phoss.smp.domain.sml.ISMLInfoManager)3 ISimpleURL (com.helger.commons.url.ISimpleURL)2 ISMLInfo (com.helger.peppol.sml.ISMLInfo)2 HCRow (com.helger.html.hc.html.tabular.HCRow)1 HCTable (com.helger.html.hc.html.tabular.HCTable)1 HCA (com.helger.html.hc.html.textlevel.HCA)1 HCNodeList (com.helger.html.hc.impl.HCNodeList)1 HCTextNode (com.helger.html.hc.impl.HCTextNode)1 ISMPSettings (com.helger.phoss.smp.settings.ISMPSettings)1 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)1 BootstrapDTColAction (com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction)1 BootstrapDataTables (com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables)1 DataTables (com.helger.photon.uictrls.datatables.DataTables)1 DTCol (com.helger.photon.uictrls.datatables.column.DTCol)1 URL (java.net.URL)1 Locale (java.util.Locale)1 Test (org.junit.Test)1