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);
}
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;
}
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;
}
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());
}
}
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);
}
Aggregations