use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class AbstractPageSecureEndpoint method showInputForm.
@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPServiceInformation aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
final boolean bEdit = eFormAction.isEdit();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final ISMPProcess aSelectedProcess = aWPEC.getRequestScope().attrs().getCastedValue(REQUEST_ATTR_PROCESS);
final ISMPEndpoint aSelectedEndpoint = aWPEC.getRequestScope().attrs().getCastedValue(REQUEST_ATTR_ENDPOINT);
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
aForm.addChild(getUIHandler().createActionHeader(bEdit ? "Edit endpoint" : "Create new endpoint"));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Service group").setCtrl(new HCServiceGroupSelect(new RequestField(FIELD_SERVICE_GROUP_ID, aSelectedObject != null ? aSelectedObject.getServiceGroupID() : null), aDisplayLocale).setReadOnly(bEdit)).setErrorList(aFormErrors.getListOfField(FIELD_SERVICE_GROUP_ID)));
{
final BootstrapRow aRow = new BootstrapRow();
aRow.createColumn(GS_IDENTIFIER_SCHEME).addChild(new HCEdit(new RequestField(FIELD_DOCTYPE_ID_SCHEME, aSelectedObject != null ? aSelectedObject.getDocumentTypeIdentifier().getScheme() : aIdentifierFactory.getDefaultDocumentTypeIdentifierScheme())).setPlaceholder("Identifier scheme").setReadOnly(bEdit));
aRow.createColumn(GS_IDENTIFIER_VALUE).addChild(new HCEdit(new RequestField(FIELD_DOCTYPE_ID_VALUE, aSelectedObject != null ? aSelectedObject.getDocumentTypeIdentifier().getValue() : null)).setPlaceholder("Identifier value").setReadOnly(bEdit));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Document type ID").setCtrl(aRow).setErrorList(aFormErrors.getListOfFields(FIELD_DOCTYPE_ID_SCHEME, FIELD_DOCTYPE_ID_VALUE)));
}
{
final BootstrapRow aRow = new BootstrapRow();
aRow.createColumn(GS_IDENTIFIER_SCHEME).addChild(new HCEdit(new RequestField(FIELD_PROCESS_ID_SCHEME, aSelectedProcess != null ? aSelectedProcess.getProcessIdentifier().getScheme() : aIdentifierFactory.getDefaultProcessIdentifierScheme())).setPlaceholder("Identifier scheme").setReadOnly(bEdit));
aRow.createColumn(GS_IDENTIFIER_VALUE).addChild(new HCEdit(new RequestField(FIELD_PROCESS_ID_VALUE, aSelectedProcess != null ? aSelectedProcess.getProcessIdentifier().getValue() : null)).setPlaceholder("Identifier value").setReadOnly(bEdit));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Process ID").setCtrl(aRow).setErrorList(aFormErrors.getListOfFields(FIELD_PROCESS_ID_SCHEME, FIELD_PROCESS_ID_VALUE)));
}
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Transport Profile").setCtrl(new HCSMPTransportProfileSelect(new RequestField(FIELD_TRANSPORT_PROFILE, aSelectedEndpoint != null ? aSelectedEndpoint.getTransportProfile() : ESMPTransportProfile.TRANSPORT_PROFILE_AS2.getID())).setReadOnly(bEdit)).setErrorList(aFormErrors.getListOfField(FIELD_TRANSPORT_PROFILE)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Endpoint Reference").setCtrl(new HCEdit(new RequestField(FIELD_ENDPOINT_REFERENCE, aSelectedEndpoint != null ? aSelectedEndpoint.getEndpointReference() : null))).setHelpText("The URL where messsages of this type should be targeted to.").setErrorList(aFormErrors.getListOfField(FIELD_ENDPOINT_REFERENCE)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Requires Business Level Signature").setCtrl(new HCCheckBox(new RequestFieldBoolean(FIELD_REQUIRES_BUSINESS_LEVEL_SIGNATURE, aSelectedEndpoint != null ? aSelectedEndpoint.isRequireBusinessLevelSignature() : SMPEndpoint.DEFAULT_REQUIRES_BUSINESS_LEVEL_SIGNATURE))).setHelpText("Check the box if the recipient requires business-level signatures for " + "the message, meaning a signature applied to the business message " + "before the message is put on the transport. This is independent of " + "the transport-level signatures that a specific transport profile, such " + "as the START profile, might mandate. This flag does not indicate " + "which type of business-level signature might be required. Setting or " + "consuming business-level signatures would typically be the " + "responsibility of the final senders and receivers of messages, rather " + "than a set of APs.").setErrorList(aFormErrors.getListOfField(FIELD_REQUIRES_BUSINESS_LEVEL_SIGNATURE)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Minimum Authentication Level").setCtrl(new HCEdit(new RequestField(FIELD_MINIMUM_AUTHENTICATION_LEVEL, aSelectedEndpoint != null ? aSelectedEndpoint.getMinimumAuthenticationLevel() : null))).setHelpText("Indicates the minimum authentication level that recipient requires. " + "The specific semantics of this field is defined in a specific instance " + "of the BUSDOX infrastructure. It could for example reflect the " + "value of the \"urn:eu:busdox:attribute:assurance-level\" SAML " + "attribute defined in the START specification.").setErrorList(aFormErrors.getListOfField(FIELD_MINIMUM_AUTHENTICATION_LEVEL)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Not before").setCtrl(BootstrapDateTimePicker.create(FIELD_NOT_BEFORE, aSelectedEndpoint != null ? aSelectedEndpoint.getServiceActivationDate() : null, aDisplayLocale)).setHelpText("Activation date of the service. Senders should ignore services that " + "are not yet activated.").setErrorList(aFormErrors.getListOfField(FIELD_NOT_BEFORE)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Not after").setCtrl(BootstrapDateTimePicker.create(FIELD_NOT_AFTER, aSelectedEndpoint != null ? aSelectedEndpoint.getServiceExpirationDate() : null, aDisplayLocale)).setHelpText("Expiration date of the service. Senders should ignore services that " + "are expired.").setErrorList(aFormErrors.getListOfField(FIELD_NOT_AFTER)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Certificate").setCtrl(new HCTextArea(new RequestField(FIELD_CERTIFICATE, aSelectedEndpoint != null ? aSelectedEndpoint.getCertificate() : null))).setHelpText("Holds the complete signing certificate of the recipient AP, as a " + "PEM base 64 encoded X509 DER formatted value.").setErrorList(aFormErrors.getListOfField(FIELD_CERTIFICATE)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Service Description").setCtrl(new HCEdit(new RequestField(FIELD_SERVICE_DESCRIPTION, aSelectedEndpoint != null ? aSelectedEndpoint.getServiceDescription() : null))).setHelpText("A human readable description of the service.").setErrorList(aFormErrors.getListOfField(FIELD_SERVICE_DESCRIPTION)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Technical Contact").setCtrl(new HCEdit(new RequestField(FIELD_TECHNICAL_CONTACT, aSelectedEndpoint != null ? aSelectedEndpoint.getTechnicalContactUrl() : null))).setHelpText("Represents a link to human readable contact information. This " + "might also be an email address.").setErrorList(aFormErrors.getListOfField(FIELD_TECHNICAL_CONTACT)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Technical Information").setCtrl(new HCEdit(new RequestField(FIELD_TECHNICAL_INFORMATION, aSelectedEndpoint != null ? aSelectedEndpoint.getTechnicalInformationUrl() : null))).setHelpText("A URL to human readable documentation of the service format. " + "This could for example be a web site containing links to XML " + "Schemas, WSDLs, Schematrons and other relevant resources.").setErrorList(aFormErrors.getListOfField(FIELD_TECHNICAL_INFORMATION)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Extension").setCtrl(new HCTextArea(new RequestField(FIELD_EXTENSION, aSelectedEndpoint != null ? aSelectedEndpoint.getFirstExtensionXML() : null))).setHelpText("Optional extension to the endpoint. If present it must be valid XML content!").setErrorList(aFormErrors.getListOfField(FIELD_EXTENSION)));
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class AbstractPageSecureEndpoint method validateAndSaveInputParameters.
@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPServiceInformation aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
final boolean bEdit = eFormAction.isEdit();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final ISMPProcess aSelectedProcess = aWPEC.getRequestScope().attrs().getCastedValue(REQUEST_ATTR_PROCESS);
final ISMPEndpoint aSelectedEndpoint = aWPEC.getRequestScope().attrs().getCastedValue(REQUEST_ATTR_ENDPOINT);
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
final ISMPTransportProfileManager aTransportProfileMgr = SMPMetaManager.getTransportProfileMgr();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final String sServiceGroupID = bEdit ? aSelectedObject.getServiceGroupID() : aWPEC.params().getAsStringTrimmed(FIELD_SERVICE_GROUP_ID);
ISMPServiceGroup aServiceGroup = null;
final String sDocTypeIDScheme = bEdit ? aSelectedObject.getDocumentTypeIdentifier().getScheme() : aWPEC.params().getAsStringTrimmed(FIELD_DOCTYPE_ID_SCHEME);
final String sDocTypeIDValue = bEdit ? aSelectedObject.getDocumentTypeIdentifier().getValue() : aWPEC.params().getAsStringTrimmed(FIELD_DOCTYPE_ID_VALUE);
IDocumentTypeIdentifier aDocTypeID = null;
final String sProcessIDScheme = bEdit ? aSelectedProcess.getProcessIdentifier().getScheme() : aWPEC.params().getAsStringTrimmed(FIELD_PROCESS_ID_SCHEME);
final String sProcessIDValue = bEdit ? aSelectedProcess.getProcessIdentifier().getValue() : aWPEC.params().getAsStringTrimmed(FIELD_PROCESS_ID_VALUE);
IProcessIdentifier aProcessID = null;
final String sTransportProfileID = bEdit ? aSelectedEndpoint.getTransportProfile() : aWPEC.params().getAsStringTrimmed(FIELD_TRANSPORT_PROFILE);
final ISMPTransportProfile aTransportProfile = aTransportProfileMgr.getSMPTransportProfileOfID(sTransportProfileID);
final String sEndpointReference = aWPEC.params().getAsStringTrimmed(FIELD_ENDPOINT_REFERENCE);
final boolean bRequireBusinessLevelSignature = aWPEC.params().getAsBoolean(FIELD_REQUIRES_BUSINESS_LEVEL_SIGNATURE);
final String sMinimumAuthenticationLevel = aWPEC.params().getAsStringTrimmed(FIELD_MINIMUM_AUTHENTICATION_LEVEL);
final String sNotBefore = aWPEC.params().getAsStringTrimmed(FIELD_NOT_BEFORE);
final LocalDate aNotBeforeDate = PDTFromString.getLocalDateFromString(sNotBefore, aDisplayLocale);
final String sNotAfter = aWPEC.params().getAsStringTrimmed(FIELD_NOT_AFTER);
final LocalDate aNotAfterDate = PDTFromString.getLocalDateFromString(sNotAfter, aDisplayLocale);
final String sCertificate = aWPEC.params().getAsStringTrimmed(FIELD_CERTIFICATE);
final String sServiceDescription = aWPEC.params().getAsStringTrimmed(FIELD_SERVICE_DESCRIPTION);
final String sTechnicalContact = aWPEC.params().getAsStringTrimmed(FIELD_TECHNICAL_CONTACT);
final String sTechnicalInformation = aWPEC.params().getAsStringTrimmed(FIELD_TECHNICAL_INFORMATION);
final String sExtension = aWPEC.params().getAsStringTrimmed(FIELD_EXTENSION);
// validations
if (StringHelper.hasNoText(sServiceGroupID))
aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "A service group must be selected!");
else {
aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID));
if (aServiceGroup == null)
aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "The provided service group does not exist!");
}
if (aIdentifierFactory.isDocumentTypeIdentifierSchemeMandatory() && StringHelper.hasNoText(sDocTypeIDScheme))
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_SCHEME, "Document type ID scheme must not be empty!");
else if (StringHelper.hasNoText(sDocTypeIDValue))
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE, "Document type ID value must not be empty!");
else {
aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(sDocTypeIDScheme, sDocTypeIDValue);
if (aDocTypeID == null)
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE, "The provided document type ID has an invalid syntax!");
else {
if (aServiceGroup != null)
if (aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID) != null)
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE, "At least one redirect is registered for this document type. Delete the redirect before you can create an endpoint.");
}
}
if (aIdentifierFactory.isProcessIdentifierSchemeMandatory() && StringHelper.hasNoText(sProcessIDScheme))
aFormErrors.addFieldError(FIELD_PROCESS_ID_SCHEME, "Process ID scheme must not be empty!");
else if (StringHelper.hasNoText(sProcessIDValue))
aFormErrors.addFieldError(FIELD_PROCESS_ID_SCHEME, "Process ID value must not be empty!");
else {
aProcessID = aIdentifierFactory.createProcessIdentifier(sProcessIDScheme, sProcessIDValue);
if (aProcessID == null)
aFormErrors.addFieldError(FIELD_PROCESS_ID_VALUE, "The provided process ID has an invalid syntax!");
}
if (StringHelper.hasNoText(sTransportProfileID))
aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE, "Transport Profile must not be empty!");
else if (aTransportProfile == null)
aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE, "Transport Profile of type '" + sTransportProfileID + "' does not exist!");
if (!bEdit && aServiceGroup != null && aDocTypeID != null && aProcessID != null && aTransportProfile != null && aServiceInfoMgr.findServiceInformation(aServiceGroup, aDocTypeID, aProcessID, aTransportProfile) != null) {
final String sMsg = "Another endpoint for the provided service group, document type, process and transport profile is already present. Some of the identifiers may be treated case insensitive!";
aFormErrors.addFieldError(FIELD_DOCTYPE_ID_VALUE, sMsg);
aFormErrors.addFieldError(FIELD_PROCESS_ID_VALUE, sMsg);
aFormErrors.addFieldError(FIELD_TRANSPORT_PROFILE, sMsg);
}
if (StringHelper.hasNoText(sEndpointReference)) {
if (false)
aFormErrors.addFieldError(FIELD_ENDPOINT_REFERENCE, "Endpoint Reference must not be empty!");
} else if (URLHelper.getAsURL(sEndpointReference) == null)
aFormErrors.addFieldError(FIELD_ENDPOINT_REFERENCE, "The Endpoint Reference is not a valid URL!");
if (aNotBeforeDate != null && aNotAfterDate != null)
if (aNotBeforeDate.isAfter(aNotAfterDate))
aFormErrors.addFieldError(FIELD_NOT_BEFORE, "Not Before Date must not be after Not After Date!");
if (StringHelper.hasNoText(sCertificate))
aFormErrors.addFieldError(FIELD_CERTIFICATE, "Certificate must not be empty!");
else {
X509Certificate aCert = null;
try {
aCert = CertificateHelper.convertStringToCertficate(sCertificate);
} catch (final CertificateException ex) {
// Fall through
}
if (aCert == null)
aFormErrors.addFieldError(FIELD_CERTIFICATE, "The provided certificate string is not a valid X509 certificate!");
}
if (StringHelper.hasNoText(sServiceDescription))
aFormErrors.addFieldError(FIELD_SERVICE_DESCRIPTION, "Service Description must not be empty!");
if (StringHelper.hasNoText(sTechnicalContact))
aFormErrors.addFieldError(FIELD_TECHNICAL_CONTACT, "Technical Contact must not be empty!");
if (StringHelper.hasText(sExtension)) {
final IMicroDocument aDoc = MicroReader.readMicroXML(sExtension);
if (aDoc == null)
aFormErrors.addFieldError(FIELD_EXTENSION, "The extension must be XML content.");
}
if (aFormErrors.isEmpty()) {
ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID);
if (aServiceInfo == null)
aServiceInfo = new SMPServiceInformation(aServiceGroup, aDocTypeID, null, null);
ISMPProcess aProcess = aServiceInfo.getProcessOfID(aProcessID);
if (aProcess == null) {
aProcess = new SMPProcess(aProcessID, null, null);
aServiceInfo.addProcess((SMPProcess) aProcess);
}
aProcess.setEndpoint(new SMPEndpoint(sTransportProfileID, sEndpointReference, bRequireBusinessLevelSignature, sMinimumAuthenticationLevel, PDTFactory.createXMLOffsetDateTime(aNotBeforeDate), PDTFactory.createXMLOffsetDateTime(aNotAfterDate), sCertificate, sServiceDescription, sTechnicalContact, sTechnicalInformation, sExtension));
if (aServiceInfoMgr.mergeSMPServiceInformation(aServiceInfo).isSuccess()) {
if (bEdit) {
aWPEC.postRedirectGetInternal(success("Successfully edited the endpoint for service group '" + aServiceGroup.getParticipantIdentifier().getURIEncoded() + "'."));
} else {
aWPEC.postRedirectGetInternal(success("Successfully created a new endpoint for service group '" + aServiceGroup.getParticipantIdentifier().getURIEncoded() + "'."));
}
} else {
if (bEdit) {
aWPEC.postRedirectGetInternal(error("Error editing the endpoint for service group '" + aServiceGroup.getParticipantIdentifier().getURIEncoded() + "'."));
} else {
aWPEC.postRedirectGetInternal(error("Error creating a new endpoint for service group '" + aServiceGroup.getParticipantIdentifier().getURIEncoded() + "'."));
}
}
}
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class APIExecutorMigrationOutboundFinalizePut method invokeAPI.
public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
final String sServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sServiceGroupID);
// Is the writable API disabled?
if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
throw new SMPPreconditionFailedException("The writable REST API is disabled. migrationOutboundFinalize will not be executed", aDataProvider.getCurrentURI());
}
final String sLogPrefix = "[REST API Migration-Outbound-Finalize] ";
LOGGER.info(sLogPrefix + "Finalizing outbound migration for Service Group ID '" + sServiceGroupID + "'");
// Only authenticated user may do so
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
SMPUserManagerPhoton.validateUserCredentials(aBasicAuth);
final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
if (aServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sServiceGroupID, aDataProvider.getCurrentURI());
}
// Find matching migration object
final ISMPParticipantMigration aMigration = aParticipantMigrationMgr.getParticipantMigrationOfParticipantID(EParticipantMigrationDirection.OUTBOUND, EParticipantMigrationState.IN_PROGRESS, aServiceGroupID);
if (aMigration == null) {
throw new SMPBadRequestException("Failed to resolve outbound participant migration for Service Group ID '" + sServiceGroupID + "'", aDataProvider.getCurrentURI());
}
// Remember the old state
final String sMigrationID = aMigration.getID();
final EParticipantMigrationState eOldState = aMigration.getState();
// Migrate state
if (aParticipantMigrationMgr.setParticipantMigrationState(sMigrationID, EParticipantMigrationState.MIGRATED).isUnchanged()) {
throw new SMPBadRequestException("The participant migration with ID '" + sMigrationID + "' is already finalized", aDataProvider.getCurrentURI());
}
LOGGER.info(sLogPrefix + "The outbound Participant Migration with ID '" + sMigrationID + "' for '" + sServiceGroupID + "' was successfully finalized!");
try {
// in the SML
if (aServiceGroupMgr.deleteSMPServiceGroup(aServiceGroupID, false).isChanged()) {
LOGGER.info(sLogPrefix + "The SMP Service Group for participant '" + sServiceGroupID + "' was successfully deleted from this SMP (without SML)!");
} else {
throw new SMPBadRequestException("The SMP Service Group for participant '" + sServiceGroupID + "' could not be deleted", aDataProvider.getCurrentURI());
}
} catch (final SMPServerException ex) {
// manager
if (aParticipantMigrationMgr.setParticipantMigrationState(sMigrationID, eOldState).isChanged()) {
LOGGER.warn(sLogPrefix + "Successfully reverted the state of the outbound Participant Migration for '" + sServiceGroupID + "' to " + eOldState + "!");
} else {
// Error in error handling. Yeah
LOGGER.error(sLogPrefix + "Failed to revert the state of the outbound Participant Migration for '" + sServiceGroupID + "' to " + eOldState + "!");
}
throw ex;
}
aUnifiedResponse.setStatus(CHttp.HTTP_OK).disableCaching();
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class APIExecutorMigrationOutboundStartPut method invokeAPI.
public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
final String sServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sServiceGroupID);
// Is the writable API disabled?
if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
throw new SMPPreconditionFailedException("The writable REST API is disabled. migrationOutboundStart will not be executed", aDataProvider.getCurrentURI());
}
final String sLogPrefix = "[REST API Migration-Outbound-Start] ";
LOGGER.info(sLogPrefix + "Starting outbound migration for Service Group ID '" + sServiceGroupID + "'");
// Only authenticated user may do so
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
SMPUserManagerPhoton.validateUserCredentials(aBasicAuth);
final ISMPSettings aSettings = SMPMetaManager.getSettings();
final ISMLInfo aSMLInfo = aSettings.getSMLInfo();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
if (aSMLInfo == null) {
throw new SMPPreconditionFailedException("Currently no SML is available. Please select it in the UI at the 'SMP Settings' page", aDataProvider.getCurrentURI());
}
if (!aSettings.isSMLEnabled()) {
throw new SMPPreconditionFailedException("SML Connection is not enabled hence no participant can be migrated", aDataProvider.getCurrentURI());
}
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
if (aServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sServiceGroupID, aDataProvider.getCurrentURI());
}
// Check that service group exists
if (!aServiceGroupMgr.containsSMPServiceGroupWithID(aServiceGroupID)) {
throw new SMPBadRequestException("The Service Group '" + sServiceGroupID + "' does not exist", aDataProvider.getCurrentURI());
}
// Ensure no existing migration is in process
if (aParticipantMigrationMgr.containsOutboundMigrationInProgress(aServiceGroupID)) {
throw new SMPBadRequestException("The outbound Participant Migration of the Service Group '" + sServiceGroupID + "' is already in progress", aDataProvider.getCurrentURI());
}
String sMigrationKey = null;
try {
final ManageParticipantIdentifierServiceCaller aCaller = new ManageParticipantIdentifierServiceCaller(aSMLInfo);
aCaller.setSSLSocketFactory(SMPKeyManager.getInstance().createSSLContext().getSocketFactory());
// Create a random migration key,
// Than call SML
sMigrationKey = aCaller.prepareToMigrate(aServiceGroupID, SMPServerConfiguration.getSMLSMPID());
LOGGER.info(sLogPrefix + "Successfully called prepareToMigrate on SML. Created migration key is '" + sMigrationKey + "'");
} catch (final BadRequestFault | InternalErrorFault | NotFoundFault | UnauthorizedFault | ClientTransportException ex) {
throw new SMPSMLException("Failed to call prepareToMigrate on SML for Service Group '" + sServiceGroupID + "'", ex);
}
// Remember internally
final ISMPParticipantMigration aMigration = aParticipantMigrationMgr.createOutboundParticipantMigration(aServiceGroupID, sMigrationKey);
if (aMigration == null) {
throw new SMPInternalErrorException("Failed to create outbound Participant Migration for '" + sServiceGroupID + "' internally");
}
LOGGER.info(sLogPrefix + "Successfully created outbound Participant Migration with ID '" + aMigration.getID() + "' internally.");
// Build result
final IMicroDocument aResponseDoc = new MicroDocument();
final IMicroElement eRoot = aResponseDoc.appendElement("migrationOutboundResponse");
eRoot.setAttribute("success", true);
eRoot.appendElement(XML_ELEMENT_PARTICIPANT_ID).appendText(sServiceGroupID);
eRoot.appendElement(XML_ELEMENT_MIGRATION_KEY).appendText(sMigrationKey);
final XMLWriterSettings aXWS = new XMLWriterSettings().setIndent(EXMLSerializeIndent.INDENT_AND_ALIGN);
aUnifiedResponse.setContentAndCharset(MicroWriter.getNodeAsString(aResponseDoc, aXWS), aXWS.getCharset()).setMimeType(new MimeType(CMimeType.APPLICATION_XML).addParameter(CMimeType.PARAMETER_NAME_CHARSET, aXWS.getCharset().name())).disableCaching();
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class APIExecutorQueryGetServiceMetadata method invokeAPI.
public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
final String sPathServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sPathServiceGroupID);
// Is the remote query API disabled?
if (SMPServerConfiguration.isRestRemoteQueryAPIDisabled()) {
throw new SMPPreconditionFailedException("The remote query API is disabled. getRemoteServiceInformation will not be executed", aDataProvider.getCurrentURI());
}
final IIdentifierFactory aIF = SMPMetaManager.getIdentifierFactory();
final ESMPAPIType eAPIType = SMPServerConfiguration.getRESTType().getAPIType();
final IParticipantIdentifier aParticipantID = aIF.parseParticipantIdentifier(sPathServiceGroupID);
if (aParticipantID == null) {
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, aDataProvider.getCurrentURI());
}
final SMPQueryParams aQueryParams = SMPQueryParams.create(eAPIType, aParticipantID);
final String sDocTypeID = aPathVariables.get(SMPRestFilter.PARAM_DOCUMENT_TYPE_ID);
final IDocumentTypeIdentifier aDocTypeID = aIF.parseDocumentTypeIdentifier(sDocTypeID);
if (aDocTypeID == null)
throw SMPBadRequestException.failedToParseDocType(sDocTypeID, null);
final boolean bXMLSchemaValidation = aRequestScope.params().getAsBoolean("xmlSchemaValidation", true);
final boolean bVerifySignature = aRequestScope.params().getAsBoolean("verifySignature", true);
final ZonedDateTime aQueryDT = PDTFactory.getCurrentZonedDateTimeUTC();
final StopWatch aSW = StopWatch.createdStarted();
final String sLogPrefix = "[QueryAPI] ";
LOGGER.info(sLogPrefix + "Participant information of '" + aParticipantID.getURIEncoded() + "' is queried using SMP API '" + eAPIType + "' from '" + aQueryParams.getSMPHostURI() + "' for document type '" + aDocTypeID.getURIEncoded() + "'; XSD validation=" + bXMLSchemaValidation + "; signature verification=" + bVerifySignature);
IJsonObject aJson = null;
switch(eAPIType) {
case PEPPOL:
{
final SMPClientReadOnly aSMPClient = new SMPClientReadOnly(aQueryParams.getSMPHostURI());
aSMPClient.setXMLSchemaValidation(bXMLSchemaValidation);
aSMPClient.setVerifySignature(bVerifySignature);
final com.helger.xsds.peppol.smp1.SignedServiceMetadataType aSSM = aSMPClient.getServiceMetadataOrNull(aParticipantID, aDocTypeID);
if (aSSM != null) {
final com.helger.xsds.peppol.smp1.ServiceMetadataType aSM = aSSM.getServiceMetadata();
aJson = SMPJsonResponse.convert(aParticipantID, aDocTypeID, aSM);
}
break;
}
case OASIS_BDXR_V1:
{
final BDXRClientReadOnly aBDXR1Client = new BDXRClientReadOnly(aQueryParams.getSMPHostURI());
aBDXR1Client.setXMLSchemaValidation(bXMLSchemaValidation);
aBDXR1Client.setVerifySignature(bVerifySignature);
final com.helger.xsds.bdxr.smp1.SignedServiceMetadataType aSSM = aBDXR1Client.getServiceMetadataOrNull(aParticipantID, aDocTypeID);
if (aSSM != null) {
final com.helger.xsds.bdxr.smp1.ServiceMetadataType aSM = aSSM.getServiceMetadata();
aJson = SMPJsonResponse.convert(aParticipantID, aDocTypeID, aSM);
}
break;
}
}
aSW.stop();
if (aJson == null) {
LOGGER.error(sLogPrefix + "Failed to perform the SMP lookup");
aUnifiedResponse.setStatus(CHttp.HTTP_NOT_FOUND);
} else {
LOGGER.info(sLogPrefix + "Succesfully finished lookup lookup after " + aSW.getMillis() + " milliseconds");
aJson.add("queryDateTime", DateTimeFormatter.ISO_ZONED_DATE_TIME.format(aQueryDT));
aJson.add("queryDurationMillis", aSW.getMillis());
final String sRet = new JsonWriter(JsonWriterSettings.DEFAULT_SETTINGS_FORMATTED).writeAsString(aJson);
aUnifiedResponse.setContentAndCharset(sRet, StandardCharsets.UTF_8).setMimeType(CMimeType.APPLICATION_JSON).enableCaching(1 * CGlobal.SECONDS_PER_HOUR);
}
}
Aggregations