Search in sources :

Example 1 with ESMPIdentifierType

use of com.helger.peppolid.factory.ESMPIdentifierType in project peppol-practical by phax.

the class SMLConfigurationMicroTypeConverter method convertToNative.

@Nonnull
public SMLConfiguration convertToNative(@Nonnull final IMicroElement aElement) {
    final IMicroElement eSMLInfo = aElement.getFirstChildElement(ELEMENT_SML_INFO);
    final SMLInfo aSMLInfo;
    final ESMPAPIType eSMPAPIType;
    final ESMPIdentifierType eSMPIdentifierType;
    final boolean bProduction;
    if (eSMLInfo != null) {
        aSMLInfo = MicroTypeConverter.convertToNative(eSMLInfo, SMLInfo.class);
        eSMPAPIType = ESMPAPIType.getFromIDOrDefault(aElement.getAttributeValue(ATTR_SMP_API_TYPE), ESMPAPIType.PEPPOL);
        eSMPIdentifierType = ESMPIdentifierType.getFromIDOrDefault(aElement.getAttributeValue(ATTR_SMP_IDENTIFIER_TYPE), ESMPIdentifierType.PEPPOL);
        bProduction = aElement.getAttributeValueAsBool(ATTR_PRODUCTION, false);
    } else {
        // Assume we read legacy data
        aSMLInfo = MicroTypeConverter.convertToNative(aElement, SMLInfo.class);
        eSMPAPIType = ESMPAPIType.PEPPOL;
        eSMPIdentifierType = ESMPIdentifierType.PEPPOL;
        bProduction = false;
    }
    return new SMLConfiguration(aSMLInfo, eSMPAPIType, eSMPIdentifierType, bProduction);
}
Also used : ESMPIdentifierType(com.helger.peppolid.factory.ESMPIdentifierType) IMicroElement(com.helger.xml.microdom.IMicroElement) SMLInfo(com.helger.peppol.sml.SMLInfo) ESMPAPIType(com.helger.peppol.sml.ESMPAPIType) Nonnull(javax.annotation.Nonnull)

Example 2 with ESMPIdentifierType

use of com.helger.peppolid.factory.ESMPIdentifierType in project phoss-smp by phax.

the class SMPMetaManager method onAfterInstantiation.

@Override
protected void onAfterInstantiation(@Nonnull final IScope aScope) {
    if (s_aManagerProvider == null)
        throw new InitializationException("No ManagerProvider is set. Please call setManagerProvider before you call getInstance!");
    try {
        // Before all
        s_aManagerProvider.beforeInitManagers();
        final ESMPIdentifierType eIdentifierType = SMPServerConfiguration.getIdentifierType();
        m_aIdentifierFactory = eIdentifierType.getIdentifierFactory();
        // RegistrationHookFactory
        try {
            SMPTrustManager.getInstance();
        } catch (final Exception ex) {
        // fall through. No special trust store - no problem :)
        }
        try {
            SMPKeyManager.getInstance();
        } catch (final Exception ex) {
        // fall through. Certificate stays invalid, no SML access possible.
        }
        m_eBackendConnectionState = s_aManagerProvider.getBackendConnectionEstablishedDefaultState();
        if (m_eBackendConnectionState == null)
            throw new IllegalStateException("Failed to get default backend connection state!");
        // TODO This might become configurable in the future
        m_aSMPURLProvider = SMPServerConfiguration.getRESTType().isPeppol() ? PeppolURLProvider.INSTANCE : BDXLURLProvider.INSTANCE;
        if (m_aSMPURLProvider == null)
            throw new IllegalStateException("Failed to create SMP URL Provider!");
        m_aSMLInfoMgr = s_aManagerProvider.createSMLInfoMgr();
        if (m_aSMLInfoMgr == null)
            throw new IllegalStateException("Failed to create SML Info manager!");
        m_aSettingsMgr = s_aManagerProvider.createSettingsMgr();
        if (m_aSettingsMgr == null)
            throw new IllegalStateException("Failed to create Settings manager!");
        m_aTransportProfileMgr = s_aManagerProvider.createTransportProfileMgr();
        if (m_aTransportProfileMgr == null)
            throw new IllegalStateException("Failed to create TransportProfile manager!");
        // Service group manager must be before redirect and service information!
        m_aServiceGroupMgr = s_aManagerProvider.createServiceGroupMgr();
        if (m_aServiceGroupMgr == null)
            throw new IllegalStateException("Failed to create ServiceGroup manager!");
        m_aRedirectMgr = s_aManagerProvider.createRedirectMgr(m_aIdentifierFactory, m_aServiceGroupMgr);
        if (m_aRedirectMgr == null)
            throw new IllegalStateException("Failed to create Redirect manager!");
        m_aServiceInformationMgr = s_aManagerProvider.createServiceInformationMgr(m_aIdentifierFactory, m_aServiceGroupMgr);
        if (m_aServiceInformationMgr == null)
            throw new IllegalStateException("Failed to create ServiceInformation manager!");
        m_aParticipantMigrationMgr = s_aManagerProvider.createParticipantMigrationMgr();
        if (m_aParticipantMigrationMgr == null)
            throw new IllegalStateException("Failed to create ParticipantMigration manager!");
        // May be null!
        m_aBusinessCardMgr = s_aManagerProvider.createBusinessCardMgr(m_aIdentifierFactory, m_aServiceGroupMgr);
        _initCallbacks();
        _performMigrations();
        // After all
        s_aManagerProvider.afterInitManagers();
        LOGGER.info(ClassHelper.getClassLocalName(this) + " was initialized");
    } catch (final Exception ex) {
        throw new InitializationException("Failed to init " + ClassHelper.getClassLocalName(this), ex);
    }
}
Also used : ESMPIdentifierType(com.helger.peppolid.factory.ESMPIdentifierType) InitializationException(com.helger.commons.exception.InitializationException) InitializationException(com.helger.commons.exception.InitializationException)

Example 3 with ESMPIdentifierType

use of com.helger.peppolid.factory.ESMPIdentifierType in project peppol-practical by phax.

the class PageSecureSMLConfiguration method validateAndSaveInputParameters.

@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMLConfiguration aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
    final boolean bEdit = eFormAction.isEdit();
    final ISMLConfigurationManager aSMLConfigurationMgr = PPMetaManager.getSMLConfigurationMgr();
    final String sID = aWPEC.params().getAsString(FIELD_ID);
    final String sDisplayName = aWPEC.params().getAsString(FIELD_DISPLAY_NAME);
    final String sDNSZone = aWPEC.params().getAsString(FIELD_DNS_ZONE);
    final String sManagementAddressURL = aWPEC.params().getAsString(FIELD_MANAGEMENT_ADDRESS_URL);
    final boolean bClientCertificateRequired = aWPEC.params().isCheckBoxChecked(FIELD_CLIENT_CERTIFICATE_REQUIRED, DEFAULT_CLIENT_CERTIFICATE_REQUIRED);
    final String sSMPAPIType = aWPEC.params().getAsString(FIELD_SMP_API_TYPE);
    final ESMPAPIType eSMPAPIType = ESMPAPIType.getFromIDOrNull(sSMPAPIType);
    final String sSMPIdentifierType = aWPEC.params().getAsString(FIELD_SMP_ID_TYPE);
    final ESMPIdentifierType eSMPIdentifierType = ESMPIdentifierType.getFromIDOrNull(sSMPIdentifierType);
    final boolean bProduction = aWPEC.params().isCheckBoxChecked(FIELD_PRODUCTION, false);
    // validations
    if (StringHelper.hasNoText(sID))
        aFormErrors.addFieldError(FIELD_ID, "The SML configuration ID must not be empty!");
    else if (ISMLConfigurationManager.ID_AUTO_DETECT.equals(sID))
        aFormErrors.addFieldError(FIELD_ID, "This SML configuration ID is reserved!");
    else {
        final ISMLConfiguration aExisting = aSMLConfigurationMgr.getSMLInfoOfID(sID);
        if (bEdit) {
            // Expect aExistring == aSelectedObject
            if (aExisting == null)
                aFormErrors.addFieldError(FIELD_ID, "Invalid SML configuration ID provided!");
            else if (aExisting != aSelectedObject)
                aFormErrors.addFieldError(FIELD_ID, "Another SML configuration with the same ID already exists!");
        } else {
            if (aExisting != null)
                aFormErrors.addFieldError(FIELD_ID, "Another SML configuration with the same ID already exists!");
        }
    }
    if (StringHelper.hasNoText(sDisplayName))
        aFormErrors.addFieldError(FIELD_DISPLAY_NAME, "The SML configuration name must not be empty!");
    if (StringHelper.hasNoText(sDNSZone))
        aFormErrors.addFieldError(FIELD_DNS_ZONE, "The DNS Zone must not be empty!");
    if (StringHelper.hasNoText(sManagementAddressURL))
        aFormErrors.addFieldError(FIELD_MANAGEMENT_ADDRESS_URL, "The Management Address URL must not be empty!");
    else {
        final URL aURL = URLHelper.getAsURL(sManagementAddressURL);
        if (aURL == null)
            aFormErrors.addFieldError(FIELD_MANAGEMENT_ADDRESS_URL, "The Management Address URL is not a valid URL!");
        else if (!"https".equals(aURL.getProtocol()) && !"http".equals(aURL.getProtocol()))
            aFormErrors.addFieldError(FIELD_MANAGEMENT_ADDRESS_URL, "The Management Address URL should only be use the 'http' or the 'https' protocol!");
    }
    if (StringHelper.hasNoText(sSMPAPIType))
        aFormErrors.addFieldError(FIELD_SMP_API_TYPE, "An SMP API type must be selected!");
    else if (eSMPAPIType == null)
        aFormErrors.addFieldError(FIELD_SMP_API_TYPE, "A valid SMP API type must be selected!");
    if (StringHelper.hasNoText(sSMPIdentifierType))
        aFormErrors.addFieldError(FIELD_SMP_ID_TYPE, "An SMP identifier type must be selected!");
    else if (eSMPIdentifierType == null)
        aFormErrors.addFieldError(FIELD_SMP_ID_TYPE, "A valid SMP identifier type must be selected!");
    if (aFormErrors.isEmpty()) {
        // Lowercase with the US locale - not display locale specific
        final String sDNSZoneLC = sDNSZone.toLowerCase(Locale.US);
        if (bEdit) {
            aSMLConfigurationMgr.updateSMLInfo(aSelectedObject.getID(), sDisplayName, sDNSZoneLC, sManagementAddressURL, bClientCertificateRequired, eSMPAPIType, eSMPIdentifierType, bProduction);
            aWPEC.postRedirectGetInternal(success("The SML configuration '" + sDisplayName + "' was successfully edited."));
        } else {
            aSMLConfigurationMgr.createSMLInfo(sID, sDisplayName, sDNSZoneLC, sManagementAddressURL, bClientCertificateRequired, eSMPAPIType, eSMPIdentifierType, bProduction);
            aWPEC.postRedirectGetInternal(success("The new SML configuration '" + sDisplayName + "' was successfully created."));
        }
    }
}
Also used : ESMPIdentifierType(com.helger.peppolid.factory.ESMPIdentifierType) ISMLConfigurationManager(com.helger.peppol.app.mgr.ISMLConfigurationManager) ISMLConfiguration(com.helger.peppol.domain.ISMLConfiguration) URL(java.net.URL) ISimpleURL(com.helger.commons.url.ISimpleURL) ESMPAPIType(com.helger.peppol.sml.ESMPAPIType)

Aggregations

ESMPIdentifierType (com.helger.peppolid.factory.ESMPIdentifierType)3 ESMPAPIType (com.helger.peppol.sml.ESMPAPIType)2 InitializationException (com.helger.commons.exception.InitializationException)1 ISimpleURL (com.helger.commons.url.ISimpleURL)1 ISMLConfigurationManager (com.helger.peppol.app.mgr.ISMLConfigurationManager)1 ISMLConfiguration (com.helger.peppol.domain.ISMLConfiguration)1 SMLInfo (com.helger.peppol.sml.SMLInfo)1 IMicroElement (com.helger.xml.microdom.IMicroElement)1 URL (java.net.URL)1 Nonnull (javax.annotation.Nonnull)1