Search in sources :

Example 1 with ISMPParticipantMigrationManager

use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager 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();
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) EParticipantMigrationState(com.helger.phoss.smp.domain.pmigration.EParticipantMigrationState) SMPPreconditionFailedException(com.helger.phoss.smp.exception.SMPPreconditionFailedException) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) ISMPParticipantMigrationManager(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException)

Example 2 with ISMPParticipantMigrationManager

use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager 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();
}
Also used : ClientTransportException(com.sun.xml.ws.client.ClientTransportException) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) BadRequestFault(com.helger.peppol.smlclient.participant.BadRequestFault) ISMLInfo(com.helger.peppol.sml.ISMLInfo) NotFoundFault(com.helger.peppol.smlclient.participant.NotFoundFault) SMPSMLException(com.helger.phoss.smp.exception.SMPSMLException) CMimeType(com.helger.commons.mime.CMimeType) MimeType(com.helger.commons.mime.MimeType) IMicroDocument(com.helger.xml.microdom.IMicroDocument) MicroDocument(com.helger.xml.microdom.MicroDocument) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) ISMPParticipantMigrationManager(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) XMLWriterSettings(com.helger.xml.serialize.write.XMLWriterSettings) ManageParticipantIdentifierServiceCaller(com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller) UnauthorizedFault(com.helger.peppol.smlclient.participant.UnauthorizedFault) SMPPreconditionFailedException(com.helger.phoss.smp.exception.SMPPreconditionFailedException) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) SMPInternalErrorException(com.helger.phoss.smp.exception.SMPInternalErrorException) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroDocument(com.helger.xml.microdom.IMicroDocument) InternalErrorFault(com.helger.peppol.smlclient.participant.InternalErrorFault) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 3 with ISMPParticipantMigrationManager

use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager in project phoss-smp by phax.

the class PageSecureServiceGroupMigrationInbound method showListOfExistingObjects.

@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    {
        final HCOL aOL = new HCOL();
        aOL.addItem("The migration was initiated by another SMP, and the SML must have been informed about the upcoming migration");
        aOL.addItem("This SMP, that is taking over the Service Group, must acknowledge the migration by providing the same migration code (created by the other SMP) to the SML");
        aOL.addItem("If the migration was successful, the Service Group must be deleted from the other SMP, ideally a temporary redirect to the new SMP is created");
        aNodeList.addChild(info().addChild(div("The process of migrating a Service Group to another SMP consists of multiple steps:")).addChild(aOL).addChild(div("If a Migration is unsuccessful, it can be retried later.")));
    }
    EValidity eCanMigrate = EValidity.VALID;
    if (aSettings.getSMLInfo() == null) {
        final BootstrapWarnBox aWarnBox = aNodeList.addAndReturnChild(warn().addChild(div("No valid SML Configuration is selected hence no participant can be migrated.")).addChild(new BootstrapButton().addChild("Select SML Configuration in the Settings").setOnClick(aWPEC.getLinkToMenuItem(CMenuSecure.MENU_SMP_SETTINGS)).setIcon(EDefaultIcon.EDIT)));
        if (aSettings.isSMLEnabled() || aSettings.isSMLRequired()) {
            aWarnBox.addChild(div(new BootstrapButton().addChild("Create a new SML Configuration").setOnClick(createCreateURL(aWPEC, CMenuSecure.MENU_SML_CONFIGURATION)).setIcon(EDefaultIcon.YES)));
        }
        eCanMigrate = EValidity.INVALID;
    } else if (!aSettings.isSMLEnabled()) {
        aNodeList.addChild(warn().addChild(div("SML Connection is not enabled hence no participant can be migrated.")).addChild(div(new BootstrapButton().addChild("Enable SML in the Settings").setOnClick(aWPEC.getLinkToMenuItem(CMenuSecure.MENU_SMP_SETTINGS)).setIcon(EDefaultIcon.EDIT))));
        eCanMigrate = EValidity.INVALID;
    }
    {
        final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
        aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
        aToolbar.addChild(new BootstrapButton().addChild("Start Participant Migration").setOnClick(createCreateURL(aWPEC)).setDisabled(eCanMigrate.isInvalid()).setIcon(EDefaultIcon.NEW));
        aNodeList.addChild(aToolbar);
    }
    final BootstrapTabBox aTabBox = aNodeList.addAndReturnChild(new BootstrapTabBox());
    final ICommonsList<ISMPParticipantMigration> aAllMigs = aParticipantMigrationMgr.getAllInboundParticipantMigrations(null);
    for (final EParticipantMigrationState eState : EParticipantMigrationState.values()) if (eState.isInboundState()) {
        final ICommonsList<ISMPParticipantMigration> aMatchingMigs = aAllMigs.getAll(x -> x.getState() == eState);
        aTabBox.addTab(eState.getID(), eState.getDisplayName() + " (" + aMatchingMigs.size() + ")", _createTable(aWPEC, aMatchingMigs, eState));
    }
}
Also used : CSMPServer(com.helger.phoss.smp.CSMPServer) HCOL(com.helger.html.hc.html.grouping.HCOL) SMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration) WebPageExecutionContext(com.helger.photon.uicore.page.WebPageExecutionContext) EDefaultIcon(com.helger.photon.uicore.icon.EDefaultIcon) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) LoggerFactory(org.slf4j.LoggerFactory) IMicroDocument(com.helger.xml.microdom.IMicroDocument) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) AbstractBootstrapWebPageActionHandlerDelete(com.helger.photon.bootstrap4.pages.handler.AbstractBootstrapWebPageActionHandlerDelete) FormErrorList(com.helger.photon.core.form.FormErrorList) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ICommonsIterable(com.helger.commons.collection.impl.ICommonsIterable) Nonempty(com.helger.commons.annotation.Nonempty) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) Locale(java.util.Locale) IUser(com.helger.photon.security.user.IUser) HCA(com.helger.html.hc.html.textlevel.HCA) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) HCTextArea(com.helger.html.hc.html.forms.HCTextArea) ISMPParticipantMigrationManager(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager) SMPCommonUI(com.helger.phoss.smp.ui.SMPCommonUI) PDTToString(com.helger.commons.datetime.PDTToString) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox) IHCCell(com.helger.html.hc.html.tabular.IHCCell) BootstrapTechnicalUI(com.helger.photon.bootstrap4.uictrls.ext.BootstrapTechnicalUI) EWebPageFormAction(com.helger.photon.uicore.page.EWebPageFormAction) HCUserSelect(com.helger.phoss.smp.ui.secure.hc.HCUserSelect) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) SingleError(com.helger.commons.error.SingleError) ICommonsList(com.helger.commons.collection.impl.ICommonsList) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) PhotonSecurityManager(com.helger.photon.security.mgr.PhotonSecurityManager) ManageParticipantIdentifierServiceCaller(com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller) DataTables(com.helger.photon.uictrls.datatables.DataTables) HCRow(com.helger.html.hc.html.tabular.HCRow) EValidity(com.helger.commons.state.EValidity) HCEdit(com.helger.html.hc.html.forms.HCEdit) BootstrapRow(com.helger.photon.bootstrap4.grid.BootstrapRow) AbstractSMPWebPageForm(com.helger.phoss.smp.ui.AbstractSMPWebPageForm) IHCNode(com.helger.html.hc.IHCNode) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) EParticipantMigrationState(com.helger.phoss.smp.domain.pmigration.EParticipantMigrationState) SMPKeyManager(com.helger.phoss.smp.security.SMPKeyManager) EDTColType(com.helger.photon.uictrls.datatables.column.EDTColType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ISimpleURL(com.helger.commons.url.ISimpleURL) HCNodeList(com.helger.html.hc.impl.HCNodeList) BootstrapWarnBox(com.helger.photon.bootstrap4.alert.BootstrapWarnBox) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) Logger(org.slf4j.Logger) StringHelper(com.helger.commons.string.StringHelper) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) HCTable(com.helger.html.hc.html.tabular.HCTable) SMPMetaManager(com.helger.phoss.smp.domain.SMPMetaManager) RequestField(com.helger.photon.core.form.RequestField) SMPServerConfiguration(com.helger.phoss.smp.SMPServerConfiguration) LoggedInUserManager(com.helger.photon.security.login.LoggedInUserManager) ESortOrder(com.helger.commons.compare.ESortOrder) MicroReader(com.helger.xml.microdom.serialize.MicroReader) EValidity(com.helger.commons.state.EValidity) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCNodeList(com.helger.html.hc.impl.HCNodeList) EParticipantMigrationState(com.helger.phoss.smp.domain.pmigration.EParticipantMigrationState) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox) BootstrapWarnBox(com.helger.photon.bootstrap4.alert.BootstrapWarnBox) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) HCOL(com.helger.html.hc.html.grouping.HCOL) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) ISMPParticipantMigrationManager(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)

Example 4 with ISMPParticipantMigrationManager

use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager in project phoss-smp by phax.

the class PageSecureServiceGroupMigrationInbound method validateAndSaveInputParameters.

@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPParticipantMigration aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
    final String sMigrationKey = aWPEC.params().getAsStringTrimmed(FIELD_MIGRATION_KEY);
    final String sParticipantIDScheme = aWPEC.params().getAsStringTrimmed(FIELD_PARTICIPANT_ID_SCHEME);
    final String sParticipantIDValue = aWPEC.params().getAsStringTrimmed(FIELD_PARTICIPANT_ID_VALUE);
    IParticipantIdentifier aParticipantID = null;
    final String sOwningUserID = aWPEC.params().getAsStringTrimmed(FIELD_OWNING_USER_ID);
    final IUser aOwningUser = PhotonSecurityManager.getUserMgr().getUserOfID(sOwningUserID);
    final String sExtension = aWPEC.params().getAsStringTrimmed(FIELD_EXTENSION);
    // validations
    if (StringHelper.hasNoText(sMigrationKey))
        aFormErrors.addFieldError(FIELD_MIGRATION_KEY, "The migration key must not be empty!");
    else if (!SMPParticipantMigration.isValidMigrationKey(sMigrationKey))
        aFormErrors.addFieldError(FIELD_MIGRATION_KEY, "The migration key is not valid. Please verify the received code is correct.");
    if (aIdentifierFactory.isParticipantIdentifierSchemeMandatory() && StringHelper.hasNoText(sParticipantIDScheme))
        aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_SCHEME, "Participant ID scheme must not be empty!");
    else if (StringHelper.hasNoText(sParticipantIDValue))
        aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_VALUE, "Participant ID value must not be empty!");
    else {
        aParticipantID = aIdentifierFactory.createParticipantIdentifier(sParticipantIDScheme, sParticipantIDValue);
        if (aParticipantID == null)
            aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_VALUE, "The provided participant ID has an invalid syntax!");
        else if (aServiceGroupMgr.getSMPServiceGroupOfID(aParticipantID) != null)
            aFormErrors.addFieldError(FIELD_PARTICIPANT_ID_VALUE, "Another service group for the same participant ID is already present (may be case insensitive)!");
    }
    if (StringHelper.hasNoText(sOwningUserID))
        aFormErrors.addFieldError(FIELD_OWNING_USER_ID, "Owning User must not be empty!");
    else if (aOwningUser == null)
        aFormErrors.addFieldError(FIELD_OWNING_USER_ID, "Provided owning user does not exist!");
    if (StringHelper.hasText(sExtension)) {
        final IMicroDocument aDoc = MicroReader.readMicroXML(sExtension);
        if (aDoc == null)
            aFormErrors.addFieldError(FIELD_EXTENSION, "The extension must be XML content.");
    }
    final HCNodeList aRedirectNotes = new HCNodeList();
    if (aFormErrors.isEmpty()) {
        // create the Service Group locally
        try {
            final ManageParticipantIdentifierServiceCaller aCaller = new ManageParticipantIdentifierServiceCaller(aSettings.getSMLInfo());
            aCaller.setSSLSocketFactory(SMPKeyManager.getInstance().createSSLContext().getSocketFactory());
            // SML call
            aCaller.migrate(aParticipantID, sMigrationKey, SMPServerConfiguration.getSMLSMPID());
            LOGGER.info("Successfully migrated '" + aParticipantID.getURIEncoded() + "' in the SML to this SMP using migration key '" + sMigrationKey + "'");
            aRedirectNotes.addChild(success("Successfully migrated '" + aParticipantID.getURIEncoded() + "' in SML to this SMP using migration key ").addChild(code(sMigrationKey)));
        } catch (final Exception ex) {
            LOGGER.error("Error invoking migrate on SML", ex);
            // Use a global field error here, to avoid that users must enter the
            // values over and over in case of error
            aFormErrors.add(SingleError.builderError().errorText("Failed to confirm the migration for participant '" + aParticipantID.getURIEncoded() + "' in SML, hence the migration failed." + " Please check the participant identifier and the migration key.\n" + BootstrapTechnicalUI.getTechnicalDetailsString(ex, CSMPServer.DEFAULT_LOCALE)).build());
            if (false)
                aWPEC.postRedirectGetInternal(error("Failed to confirm the migration for participant '" + aParticipantID.getURIEncoded() + "' in SML, hence the migration failed." + " Please check the participant identifier and the migration key.").addChild(SMPCommonUI.getTechnicalDetailsUI(ex)));
        }
    }
    if (aFormErrors.isEmpty()) {
        // Now create the service group locally (it was already checked that the
        // PID is available on this SMP)
        ISMPServiceGroup aSG = null;
        Exception aCaughtEx = null;
        try {
            // Do NOT create in SMK/SML
            aSG = aServiceGroupMgr.createSMPServiceGroup(aOwningUser.getID(), aParticipantID, sExtension, false);
        } catch (final Exception ex) {
            aCaughtEx = ex;
        }
        if (aSG != null) {
            aRedirectNotes.addChild(success("The new SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "' was successfully created."));
        } else {
            aRedirectNotes.addChild(error("Error creating the new SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "'.").addChild(SMPCommonUI.getTechnicalDetailsUI(aCaughtEx)));
        }
        // Remember internally
        if (aParticipantMigrationMgr.createInboundParticipantMigration(aParticipantID, sMigrationKey) != null) {
            aRedirectNotes.addChild(success().addChild(div("The participant migration for '" + aParticipantID.getURIEncoded() + "' with migration key ").addChild(code(sMigrationKey)).addChild(" was successfully performed.")).addChild(div("Please inform the source SMP that the migration was successful.")));
        } else {
            aRedirectNotes.addChild(error("Failed to store the participant migration for '" + aParticipantID.getURIEncoded() + "'."));
        }
        aWPEC.postRedirectGetInternal(aRedirectNotes);
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IUser(com.helger.photon.security.user.IUser) ISMPParticipantMigrationManager(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager) PDTToString(com.helger.commons.datetime.PDTToString) IMicroDocument(com.helger.xml.microdom.IMicroDocument) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ManageParticipantIdentifierServiceCaller(com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 5 with ISMPParticipantMigrationManager

use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager in project phoss-smp by phax.

the class PageSecureServiceGroupMigrationOutbound method showInputForm.

@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPParticipantMigration aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bIsFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
    // State is filtered below
    final ICommonsList<ISMPParticipantMigration> aExistingOutgoingMigrations = aParticipantMigrationMgr.getAllOutboundParticipantMigrations(null);
    // Get all participant identifiers for which NO new migration can be
    // initiated (because they were already migrated or migration is currently
    // in progress)
    final ICommonsSet<IParticipantIdentifier> aPIDsThatCannotBeUsed = new CommonsHashSet<>();
    aPIDsThatCannotBeUsed.addAllMapped(aExistingOutgoingMigrations, x -> x.getState().preventsNewMigration(), ISMPParticipantMigration::getParticipantIdentifier);
    // Filter out all for which it makes no sense
    final HCServiceGroupSelect aSGSelect = new HCServiceGroupSelect(new RequestField(FIELD_PARTICIPANT_ID), aDisplayLocale, x -> aPIDsThatCannotBeUsed.containsNone(y -> x.getParticipantIdentifier().hasSameContent(y)));
    if (!aSGSelect.containsAnyServiceGroup()) {
        aForm.addChild(warn("No Service Group on this SMP can currently be migrated."));
    } else {
        aForm.addChild(getUIHandler().createActionHeader("Start a Participant Migration from this SMP to another SMP"));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Service Group").setCtrl(aSGSelect).setHelpText("Select the Service Group to migrate to another SMP. Each Service Group can only be migrated once from this SMP. Only Service Groups registered to the SML can be migrated.").setErrorList(aFormErrors.getListOfField(FIELD_PARTICIPANT_ID)));
    }
}
Also used : Locale(java.util.Locale) HCOL(com.helger.html.hc.html.grouping.HCOL) WebPageExecutionContext(com.helger.photon.uicore.page.WebPageExecutionContext) EDefaultIcon(com.helger.photon.uicore.icon.EDefaultIcon) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) LoggerFactory(org.slf4j.LoggerFactory) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) AbstractBootstrapWebPageActionHandlerDelete(com.helger.photon.bootstrap4.pages.handler.AbstractBootstrapWebPageActionHandlerDelete) FormErrorList(com.helger.photon.core.form.FormErrorList) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ICommonsIterable(com.helger.commons.collection.impl.ICommonsIterable) HCServiceGroupSelect(com.helger.phoss.smp.ui.secure.hc.HCServiceGroupSelect) Nonempty(com.helger.commons.annotation.Nonempty) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) Locale(java.util.Locale) HCA(com.helger.html.hc.html.textlevel.HCA) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) CPageParam(com.helger.photon.uicore.css.CPageParam) ISMPParticipantMigrationManager(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager) SMPCommonUI(com.helger.phoss.smp.ui.SMPCommonUI) PDTToString(com.helger.commons.datetime.PDTToString) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox) IHCCell(com.helger.html.hc.html.tabular.IHCCell) EWebPageFormAction(com.helger.photon.uicore.page.EWebPageFormAction) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) ICommonsList(com.helger.commons.collection.impl.ICommonsList) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ManageParticipantIdentifierServiceCaller(com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller) ICommonsSet(com.helger.commons.collection.impl.ICommonsSet) DataTables(com.helger.photon.uictrls.datatables.DataTables) HCRow(com.helger.html.hc.html.tabular.HCRow) EValidity(com.helger.commons.state.EValidity) AbstractSMPWebPageForm(com.helger.phoss.smp.ui.AbstractSMPWebPageForm) IHCNode(com.helger.html.hc.IHCNode) EParticipantMigrationState(com.helger.phoss.smp.domain.pmigration.EParticipantMigrationState) SMPKeyManager(com.helger.phoss.smp.security.SMPKeyManager) EDTColType(com.helger.photon.uictrls.datatables.column.EDTColType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ISimpleURL(com.helger.commons.url.ISimpleURL) HCNodeList(com.helger.html.hc.impl.HCNodeList) BootstrapWarnBox(com.helger.photon.bootstrap4.alert.BootstrapWarnBox) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) Logger(org.slf4j.Logger) StringHelper(com.helger.commons.string.StringHelper) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) HCTable(com.helger.html.hc.html.tabular.HCTable) SMPMetaManager(com.helger.phoss.smp.domain.SMPMetaManager) RequestField(com.helger.photon.core.form.RequestField) CommonsHashSet(com.helger.commons.collection.impl.CommonsHashSet) SMPServerConfiguration(com.helger.phoss.smp.SMPServerConfiguration) ESortOrder(com.helger.commons.compare.ESortOrder) AbstractBootstrapWebPageActionHandlerWithQuery(com.helger.photon.bootstrap4.pages.handler.AbstractBootstrapWebPageActionHandlerWithQuery) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) HCServiceGroupSelect(com.helger.phoss.smp.ui.secure.hc.HCServiceGroupSelect) ISMPParticipantMigrationManager(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) CommonsHashSet(com.helger.commons.collection.impl.CommonsHashSet) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) RequestField(com.helger.photon.core.form.RequestField)

Aggregations

ISMPParticipantMigrationManager (com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager)10 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)9 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)9 ISMPParticipantMigration (com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration)8 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)8 ManageParticipantIdentifierServiceCaller (com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller)7 ISMPSettings (com.helger.phoss.smp.settings.ISMPSettings)7 PDTToString (com.helger.commons.datetime.PDTToString)5 BasicAuthClientCredentials (com.helger.http.basicauth.BasicAuthClientCredentials)5 IMicroDocument (com.helger.xml.microdom.IMicroDocument)5 HCNodeList (com.helger.html.hc.impl.HCNodeList)4 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)4 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)4 SMPPreconditionFailedException (com.helger.phoss.smp.exception.SMPPreconditionFailedException)4 ISMPServerAPIDataProvider (com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider)4 Nonempty (com.helger.commons.annotation.Nonempty)3 ICommonsIterable (com.helger.commons.collection.impl.ICommonsIterable)3 ICommonsList (com.helger.commons.collection.impl.ICommonsList)3 ESortOrder (com.helger.commons.compare.ESortOrder)3 EValidity (com.helger.commons.state.EValidity)3