Search in sources :

Example 41 with IIdentifierFactory

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;
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) Nullable(javax.annotation.Nullable)

Example 42 with IIdentifierFactory

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;
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nullable(javax.annotation.Nullable)

Example 43 with IIdentifierFactory

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();
}
Also used : IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ClientCertificateValidationResult(com.helger.pd.indexer.clientcert.ClientCertificateValidationResult) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 44 with IIdentifierFactory

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);
}
Also used : SMPBusinessCardProvider(com.helger.pd.indexer.businesscard.SMPBusinessCardProvider) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMLInfo(com.helger.peppol.sml.ISMLInfo) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) IPDBusinessCardProvider(com.helger.pd.indexer.businesscard.IPDBusinessCardProvider) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) RequestField(com.helger.photon.core.form.RequestField)

Example 45 with IIdentifierFactory

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));
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCA(com.helger.html.hc.html.textlevel.HCA) HCRow(com.helger.html.hc.html.tabular.HCRow) IOException(java.io.IOException) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) HCTable(com.helger.html.hc.html.tabular.HCTable) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) MutableInt(com.helger.commons.mutable.MutableInt) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) Map(java.util.Map) ICommonsSortedMap(com.helger.commons.collection.impl.ICommonsSortedMap) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Aggregations

IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)82 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)56 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)34 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)33 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)29 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)22 IUser (com.helger.photon.security.user.IUser)20 Test (org.junit.Test)19 Nonnull (javax.annotation.Nonnull)18 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)17 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)16 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)15 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)13 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)13 Locale (java.util.Locale)11 Nullable (javax.annotation.Nullable)11 HCNodeList (com.helger.html.hc.impl.HCNodeList)9 ISMPRedirect (com.helger.phoss.smp.domain.redirect.ISMPRedirect)9 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)9 ISMPServerAPIDataProvider (com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider)8