use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-directory by phax.
the class SMPBusinessCardProvider method getBusinessCardPeppolSMP.
@Nullable
@VisibleForTesting
PDExtendedBusinessCard getBusinessCardPeppolSMP(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final SMPClientReadOnly aSMPClient, @Nonnull final HttpClientSettings aHCS) {
LOGGER.info("Querying BusinessCard for '" + aParticipantID.getURIEncoded() + "' from Peppol SMP '" + aSMPClient.getSMPHostURI() + "'");
// First query the service group
com.helger.xsds.peppol.smp1.ServiceGroupType aServiceGroup;
try {
aServiceGroup = aSMPClient.getServiceGroupOrNull(aParticipantID);
} catch (final SMPClientException ex) {
LOGGER.error("Error querying SMP for ServiceGroup of '" + aParticipantID.getURIEncoded() + "'", ex);
return null;
}
// If the service group is present, try querying the business card
final PDBusinessCard aBusinessCard;
try (final HttpClientManager aHCM = HttpClientManager.create(aHCS)) {
// Use the optional business card API
final HttpGet aRequest = new HttpGet(aSMPClient.getSMPHostURI() + "businesscard/" + aParticipantID.getURIPercentEncoded());
aBusinessCard = aHCM.execute(aRequest, new PDSMPHttpResponseHandlerBusinessCard());
} catch (final IOException ex) {
if ((ex instanceof HttpResponseException && ((HttpResponseException) ex).getStatusCode() == CHttp.HTTP_NOT_FOUND) || ex instanceof UnknownHostException) {
LOGGER.warn("No BusinessCard available for '" + aParticipantID.getURIEncoded() + "' - not in configured SMK/SML? - " + ex.getMessage());
} else
LOGGER.error("Error querying SMP for BusinessCard of '" + aParticipantID.getURIEncoded() + "'", ex);
return null;
}
if (aBusinessCard == null) {
// No extension present - no need to try again
LOGGER.warn("Failed to get SMP BusinessCard of " + aParticipantID.getURIEncoded());
return null;
}
// Query all document types
final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
final ICommonsList<IDocumentTypeIdentifier> aDocumentTypeIDs = SMPClientReadOnly.getAllDocumentTypes(aServiceGroup, aIdentifierFactory, UNHANDLED_HREF_HANDLER);
return new PDExtendedBusinessCard(aBusinessCard, aDocumentTypeIDs);
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-directory by phax.
the class PageSecureParticipantActions method _deleteDuplicateIDs.
private void _deleteDuplicateIDs(@Nonnull final WebPageExecutionContext aWPEC) {
LOGGER.info("Deleting all duplicate participant identifiers");
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final ICommonsMap<IParticipantIdentifier, ICommonsSortedSet<String>> aDupMap = _getDuplicateSourceMap();
final ICommonsSortedSet<String> aPIsToDelete = new CommonsTreeSet<>();
final ICommonsSortedSet<String> aPIsToAdd = new CommonsTreeSet<>();
for (final Map.Entry<IParticipantIdentifier, ICommonsSortedSet<String>> aEntry : aDupMap.entrySet()) {
final ICommonsSortedSet<String> aSet = aEntry.getValue();
final IParticipantIdentifier aPI = aEntry.getKey();
final String sDesiredVersion = aPI.getURIEncoded();
if (aSet.contains(sDesiredVersion)) {
// Simple kill the other ones
aPIsToDelete.addAll(aSet, x -> !x.equals(sDesiredVersion));
} else {
// Remove all and index the correct version
aPIsToDelete.addAll(aSet);
aPIsToAdd.add(sDesiredVersion);
}
}
if (aPIsToDelete.isNotEmpty()) {
final HCNodeList aNL = new HCNodeList();
// Important to use this identifier factory so that the correct key is
// created
final IIdentifierFactory aIF = SimpleIdentifierFactory.INSTANCE;
final PDIndexerManager aIndexerMgr = PDMetaManager.getIndexerMgr();
String sMsg = "Deleting " + aPIsToDelete.size() + " participant ID(s):";
LOGGER.info(sMsg);
aNL.addChild(h2(sMsg));
HCOL aOL = aNL.addAndReturnChild(new HCOL());
for (final String s : aPIsToDelete.getSorted(IComparator.getComparatorCollating(aDisplayLocale))) {
aOL.addItem(s);
aIndexerMgr.queueWorkItem(aIF.parseParticipantIdentifier(s), EIndexerWorkItemType.DELETE, "duplicate-elimination", PDIndexerManager.HOST_LOCALHOST);
}
if (aPIsToAdd.isNotEmpty()) {
sMsg = "Adding " + aPIsToAdd.size() + " participant ID(s) instead:";
LOGGER.info(sMsg);
aNL.addChild(h2(sMsg));
aOL = aNL.addAndReturnChild(new HCOL());
for (final String s : aPIsToAdd.getSorted(IComparator.getComparatorCollating(aDisplayLocale))) {
aOL.addItem(s);
aIndexerMgr.queueWorkItem(aIF.parseParticipantIdentifier(s), EIndexerWorkItemType.CREATE_UPDATE, "duplicate-elimination", PDIndexerManager.HOST_LOCALHOST);
}
}
aWPEC.postRedirectGetInternal(aNL);
} else {
final String sMsg = "Found no duplicate entries to remove";
LOGGER.info(sMsg);
aWPEC.postRedirectGetInternal(success(sMsg));
}
}
use of com.helger.peppolid.factory.IIdentifierFactory 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.factory.IIdentifierFactory 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();
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-directory by phax.
the class IndexerResource method createOrUpdateParticipant.
@PUT
public Response createOrUpdateParticipant(@Context @Nonnull final HttpServletRequest aHttpServletRequest, @Nonnull final String sParticipantID) {
final String sLogPrefix = "[createOrUpdateParticipant] ";
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.CREATE_UPDATE, aResult.getClientID(), _getRequestingHost(aHttpServletRequest)).isUnchanged()) {
if (LOGGER.isInfoEnabled())
LOGGER.info(sLogPrefix + "Ignoring duplicate CREATE/UPDATE request for '" + aPI.getURIEncoded() + "'");
}
// And done
return Response.noContent().build();
}
Aggregations