Search in sources :

Example 1 with ISMPTransportProfile

use of com.helger.peppol.smp.ISMPTransportProfile in project phoss-smp by phax.

the class SMPTransportProfileManagerJDBC method getSMPTransportProfileOfID.

@Nullable
public ISMPTransportProfile getSMPTransportProfileOfID(@Nullable final String sID) {
    if (StringHelper.hasNoText(sID))
        return null;
    final Wrapper<DBResultRow> aDBResult = new Wrapper<>();
    newExecutor().querySingle("SELECT name, deprecated FROM smp_tprofile WHERE id=?", new ConstantPreparedStatementDataProvider(sID), aDBResult::set);
    if (aDBResult.isNotSet())
        return null;
    final DBResultRow aRow = aDBResult.get();
    return new SMPTransportProfile(sID, aRow.getAsString(0), aRow.getAsBoolean(1, SMPTransportProfile.DEFAULT_DEPRECATED));
}
Also used : Wrapper(com.helger.commons.wrapper.Wrapper) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPTransportProfile(com.helger.peppol.smp.SMPTransportProfile) Nullable(javax.annotation.Nullable)

Example 2 with ISMPTransportProfile

use of com.helger.peppol.smp.ISMPTransportProfile 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() + "'."));
            }
        }
    }
}
Also used : Locale(java.util.Locale) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) CertificateException(java.security.cert.CertificateException) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) PDTToString(com.helger.commons.datetime.PDTToString) PDTFromString(com.helger.commons.datetime.PDTFromString) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) LocalDate(java.time.LocalDate) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) X509Certificate(java.security.cert.X509Certificate) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) ISMPTransportProfileManager(com.helger.phoss.smp.domain.transportprofile.ISMPTransportProfileManager) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) IMicroDocument(com.helger.xml.microdom.IMicroDocument) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory)

Example 3 with ISMPTransportProfile

use of com.helger.peppol.smp.ISMPTransportProfile in project phoss-smp by phax.

the class V5__MigrateTransportProfilesToDB method migrate.

public void migrate(@Nonnull final Context context) throws Exception {
    try (final WebScoped aWS = new WebScoped()) {
        LOGGER.info("Migrating all transport profiles to the DB");
        final String sFilename = "transportprofiles.xml";
        final File aFile = WebFileIO.getDataIO().getFile(sFilename);
        if (aFile.exists()) {
            final SMPTransportProfileManagerXML aMgrXML = new SMPTransportProfileManagerXML(sFilename);
            final ICommonsList<ISMPTransportProfile> aTransportProfiles = aMgrXML.getAll();
            if (aTransportProfiles.isNotEmpty()) {
                final SMPTransportProfileManagerJDBC aMgrNew = new SMPTransportProfileManagerJDBC(SMPDBExecutor::new);
                for (final ISMPTransportProfile aTransportProfile : aTransportProfiles) if (aMgrNew.createSMPTransportProfile(aTransportProfile.getID(), aTransportProfile.getName(), aTransportProfile.isDeprecated()) == null)
                    LOGGER.error("Failed to migrate " + aTransportProfile + " to DB");
            }
            // Rename to avoid later inconsistencies
            WebFileIO.getDataIO().renameFile(sFilename, sFilename + ".migrated");
            LOGGER.info("Finished migrating all " + aTransportProfiles.size() + " transport profiles to the DB");
        } else {
            LOGGER.info("No transport profile file found");
        }
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPTransportProfileManagerJDBC(com.helger.phoss.smp.backend.sql.mgr.SMPTransportProfileManagerJDBC) SMPTransportProfileManagerXML(com.helger.phoss.smp.domain.transportprofile.SMPTransportProfileManagerXML) File(java.io.File) SMPDBExecutor(com.helger.phoss.smp.backend.sql.SMPDBExecutor)

Example 4 with ISMPTransportProfile

use of com.helger.peppol.smp.ISMPTransportProfile in project phoss-smp by phax.

the class SMPTransportProfileManagerXML method createSMPTransportProfile.

@Nullable
public ISMPTransportProfile createSMPTransportProfile(@Nonnull @Nonempty final String sID, @Nonnull @Nonempty final String sName, final boolean bIsDeprecated) {
    // Double ID needs to be taken care of
    if (containsWithID(sID))
        return null;
    final SMPTransportProfile aSMPTransportProfile = new SMPTransportProfile(sID, sName, bIsDeprecated);
    m_aRWLock.writeLocked(() -> {
        internalCreateItem(aSMPTransportProfile);
    });
    AuditHelper.onAuditCreateSuccess(SMPTransportProfile.OT, sID, sName, Boolean.valueOf(bIsDeprecated));
    return aSMPTransportProfile;
}
Also used : ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPTransportProfile(com.helger.peppol.smp.SMPTransportProfile) ESMPTransportProfile(com.helger.peppol.smp.ESMPTransportProfile) Nullable(javax.annotation.Nullable)

Example 5 with ISMPTransportProfile

use of com.helger.peppol.smp.ISMPTransportProfile in project phoss-smp by phax.

the class PageSecureTransportProfiles method validateAndSaveInputParameters.

@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPTransportProfile aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
    final boolean bEdit = eFormAction.isEdit();
    final ISMPTransportProfileManager aTransportProfileMgr = SMPMetaManager.getTransportProfileMgr();
    // Never edit ID
    final String sID = bEdit ? aSelectedObject.getID() : aWPEC.params().getAsString(FIELD_ID);
    final String sName = aWPEC.params().getAsString(FIELD_NAME);
    final boolean bIsDeprecated = aWPEC.params().getAsBoolean(FIELD_DEPRECATED, DEFAULT_DEPRECATED);
    // validations
    if (StringHelper.hasNoText(sID))
        aFormErrors.addFieldError(FIELD_ID, "Transport profile ID must not be empty!");
    else if (!bEdit) {
        final ISMPTransportProfile aOther = aTransportProfileMgr.getSMPTransportProfileOfID(sID);
        if (aOther != null)
            aFormErrors.addFieldError(FIELD_ID, "Another transport profile with the same name already exists!");
    }
    if (StringHelper.hasNoText(sName))
        aFormErrors.addFieldError(FIELD_NAME, "The transport profile name must not be empty!");
    if (aFormErrors.isEmpty()) {
        if (bEdit) {
            if (aTransportProfileMgr.updateSMPTransportProfile(sID, sName, bIsDeprecated).isChanged())
                aWPEC.postRedirectGetInternal(success("The transport profile '" + sID + "' was successfully edited."));
            else
                aWPEC.postRedirectGetInternal(error("Failed to edit transport profile '" + sID + "'."));
        } else {
            if (aTransportProfileMgr.createSMPTransportProfile(sID, sName, bIsDeprecated) != null)
                aWPEC.postRedirectGetInternal(success("The new transport profile '" + sID + "' was successfully created."));
            else
                aWPEC.postRedirectGetInternal(error("Failed to create transport profile '" + sID + "'."));
        }
    }
}
Also used : ISMPTransportProfileManager(com.helger.phoss.smp.domain.transportprofile.ISMPTransportProfileManager) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile)

Aggregations

ISMPTransportProfile (com.helger.peppol.smp.ISMPTransportProfile)10 SMPTransportProfile (com.helger.peppol.smp.SMPTransportProfile)4 ISMPTransportProfileManager (com.helger.phoss.smp.domain.transportprofile.ISMPTransportProfileManager)4 Nullable (javax.annotation.Nullable)4 ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)2 ESMPTransportProfile (com.helger.peppol.smp.ESMPTransportProfile)2 Locale (java.util.Locale)2 CommonsHashSet (com.helger.commons.collection.impl.CommonsHashSet)1 PDTFromString (com.helger.commons.datetime.PDTFromString)1 PDTToString (com.helger.commons.datetime.PDTToString)1 ESuccess (com.helger.commons.state.ESuccess)1 ISimpleURL (com.helger.commons.url.ISimpleURL)1 Wrapper (com.helger.commons.wrapper.Wrapper)1 DBExecutor (com.helger.db.jdbc.executor.DBExecutor)1 DBResultRow (com.helger.db.jdbc.executor.DBResultRow)1 HCRow (com.helger.html.hc.html.tabular.HCRow)1 HCTable (com.helger.html.hc.html.tabular.HCTable)1 HCA (com.helger.html.hc.html.textlevel.HCA)1 HCNodeList (com.helger.html.hc.impl.HCNodeList)1 HCTextNode (com.helger.html.hc.impl.HCTextNode)1