use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-directory by phax.
the class PDQueryManager method getDocumentTypeIDLuceneQuery.
@Nullable
public static Query getDocumentTypeIDLuceneQuery(@Nonnull @Nonempty final String sQueryString) {
ValueEnforcer.notEmpty(sQueryString, "QueryString");
ValueEnforcer.notEmpty(sQueryString.trim(), "QueryString trimmed");
final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
// No casing here!
final IDocumentTypeIdentifier aDTI = aIdentifierFactory.parseDocumentTypeIdentifier(sQueryString);
if (aDTI == null) {
LOGGER.warn("Failed to convert '" + sQueryString + "' to document type ID!");
return null;
}
final Query aQuery = new TermQuery(PDField.DOCTYPE_ID.getExactMatchTerm(aDTI));
return aQuery;
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-directory by phax.
the class PDQueryManager method getParticipantIDLuceneQuery.
@Nullable
public static Query getParticipantIDLuceneQuery(@Nonnull @Nonempty final String sQueryString) {
ValueEnforcer.notEmpty(sQueryString, "QueryString");
ValueEnforcer.notEmpty(sQueryString.trim(), "QueryString trimmed");
final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPI = aIdentifierFactory.parseParticipantIdentifier(_lowerCase(sQueryString));
if (aPI == null) {
LOGGER.warn("Failed to convert '" + sQueryString + "' to participant ID!");
return null;
}
final Query aQuery = new TermQuery(PDField.PARTICIPANT_ID.getExactMatchTerm(aPI));
return aQuery;
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-directory by phax.
the class IndexerResource method checkParticipantExistence.
@GET
@Path("{participantID}")
public Response checkParticipantExistence(@Context @Nonnull final HttpServletRequest aHttpServletRequest, @PathParam("participantID") @Nonnull final String sParticipantID) throws IOException {
final String sLogPrefix = "[checkParticipantExistence] ";
final ClientCertificateValidationResult aResult = _checkClientCertificate(aHttpServletRequest, sLogPrefix);
if (aResult.isFailure())
return Response.status(Response.Status.FORBIDDEN).build();
final String sRealParticipantID = _unifyPID(sParticipantID);
if (LOGGER.isInfoEnabled())
LOGGER.info(sLogPrefix + "'" + sRealParticipantID + "'");
// Parse identifier
final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPI = aIdentifierFactory.parseParticipantIdentifier(sRealParticipantID);
if (aPI == null)
if (LOGGER.isErrorEnabled())
LOGGER.error(sLogPrefix + "Failed to parse participant identifier '" + sRealParticipantID + "'");
// Queue for handling
if (!PDMetaManager.getStorageMgr().containsEntry(aPI, EQueryMode.NON_DELETED_ONLY))
return Response.status(Response.Status.NOT_FOUND).build();
// And done
return Response.noContent().build();
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-directory by phax.
the class PageSecureIndexManually method fillContent.
@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
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)));
}
}
}
if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
final String sParticipantID = aWPEC.params().getAsString(FIELD_PARTICIPANT_ID);
final IParticipantIdentifier aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sParticipantID);
if (StringHelper.hasNoText(sParticipantID))
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "A participant ID must be provided.");
else if (aParticipantID == null)
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "The provided participant ID is syntactically invalid.");
if (aFormErrors.isEmpty()) {
if (PDMetaManager.getIndexerMgr().queueWorkItem(aParticipantID, EIndexerWorkItemType.CREATE_UPDATE, "manually-triggered", PDIndexerManager.HOST_LOCALHOST).isChanged()) {
aWPEC.postRedirectGetInternal(success("The indexing of participant ID '" + sParticipantID + "' was successfully triggered!"));
} else {
aWPEC.postRedirectGetInternal(warn("Participant ID '" + sParticipantID + "' is already in the indexing queue!"));
}
}
}
final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Participant ID").setCtrl(new HCEdit(new RequestField(FIELD_PARTICIPANT_ID, PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME + CIdentifier.URL_SCHEME_VALUE_SEPARATOR))).setHelpText(span().addChild("Enter the fully qualified Peppol participant ID (including the scheme) you want to index.\nExample identifier layout: ").addChild(code(aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "9999:test").getURIEncoded()))).setErrorList(aFormErrors.getListOfField(FIELD_PARTICIPANT_ID)));
final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
aToolbar.addSubmitButton("Add to queue", EDefaultIcon.YES);
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-directory by phax.
the class PageSecureParticipantList method fillContent.
@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final IRequestWebScopeWithoutResponse aRequestScope = aWPEC.getRequestScope();
if (aWPEC.hasAction(CPageParam.ACTION_DELETE)) {
final String sParticipantID = aRequestScope.params().getAsString(FIELD_PARTICIPANT_ID);
final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
final IParticipantIdentifier aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sParticipantID);
if (aParticipantID != null) {
boolean bSuccess = false;
try {
bSuccess = PDMetaManager.getStorageMgr().deleteEntry(aParticipantID, null, false) > 0;
} catch (final IOException ex) {
// ignore
}
if (bSuccess)
aNodeList.addChild(info("The participant ID '" + aParticipantID.getURIEncoded() + "' was deleted"));
else
aNodeList.addChild(error("Error deleting participant ID '" + aParticipantID.getURIEncoded() + "'"));
}
}
final ICommonsSortedMap<IParticipantIdentifier, MutableInt> aAllIDs = PDMetaManager.getStorageMgr().getAllContainedParticipantIDs(EQueryMode.NON_DELETED_ONLY);
aNodeList.addChild(h3(aAllIDs.size() + " participants (=Business Cards) are contained"));
int nMaxEntries;
if (aWPEC.params().containsKey(PARAM_SHOW_ALL))
nMaxEntries = Integer.MAX_VALUE;
else {
nMaxEntries = aWPEC.params().getAsInt(PARAM_MAX_ENTRIES, -1);
if (nMaxEntries <= 0) {
// Avoid negative entry count
nMaxEntries = 500;
}
if (aAllIDs.size() > nMaxEntries) {
aNodeList.addChild(info("Showing only the first " + nMaxEntries + " participant(s), to avoid too much load on the server. Use the parameter '" + PARAM_SHOW_ALL + "' to show all participants, or '" + PARAM_MAX_ENTRIES + "' to specify a maximum number of entries."));
}
}
final HCTable aTable = new HCTable(new DTCol("ID").setInitialSorting(ESortOrder.ASCENDING), new DTCol("Entities").setDisplayType(EDTColType.INT, aDisplayLocale), new BootstrapDTColAction()).setID(getID());
for (final Map.Entry<IParticipantIdentifier, MutableInt> aEntry : aAllIDs.entrySet()) {
final String sParticipantID = aEntry.getKey().getURIEncoded();
final HCRow aRow = aTable.addBodyRow();
aRow.addCell(sParticipantID);
aRow.addCell(Integer.toString(aEntry.getValue().intValue()));
final IHCCell<?> aActionCell = aRow.addCell();
final ISimpleURL aShowDetails = aWPEC.getLinkToMenuItem(CApplicationID.APP_ID_PUBLIC, CMenuPublic.MENU_SEARCH_SIMPLE).add(PagePublicSearchSimple.FIELD_QUERY, sParticipantID).add(CPageParam.PARAM_ACTION, CPageParam.ACTION_VIEW).add(PagePublicSearchSimple.FIELD_PARTICIPANT_ID, sParticipantID);
aActionCell.addChild(new HCA(aShowDetails).addChild("Search"));
aActionCell.addChild(" ");
final ISimpleURL aReIndex = aWPEC.getLinkToMenuItem(CMenuSecure.MENU_INDEX_MANUALLY).add(PageSecureIndexManually.FIELD_PARTICIPANT_ID, sParticipantID).add(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
aActionCell.addChild(new HCA(aReIndex).addChild("Reindex"));
aActionCell.addChild(" ");
final ISimpleURL aDelete = aWPEC.getSelfHref().add(FIELD_PARTICIPANT_ID, sParticipantID).add(CPageParam.PARAM_ACTION, CPageParam.ACTION_DELETE);
aActionCell.addChild(new HCA(aDelete).addChild("Delete"));
if (aTable.getBodyRowCount() >= nMaxEntries) {
LOGGER.info("Stopping rendering after " + nMaxEntries + " entries");
break;
}
}
aNodeList.addChild(aTable).addChild(BootstrapDataTables.createDefaultDataTables(aWPEC, aTable));
}
Aggregations