use of com.helger.html.hc.html.forms.HCSelect 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);
}
}
Aggregations