Search in sources :

Example 1 with ISMPSettings

use of com.helger.phoss.smp.settings.ISMPSettings in project phoss-smp by phax.

the class SMPSettingsManagerJDBC method getSettings.

@Nonnull
public ISMPSettings getSettings() {
    final ICommonsMap<String, String> aValues = getAllSettingsValues();
    final SMPSettings ret = new SMPSettings(false);
    ret.setRESTWritableAPIDisabled(StringParser.parseBool(aValues.get(SMP_REST_WRITABLE_API_DISABLED), SMPServerConfiguration.DEFAULT_SMP_REST_WRITABLE_API_DISABLED));
    ret.setDirectoryIntegrationEnabled(StringParser.parseBool(aValues.get(DIRECTORY_INTEGRATION_ENABLED), SMPServerConfiguration.DEFAULT_SMP_DIRECTORY_INTEGRATION_ENABLED));
    ret.setDirectoryIntegrationRequired(StringParser.parseBool(aValues.get(DIRECTORY_INTEGRATION_REQUIRED), SMPServerConfiguration.DEFAULT_SMP_DIRECTORY_INTEGRATION_REQUIRED));
    ret.setDirectoryIntegrationAutoUpdate(StringParser.parseBool(aValues.get(DIRECTORY_INTEGRATION_AUTO_UPDATE), SMPServerConfiguration.DEFAULT_SMP_DIRECTORY_INTEGRATION_AUTO_UPDATE));
    ret.setDirectoryHostName(aValues.get(DIRECTORY_HOSTNAME));
    ret.setSMLEnabled(StringParser.parseBool(aValues.get(SML_ENABLED), SMPServerConfiguration.DEFAULT_SML_ENABLED));
    ret.setSMLRequired(StringParser.parseBool(aValues.get(SML_REQUIRED), SMPServerConfiguration.DEFAULT_SML_REQUIRED));
    ret.setSMLInfoID(aValues.get(SML_INFO_ID));
    return ret;
}
Also used : SMPSettings(com.helger.phoss.smp.settings.SMPSettings) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) Nonnull(javax.annotation.Nonnull)

Example 2 with ISMPSettings

use of com.helger.phoss.smp.settings.ISMPSettings in project phoss-smp by phax.

the class PageSecureBusinessCard method isValidToDisplayPage.

@Override
@Nonnull
protected IValidityIndicator isValidToDisplayPage(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    if (!aSettings.isDirectoryIntegrationEnabled()) {
        aNodeList.addChild(warn(SMPWebAppConfiguration.getDirectoryName() + " integration is disabled hence no Business Cards can be created."));
        aNodeList.addChild(new BootstrapButton().addChild("Change settings").setOnClick(createCreateURL(aWPEC, CMenuSecure.MENU_SMP_SETTINGS)).setIcon(EDefaultIcon.YES));
        return EValidity.INVALID;
    }
    final ISMPServiceGroupManager aServiceGroupManager = SMPMetaManager.getServiceGroupMgr();
    if (aServiceGroupManager.getSMPServiceGroupCount() <= 0) {
        aNodeList.addChild(warn("No Service Group is present! At least one Service Group must be present to create a Business Card for it."));
        aNodeList.addChild(new BootstrapButton().addChild("Create new Service Group").setOnClick(createCreateURL(aWPEC, CMenuSecure.MENU_SERVICE_GROUPS)).setIcon(EDefaultIcon.YES));
        return EValidity.INVALID;
    }
    return super.isValidToDisplayPage(aWPEC);
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) Nonnull(javax.annotation.Nonnull)

Example 3 with ISMPSettings

use of com.helger.phoss.smp.settings.ISMPSettings 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 4 with ISMPSettings

use of com.helger.phoss.smp.settings.ISMPSettings in project phoss-smp by phax.

the class SMPStatusProvider method getDefaultStatusData.

@Nonnull
@ReturnsMutableCopy
public static IJsonObject getDefaultStatusData(final boolean bDisableLongRunningOperations) {
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Building status data");
    final StopWatch aSW = StopWatch.createdStarted();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    final LocalDateTime aNow = PDTFactory.getCurrentLocalDateTime();
    final ISMLInfo aSMLInfo = aSettings.getSMLInfo();
    final IJsonObject aStatusData = new JsonObject();
    // Since 5.0.7
    aStatusData.add("build.timestamp", CSMPServer.getBuildTimestamp());
    // Since 5.3.3
    aStatusData.addIfNotNull("startup.datetime", PDTWebDateHelper.getAsStringXSD(SMPWebAppListener.getStartupDateTime()));
    aStatusData.add("status.datetime", PDTWebDateHelper.getAsStringXSD(PDTFactory.getCurrentOffsetDateTimeUTC()));
    aStatusData.add("version.smp", CSMPServer.getVersionNumber());
    aStatusData.add("version.java", SystemProperties.getJavaVersion());
    aStatusData.add("global.debug", GlobalDebug.isDebugMode());
    aStatusData.add("global.production", GlobalDebug.isProductionMode());
    aStatusData.add("smp.backend", SMPServerConfiguration.getBackend());
    aStatusData.add("smp.mode", SMPWebAppConfiguration.isTestVersion() ? "test" : "production");
    aStatusData.add("smp.resttype", SMPServerConfiguration.getRESTType().getID());
    aStatusData.add("smp.identifiertype", SMPServerConfiguration.getIdentifierType().getID());
    aStatusData.add("smp.id", SMPServerConfiguration.getSMLSMPID());
    aStatusData.add("smp.writable-rest-api.enabled", !aSettings.isRESTWritableAPIDisabled());
    // New in 5.1.0
    aStatusData.add("smp.publicurl", SMPServerConfiguration.getPublicServerURL());
    // New in 5.1.0
    aStatusData.add("smp.forceroot", SMPServerConfiguration.isForceRoot());
    // New in 5.2.0
    aStatusData.add("smp.rest.log-exceptions", SMPServerConfiguration.isRESTLogExceptions());
    // New in 5.2.1
    aStatusData.add("smp.rest.payload-on-error", SMPServerConfiguration.isRESTPayloadOnError());
    // SML information
    aStatusData.add("smp.sml.enabled", aSettings.isSMLEnabled());
    aStatusData.add("smp.sml.needed", aSettings.isSMLRequired());
    if (aSMLInfo != null) {
        aStatusData.add("smp.sml.url", aSMLInfo.getManagementServiceURL());
        aStatusData.add("smp.sml.dnszone", aSMLInfo.getDNSZone());
    }
    aStatusData.addIfNotNull("smp.sml.connection-timeout-ms", SMPServerConfiguration.getSMLConnectionTimeoutMS());
    aStatusData.add("smp.sml.request-timeout-ms", SMPServerConfiguration.getSMLRequestTimeoutMS());
    // Directory information
    aStatusData.add("smp.pd.enabled", aSettings.isDirectoryIntegrationEnabled());
    // New in 5.1.0
    aStatusData.add("smp.pd.needed", aSettings.isDirectoryIntegrationRequired());
    aStatusData.add("smp.pd.auto-update", aSettings.isDirectoryIntegrationAutoUpdate());
    aStatusData.add("smp.pd.hostname", aSettings.getDirectoryHostName());
    // Certificate information
    final boolean bCertConfigOk = SMPKeyManager.isKeyStoreValid();
    aStatusData.add("smp.certificate.configuration-valid", bCertConfigOk);
    if (bCertConfigOk) {
        final SMPKeyManager aKeyMgr = SMPKeyManager.getInstance();
        final PrivateKeyEntry aKeyEntry = aKeyMgr.getPrivateKeyEntry();
        if (aKeyEntry != null) {
            final Certificate[] aChain = aKeyEntry.getCertificateChain();
            if (aChain.length > 0 && aChain[0] instanceof X509Certificate) {
                final X509Certificate aX509Cert = (X509Certificate) aChain[0];
                aStatusData.add("smp.certificate.issuer", aX509Cert.getIssuerX500Principal().getName());
                aStatusData.add("smp.certificate.subject", aX509Cert.getSubjectX500Principal().getName());
                final LocalDateTime aNotAfter = PDTFactory.createLocalDateTime(aX509Cert.getNotAfter());
                final boolean bIsExpired = aNow.isAfter(aNotAfter);
                aStatusData.add("smp.certificate.expired", bIsExpired);
            }
        }
    }
    // Proxy configuration (since 5.2.0)
    aStatusData.add("proxy.http.configured", SMPServerConfiguration.getAsHttpProxySettings() != null);
    aStatusData.add("proxy.https.configured", SMPServerConfiguration.getAsHttpsProxySettings() != null);
    aStatusData.add("proxy.username.configured", StringHelper.hasText(SMPServerConfiguration.getProxyUsername()));
    // CSP configuration (since 5.2.6)
    aStatusData.add("csp.enabled", SMPWebAppConfiguration.isCSPEnabled());
    aStatusData.add("csp.reporting.only", SMPWebAppConfiguration.isCSPReportingOnly());
    aStatusData.add("csp.reporting.enabled", SMPWebAppConfiguration.isCSPReportingEnabled());
    // Add SPI data as well
    for (final ISMPStatusProviderExtensionSPI aImpl : LIST) {
        final ICommonsOrderedMap<String, ?> aMap = aImpl.getAdditionalStatusData(bDisableLongRunningOperations);
        aStatusData.addAll(aMap);
    }
    final long nMillis = aSW.stopAndGetMillis();
    if (nMillis > 100)
        LOGGER.info("Finished building status data after " + nMillis + " milliseconds which is considered to be too long");
    else if (LOGGER.isDebugEnabled())
        LOGGER.debug("Finished building status data");
    return aStatusData;
}
Also used : LocalDateTime(java.time.LocalDateTime) ISMLInfo(com.helger.peppol.sml.ISMLInfo) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) X509Certificate(java.security.cert.X509Certificate) StopWatch(com.helger.commons.timing.StopWatch) SMPKeyManager(com.helger.phoss.smp.security.SMPKeyManager) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) IJsonObject(com.helger.json.IJsonObject) PrivateKeyEntry(java.security.KeyStore.PrivateKeyEntry) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 5 with ISMPSettings

use of com.helger.phoss.smp.settings.ISMPSettings in project phoss-smp by phax.

the class PageSecureBusinessCard method validateAndSaveInputParameters.

@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPBusinessCard aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final boolean bEdit = eFormAction.isEdit();
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    final ISMPServiceGroupManager aServiceGroupManager = SMPMetaManager.getServiceGroupMgr();
    final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
    final String sServiceGroupID = bEdit ? aSelectedObject.getID() : aWPEC.params().getAsString(FIELD_SERVICE_GROUP_ID);
    ISMPServiceGroup aServiceGroup = null;
    final ICommonsList<SMPBusinessCardEntity> aSMPEntities = new CommonsArrayList<>();
    // validations
    if (StringHelper.hasNoText(sServiceGroupID))
        aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "A Service Group must be selected!");
    else {
        aServiceGroup = aServiceGroupManager.getSMPServiceGroupOfID(aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID));
        if (aServiceGroup == null)
            aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "The provided Service Group does not exist!");
        else if (!bEdit) {
            final ISMPBusinessCard aExistingBusinessCard = aBusinessCardMgr.getSMPBusinessCardOfID(aServiceGroup.getParticipantIdentifier());
            if (aExistingBusinessCard != null)
                aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "The selected Service Group already has a Business Card assigned!");
        }
    }
    final IRequestParamMap aEntities = aWPEC.getRequestParamMap().getMap(PREFIX_ENTITY);
    if (aEntities != null)
        for (final String sEntityRowID : aEntities.keySet()) {
            final ICommonsMap<String, String> aEntityRow = aEntities.getValueMap(sEntityRowID);
            final int nErrors = aFormErrors.size();
            // Entity name
            final String sFieldName = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, SUFFIX_NAME);
            final String sEntityName = aEntityRow.get(SUFFIX_NAME);
            if (StringHelper.hasNoText(sEntityName))
                aFormErrors.addFieldError(sFieldName, "The Name of the Entity must be provided!");
            // Entity country code
            final String sFieldCountryCode = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, SUFFIX_COUNTRY_CODE);
            final String sCountryCode = aEntityRow.get(SUFFIX_COUNTRY_CODE);
            if (StringHelper.hasNoText(sCountryCode))
                aFormErrors.addFieldError(sFieldCountryCode, "The Country Code of the Entity must be provided!");
            // Entity Geographical Information
            final String sGeoInfo = aEntityRow.get(SUFFIX_GEO_INFO);
            // Entity Identifiers
            final ICommonsList<SMPBusinessCardIdentifier> aSMPIdentifiers = new CommonsArrayList<>();
            final IRequestParamMap aIdentifiers = aEntities.getMap(sEntityRowID, PREFIX_IDENTIFIER);
            if (aIdentifiers != null)
                for (final String sIdentifierRowID : aIdentifiers.keySet()) {
                    final ICommonsMap<String, String> aIdentifierRow = aIdentifiers.getValueMap(sIdentifierRowID);
                    final int nErrors2 = aFormErrors.size();
                    // Scheme
                    final String sFieldScheme = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, PREFIX_IDENTIFIER, sIdentifierRowID, SUFFIX_SCHEME);
                    final String sScheme = aIdentifierRow.get(SUFFIX_SCHEME);
                    if (StringHelper.hasNoText(sScheme))
                        aFormErrors.addFieldError(sFieldScheme, "The Scheme of the Identifier must be provided!");
                    // Value
                    final String sFieldValue = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, PREFIX_IDENTIFIER, sIdentifierRowID, SUFFIX_VALUE);
                    final String sValue = aIdentifierRow.get(SUFFIX_VALUE);
                    if (StringHelper.hasNoText(sValue))
                        aFormErrors.addFieldError(sFieldValue, "The Value of the Identifier must be provided!");
                    if (aFormErrors.size() == nErrors2) {
                        final boolean bIsNewIdentifier = sIdentifierRowID.startsWith(TMP_ID_PREFIX);
                        aSMPIdentifiers.add(bIsNewIdentifier ? new SMPBusinessCardIdentifier(sScheme, sValue) : new SMPBusinessCardIdentifier(sIdentifierRowID, sScheme, sValue));
                    }
                }
            aSMPIdentifiers.sort((o1, o2) -> {
                int ret = o1.getScheme().compareToIgnoreCase(o2.getScheme());
                if (ret == 0)
                    ret = o1.getValue().compareToIgnoreCase(o2.getValue());
                return ret;
            });
            // Entity Website URIs
            final String sFieldWebsiteURIs = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, SUFFIX_WEBSITE_URIS);
            final String sWebsiteURIs = aEntityRow.get(SUFFIX_WEBSITE_URIS);
            final ICommonsList<String> aWebsiteURIs = new CommonsArrayList<>();
            for (final String sWebsiteURI : RegExHelper.getSplitToArray(sWebsiteURIs, "\\n")) {
                final String sRealWebsiteURI = sWebsiteURI.trim();
                if (sRealWebsiteURI.length() > 0)
                    if (URLValidator.isValid(sRealWebsiteURI))
                        aWebsiteURIs.add(sRealWebsiteURI);
                    else
                        aFormErrors.addFieldError(sFieldWebsiteURIs, "The website URI '" + sRealWebsiteURI + "' is invalid!");
            }
            // Entity Contacts
            final ICommonsList<SMPBusinessCardContact> aSMPContacts = new CommonsArrayList<>();
            final IRequestParamMap aContacts = aEntities.getMap(sEntityRowID, PREFIX_CONTACT);
            if (aContacts != null)
                for (final String sContactRowID : aContacts.keySet()) {
                    final ICommonsMap<String, String> aContactRow = aContacts.getValueMap(sContactRowID);
                    final int nErrors2 = aFormErrors.size();
                    final String sType = aContactRow.get(SUFFIX_TYPE);
                    final String sName = aContactRow.get(SUFFIX_NAME);
                    final String sPhoneNumber = aContactRow.get(SUFFIX_PHONE);
                    final String sFieldEmail = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, PREFIX_CONTACT, sContactRowID, SUFFIX_EMAIL);
                    final String sEmail = aContactRow.get(SUFFIX_EMAIL);
                    if (StringHelper.hasText(sEmail))
                        if (!EmailAddressValidator.isValid(sEmail))
                            aFormErrors.addFieldError(sFieldEmail, "The provided email address is invalid!");
                    final boolean bIsAnySet = StringHelper.hasText(sType) || StringHelper.hasText(sName) || StringHelper.hasText(sPhoneNumber) || StringHelper.hasText(sEmail);
                    if (aFormErrors.size() == nErrors2 && bIsAnySet) {
                        final boolean bIsNewContact = sContactRowID.startsWith(TMP_ID_PREFIX);
                        aSMPContacts.add(bIsNewContact ? new SMPBusinessCardContact(sType, sName, sPhoneNumber, sEmail) : new SMPBusinessCardContact(sContactRowID, sType, sName, sPhoneNumber, sEmail));
                    }
                }
            aSMPContacts.sort((o1, o2) -> {
                int ret = CompareHelper.compareIgnoreCase(o1.getType(), o2.getType());
                if (ret == 0) {
                    ret = CompareHelper.compareIgnoreCase(o1.getName(), o2.getName());
                    if (ret == 0) {
                        ret = CompareHelper.compareIgnoreCase(o1.getPhoneNumber(), o2.getPhoneNumber());
                        if (ret == 0)
                            ret = CompareHelper.compareIgnoreCase(o1.getEmail(), o2.getEmail());
                    }
                }
                return ret;
            });
            // Entity Additional Information
            final String sAdditionalInfo = aEntityRow.get(SUFFIX_ADDITIONAL_INFO);
            // Entity Registration Date
            final String sFieldRegDate = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityRowID, SUFFIX_REG_DATE);
            final String sRegDate = aEntityRow.get(SUFFIX_REG_DATE);
            final LocalDate aRegDate = PDTFromString.getLocalDateFromString(sRegDate, aDisplayLocale);
            if (aRegDate == null && StringHelper.hasText(sRegDate))
                aFormErrors.addFieldError(sFieldRegDate, "The entered registration date is invalid!");
            if (aFormErrors.size() == nErrors) {
                // Add to list
                final boolean bIsNewEntity = sEntityRowID.startsWith(TMP_ID_PREFIX);
                final SMPBusinessCardEntity aEntity = bIsNewEntity ? new SMPBusinessCardEntity() : new SMPBusinessCardEntity(sEntityRowID);
                aEntity.names().add(new SMPBusinessCardName(sEntityName, null));
                aEntity.setCountryCode(sCountryCode);
                aEntity.setGeographicalInformation(sGeoInfo);
                aEntity.identifiers().setAll(aSMPIdentifiers);
                aEntity.websiteURIs().setAll(aWebsiteURIs);
                aEntity.contacts().setAll(aSMPContacts);
                aEntity.setAdditionalInformation(sAdditionalInfo);
                aEntity.setRegistrationDate(aRegDate);
                aSMPEntities.add(aEntity);
            }
        }
    if (aSMPEntities.isEmpty())
        if (aFormErrors.isEmpty())
            aFormErrors.addFieldError(FIELD_SERVICE_GROUP_ID, "At least one entity must be provided.");
    if (aFormErrors.isEmpty()) {
        // Store in a consistent manner
        aSMPEntities.sort((o1, o2) -> o1.names().getFirst().getName().compareToIgnoreCase(o2.names().getFirst().getName()));
        if (aBusinessCardMgr.createOrUpdateSMPBusinessCard(aServiceGroup.getParticipantIdentifier(), aSMPEntities) != null) {
            final ISMPSettings aSettings = SMPMetaManager.getSettings();
            aWPEC.postRedirectGetInternal(success("The Business Card for Service Group '" + aServiceGroup.getID() + "' was successfully saved." + (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate() ? " " + SMPWebAppConfiguration.getDirectoryName() + " server should have been updated." : "")));
        } else
            aWPEC.postRedirectGetInternal(error("Error creating the Business Card for Service Group '" + aServiceGroup.getID() + "'"));
    }
}
Also used : Locale(java.util.Locale) GlobalIDFactory(com.helger.commons.id.factory.GlobalIDFactory) ILayoutExecutionContext(com.helger.photon.core.execcontext.ILayoutExecutionContext) PDClientProvider(com.helger.phoss.smp.app.PDClientProvider) EWithDeprecated(com.helger.photon.uicore.html.select.HCCountrySelect.EWithDeprecated) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) FormErrorList(com.helger.photon.core.form.FormErrorList) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) HCServiceGroupSelect(com.helger.phoss.smp.ui.secure.hc.HCServiceGroupSelect) Nonempty(com.helger.commons.annotation.Nonempty) SMPBusinessCardIdentifier(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardIdentifier) HCA(com.helger.html.hc.html.textlevel.HCA) HCTextArea(com.helger.html.hc.html.forms.HCTextArea) CPageParam(com.helger.photon.uicore.css.CPageParam) PDTToString(com.helger.commons.datetime.PDTToString) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) IHCCell(com.helger.html.hc.html.tabular.IHCCell) HCDiv(com.helger.html.hc.html.grouping.HCDiv) HCTextNode(com.helger.html.hc.impl.HCTextNode) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCExtHelper(com.helger.html.hc.ext.HCExtHelper) RegExHelper(com.helger.commons.regex.RegExHelper) IValidityIndicator(com.helger.commons.state.IValidityIndicator) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) RequestParamMap(com.helger.servlet.request.RequestParamMap) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) BootstrapCardBody(com.helger.photon.bootstrap4.card.BootstrapCardBody) JSJQueryHelper(com.helger.photon.uicore.js.JSJQueryHelper) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) DataTables(com.helger.photon.uictrls.datatables.DataTables) IRequestParamMap(com.helger.servlet.request.IRequestParamMap) LinkHelper(com.helger.photon.app.url.LinkHelper) JSAssocArray(com.helger.html.jscode.JSAssocArray) BootstrapDateTimePicker(com.helger.photon.bootstrap4.uictrls.datetimepicker.BootstrapDateTimePicker) PDTFromString(com.helger.commons.datetime.PDTFromString) HCEdit(com.helger.html.hc.html.forms.HCEdit) IHCNode(com.helger.html.hc.IHCNode) JQuery(com.helger.html.jquery.JQuery) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) Nullable(javax.annotation.Nullable) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) StringHelper(com.helger.commons.string.StringHelper) WorkInProgress(com.helger.commons.annotation.WorkInProgress) SMPMetaManager(com.helger.phoss.smp.domain.SMPMetaManager) BootstrapFormHelper(com.helger.photon.bootstrap4.form.BootstrapFormHelper) CAjax(com.helger.phoss.smp.ui.ajax.CAjax) HCA_MailTo(com.helger.html.hc.ext.HCA_MailTo) HCCol(com.helger.html.hc.html.tabular.HCCol) RequestField(com.helger.photon.core.form.RequestField) AbstractBootstrapWebPageActionHandler(com.helger.photon.bootstrap4.pages.handler.AbstractBootstrapWebPageActionHandler) ESortOrder(com.helger.commons.compare.ESortOrder) JSAnonymousFunction(com.helger.html.jscode.JSAnonymousFunction) LayoutExecutionContext(com.helger.photon.core.execcontext.LayoutExecutionContext) JSVar(com.helger.html.jscode.JSVar) WebPageExecutionContext(com.helger.photon.uicore.page.WebPageExecutionContext) EDefaultIcon(com.helger.photon.uicore.icon.EDefaultIcon) BootstrapSuccessBox(com.helger.photon.bootstrap4.alert.BootstrapSuccessBox) AbstractBootstrapWebPageActionHandlerDelete(com.helger.photon.bootstrap4.pages.handler.AbstractBootstrapWebPageActionHandlerDelete) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) Locale(java.util.Locale) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) EmailAddressValidator(com.helger.smtp.util.EmailAddressValidator) SMPCommonUI(com.helger.phoss.smp.ui.SMPCommonUI) BootstrapErrorBox(com.helger.photon.bootstrap4.alert.BootstrapErrorBox) HCCountrySelect(com.helger.photon.uicore.html.select.HCCountrySelect) EWebPageFormAction(com.helger.photon.uicore.page.EWebPageFormAction) BootstrapCard(com.helger.photon.bootstrap4.card.BootstrapCard) IAjaxFunctionDeclaration(com.helger.photon.ajax.decl.IAjaxFunctionDeclaration) PDClient(com.helger.pd.client.PDClient) CountryCache(com.helger.commons.locale.country.CountryCache) EFamFamIcon(com.helger.photon.uictrls.famfam.EFamFamIcon) LocalDate(java.time.LocalDate) SMPWebAppConfiguration(com.helger.phoss.smp.app.SMPWebAppConfiguration) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ESuccess(com.helger.commons.state.ESuccess) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) HCRow(com.helger.html.hc.html.tabular.HCRow) EValidity(com.helger.commons.state.EValidity) PhotonUnifiedResponse(com.helger.photon.app.PhotonUnifiedResponse) AbstractSMPWebPageForm(com.helger.phoss.smp.ui.AbstractSMPWebPageForm) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) CompareHelper(com.helger.commons.compare.CompareHelper) URLValidator(com.helger.commons.url.URLValidator) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) ISimpleURL(com.helger.commons.url.ISimpleURL) HCNodeList(com.helger.html.hc.impl.HCNodeList) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) CBootstrapCSS(com.helger.photon.bootstrap4.CBootstrapCSS) HCTable(com.helger.html.hc.html.tabular.HCTable) JQueryAjaxBuilder(com.helger.html.jquery.JQueryAjaxBuilder) SMPBusinessCardName(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName) EBootstrapButtonSize(com.helger.photon.bootstrap4.button.EBootstrapButtonSize) EShowList(com.helger.photon.uicore.page.EShowList) EFamFamFlagIcon(com.helger.photon.uictrls.famfam.EFamFamFlagIcon) SMPBusinessCardContact(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardContact) JSPackage(com.helger.html.jscode.JSPackage) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) SMPBusinessCardName(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName) PDTToString(com.helger.commons.datetime.PDTToString) PDTFromString(com.helger.commons.datetime.PDTFromString) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) LocalDate(java.time.LocalDate) SMPBusinessCardIdentifier(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardIdentifier) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) SMPBusinessCardContact(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardContact) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) IRequestParamMap(com.helger.servlet.request.IRequestParamMap) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList)

Aggregations

ISMPSettings (com.helger.phoss.smp.settings.ISMPSettings)22 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)12 HCNodeList (com.helger.html.hc.impl.HCNodeList)10 Nonnull (javax.annotation.Nonnull)9 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)8 PDTToString (com.helger.commons.datetime.PDTToString)7 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)7 HCA (com.helger.html.hc.html.textlevel.HCA)6 ManageParticipantIdentifierServiceCaller (com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller)6 ISMPParticipantMigrationManager (com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager)6 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)6 ISMLInfo (com.helger.peppol.sml.ISMLInfo)5 SMPMetaManager (com.helger.phoss.smp.domain.SMPMetaManager)5 ISMPBusinessCardManager (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager)5 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)5 BootstrapButton (com.helger.photon.bootstrap4.button.BootstrapButton)5 Locale (java.util.Locale)5 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)4 ICommonsList (com.helger.commons.collection.impl.ICommonsList)4 ISMPBusinessCard (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard)4