use of com.helger.photon.bootstrap4.badge.EBootstrapBadgeType 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.badge.EBootstrapBadgeType in project phoss-directory by phax.
the class NiceNameUI method _createFormattedID.
@Nonnull
private static IHCNode _createFormattedID(@Nonnull final String sID, @Nullable final String sName, @Nullable final EBootstrapBadgeType eType, final boolean bIsDeprecated, final boolean bInDetails) {
if (sName == null) {
// No nice name present
if (bInDetails)
return new HCCode().addChild(sID);
return new HCTextNode(sID);
}
final HCNodeList ret = new HCNodeList();
ret.addChild(new BootstrapBadge(eType).addChild(sName));
if (bIsDeprecated) {
ret.addChild(" ").addChild(new BootstrapBadge(EBootstrapBadgeType.WARNING).addChild("Identifier is deprecated"));
}
if (bInDetails) {
ret.addChild(new HCSmall().addChild(" (").addChild(new HCCode().addChild(sID)).addChild(")"));
}
return ret;
}
use of com.helger.photon.bootstrap4.badge.EBootstrapBadgeType in project phoss-smp by phax.
the class NiceNameUI method createFormattedID.
@Nonnull
private static IHCNode createFormattedID(@Nonnull final String sID, @Nullable final String sName, @Nullable final EBootstrapBadgeType eType, final boolean bIsDeprecated, final boolean bInDetails) {
if (sName == null) {
// No nice name present
if (bInDetails)
return new HCCode().addChild(sID);
return new HCTextNode(sID);
}
final HCNodeList ret = new HCNodeList();
ret.addChild(new BootstrapBadge(eType).addChild(sName));
if (bIsDeprecated) {
ret.addChild(" ").addChild(new BootstrapBadge(EBootstrapBadgeType.WARNING).addChild("Identifier is deprecated"));
}
if (bInDetails) {
ret.addChild(new HCSmall().addChild(" (").addChild(new HCCode().addChild(sID)).addChild(")"));
}
return ret;
}
Aggregations