use of com.helger.photon.bootstrap4.form.BootstrapFormGroup in project phoss-smp by phax.
the class PageSecureEndpointChangeURL method fillContent.
@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final HCNodeList aNodeList = aWPEC.getNodeList();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
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;
int nTotalEndpointCountWithURL = 0;
for (final ISMPServiceInformation aSI : aAllSIs) {
final ISMPServiceGroup aSG = aSI.getServiceGroup();
for (final ISMPProcess aProcess : aSI.getAllProcesses()) for (final ISMPEndpoint aEndpoint : aProcess.getAllEndpoints()) {
++nTotalEndpointCount;
if (aEndpoint.hasEndpointReference()) {
aEndpointsGroupedPerURL.computeIfAbsent(aEndpoint.getEndpointReference(), k -> new CommonsArrayList<>()).add(aEndpoint);
aServiceGroupsGroupedPerURL.computeIfAbsent(aEndpoint.getEndpointReference(), k -> new CommonsHashSet<>()).add(aSG);
++nTotalEndpointCountWithURL;
}
}
}
{
final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
aNodeList.addChild(aToolbar);
final int nCount = BulkChangeEndpointURL.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 sOldURL = aWPEC.params().getAsString(FIELD_OLD_URL);
if (aWPEC.hasSubAction(CPageParam.ACTION_SAVE)) {
// Find selected service group (if any)
final String sServiceGroupID = aWPEC.params().getAsString(FIELD_SERVICE_GROUP);
ISMPServiceGroup aServiceGroup = null;
if (StringHelper.hasText(sServiceGroupID)) {
final IParticipantIdentifier aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
if (aParticipantID != null)
aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aParticipantID);
}
final String sNewURL = aWPEC.params().getAsString(FIELD_NEW_URL);
if (StringHelper.hasNoText(sOldURL))
aFormErrors.addFieldInfo(FIELD_OLD_URL, "An old URL must be provided");
else if (!URLValidator.isValid(sOldURL))
aFormErrors.addFieldInfo(FIELD_OLD_URL, "The old URL is invalid");
if (StringHelper.hasNoText(sNewURL))
aFormErrors.addFieldInfo(FIELD_NEW_URL, "A new URL must be provided");
else if (!URLValidator.isValid(sNewURL))
aFormErrors.addFieldInfo(FIELD_NEW_URL, "The new URL is invalid");
else if (sNewURL.equals(sOldURL))
aFormErrors.addFieldInfo(FIELD_NEW_URL, "The new URL is identical to the old URL");
// Validate parameters
if (aFormErrors.isEmpty()) {
PhotonWorkerPool.getInstance().run("BulkChangeEndpointURL", new BulkChangeEndpointURL(aAllSIs, aServiceGroup, sOldURL, sNewURL));
aWPEC.postRedirectGetInternal(success("The bulk change of the endpoint URL from '" + sOldURL + "' to '" + sNewURL + "' is now running in the background. Please manually refresh the page to see the update."));
}
}
final ICommonsSet<ISMPServiceGroup> aServiceGroups = aServiceGroupsGroupedPerURL.get(sOldURL);
final int nSGCount = CollectionHelper.getSize(aServiceGroups);
final int nEPCount = CollectionHelper.getSize(aEndpointsGroupedPerURL.get(sOldURL));
aNodeList.addChild(info("The selected old URL '" + sOldURL + "' 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));
if (nSGCount > 1) {
// Select the affected service groups if more than one is available
final HCSelect aSGSelect = new HCSelect(new RequestField(FIELD_SERVICE_GROUP));
aSGSelect.addOption(SERVICE_GROUP_ALL, "All affected Service Groups");
if (aServiceGroups != null)
for (final ISMPServiceGroup aSG : aServiceGroups.getSorted(ISMPServiceGroup.comparator())) aSGSelect.addOption(aSG.getID(), aSG.getParticipantIdentifier().getURIEncoded());
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Service group").setCtrl(aSGSelect).setHelpText("If a specific service group is selected, the URL change will only happen in the endpoints of the selected service group. Othwerwise the endpoint is changed in ALL service groups with matching endpoints.").setErrorList(aFormErrors.getListOfField(FIELD_OLD_URL)));
} else {
// If less than 2 service groups are affected, use the 0/1
// automatically.
aForm.addChild(new HCHiddenField(FIELD_SERVICE_GROUP, SERVICE_GROUP_ALL));
}
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Old endpoint URL").setCtrl(new HCEdit(new RequestField(FIELD_OLD_URL, sOldURL))).setHelpText("The old URL that is to be changed in all matching endpoints").setErrorList(aFormErrors.getListOfField(FIELD_OLD_URL)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("New endpoint URL").setCtrl(new HCEdit(new RequestField(FIELD_NEW_URL, sOldURL))).setHelpText("The new URL that is used instead").setErrorList(aFormErrors.getListOfField(FIELD_NEW_URL)));
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 URLs of multiple endpoints at once. This is e.g. helpful when the underlying server got a new URL."), div("Currently " + (nTotalEndpointCount == 1 ? "1 endpoint is" : nTotalEndpointCount + " endpoints are") + " registered" + (nTotalEndpointCountWithURL < nTotalEndpointCount ? " of which " + nTotalEndpointCountWithURL + " have an endpoint reference" : "") + ".")));
final HCTable aTable = new HCTable(new DTCol("Endpoint URL").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((sURL, aEndpoints) -> {
final HCRow aRow = aTable.addBodyRow();
aRow.addCell(sURL);
final int nSGCount = CollectionHelper.getSize(aServiceGroupsGroupedPerURL.get(sURL));
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_URL, sURL);
aRow.addCell(new HCA(aEditURL).setTitle("Change all endpoints pointing to " + sURL).addChild(EDefaultIcon.EDIT.getAsNode()));
});
final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
aNodeList.addChild(aTable).addChild(aDataTables);
}
}
use of com.helger.photon.bootstrap4.form.BootstrapFormGroup in project phoss-smp by phax.
the class PageSecureServiceGroup method showSelectedObject.
@Override
protected void showSelectedObject(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final ISMPServiceGroup aSelectedObject) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final ISMPSettings aSettings = SMPMetaManager.getSettings();
final boolean bShowBusinessCard = CSMP.ENABLE_ISSUE_56 && aSettings.isDirectoryIntegrationEnabled();
aNodeList.addChild(getUIHandler().createActionHeader("Show details of service group '" + aSelectedObject.getID() + "'"));
final BootstrapViewForm aForm = new BootstrapViewForm();
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Participant ID").setCtrl(aSelectedObject.getParticipantIdentifier().getURIEncoded()));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Owning user").setCtrl(SMPCommonUI.getOwnerName(aSelectedObject.getOwnerID())));
if (aSelectedObject.extensions().isNotEmpty())
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Extension").setCtrl(SMPCommonUI.getExtensionDisplay(aSelectedObject)));
if (bShowBusinessCard) {
aForm.addChild(getUIHandler().createDataGroupHeader("Business Card Details"));
final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr();
final ISMPBusinessCard aBC = aBCMgr.getSMPBusinessCardOfServiceGroup(aSelectedObject);
if (aBC != null) {
int nIndex = 0;
for (final SMPBusinessCardEntity aEntity : aBC.getAllEntities()) {
++nIndex;
aForm.addChild(PageSecureBusinessCard.showBusinessCardEntity(aEntity, nIndex, aDisplayLocale));
}
}
}
aNodeList.addChild(aForm);
}
use of com.helger.photon.bootstrap4.form.BootstrapFormGroup in project phoss-smp by phax.
the class PageSecureServiceGroupImport method fillContent.
@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final ISMPSettings aSettings = SMPMetaManager.getSettings();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
final ICommonsSet<String> aAllServiceGroupIDs = aServiceGroupMgr.getAllSMPServiceGroupIDs();
final ICommonsSet<String> aAllBusinessCardIDs = aBusinessCardMgr.getAllSMPBusinessCardIDs();
final FormErrorList aFormErrors = new FormErrorList();
final HCUL aImportResultUL = new HCUL();
if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
// Start import
final IFileItem aImportFile = aWPEC.params().getAsFileItem(FIELD_IMPORT_FILE);
final boolean bOverwriteExisting = aWPEC.params().isCheckBoxChecked(FIELD_OVERWRITE_EXISTING, DEFAULT_OVERWRITE_EXISTING);
final String sDefaultOwnerID = aWPEC.params().getAsString(FIELD_DEFAULT_OWNER);
final IUser aDefaultOwner = aUserMgr.getActiveUserOfID(sDefaultOwnerID);
if (aImportFile == null || aImportFile.getSize() == 0)
aFormErrors.addFieldError(FIELD_IMPORT_FILE, "A file to import must be selected!");
if (StringHelper.hasNoText(sDefaultOwnerID))
aFormErrors.addFieldError(FIELD_DEFAULT_OWNER, "A default owner must be selected!");
else if (aDefaultOwner == null)
aFormErrors.addFieldError(FIELD_DEFAULT_OWNER, "A valid default owner must be selected!");
if (aFormErrors.isEmpty()) {
final SAXReaderSettings aSRS = new SAXReaderSettings();
final IMicroDocument aDoc = MicroReader.readMicroXML(aImportFile, aSRS);
if (aDoc == null || aDoc.getDocumentElement() == null)
aFormErrors.addFieldError(FIELD_IMPORT_FILE, "The provided file is not a valid XML file!");
else {
// Start interpreting
final String sVersion = aDoc.getDocumentElement().getAttributeValue(CSMPExchange.ATTR_VERSION);
if (CSMPExchange.VERSION_10.equals(sVersion)) {
// Version 1.0
final ICommonsList<ImportActionItem> aActionList = new CommonsArrayList<>();
final ImportSummary aImportSummary = new ImportSummary();
ServiceGroupImport.importXMLVer10(aDoc.getDocumentElement(), bOverwriteExisting, aDefaultOwner, aAllServiceGroupIDs, aAllBusinessCardIDs, aActionList, aImportSummary);
for (final ImportActionItem aAction : aActionList) {
final IErrorLevel aErrorLevel = aAction.getErrorLevel();
final EBootstrapBadgeType eBadgeType;
if (aErrorLevel.isGE(EErrorLevel.ERROR))
eBadgeType = EBootstrapBadgeType.DANGER;
else if (aErrorLevel.isGE(EErrorLevel.WARN))
eBadgeType = EBootstrapBadgeType.WARNING;
else if (aErrorLevel.isGE(EErrorLevel.INFO))
eBadgeType = EBootstrapBadgeType.INFO;
else
eBadgeType = EBootstrapBadgeType.SUCCESS;
// By default is is centered
aImportResultUL.addItem(new BootstrapBadge(eBadgeType).addChild((aAction.hasParticipantID() ? "[" + aAction.getParticipantID() + "] " : "") + aAction.getMessage()).addChild(SMPCommonUI.getTechnicalDetailsUI(aAction.getLinkedException())).addClass(CBootstrapCSS.TEXT_LEFT));
}
} else {
// Unsupported or no version present
if (sVersion == null)
aFormErrors.addFieldError(FIELD_IMPORT_FILE, "The provided file cannot be imported because it has the wrong layout.");
else
aFormErrors.addFieldError(FIELD_IMPORT_FILE, "The provided file contains the unsupported version '" + sVersion + "'.");
}
}
}
}
final boolean bHandleBusinessCards = aSettings.isDirectoryIntegrationEnabled();
if (aImportResultUL.hasChildren()) {
final BootstrapCard aPanel = new BootstrapCard();
aPanel.createAndAddHeader().addChild("Import results");
aPanel.createAndAddBody().addChild(aImportResultUL);
aNodeList.addChild(aPanel);
}
aNodeList.addChild(info("Import service groups incl. all endpoints" + (bHandleBusinessCards ? " and business cards" : "") + " from a file."));
final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormFileUploadSelf(aWPEC));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("File to import").setCtrl(new BootstrapFileUpload(FIELD_IMPORT_FILE, aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_IMPORT_FILE)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Overwrite existing elements").setCtrl(new HCCheckBox(new RequestFieldBoolean(FIELD_OVERWRITE_EXISTING, DEFAULT_OVERWRITE_EXISTING))).setHelpText("If this box is checked, all existing endpoints etc. of a service group are deleted and new endpoints are created! If the " + SMPWebAppConfiguration.getDirectoryName() + " integration is enabled, existing business cards contained in the import are also overwritten!").setErrorList(aFormErrors.getListOfField(FIELD_OVERWRITE_EXISTING)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Owner of the new service groups").setCtrl(new HCUserSelect(new RequestField(FIELD_DEFAULT_OWNER), aDisplayLocale)).setHelpText("This owner is only selected, if the owner contained in the import file is unknown.").setErrorList(aFormErrors.getListOfField(FIELD_DEFAULT_OWNER)));
final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(getUIHandler().createToolbar(aWPEC));
aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
aToolbar.addChild(new BootstrapSubmitButton().addChild("Import Service Groups").setIcon(EDefaultIcon.ADD));
}
use of com.helger.photon.bootstrap4.form.BootstrapFormGroup in project phoss-smp by phax.
the class PageSecureServiceGroupMigrationInbound method showInputForm.
@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPParticipantMigration aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bIsFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Migration Key").setCtrl(new HCEdit(new RequestField(FIELD_MIGRATION_KEY))).setHelpText("The migration key received from the other SMP that was acknowledged by the SMK/SML.").setErrorList(aFormErrors.getListOfField(FIELD_MIGRATION_KEY)));
{
final String sDefaultScheme = aIdentifierFactory.getDefaultParticipantIdentifierScheme();
final BootstrapRow aRow = new BootstrapRow();
aRow.createColumn(GS_IDENTIFIER_SCHEME).addChild(new HCEdit(new RequestField(FIELD_PARTICIPANT_ID_SCHEME, aSelectedObject != null ? aSelectedObject.getParticipantIdentifier().getScheme() : sDefaultScheme)).setPlaceholder("Identifier scheme"));
aRow.createColumn(GS_IDENTIFIER_VALUE).addChild(new HCEdit(new RequestField(FIELD_PARTICIPANT_ID_VALUE, aSelectedObject != null ? aSelectedObject.getParticipantIdentifier().getValue() : null)).setPlaceholder("Identifier value"));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Participant ID").setCtrl(aRow).setHelpText("The participant identifier for which the service group should be created. The left part is the identifier scheme" + (sDefaultScheme == null ? "" : " (default: " + sDefaultScheme + ")") + ", the right part is the identifier value (e.g. 9915:test)").setErrorList(aFormErrors.getListOfFields(FIELD_PARTICIPANT_ID_SCHEME, FIELD_PARTICIPANT_ID_VALUE)));
}
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Owning User").setCtrl(new HCUserSelect(new RequestField(FIELD_OWNING_USER_ID, LoggedInUserManager.getInstance().getCurrentUserID()), aDisplayLocale)).setHelpText("The user who owns this entry. Only this user can make changes via the REST API.").setErrorList(aFormErrors.getListOfField(FIELD_OWNING_USER_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Extension").setCtrl(new HCTextArea(new RequestField(FIELD_EXTENSION))).setHelpText("Optional extension to the service group. If present it must be valid XML content!").setErrorList(aFormErrors.getListOfField(FIELD_EXTENSION)));
}
use of com.helger.photon.bootstrap4.form.BootstrapFormGroup in project phoss-smp by phax.
the class PageSecureRedirect method showInputForm.
@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPRedirect aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
final boolean bEdit = eFormAction.isEdit();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
aForm.addChild(getUIHandler().createActionHeader(bEdit ? "Edit Redirect" : "Create new Redirect"));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Service Group").setCtrl(new HCServiceGroupSelect(new RequestField(FIELD_SERVICE_GROUP_ID, aSelectedObject != null ? aSelectedObject.getServiceGroupID() : null), aDisplayLocale).setReadOnly(bEdit)).setErrorList(aFormErrors.getListOfField(FIELD_SERVICE_GROUP_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Document Type ID").setCtrl(new HCEdit(new RequestField(FIELD_DOCTYPE_ID, aSelectedObject != null ? aSelectedObject.getDocumentTypeIdentifier().getURIEncoded() : aIdentifierFactory.getDefaultDocumentTypeIdentifierScheme() + CIdentifier.URL_SCHEME_VALUE_SEPARATOR)).setReadOnly(bEdit)).setErrorList(aFormErrors.getListOfField(FIELD_DOCTYPE_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Redirect To").setCtrl(new HCEdit(new RequestField(FIELD_REDIRECT_TO, aSelectedObject != null ? aSelectedObject.getTargetHref() : null))).setHelpText("URL to redirect to. Must include the service group and the document type in the URL!").setErrorList(aFormErrors.getListOfField(FIELD_REDIRECT_TO)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Subject Unique Identifier").setCtrl(new HCEdit(new RequestField(FIELD_SUBJECT_UNIQUE_IDENTIFIER, aSelectedObject != null ? aSelectedObject.getSubjectUniqueIdentifier() : null))).setHelpText("Holds the Subject Unique Identifier of the certificate of the " + "destination SMP. A client SHOULD validate that the Subject " + "Unique Identifier of the certificate used to sign the resource at the " + "destination SMP matches the Subject Unique Identifier published in " + "the redirecting SMP.").setErrorList(aFormErrors.getListOfField(FIELD_SUBJECT_UNIQUE_IDENTIFIER)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Extension").setCtrl(new HCTextArea(new RequestField(FIELD_EXTENSION, aSelectedObject != null ? aSelectedObject.getFirstExtensionXML() : null))).setHelpText("Optional extension to the service group. If present it must be valid XML content!").setErrorList(aFormErrors.getListOfField(FIELD_EXTENSION)));
}
Aggregations