Search in sources :

Example 1 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.

the class SMPServiceInformationManagerJDBC method getAllSMPServiceInformationOfServiceGroup.

@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPServiceInformation> getAllSMPServiceInformationOfServiceGroup(@Nullable final ISMPServiceGroup aServiceGroup) {
    final ICommonsList<ISMPServiceInformation> ret = new CommonsArrayList<>();
    if (aServiceGroup != null) {
        final IParticipantIdentifier aPID = aServiceGroup.getParticipantIdentifier();
        final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT sm.documentIdentifierScheme, sm.documentIdentifier, sm.extension," + "   sp.processIdentifierType, sp.processIdentifier, sp.extension," + "   se.transportProfile, se.endpointReference, se.requireBusinessLevelSignature, se.minimumAuthenticationLevel," + "     se.serviceActivationDate, se.serviceExpirationDate, se.certificate, se.serviceDescription," + "     se.technicalContactUrl, se.technicalInformationUrl, se.extension" + " FROM smp_service_metadata AS sm" + " INNER JOIN smp_process AS sp" + "   ON sm.businessIdentifierScheme=sp.businessIdentifierScheme AND sm.businessIdentifier=sp.businessIdentifier" + "   AND sm.documentIdentifierScheme=sp.documentIdentifierScheme AND sm.documentIdentifier=sp.documentIdentifier" + " INNER JOIN smp_endpoint AS se" + "   ON sp.businessIdentifierScheme=se.businessIdentifierScheme AND sp.businessIdentifier=se.businessIdentifier" + "   AND sp.documentIdentifierScheme=se.documentIdentifierScheme AND sp.documentIdentifier=se.documentIdentifier" + "   AND sp.processIdentifierType=se.processIdentifierType AND sp.processIdentifier=se.processIdentifier" + " WHERE sm.businessIdentifierScheme=? AND sm.businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
        if (aDBResult != null) {
            final ICommonsMap<DocTypeAndExtension, ICommonsMap<SMPProcess, ICommonsList<SMPEndpoint>>> aGrouping = new CommonsHashMap<>();
            for (final DBResultRow aDBRow : aDBResult) {
                // Document type ID and extension
                final IDocumentTypeIdentifier aDocTypeID = new SimpleDocumentTypeIdentifier(aDBRow.getAsString(0), aDBRow.getAsString(1));
                final String sServiceInformationExtension = aDBRow.getAsString(2);
                // Process without endpoints
                final SMPProcess aProcess = new SMPProcess(new SimpleProcessIdentifier(aDBRow.getAsString(3), aDBRow.getAsString(4)), null, aDBRow.getAsString(5));
                // Don't add endpoint to process, because that impacts
                // SMPProcess.equals/hashcode
                final SMPEndpoint aEndpoint = new SMPEndpoint(aDBRow.getAsString(6), aDBRow.getAsString(7), aDBRow.getAsBoolean(8, SMPEndpoint.DEFAULT_REQUIRES_BUSINESS_LEVEL_SIGNATURE), aDBRow.getAsString(9), aDBRow.getAsXMLOffsetDateTime(10), aDBRow.getAsXMLOffsetDateTime(11), aDBRow.getAsString(12), aDBRow.getAsString(13), aDBRow.getAsString(14), aDBRow.getAsString(15), aDBRow.getAsString(16));
                aGrouping.computeIfAbsent(new DocTypeAndExtension(aDocTypeID, sServiceInformationExtension), k -> new CommonsHashMap<>()).computeIfAbsent(aProcess, k -> new CommonsArrayList<>()).add(aEndpoint);
            }
            for (final Map.Entry<DocTypeAndExtension, ICommonsMap<SMPProcess, ICommonsList<SMPEndpoint>>> aEntry : aGrouping.entrySet()) {
                // Flatten list
                final ICommonsList<SMPProcess> aProcesses = new CommonsArrayList<>();
                for (final Map.Entry<SMPProcess, ICommonsList<SMPEndpoint>> aEntry2 : aEntry.getValue().entrySet()) {
                    final SMPProcess aProcess = aEntry2.getKey();
                    aProcess.addEndpoints(aEntry2.getValue());
                    aProcesses.add(aProcess);
                }
                final DocTypeAndExtension aDE = aEntry.getKey();
                ret.add(new SMPServiceInformation(aServiceGroup, aDE.m_aDocTypeID, aProcesses, aDE.m_sExt));
            }
        }
    }
    return ret;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) Nonnegative(javax.annotation.Nonnegative) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SimpleProcessIdentifier(com.helger.peppolid.simple.process.SimpleProcessIdentifier) MustImplementEqualsAndHashcode(com.helger.commons.annotation.MustImplementEqualsAndHashcode) EChange(com.helger.commons.state.EChange) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) Supplier(java.util.function.Supplier) CallbackList(com.helger.commons.callback.CallbackList) DBValueHelper(com.helger.db.api.helper.DBValueHelper) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) AbstractJDBCEnabledManager(com.helger.db.jdbc.mgr.AbstractJDBCEnabledManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) MutableBoolean(com.helger.commons.mutable.MutableBoolean) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) Map(java.util.Map) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ISMPServiceInformationCallback(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) HashCodeGenerator(com.helger.commons.hashcode.HashCodeGenerator) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) StringHelper(com.helger.commons.string.StringHelper) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) EqualsHelper(com.helger.commons.equals.EqualsHelper) ValueEnforcer(com.helger.commons.ValueEnforcer) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) AuditHelper(com.helger.photon.audit.AuditHelper) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) Wrapper(com.helger.commons.wrapper.Wrapper) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ReturnsMutableObject(com.helger.commons.annotation.ReturnsMutableObject) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) ICommonsList(com.helger.commons.collection.impl.ICommonsList) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) SimpleProcessIdentifier(com.helger.peppolid.simple.process.SimpleProcessIdentifier) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) Map(java.util.Map) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 2 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.

the class SMPServiceInformationManagerJDBC method deleteAllSMPServiceInformationOfServiceGroup.

@Nonnull
public EChange deleteAllSMPServiceInformationOfServiceGroup(@Nullable final ISMPServiceGroup aServiceGroup) {
    if (aServiceGroup == null)
        return EChange.UNCHANGED;
    final Wrapper<Long> ret = new Wrapper<>(Long.valueOf(0));
    final Wrapper<ICommonsList<ISMPServiceInformation>> aAllDeleted = new Wrapper<>();
    final DBExecutor aExecutor = newExecutor();
    final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
        // get the old ones first
        aAllDeleted.set(getAllSMPServiceInformationOfServiceGroup(aServiceGroup));
        final IParticipantIdentifier aPID = aServiceGroup.getParticipantIdentifier();
        final long nCountEP = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_endpoint" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
        final long nCountProc = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_process" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
        final long nCountSM = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_service_metadata" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
        ret.set(Long.valueOf(nCountEP + nCountProc + nCountSM));
    });
    if (eSuccess.isFailure() || ret.get().longValue() <= 0) {
        AuditHelper.onAuditDeleteFailure(SMPServiceInformation.OT, "no-such-id", aServiceGroup.getID());
        return EChange.UNCHANGED;
    }
    // Callback outside of transaction
    if (aAllDeleted.isSet())
        for (final ISMPServiceInformation aSMPServiceInformation : aAllDeleted.get()) {
            AuditHelper.onAuditDeleteSuccess(SMPServiceInformation.OT, aSMPServiceInformation.getID());
            m_aCBs.forEach(x -> x.onSMPServiceInformationDeleted(aSMPServiceInformation));
        }
    return EChange.CHANGED;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) ESuccess(com.helger.commons.state.ESuccess) Nonnegative(javax.annotation.Nonnegative) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SimpleProcessIdentifier(com.helger.peppolid.simple.process.SimpleProcessIdentifier) MustImplementEqualsAndHashcode(com.helger.commons.annotation.MustImplementEqualsAndHashcode) EChange(com.helger.commons.state.EChange) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) Supplier(java.util.function.Supplier) CallbackList(com.helger.commons.callback.CallbackList) DBValueHelper(com.helger.db.api.helper.DBValueHelper) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) AbstractJDBCEnabledManager(com.helger.db.jdbc.mgr.AbstractJDBCEnabledManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) MutableBoolean(com.helger.commons.mutable.MutableBoolean) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) Map(java.util.Map) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ISMPServiceInformationCallback(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) HashCodeGenerator(com.helger.commons.hashcode.HashCodeGenerator) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) StringHelper(com.helger.commons.string.StringHelper) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) EqualsHelper(com.helger.commons.equals.EqualsHelper) ValueEnforcer(com.helger.commons.ValueEnforcer) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) AuditHelper(com.helger.photon.audit.AuditHelper) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) Wrapper(com.helger.commons.wrapper.Wrapper) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ReturnsMutableObject(com.helger.commons.annotation.ReturnsMutableObject) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) Wrapper(com.helger.commons.wrapper.Wrapper) ICommonsList(com.helger.commons.collection.impl.ICommonsList) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull)

Example 3 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.

the class SMPServiceInformationManagerMongoDB method mergeSMPServiceInformation.

@Nonnull
public ESuccess mergeSMPServiceInformation(@Nonnull final ISMPServiceInformation aSMPServiceInformationObj) {
    final SMPServiceInformation aSMPServiceInformation = (SMPServiceInformation) aSMPServiceInformationObj;
    ValueEnforcer.notNull(aSMPServiceInformation, "ServiceInformation");
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("mergeSMPServiceInformation (" + aSMPServiceInformationObj + ")");
    // Check for an update
    boolean bChangedExisting = false;
    final ISMPServiceInformation aOldInformation = getSMPServiceInformationOfServiceGroupAndDocumentType(aSMPServiceInformation.getServiceGroup(), aSMPServiceInformation.getDocumentTypeIdentifier());
    if (aOldInformation != null) {
        // This is not true for the REST API
        if (EqualsHelper.identityEqual(aOldInformation, aSMPServiceInformation))
            bChangedExisting = true;
    }
    if (bChangedExisting) {
        // Edit existing
        getCollection().replaceOne(new Document(BSON_ID, aOldInformation.getID()), toBson(aSMPServiceInformation));
        AuditHelper.onAuditModifySuccess(SMPServiceInformation.OT, "set-all", aOldInformation.getID(), aOldInformation.getServiceGroupID(), aOldInformation.getDocumentTypeIdentifier().getURIEncoded(), aOldInformation.getAllProcesses(), aOldInformation.getExtensionsAsString());
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("mergeSMPServiceInformation - success - updated");
        m_aCBs.forEach(x -> x.onSMPServiceInformationUpdated(aSMPServiceInformation));
    } else {
        // (Optionally delete the old one and) create the new one
        boolean bRemovedOld = false;
        if (aOldInformation != null) {
            // Delete only if present
            final DeleteResult aDR = getCollection().deleteOne(new Document(BSON_ID, aOldInformation.getID()));
            bRemovedOld = aDR.wasAcknowledged() && aDR.getDeletedCount() > 0;
        }
        if (!getCollection().insertOne(toBson(aSMPServiceInformation)).wasAcknowledged())
            throw new IllegalStateException("Failed to insert into MongoDB Collection");
        if (bRemovedOld) {
            AuditHelper.onAuditDeleteSuccess(SMPServiceInformation.OT, aOldInformation.getID(), aOldInformation.getServiceGroupID(), aOldInformation.getDocumentTypeIdentifier().getURIEncoded());
        } else if (aOldInformation != null) {
            AuditHelper.onAuditDeleteFailure(SMPServiceInformation.OT, aOldInformation.getID(), aOldInformation.getServiceGroupID(), aOldInformation.getDocumentTypeIdentifier().getURIEncoded());
        }
        AuditHelper.onAuditCreateSuccess(SMPServiceInformation.OT, aSMPServiceInformation.getID(), aSMPServiceInformation.getServiceGroupID(), aSMPServiceInformation.getDocumentTypeIdentifier().getURIEncoded(), aSMPServiceInformation.getAllProcesses(), aSMPServiceInformation.getExtensionsAsString());
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("mergeSMPServiceInformation - success - created");
        if (bChangedExisting)
            m_aCBs.forEach(x -> x.onSMPServiceInformationUpdated(aSMPServiceInformation));
        else
            m_aCBs.forEach(x -> x.onSMPServiceInformationCreated(aSMPServiceInformation));
    }
    return ESuccess.SUCCESS;
}
Also used : Document(org.bson.Document) ESuccess(com.helger.commons.state.ESuccess) Nonnegative(javax.annotation.Nonnegative) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) EChange(com.helger.commons.state.EChange) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) CallbackList(com.helger.commons.callback.CallbackList) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) Filters(com.mongodb.client.model.Filters) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) ISMPServiceInformationCallback(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) StringHelper(com.helger.commons.string.StringHelper) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) EqualsHelper(com.helger.commons.equals.EqualsHelper) ValueEnforcer(com.helger.commons.ValueEnforcer) Consumer(java.util.function.Consumer) AuditHelper(com.helger.photon.audit.AuditHelper) List(java.util.List) TypeConverter(com.helger.commons.typeconvert.TypeConverter) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ReturnsMutableObject(com.helger.commons.annotation.ReturnsMutableObject) DeleteResult(com.mongodb.client.result.DeleteResult) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) Document(org.bson.Document) DeleteResult(com.mongodb.client.result.DeleteResult) Nonnull(javax.annotation.Nonnull)

Example 4 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation 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 5 with ISMPServiceInformation

use of com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation in project phoss-smp by phax.

the class SMPMetaManager method _performMigrations.

private void _performMigrations() {
    // Required for SQL version
    try (final WebScoped aWS = new WebScoped()) {
        // See issue #128
        PhotonBasicManager.getSystemMigrationMgr().performMigrationIfNecessary("ensure-transport-profiles-128", () -> {
            LOGGER.info("Started running migration to ensure all used transport profiles are automatically created");
            for (final ISMPServiceInformation aSI : m_aServiceInformationMgr.getAllSMPServiceInformation()) for (final ISMPProcess aProc : aSI.getAllProcesses()) for (final ISMPEndpoint aEP : aProc.getAllEndpoints()) {
                final String sTransportProfile = aEP.getTransportProfile();
                if (!m_aTransportProfileMgr.containsSMPTransportProfileWithID(sTransportProfile)) {
                    m_aTransportProfileMgr.createSMPTransportProfile(sTransportProfile, sTransportProfile + " (automatically created)", false);
                    LOGGER.info("Created missing transport profile '" + sTransportProfile + "'");
                }
            }
        });
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess)

Aggregations

ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)31 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)27 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)27 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)20 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)20 Nonnull (javax.annotation.Nonnull)20 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)17 ISMPProcess (com.helger.phoss.smp.domain.serviceinfo.ISMPProcess)16 ISMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint)15 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)14 ICommonsList (com.helger.commons.collection.impl.ICommonsList)13 SMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation)12 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)11 IProcessIdentifier (com.helger.peppolid.IProcessIdentifier)11 SMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint)11 EChange (com.helger.commons.state.EChange)10 ValueEnforcer (com.helger.commons.ValueEnforcer)9 StringHelper (com.helger.commons.string.StringHelper)9 ISMPTransportProfile (com.helger.peppol.smp.ISMPTransportProfile)9 ISMPServiceInformationCallback (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback)9