use of com.helger.peppolid.IParticipantIdentifier in project phoss-directory by phax.
the class PDStorageManager method getAllContainedParticipantIDs.
@Nonnull
@ReturnsMutableCopy
public ICommonsSortedMap<IParticipantIdentifier, MutableInt> getAllContainedParticipantIDs(@Nonnull final EQueryMode eQueryMode) {
// Map from ID to entity count
final ICommonsSortedMap<IParticipantIdentifier, MutableInt> aTargetSet = new CommonsTreeMap<>();
final Query aQuery = eQueryMode.getEffectiveQuery(new MatchAllDocsQuery());
try {
final ObjIntConsumer<Document> aConsumer = (aDoc, nDocID) -> {
final IParticipantIdentifier aResolvedParticipantID = PDField.PARTICIPANT_ID.getDocValue(aDoc);
aTargetSet.computeIfAbsent(aResolvedParticipantID, k -> new MutableInt(0)).inc();
};
final Collector aCollector = new AllDocumentsCollector(m_aLucene, aConsumer);
searchAtomic(aQuery, aCollector);
} catch (final IOException ex) {
LOGGER.error("Error searching for documents with query " + aQuery, ex);
}
return aTargetSet;
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-directory by phax.
the class AbstractPagePublicSearch method createParticipantDetails.
@Nonnull
protected HCNodeList createParticipantDetails(@Nonnull final Locale aDisplayLocale, @Nonnull final String sParticipantID, @Nonnull final IParticipantIdentifier aParticipantID, final boolean bIsLoggedInUserAdministrator) {
final HCNodeList aDetails = new HCNodeList();
// Search document matching participant ID
final ICommonsList<PDStoredBusinessEntity> aResultDocs = PDMetaManager.getStorageMgr().getAllDocumentsOfParticipant(aParticipantID);
// Group by participant ID
final ICommonsMap<IParticipantIdentifier, ICommonsList<PDStoredBusinessEntity>> aGroupedDocs = PDStorageManager.getGroupedByParticipantID(aResultDocs);
if (aGroupedDocs.isEmpty())
LOGGER.error("No stored document matches participant identifier '" + sParticipantID + "' - cannot show details");
else {
if (aGroupedDocs.size() > 1)
LOGGER.warn("Found " + aGroupedDocs.size() + " entries for participant identifier '" + sParticipantID + "' - weird");
// Get the first one
final ICommonsList<PDStoredBusinessEntity> aStoredEntities = aGroupedDocs.getFirstValue();
// Details header
{
IHCNode aDetailsHeader = null;
final boolean bIsPeppolDefault = aParticipantID.hasScheme(PeppolIdentifierFactory.INSTANCE.getDefaultParticipantIdentifierScheme());
if (bIsPeppolDefault) {
final IParticipantIdentifierScheme aIIA = ParticipantIdentifierSchemeManager.getSchemeOfIdentifier(aParticipantID);
if (aIIA != null) {
final HCH1 aH1 = h1("Details for: " + aParticipantID.getValue());
if (StringHelper.hasText(aIIA.getSchemeAgency()))
aH1.addChild(small(" (" + aIIA.getSchemeAgency() + ")"));
aDetailsHeader = new BootstrapPageHeader().addChild(aH1);
}
}
if (aDetailsHeader == null) {
// Fallback
aDetailsHeader = BootstrapWebPageUIHandler.INSTANCE.createPageHeader("Details for " + sParticipantID);
}
aDetails.addChild(aDetailsHeader);
}
final BootstrapTabBox aTabBox = new BootstrapTabBox();
// Business information
{
final HCNodeList aOL = new HCNodeList();
int nIndex = 1;
for (final PDStoredBusinessEntity aStoredEntity : aStoredEntities) {
final BootstrapCard aCard = aOL.addAndReturnChild(new BootstrapCard());
aCard.addClass(CSS_CLASS_RESULT_PANEL);
if (aStoredEntities.size() > 1)
aCard.createAndAddHeader().addChild("Business information entity " + nIndex);
final BootstrapViewForm aViewForm = PDCommonUI.showBusinessInfoDetails(aStoredEntity, aDisplayLocale);
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Full Peppol participant ID").setCtrl(code(sParticipantID)));
if (GlobalDebug.isDebugMode() || bIsLoggedInUserAdministrator) {
aViewForm.addChild(new HCHR());
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("[Debug] Creation DT").setCtrl(PDTToString.getAsString(aStoredEntity.getMetaData().getCreationDT(), aDisplayLocale)));
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("[Debug] Owner ID").setCtrl(code(aStoredEntity.getMetaData().getOwnerID())));
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("[Debug] Requesting Host").setCtrl(code(aStoredEntity.getMetaData().getRequestingHost())));
}
aCard.createAndAddBody().addChild(aViewForm);
++nIndex;
}
// Add whole list or just the first item?
final IHCNode aTabLabel = span("Business information ").addChild(badgePrimary(aStoredEntities.size()));
aTabBox.addTab("businessinfo", aTabLabel, aOL, true);
}
// Document types
{
final HCNodeList aDocTypeCtrl = new HCNodeList();
final ICommonsList<String> aNames = new CommonsArrayList<>();
for (final PDStoredBusinessEntity aStoredEntity : aStoredEntities) aNames.addAllMapped(aStoredEntity.names(), PDStoredMLName::getName);
aDocTypeCtrl.addChild(info("The following document types are supported by " + _getImplodedMapped(", ", " and ", aNames, x -> "'" + x + "'") + ":"));
HCOL aDocTypeOL = null;
final ICommonsList<IDocumentTypeIdentifier> aDocTypeIDs = aResultDocs.getFirst().documentTypeIDs().getSorted(IDocumentTypeIdentifier.comparator());
for (final IDocumentTypeIdentifier aDocTypeID : aDocTypeIDs) {
if (aDocTypeOL == null)
aDocTypeOL = aDocTypeCtrl.addAndReturnChild(new HCOL());
final HCLI aLI = aDocTypeOL.addItem();
aLI.addChild(NiceNameUI.getDocumentTypeID(aDocTypeID));
}
if (aDocTypeOL == null)
aDocTypeCtrl.addChild(warn("This participant does not support any document types!"));
aTabBox.addTab("doctypes", span("Supported document types ").addChild(badgePrimary(aDocTypeIDs.size())), aDocTypeCtrl, false);
}
aDetails.addChild(aTabBox);
}
return aDetails;
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-directory by phax.
the class PageSecureDeleteManually method fillContent.
@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
final FormErrorList aFormErrors = new FormErrorList();
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()) {
int nDeleted = 0;
try {
nDeleted = PDMetaManager.getStorageMgr().deleteEntry(aParticipantID, null, false);
} catch (final IOException ex) {
// ignore
nDeleted = -1;
}
if (nDeleted > 0)
aWPEC.postRedirectGetInternal(success("The participant ID '" + aParticipantID.getURIEncoded() + "' was deleted (" + nDeleted + " rows)"));
else
aWPEC.postRedirectGetInternal(error("Error deleting participant ID '" + aParticipantID.getURIEncoded() + "'"));
}
}
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 delete.\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("Delete from index", EDefaultIcon.DELETE);
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-directory by phax.
the class IndexerResourceTest method testCreateAndDeleteParticipant.
@Test
public void testCreateAndDeleteParticipant() throws IOException {
final AtomicInteger aIndex = new AtomicInteger(0);
final PeppolIdentifierFactory aIF = PeppolIdentifierFactory.INSTANCE;
// Create
final int nCount = 4;
CommonsTestHelper.testInParallel(nCount, () -> {
final IParticipantIdentifier aPI = aIF.createParticipantIdentifierWithDefaultScheme("9915:test" + aIndex.getAndIncrement());
final String sPayload = aPI.getURIPercentEncoded();
LOGGER.info("PUT " + sPayload);
final String sResponseMsg = m_aTarget.path("1.0").request().put(Entity.text(sPayload), String.class);
assertEquals("", sResponseMsg);
});
LOGGER.info("waiting");
ThreadHelper.sleep(2000);
for (int i = 0; i < nCount; ++i) {
final IParticipantIdentifier aPI = aIF.createParticipantIdentifierWithDefaultScheme("9915:test" + i);
assertTrue(PDMetaManager.getStorageMgr().containsEntry(aPI, EQueryMode.ALL));
}
// Delete
aIndex.set(0);
CommonsTestHelper.testInParallel(nCount, () -> {
final IParticipantIdentifier aPI = aIF.createParticipantIdentifierWithDefaultScheme("9915:test" + aIndex.getAndIncrement());
final String sPI = aPI.getURIEncoded();
LOGGER.info("DELETE " + sPI);
final String sResponseMsg = m_aTarget.path("1.0").path(sPI).request().delete(String.class);
assertEquals("", sResponseMsg);
});
LOGGER.info("waiting");
ThreadHelper.sleep(2000);
for (int i = 0; i < nCount; ++i) {
final IParticipantIdentifier aPI = aIF.createParticipantIdentifierWithDefaultScheme("9915:test" + i);
assertFalse(PDMetaManager.getStorageMgr().containsEntry(aPI, EQueryMode.ALL));
}
// Test with invalid URL encoded ID
{
final String sPayload = "iso6523-actorid-upis%3a%3a9915%3atest0%%%abc";
LOGGER.info("CREATE " + sPayload);
try {
m_aTarget.path("1.0").request().put(Entity.text(sPayload), String.class);
fail();
} catch (final BadRequestException ex) {
// Expected
}
}
}
use of com.helger.peppolid.IParticipantIdentifier in project phoss-directory by phax.
the class IndexerResource method deleteParticipant.
@DELETE
@Path("{participantID}")
public Response deleteParticipant(@Context @Nonnull final HttpServletRequest aHttpServletRequest, @PathParam("participantID") @Nonnull final String sParticipantID) {
final String sLogPrefix = "[deleteParticipant] ";
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 + "'");
return Response.status(Status.BAD_REQUEST).build();
}
// Queue for handling
if (PDMetaManager.getIndexerMgr().queueWorkItem(aPI, EIndexerWorkItemType.DELETE, aResult.getClientID(), _getRequestingHost(aHttpServletRequest)).isUnchanged()) {
if (LOGGER.isInfoEnabled())
LOGGER.info(sLogPrefix + "Ignoring duplicate DELETE request for '" + aPI.getURIEncoded() + "'");
}
// And done
return Response.noContent().build();
}
Aggregations