use of com.helger.peppol.sml.ISMLInfo in project phoss-directory by phax.
the class AbstractPageSecureReIndex method showSelectedObject.
@Override
protected void showSelectedObject(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final IReIndexWorkItem aSelectedObject) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final ISMPURLProvider aURLProvider = PDServerConfiguration.getURLProvider();
final IIndexerWorkItem aWorkItem = aSelectedObject.getWorkItem();
final IParticipantIdentifier aParticipantID = aWorkItem.getParticipantID();
final BootstrapViewForm aViewForm = aNodeList.addAndReturnChild(new BootstrapViewForm());
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Creation datetime").setCtrl(PDTToString.getAsString(aWorkItem.getCreationDateTime(), aDisplayLocale)));
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Participant ID").setCtrl(aParticipantID.getURIEncoded()));
final String sBCSuffix = "/businesscard/" + aParticipantID.getURIPercentEncoded();
{
final HCNodeList aURLs = new HCNodeList();
for (final ISMLInfo aSMLInfo : PDPMetaManager.getSMLInfoMgr().getAll()) {
if (aURLs.hasChildren())
aURLs.addChild(div("or"));
try {
aURLs.addChild(div(HCA.createLinkedWebsite(aURLProvider.getSMPURIOfParticipant(aParticipantID, aSMLInfo).toString() + sBCSuffix)));
} catch (final SMPDNSResolutionException ex) {
// Non existing participant!
aURLs.addChild(div(aParticipantID.getURIPercentEncoded() + " on " + aSMLInfo.getDisplayName() + " @ " + sBCSuffix + " [" + ex.getMessage() + "]"));
}
}
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Business Card URL").setCtrl(aURLs));
}
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Action type").setCtrl(aWorkItem.getType().getDisplayName()));
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Owner").setCtrl(aWorkItem.getOwnerID()));
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Requesting host").setCtrl(aWorkItem.getRequestingHost()));
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Retries so far").setCtrl(Integer.toString(aSelectedObject.getRetryCount())));
if (aSelectedObject.hasPreviousRetryDT())
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Previous retry").setCtrl(PDTToString.getAsString(aSelectedObject.getPreviousRetryDT(), aDisplayLocale)));
if (!m_bDeadIndex)
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Next retry").setCtrl(PDTToString.getAsString(aSelectedObject.getNextRetryDT(), aDisplayLocale)));
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Last retry").setCtrl(PDTToString.getAsString(aSelectedObject.getMaxRetryDT(), aDisplayLocale)));
}
use of com.helger.peppol.sml.ISMLInfo in project phoss-directory by phax.
the class PageSecureIndexImport method fillContent.
@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
final FormErrorList aFormErrors = new FormErrorList();
{
final IPDBusinessCardProvider aBCProv = PDMetaManager.getBusinessCardProvider();
if (aBCProv instanceof SMPBusinessCardProvider) {
final SMPBusinessCardProvider aSMPBCProv = (SMPBusinessCardProvider) aBCProv;
if (aSMPBCProv.isFixedSMP()) {
aNodeList.addChild(info("Fixed SMP URI " + aSMPBCProv.getFixedSMPURI() + " is used."));
} else {
aNodeList.addChild(info("The following SMLs are crawled for entries: " + StringHelper.getImplodedMapped(", ", aSMPBCProv.getAllSMLsToUse(), ISMLInfo::getDisplayName)));
}
}
}
final boolean bIsFormSubmitted = aWPEC.hasAction(CPageParam.ACTION_PERFORM);
if (bIsFormSubmitted) {
final IFileItem aFile = aWPEC.params().getAsFileItem(FIELD_FILE);
if (aFile == null || StringHelper.hasNoText(aFile.getName()))
aFormErrors.addFieldError(FIELD_FILE, "No file was selected");
if (aFormErrors.isEmpty()) {
final HCNodeList aResultNL = new HCNodeList();
final SAXReaderSettings aSettings = new SAXReaderSettings();
aSettings.setFeatureValues(EXMLParserFeature.AVOID_DOS_SETTINGS);
final CollectingSAXErrorHandler aErrorHandler = new CollectingSAXErrorHandler();
aSettings.setErrorHandler(aErrorHandler);
final ICommonsList<IParticipantIdentifier> aQueued = new CommonsArrayList<>();
final ICommonsList<IParticipantIdentifier> aNotQueued = new CommonsArrayList<>();
aSettings.setContentHandler(new DefaultHandler() {
@Override
public void startElement(final String sURI, final String sLocalName, final String sQName, final Attributes aAttributes) throws SAXException {
if (sQName.equals("participant")) {
final String sScheme = aAttributes.getValue("scheme");
final String sValue = aAttributes.getValue("value");
final IParticipantIdentifier aParticipantID = aIdentifierFactory.createParticipantIdentifier(sScheme, sValue);
if (aParticipantID != null) {
if (PDMetaManager.getIndexerMgr().queueWorkItem(aParticipantID, EIndexerWorkItemType.CREATE_UPDATE, "import-triggered", PDIndexerManager.HOST_LOCALHOST).isChanged()) {
aQueued.add(aParticipantID);
} else {
aNotQueued.add(aParticipantID);
}
} else
LOGGER.error("Failed to convert '" + sScheme + "' and '" + sValue + "' to a participant identifier");
}
}
});
LOGGER.info("Importing participant IDs from '" + aFile.getNameSecure() + "'");
final ESuccess eSuccess = SAXReader.readXMLSAX(new FileItemResource(aFile), aSettings);
LOGGER.info("Finished reading XML file. Queued " + aQueued.size() + "; not queued: " + aNotQueued.size() + "; errors: " + aErrorHandler.getErrorList().size());
// Some things may have been queued even in case of error
if (aQueued.isNotEmpty()) {
final HCUL aUL = new HCUL();
for (final IParticipantIdentifier aPI : aQueued) aUL.addItem(aPI.getURIEncoded());
aResultNL.addChild(success(div("The following identifiers were successfully queued for indexing:")).addChild(aUL));
}
if (aNotQueued.isNotEmpty()) {
final HCUL aUL = new HCUL();
for (final IParticipantIdentifier aPI : aNotQueued) aUL.addItem(aPI.getURIEncoded());
aResultNL.addChild(warn(div("The following identifiers could not be queued (because they are already in the queue):")).addChild(aUL));
}
if (eSuccess.isFailure()) {
final HCUL aUL = new HCUL();
for (final IError aError : aErrorHandler.getErrorList()) {
final String sMsg = aError.getAsString(AppCommonUI.DEFAULT_LOCALE);
LOGGER.error(" " + sMsg);
aUL.addItem(sMsg);
}
aResultNL.addChild(error(div("Error parsing provided XML:")).addChild(aUL));
}
aWPEC.postRedirectGetInternal(aResultNL);
}
}
final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormFileUploadSelf(aWPEC, bIsFormSubmitted));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Import file").setCtrl(new BootstrapFileUpload(FIELD_FILE, aDisplayLocale)).setHelpText("Select a file that was created from a full XML export to index of all them manually.").setErrorList(aFormErrors.getListOfField(FIELD_FILE)));
final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
aToolbar.addSubmitButton("Import all", EDefaultIcon.YES);
}
use of com.helger.peppol.sml.ISMLInfo in project phoss-smp by phax.
the class SMLInfoManagerMongoDBTest method testConversion.
@Test
public void testConversion() {
final ISMLInfo aInfo = new SMLInfo("displayName", "DNSZone", "https://url/url", true);
final Document aSrc = SMLInfoManagerMongoDB.toBson(aInfo);
assertNotNull(aSrc);
final ISMLInfo aSrc2 = SMLInfoManagerMongoDB.toDomain(aSrc);
assertNotNull(aSrc2);
assertEquals(aInfo, aSrc2);
}
use of com.helger.peppol.sml.ISMLInfo in project phoss-smp by phax.
the class SMPSettingsManagerMongoDBTest method testBasic.
@Test
public void testBasic() {
final ISMLInfoManager aSMLInfoMgr = SMPMetaManager.getSMLInfoMgr();
final ISMLInfo aSMLInfo = aSMLInfoMgr.createSMLInfo("bla", "foo", "http://bar", true);
assertNotNull(aSMLInfo);
try (final SMPSettingsManagerMongoDB aMgr = new SMPSettingsManagerMongoDB()) {
final ISMPSettings aSettings = aMgr.getSettings();
assertNotNull(aSettings);
aMgr.updateSettings(true, true, true, true, "v1", true, true, aSMLInfo.getID());
assertTrue(aSettings.isRESTWritableAPIDisabled());
assertTrue(aSettings.isDirectoryIntegrationRequired());
assertTrue(aSettings.isDirectoryIntegrationEnabled());
assertTrue(aSettings.isDirectoryIntegrationAutoUpdate());
assertEquals("v1", aSettings.getDirectoryHostName());
assertTrue(aSettings.isSMLRequired());
assertTrue(aSettings.isSMLEnabled());
assertEquals(aSMLInfo, aSettings.getSMLInfo());
aMgr.updateSettings(false, false, false, false, "v2", false, false, aSMLInfo.getID());
assertFalse(aSettings.isRESTWritableAPIDisabled());
assertFalse(aSettings.isDirectoryIntegrationRequired());
assertFalse(aSettings.isDirectoryIntegrationEnabled());
assertFalse(aSettings.isDirectoryIntegrationAutoUpdate());
assertEquals("v2", aSettings.getDirectoryHostName());
assertFalse(aSettings.isSMLRequired());
assertFalse(aSettings.isSMLEnabled());
assertEquals(aSMLInfo, aSettings.getSMLInfo());
} finally {
aSMLInfoMgr.deleteSMLInfo(aSMLInfo.getID());
}
}
use of com.helger.peppol.sml.ISMLInfo in project phoss-smp by phax.
the class SMLInfoManagerMongoDB method createSMLInfo.
@Nonnull
public ISMLInfo createSMLInfo(@Nonnull @Nonempty final String sDisplayName, @Nonnull @Nonempty final String sDNSZone, @Nonnull @Nonempty final String sManagementServiceURL, final boolean bClientCertificateRequired) {
final SMLInfo aSMLInfo = new SMLInfo(sDisplayName, sDNSZone, sManagementServiceURL, bClientCertificateRequired);
if (!getCollection().insertOne(toBson(aSMLInfo)).wasAcknowledged())
throw new IllegalStateException("Failed to insert into MongoDB Collection");
AuditHelper.onAuditCreateSuccess(SMLInfo.OT, aSMLInfo.getID(), sDisplayName, sDNSZone, sManagementServiceURL, Boolean.valueOf(bClientCertificateRequired));
return aSMLInfo;
}
Aggregations