Search in sources :

Example 6 with ISMPTransportProfile

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

the class NiceNameUI method getTransportProfile.

@Nonnull
public static IHCNode getTransportProfile(@Nullable final String sTransportProfile, final boolean bInDetails) {
    final ISMPTransportProfileManager aTransportProfileMgr = SMPMetaManager.getTransportProfileMgr();
    final ISMPTransportProfile aTP = aTransportProfileMgr.getSMPTransportProfileOfID(sTransportProfile);
    if (aTP == null)
        return createFormattedID(sTransportProfile, null, null, false, bInDetails);
    return createFormattedID(sTransportProfile, aTP.getName(), EBootstrapBadgeType.SUCCESS, aTP.isDeprecated(), bInDetails);
}
Also used : ISMPTransportProfileManager(com.helger.phoss.smp.domain.transportprofile.ISMPTransportProfileManager) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) Nonnull(javax.annotation.Nonnull)

Example 7 with ISMPTransportProfile

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

the class SMPTransportProfileManagerMongoDB method createSMPTransportProfile.

@Nullable
public ISMPTransportProfile createSMPTransportProfile(@Nonnull @Nonempty final String sID, @Nonnull @Nonempty final String sName, final boolean bIsDeprecated) {
    // Double ID needs to be taken care of
    if (containsSMPTransportProfileWithID(sID))
        return null;
    final SMPTransportProfile aSMPTransportProfile = new SMPTransportProfile(sID, sName, bIsDeprecated);
    if (!getCollection().insertOne(toBson(aSMPTransportProfile)).wasAcknowledged())
        throw new IllegalStateException("Failed to insert into MongoDB Collection");
    AuditHelper.onAuditCreateSuccess(SMPTransportProfile.OT, sID, sName, Boolean.valueOf(bIsDeprecated));
    return aSMPTransportProfile;
}
Also used : ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPTransportProfile(com.helger.peppol.smp.SMPTransportProfile) Nullable(javax.annotation.Nullable)

Example 8 with ISMPTransportProfile

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

the class SMPTransportProfileManagerJDBC method createSMPTransportProfile.

@Nullable
public ISMPTransportProfile createSMPTransportProfile(@Nonnull @Nonempty final String sID, @Nonnull @Nonempty final String sName, final boolean bIsDeprecated) {
    final ISMPTransportProfile ret = new SMPTransportProfile(sID, sName, bIsDeprecated);
    final DBExecutor aExecutor = newExecutor();
    final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
        // Create new
        final long nCreated = aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_tprofile (id, name, deprecated) VALUES (?, ?, ?)", new ConstantPreparedStatementDataProvider(DBValueHelper.getTrimmedToLength(ret.getID(), 45), ret.getName(), Boolean.valueOf(ret.isDeprecated())));
        if (nCreated != 1)
            throw new IllegalStateException("Failed to create new DB entry (" + nCreated + ")");
    });
    if (eSuccess.isFailure()) {
        AuditHelper.onAuditCreateFailure(SMPTransportProfile.OT, sID, sName, Boolean.valueOf(bIsDeprecated), "database-error");
        return null;
    }
    AuditHelper.onAuditCreateSuccess(SMPTransportProfile.OT, sID, sName, Boolean.valueOf(bIsDeprecated));
    return ret;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPTransportProfile(com.helger.peppol.smp.SMPTransportProfile) Nullable(javax.annotation.Nullable)

Example 9 with ISMPTransportProfile

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

the class SMPTransportProfileManagerMongoDBTest method testBasic.

@Test
public void testBasic() {
    try (final SMPTransportProfileManagerMongoDB aMgr = new SMPTransportProfileManagerMongoDB()) {
        assertEquals(0, aMgr.getAllSMPTransportProfiles().size());
        final ICommonsList<ISMPTransportProfile> aCreated = aMgr.getAllSMPTransportProfiles();
        for (final ESMPTransportProfile e : ESMPTransportProfile.values()) {
            final ISMPTransportProfile aCreate = aMgr.createSMPTransportProfile(e.getID(), e.getName(), e.isDeprecated());
            aCreated.add(aCreate);
        }
        final ICommonsList<ISMPTransportProfile> aAll = aMgr.getAllSMPTransportProfiles();
        assertEquals(ESMPTransportProfile.values().length, aAll.size());
        for (final ISMPTransportProfile aCreate : aCreated) assertTrue(aAll.contains(aCreate));
        for (final ISMPTransportProfile aCreate : aCreated) assertTrue(aMgr.updateSMPTransportProfile(aCreate.getID(), "bla " + aCreate.getName(), aCreate.isDeprecated()).isChanged());
        for (final ISMPTransportProfile aCreate : aCreated) {
            final ISMPTransportProfile aInfo = aMgr.getSMPTransportProfileOfID(aCreate.getID());
            assertNotNull(aInfo);
            assertTrue(aInfo.getName().startsWith("bla "));
        }
        for (final ISMPTransportProfile aCreate : aCreated) assertTrue(aMgr.deleteSMPTransportProfile(aCreate.getID()).isChanged());
        assertEquals(0, aMgr.getAllSMPTransportProfiles().size());
    }
}
Also used : ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) ESMPTransportProfile(com.helger.peppol.smp.ESMPTransportProfile) Test(org.junit.Test)

Example 10 with ISMPTransportProfile

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

the class PageSecureTransportProfiles method showListOfExistingObjects.

@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMPTransportProfileManager aTransportProfileMgr = SMPMetaManager.getTransportProfileMgr();
    aNodeList.addChild(info("This page lets you create custom transport profiles that can be used in service information endpoints."));
    final ICommonsList<ISMPTransportProfile> aList = aTransportProfileMgr.getAllSMPTransportProfiles();
    final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
    aToolbar.addChild(new BootstrapButton().addChild("Create new transport profile").setOnClick(createCreateURL(aWPEC)).setIcon(EDefaultIcon.NEW));
    final ICommonsSet<String> aExistingIDs = new CommonsHashSet<>(aList, ISMPTransportProfile::getID);
    if (!aExistingIDs.containsAll(DEFAULT_PROFILE_IDS)) {
        // Show button only on demand
        aToolbar.addChild(new BootstrapButton().addChild("Ensure all default transport profiles").setOnClick(aWPEC.getSelfHref().add(CPageParam.PARAM_ACTION, ACTION_ENSURE_DEFAULT)).setIcon(EDefaultIcon.PLUS));
    }
    aNodeList.addChild(aToolbar);
    final HCTable aTable = new HCTable(new DTCol("ID").setInitialSorting(ESortOrder.ASCENDING), new DTCol("Name"), new DTCol("Deprecated?"), new BootstrapDTColAction(aDisplayLocale)).setID(getID());
    for (final ISMPTransportProfile aCurObject : aList) {
        final ISimpleURL aViewLink = createViewURL(aWPEC, aCurObject);
        final HCRow aRow = aTable.addBodyRow();
        aRow.addCell(new HCA(aViewLink).addChild(aCurObject.getID()));
        aRow.addCell(aCurObject.getName());
        aRow.addCell(EPhotonCoreText.getYesOrNo(aCurObject.isDeprecated(), 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.getID()) : 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) HCA(com.helger.html.hc.html.textlevel.HCA) HCRow(com.helger.html.hc.html.tabular.HCRow) HCTable(com.helger.html.hc.html.tabular.HCTable) ISMPTransportProfileManager(com.helger.phoss.smp.domain.transportprofile.ISMPTransportProfileManager) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) HCTextNode(com.helger.html.hc.impl.HCTextNode) CommonsHashSet(com.helger.commons.collection.impl.CommonsHashSet) DataTables(com.helger.photon.uictrls.datatables.DataTables) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables)

Aggregations

ISMPTransportProfile (com.helger.peppol.smp.ISMPTransportProfile)10 SMPTransportProfile (com.helger.peppol.smp.SMPTransportProfile)4 ISMPTransportProfileManager (com.helger.phoss.smp.domain.transportprofile.ISMPTransportProfileManager)4 Nullable (javax.annotation.Nullable)4 ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)2 ESMPTransportProfile (com.helger.peppol.smp.ESMPTransportProfile)2 Locale (java.util.Locale)2 CommonsHashSet (com.helger.commons.collection.impl.CommonsHashSet)1 PDTFromString (com.helger.commons.datetime.PDTFromString)1 PDTToString (com.helger.commons.datetime.PDTToString)1 ESuccess (com.helger.commons.state.ESuccess)1 ISimpleURL (com.helger.commons.url.ISimpleURL)1 Wrapper (com.helger.commons.wrapper.Wrapper)1 DBExecutor (com.helger.db.jdbc.executor.DBExecutor)1 DBResultRow (com.helger.db.jdbc.executor.DBResultRow)1 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